From 9f102c48a2c948690a75c0381ed007b8712ea709 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 4 Jul 2024 14:57:26 +0530 Subject: [PATCH 1/2] Allows duplicate symptom entries for once that has cure date --- .../api/serializers/patient_consultation.py | 4 ++- .../tests/test_encounter_symptom_api.py | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/care/facility/api/serializers/patient_consultation.py b/care/facility/api/serializers/patient_consultation.py index 6c0796328a..cc34de6970 100644 --- a/care/facility/api/serializers/patient_consultation.py +++ b/care/facility/api/serializers/patient_consultation.py @@ -555,7 +555,9 @@ def validate_create_symptoms(self, value): if item in counter: # Reject if duplicate symptoms are provided raise ValidationError("Duplicate symptoms are not allowed") - counter.add(item) + if not obj.get("cure_date"): + # skip duplicate symptom check for ones that has cure date + counter.add(item) current_time = now() for obj in value: diff --git a/care/facility/tests/test_encounter_symptom_api.py b/care/facility/tests/test_encounter_symptom_api.py index efff7fb6d2..90d6ba0015 100644 --- a/care/facility/tests/test_encounter_symptom_api.py +++ b/care/facility/tests/test_encounter_symptom_api.py @@ -114,6 +114,37 @@ def test_create_consultation_with_duplicate_symptoms(self): {"create_symptoms": ["Duplicate symptoms are not allowed"]}, ) + def test_create_consultation_with_duplicate_cured_symptoms(self): + data = self.consultation_data.copy() + data["create_symptoms"] = [ + { + "symptom": Symptom.FEVER, + "onset_date": now(), + "cure_date": now(), + }, + { + "symptom": Symptom.FEVER, + "onset_date": now(), + }, + { + "symptom": Symptom.OTHERS, + "other_symptom": "Other Symptom", + "onset_date": now(), + "cure_date": now(), + }, + { + "symptom": Symptom.OTHERS, + "other_symptom": "Other Symptom", + "onset_date": now(), + }, + ] + response = self.client.post( + "/api/v1/consultation/", + data, + format="json", + ) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + def test_create_consultation_with_no_symptom(self): data = self.consultation_data.copy() From a0d8563edb5052cb789840c37dfb52a9358a5af3 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Wed, 21 Aug 2024 12:15:19 +0530 Subject: [PATCH 2/2] 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)