FHIR Bundle
Bundle is a FHIR Resource that serves as a container for a collection of resources. It can be used in different contexts based on bundle type. Bundle of type Batch allows creating, updating, or deleting multiple records in a single request for efficient processing and reducing the number of individual requests. Bundle of type Document used to group together resources that collectively form a clinical document or a patient record. When performing a search operation in FHIR, the server can respond with a FHIR bundle that contains a set of resources matching the search criteria. FHIR Bundles also serve as a container for exchanging messages between different healthcare systems. They can also be used to represent the history of a resource or a specific version of a resource.
Using FHIR Bundles
The content and rules for using a Bundle depend on the type of the bundle.
Document
A document Bundle (type = "document") consists of a series of entries, the first of which is a Composition. Each entry element SHALL contain a resource.
Message
A message Bundle (type = "message") consists of a series of entries, the first of which is a MessageHeader. Each entry element SHALL contain a resource.
History
A change history (type = "history") consists of a series of 0 or more entries. Each entry element contains a request element that describes the change that was made and, if the method is a POST or PUT, a resource that represents the state of the resource at the conclusion of the operation.
Transaction / Batch
A transaction (type = "transaction") or batch (type = "batch") consists of a series of 0 or more entries. Each entry element SHALL contain a request element with the details of an HTTP operation that informs the system what to do with the entry. If the entry method is a 'PUT' or 'POST', then the entry SHALL contain a resource that becomes the body of the HTTP operation. See Transactions/Batch for further information.
Transaction/Batch Response
A transaction response (type = "transaction-response") or batch response (type="batch-response") consists of a series of 0 or more entries: 1 for each entry in the transaction or batch it is in response to. Each entry element contain a response element which indicates the outcome of the HTTP operation that the server performed for the entry.
Collection
A collection (type = "collection") consists of a series of 0 or more entries. No particular use with respect to the FHIR specification is associated with this FHIR Bundle. Each entry element SHALL contain a resource.
Endpoints
The Bundle resource type has an end-point like all most other resources. This end-point serves the usual interactions. Bundles are treated as static resources on the /Bundle end-point (i.e. when a batch, transaction, or message is POSTed to /Bundle, it is stored as is, and the content is not processed as batch, transaction, or message - instead, they are processed like normal resource, with indexing / auditing etc. Performing a GET /Bundle/[location] will return the same resource.
{{fhir_base}}/fhir/Bundle
Resolving references in Bundle
References in a Bundle are resolved in the next way(only for Bundle type "transaction"):
- If the reference is not an absolute reference, it is converted to an absolute URL:
- if the reference has the format [type]/[id], and
- if the fullUrl for the bundle entry containing the resource is a RESTful one the [root] from the fullUrl is extracted, and the reference (type/id) appended to it then it is resolved within the bundle as for a RESTful URL reference. If no resolution is possible, then the reference has no defined meaning within this specification
- else no resolution is possible and the reference has no defined meaning within this specification
- else
- Kodjin looks for an entry with a fullUrl that matches the URI in the reference
- if no match is found, and the URI is a URL that can be resolved (starts with Kodjin host), Kodjin tries accessing it directly(get by id))
Note also that transactions may contain conditional references that are resolved by the Kodjin FHIR Server before processing the matches.