Class SearchUtil


  • public class SearchUtil
    extends Object
    Search Utility
    This class uses FHIRPath Expressions (and currently does not support XPath) and uses init to activate the Parameters/Compartments/ValueTypes components.
    • Method Detail

      • init

        public static void init()
        Initializes the various services related to Search and pre-caches.
        Loads the class in the classloader to initialize static members. Call this before using the class in order to avoid a slight performance hit on first use.
      • getUserDefinedSearchParameters

        protected static List<SearchParameter> getUserDefinedSearchParameters​(String resourceType)
                                                                       throws Exception
        Retrieves user-defined SearchParameters associated with the specified resource type and current tenant id.
        Parameters:
        resourceType - the resource type for which user-defined SearchParameters will be returned
        Returns:
        a list of user-defined SearchParameters associated with the specified resource type
        Throws:
        Exception
      • getFilteredBuiltinSearchParameters

        protected static List<SearchParameter> getFilteredBuiltinSearchParameters​(String resourceType)
                                                                           throws Exception
        Returns a filtered list of built-in SearchParameters associated with the specified resource type and those associated with the "Resource" resource type.
        Parameters:
        resourceType - the resource type
        Returns:
        a filtered list of SearchParameters
        Throws:
        Exception
      • getSearchParameter

        public static SearchParameter getSearchParameter​(Class<?> resourceType,
                                                         String code)
                                                  throws Exception
        Parameters:
        resourceType -
        code -
        Returns:
        the SearchParameter for type resourceType with code code or null if it doesn't exist
        Throws:
        Exception
      • getSearchParameter

        public static SearchParameter getSearchParameter​(String resourceType,
                                                         String code)
                                                  throws Exception
        Parameters:
        resourceType -
        code -
        Returns:
        the SearchParameter for type resourceType with code code or null if it doesn't exist
        Throws:
        Exception
      • getSearchParameter

        public static SearchParameter getSearchParameter​(Class<?> resourceType,
                                                         Canonical uri)
                                                  throws Exception
        Parameters:
        resourceType -
        uri -
        Returns:
        the SearchParameter for type resourceType with url uri or null if it doesn't exist
        Throws:
        Exception
      • getSearchParameter

        public static SearchParameter getSearchParameter​(String resourceType,
                                                         Canonical uri)
                                                  throws Exception
        Parameters:
        resourceType -
        uri -
        Returns:
        the SearchParameter for type resourceType with url uri or null if it doesn't exist
        Throws:
        Exception
      • extractReferenceValue

        public static String extractReferenceValue​(String valueString)
                                            throws FHIRSearchException
        Convert the string to a reference value useable by the persistence layer. This simply involves removing the URL prefix if it matches the originalUri in the request context
        Parameters:
        valueString -
        Returns:
        Throws:
        FHIRSearchException
      • getApplicableSearchParameters

        public static List<SearchParameter> getApplicableSearchParameters​(String resourceType)
                                                                   throws Exception
        Returns a list of SearchParameters that consist of those associated with the "Resource" base resource type, as well as those associated with the specified resource type.
        Throws:
        Exception
      • parseReadQueryParameters

        public static FHIRSearchContext parseReadQueryParameters​(Class<?> resourceType,
                                                                 Map<String,​List<String>> queryParameters,
                                                                 String interaction,
                                                                 boolean lenient)
                                                          throws Exception
        Parse query parameters for read and vread.
        Parameters:
        resourceType - the resource type
        queryParameters - the query parameters
        interaction - read or vread
        lenient - true if lenient, false if strict
        Returns:
        the FHIR search context
        Throws:
        Exception - an exception
      • useStoredCompartmentParam

        public static boolean useStoredCompartmentParam()
        Check the configuration to see if the flag enabling the compartment search optimization. Defaults to false so the behavior won't change unless it is explicitly enabled in fhir-server-config. This is important, because existing data must be reindexed (see $reindex custom operation) to generate values for the ibm-internal compartment relationship params.
        Returns:
      • parseCompartmentQueryParameters

        public static FHIRSearchContext parseCompartmentQueryParameters​(String compartmentName,
                                                                        String compartmentLogicalId,
                                                                        Class<?> resourceType,
                                                                        Map<String,​List<String>> queryParameters,
                                                                        boolean lenient)
                                                                 throws Exception
        Parameters:
        lenient - Whether to ignore unknown or unsupported parameter
        Returns:
        Throws:
        Exception
      • buildInclusionCriteria

        public static QueryParameter buildInclusionCriteria​(String compartmentName,
                                                            List<String> compartmentLogicalIds,
                                                            String resourceType)
                                                     throws FHIRSearchException
        Build a query parameter to encapsulate the inclusion criteria for a compartment query
        Parameters:
        compartmentName -
        compartmentLogicalIds -
        resourceType -
        Returns:
        Throws:
        FHIRSearchException
      • isSearchResultParameter

        public static boolean isSearchResultParameter​(String name)
      • isSearchSingletonParameter

        public static boolean isSearchSingletonParameter​(String name)
      • isGeneralParameter

        public static boolean isGeneralParameter​(String name)
      • isChainedParameter

        public static boolean isChainedParameter​(String name)
      • isReverseChainedParameter

        public static boolean isReverseChainedParameter​(String code)
      • parseChainedInclusionCriteria

        public static QueryParameter parseChainedInclusionCriteria​(QueryParameter inclusionCriteriaParm)
        Transforms the passed QueryParameter representing chained inclusion criteria, into an actual chain of QueryParameter objects. This method consumes QueryParameters with names of this form:
         "{attribute1}.{attribute2}:{resourceType}"
         
        For specific examples of chained inclusion criteria, see the FHIR spec for the Patient compartment
        Parameters:
        inclusionCriteriaParm -
        Returns:
        QueryParameter - The root of a parameter chain for chained inclusion criteria.
      • normalizeForSearch

        public static String normalizeForSearch​(String value)
        Normalizes a string to be used as a search parameter value. All accents and diacritics are removed. And then the string is transformed to lower case.
        Parameters:
        value -
        Returns:
      • getSummaryTextElementNames

        public static Set<String> getSummaryTextElementNames​(Class<?> resourceType)
        Return only the "text" element, the 'id' element, the 'meta' element, and only top-level mandatory elements. The id, meta and the top-level mandatory elements will be added by the ElementFilter automatically.
        Parameters:
        resourceType -
        Returns:
      • extractCompartmentParameterValues

        public static Map<String,​Set<CompartmentReference>> extractCompartmentParameterValues​(Resource fhirResource,
                                                                                                    Map<String,​Set<String>> compartmentRefParams)
                                                                                             throws FHIRSearchException
        Extracts the parameter values defining compartment membership.
        Parameters:
        fhirResource -
        compartmentRefParams - a map of parameter names to a set of compartment names (resource types)
        Returns:
        a map of compartment name to a set of unique compartment reference values
        Throws:
        FHIRSearchException
      • makeCompositeSubCode

        public static String makeCompositeSubCode​(String compositeCode,
                                                  String subParameterCode)
        Build a parameter name (code) which can be used to uniquely represent the stored composite sub-parameter (the values get added to the parameter_names table). We use a prefix just to avoid any (albeit already remote) possibility of collision. Also makes these more visible as something added by the implementation code, not from a configuration file.
        Parameters:
        compositeCode -
        subParameterCode -
        Returns: