Skip to content

Commit

Permalink
Sort "No Consultation Filed" patients to the top of Patient List page (
Browse files Browse the repository at this point in the history
…#1718)

* Add annotation and ordering to PatientViewSet
queryset

* Refactor PatientViewSet queryset annotation

* cleanup

---------

Co-authored-by: Aakash Singh <[email protected]>
Co-authored-by: Vignesh Hari <[email protected]>
  • Loading branch information
3 people authored Apr 22, 2024
1 parent 2c023e1 commit 164351d
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,28 @@ class PatientViewSet(
CSV_EXPORT_LIMIT = 7

def get_queryset(self):
# filter_query = self.request.query_params.get("disease_status")
queryset = super().get_queryset()
# 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 = super().get_queryset().order_by("modified_date")

if self.action == "list":
queryset = queryset.annotate(
no_consultation_filed=Case(
When(
Q(last_consultation__isnull=True)
| ~Q(last_consultation__facility__id=F("facility__id"))
| (
Q(last_consultation__discharge_date__isnull=False)
& Q(is_active=True)
),
then=True,
),
default=False,
output_field=models.BooleanField(),
)
).order_by(
"-no_consultation_filed",
"modified_date",
)

return queryset

def get_serializer_class(self):
Expand Down

0 comments on commit 164351d

Please sign in to comment.