View raw Markdown
type: resourceresource: profile-batch-bundle

profile-batch-bundle

Introduction

Scope and Usage

One common operation performed with resources is to gather a collection of resources into a single instance with containing context. In FHIR this is referred to as "bundling" the resources together. These resource bundles are useful for a variety of different reasons, including:

Boundaries and Relationships

There are two ways to collect resources together for transport and persistence purposes - contained resources, and bundles. There is an important difference between the two:

In addition to these two technical mechanisms, there are three administrative and infrastructure resources which also support grouping of content. These resources do not contain resources directly, but instead use [Reference] to point to the grouped resources:

These three resources represent meaningful groupings of the resources they refer to (e.g. a discharge medication List, a Group of participants for a clinical trial, a set of resources that form a signed document), while a Bundle is merely is a container for resources used for transfer and storage. This list is not exhaustive; other resources also provide grouping functionality.

Notes

Notes about Bundle

Using Additional Resources in Bundles

Bundle entries contain resources which may be either be one of the <%res-type-count%> resources defined in this specification, or an additional resource.

In JSON, this looks like:

{ "resourceType" : "Bundle", "entry" : [{ "resource" : { "resourceType" : "ViewDefinition", "resourceDefinition" : "http://hl7.org/fhir/uv/sql-on-fhir/StructureDefinition/ViewDefinition|2.0.0-pre", "id": "a-valid-id", // etc } }] }

In XML, this looks like:

<Bundle xmlns="http://hl7.org/fhir"> <entry> <resource> // etc <ViewDefinition> </resource> </entry> </Bundle>

Using Bundles

The content and rules for using a Bundle depend on the type of the bundle. Note that all bundle types use resource identity resolution as described below.

Document

A document Bundle (type = "document") consists of a series of entries, the first of which is a Composition. Each entry element contains a resource. See Documents for further information.

Example

Message

A message Bundle (type = "message") consists of a series of entries, the first of which is a MessageHeader. Each entry element contains a resource. See Messaging for further information.

Example Request and Response

Search Results

A set of search results (type = "searchset") consists of a series of 0 or more entries. Each entry element contains a resource. See Search for further information.

In addition, Bundle.total may be used to return the total number of resources that match the search, and that may be returned by following the "next" link. This total MAY be an estimate. Full iteration of the search set or using _total=accurate are the only mechanisms to reliably determine an exact count against an arbitrary system.

For each entry, a search set can also contain two specific pieces of search related information:

Example

History

A change history (type = "history") consists of a series of 0 or more entries. Each entry element SHALL contain a request element that describes the change that was made and, if the method is a POST, PATCH, or PUT, a resource that represents the state of the resource at the conclusion of the operation. A response element SHALL also be present so that consumers can access the location header. See History for further information.

In addition, Bundle.total may be used to return the total number of resources that are included in the change history, including those that may be returned by following the "next" link.

Transaction / Batch

A transaction (type = "transaction") or batch (type = "batch") consists of a series of 0 or more entries. Each entry element contains a request element has the details of an HTTP operation that informs the system processing the transaction what to do with the entry. If the entry method is a 'PUT', 'PATCH' or 'POST', then the entry contains a resource that becomes the body of the HTTP operation. See Transactions for further information.

Example

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 contains a response element which indicates the outcome of the HTTP operation that the server performed for the entry.

Example

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 Bundle. Each entry element contains a resource.

Example

Subscription Notification

A subscription notification (type = "subscription-notification") consists of a series of 1 or more entries, the first of which is a SubscriptionStatus. There may be additional contents, as specified by the subscription responsible for generating the notification. See Subscription for further information.

Examples

Resource URL & Uniqueness rules in a bundle

Except for transactions and batches, each entry in a Bundle SHALL have a fullUrl which is the identity of the resource in the entry. Note that this is not a versioned reference to the resource, but its identity. Where a resource is not assigned a persistent identity that can be used in the Bundle, a UUID SHALL be used in fullUrl (urn:uuid:...).

For transactions and batches, entries MAY omit fullURLs when the entry.request.method = POST, and the resource has no identity. Note that even in this case, there may still be a fullURL in a transaction when entry.request.method = POST so that relationships between resources can be represented (see Transactions).

A given version of a resource SHALL only appear once in each Bundle. There MAY, however, be multiple versions of a single resource present in a single bundle. This would be expected in Bundles of type history, and also might be necessitated by closely tracking Provenance.

Note that the meaning of an unversioned reference to a resource that appears multiple times is potentially ambiguous, though processors may have additional information to help resolve this (e.g. change order in a history bundle).

When processing batches and transactions, it is at server discretion how to behave if multiple versions of a single resource are present.

Resolving references in Bundles

The Bundle resource is a packaging construct that has one of more entries that are other kinds of resources. Those resources themselves have references to other resources - e.g. an Observation that refers to a Patient. The referenced resources may also be found in the Bundle. For example, the system that constructed the Bundle may have included both the Observation and the Patient. The content of the references between resources doesn't change because of the bundle.

This section documents a method that resolves references correctly within a bundle. Note that this method does not define any new semantics; resolution is based on the way resource identity and resource references work.

Applications reading a Bundle should always look for a resource by its identity in the bundle first before trying to access it by its URL externally.

Note that reference.reference in entry resources can use any URI scheme (in addition to using relative values like "Patient/123").

How to resolve a reference in a Bundle:

Resolving urns. If the reference.reference is a URN (always absolute) (e.g. "urn:uuid:9d1714da-b7e6-455b-bfd2-69ce0ff5fb12")

Resolving absolute references. If the reference.reference is an absolute URL (e.g., "https://fhir.example.org/base/Patient/123", "https://fhir.example.org/base/Patient/123/_history/a"):

Resolving relative references against a RESTful base. If the reference.reference is of the form "[type]/[id]" (e.g., "Patient/123"):

Resolving conditional references. If the reference occurs in a transaction Bundle and the reference.reference is a conditional reference (e.g. "http://example.org/base/Patient?identifier=1234"):

NOTE: It is sometimes not safe to perform resolution of conditional references within the Bundle because in some cases there may be multiple matches which, once the data hits the server, will turn into a single match due to mutually exclusive conditional create/conditional update rules.

Resolving canonical references: If the canonical reference is version-specific, look for an entry with a matching URL and version. If the canonical omits version, look for an entry with a matching URL and if there is more than one, find the most recent version based on the versionAlgorithm. If there is exactly one, it's a match. If there are no matches, then resolve as an external canonical as usual. If there is more than one, it's an error.

Resolving other references. If the rules above do not apply, the resolution fails (and ends) here. The reference has no defined meaning within this specification.

Note that the rules for resolving references in contained resources are the same as those for resolving references in the resource that contains the contained resource. I.e. the fullUrl of the containing resource is used when determining the base for relative references, etc.

Several portions of this algorithm are dependent on on the presence of Bundle.entry.fullUrl. In instances where references might be resolved within a Bundle but entries do not have fullURLs, resolution expectations are undefined. For this reason, Bundles where cross-Bundle references are present SHOULD always populate Bundle.entry.fullUrl.

If multiple matches are found (except where explicitly handled in the above algorithm), it is ambiguous which is correct. Applications MAY return an error or take some other action as they deem appropriate

There is an example Bundle that demonstrates these rules.

Graph-connected Bundles

Both FHIR messages and FHIR documents have a requirement that all entries within the Bundle are interconnected. This expectation means that all entries in the Bundle must produce a single graph of interconnected resources. These connections might be via Reference, canonical, url, or "href" references within narrative.

Note that some references might be 'reverse' references, such as Provenances that point to resources within the Bundle. These references are resolved as defined above.

Serving Bundles using the RESTful API

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 /[base]/Bundle/[location] will return the same resource.

The Bundle end point does have two special search parameters - composition and message, which allow for chained search into the first (special) entries in document and message resources.

All elements in Bundle are marked as summary because Bundle resources need to be fully populated when doing a search, and most use cases for retrieving summaries of documents or other types of bundles are not well suited by the standard isSummary mechanism and are better handles by operations or other mechanisms.

[%stu-note dstu%] If an element marked as 'summary' is itself a nested resource (i.e. type is Resource), then the expectation is that the conveyed resource will also be expressed in its summary form. The typical place this applies is Bundle.entry.resource. This statement is left as STU because there is not yet significant implementer experience on its ramifications. [%end-note%]

Signatures

The Bundle resource includes a signature element (digital signature) which can be used for standards based integrity verification and non-repudiation purposes. The Signature datatype provides details on use of the signature element. The Signature.type coded value of "Source" should be used when the signature is for simply proving that the resource content is the same as it was when the resource was updated or created.

StructureDefinition

Elements (Simplified)

Mappings

Mapping Exceptions

bundle-fivews-mapping-exceptions.xml

Unmapped Elements