diff --git a/src/cases/service/case_service.py b/src/cases/service/case_service.py index 3f0f4c0..23a4855 100644 --- a/src/cases/service/case_service.py +++ b/src/cases/service/case_service.py @@ -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), ) ) @@ -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"))