Class TransactionBuilder
- Namespace
- ToFhir
- Assembly
- ToFhir.dll
Builder for creating FHIR transaction bundles. By default, using the update-as-create approach.
public sealed class TransactionBuilder
- Inheritance
-
TransactionBuilder
- Inherited Members
Methods
AddDeleteEntries(params ResourceReference[])
Adds references to resources that should be deleted as part of the transaction.
public TransactionBuilder AddDeleteEntries(params ResourceReference[] resources)
Parameters
resourcesResourceReference[]References to the resources to delete.
Returns
- TransactionBuilder
This builder instance for chaining.
AddDeleteEntries(IEnumerable<ResourceReference>)
Adds a sequence of references to resources that should be deleted.
public TransactionBuilder AddDeleteEntries(IEnumerable<ResourceReference> resources)
Parameters
resourcesIEnumerable<ResourceReference>References to the resources to delete.
Returns
- TransactionBuilder
This builder instance for chaining.
AddDeleteEntry(ResourceReference)
Adds a reference to a resource that should be deleted as part of the transaction.
public TransactionBuilder AddDeleteEntry(ResourceReference resource)
Parameters
resourceResourceReferenceA reference to the resource to delete.
Returns
- TransactionBuilder
This builder instance for chaining.
AddEntries(params Resource[])
Adds FHIR resources to the transaction bundle.
public TransactionBuilder AddEntries(params Resource[] resources)
Parameters
resourcesResource[]The FHIR resources to add to the bundle.
Returns
- TransactionBuilder
This builder instance for chaining.
AddEntries(IEnumerable<Resource>)
Adds a sequence of FHIR resources to the transaction bundle.
public TransactionBuilder AddEntries(IEnumerable<Resource> resources)
Parameters
resourcesIEnumerable<Resource>The FHIR resources to add to the bundle.
Returns
- TransactionBuilder
This builder instance for chaining.
AddEntry(Resource)
Adds a FHIR resource to the transaction bundle.
public TransactionBuilder AddEntry(Resource resource)
Parameters
resourceResourceThe FHIR resource to add to the bundle.
Returns
- TransactionBuilder
This builder instance for chaining.
Build()
Builds and returns a FHIR Bundle with the configured type.
public Bundle Build()
Returns
- Bundle
A new Bundle instance with the configured type.
Exceptions
- InvalidOperationException
FailOnDuplicateEntries() is enabled and duplicate resource ids were found.
BuildWithSeparateProvenance()
Builds and returns two FHIR Bundles: a data bundle containing only the data resources and delete entries, and a provenance bundle containing the Provenance resource(s) and optionally the Device resource (if configured via WithProvenance(Device, ResourceReference)). The provenance bundle always uses Hl7.Fhir.Model.Bundle.BundleType.Transaction.
public DataAndProvenanceBundles BuildWithSeparateProvenance()
Returns
- DataAndProvenanceBundles
The data and provenance bundles.
Exceptions
- InvalidOperationException
Provenance has not been enabled via WithProvenance(ResourceReference, ResourceReference) or WithProvenance(Device, ResourceReference), or FailOnDuplicateEntries() is enabled and duplicate resource ids were found.
FailOnDuplicateEntries()
Configures the builder to throw if multiple resources with the same id are added when the transaction is built.
public TransactionBuilder FailOnDuplicateEntries()
Returns
- TransactionBuilder
This builder instance for chaining.
WithFullUrlBase(string)
Sets an absolute base URL used to build each entry's fullUrl as
<baseUrl>/<ResourceType>/<id>, making the fullUrl absolute as FHIR
requires. Plain ResourceType/id references used elsewhere in the bundle (e.g. in a
Provenance.target) still resolve correctly against it, since those match by the tail
of a hierarchical fullUrl. The base URL does not need to be a real, dereferenceable server
endpoint.
public TransactionBuilder WithFullUrlBase(string baseUrl)
Parameters
baseUrlstringAn absolute base URL, e.g.
https://example.org/fhir(a trailing slash is optional).
Returns
- TransactionBuilder
This builder instance for chaining.
WithId(string)
Sets the id of the bundle.
public TransactionBuilder WithId(string id)
Parameters
idstringThe id to set for the bundle.
Returns
- TransactionBuilder
This builder instance for chaining.
WithProvenance(Device, ResourceReference)
Enables the inclusion of a Provenance resource in the transaction bundle, using the given
Device as the Provenance.agent.who.
public TransactionBuilder WithProvenance(Device device, ResourceReference what)
Parameters
deviceDeviceThe Device resource representing the agent responsible for the transformation or deletion. The resource is automatically added to the bundle and referenced in the
Provenance.agent.whoelement.whatResourceReferenceA reference to the resource that is the source of the transformation.
Returns
- TransactionBuilder
This builder instance for chaining.
WithProvenance(ResourceReference, ResourceReference)
Enables the inclusion of a Provenance resource in the transaction bundle, with the specified
Provenance.agent.who and Provenance.entity.what references. If the bundle
contains both delete and update/create entries, two Provenance resources will be included.
The Provenance.id is built from the hash of the who and
what references.
public TransactionBuilder WithProvenance(ResourceReference who, ResourceReference what)
Parameters
whoResourceReferenceA reference to the agent responsible for the transformation or deletion. This is typically the transformation service itself.
whatResourceReferenceA reference to the resource that is the source of the transformation.
Returns
- TransactionBuilder
This builder instance for chaining.
WithType(BundleType)
Sets the bundle type.
public TransactionBuilder WithType(Bundle.BundleType bundleType)
Parameters
bundleTypeBundle.BundleTypeThe type of bundle to build.
Returns
- TransactionBuilder
This builder instance for chaining.