From 379cf51b5bd97e2ec6b317ea9280b0e333dcfc46 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Fri, 15 Mar 2024 10:50:01 +0530 Subject: [PATCH 1/4] 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 ( From 15abfe1a9cdd47f604767b9aab01768a082f450a Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Fri, 15 Mar 2024 11:05:59 +0530 Subject: [PATCH 2/4] update tests --- care/facility/tests/test_patient_consultation_api.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/care/facility/tests/test_patient_consultation_api.py b/care/facility/tests/test_patient_consultation_api.py index 1fa6f056af..758163f404 100644 --- a/care/facility/tests/test_patient_consultation_api.py +++ b/care/facility/tests/test_patient_consultation_api.py @@ -546,6 +546,7 @@ def test_create_consultations_with_duplicate_patient_no_within_facility(self): ) res = self.client.post(self.get_url(), data, format="json") self.assertEqual(res.status_code, status.HTTP_201_CREATED) + data.update( { "patient_no": "IP1234", @@ -557,6 +558,10 @@ def test_create_consultations_with_duplicate_patient_no_within_facility(self): res = self.client.post(self.get_url(), data, format="json") self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST) + data.update({"suggestion": SuggestionChoices.A}) + res = self.client.post(self.get_url(), data, format="json") + self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST) + def test_create_consultations_with_same_patient_no_in_different_facilities(self): facility2 = self.create_facility( self.super_user, self.district, self.local_body, name="bar" From 55b7bff1b85868f29776bb5efe27123a46d87809 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Fri, 15 Mar 2024 14:20:28 +0530 Subject: [PATCH 3/4] treat all non admission consultations as OP consultations --- care/facility/api/serializers/patient_consultation.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/care/facility/api/serializers/patient_consultation.py b/care/facility/api/serializers/patient_consultation.py index 74cfdc4ab2..c1b495e762 100644 --- a/care/facility/api/serializers/patient_consultation.py +++ b/care/facility/api/serializers/patient_consultation.py @@ -518,15 +518,19 @@ def validate(self, attrs): validated = super().validate(attrs) # TODO Add Bed Authorisation Validation - if not self.instance and "suggestion" in validated: + if ( + not self.instance or validated.get("patient_no") != self.instance.patient_no + ) and "suggestion" in validated: suggestion = validated["suggestion"] patient_no = validated.get("patient_no") + if suggestion == SuggestionChoices.A and not patient_no: raise ValidationError( {"patient_no": "This field is required for admission."} ) + if ( - suggestion == SuggestionChoices.A or suggestion == SuggestionChoices.OP + suggestion == SuggestionChoices.A or patient_no is not None ) and PatientConsultation.objects.filter( patient_no=patient_no, facility=( From 51ce81e9ca6897e4f0283f967bb242b60022f2bd Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Fri, 15 Mar 2024 15:08:17 +0530 Subject: [PATCH 4/4] minor fix --- care/facility/api/serializers/patient_consultation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/care/facility/api/serializers/patient_consultation.py b/care/facility/api/serializers/patient_consultation.py index c1b495e762..6b992b414c 100644 --- a/care/facility/api/serializers/patient_consultation.py +++ b/care/facility/api/serializers/patient_consultation.py @@ -530,7 +530,7 @@ def validate(self, attrs): ) if ( - suggestion == SuggestionChoices.A or patient_no is not None + suggestion == SuggestionChoices.A or patient_no ) and PatientConsultation.objects.filter( patient_no=patient_no, facility=(