Skip to main content
Version: 3.1

Medication request

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

A medication request records one medicine ordered for a patient in an encounter. It can belong to a prescription, which groups medication requests of the same encounter, but the link is optional.

Source:

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

Models​

ModelPurpose
MedicationRequestOne medicine ordered for a patient within an encounter
MedicationRequestPrescriptionAn optional group of medication requests in one encounter (a prescription)

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

MedicationRequest 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.

Order status & intent​

FieldModel typeSpec typeRequired (API)Notes
statusCharField(100), nullableMedicationRequestStatusYesNo default in the model or the spec. Can change after create. See status values
status_reasonCharField(100), nullableStatusReason | NoneNoFixed. See status reason values
intentCharField(100), nullableMedicationRequestIntentYesFixed
categoryCharField(100), nullableMedicationRequestCategoryYesFixed
priorityCharField(100), nullableMedicationRequestPriorityYesFixed
do_not_performBooleanField, no defaultboolYesFixed
dispense_statusCharField(100), nullable, default nullMedicationRequestDispenseStatus | NoneNoCan change after create. Dispensing also changes it, see Methods & save behaviour

Medication & dosage​

FieldModel typeSpec typeRequired (API)Notes
medicationJSONField, default {}, nullableValueSetBoundCoding[system-medication] | NoneConditionalOne Coding bound to the Medication value set. Send exactly one of medication and requested_product. Fixed
methodJSONField, default {}, nullableNot in any specn/aStored only. The administration method travels on each dosage line as dosage_instruction[].method
dosage_instructionJSONField, default [], nullablelist[DosageInstruction]YesThe list can be empty. See DosageInstruction. Fixed
noteTextField, nullablestr | NoneNoCan change after create. Sending null does not clear it

Subject & provenance​

FieldModel typeSpec typeRequired (API)Notes
patientFK → Patient, CASCADENot acceptedServer-setCopied from the encounter on create
encounterFK → Encounter, CASCADEUUID4Yes (create)Must exist ("Encounter not found"). Dropped from an update body. Read returns the encounter id
authored_onDateTimeField, nullable, default timezone.nowdatetimeYesNo validator: no time-zone check and no future-date check. The model default does not apply to API creates. Fixed
requesterFK → users.User, SET_NULLUUID4 | NoneNoThe requester must also pass the write check, see Authorization. Cannot change after create
requested_productFK → ProductKnowledge, SET_NULLUUID4 | NoneConditionalA product of the encounter's facility, or a product with no facility. Fixed
prescriptionFK → MedicationRequestPrescription, SET_NULLUUID4 | NoneNoMust be in the same encounter. Or use create_prescription. Fixed

Enum values​

Enum values use underscores (on_hold, entered_in_error, original_order). They are the exact strings that the API accepts and returns.

MedicationRequestStatus values​

Value
active
on_hold
ended
stopped
completed
cancelled
entered_in_error
draft
unknown

StatusReason values​

Value
altchoice
clarif
drughigh
hospadm
labint
non_avail
preg
salg
sddi
sdupther
sintol
surg
washout

MedicationRequestIntent values​

Value
proposal
plan
order
original_order
reflex_order
filler_order
instance_order

MedicationRequestPriority values​

Value
routine
urgent
asap
stat

MedicationRequestCategory values​

Value
inpatient
outpatient
community
discharge

MedicationRequestDispenseStatus values​

ValueSet by
completeA dispense saved with fully_dispensed: true, or a client update
partialA dispense saved with fully_dispensed: false, or a client update
incompleteCancelling a dispense that has a charge item, cancelling a dispense order, or a client update
declinedOnly a client update. No Care code sets it

TimingUnit values​

Used by Timing.repeat.period_unit and by the unit of every TimingQuantity (bounds_duration, bounds_range.low, bounds_range.high).

Value
s
min
h
d
wk
mo
a

DoseType values​

Used by DoseAndRate.type.

Value
ordered
calculated

DosageInstruction nested spec​

Each entry of the dosage_instruction list is a DosageInstruction. Keys are snake_case, as the spec declares them.

