FHIR R5 Bundle resource.
A container for a collection of resources. Used for transactions, search results, documents, messages, and more.
https://www.hl7.org/fhir/R5/bundle.html
Bundle types
document | message | transaction | transaction-response |
batch | batch-response | history | searchset | collection |
subscription-notification
Building bundles
Use the builder helpers rather than constructing the struct directly:
alias FhirEx.Resources.Bundle
# Transaction bundle (create/update/delete in one request)
bundle = Bundle.transaction([
Bundle.entry(patient, request: %{method: "POST", url: "Patient"}),
Bundle.entry(obs, request: %{method: "PUT", url: "Observation/obs-001"})
])
# Batch bundle
bundle = Bundle.batch([
Bundle.entry(patient, request: %{method: "GET", url: "Patient/p-001"})
])
# Searchset (list of matching resources)
bundle = Bundle.searchset([Bundle.entry(patient)], total: 1)
# Collection (simple grouping)
bundle = Bundle.collection([Bundle.entry(patient), Bundle.entry(obs)])
json = FhirEx.JSON.encode!(bundle)Entries
Bundle.entry/2 builds a BundleEntry map. Options:
Bundle.entry(resource,
full_url: "urn:uuid:abc",
request: %{method: "POST", url: "Patient"},
search: %{mode: "match", score: 1.0}
)Decoding
When decoding a Bundle, each entry's :resource is kept as a raw
map() because the resource type is only known at runtime. Decode
individual entries with the appropriate resource module:
%Bundle{} = bundle = FhirEx.JSON.decode!(json, Bundle)
patient = FhirEx.Resources.Patient.from_map(bundle.entry |> hd() |> Map.get(:resource))
Summary
Functions
Builds a batch bundle from a list of entries.
Builds a collection bundle from a list of entries.
Builds a document bundle from a list of entries.
Builds a bundle entry map.
Builds the struct from a string-keyed map (e.g., from decoded FHIR JSON).
Builds a new struct from a map or keyword list of field values.
Returns the FHIR resource type name string.
Builds a searchset bundle. Pass total: to set the search total.
Converts the struct to a string-keyed map for use with FhirEx.JSON.
Builds a transaction bundle from a list of entries.
Types
@type entry() :: %{ link: [link()] | nil, full_url: String.t() | nil, resource: struct() | map() | nil, search: search_info() | nil, request: request_info() | nil, response: response_info() | nil }
@type t() :: %FhirEx.Resources.Bundle{ entry: [entry()] | nil, id: String.t() | nil, identifier: FhirEx.Types.Identifier.t() | nil, link: [link()] | nil, meta: FhirEx.Types.Meta.t() | nil, timestamp: String.t() | nil, total: non_neg_integer() | nil, type: String.t() }
Functions
Builds a batch bundle from a list of entries.
Builds a collection bundle from a list of entries.
Builds a document bundle from a list of entries.
Builds a bundle entry map.
Options:
full_url— the full URL for this entry (e.g."urn:uuid:abc")request— a map with:methodand:url(and optional:if_matchetc.)search— a map with optional:mode("match"|"include"|"outcome") and:scoreresponse— a map with:status, optional:location,:etag,:last_modified,:outcome
Builds the struct from a string-keyed map (e.g., from decoded FHIR JSON).
Builds a new struct from a map or keyword list of field values.
@spec resource_type() :: String.t()
Returns the FHIR resource type name string.
Builds a searchset bundle. Pass total: to set the search total.
Converts the struct to a string-keyed map for use with FhirEx.JSON.
Builds a transaction bundle from a list of entries.