From 900da607cce7ce95c7bd0f452099284213d04401 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Wed, 25 Dec 2024 23:28:00 +0530 Subject: [PATCH 1/5] add date and resource filter for appointments viewset --- care/emr/api/viewsets/scheduling/booking.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/care/emr/api/viewsets/scheduling/booking.py b/care/emr/api/viewsets/scheduling/booking.py index 08dba5f1a1..b09d4f0388 100644 --- a/care/emr/api/viewsets/scheduling/booking.py +++ b/care/emr/api/viewsets/scheduling/booking.py @@ -1,4 +1,4 @@ -from django_filters import CharFilter, FilterSet, UUIDFilter +from django_filters import CharFilter, DateFilter, FilterSet, UUIDFilter from django_filters.rest_framework import DjangoFilterBackend from rest_framework.decorators import action from rest_framework.response import Response @@ -21,7 +21,9 @@ class TokenBookingFilters(FilterSet): status = CharFilter(field_name="status") + date = DateFilter(field_name="token_slot__start_datetime__date") slot = UUIDFilter(field_name="token_slot__external_id") + resource = UUIDFilter(field_name="token_slot__resource__resource__external_id") patient = UUIDFilter(field_name="patient__external_id") From 0895ed81089672bfb45879e6b6d295c6f5d88b6e Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 26 Dec 2024 16:04:24 +0530 Subject: [PATCH 2/5] serialize address ids --- care/emr/resources/patient/otp_based_flow.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/care/emr/resources/patient/otp_based_flow.py b/care/emr/resources/patient/otp_based_flow.py index 78e4e773bb..e388b88872 100644 --- a/care/emr/resources/patient/otp_based_flow.py +++ b/care/emr/resources/patient/otp_based_flow.py @@ -28,20 +28,20 @@ class PatientOTPReadSpec(PatientOTPBaseSpec): emergency_phone_number: str address: str pincode: int - state: str - district: str - local_body: str - ward: str + state_id: str + district_id: str + local_body_id: str + ward_id: str date_of_birth: datetime.date year_of_birth: int @classmethod def perform_extra_serialization(cls, mapping, obj): mapping["id"] = obj.external_id - mapping["state"] = obj.state.name if obj.state else None - mapping["district"] = obj.district.name if obj.district else None - mapping["local_body"] = obj.local_body.name if obj.local_body else None - mapping["ward"] = obj.ward.name if obj.ward else None + mapping["state_id"] = obj.state and obj.state.id + mapping["district_id"] = obj.district and obj.district.id + mapping["local_body_id"] = obj.local_body and obj.local_body.id + mapping["ward_id"] = obj.ward and obj.ward.id class PatientOTPWriteSpec(PatientOTPBaseSpec): From 9ac775692d1314364e64859b7f5fa2a19d9252f0 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 26 Dec 2024 16:07:57 +0530 Subject: [PATCH 3/5] Revert "serialize address ids" This reverts commit 0895ed81089672bfb45879e6b6d295c6f5d88b6e. --- care/emr/resources/patient/otp_based_flow.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/care/emr/resources/patient/otp_based_flow.py b/care/emr/resources/patient/otp_based_flow.py index e388b88872..78e4e773bb 100644 --- a/care/emr/resources/patient/otp_based_flow.py +++ b/care/emr/resources/patient/otp_based_flow.py @@ -28,20 +28,20 @@ class PatientOTPReadSpec(PatientOTPBaseSpec): emergency_phone_number: str address: str pincode: int - state_id: str - district_id: str - local_body_id: str - ward_id: str + state: str + district: str + local_body: str + ward: str date_of_birth: datetime.date year_of_birth: int @classmethod def perform_extra_serialization(cls, mapping, obj): mapping["id"] = obj.external_id - mapping["state_id"] = obj.state and obj.state.id - mapping["district_id"] = obj.district and obj.district.id - mapping["local_body_id"] = obj.local_body and obj.local_body.id - mapping["ward_id"] = obj.ward and obj.ward.id + mapping["state"] = obj.state.name if obj.state else None + mapping["district"] = obj.district.name if obj.district else None + mapping["local_body"] = obj.local_body.name if obj.local_body else None + mapping["ward"] = obj.ward.name if obj.ward else None class PatientOTPWriteSpec(PatientOTPBaseSpec): From a90aa7085dc6943a01e98855450a869a888fa420 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 2 Jan 2025 17:00:49 +0530 Subject: [PATCH 4/5] fixes available doctors not working --- care/emr/api/viewsets/scheduling/booking.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/care/emr/api/viewsets/scheduling/booking.py b/care/emr/api/viewsets/scheduling/booking.py index b09d4f0388..e928af98a0 100644 --- a/care/emr/api/viewsets/scheduling/booking.py +++ b/care/emr/api/viewsets/scheduling/booking.py @@ -16,16 +16,24 @@ TokenBookingUpdateSpec, ) from care.emr.resources.user.spec import UserSpec -from care.facility.models import Facility, FacilityUser +from care.facility.models import Facility, FacilityOrganizationUser class TokenBookingFilters(FilterSet): status = CharFilter(field_name="status") date = DateFilter(field_name="token_slot__start_datetime__date") slot = UUIDFilter(field_name="token_slot__external_id") - resource = UUIDFilter(field_name="token_slot__resource__resource__external_id") + resource = UUIDFilter(method="filter_by_resource") patient = UUIDFilter(field_name="patient__external_id") + def filter_by_resource(self, queryset, name, value): + resource = SchedulableUserResource.objects.filter( + resource__external_id=value + ).first() + if not resource: + return queryset.none() + return queryset.filter(token_slot__resource=resource) + class TokenBookingViewSet( EMRRetrieveMixin, EMRUpdateMixin, EMRListMixin, EMRDeleteMixin, EMRBaseViewSet @@ -60,11 +68,11 @@ def get_queryset(self): @action(detail=False, methods=["GET"]) def available_doctors(self, request, *args, **kwargs): facility = Facility.objects.get(external_id=self.kwargs["facility_external_id"]) - facility_users = FacilityUser.objects.filter( + facility_users = FacilityOrganizationUser.objects.filter( + organization__facility=facility, user_id__in=SchedulableUserResource.objects.filter( facility=facility ).values("resource_id"), - facility=facility, ) return Response( From bc08761630c775a3b2a16e6b196711e988697fa5 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 2 Jan 2025 18:06:28 +0530 Subject: [PATCH 5/5] prevent filtering queryset if filter not applied --- care/emr/api/viewsets/scheduling/booking.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/care/emr/api/viewsets/scheduling/booking.py b/care/emr/api/viewsets/scheduling/booking.py index e928af98a0..c86fa53d2a 100644 --- a/care/emr/api/viewsets/scheduling/booking.py +++ b/care/emr/api/viewsets/scheduling/booking.py @@ -27,6 +27,8 @@ class TokenBookingFilters(FilterSet): patient = UUIDFilter(field_name="patient__external_id") def filter_by_resource(self, queryset, name, value): + if not value: + return queryset resource = SchedulableUserResource.objects.filter( resource__external_id=value ).first()