Skip to content

Commit b19cf9d

Browse files
authored
Merge pull request #71 from Paper-Chart-Extraction-Project/main
Update for some commits to main.
2 parents f5ff2ce + 5ac49ef commit b19cf9d

3 files changed

Lines changed: 27 additions & 43 deletions

File tree

src/ChartExtractor/extraction/preoperative_postoperative_digit_boxes.py

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -233,35 +233,31 @@ def extract_vitals(
233233
vital_values: Dict[str, int] = get_relevant_boxes(
234234
number_detections, preop_or_pacu, im_width, im_height
235235
)
236-
vital_dict: Dict[str, int] = dict()
236+
vital_dict: Dict[str, str] = dict()
237237

238238
def get_whole_value_from_vital_values(
239239
vital: str, digit_strs: List[str] = ["hundreds", "tens", "ones"]
240-
) -> Dict[str, int]:
240+
) -> Optional[str]:
241241
if any(
242242
[
243243
f"{preop_or_pacu}_{vital}_{place}" in vital_values.keys()
244244
for place in digit_strs
245245
]
246246
):
247-
return {
248-
f"{preop_or_pacu}_{vital}": "".join(
249-
[
250-
get_category_or_space(
251-
vital_values.get(f"{preop_or_pacu}_{vital}_{place}")
252-
)
253-
for place in digit_strs
254-
]
255-
).strip()
256-
}
257-
else:
258-
return dict()
247+
return "".join(
248+
[
249+
get_category_or_space(
250+
vital_values.get(f"{preop_or_pacu}_{vital}_{place}")
251+
)
252+
for place in digit_strs
253+
]
254+
).strip()
255+
256+
for vital_name in ["sys", "dia", "hr", "rr", "ox"]:
257+
whole_value: Optional[str] = get_whole_value_from_vital_values(vital_name)
258+
if whole_value:
259+
vital_dict[vital_name] = whole_value
259260

260-
vital_dict.update(get_whole_value_from_vital_values("sys"))
261-
vital_dict.update(get_whole_value_from_vital_values("dia"))
262-
vital_dict.update(get_whole_value_from_vital_values("hr"))
263-
vital_dict.update(get_whole_value_from_vital_values("rr"))
264-
vital_dict.update(get_whole_value_from_vital_values("ox"))
265261
return vital_dict
266262

267263

@@ -359,7 +355,7 @@ def extract_aldrete_score(
359355
number_detections: List[Detection],
360356
im_width: int,
361357
im_height: int,
362-
) -> Dict[str, int]:
358+
) -> str:
363359
"""Extracts the aldrete score from the number detections.
364360
365361
Args:
@@ -378,7 +374,7 @@ def extract_aldrete_score(
378374
)
379375
tens: str = get_category_or_space(aldrete_values.get("aldrete_tens"))
380376
ones: str = get_category_or_space(aldrete_values.get("aldrete_ones"))
381-
return {"aldrete_score": f"{tens}{ones}".strip()}
377+
return f"{tens}{ones}".strip()
382378

383379

384380
def extract_preop_postop_digit_data(
@@ -400,25 +396,13 @@ def extract_preop_postop_digit_data(
400396
A dictionary with all the preoperative and postoperative data.
401397
"""
402398
data: Dict[str, str] = dict()
403-
data.update(
404-
{"timing": extract_time_of_assessment(number_detections, im_width, im_height)}
405-
)
406-
data.update({"demographics": extract_age(number_detections, im_width, im_height)})
407-
data.update(
408-
{"demographics": extract_height(number_detections, im_width, im_height)}
409-
)
410-
data.update(
411-
{"demographics": extract_weight(number_detections, im_width, im_height)}
412-
)
413-
data.update(
414-
{"vitals": extract_vitals(number_detections, "preop", im_width, im_height)}
415-
)
416-
data.update(
417-
{"vitals": extract_vitals(number_detections, "pacu", im_width, im_height)}
418-
)
419-
data.update(
420-
{"lab_values": extract_lab_results(number_detections, im_width, im_height)}
421-
)
422-
data.update(extract_aldrete_score(number_detections, im_width, im_height))
399+
data["timing"] = extract_time_of_assessment(number_detections, im_width, im_height)
400+
data["age"] = extract_age(number_detections, im_width, im_height)
401+
data["height"] = extract_height(number_detections, im_width, im_height)
402+
data["weight"] = extract_weight(number_detections, im_width, im_height)
403+
data["preop_vitals"] = extract_vitals(number_detections, "preop", im_width, im_height)
404+
data["pacu_vitals"] = extract_vitals(number_detections, "pacu", im_width, im_height)
405+
data["lab_values"] = extract_lab_results(number_detections, im_width, im_height)
406+
data["aldrete_score"] = extract_aldrete_score(number_detections, im_width, im_height)
423407

424408
return data

src/ChartExtractor/object_detection_models/onnx_yolov11_detection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __call__(
128128
Returns:
129129
A list of detections for each image.
130130
"""
131-
if not model_is_loaded:
131+
if not self.model_is_loaded:
132132
self.load_model()
133133
if not isinstance(images, list):
134134
images = [images]

src/ChartExtractor/object_detection_models/onnx_yolov11_pose_single.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def __call__(
133133
Returns:
134134
A list of detections for each image.
135135
"""
136-
if not model_is_loaded:
136+
if not self.model_is_loaded:
137137
self.load_model()
138138
if not isinstance(images, list):
139139
images = [images]

0 commit comments

Comments
 (0)