Skip to content

Commit

Permalink
Modified spec for Medication
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshhari committed Jan 14, 2025
1 parent 73f36db commit 98c55dd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.1.4 on 2025-01-14 18:13

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('emr', '0006_alter_patient_blood_group'),
]

operations = [
migrations.RemoveField(
model_name='medicationrequest',
name='authored_on',
),
migrations.RemoveField(
model_name='medicationrequest',
name='status_changed',
),
]
2 changes: 0 additions & 2 deletions care/emr/models/medication_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
class MedicationRequest(EMRBaseModel):
status = models.CharField(max_length=100, null=True, blank=True)
status_reason = models.CharField(max_length=100, null=True, blank=True)
status_changed = models.DateTimeField(null=True, blank=True)
intent = models.CharField(max_length=100, null=True, blank=True)
category = models.CharField(max_length=100, null=True, blank=True)
priority = models.CharField(max_length=100, null=True, blank=True)
do_not_perform = models.BooleanField()
method = models.JSONField(default=dict, null=True, blank=True)
patient = models.ForeignKey("emr.Patient", on_delete=models.CASCADE)
encounter = models.ForeignKey("emr.Encounter", on_delete=models.CASCADE)
authored_on = models.DateTimeField(null=True, blank=True)
dosage_instruction = models.JSONField(default=list, null=True, blank=True)
note = models.TextField(null=True, blank=True)
11 changes: 3 additions & 8 deletions care/emr/resources/medication/administration/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,13 @@ class BaseMedicationAdministrationSpec(EMRResource):
__exclude__ = ["patient", "encounter", "request"]
id: UUID4 = None

status: MedicationAdministrationStatus = Field(
description="Represents the current status of the medication administration",
)
status: MedicationAdministrationStatus

status_reason: Coding | None = Field(
None,
description="The reason why the medication was not administered",
json_schema_extra={"slug": CARE_MEDICATION_VALUESET.slug},
)
category: MedicationAdministrationCategory | None = Field(
None,
description="The category of the medication administration",
)
category: MedicationAdministrationCategory | None = None

medication: Coding = Field(
description="The medication that was taken",
Expand Down
63 changes: 24 additions & 39 deletions care/emr/resources/medication/request/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from care.emr.resources.medication.valueset.body_site import CARE_BODY_SITE_VALUESET
from care.emr.resources.medication.valueset.medication import CARE_MEDICATION_VALUESET
from care.emr.resources.medication.valueset.route import CARE_ROUTE_VALUESET
from care.emr.resources.observation.valueset import CARE_UCUM_UNITS
from care.emr.resources.user.spec import UserSpec


Expand Down Expand Up @@ -93,7 +92,12 @@ class DoseType(str, Enum):

class DosageQuantity(BaseModel):
value: float
unit: Coding = Field(None, json_schema_extra={"slug": CARE_UCUM_UNITS.slug})
unit: Coding


class TimingQuantity(BaseModel):
value: float
unit: TimingUnit


class DoseRange(BaseModel):
Expand All @@ -102,21 +106,21 @@ class DoseRange(BaseModel):


class DoseAndRate(BaseModel):
type: DoseType | None = None
type: DoseType
dose_range: DoseRange | None = None
dose_quantity: DosageQuantity | None = None


class TimingRepeat(BaseModel):
frequency: int | None = None
period: float | None = None
frequency: int
period: float
period_unit: TimingUnit
bounds_duration: DosageQuantity | None = None
bounds_duration: TimingQuantity


class Timing(BaseModel):
repeat: TimingRepeat | None = None
code: Coding | None = None
repeat: TimingRepeat
code: Coding


class DosageInstruction(BaseModel):
Expand All @@ -127,7 +131,7 @@ class DosageInstruction(BaseModel):
)
patient_instruction: str | None = None
timing: Timing | None = None
as_needed_boolean: bool | None = None
as_needed_boolean: bool
as_needed_for: Coding | None = Field(
None, json_schema_extra={"slug": CARE_AS_NEEDED_REASON_VALUESET.slug}
)
Expand Down Expand Up @@ -196,47 +200,26 @@ class BaseMedicationRequestSpec(EMRResource):
__exclude__ = ["patient", "encounter"]
id: UUID4 = None

