From b45d8d0296c47c448831d120b39f757114542f7f Mon Sep 17 00:00:00 2001 From: Prafful Date: Tue, 9 Apr 2024 11:35:24 +0530 Subject: [PATCH] added tests for ambulance endpoints --- care/facility/tests/test_patient_api.py | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/care/facility/tests/test_patient_api.py b/care/facility/tests/test_patient_api.py index c3621e66eb..3de511ddd3 100644 --- a/care/facility/tests/test_patient_api.py +++ b/care/facility/tests/test_patient_api.py @@ -444,6 +444,9 @@ def setUpTestData(cls): cls.patient.save() def test_patient_transfer(self): + # test transfer of patient to a outside facility with allow_transfer set to "True" + # test transfer patient with dob + self.client.force_authenticate(user=self.super_user) response = self.client.post( f"/api/v1/patient/{self.patient.external_id}/transfer/", @@ -489,6 +492,8 @@ def test_transfer_with_active_consultation_same_facility(self): def test_transfer_disallowed_by_facility(self): # Set the patient's facility to disallow transfers + # Also test transfer of patient with live consultation to different facility with allow_transfer="False" + self.patient.allow_transfer = False self.patient.save() @@ -505,3 +510,39 @@ def test_transfer_disallowed_by_facility(self): response.data["Patient"], "Patient transfer cannot be completed because the source facility does not permit it", ) + + def test_transfer_within_facility(self): + self.client.force_authenticate(user=self.super_user) + response = self.client.post( + f"/api/v1/patient/{self.patient.external_id}/transfer/", + { + "date_of_birth": "1992-04-01", + "facility": self.facility.external_id, + }, + ) + self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE) + self.assertEqual( + response.data["Patient"], + "Patient transfer cannot be completed because the patient has an active consultation in the same facility", + ) + + def test_transfer_without_dob(self): + self.client.force_authenticate(user=self.super_user) + response = self.client.post( + f"/api/v1/patient/{self.patient.external_id}/transfer/", + { + "age": "32", + "facility": self.destination_facility.external_id, + }, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + self.patient.refresh_from_db() + self.consultation.refresh_from_db() + + self.assertEqual(self.patient.facility, self.destination_facility) + + self.assertEqual( + self.consultation.new_discharge_reason, NewDischargeReasonEnum.REFERRED + ) + self.assertIsNotNone(self.consultation.discharge_date)