Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add medicine filter to prescriptions #2068

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
Loading