Skip to content

Commit

Permalink
Add medicine filter to prescriptions (#2068)
Browse files Browse the repository at this point in the history
* Log Prescriptions

* pass medicine object instead of just id

* refactor

* add tests

* update tests

---------

Co-authored-by: Vignesh Hari <[email protected]>
  • Loading branch information
Pranshu1902 and vigneshhari authored May 8, 2024
1 parent 8481175 commit 0bf4d1d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions care/facility/api/viewsets/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class ConsultationPrescriptionFilter(filters.FilterSet):
dosage_type = MultiSelectFilter()
prescription_type = CareChoiceFilter(choice_dict=inverse_prescription_type)
discontinued = filters.BooleanFilter()
medicine = filters.UUIDFilter(field_name="medicine__external_id")


class ConsultationPrescriptionViewSet(
Expand Down
36 changes: 36 additions & 0 deletions care/facility/tests/test_prescriptions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def setUp(self) -> None:
super().setUp()
self.consultation = self.create_consultation(self.patient, self.facility)
self.medicine = MedibaseMedicine.objects.first()
self.medicine2 = MedibaseMedicine.objects.all()[1]

self.normal_prescription_data = {
"medicine": self.medicine.external_id,
Expand All @@ -29,6 +30,14 @@ def setUp(self) -> None:
"dosage_type": "REGULAR",
}

self.normal_prescription_data2 = {
"medicine": self.medicine2.external_id,
"prescription_type": "REGULAR",
"base_dosage": "1 mg",
"frequency": "OD",
"dosage_type": "REGULAR",
}

def test_create_normal_prescription(self):
response = self.client.post(
f"/api/v1/consultation/{self.consultation.external_id}/prescriptions/",
Expand Down Expand Up @@ -113,3 +122,30 @@ def test_create_prn_prescription(self):
prn_prescription_data,
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

def test_medicine_filter_for_prescription(self):
# post 2 prescriptions with different medicines
self.client.post(
f"/api/v1/consultation/{self.consultation.external_id}/prescriptions/",
self.normal_prescription_data,
)
self.client.post(
f"/api/v1/consultation/{self.consultation.external_id}/prescriptions/",
self.normal_prescription_data2,
)

# get all prescriptions without medicine filter
response = self.client.get(
f"/api/v1/consultation/{self.consultation.external_id}/prescriptions/",
)
self.assertEqual(response.data["count"], 2)

# get all prescriptions with medicine filter
response = self.client.get(
f"/api/v1/consultation/{self.consultation.external_id}/prescriptions/?medicine={self.medicine.external_id}",
)

for prescription in response.data["results"]:
self.assertEqual(
prescription["medicine_object"]["name"], self.medicine.name
)

0 comments on commit 0bf4d1d

Please sign in to comment.