diff --git a/care/facility/api/viewsets/patient.py b/care/facility/api/viewsets/patient.py index e329a597df..0a18f48909 100644 --- a/care/facility/api/viewsets/patient.py +++ b/care/facility/api/viewsets/patient.py @@ -301,6 +301,7 @@ def filter_queryset(self, request, queryset, view): q_filters = Q(facility__id__in=allowed_facilities) if view.action == "retrieve": q_filters |= Q(consultations__facility__id__in=allowed_facilities) + queryset = queryset.distinct("id") q_filters |= Q(last_consultation__assigned_to=request.user) q_filters |= Q(assigned_to=request.user) queryset = queryset.filter(q_filters) @@ -340,7 +341,7 @@ def filter_queryset(self, request, queryset, view): ) ).order_by(ordering) - return queryset.distinct(ordering.lstrip("-") if ordering else "id") + return queryset @extend_schema_view(history=extend_schema(tags=["patient"]))