Clinical resources
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 asserviceProviderId, instead of nested FHIR reference objects. References insideparticipant,diagnosis, andlocationuse the standard shape ({ "reference": "Practitioner/<uuid>" }). All ids are raw UUIDs (v4) — no type prefixes.
Creating an Encounter
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" }] }
]
}'
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:
| Code | Description |
|---|---|
AMB | Ambulatory / office visit |
EMER | Emergency |
IMP | Inpatient (the one $admit uses) |
SS | Short stay / day hospital |
HH | Home health |
VR | Virtual / telehealth |
Statuses and Transitions
| Status | Meaning | Can move to |
|---|---|---|
planned | Scheduled, not yet started | arrived, cancelled |
arrived | Patient has arrived | triaged, in-progress, cancelled |
triaged | Patient triaged, waiting | in-progress, cancelled |
in-progress | Encounter ongoing | onleave, finished, cancelled |
onleave | Patient temporarily away | in-progress, finished |
finished | Encounter completed | — |
cancelled | Encounter 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
| Parameter | Behavior |
|---|---|
_id | Exact id |
patient / subject | Patient id (<uuid> or Patient/<uuid>) |
status, class | Exact |
participant / actor | Contains match on a participant’s individual.reference (Practitioner/<uuid> or just <uuid>) |
service-provider | Organization id |
type, reason-code | Partial text inside the CodeableConcept |
date | Date 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).
curl "https://api.esus.health/fhir/Encounter?patient=3fa85f64-5717-4562-b3fc-2c963f66afa6&status=in-progress" \
-H "Authorization: Bearer YOUR_TOKEN"
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
| Operation | Body | What 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.