FHIR API
Bulk data export
Export large amounts of data as NDJSON with the asynchronous FHIR Bulk Data pattern.
Bulk export is how analytics platforms, registries and payers pull data out of a FHIR server. It's switched on in this lab (bulk_export_enabled: true).
Start the export#
curl -s -i "$FHIR/\$export?_type=Patient,Observation,Condition" \
-H "Accept: application/fhir+json" -H "Prefer: respond-async" | grep -iE "^(HTTP|content-location)"HTTP/1.1 202 Accepted
Content-Location: http://192.168.1.181:8080/fhir/$export-poll-status?_jobId=5d1c...Poll until it's done#
STATUS="http://192.168.1.181:8080/fhir/\$export-poll-status?_jobId=5d1c..."
until [ "$(curl -s -o /tmp/manifest.json -w '%{http_code}' "$STATUS")" = 200 ]; do sleep 3; done
jq '.output[] | {type, url}' /tmp/manifest.jsonWhile the export is running, the poll returns 202 (often with an X-Progress header). When it's finished, you get 200 and a manifest.
Download the files#
jq -r '.output[].url' /tmp/manifest.json | while read u; do curl -s "$u" | head -c 300; echo; doneEach file is NDJSON: one resource per line. HAPI keeps the files for 2 hours (bulk_export_file_retention_period_hours).
Export levels#
| URL | Exports |
|---|---|
[base]/$export |
Everything (system level) |
[base]/Patient/$export |
All patients and their compartments |
[base]/Group/{id}/$export |
The members of one Group |
Useful parameters are _type, _since (only changes after a time, for incremental feeds) and _typeFilter=Observation?category=laboratory.
In production
Real bulk endpoints are protected by SMART Backend Services, where the client signs a JWT and is issued an access token. See SMART on FHIR.