FieldTypeRequiredNotes
sequenceint | NoneNoOrder of the instruction
textstr | NoneNoFree-text dosage instruction
additional_instructionlist[Coding] | NoneNoEach bound to the Additional Instruction value set
patient_instructionstr | NoneNo
timingTiming | NoneNoSee the sub-types below
as_needed_booleanboolYesThe only required field
as_needed_forCoding | NoneNoBound to the As Needed value set
siteCoding | NoneNoBound to the Body Site value set
routeCoding | NoneNoBound to the Route value set
methodCoding | NoneNoBound to the Administration Method value set
dose_and_rateDoseAndRate | NoneNo
max_dose_per_periodDoseRange | NoneNo

Sub-types under DosageInstruction​

Timing {
repeat: TimingRepeat # required
code: Coding | None
}

TimingRepeat {
frequency: int # required
period: Decimal(20,0) # required, whole number
period_unit: TimingUnit # required
bounds_duration: TimingQuantity | None
bounds_range: TimingRange | None
bounds_period: PeriodSpec | None
} # at least one bound is required

TimingQuantity {
value: Decimal(20,0) # required, whole number
unit: TimingUnit # required
}

TimingRange {
low: TimingQuantity # required
high: TimingQuantity # required
}

PeriodSpec {
start: datetime | None # time zone required when set
end: datetime | None # time zone required when set
} # start cannot be after end

DoseAndRate {
type: DoseType # required
dose_range: DoseRange | None
dose_quantity: DosageQuantity | None
}

DoseRange {
low: DosageQuantity # required
high: DosageQuantity # required
}

DosageQuantity {
value: Decimal(20,6) # required
unit: Coding # required
}

Coding {
system: str | None
version: str | None
code: str # required
display: str | None
} # unknown keys are refused

A TimingRepeat with no bound fails with "At least one of bounds_duration, bounds_range, or bounds_period is required". bounds_range and bounds_period were added in June 2026.

Bound value sets​

Coded fields bind to Care value sets through ValueSetBoundCoding[<slug>]. Every write checks the code against the value set and refuses a code outside it ("Code does not exist in the valueset").

FieldValue set slugSNOMED CT scope
medicationsystem-medication<< 763158003 Medicinal product
dosage_instruction[].routesystem-routeis-a 284009009
dosage_instruction[].sitesystem-body-siteis-a 91723000
dosage_instruction[].methodsystem-administration-methodis-a 736665006
dosage_instruction[].as_needed_forsystem-as-needed-reasonis-a 404684003
dosage_instruction[].additional_instructionsystem-additional-instructionis-a 419492006

Care checks codes against the copy of each 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 the scope above.

The same directory defines system-medication-not-given. No medication spec binds it.

MedicationRequestPrescription​

A prescription groups medication requests of one encounter. Each request points to at most one prescription through MedicationRequest.prescription.

encounter → FK Encounter (CASCADE)
patient → FK Patient (CASCADE)
name → CharField(100), nullable
note → TextField, nullable
prescribed_by → FK users.User (CASCADE, nullable)
status → CharField(100), nullable → MedicationRequestPrescriptionStatus
approval_status → CharField(100), nullable; no spec reads or writes it
alternate_identifier → CharField(100), nullable; set only through create_prescription
tags → ArrayField[int], default []
tags_data → JSONField, default {}; added in the 3.1 release

The unique_alternate_identifier_encounter constraint keeps alternate_identifier unique within an encounter.

tags_data holds the expiry of each tag, keyed by the tag id as a string. Care writes the entry when a tag is set with an expiry and removes it when the tag is removed.

tags_data = {
"<tag id>": { "expiry": "<ISO date-time>" }
}

On a read, a rendered tag that has an expiry carries expiry, and also expired: true after that time.

MedicationRequestPrescriptionStatus values​

Value
active
on_hold
ended
stopped
completed
cancelled
entered_in_error
draft

There is no unknown value. A user who passes only the pharmacist check can set active, on_hold or completed (MEDICATION_PRESCRIPTION_PHARMACIST_ALLOWED_STATUS), see Authorization.

Prescription specs​

The prescription resource leaves patient and encounter out of the automatic field copy.

