big changes to the application flow - get_language
Browse files- utils/oneclick.py +1 -1
- utils/responseparser.py +18 -4
utils/oneclick.py
CHANGED
@@ -150,4 +150,4 @@ def generate_discharge_paper_one_click(
|
|
150 |
|
151 |
except Exception as e:
|
152 |
logger.error("Error in one-click discharge generation: %s\n%s", str(e), traceback.format_exc())
|
153 |
-
return None, f"Error: {str(e)}", None
|
|
|
150 |
|
151 |
except Exception as e:
|
152 |
logger.error("Error in one-click discharge generation: %s\n%s", str(e), traceback.format_exc())
|
153 |
+
return None, f"Error: {str(e)}", None
|
utils/responseparser.py
CHANGED
@@ -3,6 +3,14 @@ import lxml.etree as etree
|
|
3 |
from datetime import datetime
|
4 |
from typing import List, Dict, Optional, Union
|
5 |
import base64
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
class PatientDataExtractor:
|
8 |
"""Class to extract fields from FHIR Patient Bundle (JSON) or C-CDA (XML)."""
|
@@ -221,7 +229,14 @@ class PatientDataExtractor:
|
|
221 |
return lang[0] if lang else ""
|
222 |
elif self.format == "json":
|
223 |
comms = patient.get("communication", [])
|
224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
# Medications
|
227 |
def get_medications(self) -> List[Dict[str, str]]:
|
@@ -235,7 +250,7 @@ class PatientDataExtractor:
|
|
235 |
start_list = med.xpath(".//hl7:effectiveTime/hl7:low/@value", namespaces=self.ns)
|
236 |
start = start_list[0] if start_list else ""
|
237 |
stop_list = med.xpath(".//hl7:effectiveTime/hl7:high/@value", namespaces=self.ns)
|
238 |
-
stop = stop_list[0] if stop_list else ""
|
239 |
desc_list = med.xpath(".//hl7:manufacturedMaterial/hl7:code/@displayName", namespaces=self.ns)
|
240 |
desc = desc_list[0] if desc_list else ""
|
241 |
code_list = med.xpath(".//hl7:manufacturedMaterial/hl7:code/@code", namespaces=self.ns)
|
@@ -449,5 +464,4 @@ class PatientDataExtractor:
|
|
449 |
|
450 |
def get_patient_ids(self) -> List[str]:
|
451 |
"""Return a list of all patient IDs."""
|
452 |
-
return [self.get_id() for _ in self.patients]
|
453 |
-
|
|
|
3 |
from datetime import datetime
|
4 |
from typing import List, Dict, Optional, Union
|
5 |
import base64
|
6 |
+
import logging
|
7 |
+
|
8 |
+
# Set up logging
|
9 |
+
logging.basicConfig(
|
10 |
+
level=logging.INFO,
|
11 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
12 |
+
)
|
13 |
+
logger = logging.getLogger(__name__)
|
14 |
|
15 |
class PatientDataExtractor:
|
16 |
"""Class to extract fields from FHIR Patient Bundle (JSON) or C-CDA (XML)."""
|
|
|
229 |
return lang[0] if lang else ""
|
230 |
elif self.format == "json":
|
231 |
comms = patient.get("communication", [])
|
232 |
+
if comms and "language" in comms[0]:
|
233 |
+
lang = comms[0]["language"]
|
234 |
+
# Try 'text' first, then fall back to 'coding' if available
|
235 |
+
if "text" in lang:
|
236 |
+
return lang["text"]
|
237 |
+
elif "coding" in lang and lang["coding"]:
|
238 |
+
return lang["coding"][0].get("display", lang["coding"][0].get("code", ""))
|
239 |
+
return ""
|
240 |
|
241 |
# Medications
|
242 |
def get_medications(self) -> List[Dict[str, str]]:
|
|
|
250 |
start_list = med.xpath(".//hl7:effectiveTime/hl7:low/@value", namespaces=self.ns)
|
251 |
start = start_list[0] if start_list else ""
|
252 |
stop_list = med.xpath(".//hl7:effectiveTime/hl7:high/@value", namespaces=self.ns)
|
253 |
+
stop = stop_list[0] if stop_list else ""
|
254 |
desc_list = med.xpath(".//hl7:manufacturedMaterial/hl7:code/@displayName", namespaces=self.ns)
|
255 |
desc = desc_list[0] if desc_list else ""
|
256 |
code_list = med.xpath(".//hl7:manufacturedMaterial/hl7:code/@code", namespaces=self.ns)
|
|
|
464 |
|
465 |
def get_patient_ids(self) -> List[str]:
|
466 |
"""Return a list of all patient IDs."""
|
467 |
+
return [self.get_id() for _ in self.patients]
|
|