Class 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
    • Method Detail

      • 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.
      • addTransactionDeleteEntry

        public void addTransactionDeleteEntry​(IBaseResource theResource)
        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

        public void addTransactionDeleteEntry​(String theResourceType,
                                              String theIdPart)
        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.
      • addEntry

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

        public IBaseBackboneElement addSearch​(IBase entry)
        Creates new search instance for the specified entry
        Parameters:
        entry - Entry to create search instance for
        Returns:
        Returns the search instance
      • 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.