From 379cf51b5bd97e2ec6b317ea9280b0e333dcfc46 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Fri, 15 Mar 2024 10:50:01 +0530 Subject: [PATCH] fixes https://github.com/coronasafe/care_fe/issues/7410 --- .../api/serializers/patient_consultation.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/care/facility/api/serializers/patient_consultation.py b/care/facility/api/serializers/patient_consultation.py index f3df403581..74cfdc4ab2 100644 --- a/care/facility/api/serializers/patient_consultation.py +++ b/care/facility/api/serializers/patient_consultation.py @@ -518,17 +518,16 @@ def validate(self, attrs): validated = super().validate(attrs) # TODO Add Bed Authorisation Validation - if ( - not self.instance - and "suggestion" in validated - and validated["suggestion"] == SuggestionChoices.A - ): + if not self.instance and "suggestion" in validated: + suggestion = validated["suggestion"] patient_no = validated.get("patient_no") - if not patient_no: + if suggestion == SuggestionChoices.A and not patient_no: raise ValidationError( - {"ip_no": ["This field is required for admission."]} + {"patient_no": "This field is required for admission."} ) - if PatientConsultation.objects.filter( + if ( + suggestion == SuggestionChoices.A or suggestion == SuggestionChoices.OP + ) and PatientConsultation.objects.filter( patient_no=patient_no, facility=( self.instance.facility @@ -537,7 +536,9 @@ def validate(self, attrs): ), ).exists(): raise ValidationError( - "Patient number must be unique within the facility." + { + "patient_no": "Consultation with this IP/OP number already exists within the facility." + } ) if (