Documents
Document Searching
Search patterns across document resources
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.
Supported Search Parameters
Each document resource implements its own set of filters. Parameters not listed here are ignored (they do not cause an error), so a typo silently returns unfiltered results.
| Parameter | DocumentReference | DiagnosticReport | Composition | Media |
|---|---|---|---|---|
patient | ✓ | ✓ | ✓ | ✓ |
status | ✓ | ✓ | ✓ | ✓ |
type | ✓ | — | ✓ | ✓ |
code | — | ✓ | — | — |
category | ✓ | ✓ | — | — |
date | ✓ | ✓ (effectiveDateTime) | ✓ | — |
encounter | ✓ | ✓ | ✓ | — |
author | ✓ | — | — | — |
result | — | ✓ | — | — |
Matching rules:
patient,statusand (except on DocumentReference)encounterare exact matches.patientaccepts<id>orPatient/<id>.type,code,category,author,result(andencounteron DocumentReference) are substring matches over the stored JSON. Pass a bare code or id (type=34105-7); thesystem|codetoken form does not match.datewithout a prefix matches the same calendar day; thegt,ge,lt,leandneprefixes are applied (date=ge2026-04-01). Repeating the parameter combines the bounds, sodate=ge2026-04-01&date=lt2026-05-01is a closed range.
Pagination and Result Shaping
_count(default 20, max 100) and_offset; the Bundle includestotaland alinkwithrelation: "next"when there are more results._summary=countreturns onlytotal;_elements=a,btrims each resource to the listed top-level fields._sortis not applied by these resources: results come back in database order. Sort client-side if you need a timeline._includeand_revincludeare not supported: they are accepted and ignored, and the Bundle only contains matches. Fetch the referenced Patient or Encounter with its own request.
Full-text search over file contents, chained search, and a per-resource $export are not available. For large exports use the system-level Bulk Export (see Platform Features).
Filter Examples
Discharge summaries
curl "https://api.esus.health/fhir/DocumentReference?patient=3fa85f64-5717-4562-b3fc-2c963f66afa6&type=34105-7" \
-H "Authorization: Bearer YOUR_TOKEN"
const { resources, total } = await esus.fhir.search("DocumentReference", {
"patient": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"type": "34105-7"
});
Clinical notes by author
curl "https://api.esus.health/fhir/DocumentReference?patient=3fa85f64-5717-4562-b3fc-2c963f66afa6&author=a7b1c2d3-e4f5-6789-abcd-ef0123456789" \
-H "Authorization: Bearer YOUR_TOKEN"
const { resources, total } = await esus.fhir.search("DocumentReference", {
"patient": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"author": "a7b1c2d3-e4f5-6789-abcd-ef0123456789"
});
Reports that include a given Observation
curl "https://api.esus.health/fhir/DiagnosticReport?result=aa11bb22-cc33-dd44-ee55-ff6677889900" \
-H "Authorization: Bearer YOUR_TOKEN"
const { resources, total } = await esus.fhir.search("DiagnosticReport", {
"result": "aa11bb22-cc33-dd44-ee55-ff6677889900"
});
Updates, History and Optimistic Concurrency
All four resources support PUT (merge: fields you omit are kept), PATCH (partial object, application/json-patch+json or application/merge-patch+json), DELETE (204), and history via GET /:id/_history and GET /:id/_history/:vid.
PUT and PATCH responses include an ETag: W/"<versionId>" header; on reads, use meta.versionId. Send it back in If-Match and, if the resource has changed in the meantime, the write is rejected with 412 Precondition Failed. Without If-Match the write always proceeds.
Privacy and Access Control
- Tenant isolation: every query is scoped to your organization (PostgreSQL RLS).
- RBAC / ABAC: each request is checked against your role and policies; API keys need the matching scope (e.g.
DocumentReference.read). - Consent: reading, updating or deleting a specific patient’s document requires an active treatment
Consentfor that patient (admins and API keys are exempt). Search also requires an explicit patient filter and that patient’s active treatment consent; create does not require prior consent. - Audit: FHIR accesses and file downloads are written to the audit trail.