Explore documentation

Creating Appointments

How to book and manage appointments via API

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.

The recommended way to book against a free slot is POST /fhir/Appointment/$book. It takes { slotId, participant[], reasonCode?, comment? } (each participant needs at least status), and:

  1. Checks the slot exists (404 otherwise) and is free.
  2. Checks every participant actor.reference for overlapping appointments.
  3. Atomically claims the slot (free → busy); if two requests race for the same slot, only one wins.
  4. Creates the Appointment with status: "booked", start/end copied from the slot and slot[] pointing at it, and returns it with HTTP 201.
REST
curl -X POST https://api.esus.health/fhir/Appointment/\$book \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/fhir+json" \
  -d '{
    "slotId": "c1a2e3d4-5b6f-7890-abcd-ef1234567890",
    "participant": [
      {
        "actor": { "reference": "Patient/3fa85f64-5717-4562-b3fc-2c963f66afa6", "display": "John Doe" },
        "required": "required",
        "status": "accepted"
      },
      {
        "actor": { "reference": "Practitioner/a7b1c2d3-e4f5-6789-abcd-ef0123456789", "display": "Dr. Sarah Johnson" },
        "required": "required",
        "status": "accepted"
      }
    ],
    "reasonCode": [{
      "coding": [{ "system": "http://snomed.info/sct", "code": "185349003", "display": "Encounter for check up" }]
    }],
    "comment": "Annual wellness checkup"
  }'
SDK
const { body } = await esus.fhir.operation("POST /fhir/Appointment/$book", {
  body: {
    "slotId": "c1a2e3d4-5b6f-7890-abcd-ef1234567890",
    "participant": [
      {
        "actor": {
          "reference": "Patient/3fa85f64-5717-4562-b3fc-2c963f66afa6",
          "display": "John Doe"
        },
        "required": "required",
        "status": "accepted"
      },
      {
        "actor": {
          "reference": "Practitioner/a7b1c2d3-e4f5-6789-abcd-ef0123456789",
          "display": "Dr. Sarah Johnson"
        },
        "required": "required",
        "status": "accepted"
      }
    ],
    "reasonCode": [
      {
        "coding": [
          {
            "system": "http://snomed.info/sct",
            "code": "185349003",
            "display": "Encounter for check up"
          }
        ]
      }
    ],
    "comment": "Annual wellness checkup"
  },
});

Errors are HTTP 400 OperationOutcomes with code invalid: "Slot is not available (status: busy)" when the slot isn’t free, and "Double booking detected" when a participant already has an overlapping appointment (ignoring cancelled, noshow and entered-in-error ones).

Create an Appointment manually

You can also POST /fhir/Appointment directly. Only participant[] is required; status defaults to proposed. The slot[] and participant[].actor references use the standard FHIR reference shape.

Heads up: a manual create that carries slot[] does NOT flip the Slot to busy and does not check the slot’s status — only $book does. The double-booking check runs only when you send both start and end. For bookings against a slot, prefer $book.

REST
curl -X POST https://api.esus.health/fhir/Appointment \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/fhir+json" \
  -d '{
    "status": "pending",
    "serviceType": [{
      "coding": [{
        "system": "http://terminology.hl7.org/CodeSystem/service-type",
        "code": "124",
        "display": "General Practice"
      }]
    }],
    "appointmentType": {
      "coding": [{
        "system": "http://terminology.hl7.org/CodeSystem/v2-0276",
        "code": "ROUTINE",
        "display": "Routine appointment"
      }]
    },
    "start": "2026-04-21T09:00:00Z",
    "end": "2026-04-21T09:30:00Z",
    "minutesDuration": 30,
    "participant": [
      {
        "actor": { "reference": "Patient/3fa85f64-5717-4562-b3fc-2c963f66afa6", "display": "John Doe" },
        "required": "required",
        "status": "needs-action"
      },
      {
        "actor": { "reference": "Practitioner/a7b1c2d3-e4f5-6789-abcd-ef0123456789", "display": "Dr. Sarah Johnson" },
        "required": "required",
        "status": "accepted"
      }
    ],
    "reasonCode": [{
      "coding": [{
        "system": "http://snomed.info/sct",
        "code": "185349003",
        "display": "Encounter for check up"
      }]
    }],
    "description": "Annual wellness checkup"
  }'
