Medications
MedicationDispense and Pharmacy
How pharmacy dispenses medications to patients
Set up the SDK server client to run the examples using esus. The REST examples use a session token. To run them with the SDK’s API key, send X-API-Key instead of Authorization.
Overview
MedicationDispense represents medication that has been prepared and handed out by a pharmacy. It bridges the gap between the prescriber’s order and the patient’s receipt of the medication.
Use Cases
- Outpatient pharmacy dispensing
- Hospital pharmacy dispensing
- Dispensing history per prescription
Creating a Dispense Record
curl -X POST https://api.esus.health/fhir/MedicationDispense \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/fhir+json" \
-d '{
"status": "completed",
"medicationCodeableConcept": {
"coding": [{
"system": "http://www.nlm.nih.gov/research/umls/rxnorm",
"code": "197361",
"display": "Amoxicillin 500mg capsule"
}]
},
"subjectId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"locationId": "d4e5f6a7-b8c9-0123-def4-567890abcdef",
"performer": [{
"actor": {
"reference": "Organization/9a8b7c6d-5e4f-3210-9876-543210fedcba"
}
}],
"authorizingPrescription": [{
"reference": "MedicationRequest/c1a2e3d4-5b6f-7890-abcd-ef1234567890"
}],
"quantity": { "value": 30, "unit": "capsules" },
"daysSupply": { "value": 10, "unit": "days" },
"whenPrepared": "2026-04-21T09:00:00Z",
"whenHandedOver": "2026-04-21T09:30:00Z",
"dosageInstruction": [{
"text": "Take 1 capsule by mouth 3 times a day for 10 days"
}]
}'
const created = await esus.fhir.create("MedicationDispense", {
"status": "completed",
"medicationCodeableConcept": {
"coding": [
{
"system": "http://www.nlm.nih.gov/research/umls/rxnorm",
"code": "197361",
"display": "Amoxicillin 500mg capsule"
}
]
},
"subjectId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"locationId": "d4e5f6a7-b8c9-0123-def4-567890abcdef",
"performer": [
{
"actor": {
"reference": "Organization/9a8b7c6d-5e4f-3210-9876-543210fedcba"
}
}
],
"authorizingPrescription": [
{
"reference": "MedicationRequest/c1a2e3d4-5b6f-7890-abcd-ef1234567890"
}
],
"quantity": {
"value": 30,
"unit": "capsules"
},
"daysSupply": {
"value": 10,
"unit": "days"
},
"whenPrepared": "2026-04-21T09:00:00Z",
"whenHandedOver": "2026-04-21T09:30:00Z",
"dosageInstruction": [
{
"text": "Take 1 capsule by mouth 3 times a day for 10 days"
}
]
});
Notes:
subjectId(required) andlocationIdare flat UUIDs;locationIdcomes back aslocation: { "reference": "Location/<uuid>" }.statusdefaults tocompleted.performer[]andauthorizingPrescription[]are arrays of standard FHIR references.- Other accepted fields include
encounterId,type,destination,receiver[],substitution(wasSubstitutedis required inside it),statusReasonCodeableConcept,note[].
Dispense Status Values
| Status | Meaning |
|---|---|
preparation | Being prepared |
in-progress | Being dispensed |
on-hold | Paused |
completed | Dispensed and given to the patient (default) |
cancelled | Dispense cancelled |
stopped | Stopped before completion |
declined | Pharmacy declined to dispense |
entered-in-error | Recorded in error |
unknown | Status unknown |
Tracking Refills
Each refill is its own MedicationDispense that points to the same authorizingPrescription. To see every dispense of a prescription:
curl "https://api.esus.health/fhir/MedicationDispense?prescription=c1a2e3d4-5b6f-7890-abcd-ef1234567890" \
-H "Authorization: Bearer YOUR_TOKEN"
const { resources, total } = await esus.fhir.search("MedicationDispense", {
"prescription": "c1a2e3d4-5b6f-7890-abcd-ef1234567890"
});
Search Parameters
| Parameter | Matching |
|---|---|
patient, encounter, location | Exact id |
status | Exact code |
medication | Partial text match on medicationCodeableConcept |
prescription | Partial match on authorizingPrescription (<uuid> or MedicationRequest/<uuid>) |
whenhanded | Date of whenHandedOver (YYYY-MM-DD); without a prefix it matches the whole day. Supports gt, ge, lt, le and ne. Repeat it for a range (whenhanded=ge2026-04-01&whenhanded=lt2026-05-01) |