Explore documentation

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

REST
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"
    }]
  }'
SDK
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) and locationId are flat UUIDs; locationId comes back as location: { "reference": "Location/<uuid>" }. status defaults to completed.
  • performer[] and authorizingPrescription[] are arrays of standard FHIR references.
  • Other accepted fields include encounterId, type, destination, receiver[], substitution (wasSubstituted is required inside it), statusReasonCodeableConcept, note[].

Dispense Status Values

StatusMeaning
preparationBeing prepared
in-progressBeing dispensed
on-holdPaused
completedDispensed and given to the patient (default)
cancelledDispense cancelled
stoppedStopped before completion
declinedPharmacy declined to dispense
entered-in-errorRecorded in error
unknownStatus unknown

Tracking Refills

Each refill is its own MedicationDispense that points to the same authorizingPrescription. To see every dispense of a prescription:

REST
curl "https://api.esus.health/fhir/MedicationDispense?prescription=c1a2e3d4-5b6f-7890-abcd-ef1234567890" \
  -H "Authorization: Bearer YOUR_TOKEN"
SDK
const { resources, total } = await esus.fhir.search("MedicationDispense", {
  "prescription": "c1a2e3d4-5b6f-7890-abcd-ef1234567890"
});

Search Parameters

ParameterMatching
patient, encounter, locationExact id
statusExact code
medicationPartial text match on medicationCodeableConcept
prescriptionPartial match on authorizingPrescription (<uuid> or MedicationRequest/<uuid>)
whenhandedDate 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)