Spec classRoleNotes
BaseMedicationRequestPrescriptionSpecsharedid, status (required), note, name
MedicationRequestPrescriptionWriteSpecwrite · createAdds encounter and prescribed_by (both required UUIDs). patient comes from the encounter. No alternate_identifier
MedicationRequestPrescriptionUpdateSpecwrite · updateThe shared fields: status (required), note, name
MedicationRequestPrescriptionReadSpecread · listAdds created_date, modified_date, prescribed_by (UserSpec) and the rendered tags
MedicationRequestPrescriptionRetrieveSpecread · sharedAdds created_by and updated_by. Base of the next two
MedicationRequestPrescriptionRetrieveMedicationsSpecread · detailAdds the full encounter (EncounterRetrieveSpec) and medications: every medication request of the prescription in any status, deleted ones left out, each as MedicationRequestReadWithoutPrescriptionSpec
MedicationRequestPrescriptionRetrieveDetailedSpecread · facility summary itemAdds the encounter in its list form. No medications

Resource specs (API schema)​

Resource specs never copy foreign keys automatically. MedicationRequestResource also lists patient, encounter, requester, requested_product and prescription in __exclude__, and the extra (de)serialization hooks set them.

Spec classRoleNotes
MedicationRequestResourceshared (binding)Binds the specs to MedicationRequest and declares __exclude__
MedicationRequestAbstractSpecshared (fields)status, status_reason, intent, category, priority, do_not_perform, medication, dosage_instruction, authored_on, note, dispense_status
BaseMedicationRequestSpecsharedThe binding plus the fields plus id
MedicationRequestSpecwrite · createAdds encounter (required), requester, requested_product, prescription and create_prescription. Holds the validators
MedicationRequestUpdateSpecwrite · updateOnly status (required), note and dispense_status
MedicationRequestReadWithoutPrescriptionSpecread · embeddedAdds created_by, updated_by, created_date, modified_date, requested_product (ProductKnowledgeReadSpec) and requester (UserSpec). Used for the medications of an opened prescription
MedicationRequestReadSpecread · list and detailAdds prescription (prescription read spec) and the encounter id
CreatePrescriptionwrite · nestedname (optional), note (optional), alternate_identifier (required)

Validation (create)​

  • Sending both medication and requested_product fails with "Cannot have both medication and requested product". Sending neither fails with "Either medication or requested product is required".
  • Sending both prescription and create_prescription fails with "Cannot have both prescription and create_prescription".
  • The encounter must exist ("Encounter not found").
  • A requested_product of another facility fails with "Product not found in facility". A product with no facility passes.
  • A prescription id must belong to the same encounter, or Care answers 404. Its status is not checked on this path.
  • authored_on has no validator. Only a PeriodSpec (bounds_period) requires time-zone-aware date-times.
  • The update spec has no status-transition rule. Any status can follow any status.

Server-side side effects​

  • patient is copied from the encounter, never from the URL or the body.
  • With create_prescription, Care looks for a prescription with the same alternate_identifier in the encounter. A match that is not active fails with "Prescription is not active". An active match is reused.
  • With no match, Care creates an active prescription with that identifier, the given name and note, and the request's requester as prescribed_by.
  • Every create and update also writes a questionnaire response with structured type medication_request and submit type CREATE or UPDATE.

Methods & save behaviour​

The models define no save() or delete() override. The behaviour below lives in the specs and the viewsets.

  • Create runs in this order: validate the body, authorize, build the record (the extra deserialization checks run here), 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.
  • Dispensing changes dispense_status. A dispense with fully_dispensed set marks the request complete (true) or partial (false).
  • Cancelling a dispense that has a charge item sets the request to incomplete and removes the link from the dispense. Cancelling a dispense order does the same for each of its dispenses.
  • A prescription created through the prescription endpoint writes no questionnaire response.

API integration notes​

Endpoints​

All paths are under /api/v1/.

