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

ICD-11 diagnosis cannot be both provisional and final #1673

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions care/facility/api/serializers/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,15 @@ def validate(self, attrs):
}
)

if len(set(final_diagnosis).intersection(provisional_diagnosis)):
raise ValidationError(
{
"icd11_diagnoses": [
"A diagnosis cannot be both provisional and final"
],
}
)

if (
"icd11_principal_diagnosis" in validated
and validated.get("suggestion") != SuggestionChoices.DD
Expand Down
20 changes: 20 additions & 0 deletions care/facility/tests/test_patient_consultation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
CATEGORY_CHOICES,
PatientConsultation,
)
from care.facility.static_data.icd11 import ICDDiseases, fetch_from_db
from care.utils.tests.test_utils import TestUtils


Expand Down Expand Up @@ -257,6 +258,25 @@ def test_referred_to_external_valid_value(self):
)
self.assertEqual(res.status_code, status.HTTP_200_OK)

def test_icd11_diagnosis_final_and_provisional(self):
ICDDiseases.insert_many(fetch_from_db())
consultation = self.create_admission_consultation(
suggestion="A",
admission_date=make_aware(datetime.datetime(2023, 4, 1, 15, 30, 00)),
)
res = self.update_consultation(
consultation,
icd11_provisional_diagnoses=["1665365733"],
icd11_diagnoses=["1665365733"],
)
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)
res = self.update_consultation(
consultation,
icd11_provisional_diagnoses=["1665365733"],
icd11_diagnoses=["588616678"],
)
self.assertEqual(res.status_code, status.HTTP_200_OK)

def test_medico_legal_case(self):
consultation = self.create_admission_consultation(
medico_legal_case=True,
Expand Down