From 3a1238152f826b58cf4aad2c174ad414a179cb06 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Wed, 21 Aug 2024 16:18:20 +0530 Subject: [PATCH 1/2] Fixes incorrect check for missing treating physician field and not mandate for DC suggestion --- .../api/serializers/patient_consultation.py | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/care/facility/api/serializers/patient_consultation.py b/care/facility/api/serializers/patient_consultation.py index c3437cf99a..56fd74ca24 100644 --- a/care/facility/api/serializers/patient_consultation.py +++ b/care/facility/api/serializers/patient_consultation.py @@ -613,11 +613,12 @@ def validate(self, attrs): {"patient_no": "This field is required for admission."} ) - if ( - "suggestion" in validated - and validated["suggestion"] != SuggestionChoices.DD - ): - if "treating_physician" not in validated: + if "suggestion" in validated and validated["suggestion"] not in [ + SuggestionChoices.DD, + SuggestionChoices.DC, + ]: + treating_physician = validated.get("treating_physician") + if not treating_physician: raise ValidationError( { "treating_physician": [ @@ -625,10 +626,7 @@ def validate(self, attrs): ] } ) - if ( - not validated["treating_physician"].user_type - == User.TYPE_VALUE_MAP["Doctor"] - ): + if not treating_physician.user_type == User.TYPE_VALUE_MAP["Doctor"]: raise ValidationError("Only Doctors can verify a Consultation") facility = ( @@ -637,8 +635,8 @@ def validate(self, attrs): or validated["patient"].facility ) if ( - validated["treating_physician"].home_facility - and validated["treating_physician"].home_facility != facility + treating_physician.home_facility + and treating_physician.home_facility != facility ): raise ValidationError( "Home Facility of the Doctor must be the same as the Consultation Facility" From 96e8417c756fb6ca4b48063e155ee54fd706eb42 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 22 Aug 2024 18:04:10 +0530 Subject: [PATCH 2/2] add tests --- .../facility/tests/test_patient_consultation_api.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/care/facility/tests/test_patient_consultation_api.py b/care/facility/tests/test_patient_consultation_api.py index 8fd901e274..0bea4b9847 100644 --- a/care/facility/tests/test_patient_consultation_api.py +++ b/care/facility/tests/test_patient_consultation_api.py @@ -87,7 +87,7 @@ def create_route_to_facility_consultation( data.update(kwargs) return self.client.post(self.get_url(), data, format="json") - def create_admission_consultation(self, patient=None, **kwargs): + def call_create_admission_consultation_api(self, patient=None, **kwargs): patient = patient or self.create_patient(self.district, self.facility) data = self.get_default_data().copy() kwargs.update( @@ -97,7 +97,10 @@ def create_admission_consultation(self, patient=None, **kwargs): } ) data.update(kwargs) - res = self.client.post(self.get_url(), data, format="json") + return self.client.post(self.get_url(), data, format="json") + + def create_admission_consultation(self, patient=None, **kwargs): + res = self.call_create_admission_consultation_api(patient, **kwargs) return PatientConsultation.objects.get(external_id=res.data["id"]) def update_consultation(self, consultation, **kwargs): @@ -132,6 +135,12 @@ def test_encounter_date_less_than_minimum(self): res = self.client.post(self.get_url(), data, format="json") self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST) + def test_create_admission_consultation_without_treating_physician(self): + res = self.call_create_admission_consultation_api( + suggestion="A", treating_physician=None + ) + self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST) + def test_create_consultation_treating_physician_invalid_user(self): consultation = self.create_admission_consultation(suggestion="A") res = self.update_consultation(