From 467a270cdaa3545c1a3382377c30bce8638aeb4f Mon Sep 17 00:00:00 2001 From: Michael Barton Date: Mon, 10 Feb 2025 21:54:16 +0000 Subject: [PATCH 1/2] Fix ethnicity treemap when no data uploaded --- .../components/cards/ethnicity_card.html | 22 ++++++++++++------- project/npda/views/dashboard/dashboard.py | 3 +++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/project/npda/templates/dashboard/components/cards/ethnicity_card.html b/project/npda/templates/dashboard/components/cards/ethnicity_card.html index ec35fe46..f2860375 100644 --- a/project/npda/templates/dashboard/components/cards/ethnicity_card.html +++ b/project/npda/templates/dashboard/components/cards/ethnicity_card.html @@ -3,15 +3,21 @@ Ethnicity {% endblock card_title%} {% block card_body %} -
+{% if charts.pt_ethnicity_tree_map_data.no_eligible_patients %} +
+ No eligible patients. +
+{% else %} +
-
-
+
+
+{% endif %} {% endblock %} diff --git a/project/npda/views/dashboard/dashboard.py b/project/npda/views/dashboard/dashboard.py index b006f2dd..7b31af21 100644 --- a/project/npda/views/dashboard/dashboard.py +++ b/project/npda/views/dashboard/dashboard.py @@ -325,6 +325,7 @@ def dashboard(request): }, "pt_ethnicity_tree_map_data": json.dumps( { + "no_eligible_patients": not pt_ethnicity_value_counts, "data": pt_ethnicity_value_counts, "parent_color_map": constants.ethnicities.ETHNICITY_PARENT_COLOR_MAP, "child_parent_map": constants.ethnicities.ETHNICITY_CHILD_PARENT_MAP, @@ -354,4 +355,6 @@ def dashboard(request): "aggregation_level": "pdu", } + print(f"!! {context['charts']['pt_ethnicity_tree_map_data']}") + return render(request, template_name=template, context=context) From 0157ba6236aa4d079833055e5dea80f2859f0b74 Mon Sep 17 00:00:00 2001 From: Michael Barton Date: Mon, 10 Feb 2025 21:54:35 +0000 Subject: [PATCH 2/2] Fix treemap client error if sex/ethnicity not set --- project/npda/views/dashboard/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/npda/views/dashboard/helpers.py b/project/npda/views/dashboard/helpers.py index 7b5df4d3..4eb6e813 100644 --- a/project/npda/views/dashboard/helpers.py +++ b/project/npda/views/dashboard/helpers.py @@ -722,9 +722,9 @@ def get_pt_demographic_value_counts( "sex", "ethnicity", "index_of_multiple_deprivation_quintile" ) sex_map = dict(SEX_TYPE) - sex_counts = Counter(sex_map.get(item["sex"]) for item in all_values) + sex_counts = Counter(sex_map[item["sex"]] for item in all_values if item["sex"] in sex_map) ethnicity_map = dict(ETHNICITIES) - ethnicity_counts = Counter(ethnicity_map.get(item["ethnicity"]) for item in all_values) + ethnicity_counts = Counter(ethnicity_map[item["ethnicity"]] for item in all_values if item["ethnicity"] in ethnicity_map) imd_map = { 1: "1st Quintile", 2: "2nd Quintile",