MethodPathAction
GETpatient/{patient_id}/medication/request/List
POSTpatient/{patient_id}/medication/request/Create
GETpatient/{patient_id}/medication/request/{id}/Retrieve
PUT, PATCHpatient/{patient_id}/medication/request/{id}/Update. Both use MedicationRequestUpdateSpec
DELETEpatient/{patient_id}/medication/request/{id}/Soft delete
POSTpatient/{patient_id}/medication/request/upsert/Batch create or update, see Upsert
GET, POSTpatient/{patient_id}/medication/prescription/List, create
GET, PUT, PATCHpatient/{patient_id}/medication/prescription/{id}/Retrieve, update. Both updates use MedicationRequestPrescriptionUpdateSpec. There is no delete
POSTpatient/{patient_id}/medication/prescription/upsert/Batch create or update
POSTpatient/{patient_id}/medication/prescription/{id}/set_tags/Set tags
POSTpatient/{patient_id}/medication/prescription/{id}/remove_tags/Remove tags
GETfacility/{facility_id}/medication_prescription/summary/Prescriptions of every encounter in the facility, newest first. The only action on this route

The tag body is {"tags": [{"tag": "<tag config id>", "expiry_offset": ...}]}. The 3.1 release changed it from a plain list of tag ids. Tags can also go in the create body of a prescription.

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
Medication request: listWith ?facility=: "Pharmacist in Care" in any department of that facility. Otherwise "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 facility or encounter filter then limits the results to that facility or encounter
Medication request: retrieveThe read check of the list runs first
Medication request: create, upsert items without idClinical write on the encounter in the body. Else 403 "You do not have permission to update encounter"
Medication request: create with requesterThe requester also has clinical write on that encounter. Else 403 "Requester does not have permission to update encounter"
Medication request: update, deleteThe read check of the list runs first. Then clinical write on the record's encounter
Prescription: listThe same read check as medication requests
Prescription: retrieve"Can Read encounter" on its encounter, or "Pharmacist in Care" in its facility. Else 403 "Access Denied to prescription"
Prescription: createClinical write on the encounter
Prescription: update, set tags, remove tagsClinical write allows any change. Otherwise "Pharmacist in Care" in the encounter's facility, else 403 "Access Denied to prescription"
Prescription: update by a pharmacist-only userA new status must be active, on_hold or completed, else 403 "You do not have permission to update medication request prescription". Only status is saved. No encounter-status condition applies
Facility summary"Pharmacist in Care" in the facility of the URL. Else 403 "You do not have permission to view this facility"

"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 Read encounter"Doctor, Nurse, Facility Admin
"Can view clinical data about patients"Staff, Doctor, Nurse, Facility Admin
"Pharmacist in Care"Facility Admin, Pharmacist

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​

Medication request list:

ParameterMeaning
encounterEncounter id
statusComma-separated statuses
nameMedicine display contains the text, case-insensitive
encounter_classDoes not work: Care answers HTTP 500. The filter is declared on encounter__class, but the encounter's field is encounter_class
priorityExact priority, case-insensitive
dispense_status, exclude_dispense_statusComma-separated dispense statuses to keep or to leave out
dispense_status_isnullRequests with or without a dispense status
facilityFacility of the encounter. Also turns on the pharmacist read check
prescriptionPrescription id
product_typeType of the requested product: medication, nutritional_product or consumable
medications_onlytrue keeps requests for a medication product and requests with no product
orderingcreated_date or modified_date. Without it, newest record first

Prescription list: encounter, status (comma-separated), facility, a created_date range, and tags with tags_behavior (any, the default, or all). Ordering by created_date or modified_date.

Facility summary: a created_date range, status (one value, case-insensitive), patient_external_id, encounter_external_id, encounter_class (on the encounter's encounter_class field) and the tag filter.

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​

  • Send each coded field as one Coding object, {system, version, code, display}, with a code from the bound value set.
  • status has no backend default. The Care frontend starts each new medicine at active, intent order, priority routine, category inpatient, with the signed-in user as requester. It has no category or priority field.
  • The Care frontend saves medicines through the upsert. Each save sends one new create_prescription identifier and no name, so the new medicines of one save share one prescription.
  • The Care frontend never deletes a medication request. Its "remove" sets the status to entered_in_error.
  • requester, requested_product and prescription are SET_NULL links. The prescription's prescribed_by is a CASCADE link. These rules act only when a row is removed from the database. The API delete and the model delete() are soft and do not trigger them.
  • No deployment setting is specific to this resource.