status: MedicationRequestStatus = Field(
description="Status of the medication request",
)
status: MedicationRequestStatus

status_reason: StatusReason | None = Field(
None, description="Reason for current status"
)
status_reason: StatusReason | None = None

status_changed: datetime = None
intent: MedicationRequestIntent

intent: MedicationRequestIntent = Field(
description="Whether this is a proposal, plan, original order, etc.",
)
category: MedicationRequestCategory
priority: MedicationRequestPriority

category: MedicationRequestCategory = Field(
description="Context of medication request",
)
priority: MedicationRequestPriority = Field(
description="Urgency of the request",
)

do_not_perform: bool = Field(
description="True if medication is NOT to be given",
)
do_not_perform: bool

medication: Coding = Field(
description="Medication requested, using SNOMED CT coding",
json_schema_extra={"slug": CARE_MEDICATION_VALUESET.slug},
)

encounter: UUID4 = Field(description="Encounter during which request was created")
encounter: UUID4

authored_on: datetime = Field(
description="When request was initially authored",
)

dosage_instruction: list[DosageInstruction] = Field(
description="Dosage instructions for the medication",
)
dosage_instruction: list[DosageInstruction] = Field()

note: str | None = Field(None, description="Additional notes about the request")
note: str | None = Field(None)


class MedicationRequestSpec(BaseMedicationRequestSpec):
Expand Down Expand Up @@ -268,6 +251,8 @@ def perform_extra_deserialization(self, is_update, obj):
class MedicationRequestReadSpec(BaseMedicationRequestSpec):
created_by: UserSpec = dict
updated_by: UserSpec = dict
created_date: datetime
modified_date: datetime

@classmethod
def perform_extra_serialization(cls, mapping, obj):
Expand Down
37 changes: 10 additions & 27 deletions care/emr/resources/medication/statement/spec.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from enum import Enum

from pydantic import UUID4, Field, field_validator
Expand Down Expand Up @@ -33,43 +34,23 @@ class BaseMedicationStatementSpec(EMRResource):
__exclude__ = ["patient", "encounter"]
id: UUID4 = None

status: MedicationStatementStatus = Field(
...,
description="Represents the current status of the medication request",
)
reason: str | None = Field(
None,
description="The reason why the medication is being/was taken",
)
status: MedicationStatementStatus
reason: str | None = None

medication: Coding = Field(
...,
description="The medication that was taken",
json_schema_extra={"slug": CARE_MEDICATION_VALUESET.slug},
)
dosage_text: str | None = Field(
None,
description="The dosage of the medication",
) # consider using Dosage from MedicationRequest
effective_period: Period | None = Field(
None,
description="The period during which the medication was taken",
)

encounter: UUID4 = Field(
...,
description="The encounter where the statement was noted",
)
effective_period: Period | None = None

information_source: MedicationStatementInformationSourceType | None = Field(
None,
description="The source of the information about the medication, patient, related person, or healthcare provider",
)
encounter: UUID4

note: str | None = Field(
None,
description="Any additional notes about the medication",
)
information_source: MedicationStatementInformationSourceType | None = None

note: str | None = None


class MedicationStatementSpec(BaseMedicationStatementSpec):
Expand Down Expand Up @@ -101,6 +82,8 @@ def perform_extra_deserialization(self, is_update, obj):
class MedicationStatementReadSpec(BaseMedicationStatementSpec):
created_by: UserSpec = dict
updated_by: UserSpec = dict
created_date: datetime
modified_date: datetime

@classmethod
def perform_extra_serialization(cls, mapping, obj):
Expand Down

0 comments on commit 98c55dd

Please sign in to comment.