diff --git a/project/npda/kpi_class/kpis.py b/project/npda/kpi_class/kpis.py index b56f4240..25680015 100644 --- a/project/npda/kpi_class/kpis.py +++ b/project/npda/kpi_class/kpis.py @@ -3277,11 +3277,31 @@ def calculate_kpi_45_median_hba1c( ).values("patient__postcode", "hba1c", "patient__pk") # debugging - from pprint import pprint + from pprint import pprint, pformat + tmp_pts_data = defaultdict(list) for v in Visit.objects.all().values('visit_date', 'hba1c_date','patient__diagnosis_date', 'hba1c', 'patient__postcode'): - pprint(v) + tmp_pts_data[(v['patient__postcode'], v['patient__diagnosis_date'])].append({ + v['visit_date']: { + 'hba1c_date': v['hba1c_date'], + 'hba1c': v['hba1c'], + } + }) + for (pt_name, diagnosis_date), visit_data in tmp_pts_data.items(): + print(f'{pt_name=}, diagnosed on {diagnosis_date}') + pprint(visit_data) print() - + breakpoint() + # diagnosis_date = v['patient__diagnosis_date'] + # hba1c_date = v['hba1c_date'] + # print(f'{v["patient__postcode"]}') + # print(f"{v['patient__diagnosis_date']=} {v['hba1c_date']=}") + # if diagnosis_date and hba1c_date: + # print(f"Measurement taken {v['hba1c_date'] - v['patient__diagnosis_date']} days after diagnosis: {'excluded' if (hba1c_date - diagnosis_date).days < 90 else 'included'}") + # else: + # print(f"Taken after 90 days of diabetes diagnosis: False") + # print(f"{v['visit_date']=}") + # print(f"{v['hba1c']=}") + # print() # Group HbA1c values by patient ID into a list so can use # calculate_median method