Package com.ibm.fhir.search.util
Class SearchUtil
- java.lang.Object
-
- com.ibm.fhir.search.util.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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static QueryParameter
buildInclusionCriteria(String compartmentName, List<String> compartmentLogicalIds, String resourceType)
Build a query parameter to encapsulate the inclusion criteria for a compartment querystatic String
buildSearchSelfUri(String requestUriString, FHIRSearchContext context)
Build the self link from the search parameters actually used by the serverstatic Map<String,Set<CompartmentReference>>
extractCompartmentParameterValues(Resource fhirResource, Map<String,Set<String>> compartmentRefParams)
Extracts the parameter values defining compartment membership.static Map<SearchParameter,List<FHIRPathNode>>
extractParameterValues(Resource resource)
skips the empty extracted search parametersstatic Map<SearchParameter,List<FHIRPathNode>>
extractParameterValues(Resource resource, boolean skipEmpty)
extract parameter values.static String
extractReferenceValue(String valueString)
Convert the string to a reference value useable by the persistence layer.static List<SearchParameter>
getApplicableSearchParameters(String resourceType)
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.protected static List<SearchParameter>
getFilteredBuiltinSearchParameters(String resourceType)
Returns a filtered list of built-in SearchParameters associated with the specified resource type and those associated with the "Resource" resource type.static SearchParameter
getSearchParameter(Class<?> resourceType, Canonical uri)
static SearchParameter
getSearchParameter(Class<?> resourceType, String code)
static SearchParameter
getSearchParameter(String resourceType, Canonical uri)
static SearchParameter
getSearchParameter(String resourceType, String code)
static Set<String>
getSummaryTextElementNames(Class<?> resourceType)
Return only the "text" element, the 'id' element, the 'meta' element, and only top-level mandatory elements.protected static List<SearchParameter>
getUserDefinedSearchParameters(String resourceType)
Retrieves user-defined SearchParameters associated with the specified resource type and current tenant id.static void
init()
Initializes the various services related to Search and pre-caches.protected static boolean
isAllowed(SearchConstants.Type type, SearchConstants.Modifier modifier)
static boolean
isChainedParameter(String name)
static boolean
isGeneralParameter(String name)
static boolean
isReverseChainedParameter(String code)
static boolean
isSearchResultParameter(String name)
static boolean
isSearchSingletonParameter(String name)
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).static String
normalizeForSearch(String value)
Normalizes a string to be used as a search parameter value.static QueryParameter
parseChainedInclusionCriteria(QueryParameter inclusionCriteriaParm)
Transforms the passed QueryParameter representing chained inclusion criteria, into an actual chain of QueryParameter objects.static FHIRSearchContext
parseCompartmentQueryParameters(String compartmentName, String compartmentLogicalId, Class<?> resourceType, Map<String,List<String>> queryParameters)
static FHIRSearchContext
parseCompartmentQueryParameters(String compartmentName, String compartmentLogicalId, Class<?> resourceType, Map<String,List<String>> queryParameters, boolean lenient)
static FHIRSearchContext
parseQueryParameters(Class<?> resourceType, Map<String,List<String>> queryParameters)
static FHIRSearchContext
parseQueryParameters(Class<?> resourceType, Map<String,List<String>> queryParameters, boolean lenient)
static FHIRSearchContext
parseReadQueryParameters(Class<?> resourceType, Map<String,List<String>> queryParameters, String interaction, boolean lenient)
Parse query parameters for read and vread.static boolean
useStoredCompartmentParam()
Check the configuration to see if the flag enabling the compartment search optimization.
-
-
-
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 codecode
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 codecode
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 urluri
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 urluri
or null if it doesn't exist - Throws:
Exception
-
extractParameterValues
public static Map<SearchParameter,List<FHIRPathNode>> extractParameterValues(Resource resource) throws Exception
skips the empty extracted search parameters- Parameters:
resource
-- Returns:
- Throws:
Exception
-
extractParameterValues
public static Map<SearchParameter,List<FHIRPathNode>> extractParameterValues(Resource resource, boolean skipEmpty) throws Exception
extract parameter values.- Parameters:
resource
-skipEmpty
-- Returns:
- Throws:
Exception
-
parseQueryParameters
public static FHIRSearchContext parseQueryParameters(Class<?> resourceType, Map<String,List<String>> queryParameters) throws Exception
- Throws:
Exception
-
parseQueryParameters
public static FHIRSearchContext parseQueryParameters(Class<?> resourceType, Map<String,List<String>> queryParameters, boolean lenient) throws Exception
- 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
-
isAllowed
protected static boolean isAllowed(SearchConstants.Type type, SearchConstants.Modifier modifier)
- Parameters:
type
-modifier
-- Returns:
-
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 typequeryParameters
- the query parametersinteraction
- read or vreadlenient
- true if lenient, false if strict- Returns:
- the FHIR search context
- Throws:
Exception
- an exception
-
parseCompartmentQueryParameters
public static FHIRSearchContext parseCompartmentQueryParameters(String compartmentName, String compartmentLogicalId, Class<?> resourceType, Map<String,List<String>> queryParameters) throws Exception
- Throws:
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:
-
buildSearchSelfUri
public static String buildSearchSelfUri(String requestUriString, FHIRSearchContext context) throws URISyntaxException
Build the self link from the search parameters actually used by the server- Throws:
URISyntaxException
-
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:
-
-