Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion src/cases/service/case_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,15 @@ def get_nodes_of_measurement(self, case_id, title_config):
children_measurements, lambda m: m.measurement_concept_id
)
for concept_id, rows in measurements_by_concept.items():
# Special handling for BMI - change title from 'centile' to 'range'
if concept_id == 40490382:
concept_name = "BMI (body mass index) range"
else:
concept_name = self.get_concept_name(concept_id)

parent_node.add_node(
TreeNode(
self.get_concept_name(concept_id),
concept_name,
get_value_of_rows(rows, self.get_value_of_measurement),
)
)
Expand Down Expand Up @@ -379,6 +385,49 @@ def get_case_review(self, case_config_id): # pragma: no cover
"weight": merged["top"],
}
)

# --- 4b) Prune PHYSICAL EXAMINATION per path_config ---
for top in case_details:
if top.key != "PHYSICAL EXAMINATION":
continue
for child in top.values:
pk = f"PHYSICAL EXAMINATION.{child.key}"
if pk not in parent_to_entries:
# If this section is not in path_config, remove all values
child.values = []
continue

entries = parent_to_entries[pk]
keep = {e["leaf"] for e in entries}

# Filter child.values - handle both string lists and TreeNode lists
if child.values and isinstance(child.values[0], TreeNode):
# child.values is a list of TreeNode objects
child.values = [v for v in child.values if v.key in keep]
else:
# child.values is a list of strings
child.values = [v for v in child.values if v in keep]

# Merge style directives
merged: dict = {}
for e in entries:
s = e["style"]
if "collapse" in s:
merged["collapse"] = not s["collapse"]
if "highlight" in s:
merged["highlight"] = s["highlight"]
if "top" in s:
merged["top"] = max(merged.get("top", -1), s["top"])

child.style = merged
if merged.get("top") is not None:
important_infos.append(
{
"key": child.key,
"values": child.values,
"weight": merged["top"],
}
)

# sort and wrap into TreeNodes
important_infos.sort(key=itemgetter("weight"))
Expand Down
Loading