Skip to content

Commit

Permalink
fix update patient details to include transfer fields, fix mixin also
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourpeas committed Jul 30, 2024
1 parent 256e2d0 commit 7183b5c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion project/npda/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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"])
Expand Down
11 changes: 8 additions & 3 deletions project/npda/views/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 7183b5c

Please sign in to comment.