Skip to content

Commit

Permalink
fix patient list filter to include only active cohorts
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourpeas committed Jun 12, 2024
1 parent 5a59b34 commit 354de39
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions project/npda/views/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down

0 comments on commit 354de39

Please sign in to comment.