SDK
const created = await esus.fhir.create("Appointment", {
  "status": "pending",
  "serviceType": [
    {
      "coding": [
        {
          "system": "http://terminology.hl7.org/CodeSystem/service-type",
          "code": "124",
          "display": "General Practice"
        }
      ]
    }
  ],
  "appointmentType": {
    "coding": [
      {
        "system": "http://terminology.hl7.org/CodeSystem/v2-0276",
        "code": "ROUTINE",
        "display": "Routine appointment"
      }
    ]
  },
  "start": "2026-04-21T09:00:00Z",
  "end": "2026-04-21T09:30:00Z",
  "minutesDuration": 30,
  "participant": [
    {
      "actor": {
        "reference": "Patient/3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "display": "John Doe"
      },
      "required": "required",
      "status": "needs-action"
    },
    {
      "actor": {
        "reference": "Practitioner/a7b1c2d3-e4f5-6789-abcd-ef0123456789",
        "display": "Dr. Sarah Johnson"
      },
      "required": "required",
      "status": "accepted"
    }
  ],
  "reasonCode": [
    {
      "coding": [
        {
          "system": "http://snomed.info/sct",
          "code": "185349003",
          "display": "Encounter for check up"
        }
      ]
    }
  ],
  "description": "Annual wellness checkup"
});

Other optional fields: identifier[], cancelationReason, serviceCategory[], specialty[], priority, slot[], comment, patientInstruction, basedOn[], requestedPeriod[], note[].

Appointment Status Flow

proposed → pending → booked → arrived → fulfilled
                           ↘ cancelled
                           ↘ noshow

The valid transitions are fixed on the server: proposed → {pending, cancelled}, pending → {booked, cancelled}, booked → {arrived, cancelled, noshow}, arrived → {fulfilled, cancelled}. Any other transition returns HTTP 400 (e.g. "Cannot transition from 'booked' to 'fulfilled'").

StatusMeaning
proposedAppointment suggested but not confirmed (default on create)
pendingAwaiting confirmation
bookedConfirmed
arrivedPatient has arrived
fulfilledAppointment completed
cancelledAppointment cancelled
noshowPatient did not attend
checked-inOnly settable on create; no transition leads to it
waitlistOnly settable on create; no outgoing transition (see Waitlist Management)
entered-in-errorOnly settable on create; no transition leads to it

Updating an Appointment

A status change must follow the transitions above; otherwise the API answers 400. You can change the status and other fields in the same request. Resending the current status (e.g. a PUT with the full resource and "status": "booked" on a booked appointment) is not a transition: it is accepted and the other fields are applied. That is why both partial PATCH bodies (application/fhir+json, application/json, application/merge-patch+json) and JSON Patch (application/json-patch+json) work.

Register Patient Arrival

curl -X PATCH https://api.esus.health/fhir/Appointment/d4e5f6a7-b8c9-0123-def4-567890abcdef \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/fhir+json" \
  -d '{ "status": "arrived" }'

Cancel an Appointment

Send the status change and the reason in the same request:

curl -X PATCH https://api.esus.health/fhir/Appointment/d4e5f6a7-b8c9-0123-def4-567890abcdef \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/fhir+json" \
  -d '{
    "status": "cancelled",
    "cancelationReason": {
      "coding": [{
        "system": "http://terminology.hl7.org/CodeSystem/appointment-cancellation-reason",
        "code": "pat",
        "display": "Patient"
      }]
    }
  }'

Then, if the appointment held a slot, set that Slot back to free (see “Slots and Availability”); cancellation doesn’t release it.

Search Appointments

ParameterMatching
_id, statusExact
patientPatient id (Patient/<id> or bare id) among the participants
practitioner, locationId among the participants (Practitioner/<id> / Location/<id> or bare id)
actorPartial match on any participant reference, e.g. actor=Practitioner/<id>
dateOn start; eq (default, same day), gt, lt, ge, le. Repeat it for a range
service-type, specialty, reason-code, slotPartial text match

_sort supports date, status and _lastUpdated (prefix - for descending); the default is start ascending. _include and _revinclude are not supported (accepted and ignored).

REST
# A practitioner's booked appointments on April 21
curl "https://api.esus.health/fhir/Appointment?practitioner=a7b1c2d3-e4f5-6789-abcd-ef0123456789&status=booked&date=ge2026-04-21T00:00:00Z&date=lt2026-04-22T00:00:00Z" \
  -H "Authorization: Bearer YOUR_TOKEN"
SDK
const { resources, total } = await esus.fhir.search("Appointment", {
  "practitioner": "a7b1c2d3-e4f5-6789-abcd-ef0123456789",
  "status": "booked",
  "date": [
    "ge2026-04-21T00:00:00Z",
    "lt2026-04-22T00:00:00Z"
  ]
});