Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:ohcnetwork/care into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshhari committed Jan 2, 2025
2 parents ccc05a8 + 0e288c7 commit 46a8f7a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions care/emr/api/viewsets/scheduling/booking.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,14 +16,26 @@
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(method="filter_by_resource")
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()
if not resource:
return queryset.none()
return queryset.filter(token_slot__resource=resource)


class TokenBookingViewSet(
EMRRetrieveMixin, EMRUpdateMixin, EMRListMixin, EMRDeleteMixin, EMRBaseViewSet
Expand Down Expand Up @@ -58,11 +70,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(
Expand Down

0 comments on commit 46a8f7a

Please sign in to comment.