From 16b7cbbe6b47e4e834c66622f23db265434dfdac Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:11:03 +0530 Subject: [PATCH 1/3] Fix bed assignment validation for admission --- care/facility/api/serializers/daily_round.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/care/facility/api/serializers/daily_round.py b/care/facility/api/serializers/daily_round.py index 72d6b23893..3f14980056 100644 --- a/care/facility/api/serializers/daily_round.py +++ b/care/facility/api/serializers/daily_round.py @@ -179,8 +179,11 @@ def create(self, validated_data): ) # Authorisation Checks End - # Patient needs to have a bed assigned - if not consultation.current_bed: + # Patient needs to have a bed assigned for admission + if ( + not consultation.current_bed + and consultation.suggestion == SuggestionChoices.A + ): raise ValidationError( { "bed": "Patient does not have a bed assigned. Please assign a bed first" From 89f9749a386ab8f932c897d44afc7b29f9bdcbfe Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:11:27 +0530 Subject: [PATCH 2/3] add tests --- .../tests/test_patient_daily_rounds_api.py | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/care/facility/tests/test_patient_daily_rounds_api.py b/care/facility/tests/test_patient_daily_rounds_api.py index ceb221e32f..037701a31d 100644 --- a/care/facility/tests/test_patient_daily_rounds_api.py +++ b/care/facility/tests/test_patient_daily_rounds_api.py @@ -4,6 +4,7 @@ from rest_framework.test import APITestCase from care.facility.models import PatientRegistration +from care.facility.models.patient_consultation import PatientConsultation from care.utils.tests.test_utils import TestUtils @@ -19,8 +20,15 @@ def setUpTestData(cls) -> None: cls.patient = cls.create_patient(district=cls.district, facility=cls.facility) cls.asset_location = cls.create_asset_location(cls.facility) cls.bed = cls.create_bed(facility=cls.facility, location=cls.asset_location) - cls.consultation_without_bed = cls.create_consultation( - facility=cls.facility, patient=cls.patient + cls.admission_consultation_no_bed = cls.create_consultation( + facility=cls.facility, + patient=cls.patient, + suggestion=PatientConsultation.SUGGESTION_CHOICES[1][0], + ) + cls.domiciliary_consultation_no_bed = cls.create_consultation( + facility=cls.facility, + patient=cls.patient, + suggestion=PatientConsultation.SUGGESTION_CHOICES[4][0], ) cls.consultation_with_bed = cls.create_consultation( facility=cls.facility, patient=cls.patient @@ -65,11 +73,11 @@ def test_action_in_log_update( patient.action, PatientRegistration.ActionEnum.DISCHARGE_RECOMMENDED.value ) - def test_log_update_without_bed( + def test_log_update_without_bed_for_admission( self, ): response = self.client.post( - f"/api/v1/consultation/{self.consultation_without_bed.external_id}/daily_rounds/", + f"/api/v1/consultation/{self.admission_consultation_no_bed.external_id}/daily_rounds/", data=self.log_update, format="json", ) @@ -78,3 +86,13 @@ def test_log_update_without_bed( response.data["bed"], "Patient does not have a bed assigned. Please assign a bed first", ) + + def test_log_update_without_bed_for_domiciliary( + self, + ): + response = self.client.post( + f"/api/v1/consultation/{self.domiciliary_consultation_no_bed.external_id}/daily_rounds/", + data=self.log_update, + format="json", + ) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) From d37985abf2f404bc4429a5d664737d3ac87e0770 Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:56:07 +0530 Subject: [PATCH 3/3] add comments for suggestion choices --- care/facility/tests/test_patient_consultation_api.py | 4 +++- care/facility/tests/test_patient_daily_rounds_api.py | 4 ++-- care/utils/tests/test_utils.py | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/care/facility/tests/test_patient_consultation_api.py b/care/facility/tests/test_patient_consultation_api.py index 9b74338d1a..2e3e007a06 100644 --- a/care/facility/tests/test_patient_consultation_api.py +++ b/care/facility/tests/test_patient_consultation_api.py @@ -39,7 +39,9 @@ def get_default_data(self): "examination_details": "examination_details", "history_of_present_illness": "history_of_present_illness", "treatment_plan": "treatment_plan", - "suggestion": PatientConsultation.SUGGESTION_CHOICES[0][0], + "suggestion": PatientConsultation.SUGGESTION_CHOICES[0][ + 0 + ], # HOME ISOLATION "treating_physician": self.doctor.id, "create_diagnoses": [ { diff --git a/care/facility/tests/test_patient_daily_rounds_api.py b/care/facility/tests/test_patient_daily_rounds_api.py index 037701a31d..07ccb87df6 100644 --- a/care/facility/tests/test_patient_daily_rounds_api.py +++ b/care/facility/tests/test_patient_daily_rounds_api.py @@ -23,12 +23,12 @@ def setUpTestData(cls) -> None: cls.admission_consultation_no_bed = cls.create_consultation( facility=cls.facility, patient=cls.patient, - suggestion=PatientConsultation.SUGGESTION_CHOICES[1][0], + suggestion=PatientConsultation.SUGGESTION_CHOICES[1][0], # ADMISSION ) cls.domiciliary_consultation_no_bed = cls.create_consultation( facility=cls.facility, patient=cls.patient, - suggestion=PatientConsultation.SUGGESTION_CHOICES[4][0], + suggestion=PatientConsultation.SUGGESTION_CHOICES[4][0], # DOMICILIARY CARE ) cls.consultation_with_bed = cls.create_consultation( facility=cls.facility, patient=cls.patient diff --git a/care/utils/tests/test_utils.py b/care/utils/tests/test_utils.py index c71622b2cf..5135e360b1 100644 --- a/care/utils/tests/test_utils.py +++ b/care/utils/tests/test_utils.py @@ -312,7 +312,9 @@ def get_consultation_data(cls): "examination_details": "examination_details", "history_of_present_illness": "history_of_present_illness", "treatment_plan": "treatment_plan", - "suggestion": PatientConsultation.SUGGESTION_CHOICES[0][0], + "suggestion": PatientConsultation.SUGGESTION_CHOICES[0][ + 0 + ], # HOME ISOLATION "referred_to": None, "encounter_date": make_aware(datetime(2020, 4, 7, 15, 30)), "discharge_date": None,