Skip to content

Commit

Permalink
Add annotation and ordering to PatientViewSet
Browse files Browse the repository at this point in the history
queryset
  • Loading branch information
GokulramGHV committed Nov 16, 2023
1 parent fa5ba42 commit a9f7bd1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,24 @@ class PatientViewSet(
def get_queryset(self):
# filter_query = self.request.query_params.get("disease_status")
queryset = super().get_queryset()
queryset = queryset.annotate(
is_last_consultation_null=Case(
When(last_consultation__isnull=True, then=True),
default=False,
output_field=models.BooleanField(),
)
)
# if filter_query:
# disease_status = filter_query if filter_query.isdigit() else DiseaseStatusEnum[filter_query].value
# return queryset.filter(disease_status=disease_status)

# if self.action == "list":
# queryset = queryset.filter(is_active=self.request.GET.get("is_active", True))
queryset = queryset.order_by(
"-is_last_consultation_null",
"last_consultation",
"modified_date",
)
return queryset

def get_serializer_class(self):
Expand Down

0 comments on commit a9f7bd1

Please sign in to comment.