From 0e8db72c5c236796c264bf30edfd0fa0baae4141 Mon Sep 17 00:00:00 2001 From: Shivank Kacker Date: Fri, 17 May 2024 06:25:29 +0000 Subject: [PATCH 1/2] Removed Discharge Filters, reused patient filters --- care/facility/api/viewsets/patient.py | 66 +++++++-------------------- 1 file changed, 16 insertions(+), 50 deletions(-) diff --git a/care/facility/api/viewsets/patient.py b/care/facility/api/viewsets/patient.py index 0b8e9000a8..b64d6bd42f 100644 --- a/care/facility/api/viewsets/patient.py +++ b/care/facility/api/viewsets/patient.py @@ -602,55 +602,6 @@ def transfer(self, request, *args, **kwargs): return Response(data=response_serializer.data, status=status.HTTP_200_OK) -class FacilityDischargedPatientFilterSet(filters.FilterSet): - disease_status = CareChoiceFilter(choice_dict=DISEASE_STATUS_DICT) - phone_number = filters.CharFilter(field_name="phone_number") - emergency_phone_number = filters.CharFilter(field_name="emergency_phone_number") - name = filters.CharFilter(field_name="name", lookup_expr="icontains") - gender = filters.NumberFilter(field_name="gender") - age = filters.NumberFilter(field_name="age") - age_min = filters.NumberFilter(field_name="age", lookup_expr="gte") - age_max = filters.NumberFilter(field_name="age", lookup_expr="lte") - created_date = filters.DateFromToRangeFilter(field_name="created_date") - modified_date = filters.DateFromToRangeFilter(field_name="modified_date") - srf_id = filters.CharFilter(field_name="srf_id") - is_declared_positive = filters.BooleanFilter(field_name="is_declared_positive") - date_declared_positive = filters.DateFromToRangeFilter( - field_name="date_declared_positive" - ) - date_of_result = filters.DateFromToRangeFilter(field_name="date_of_result") - last_vaccinated_date = filters.DateFromToRangeFilter( - field_name="last_vaccinated_date" - ) - is_antenatal = filters.BooleanFilter(field_name="is_antenatal") - last_menstruation_start_date = filters.DateFromToRangeFilter( - field_name="last_menstruation_start_date" - ) - date_of_delivery = filters.DateFromToRangeFilter(field_name="date_of_delivery") - # Location Based Filtering - district = filters.NumberFilter(field_name="district__id") - district_name = filters.CharFilter( - field_name="district__name", lookup_expr="icontains" - ) - local_body = filters.NumberFilter(field_name="local_body__id") - local_body_name = filters.CharFilter( - field_name="local_body__name", lookup_expr="icontains" - ) - state = filters.NumberFilter(field_name="state__id") - state_name = filters.CharFilter(field_name="state__name", lookup_expr="icontains") - # Vaccination Filters - covin_id = filters.CharFilter(field_name="covin_id") - is_vaccinated = filters.BooleanFilter(field_name="is_vaccinated") - number_of_doses = filters.NumberFilter(field_name="number_of_doses") - last_consultation__new_discharge_reason = filters.ChoiceFilter( - field_name="last_consultation__new_discharge_reason", - choices=NewDischargeReasonEnum.choices, - ) - last_consultation_discharge_date = filters.DateFromToRangeFilter( - field_name="last_consultation__discharge_date" - ) - - @extend_schema_view(tags=["patient"]) class FacilityDischargedPatientViewSet(GenericViewSet, mixins.ListModelMixin): permission_classes = (IsAuthenticated, DRYPermissions) @@ -661,7 +612,7 @@ class FacilityDischargedPatientViewSet(GenericViewSet, mixins.ListModelMixin): rest_framework_filters.OrderingFilter, PatientCustomOrderingFilter, ) - filterset_class = FacilityDischargedPatientFilterSet + filterset_class = PatientFilterSet queryset = ( PatientRegistration.objects.select_related( "local_body", @@ -714,11 +665,26 @@ class FacilityDischargedPatientViewSet(GenericViewSet, mixins.ListModelMixin): ) ) + date_range_fields = [ + "created_date", + "modified_date", + "date_declared_positive", + "date_of_result", + "last_vaccinated_date", + "last_consultation_encounter_date", + "last_consultation_discharge_date", + "last_consultation_symptoms_onset_date", + ] + ordering_fields = [ + "facility__name", "id", "name", "created_date", "modified_date", + "review_time", + "last_consultation__current_bed__bed__name", + "date_declared_positive", ] def get_queryset(self) -> QuerySet: From 584ca232ba96a044658150267d5f433e5220e2ec Mon Sep 17 00:00:00 2001 From: Shivank Kacker Date: Tue, 21 May 2024 10:05:19 +0530 Subject: [PATCH 2/2] Update patient.py --- care/facility/api/viewsets/patient.py | 1 - 1 file changed, 1 deletion(-) diff --git a/care/facility/api/viewsets/patient.py b/care/facility/api/viewsets/patient.py index b64d6bd42f..a79360d76c 100644 --- a/care/facility/api/viewsets/patient.py +++ b/care/facility/api/viewsets/patient.py @@ -677,7 +677,6 @@ class FacilityDischargedPatientViewSet(GenericViewSet, mixins.ListModelMixin): ] ordering_fields = [ - "facility__name", "id", "name", "created_date",