diff --git a/care/emr/migrations/0007_remove_medicationrequest_authored_on_and_more.py b/care/emr/migrations/0007_remove_medicationrequest_authored_on_and_more.py new file mode 100644 index 0000000000..e1a9fcd243 --- /dev/null +++ b/care/emr/migrations/0007_remove_medicationrequest_authored_on_and_more.py @@ -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', + ), + ] diff --git a/care/emr/models/medication_request.py b/care/emr/models/medication_request.py index ead3e97d88..e24bab6243 100644 --- a/care/emr/models/medication_request.py +++ b/care/emr/models/medication_request.py @@ -6,7 +6,6 @@ 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) @@ -14,6 +13,5 @@ class MedicationRequest(EMRBaseModel): 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) diff --git a/care/emr/resources/medication/administration/spec.py b/care/emr/resources/medication/administration/spec.py index 8a269ffc1e..360da30246 100644 --- a/care/emr/resources/medication/administration/spec.py +++ b/care/emr/resources/medication/administration/spec.py @@ -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", diff --git a/care/emr/resources/medication/request/spec.py b/care/emr/resources/medication/request/spec.py index 78800b22de..afedf31e94 100644 --- a/care/emr/resources/medication/request/spec.py +++ b/care/emr/resources/medication/request/spec.py @@ -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 @@ -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): @@ -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): @@ -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} ) @@ -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): @@ -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): diff --git a/care/emr/resources/medication/statement/spec.py b/care/emr/resources/medication/statement/spec.py index f6f9b3524b..425e9b5fd0 100644 --- a/care/emr/resources/medication/statement/spec.py +++ b/care/emr/resources/medication/statement/spec.py @@ -1,3 +1,4 @@ +from datetime import datetime from enum import Enum from pydantic import UUID4, Field, field_validator @@ -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): @@ -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):