From 354de3958a8d7a293430220bcb5b59864ea4f618 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Wed, 12 Jun 2024 23:15:49 +0100 Subject: [PATCH] fix patient list filter to include only active cohorts --- project/npda/views/patient.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/project/npda/views/patient.py b/project/npda/views/patient.py index f6cacbf2..1aaa2a8e 100644 --- a/project/npda/views/patient.py +++ b/project/npda/views/patient.py @@ -83,9 +83,9 @@ def get_context_data(self, **kwargs): "pz_code", None ) total_valid_patients = ( - Patient.objects.all() + Patient.objects.filter(audit_cohorts__submission_active=True) .annotate( - visit_error_count=Count(Case(When(visit__is_valid=False, then=1))) + visit_error_count=Count(Case(When(visit__is_valid=False, then=1))), ) .order_by("is_valid", "visit_error_count", "pk") .filter(is_valid=True, visit_error_count__lt=1) @@ -95,7 +95,8 @@ def get_context_data(self, **kwargs): context["ods_code"] = self.request.user.organisation_employer context["total_valid_patients"] = total_valid_patients context["total_invalid_patients"] = ( - Patient.objects.all().count() - total_valid_patients + Patient.objects.filter(audit_cohorts__submission_active=True).count() + - total_valid_patients ) context["index_of_first_invalid_patient"] = total_valid_patients + 1 context["organisation_choices"] = self.request.session.get(