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" 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 ceb221e32f..07ccb87df6 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], # ADMISSION + ) + cls.domiciliary_consultation_no_bed = cls.create_consultation( + facility=cls.facility, + patient=cls.patient, + suggestion=PatientConsultation.SUGGESTION_CHOICES[4][0], # DOMICILIARY CARE ) 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) 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,