Class BundleBuilder

java.lang.Object
ca.uhn.fhir.util.BundleBuilder

public class BundleBuilder extends Object
This class can be used to build a Bundle resource to be used as a FHIR transaction. Convenience methods provide support for setting various bundle fields and working with bundle parts such as metadata and entry (method and search).

This is not yet complete, and doesn't support all FHIR features. USE WITH CAUTION as the API may change.

Since:
5.1.0
  • Constructor Details

  • Method Details

    • setBundleField

      public BundleBuilder setBundleField(String theFieldName, String theFieldValue)
      Sets the specified primitive field on the bundle with the value provided.
      Parameters:
      theFieldName - Name of the primitive field.
      theFieldValue - Value of the field to be set.
    • setSearchField

      public BundleBuilder setSearchField(IBase theSearch, String theFieldName, String theFieldValue)
      Sets the specified primitive field on the search entry with the value provided.
      Parameters:
      theSearch - Search part of the entry
      theFieldName - Name of the primitive field.
      theFieldValue - Value of the field to be set.
    • setSearchField

      public BundleBuilder setSearchField(IBase theSearch, String theFieldName, IPrimitiveType<?> theFieldValue)
    • addTransactionFhirPatchEntry

      Adds a FHIRPatch patch bundle to the transaction
      Parameters:
      theTarget - The target resource ID to patch
      thePatch - The FHIRPath Parameters resource
      Since:
      6.3.0
    • addTransactionFhirPatchEntry

      Adds a FHIRPatch patch bundle to the transaction. This method is intended for conditional PATCH operations. If you know the ID of the resource you wish to patch, use addTransactionFhirPatchEntry(IIdType, IBaseParameters) instead.
      Parameters:
      thePatch - The FHIRPath Parameters resource
      Since:
      6.3.0
      See Also:
    • addTransactionUpdateEntry

      Adds an entry containing an update (PUT) request. Also sets the Bundle.type value to "transaction" if it is not already set.
      Parameters:
      theResource - The resource to update
    • addTransactionUpdateIdOnlyEntry

      Adds an entry containing an update (UPDATE) request without the body of the resource. Also sets the Bundle.type value to "transaction" if it is not already set.
      Parameters:
      theResource - The resource to update.
    • addTransactionCreateEntry

      Adds an entry containing an create (POST) request. Also sets the Bundle.type value to "transaction" if it is not already set.
      Parameters:
      theResource - The resource to create
    • addTransactionCreateEntry

      public BundleBuilder.CreateBuilder addTransactionCreateEntry(IBaseResource theResource, @Nullable String theFullUrl)
      Adds an entry containing an create (POST) request. Also sets the Bundle.type value to "transaction" if it is not already set.
      Parameters:
      theResource - The resource to create
      theFullUrl - The fullUrl to attach to the entry. If null, will default to the resource ID.
    • addTransactionCreateEntryIdOnly

      Adds an entry containing a create (POST) request without the body of the resource. Also sets the Bundle.type value to "transaction" if it is not already set.
      Parameters:
      theResource - The resource to create
    • addTransactionDeleteConditionalEntry

      Adds an entry containing a delete (DELETE) request. Also sets the Bundle.type value to "transaction" if it is not already set.

      Note that the resource is only used to extract its ID and type, and the body of the resource is not included in the entry,

      Parameters:
      theCondition - The conditional URL, e.g. "Patient?identifier=foo|bar"
      Since:
      6.8.0
    • addTransactionDeleteEntry

      Adds an entry containing a delete (DELETE) request. Also sets the Bundle.type value to "transaction" if it is not already set.

      Note that the resource is only used to extract its ID and type, and the body of the resource is not included in the entry,

      Parameters:
      theResource - The resource to delete.
    • addTransactionDeleteEntry

      Adds an entry containing a delete (DELETE) request. Also sets the Bundle.type value to "transaction" if it is not already set.

      Note that the resource is only used to extract its ID and type, and the body of the resource is not included in the entry,

      Parameters:
      theResourceId - The resource ID to delete.
      Returns:
    • addTransactionDeleteEntry

      Adds an entry containing a delete (DELETE) request. Also sets the Bundle.type value to "transaction" if it is not already set.
      Parameters:
      theResourceType - The type resource to delete.
      theIdPart - the ID of the resource to delete.
    • addTransactionDeleteEntryConditional

      Adds an entry containing a delete (DELETE) request. Also sets the Bundle.type value to "transaction" if it is not already set.
      Parameters:
      theMatchUrl - The match URL, e.g. Patient?identifier=http://foo|123
      Since:
      6.3.0
    • addCollectionEntry

      public void addCollectionEntry(IBaseResource theResource)
      Adds an entry for a Collection bundle type
    • addDocumentEntry

      public void addDocumentEntry(IBaseResource theResource)
      Adds an entry for a Document bundle type
    • addEntry

      public IBase addEntry()
      Creates new entry and adds it to the bundle
      Returns:
      Returns the new entry.
    • addSearch

      Creates new search instance for the specified entry. Note that this method does not work for DSTU2 model classes, it will only work on DSTU3+.
      Parameters:
      entry - Entry to create search instance for
      Returns:
      Returns the search instance
    • addEntryAndReturnRequest

    • getBundle

    • getBundleTyped

      public <T extends IBaseBundle> T getBundleTyped()
      Convenience method which auto-casts the results of getBundle()
      Since:
      6.3.0
    • setMetaField

      public BundleBuilder setMetaField(String theFieldName, IBase theFieldValue)
      Note that this method does not work for DSTU2 model classes, it will only work on DSTU3+.
    • addToEntry

      public void addToEntry(IBase theEntry, String theEntryChildName, IBase theValue)
      Sets the specified entry field.
      Parameters:
      theEntry - The entry instance to set values on
      theEntryChildName - The child field name of the entry instance to be set
      theValue - The field value to set
    • addToSearch

      public void addToSearch(IBase theSearch, String theSearchFieldName, IBase theSearchFieldValue)
      Sets the specified search field.
      Parameters:
      theSearch - The search instance to set values on
      theSearchFieldName - The child field name of the search instance to be set
      theSearchFieldValue - The field value to set
    • newPrimitive

      public <T> IPrimitiveType<T> newPrimitive(String theTypeName)
      Creates a new primitive.
      Type Parameters:
      T - Actual type of the parameterized primitive type interface
      Parameters:
      theTypeName - The element type for the primitive
      Returns:
      Returns the new empty instance of the element definition.
    • newPrimitive

      public <T> IPrimitiveType<T> newPrimitive(String theTypeName, T theInitialValue)
      Creates a new primitive instance of the specified element type.
      Type Parameters:
      T - Actual type of the parameterized primitive type interface
      Parameters:
      theTypeName - Element type to create
      theInitialValue - Initial value to be set on the new instance
      Returns:
      Returns the newly created instance
    • setType

      public void setType(String theType)
      Sets a value for Bundle.type. That this is a coded field so theType must be an actual valid value for this field or a DataFormatException will be thrown.
    • setIdentifier

      public void setIdentifier(@Nullable String theSystem, @Nullable String theValue)
      Adds an identifier to Bundle.identifier
      Parameters:
      theSystem - The system
      theValue - The value
      Since:
      6.4.0
    • setTimestamp

      public void setTimestamp(@Nonnull IPrimitiveType<Date> theTimestamp)
      Sets the timestamp in Bundle.timestamp
      Since:
      6.4.0
    • addProfile

      public void addProfile(String theProfile)
      Adds a profile URL to Bundle.meta.profile
      Since:
      7.4.0