Skip to content

Commit

Permalink
feat (patientconsultation): added icd11_provisional_diagnoses (#1022)
Browse files Browse the repository at this point in the history
Co-authored-by: Vignesh Hari <vichuhari100@gmail.com>
  • Loading branch information
khavinshankar and vigneshhari authored Sep 15, 2022
1 parent 2390e6d commit 3d8dfa1
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 25 additions & 2 deletions care/facility/api/serializers/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,28 @@ 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)
except BaseException:
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 + (
Expand Down Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
@@ -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),
),
]
14 changes: 14 additions & 0 deletions care/facility/migrations/0317_merge_20220915_2209.py
Original file line number Diff line number Diff line change
@@ -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 = [
]
3 changes: 3 additions & 0 deletions care/facility/models/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 3d8dfa1

Please sign in to comment.