Class ExtensionUtil

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

public class ExtensionUtil extends Object
Utility for modifying with extensions in a FHIR version-independent approach.
  • Method Details

    • getOrCreateExtension

      public static IBaseExtension<?,​?> getOrCreateExtension(IBase theBase, String theUrl)
      Returns an extension with the specified URL creating one if it doesn't exist.
      Parameters:
      theBase - Base resource to get extension from
      theUrl - URL for the extension
      Returns:
      Returns a extension with the specified URL.
      Throws:
      IllegalArgumentException - IllegalArgumentException is thrown in case resource doesn't support extensions
    • addExtension

      public static IBaseExtension<?,​?> addExtension(IBase theBase)
      Returns an new empty extension.
      Parameters:
      theBase - Base resource to add the extension to
      Returns:
      Returns a new extension
      Throws:
      IllegalArgumentException - IllegalArgumentException is thrown in case resource doesn't support extensions
    • addExtension

      public static IBaseExtension<?,​?> addExtension(IBase theBase, String theUrl)
      Returns an extension with the specified URL
      Parameters:
      theBase - Base resource to add the extension to
      theUrl - URL for the extension
      Returns:
      Returns a new extension with the specified URL.
      Throws:
      IllegalArgumentException - IllegalArgumentException is thrown in case resource doesn't support extensions
    • addExtension

      public static void addExtension(FhirContext theFhirContext, IBase theBase, String theUrl, String theValueType, Object theValue)
      Adds an extension with the specified value
      Parameters:
      theBase - The resource to update extension on
      theUrl - Extension URL
      theValueType - Type of the value to set in the extension
      theValue - Extension value
      theFhirContext - The context containing FHIR resource definitions
    • hasExtension

      public static boolean hasExtension(IBase theBase, String theExtensionUrl)
      Checks if the specified instance has an extension with the specified URL
      Parameters:
      theBase - The base resource to check extensions on
      theExtensionUrl - URL of the extension
      Returns:
      Returns true if extension is exists and false otherwise
    • hasExtension

      public static boolean hasExtension(IBase theBase, String theExtensionUrl, String theExtensionValue)
      Checks if the specified instance has an extension with the specified URL
      Parameters:
      theBase - The base resource to check extensions on
      theExtensionUrl - URL of the extension
      Returns:
      Returns true if extension is exists and false otherwise
    • getExtensionByUrl

      public static IBaseExtension<?,​?> getExtensionByUrl(IBase theBase, String theExtensionUrl)
      Gets the first extension with the specified URL
      Parameters:
      theBase - The resource to get the extension for
      theExtensionUrl - URL of the extension to get. Must be non-null
      Returns:
      Returns the first available extension with the specified URL, or null if such extension doesn't exist
    • getExtensionsMatchingPredicate

      public static List<IBaseExtension<?,​?>> getExtensionsMatchingPredicate(IBase theBase, Predicate<? super IBaseExtension<?,​?>> theFilter)
      Gets all extensions that match the specified filter predicate
      Parameters:
      theBase - The resource to get the extension for
      theFilter - Predicate to match the extension against
      Returns:
      Returns all extension with the specified URL, or an empty list if such extensions do not exist
    • clearAllExtensions

      public static List<IBaseExtension<?,​?>> clearAllExtensions(IBase theBase)
      Removes all extensions.
      Parameters:
      theBase - The resource to clear the extension for
      Returns:
      Returns all extension that were removed
    • clearExtensionsByUrl

      public static List<IBaseExtension<?,​?>> clearExtensionsByUrl(IBase theBase, String theUrl)
      Removes all extensions by URL.
      Parameters:
      theBase - The resource to clear the extension for
      theUrl - The url to clear extensions for
      Returns:
      Returns all extension that were removed
    • getExtensionsByUrl

      public static List<IBaseExtension<?,​?>> getExtensionsByUrl(IBaseHasExtensions theBase, String theExtensionUrl)
      Gets all extensions with the specified URL
      Parameters:
      theBase - The resource to get the extension for
      theExtensionUrl - URL of the extension to get. Must be non-null
      Returns:
      Returns all extension with the specified URL, or an empty list if such extensions do not exist
    • setExtension

      public static void setExtension(FhirContext theFhirContext, IBaseExtension<?,​?> theExtension, String theValue)
      Sets value of the extension as a string
      Parameters:
      theExtension - The extension to set the value on
      theValue - The value to set
      theFhirContext - The context containing FHIR resource definitions
    • setExtension

      public static void setExtension(FhirContext theFhirContext, IBaseExtension<?,​?> theExtension, String theExtensionType, Object theValue)
      Sets value of the extension
      Parameters:
      theExtension - The extension to set the value on
      theExtensionType - Element type of the extension
      theValue - The value to set
      theFhirContext - The context containing FHIR resource definitions
    • setExtensionAsString

      public static void setExtensionAsString(FhirContext theFhirContext, IBase theBase, String theUrl, String theValue)
      Sets or replaces existing extension with the specified value as a string
      Parameters:
      theBase - The resource to update extension on
      theUrl - Extension URL
      theValue - Extension value
      theFhirContext - The context containing FHIR resource definitions
    • setExtension

      public static void setExtension(FhirContext theFhirContext, IBase theBase, String theUrl, String theValueType, Object theValue)
      Sets or replaces existing extension with the specified value
      Parameters:
      theBase - The resource to update extension on
      theUrl - Extension URL
      theValueType - Type of the value to set in the extension
      theValue - Extension value
      theFhirContext - The context containing FHIR resource definitions
    • equals

      public static boolean equals(IBaseExtension<?,​?> theLeftExtension, IBaseExtension<?,​?> theRightExtension)
      Compares two extensions, returns true if they have the same value and url
      Parameters:
      theLeftExtension - : Extension to be evaluated #1
      theRightExtension - : Extension to be evaluated #2
      Returns:
      Result of the comparison