Explore documentation

Encounter

Learn about the Encounter resource for patient visits and interactions.

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 Encounter resource represents an interaction between a patient and a healthcare provider. Every visit, consultation, emergency, or inpatient stay is recorded as an Encounter.

API convention: the patient reference is sent as a flat string field (subjectId), and the service provider organization as serviceProviderId, instead of nested FHIR reference objects. References inside participant, diagnosis, and location use the standard shape ({ "reference": "Practitioner/<uuid>" }). All ids are raw UUIDs (v4) — no type prefixes.

Creating an Encounter

REST
curl -X POST https://api.esus.health/fhir/Encounter \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/fhir+json" \
  -d '{
    "status": "arrived",
    "class": "AMB",
    "subjectId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "serviceProviderId": "b8c2d3e4-f5a6-7890-bcde-f01234567890",
    "participant": [
      {
        "type": [{ "coding": [{ "code": "PPRF", "display": "primary performer" }] }],
        "individual": {
          "reference": "Practitioner/a7b1c2d3-e4f5-6789-abcd-ef0123456789",
          "display": "Dr. Maria Garcia"
        }
      }
    ],
    "reasonCode": [
      { "coding": [{ "system": "http://snomed.info/sct", "code": "29857009", "display": "Chest pain" }] }
    ]
  }'
SDK
const created = await esus.fhir.create("Encounter", {
  "status": "arrived",
  "class": "AMB",
  "subjectId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "serviceProviderId": "b8c2d3e4-f5a6-7890-bcde-f01234567890",
  "participant": [
    {
      "type": [
        {
          "coding": [
            {
              "code": "PPRF",
              "display": "primary performer"
            }
          ]
        }
      ],
      "individual": {
        "reference": "Practitioner/a7b1c2d3-e4f5-6789-abcd-ef0123456789",
        "display": "Dr. Maria Garcia"
      }
    }
  ],
  "reasonCode": [
    {
      "coding": [
        {
          "system": "http://snomed.info/sct",
          "code": "29857009",
          "display": "Chest pain"
        }
      ]
    }
  ]
});

Required: class and subjectId. If you omit status, it is stored as planned. The patient (and the organization, if you send one) must exist in your organization; otherwise the API answers 400. The 201 Created response returns the patient as subject: { "reference": "Patient/<uuid>" } and the class as class: { "code": "AMB" }.

Encounter Class

class is a short string code (max 20 characters). The API does not validate it against a code system, so use the HL7 v3 ActCode values:

CodeDescription
AMBAmbulatory / office visit
EMEREmergency
IMPInpatient (the one $admit uses)
SSShort stay / day hospital
HHHome health
VRVirtual / telehealth

Statuses and Transitions

StatusMeaningCan move to
plannedScheduled, not yet startedarrived, cancelled
arrivedPatient has arrivedtriaged, in-progress, cancelled
triagedPatient triaged, waitingin-progress, cancelled
in-progressEncounter ongoingonleave, finished, cancelled
onleavePatient temporarily awayin-progress, finished
finishedEncounter completed—
cancelledEncounter cancelled—

On update, a status change must follow this table; otherwise the API answers 400 with Cannot transition from '<current>' to '<new>'. The API fills the period itself: period.start when moving to in-progress (if not already set, and also when you create the encounter directly as in-progress) and period.end when moving to finished or cancelled.

You can change status and other fields in the same request. Repeating the current status (e.g. in-progress → in-progress, as happens with a PUT of the full resource or a JSON Patch) is not a transition: it is accepted, the other fields are applied and the period is left untouched.

PUT and PATCH only accept status, type, participant, reasonCode, diagnosis, hospitalization, and location: class, subjectId, and serviceProviderId cannot be changed after the encounter is created.

Searching Encounters

ParameterBehavior
_idExact id
patient / subjectPatient id (<uuid> or Patient/<uuid>)
status, classExact
participant / actorContains match on a participant’s individual.reference (Practitioner/<uuid> or just <uuid>)
service-providerOrganization id
type, reason-codePartial text inside the CodeableConcept
dateDate of period.start, with optional prefix eq, gt, lt, ge, or le (e.g. date=ge2026-04-01). Repeat it for a range (date=ge2026-04-01&date=lt2026-05-01)

Page with _count and _offset, and sort with _sort by _lastUpdated, date, or status (prefix - for descending).

REST
curl "https://api.esus.health/fhir/Encounter?patient=3fa85f64-5717-4562-b3fc-2c963f66afa6&status=in-progress" \
  -H "Authorization: Bearer YOUR_TOKEN"
SDK
const { resources, total } = await esus.fhir.search("Encounter", {
  "patient": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "status": "in-progress"
});

Read, delete, and _history work the same as for Patient: see CRUD Operations.

Inpatient Operations

OperationBodyWhat it does
POST /fhir/Encounter/$admit{ subjectId, bedLocationRef, participant? }Creates an in-progress encounter with class IMP assigned to the bed. Answers 201. If the bed is occupied: 400
POST /fhir/Encounter/{id}/$discharge—Moves the encounter to finished and sets period.end. Answers 200. Only from in-progress or onleave (other statuses: 400); on an already finished encounter it answers 200 without touching period.end
POST /fhir/Encounter/{id}/$transfer{ bedLocationRef }Closes the active location and assigns the new bed. Only for in-progress encounters; target bed occupied: 400. Answers 200
GET /fhir/Encounter/{id}/$everything—Bundle with the encounter and every resource that references it (observations, conditions, procedures, allergies, immunizations, prescriptions, etc.)

bedLocationRef is the bed reference, for example "Location/<uuid>".

Each $everything entry uses the same FHIR shape as an individual GET. The bundle includes only resource types your credential may read; it does not expand your permissions.

Why Encounters Matter

Linking observations, conditions, procedures, and other records to an Encounter (via encounterId) builds the patient’s care journey and lets you fetch it whole with $everything. The link is optional, but use it whenever the record comes from a visit.