From 3d8dfa1af858261c48ba5c8a27417a215422d055 Mon Sep 17 00:00:00 2001 From: Khavin Shankar Date: Thu, 15 Sep 2022 22:16:38 +0530 Subject: [PATCH] feat (patientconsultation): added icd11_provisional_diagnoses (#1022) Co-authored-by: Vignesh Hari --- .gitignore | 8 ++++++ .../api/serializers/patient_consultation.py | 27 +++++++++++++++++-- ...onsultation_icd11_provisional_diagnoses.py | 19 +++++++++++++ .../migrations/0317_merge_20220915_2209.py | 14 ++++++++++ care/facility/models/patient_consultation.py | 3 +++ 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 care/facility/migrations/0315_patientconsultation_icd11_provisional_diagnoses.py create mode 100644 care/facility/migrations/0317_merge_20220915_2209.py diff --git a/.gitignore b/.gitignore index be2720c036..d629603249 100644 --- a/.gitignore +++ b/.gitignore @@ -349,3 +349,11 @@ test_db celerybeat-schedule secrets.sh +/.idea/inspectionProfiles/profiles_settings.xml +/.idea/.gitignore +/.idea/aws.xml +/.idea/backend.iml +/.idea/git_toolbox_prj.xml +/.idea/misc.xml +/.idea/modules.xml +/.idea/vcs.xml diff --git a/care/facility/api/serializers/patient_consultation.py b/care/facility/api/serializers/patient_consultation.py index 5978ef2700..2841097385 100644 --- a/care/facility/api/serializers/patient_consultation.py +++ b/care/facility/api/serializers/patient_consultation.py @@ -84,11 +84,15 @@ class PatientConsultationSerializer(serializers.ModelSerializer): icd11_diagnoses_object = serializers.SerializerMethodField(read_only=True) - def get_icd11_diagnoses_object(self, consultation): + icd11_provisional_diagnoses_object = serializers.SerializerMethodField( + read_only=True + ) + + def get_icd11_diagnoses_objects_by_ids(self, diagnoses_ids): from care.facility.static_data.icd11 import ICDDiseases diagnosis_objects = [] - for diagnosis in consultation.icd11_diagnoses: + for diagnosis in diagnoses_ids: try: diagnosis_object = ICDDiseases.by.id[diagnosis].__dict__ diagnosis_objects.append(diagnosis_object) @@ -96,6 +100,12 @@ def get_icd11_diagnoses_object(self, consultation): pass return diagnosis_objects + def get_icd11_diagnoses_object(self, consultation): + return self.get_icd11_diagnoses_objects_by_ids(consultation.icd11_diagnoses) + + def get_icd11_provisional_diagnoses_object(self, consultation): + return self.get_icd11_diagnoses_objects_by_ids(consultation.icd11_provisional_diagnoses) + class Meta: model = PatientConsultation read_only_fields = TIMESTAMP_FIELDS + ( @@ -331,6 +341,19 @@ def validate(self, attrs): } ) + if "icd11_provisional_diagnoses" in validated: + for diagnosis in validated["icd11_provisional_diagnoses"]: + try: + ICDDiseases.by.id[diagnosis] + except BaseException: + raise ValidationError( + { + "icd11_provisional_diagnoses": [ + f"{diagnosis} is not a valid ICD 11 Diagnosis ID" + ] + } + ) + return validated diff --git a/care/facility/migrations/0315_patientconsultation_icd11_provisional_diagnoses.py b/care/facility/migrations/0315_patientconsultation_icd11_provisional_diagnoses.py new file mode 100644 index 0000000000..67fe55d3ef --- /dev/null +++ b/care/facility/migrations/0315_patientconsultation_icd11_provisional_diagnoses.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.11 on 2022-09-06 11:40 + +import django.contrib.postgres.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('facility', '0314_patientconsultation_icd11_diagnoses'), + ] + + operations = [ + migrations.AddField( + model_name='patientconsultation', + name='icd11_provisional_diagnoses', + field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), blank=True, default=[], null=True, size=None), + ), + ] diff --git a/care/facility/migrations/0317_merge_20220915_2209.py b/care/facility/migrations/0317_merge_20220915_2209.py new file mode 100644 index 0000000000..2ce17de332 --- /dev/null +++ b/care/facility/migrations/0317_merge_20220915_2209.py @@ -0,0 +1,14 @@ +# Generated by Django 2.2.11 on 2022-09-15 16:39 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('facility', '0315_patientconsultation_icd11_provisional_diagnoses'), + ('facility', '0316_auto_20220908_1112'), + ] + + operations = [ + ] diff --git a/care/facility/models/patient_consultation.py b/care/facility/models/patient_consultation.py index d080b00928..d6075d6e8d 100644 --- a/care/facility/models/patient_consultation.py +++ b/care/facility/models/patient_consultation.py @@ -42,6 +42,9 @@ class PatientConsultation(PatientBaseModel, PatientRelatedPermissionMixin): "Facility", on_delete=models.CASCADE, related_name="consultations" ) diagnosis = models.TextField(default="", null=True, blank=True) + icd11_provisional_diagnoses = ArrayField( + models.CharField(max_length=100), default=[], blank=True, null=True + ) icd11_diagnoses = ArrayField( models.CharField(max_length=100), default=[], blank=True, null=True )