Skip to content

Commit

Permalink
add root_label column to meta_icd11_diagnosis db table
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Jul 12, 2023
1 parent e9d6be9 commit 102d798
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
15 changes: 14 additions & 1 deletion care/facility/management/commands/load_meta_icd11_diagnosis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,21 @@ class Command(BaseCommand):
help = "Loads ICD11 data to a table in to database."

def handle(self, *args, **options):
print("Loading ICD11 data to database...")
print("Loading ICD11 data to DB Table (meta_icd11_diagnosis)...")
try:
icd11_objects = fetch_data()

def find_root(icd11_object):
if icd11_object["parentId"] is None:
return icd11_object["label"]
return find_root(
next(
filter(
lambda x: x["ID"] == icd11_object["parentId"], icd11_objects
)
)
)

MetaICD11Diagnosis.objects.all().delete()
MetaICD11Diagnosis.objects.bulk_create(
[
Expand All @@ -30,6 +42,7 @@ def handle(self, *args, **options):
is_leaf=icd11_object["isLeaf"],
label=icd11_object["label"],
breadth_value=icd11_object["breadthValue"],
root_label=find_root(icd11_object),
)
for icd11_object in icd11_objects
if icd11_object["ID"].split("/")[-1].isnumeric()
Expand Down
18 changes: 18 additions & 0 deletions care/facility/migrations/0371_metaicd11diagnosis_root_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.2 on 2023-07-12 08:02

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("facility", "0370_merge_20230705_1500"),
]

operations = [
migrations.AddField(
model_name="metaicd11diagnosis",
name="root_label",
field=models.CharField(default="", max_length=255),
preserve_default=False,
),
]
5 changes: 5 additions & 0 deletions care/facility/models/meta_icd11_diagnosis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@


class MetaICD11Diagnosis(models.Model):
"""
Not for production use. For Metabase purposes only. Do not build relations to this model.
"""

id = models.CharField(max_length=255, primary_key=True)
_id = models.IntegerField()
average_depth = models.IntegerField()
Expand All @@ -11,6 +15,7 @@ class MetaICD11Diagnosis(models.Model):
is_leaf = models.BooleanField()
label = models.CharField(max_length=255)
breadth_value = models.DecimalField(max_digits=24, decimal_places=22)
root_label = models.CharField(max_length=255)

class Meta:
db_table = "meta_icd11_diagnosis"
Expand Down

0 comments on commit 102d798

Please sign in to comment.