From e4f57a8af4b387e4d840c32966156249e4fc2841 Mon Sep 17 00:00:00 2001 From: Michael Barton Date: Sat, 22 Feb 2025 11:51:25 +0000 Subject: [PATCH] Fix crash viewing visit list for patients who have transferred --- project/npda/views/visit.py | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/project/npda/views/visit.py b/project/npda/views/visit.py index e4d3cb0a..681d0172 100644 --- a/project/npda/views/visit.py +++ b/project/npda/views/visit.py @@ -66,29 +66,8 @@ def get_context_data(self, **kwargs): context["patient"] = patient context["submission"] = submission - if patient.is_in_transfer_in_the_last_year(): - pz_code = ( - Transfer.objects.filter( - patient=patient, - ) - .order_by("-date_leaving_service") - .first() - .previous_pz_code - ) - PaediatricDiabetesUnit = apps.get_model("npda", "PaediatricDiabetesUnit") - pdu = PaediatricDiabetesUnit.objects.get(pz_code=pz_code) - # get the PDU for this patient - this is the PDU that the patient is currently under. - # If the patient has left the PDU, the date_leaving_service will be set and it will be possible to view KPIs for the PDU up until transfer, - # if this happened during the audit period. This is TODO - else: - # this patient has been transferred but not yet received at a new PDU - pdu = ( - Transfer.objects.filter( - patient=patient, date_leaving_service__isnull=True - ) - .first() - .paediatric_diabetes_unit - ) + # If the patient has left the PDU, they may appear in another one but we record that as a separate Patient instance + pdu = Transfer.objects.get(patient=patient).paediatric_diabetes_unit calculate_kpis = CalculateKPIS( calculation_date=datetime.date.today(), return_pt_querysets=False