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

improving tests for patient transfer #2066

Closed
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
41 changes: 41 additions & 0 deletions care/facility/tests/test_patient_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down Expand Up @@ -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()

Expand All @@ -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)