Skip to content
@deckyard/fhir

fhir cheatsheet

Every export of @deckyard/fhir. Guides are listed in the introduction.

jennifer
import "@deckyard/fhir/" as fhir;

A request the FHIR server refused throws HttpError (kind fhir.http), with status and the OperationOutcome's issues as fields; every other failure is Error{kind: "fhir"} (a refused SMART token request carries the OAuth error). A c argument is a Client; resources, bundles and patches are json.Value; a query is a list of string of name=value search parameters.

Constants

ConstantValueMeaning
DEFAULT_TIMEOUT_MS60000how long one request may take
DEFAULT_MAX_BYTES8388608the largest response read
DEFAULT_MAX_PAGES100the most pages search and history follow

The client

FunctionReturnsDoes
fhir.client(baseUrl)Clienta client; plain http only to this machine
fhir.withToken(c, token)Clientsend Authorization: Bearer <token>
fhir.withHeader(c, name, value)Clientsend another header
fhir.withTls(c, tls)Clientcertificate options (caCert, skipVerify)
fhir.withPlainHttp(c)Clientallow plain http to another machine
fhir.withTimeout(c, ms)Clientthe deadline of one request, 1000 to 86400000 ms
fhir.withMaxBytes(c, most)Clientthe largest response, 65536 to 268435456 bytes
fhir.withMaxPages(c, pages)Clientthe page cap of search and history
fhir.smartConfiguration(c)json.Valuethe server's .well-known/smart-configuration
fhir.smartBackend(c, clientId, scope, alg, key, kid)Clientauthorise as a SMART backend service (RS384 / ES384 client assertion, kid required)

Interactions

FunctionReturnsDoes
fhir.capabilities(c)json.Valuethe CapabilityStatement
fhir.read(c, type, id)json.Valuea resource
fhir.vread(c, type, id, version)json.Valueone version of a resource
fhir.search(c, type, query)list of json.Valuethe matching resources, every page, within maxPages and maxBytes
fhir.searchBundle(c, type, query)json.Valuethe first page of a search
fhir.nextBundle(c, b)list of json.Valuethe next page, or nothing
fhir.create(c, resource)json.Valuecreate; the server assigns the id
fhir.update(c, resource)json.Valueupdate, only if meta.versionId is current when it is set
fhir.patch(c, type, id, operations, version)json.Valueapply a JSON Patch, only to version when not ""
fhir.delete(c, type, id)nulldelete a resource
fhir.history(c, type, id)list of json.Valueevery version of a resource, newest first
fhir.transaction(c, b)json.Valuerun a transaction bundle, all or nothing
fhir.batch(c, b)json.Valuerun a batch bundle, entry by entry
fhir.operation(c, path, parameters)json.Valueinvoke $name, Type/$name or Type/id/$name
fhir.call(c, method, path, query, body)json.Valueany other request

Resources

FunctionReturnsDoes
fhir.resourceType(r)stringthe resourceType
fhir.idOf(r)stringthe id, "" if none
fhir.versionOf(r)stringmeta.versionId, "" if none
fhir.reference(type, id)stringType/id
fhir.referenceOf(r)stringthe resource's Type/id
fhir.identifier(system, value)json.Valuean Identifier; neither may be empty
fhir.identifierValue(r, system)stringthe value of the resource's identifier in a system
fhir.coding(system, code, display)json.Valuea Coding
fhir.concept(system, code, display)json.Valuea CodeableConcept with one coding
fhir.hasCoding(c, system, code)boolwhether a CodeableConcept has a coding
fhir.bundle(type)json.Valuea bundle without entries: transaction, batch, collection, document, message
fhir.entry(b, method, url, resource, fullUrl)json.Valueadd a checked request entry to a transaction or batch
fhir.resourcesOf(b)list of json.Valuethe resources of a bundle's entries
fhir.issues(outcome)list of Issuethe issues of an OperationOutcome

Types

Client

FieldMeaning
baseUrl as stringthe server's base URL, without a trailing slash
headers as map of string to stringheaders sent with every request
tls as http.TlsOptionscertificate checks for https
allowPlainHttp as boolplain http to another machine allowed
timeoutMs as intthe deadline of one request
maxBytes as intthe largest response
maxPages as intthe page cap of search and history

HttpError

Thrown, not returned: test $e.kind == "fhir.http" before reading the other fields.

FieldMeaning
kind as stringfhir.http
message as stringthe request, the server's diagnostics and (HTTP nnn)
status as intthe HTTP status, such as 404, 409 or 412
issues as list of Issuethe OperationOutcome's issues, empty when there was none

Issue

FieldMeaning
severity as stringfatal, error, warning, information
code as stringthe issue type, such as not-found
diagnostics as stringthe server's diagnostic text
text as stringdetails.text
expression as list of stringwhere in the resource, as FHIRPath