Class TerserUtilHelper


  • public class TerserUtilHelper
    extends Object
    Wrapper class holding context-related instances, and the resource being operated on. Sample use case is
    
     TerserUtilHelper helper = TerserUtilHelper.newHelper(ourFhirContext, "Patient");
     helper.setField("identifier.system", "http://org.com/sys");
     helper.setField("identifier.value", "123");
     ...
     Patient patient = helper.getResource();
     
    • Method Detail

      • newHelper

        public static TerserUtilHelper newHelper​(FhirContext theFhirContext,
                                                 String theResourceName)
        Factory method for creating a new instance of the wrapper
        Parameters:
        theFhirContext - FHIR Context to be used for all further operations
        theResourceName - Name of the resource type
        Returns:
        Returns a new helper instance
      • newHelper

        public static TerserUtilHelper newHelper​(FhirContext theFhirContext,
                                                 IBaseResource theResource)
        Factory method for creating a new instance of the wrapper
        Parameters:
        theFhirContext - FHIR Context to be used for all further operations
        theResource - The resource to operate on
        Returns:
        Returns a new helper instance
      • setField

        public TerserUtilHelper setField​(String theField,
                                         String theValue)
        Sets string field at the specified FHIR path
        Parameters:
        theField - The FHIR Path to set the values at
        theValue - The string value to be set
        Returns:
        Returns current instance
      • setField

        public TerserUtilHelper setField​(String theField,
                                         String theFieldType,
                                         Object theValue)
        Sets field at the specified FHIR path
        Parameters:
        theField - The FHIR Path to set the values at
        theValue - The value to be set
        Returns:
        Returns current instance
      • getFieldValues

        public List<IBasegetFieldValues​(String theField)
        Gets values for the specified child field.
        Parameters:
        theField - The field to get values from
        Returns:
        Returns a list of retrieved values or null if the specified field doesn't exist
      • getFieldValuesByFhirPath

        public List<IBasegetFieldValuesByFhirPath​(String theFhirPath)
        Gets values for the specified field values by FHIRPath.
        Parameters:
        theFhirPath - The FHIR path expression to get the values from
        Returns:
        Returns a collection of values or null if the specified field doesn't exist
      • getFieldValueByFhirPath

        public IBase getFieldValueByFhirPath​(String theFhirPath)
        Gets first available value for the specified field values by FHIRPath.
        Parameters:
        theFhirPath - The FHIR path expression to get the values from
        Returns:
        Returns the value or null if the specified field doesn't exist or is empty
      • getFieldValue

        public IBase getFieldValue​(String theField)
        Gets first available values of the specified field.
        Parameters:
        theField - The field to get values from
        Returns:
        Returns the first available value for the field name or null if the specified field doesn't exist or has no values
      • getTerser

        public FhirTerser getTerser()
        Gets the terser instance, creating one if necessary.
        Returns:
        Returns the terser
      • getResource

        public <T extends IBaseResource> T getResource()
        Gets resource that this helper operates on
        Type Parameters:
        T - Instance type of the resource
        Returns:
        Returns the resources
      • newElement

        public IBase newElement​(String theElementName)
        Creates a new element
        Parameters:
        theElementName - Name of the element to create
        Returns:
        Returns a new element
      • getContext

        public FhirContext getContext()
        Gets context holding resource definition.
        Returns:
        Returns the current FHIR context.