Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes something went wrong error for duplicate patient no. check for OP consultations and imrpove error message #1974

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions care/facility/api/serializers/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand Down
5 changes: 5 additions & 0 deletions care/facility/tests/test_patient_consultation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
Loading