Skip to main content
Version: 3.1

Medication statement

Technical reference for the MedicationStatement module in Care EMR. For what a medication statement is in the product, see the Medication statement concept.

A medication statement records a medicine in the patient's medication history: its status, the period, the dosage text and who gave the information. It is recorded against an encounter.

Source:

The Django model stores medication and effective_period as JSON columns. The Pydantic resource specs define their shape, the enums, the validation, the value set on medication and the read and write schemas. This page covers both layers.

Models​

ModelPurpose
MedicationStatementA medicine in the patient's medication history, recorded against an encounter

MedicationStatement extends EMRBaseModel. It supplies external_id, created_date, modified_date, the soft-delete flag deleted, created_by, updated_by, history and meta.

MedicationStatement fields​

In the tables below, the model type is the Django column and the spec type is what the API reads and writes. "Fixed" means that the update spec does not accept the field after create.

Statement details​

FieldModel typeSpec typeRequired (API)Notes
statusCharField(100)MedicationStatementStatusYesCan change after create. See status values
reasonCharField(100), nullablestr | NoneNoThe spec does not limit the length. The column holds at most 100 characters. Fixed
medicationJSONField, default {}ValueSetBoundCoding[system-medication]YesOne Coding bound to the Medication value set. Fixed
information_sourceCharField(100), not nullableMedicationStatementInformationSourceType | NoneNoThe spec lets you leave it out, but the column is not nullable. See information source values. Fixed
effective_periodJSONField, default {}PeriodSpec | NoneNoSee PeriodSpec shape. Can change after create. Left out on create, the column keeps {}
dosage_textTextField, nullablestr | NoneNoFree text. A code comment suggests the Dosage of medication requests as a later replacement. Fixed
noteTextField, nullablestr | NoneNoCan change after create. Sending null does not clear it

Relationships​

FieldModel typeSpec typeNotes
patientFK → Patient, CASCADENot acceptedCopied from the encounter, on create only
encounterFK → Encounter, CASCADEUUID4, requiredMust exist ("Encounter not found"). Dropped from an update body. Read returns the encounter id
patient → FK Patient (CASCADE)
encounter → FK Encounter (CASCADE)

Both links are CASCADE. The rule acts only when a row is removed from the database. The API delete and the model delete() are soft and do not trigger it.

Enum values​

Enum values use underscores. They are the exact strings that the API accepts and returns.

MedicationStatementStatus values​

Value
active
on_hold
completed
stopped
unknown
entered_in_error
not_taken
intended

MedicationStatementInformationSourceType values​

Value
related_person
practitioner
patient

Nested JSON shapes​

Coding shape​

medication is one Coding, not a CodeableConcept. Unknown keys are refused.

FieldTypeNotes
systemstr | NoneCode system URI
versionstr | NoneCode system version
codestrRequired. Checked against the bound value set
displaystr | NoneDisplay text

Bound value set​

medication is declared as ValueSetBoundCoding[CARE_MEDICATION_VALUESET.slug]. Every write checks its code against the system-medication value set: SNOMED CT concepts under << 763158003 Medicinal product. A code outside the set fails with "Code does not exist in the valueset".

Care checks codes against the copy of the value set in the database. A deployment can change that copy after it is loaded, so the codes allowed at a deployment can differ from that scope.

PeriodSpec shape​

effective_period is a PeriodSpec.

FieldTypeNotes
startdatetime | NoneMust carry a time zone when set ("Start Date must be timezone aware")
enddatetime | NoneMust carry a time zone when set ("End Date must be timezone aware")

A start after the end fails with "Start Date cannot be greater than End Date".

Resource specs (API schema)​

Resource specs never copy foreign keys automatically. Both statement specs also list patient and encounter in __exclude__.

Spec classRoleFields
BaseMedicationStatementSpecsharedid, status, reason, medication, dosage_text, effective_period, encounter, information_source, note
MedicationStatementSpecwrite · createThe shared fields. Adds the encounter check and copies patient from the encounter
MedicationStatementUpdateSpecwrite · updateOnly status (required), effective_period and note
MedicationStatementReadSpecread · list and detailAdds created_by, updated_by, created_date, modified_date and the encounter id

