Skip to content

Commit

Permalink
Add django filter for patient review missed (#1938)
Browse files Browse the repository at this point in the history
* Add django filter for patient review missed

* re-commit

* Update care/facility/tests/test_patient_api.py

* fix lint issues

* fix test cases

* handle review_missed = False

---------

Co-authored-by: Aakash Singh <[email protected]>
  • Loading branch information
jainvedant392 and sainak authored Apr 9, 2024
1 parent 76a72d8 commit da83422
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)
from django.db.models.functions import Coalesce, ExtractDay, Now
from django.db.models.query import QuerySet
from django.utils import timezone
from django_filters import rest_framework as filters
from djqscsv import render_to_csv_response
from drf_spectacular.utils import extend_schema, extend_schema_view
Expand Down Expand Up @@ -237,6 +238,20 @@ def filter_bed_not_null(self, queryset, name, value):
last_consultation__discharge_date__isnull=True,
)

def filter_by_review_missed(self, queryset, name, value):
if isinstance(value, bool):
if value:
queryset = queryset.filter(
(Q(review_time__isnull=False) & Q(review_time__lt=timezone.now()))
)
else:
queryset = queryset.filter(
Q(review_time__isnull=True) | Q(review_time__gt=timezone.now())
)
return queryset

review_missed = filters.BooleanFilter(method="filter_by_review_missed")

# Filter consultations by ICD-11 Diagnoses
diagnoses = MultiSelectFilter(method="filter_by_diagnoses")
diagnoses_unconfirmed = MultiSelectFilter(method="filter_by_diagnoses")
Expand Down
15 changes: 15 additions & 0 deletions care/facility/tests/test_patient_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,21 @@ def test_filter_by_diagnoses_confirmed(self):
)
self.assertNotContains(res, self.patient.external_id)

def test_filter_by_review_missed(self):
self.client.force_authenticate(user=self.user)
res = self.client.get(self.get_base_url() + "?review_missed=true")
self.assertEqual(res.status_code, status.HTTP_200_OK)
for patient in res.json()["results"]:
self.assertLess(patient["review_time"], now())

res = self.client.get(self.get_base_url() + "?review_missed=false")
self.assertEqual(res.status_code, status.HTTP_200_OK)
for patient in res.json()["results"]:
if patient["review_time"]:
self.assertGreaterEqual(patient["review_time"], now())
else:
self.assertIsNone(patient["review_time"])


class PatientTransferTestCase(TestUtils, APITestCase):
@classmethod
Expand Down

0 comments on commit da83422

Please sign in to comment.