Skip to content

API Examples

Shinren Pan edited this page Jun 12, 2026 · 1 revision

API Examples

All examples assume the server is running at http://localhost:8080.

All FHIR requests use Content-Type: application/fhir+json. All responses are application/fhir+json.

Patient

Create

curl -X POST http://localhost:8080/Patient \
  -H "Content-Type: application/fhir+json" \
  -d '{
    "resourceType": "Patient",
    "identifier": [{"system": "http://www.boma.mohw.gov.tw", "value": "A123456789"}],
    "name": [{"use": "official", "family": "王", "given": ["小明"]}],
    "gender": "male",
    "birthDate": "1990-01-15"
  }'
# → 201 Created, Location: http://localhost:8080/Patient/{id}/_history/1

Read

curl http://localhost:8080/Patient/{id}

Update

curl -X PUT http://localhost:8080/Patient/{id} \
  -H "Content-Type: application/fhir+json" \
  -H "If-Match: W/\"1\"" \
  -d '{"resourceType":"Patient","id":"{id}","gender":"female",...}'

Delete

curl -X DELETE http://localhost:8080/Patient/{id}
# → 204 No Content

Search

# By name (prefix match)
curl "http://localhost:8080/Patient?name=王"

# By identifier
curl "http://localhost:8080/Patient?identifier=http://www.boma.mohw.gov.tw|A123456789"

# By birthdate range
curl "http://localhost:8080/Patient?birthdate=ge1980-01-01&birthdate=lt1990-01-01"

# With pagination
curl "http://localhost:8080/Patient?_count=10&_sort=-_lastUpdated"

Observation

Create (lab result)

curl -X POST http://localhost:8080/Observation \
  -H "Content-Type: application/fhir+json" \
  -d '{
    "resourceType": "Observation",
    "status": "final",
    "category": [{"coding": [{"system": "http://terminology.hl7.org/CodeSystem/observation-category", "code": "laboratory"}]}],
    "code": {"coding": [{"system": "http://loinc.org", "code": "2093-3", "display": "Cholesterol [Mass/volume] in Serum or Plasma"}]},
    "subject": {"reference": "Patient/{id}"},
    "effectiveDateTime": "2024-01-15T09:00:00+08:00",
    "valueQuantity": {"value": 185, "unit": "mg/dL", "system": "http://unitsofmeasure.org", "code": "mg/dL"}
  }'

Search observations for a patient

curl "http://localhost:8080/Observation?patient=Patient/{id}&status=final&_sort=-date"

History

# Instance history
curl http://localhost:8080/Patient/{id}/_history

# Type history
curl "http://localhost:8080/Patient/_history?_since=2024-01-01&_count=50"

# System history
curl "http://localhost:8080/_history?_since=2024-01-01"

# Read specific version
curl http://localhost:8080/Patient/{id}/_history/3

Compartment Search

Get all clinical resources for a patient:

curl "http://localhost:8080/Patient/{id}/Observation"
curl "http://localhost:8080/Patient/{id}/Condition"
curl "http://localhost:8080/Patient/{id}/MedicationRequest"
curl "http://localhost:8080/Patient/{id}/Encounter"

Transaction Bundle

Atomic create/update/delete across multiple resources:

curl -X POST http://localhost:8080/ \
  -H "Content-Type: application/fhir+json" \
  -d '{
    "resourceType": "Bundle",
    "type": "transaction",
    "entry": [
      {
        "fullUrl": "urn:uuid:patient-1",
        "resource": {"resourceType": "Patient", "name": [{"family": "王"}]},
        "request": {"method": "POST", "url": "Patient"}
      },
      {
        "resource": {
          "resourceType": "Observation",
          "status": "final",
          "subject": {"reference": "urn:uuid:patient-1"},
          "code": {"coding": [{"system": "http://loinc.org", "code": "2093-3"}]}
        },
        "request": {"method": "POST", "url": "Observation"}
      }
    ]
  }'

_include / _revinclude

# Include the Patient referenced by each Observation
curl "http://localhost:8080/Observation?patient=Patient/{id}&_include=Observation:patient"

# Include all Observations referencing matching Patients
curl "http://localhost:8080/Patient?name=王&_revinclude=Observation:patient"

Conditional Operations

# Conditional create (only if no match exists)
curl -X POST http://localhost:8080/Patient \
  -H "Content-Type: application/fhir+json" \
  -H "If-None-Exist: identifier=http://www.boma.mohw.gov.tw|A123456789" \
  -d '{"resourceType":"Patient",...}'

# Conditional update
curl -X PUT "http://localhost:8080/Patient?identifier=http://www.boma.mohw.gov.tw|A123456789" \
  -H "Content-Type: application/fhir+json" \
  -d '{"resourceType":"Patient",...}'

Capability Statement

curl http://localhost:8080/metadata

Health & Metrics

curl http://localhost:8080/health
curl http://localhost:8080/metrics   # Prometheus text format

SMART on FHIR (when enabled)

# Discovery
curl http://localhost:8080/.well-known/smart-configuration

# Authenticated request
curl http://localhost:8080/Patient \
  -H "Authorization: Bearer <jwt-token>"

Clone this wiki locally