From a0d8563edb5052cb789840c37dfb52a9358a5af3 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Wed, 21 Aug 2024 12:15:19 +0530 Subject: [PATCH] fix consultation create with bed --- .../api/serializers/patient_consultation.py | 3 ++- .../tests/test_patient_consultation_api.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/care/facility/api/serializers/patient_consultation.py b/care/facility/api/serializers/patient_consultation.py index 30d36e7aaf..c3437cf99a 100644 --- a/care/facility/api/serializers/patient_consultation.py +++ b/care/facility/api/serializers/patient_consultation.py @@ -396,6 +396,8 @@ def create(self, validated_data): if validated_data["is_kasp"]: validated_data["kasp_enabled_date"] = now() + bed = validated_data.pop("bed", None) + # Coercing facility as the patient's facility validated_data["facility_id"] = patient.facility_id @@ -440,7 +442,6 @@ def create(self, validated_data): for obj in create_symptoms ) - bed = validated_data.pop("bed", None) if bed and consultation.suggestion == SuggestionChoices.A: consultation_bed = ConsultationBed( bed=bed, diff --git a/care/facility/tests/test_patient_consultation_api.py b/care/facility/tests/test_patient_consultation_api.py index fdb62b7bd2..8fd901e274 100644 --- a/care/facility/tests/test_patient_consultation_api.py +++ b/care/facility/tests/test_patient_consultation_api.py @@ -6,6 +6,7 @@ from rest_framework.test import APITestCase from care.facility.api.serializers.patient_consultation import MIN_ENCOUNTER_DATE +from care.facility.models.bed import Bed from care.facility.models.encounter_symptom import Symptom from care.facility.models.file_upload import FileUpload from care.facility.models.icd11_diagnosis import ( @@ -641,3 +642,17 @@ def test_allow_empty_op_no(self): ) res = self.client.post(self.get_url(), data, format="json") self.assertEqual(res.status_code, status.HTTP_201_CREATED) + + def test_create_consultation_with_bed(self): + asset_location = self.create_asset_location(self.facility) + bed = Bed.objects.create( + name="bed", location=asset_location, facility=self.facility + ) + + consultation: PatientConsultation = self.create_admission_consultation( + suggestion=SuggestionChoices.A, + encounter_date=make_aware(datetime.datetime(2020, 4, 1, 15, 30, 00)), + bed=bed.external_id, + ) + + self.assertEqual(consultation.current_bed.bed, bed)