Class ReferenceUtil


  • public class ReferenceUtil
    extends Object
    Encapsulates utility functions used when processing model Reference elements from a FHIR resource
    • Constructor Detail

      • ReferenceUtil

        public ReferenceUtil()
    • Method Detail

      • createReferenceValueFrom

        public static ReferenceValue createReferenceValueFrom​(Reference ref,
                                                              String baseUrl)
        Processes a Reference value from the FHIR model and interprets it according to https://www.hl7.org/fhir/references.html#2.3.0

        Absolute literal references will be converted to relative references if their base matches baseUrl.

        The resulting ReferenceValue will contained an inferred ReferenceType and the structure of the ReferenceValue.value will vary accordingly:

        1. LITERAL_RELATIVE: the id of the referenced resource
        2. LITERAL_ABSOLUTE: the full URI of the reference
        3. LOGICAL: the Identifier.value (Identifier.system is not presently stored)
        4. DISPLAY_ONLY: null
        5. INVALID: null
        Parameters:
        ref - a non-null FHIR Reference object
        baseUrl - the base URL used to determine whether to convert absolute references to relative references
        Returns:
        a structured representation of the reference value that varies by its inferred reference type
      • createReferenceValueFrom

        public static ReferenceValue createReferenceValueFrom​(String refValue,
                                                              String refType,
                                                              String baseUrl)
        Processes the string value of a Reference object from the FHIR model and interprets it according to https://www.hl7.org/fhir/references.html#2.3.0

        Absolute literal references will be converted to relative references if their base matches baseUrl.

        The resulting ReferenceValue will contain an inferred ReferenceType and the structure of the ReferenceValue.value will vary accordingly:

        1. LITERAL_RELATIVE: the id of the referenced resource
        2. LITERAL_ABSOLUTE: the full URI of the reference
        3. INVALID: null
        Parameters:
        refValue - a reference value string
        refType - a reference resource type (used for LITERAL_ABSOLUTE only)
        baseUrl - the base URL used to determine whether to convert absolute references to relative references
        Returns:
        a structured representation of the reference value that varies by its inferred reference type
      • getBaseUrl

        public static String getBaseUrl​(Bundle.Entry entry)
                                 throws FHIRSearchException
        Extract the base URL from the bundle entry if one is given, otherwise use the service base URL.
        Parameters:
        entry - , can be null
        Returns:
        the base URL for use in interpreting references
        Throws:
        FHIRSearchException
      • getBaseUrlFromBundle

        public static String getBaseUrlFromBundle​(Bundle.Entry entry)
                                           throws FHIRSearchException
        https://www.hl7.org/fhir/references.html#literal See: a relative URL, which is relative to the Service Base URL, or, if processing a resource from a bundle, which is relative to the base URL implied by the Bundle.entry.fullUrl (see Resolving References in Bundles) If the fullUrl looks like this "fullUrl": "https://localhost:9443/fhir-server/api/v4/Observation/17546b5a5a9-872ecfe4-cb5e-4f8c-a381-5b13df536f87" then the returned String will look like this: "https://localhost:9443/fhir-server/api/v4/"
        Parameters:
        entry -
        Returns:
        Throws:
        FHIRSearchException
      • getServiceBaseUrl

        public static String getServiceBaseUrl()
                                        throws FHIRSearchException
        Get the service base URL using the originalRequestUri currently set in the FHIRRequestContext
        Parameters:
        bundle -
        Returns:
        the base url
        Throws:
        FHIRSearchException