Skip to content

Commit

Permalink
Adds type filter to Medibase search (#1566)
Browse files Browse the repository at this point in the history
add `type` filter for medibase

Co-authored-by: Vignesh Hari <[email protected]>
  • Loading branch information
rithviknishad and vigneshhari authored Aug 31, 2023
1 parent 5276c8a commit 6390735
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions care/facility/api/viewsets/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,18 @@ def list(self, request):
from care.facility.static_data.medibase import MedibaseMedicineTable

queryset = MedibaseMedicineTable
try:
limit = min(int(request.query_params.get("limit", 30)), 100)
except ValueError:
limit = 30

if type := request.query_params.get("type"):
queryset = [x for x in queryset if x[2] == type]

if query := request.query_params.get("query"):
query = query.strip().lower()
queryset = [x for x in queryset if query in f"{x[1]} {x[3]} {x[4]}".lower()]
queryset = self.sort(query, queryset)

try:
limit = min(int(request.query_params.get("limit", 30)), 100)
except ValueError:
limit = 30

return Response(self.serailize_data(queryset[:limit]))

0 comments on commit 6390735

Please sign in to comment.