FHIR API
Operations
Server-side functions called with $: $everything, $validate, $meta, $diff and $expunge.
Operations extend REST with named functions. You call them with GET (when they don't change anything) or POST with a Parameters body.
$everything#
Everything about one patient, in a Bundle:
curl -s "$FHIR/Patient/1234/\$everything?_count=200" | jq '[.entry[].resource.resourceType] | group_by(.) | map({(.[0]): length}) | add'Useful parameters are start and end (date window), _type=Observation,Condition and _since. Results are paged, so follow next links.
$validate#
Ask the server whether a resource is valid, without saving it:
curl -s -X POST "$FHIR/Patient/\$validate" -H "Content-Type: application/fhir+json" -d @patient.json \
| jq '.issue[] | {severity, diagnostics, location}'To validate against a profile, add ?profile=http://hl7.org.au/fhir/core/StructureDefinition/au-core-patient. The server can only use profiles it has loaded; see Validate on the server.
$meta, $meta-add, $meta-delete#
Tags, profiles and security labels can be changed without creating a new version of the content:
curl -s -X POST "$FHIR/Patient/1234/\$meta-add" -H "Content-Type: application/fhir+json" -d '{
"resourceType":"Parameters",
"parameter":[{"name":"meta","valueMeta":{"tag":[{"system":"https://fhirdrill.dev/tags","code":"drill-3"}]}}]}'
curl -s "$FHIR/Patient?_tag=https://fhirdrill.dev/tags|drill-3&_summary=count"Tag your practice data
Tag what you create in each drill. Cleaning up afterwards is then a single conditional delete on _tag.
$diff#
HAPI can show what changed between two versions:
curl -s "$FHIR/Patient/drill-linh/\$diff?fromVersion=1&toVersion=3" | jq '.parameter[] | {op: .part[0].valueCode, path: .part[1].valueString}'$expunge#
$expunge permanently removes deleted resources, or old versions. It's switched on in this lab (expunge_enabled, delete_expunge_enabled).
# Remove old versions of one resource and keep the current one
curl -s -X POST "$FHIR/Patient/drill-linh/\$expunge" -H "Content-Type: application/fhir+json" \
-d '{"resourceType":"Parameters","parameter":[{"name":"expungePreviousVersions","valueBoolean":true}]}'
# Remove every deleted Patient for good
curl -s -X POST "$FHIR/Patient/\$expunge" -H "Content-Type: application/fhir+json" \
-d '{"resourceType":"Parameters","parameter":[{"name":"expungeDeletedResources","valueBoolean":true}]}'To wipe the whole server, see Reset or wipe the server.
Find every operation the server supports#
curl -s "$FHIR/metadata" | jq -r '.rest[0].operation[].name, (.rest[0].resource[] | select(.operation) | .type + ": " + ([.operation[].name] | join(", ")))'