Class SearchHelper


  • public class SearchHelper
    extends java.lang.Object
    A helper class with methods for working with HL7 FHIR search.
    • Constructor Detail

      • SearchHelper

        public SearchHelper()
    • Method Detail

      • getSearchParameter

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

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

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

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

        public java.util.Map<SearchParameter,​java.util.List<FHIRPathNode>> extractParameterValues​(Resource resource)
                                                                                                 throws java.lang.Exception
        skips the empty extracted search parameters
        Parameters:
        resource -
        Returns:
        Throws:
        java.lang.Exception
      • extractParameterValues

        public java.util.Map<SearchParameter,​java.util.List<FHIRPathNode>> extractParameterValues​(Resource resource,
                                                                                                        boolean skipEmpty)
                                                                                                 throws java.lang.Exception
        extract parameter values.
        Parameters:
        resource -
        skipEmpty -
        Returns:
        Throws:
        java.lang.Exception
      • parseQueryParameters

        public FHIRSearchContext parseQueryParameters​(java.lang.Class<?> resourceType,
                                                      java.util.Map<java.lang.String,​java.util.List<java.lang.String>> queryParameters)
                                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • parseQueryParameters

        public FHIRSearchContext parseQueryParameters​(java.lang.Class<?> resourceType,
                                                      java.util.Map<java.lang.String,​java.util.List<java.lang.String>> queryParameters,
                                                      boolean lenient,
                                                      boolean includeResource)
                                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • parseQueryParameters

        public FHIRSearchContext parseQueryParameters​(java.lang.Class<?> resourceType,
                                                      java.util.Map<java.lang.String,​java.util.List<java.lang.String>> queryParameters,
                                                      boolean lenient,
                                                      boolean includeResource,
                                                      FHIRVersionParam fhirVersion)
                                               throws java.lang.Exception
        Parse the passed query parameters into a FHIRSeachContext according to the given options
        Parameters:
        resourceType -
        queryParameters -
        lenient -
        includeResource -
        fhirVersion -
        Returns:
        Throws:
        java.lang.Exception
      • findImplicitSystem

        public static java.lang.String findImplicitSystem​(java.util.List<Extension> extensions)
        Look up the http://fhir.linuxforhealth.org/extension/implicit-system extension in the given list of Extensions
        Parameters:
        extensions -
        Returns:
        the implicit system value, or null if not found
      • extractReferenceValue

        public static java.lang.String extractReferenceValue​(java.lang.String valueString)
                                                      throws FHIRSearchException
        Convert the string to a reference value usable 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
      • getSearchParameters

        public java.util.Map<java.lang.String,​SearchParameter> getSearchParameters​(java.lang.String resourceType)
                                                                                  throws java.lang.Exception
        Returns a map of code to SearchParameter that consist of those associated with the "Resource" base resource type, as well as those associated with the specified resource type.
        Returns:
        the applicable search parameters for the current request context, indexed by code; never null
        Throws:
        java.lang.Exception
      • parseReadQueryParameters

        public FHIRSearchContext parseReadQueryParameters​(java.lang.Class<?> resourceType,
                                                          java.util.Map<java.lang.String,​java.util.List<java.lang.String>> queryParameters,
                                                          java.lang.String interaction,
                                                          boolean lenient,
                                                          FHIRVersionParam fhirVersion)
                                                   throws java.lang.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
        fhirVersion -
        Returns:
        the FHIR search context
        Throws:
        java.lang.Exception - an exception
      • parseCompartmentQueryParameters

        public FHIRSearchContext parseCompartmentQueryParameters​(java.lang.String compartmentName,
                                                                 java.lang.String compartmentLogicalId,
                                                                 java.lang.Class<?> resourceType,
                                                                 java.util.Map<java.lang.String,​java.util.List<java.lang.String>> queryParameters)
                                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • parseCompartmentQueryParameters

        public FHIRSearchContext parseCompartmentQueryParameters​(java.lang.String compartmentName,
                                                                 java.lang.String compartmentLogicalId,
                                                                 java.lang.Class<?> resourceType,
                                                                 java.util.Map<java.lang.String,​java.util.List<java.lang.String>> queryParameters,
                                                                 boolean lenient,
                                                                 boolean includeResource,
                                                                 FHIRVersionParam fhirVersion)
                                                          throws java.lang.Exception
        Parameters:
        compartmentName -
        compartmentLogicalId -
        resourceType -
        queryParameters -
        lenient - Whether to ignore unknown or unsupported parameter
        includeResource - Whether to include the resource from the result (return handling prefer != minimal)
        fhirVersion -
        Returns:
        Throws:
        java.lang.Exception
      • buildInclusionCriteria

        public QueryParameter buildInclusionCriteria​(java.lang.String compartmentName,
                                                     java.util.Set<java.lang.String> compartmentLogicalIds,
                                                     java.lang.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​(java.lang.String name)
        Determine if the parameter is a search result parameter.
        Parameters:
        name - - the parameter name
        Returns:
        true if the parameter is a search result parameter, false otherwise
      • isSearchSingletonParameter

        public static boolean isSearchSingletonParameter​(java.lang.String name)
      • isGeneralParameter

        public static boolean isGeneralParameter​(java.lang.String name)
      • isChainedParameter

        public static boolean isChainedParameter​(java.lang.String name)
      • isReverseChainedParameter

        public static boolean isReverseChainedParameter​(java.lang.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 java.lang.String normalizeForSearch​(java.lang.String value)
        Normalizes a string to be used as a search parameter value. All accents and diacritics are removed. Consecutive whitespace characters are replaced with a single space. And then the string is transformed to lower case.
        Parameters:
        value - the string to normalize
        Returns:
        the normalized string
      • buildSearchSelfUri

        public static java.lang.String buildSearchSelfUri​(java.lang.String requestUriString,
                                                          FHIRSearchContext context)
                                                   throws java.net.URISyntaxException
        Build the self link from the search parameters actually used by the server
        Throws:
        java.net.URISyntaxException
      • getSummaryTextElementNames

        public static java.util.Set<java.lang.String> getSummaryTextElementNames​(java.lang.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:
      • makeCompositeSubCode

        public static java.lang.String makeCompositeSubCode​(java.lang.String compositeCode,
                                                            java.lang.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:
      • containsInclusionParameter

        public static boolean containsInclusionParameter​(java.util.Set<java.lang.String> searchParameterCodes)
        Check if the list of search parameters contains either _include or _revinclude.
        Parameters:
        searchParameterCodes - the set of search parameters to check
        Returns:
        true if either _include or _revinclude found, false otherwise
      • checkInclusionIterateParameters

        public static void checkInclusionIterateParameters​(java.lang.String resourceType,
                                                           FHIRSearchContext context,
                                                           boolean lenient)
                                                    throws FHIRSearchException
        Check if _include or _revinclude parameters with the :iterate modifier reference invalid resource types. If in strict mode, throw a FHIRSearchException. If in lenient mode, log the invalid parameters and remove those parameters from the search context.
        Parameters:
        resourceType - the search resource type
        context - the search context
        lenient - flag indicating lenient or strict mode
        Throws:
        FHIRSearchException
      • isCompartmentType

        public boolean isCompartmentType​(java.lang.String resourceType)
        Parameters:
        resourceType -
        Returns:
        whether the passed resourceType has its own CompartmentDefinition
      • isCompartmentSearch

        public static boolean isCompartmentSearch​(FHIRSearchContext searchContext)
        Inspect the searchContext to see if the parameters define a compartment-based search. This is useful to know because it allows an implementation to enable optimizations specific to compartment-based searches.
        Parameters:
        searchContext -
        Returns: