Skip to content

Commit

Permalink
Add abatement and chronic_condition to conditions (#2771)
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak authored Jan 22, 2025
1 parent ba647ba commit 2f59824
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
30 changes: 30 additions & 0 deletions care/emr/migrations/0010_condition_abatement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 5.1.4 on 2025-01-22 12:35

from django.db import migrations, models


def fix_encounter_diagnosis_category_case(apps, schema_editor):
Condition = apps.get_model("emr", "Condition")
Condition.objects.filter(category="encounter-diagnosis").update(category="encounter_diagnosis")

def revert_encounter_diagnosis_category_case(apps, schema_editor):
Condition = apps.get_model("emr", "Condition")
Condition.objects.filter(category="encounter_diagnosis").update(category="encounter-diagnosis")

class Migration(migrations.Migration):

dependencies = [
('emr', '0009_medicationrequest_authored_on'),
]

operations = [
migrations.AddField(
model_name='condition',
name='abatement',
field=models.JSONField(default=dict),
),
migrations.RunPython(
fix_encounter_diagnosis_category_case,
revert_encounter_diagnosis_category_case,
)
]
1 change: 1 addition & 0 deletions care/emr/models/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class Condition(EMRBaseModel):
patient = models.ForeignKey("emr.Patient", on_delete=models.CASCADE)
encounter = models.ForeignKey("emr.Encounter", on_delete=models.CASCADE)
onset = models.JSONField(default=dict)
abatement = models.JSONField(default=dict)
recorded_date = models.DateTimeField(null=True, blank=True)
note = models.TextField(null=True, blank=True)
13 changes: 12 additions & 1 deletion care/emr/resources/condition/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class VerificationStatusChoices(str, Enum):

class CategoryChoices(str, Enum):
problem_list_item = "problem_list_item"
encounter_diagnosis = "encounter-diagnosis"
encounter_diagnosis = "encounter_diagnosis"
chronic_condition = "chronic_condition"


class SeverityChoices(str, Enum):
Expand All @@ -49,6 +50,13 @@ class ConditionOnSetSpec(EMRResource):
note: str | None = None


class ConditionAbatementSpec(EMRResource):
abatement_datetime: datetime.datetime | None = None
abatement_age: int | None = None
abatement_string: str | None = None
note: str | None = None


class BaseConditionSpec(EMRResource):
__model__ = Condition
__exclude__ = ["patient", "encounter"]
Expand All @@ -62,6 +70,7 @@ class ConditionSpec(BaseConditionSpec):
code: Coding = Field(json_schema_extra={"slug": CARE_CODITION_CODE_VALUESET.slug})
encounter: UUID4
onset: ConditionOnSetSpec = {}
abatement: ConditionAbatementSpec = {}
note: str | None = None

@field_validator("code")
Expand Down Expand Up @@ -102,6 +111,7 @@ class ConditionSpecRead(BaseConditionSpec):
code: Coding
encounter: UUID4
onset: ConditionOnSetSpec = dict
abatement: ConditionAbatementSpec = dict
created_by: UserSpec = dict
updated_by: UserSpec = dict
note: str | None = None
Expand All @@ -123,6 +133,7 @@ class ConditionSpecUpdate(BaseConditionSpec):
severity: SeverityChoices | None = None
code: Coding = Field(json_schema_extra={"slug": CARE_CODITION_CODE_VALUESET.slug})
onset: ConditionOnSetSpec = {}
abatement: ConditionAbatementSpec = {}
note: str | None = None

@field_validator("code")
Expand Down

0 comments on commit 2f59824

Please sign in to comment.