Skip to content

Commit

Permalink
refactor filters
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourpeas committed Feb 3, 2025
1 parent e64d42c commit 6ebd0d1
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions project/npda/views/visit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime

# Django imports
from django.apps import apps
from django.contrib import messages
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.messages.views import SuccessMessageMixin
Expand Down Expand Up @@ -63,21 +64,28 @@ def get_context_data(self, **kwargs):
context["submission"] = submission

try:
pdu = (
Transfer.objects.filter(
patient=patient, date_leaving_service__isnull=True
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
)
.first()
.paediatric_diabetes_unit
)
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
except:
# this patient has been transferred but not yet received at a new PDU
pdu = (
Transfer.objects.filter(patient=patient)
.order_by("-date_leaving_service")
Transfer.objects.filter(
patient=patient, date_leaving_service__isnull=True
)
.first()
.paediatric_diabetes_unit
)
Expand Down

0 comments on commit 6ebd0d1

Please sign in to comment.