What the specs check and maintain:

  • The encounter must exist, or the create fails with "Encounter not found".
  • patient is copied from the encounter on create only.
  • medication is checked against its value set on every write.
  • effective_period must have time-zone-aware dates, with start not after end.
  • The update spec has no status-transition rule. Any status can follow any status, including a change back from entered_in_error.
  • There is no status history column. status holds only the current value.
  • Every create and update also writes a questionnaire response with structured type medication_statement and submit type CREATE or UPDATE.

Methods & save behaviour​

  • The model defines no save() or delete() override.
  • Create runs in this order: validate the body, authorize, build the record, save.
  • Fields left at their spec default are not written (exclude_defaults=True). So an update cannot clear an optional field by sending null.
  • An update body loses id, external_id, patient and encounter before validation.
  • Delete is soft: Care sets deleted and keeps the row. The default manager hides deleted rows.

API integration notes​

Endpoints​

All paths are under /api/v1/.

MethodPathAction
GETpatient/{patient_id}/medication/statement/List
POSTpatient/{patient_id}/medication/statement/Create
GETpatient/{patient_id}/medication/statement/{id}/Retrieve
PUT, PATCHpatient/{patient_id}/medication/statement/{id}/Update. Both use MedicationStatementUpdateSpec
DELETEpatient/{patient_id}/medication/statement/{id}/Soft delete
POSTpatient/{patient_id}/medication/statement/upsert/Batch create or update, see Upsert

Authorization​

"Clinical write" below means "Update Encounter related clinical data" held in one of the encounter's departments or its current location's departments. The encounter status must not be Completed, Cancelled, Entered in Error or Discontinued.

ActionRequirement
List"Can view clinical data about patients" on the patient in the URL. Failing that, with ?encounter=: "Can Read encounter related clinical data" on that encounter. Else 403 "Permission denied to user". The encounter filter then limits the results to that encounter. There is no pharmacist route
RetrieveThe read check of the list runs first
Create, upsert items without idClinical write on the encounter in the body. Else 403 "You do not have permission to update encounter"
Update, deleteThe read check of the list runs first. Then clinical write on the record's encounter

"Can view clinical data about patients" counts the user's roles on the patient. These come from the departments of the patient's open encounters (and of their current locations), the patient's organizations, and a direct patient link. Closed encounters do not count.

Default role lists from the permission definitions:

PermissionDefault roles
"Update Encounter related clinical data"Doctor, Nurse, Facility Admin
"Can Read encounter related clinical data"Doctor, Nurse, Facility Admin
"Can view clinical data about patients"Staff, Doctor, Nurse, Facility Admin

The permission definitions also name an Admin role. Roles are matched by name, and the only role named Admin in the database is for role organizations, which the screen that links users to departments does not offer. The lists above leave it out.

A permission refusal is HTTP 403 with the message in detail. A validation error is HTTP 400 with an errors list. A missing record is HTTP 404 with type object_not_found.

Filters and ordering​

ParameterMeaning
encounterEncounter id
statusComma-separated statuses
nameMedicine display contains the text, case-insensitive
orderingcreated_date or modified_date. Without it, newest record first

Lists are paginated with limit and offset (default 14, at most 200) and return count and results.

Upsert​

POST .../upsert/ takes {"datapoints": [...]}. An item with id updates that record; an item without one creates a record.

  • An empty list fails with "No datapoints provided". More than MAX_DATAPOINTS_PER_UPSERT items (100 by default, set by environment variable) fails with "Too many datapoints provided".
  • All items run in one transaction. If any item fails, nothing is saved and the response is HTTP 400 with one result per item.

Notes​

  • The Care frontend saves the Medication Statement form through this upsert. The save goes in one batch request (POST /api/v1/batch_requests/), which keeps nothing if any request in it fails.
  • The Care frontend never deletes a medication statement.
  • Send medication as one Coding object with a code from system-medication, not as a CodeableConcept or a plain string.
  • No deployment setting is specific to this resource.