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:
- Model:
care/emr/models/medication_statement.py - Spec:
care/emr/resources/medication/statement/spec.py - Viewset:
care/emr/api/viewsets/medication_statement.py - Value set:
care/emr/resources/medication/valueset/medication.py
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
| Model | Purpose |
|---|---|
MedicationStatement | A 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
| Field | Model type | Spec type | Required (API) | Notes |
|---|---|---|---|---|
status | CharField(100) | MedicationStatementStatus | Yes | Can change after create. See status values |
reason | CharField(100), nullable | str | None | No | The spec does not limit the length. The column holds at most 100 characters. Fixed |
medication | JSONField, default {} | ValueSetBoundCoding[system-medication] | Yes | One Coding bound to the Medication value set. Fixed |
information_source | CharField(100), not nullable | MedicationStatementInformationSourceType | None | No | The spec lets you leave it out, but the column is not nullable. See information source values. Fixed |
effective_period | JSONField, default {} | PeriodSpec | None | No | See PeriodSpec shape. Can change after create. Left out on create, the column keeps {} |
dosage_text | TextField, nullable | str | None | No | Free text. A code comment suggests the Dosage of medication requests as a later replacement. Fixed |
note | TextField, nullable | str | None | No | Can change after create. Sending null does not clear it |
Relationships
| Field | Model type | Spec type | Notes |
|---|---|---|---|
patient | FK → Patient, CASCADE | Not accepted | Copied from the encounter, on create only |
encounter | FK → Encounter, CASCADE | UUID4, required | Must 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.
| Field | Type | Notes |
|---|---|---|
system | str | None | Code system URI |
version | str | None | Code system version |
code | str | Required. Checked against the bound value set |
display | str | None | Display 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.
| Field | Type | Notes |
|---|---|---|
start | datetime | None | Must carry a time zone when set ("Start Date must be timezone aware") |
end | datetime | None | Must 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 class | Role | Fields |
|---|---|---|
BaseMedicationStatementSpec | shared | id, status, reason, medication, dosage_text, effective_period, encounter, information_source, note |
MedicationStatementSpec | write · create | The shared fields. Adds the encounter check and copies patient from the encounter |
MedicationStatementUpdateSpec | write · update | Only status (required), effective_period and note |
MedicationStatementReadSpec | read · list and detail | Adds created_by, updated_by, created_date, modified_date and the encounter id |
What the specs check and maintain:
- The
encountermust exist, or the create fails with "Encounter not found". patientis copied from the encounter on create only.medicationis checked against its value set on every write.effective_periodmust have time-zone-aware dates, withstartnot afterend.- 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.
statusholds only the current value. - Every create and update also writes a questionnaire response with structured type
medication_statementand submit typeCREATEorUPDATE.
Methods & save behaviour
- The model defines no
save()ordelete()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 sendingnull. - An update body loses
id,external_id,patientandencounterbefore validation. - Delete is soft: Care sets
deletedand keeps the row. The default manager hides deleted rows.
API integration notes
Endpoints
All paths are under /api/v1/.
| Method | Path | Action |
|---|---|---|
GET | patient/{patient_id}/medication/statement/ | List |
POST | patient/{patient_id}/medication/statement/ | Create |
GET | patient/{patient_id}/medication/statement/{id}/ | Retrieve |
PUT, PATCH | patient/{patient_id}/medication/statement/{id}/ | Update. Both use MedicationStatementUpdateSpec |
DELETE | patient/{patient_id}/medication/statement/{id}/ | Soft delete |
POST | patient/{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.
| Action | Requirement |
|---|---|
| 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 |
| Retrieve | The read check of the list runs first |
Create, upsert items without id | Clinical write on the encounter in the body. Else 403 "You do not have permission to update encounter" |
| Update, delete | The 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:
| Permission | Default 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
| Parameter | Meaning |
|---|---|
encounter | Encounter id |
status | Comma-separated statuses |
name | Medicine display contains the text, case-insensitive |
ordering | created_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_UPSERTitems (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
medicationas oneCodingobject with acodefromsystem-medication, not as aCodeableConceptor a plain string. - No deployment setting is specific to this resource.
Related
- Concept: Medication statement
- Reference: Medication request
- Reference: Medication administration
- Reference: Medication dispense
- Reference: Patient
- Reference: Encounter
- Reference: Base model
- FHIR: MedicationStatement
- Source: medication_statement.py · statement/spec.py · valueset/medication.py