Explore documentation

DocumentReference

Creating and managing document references

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.

What is DocumentReference?

DocumentReference is a metadata resource that describes and locates a document. It does not contain the document bytes — it points to where they are stored (typically a file uploaded with POST /files/upload).

API convention: the patient is sent as a flat id (subjectId) and returned as subject: { "reference": "Patient/<id>" }. Author, authenticator, custodian and context.encounter keep the standard FHIR reference shape. All ids are UUIDs.

Create a DocumentReference

content is the only required field (at least one item, each with an attachment). status defaults to current. If subjectId is given, it must be a patient in your organization, otherwise the request fails with 400.

REST
curl -X POST https://api.esus.health/fhir/DocumentReference \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/fhir+json" \
  -d '{
    "status": "current",
    "docStatus": "final",
    "type": {
      "coding": [{
        "system": "http://loinc.org",
        "code": "34117-2",
        "display": "History and physical note"
      }]
    },
    "category": [{
      "coding": [{
        "system": "http://hl7.org/fhir/document-class",
        "code": "clinical-notes",
        "display": "Clinical Notes"
      }]
    }],
    "subjectId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "date": "2026-04-21T10:30:00Z",
    "author": [{
      "reference": "Practitioner/a7b1c2d3-e4f5-6789-abcd-ef0123456789",
      "display": "Dr. Sarah Johnson"
    }],
    "description": "Annual wellness examination",
    "content": [{
      "attachment": {
        "contentType": "application/pdf",
        "url": "https://api.esus.health/files/b8f0c2d1-9e3a-4f5b-8c7d-1a2b3c4d5e6f",
        "title": "Annual Wellness Exam.pdf",
        "creation": "2026-04-21T10:30:00Z"
      }
    }],
    "context": {
      "encounter": [
        { "reference": "Encounter/c1a2e3d4-5b6f-7890-abcd-ef1234567890" }
      ],
      "period": {
        "start": "2026-04-21T09:00:00Z",
        "end": "2026-04-21T10:00:00Z"
      }
    }
  }'
SDK
const created = await esus.fhir.create("DocumentReference", {
  "status": "current",
  "docStatus": "final",
  "type": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "34117-2",
        "display": "History and physical note"
      }
    ]
  },
  "category": [
    {
      "coding": [
        {
          "system": "http://hl7.org/fhir/document-class",
          "code": "clinical-notes",
          "display": "Clinical Notes"
        }
      ]
    }
  ],
  "subjectId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "date": "2026-04-21T10:30:00Z",
  "author": [
    {
      "reference": "Practitioner/a7b1c2d3-e4f5-6789-abcd-ef0123456789",
      "display": "Dr. Sarah Johnson"
    }
  ],
  "description": "Annual wellness examination",
  "content": [
    {
      "attachment": {
        "contentType": "application/pdf",
        "url": "https://api.esus.health/files/b8f0c2d1-9e3a-4f5b-8c7d-1a2b3c4d5e6f",
        "title": "Annual Wellness Exam.pdf",
        "creation": "2026-04-21T10:30:00Z"
      }
    }
  ],
  "context": {
    "encounter": [
      {
        "reference": "Encounter/c1a2e3d4-5b6f-7890-abcd-ef1234567890"
      }
    ],
    "period": {
      "start": "2026-04-21T09:00:00Z",
      "end": "2026-04-21T10:00:00Z"
    }
  }
});

The response is 201 Created with the stored resource (including id and meta.versionId). Other accepted fields: identifier, authenticator, custodian, relatesTo, securityLabel, and context.facilityType / context.practiceSetting.

DocumentReference Status

StatusMeaning
currentThe document is current and available (default)
supersededReplaced by a newer version
entered-in-errorThe reference is incorrect

Any other value is rejected with 422. docStatus (e.g. preliminary, final, amended) is free text.

Search Documents

ParameterMatching
patientExact patient id (<id> or Patient/<id>)
statusExact
typeSubstring of the stored type JSON — pass a code, e.g. type=34117-2
categorySubstring of the stored category JSON, e.g. category=clinical-notes
dateOn date. Without a prefix, the same calendar day; supports gt, ge, lt, le, ne (e.g. date=ge2026-04-01). Repeat it for a range (date=ge2026-04-01&date=lt2026-05-01)
authorSubstring of the stored author JSON, e.g. a practitioner id
encounterSubstring of the stored context JSON, e.g. an encounter id
# All documents for a patient
curl "https://api.esus.health/fhir/DocumentReference?patient=3fa85f64-5717-4562-b3fc-2c963f66afa6" \
  -H "Authorization: Bearer YOUR_TOKEN"

# Clinical notes only
curl "https://api.esus.health/fhir/DocumentReference?patient=3fa85f64-5717-4562-b3fc-2c963f66afa6&category=clinical-notes" \
  -H "Authorization: Bearer YOUR_TOKEN"

# Documents dated on a given day
curl "https://api.esus.health/fhir/DocumentReference?patient=3fa85f64-5717-4562-b3fc-2c963f66afa6&date=2026-04-21" \
  -H "Authorization: Bearer YOUR_TOKEN"

Reading and Downloading a Document

# Read the metadata
curl "https://api.esus.health/fhir/DocumentReference/c1a2e3d4-5b6f-7890-abcd-ef1234567890" \
  -H "Authorization: Bearer YOUR_TOKEN"

# Download the file referenced in content[0].attachment.url
curl "https://api.esus.health/files/b8f0c2d1-9e3a-4f5b-8c7d-1a2b3c4d5e6f" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  --output downloaded.pdf

Esus does not resolve the attachment URL for you: your client reads content[0].attachment.url and calls it with the same credentials.