From 7183b5c38e66e040dcdccefe49e7632fb9e53d64 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Tue, 30 Jul 2024 13:45:32 +0100 Subject: [PATCH] fix update patient details to include transfer fields, fix mixin also --- project/npda/views/mixins.py | 6 +++++- project/npda/views/patient.py | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/project/npda/views/mixins.py b/project/npda/views/mixins.py index af946498..0354cd1a 100644 --- a/project/npda/views/mixins.py +++ b/project/npda/views/mixins.py @@ -2,6 +2,7 @@ import logging +from django.apps import apps from django.conf import settings from django.core.exceptions import PermissionDenied from django.contrib.auth.mixins import AccessMixin @@ -121,6 +122,8 @@ def dispatch(self, request, *args, **kwargs): model = self.get_model().__name__ + Transfer = apps.get_model("npda", "Transfer") + # get PDU assigned to user who is trying to access a view user_pdu = request.user.organisation_employers.first().pz_code @@ -133,7 +136,8 @@ def dispatch(self, request, *args, **kwargs): elif model == "Patient": requested_patient = Patient.objects.get(pk=self.kwargs["pk"]) - requested_pdu = requested_patient.transfer.paediatric_diabetes_unit.pz_code + transfer = Transfer.objects.get(patient=requested_patient) + requested_pdu = transfer.paediatric_diabetes_unit.pz_code elif model == "Visit": requested_patient = Patient.objects.get(pk=self.kwargs["patient_id"]) diff --git a/project/npda/views/patient.py b/project/npda/views/patient.py index 61cdca94..b6482300 100644 --- a/project/npda/views/patient.py +++ b/project/npda/views/patient.py @@ -267,11 +267,16 @@ class PatientUpdateView( success_url = reverse_lazy("patients") def get_context_data(self, **kwargs): + PaediatricDiabetesUnit = apps.get_model("npda", "PaediatricDiabetesUnit") + Transfer = apps.get_model("npda", "Transfer") patient = Patient.objects.get(pk=self.kwargs["pk"]) - pz_code = patient.transfer.pz_code - ods_code = patient.transfer.ods_code + + transfer = Transfer.objects.get(patient=patient) + context = super().get_context_data(**kwargs) - context["title"] = f"Edit Child Details in {ods_code}({pz_code})" + context["title"] = ( + f"Edit Child Details in {transfer.paediatric_diabetes_unit.ods_code}({transfer.paediatric_diabetes_unit.pz_code})" + ) context["button_title"] = "Edit Child Details" context["form_method"] = "update" context["patient_id"] = self.kwargs["pk"]