Class SearchQueryRenderer
- java.lang.Object
-
- org.linuxforhealth.fhir.persistence.jdbc.domain.SearchQueryRenderer
-
- All Implemented Interfaces:
SearchQueryVisitor<QueryData>
public class SearchQueryRenderer extends java.lang.Object implements SearchQueryVisitor<QueryData>
Used to render the domain model into a physical, executable query modeled as a Select statement. The domain model knows about resources and parameters. This class is used to translate the logical structure of the query into a physical one, using the correct table names, join predicates and filter expressions.
-
-
Constructor Summary
Constructors Constructor Description SearchQueryRenderer(IDatabaseTranslator translator, JDBCIdentityCache identityCache, int rowOffset, int rowsPerPage, boolean includeResourceData, SchemaType schemaType)
Public constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description QueryData
addCanonicalParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm)
Filter the query using the given canonical parameterQueryData
addChained(QueryData queryData, QueryParameter currentParm)
Add a chain subquery element as part of a chained parameter searchQueryData
addCompositeParam(QueryData queryData, QueryParameter queryParm)
Add a composite query parameter filter to the queryQueryData
addCompositeParam(QueryData queryData, QueryParameter queryParm, boolean isMissing)
Add a composite query which only tests missing/not missing, not the actual parameter valueQueryData
addDateParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm)
Filter the query using the given date parametervoid
addFilter(QueryData queryData, java.lang.String resourceType, QueryParameter currentParm)
Add a filter predicate to the given chained sub-query element.protected void
addIdFilter(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm)
Add a filter on the LOGICAL_ID for the given query parameter valuesQueryData
addIncludeFilter(QueryData queryData, InclusionParameter inclusionParm, java.util.List<java.lang.Long> logicalResourceIds)
QueryData
addInclusionParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm)
Special case to handle inclusion related to compartment-based searchesQueryData
addLocationParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm)
Filter the query using the given location (lat/lng) paramQueryData
addLocationPosition(QueryData queryData, java.util.List<QueryParameter> queryParameters)
QueryData
addMissingParam(QueryData queryData, QueryParameter queryParm, boolean isMissing)
Add a missing (NOT EXISTS) parameter clause to the queryQueryData
addNumberParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm)
Filter the query using the given number parameterQueryData
addPagination(QueryData queryData)
Add pagination (LIMIT/OFFSET) to the queryQueryData
addQuantityParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm)
Filter the query using the given quantity parameterQueryData
addReferenceParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm)
Filter the query using the given reference parameterQueryData
addReverseChained(QueryData queryData, QueryParameter currentParm)
Add a reverse chain subquery element as part of a chained parameter searchQueryData
addRevIncludeFilter(QueryData queryData, InclusionParameter inclusionParm, java.util.List<java.lang.Long> logicalResourceIds)
QueryData
addSecurityParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm)
Filter the query using the given security query parameterQueryData
addSorting(QueryData queryData, java.lang.String lrAlias)
Add sorting (order by) to the queryvoid
addSortParam(QueryData queryData, java.lang.String code, SearchConstants.Type type, Sort.Direction direction)
Add the given sort parameter to the sort queryQueryData
addStringParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm)
Filter the query using the given string parameterQueryData
addTagParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm)
Filter the query using the given tag query parameterQueryData
addTokenParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm)
Filter the query using the given parameter id and token valueQueryData
addWholeSystemDataFilter(QueryData queryData, java.lang.String resourceType, java.util.List<java.lang.Long> logicalResourceIds)
QueryData
addWholeSystemResourceTypeFilter(QueryData queryData, java.util.List<java.lang.Integer> resourceTypeIds)
QueryData
addWholeSystemSorting(QueryData queryData, java.util.List<DomainSortParameter> sortParms, java.lang.String lrAlias)
Add sorting (order by) for whole-system search to the queryQueryData
countRoot(java.lang.String rootResourceType)
The root query (select statement) for a count queryQueryData
dataRoot(java.lang.String rootResourceType, int resourceTypeId)
The root query (select statement) for the data queryprotected long
getCanonicalId(java.lang.String canonicalValue)
Get the id for the given canonicalValue (cache lookup).protected int
getCodeSystemId(java.lang.String codeSystemName)
Get the id for the given code system name (cache lookup)protected java.lang.Long
getCommonTokenValueId(java.lang.String system, java.lang.String code)
Get the common token value id matching the unique tuple {system, code}protected java.util.List<java.lang.Long>
getCommonTokenValueIdList(java.lang.String code)
Get a list of common token values matching the given codeprotected java.util.Set<java.lang.Long>
getCommonTokenValueIds(java.util.Collection<CommonTokenValue> tokenValues)
Get the common token value ids for the passed list of token values {system, code}.protected WhereFragment
getDateFilter(QueryParameter queryParm, java.lang.String paramAlias)
Add a filter predicate to the given exists sub-queryprotected WhereFragment
getFilterPredicate(QueryData queryData, QueryParameter queryParm)
Get a simple filter predicate which can be used in the WHERE clause of a search query.protected WhereFragment
getIdentifierFilter(QueryParameter queryParm, java.lang.String paramAlias)
protected WhereFragment
getLocationFilter(QueryParameter queryParm, java.lang.String paramAlias)
Add a filter predicate to the given exists sub-queryprotected java.util.List<java.lang.Long>
getLogicalResourceIdList(java.lang.String logicalId)
Obtain the list of logical_resource_id values that match the given logicalId.protected java.util.Set<java.lang.Long>
getLogicalResourceIds(java.util.Collection<ResourceReferenceValue> referenceValues)
Obtain the logical_resource_id values for each of the given ResourceReferenceValues.protected java.lang.String
getLRAlias(int aliasIndex)
Get the string to use as a logical resource alias for the given aliasIndex valueprotected int
getNextAliasIndex()
Get the next index number to use as a parameter table aliasprotected WhereFragment
getNumberFilter(QueryParameter queryParm, java.lang.String paramAlias)
Get a filter predicate for the given number query parameterprotected Operator
getOperator(QueryParameter queryParameter)
Get the operator we need to use for matching values for this parameterprotected Operator
getOperator(QueryParameter queryParm, java.lang.String defaultOverride)
Map the Modifier in the passed Parameter to a supported query operator.protected java.lang.String
getParamAlias(int aliasIndex)
Get the string to use as a parameter table alias for the given aliasIndex valueQueryData
getParameterBaseQuery(QueryData parent)
Get the join to which we want to attach all the parameter tables.protected int
getParameterNameId(java.lang.String parameterName)
Get the id for the given parameter name (cache lookup)protected WhereFragment
getQuantityFilter(QueryParameter queryParm, java.lang.String paramAlias)
Add a filter predicate to the given exists sub-queryprotected WhereFragment
getReferenceFilter(QueryParameter queryParm, java.lang.String paramAlias)
Create a filter predicate for the given reference query parameterprotected WhereFragment
getReferenceFilter(QueryParameter queryParm, java.lang.String paramAlias, java.util.List<java.lang.Long> logicalResourceIdList)
protected WhereFragment
getReferenceStrFilter(QueryParameter queryParm, java.lang.String paramAlias, java.util.List<java.lang.String> ambiguousResourceReferenceTokenValues)
Create a filter predicate for the given reference query parameter using the ambiguousprotected java.lang.String
getRefParamTable(ExpNode filter, java.lang.String resourceType, java.lang.String paramAlias)
Compute the reference parameter table name we want to use to join with.protected java.lang.String
getSortParameterTableName(java.lang.String resourceType, java.lang.String code, SearchConstants.Type type)
Returns the name of the database table corresponding to the code and type of the passed sort parameter.protected WhereFragment
getStringFilter(QueryParameter queryParm, java.lang.String paramAlias)
Add a filter expression to the given parameter sub-query (which is used as an EXISTS clause)protected WhereFragment
getTokenFilter(QueryParameter queryParm, java.lang.String paramAlias)
Get the filter predicate for the given token query parameter.protected java.lang.String
getTokenParamTable(ExpNode filter, java.lang.String resourceType, java.lang.String paramAlias, boolean filterIsOptimized)
Compute the token parameter table name we want to use to join with.QueryData
includeRoot(java.lang.String rootResourceType)
The root query (select statement) for the include query.protected boolean
isOptimizedTokenParamFilter(ExpNode filter, java.lang.String paramAlias)
Inspect the filter expression to see if it mentions the TOKEN_VALUE or CODE_SYSTEM_ID columns.QueryData
joinResources(QueryData queryData, boolean includeResourceTypeId)
Finish the data query by wrapping the root and joining the resources tableprotected int
nullCheck(java.lang.Integer value)
Use -1 as a simple substitute for null literal ids because we know -1 will never exist as a value in the database (for fields populated by sequence values).protected long
nullCheck(java.lang.Long value)
Use -1 as a simple substitute for null literal ids because we know -1 will never exist as a value in the database (for fields populated by sequence values).protected WhereFragment
paramFilter(QueryParameter queryParm, java.lang.String paramTableAlias)
Get the filter predicate expression for the given query parameter taking into account its type, modifiers etc.java.lang.String
paramValuesColumnName(SearchConstants.Type paramType)
Get the column name to use for the given paramTypejava.lang.String
paramValuesTableName(java.lang.String resourceType, QueryParameter queryParm)
Get the parameter values table name (e.g.protected java.lang.String
resourceLogicalResources(java.lang.String resourceType)
Get the table name for the xx_logical_resources table where xx is the resource type nameprotected java.lang.String
resourceResources(java.lang.String resourceType)
Get the table name for the xx_resources table where xx is the resource type nameprotected java.lang.String
resourceTypeField(java.lang.String resourceType, int resourceTypeId)
QueryData
sortRoot(java.lang.String rootResourceType)
The root of the FHIR search sort queryQueryData
wholeSystemDataRoot(java.lang.String rootResourceType, int rootResourceTypeId)
The root of the FHIR whole-system data search queryQueryData
wholeSystemFilterRoot()
The root of the FHIR whole-system filter search queryQueryData
wrapInclude(QueryData query)
QueryData
wrapWholeSystem(java.util.List<QueryData> queries, boolean isCountQuery)
The wrapper for whole-system search
-
-
-
Constructor Detail
-
SearchQueryRenderer
public SearchQueryRenderer(IDatabaseTranslator translator, JDBCIdentityCache identityCache, int rowOffset, int rowsPerPage, boolean includeResourceData, SchemaType schemaType)
Public constructor- Parameters:
translator
-identityCache
-rowOffset
-rowsPerPage
-includeResourceData
-schemaType
-
-
-
Method Detail
-
getNextAliasIndex
protected int getNextAliasIndex()
Get the next index number to use as a parameter table alias- Returns:
-
resourceLogicalResources
protected java.lang.String resourceLogicalResources(java.lang.String resourceType)
Get the table name for the xx_logical_resources table where xx is the resource type name- Parameters:
resourceType
-- Returns:
- the table name
-
resourceTypeField
protected java.lang.String resourceTypeField(java.lang.String resourceType, int resourceTypeId)
-
resourceResources
protected java.lang.String resourceResources(java.lang.String resourceType)
Get the table name for the xx_resources table where xx is the resource type name- Parameters:
resourceType
-- Returns:
-
getParameterNameId
protected int getParameterNameId(java.lang.String parameterName) throws FHIRPersistenceException
Get the id for the given parameter name (cache lookup)- Parameters:
parameterName
-- Returns:
- Throws:
FHIRPersistenceException
-
getCommonTokenValueId
protected java.lang.Long getCommonTokenValueId(java.lang.String system, java.lang.String code) throws FHIRPersistenceException
Get the common token value id matching the unique tuple {system, code}- Parameters:
system
-code
-- Returns:
- Throws:
FHIRPersistenceException
-
getCommonTokenValueIds
protected java.util.Set<java.lang.Long> getCommonTokenValueIds(java.util.Collection<CommonTokenValue> tokenValues) throws FHIRPersistenceException
Get the common token value ids for the passed list of token values {system, code}.- Parameters:
tokenValues
-- Returns:
- Throws:
FHIRPersistenceException
-
getLogicalResourceIds
protected java.util.Set<java.lang.Long> getLogicalResourceIds(java.util.Collection<ResourceReferenceValue> referenceValues) throws FHIRPersistenceException
Obtain the logical_resource_id values for each of the given ResourceReferenceValues.- Parameters:
referenceValues
-- Returns:
- Throws:
FHIRPersistenceException
-
getLogicalResourceIdList
protected java.util.List<java.lang.Long> getLogicalResourceIdList(java.lang.String logicalId) throws FHIRPersistenceException
Obtain the list of logical_resource_id values that match the given logicalId.- Parameters:
logicalId
-- Returns:
- Throws:
FHIRPersistenceException
-
getCommonTokenValueIdList
protected java.util.List<java.lang.Long> getCommonTokenValueIdList(java.lang.String code) throws FHIRPersistenceException
Get a list of common token values matching the given code- Parameters:
code
-- Returns:
- Throws:
FHIRPersistenceException
-
getCodeSystemId
protected int getCodeSystemId(java.lang.String codeSystemName) throws FHIRPersistenceException
Get the id for the given code system name (cache lookup)- Parameters:
codeSystemName
-- Returns:
- Throws:
FHIRPersistenceException
-
getCanonicalId
protected long getCanonicalId(java.lang.String canonicalValue) throws FHIRPersistenceException
Get the id for the given canonicalValue (cache lookup).- Parameters:
canonicalValue
-- Returns:
- the database id, or -1 if the value does not exist
- Throws:
FHIRPersistenceException
-
countRoot
public QueryData countRoot(java.lang.String rootResourceType)
Description copied from interface:SearchQueryVisitor
The root query (select statement) for a count query- Specified by:
countRoot
in interfaceSearchQueryVisitor<QueryData>
- Returns:
-
dataRoot
public QueryData dataRoot(java.lang.String rootResourceType, int resourceTypeId)
Description copied from interface:SearchQueryVisitor
The root query (select statement) for the data query- Specified by:
dataRoot
in interfaceSearchQueryVisitor<QueryData>
- Returns:
-
getParameterBaseQuery
public QueryData getParameterBaseQuery(QueryData parent)
Description copied from interface:SearchQueryVisitor
Get the join to which we want to attach all the parameter tables. This makes it easier to build different styles of joins- Specified by:
getParameterBaseQuery
in interfaceSearchQueryVisitor<QueryData>
- Returns:
-
joinResources
public QueryData joinResources(QueryData queryData, boolean includeResourceTypeId)
Description copied from interface:SearchQueryVisitor
Finish the data query by wrapping the root and joining the resources table- Specified by:
joinResources
in interfaceSearchQueryVisitor<QueryData>
includeResourceTypeId
- include the resource_type_id in the select column list- Returns:
-
includeRoot
public QueryData includeRoot(java.lang.String rootResourceType)
Description copied from interface:SearchQueryVisitor
The root query (select statement) for the include query. This query is different than the data root because of the need to support version references for _include searches. For this, we join: xx_RESOURCES.LOGICAL_RESOURCE_ID = xx_LOGICAL_RESOURCES.LOGICAL_RESOURCE_ID and allow the filter to specify the version_id constraint. However, we still need to assert that the resource has not been deleted, so we keep: xx_LOGICAL_RESOURCES.IS_DELETED = 'N'- Specified by:
includeRoot
in interfaceSearchQueryVisitor<QueryData>
- Returns:
-
wrapInclude
public QueryData wrapInclude(QueryData query)
- Specified by:
wrapInclude
in interfaceSearchQueryVisitor<QueryData>
- Returns:
-
sortRoot
public QueryData sortRoot(java.lang.String rootResourceType)
Description copied from interface:SearchQueryVisitor
The root of the FHIR search sort query- Specified by:
sortRoot
in interfaceSearchQueryVisitor<QueryData>
- Returns:
-
wholeSystemFilterRoot
public QueryData wholeSystemFilterRoot()
Description copied from interface:SearchQueryVisitor
The root of the FHIR whole-system filter search query- Specified by:
wholeSystemFilterRoot
in interfaceSearchQueryVisitor<QueryData>
- Returns:
-
wholeSystemDataRoot
public QueryData wholeSystemDataRoot(java.lang.String rootResourceType, int rootResourceTypeId)
Description copied from interface:SearchQueryVisitor
The root of the FHIR whole-system data search query- Specified by:
wholeSystemDataRoot
in interfaceSearchQueryVisitor<QueryData>
- Returns:
-
wrapWholeSystem
public QueryData wrapWholeSystem(java.util.List<QueryData> queries, boolean isCountQuery)
Description copied from interface:SearchQueryVisitor
The wrapper for whole-system search- Specified by:
wrapWholeSystem
in interfaceSearchQueryVisitor<QueryData>
- Returns:
-
getTokenFilter
protected WhereFragment getTokenFilter(QueryParameter queryParm, java.lang.String paramAlias) throws FHIRPersistenceException
Get the filter predicate for the given token query parameter.- Parameters:
queryParm
- the token query parameterparamAlias
- the alias used for the token values table- Throws:
FHIRPersistenceException
-
getStringFilter
protected WhereFragment getStringFilter(QueryParameter queryParm, java.lang.String paramAlias) throws FHIRPersistenceException
Add a filter expression to the given parameter sub-query (which is used as an EXISTS clause)- Parameters:
paramExists
- the query statement to which we need to add the filter predicatequeryParm
- the query parameter for which we need to compute and add the filter predicateparamAlias
- the alias for the query parameter table- Returns:
- Throws:
FHIRPersistenceException
-
addSorting
public QueryData addSorting(QueryData queryData, java.lang.String lrAlias)
Description copied from interface:SearchQueryVisitor
Add sorting (order by) to the query- Specified by:
addSorting
in interfaceSearchQueryVisitor<QueryData>
- Returns:
-
addWholeSystemSorting
public QueryData addWholeSystemSorting(QueryData queryData, java.util.List<DomainSortParameter> sortParms, java.lang.String lrAlias)
Description copied from interface:SearchQueryVisitor
Add sorting (order by) for whole-system search to the query- Specified by:
addWholeSystemSorting
in interfaceSearchQueryVisitor<QueryData>
- Returns:
-
addPagination
public QueryData addPagination(QueryData queryData)
Description copied from interface:SearchQueryVisitor
Add pagination (LIMIT/OFFSET) to the query- Specified by:
addPagination
in interfaceSearchQueryVisitor<QueryData>
- Returns:
-
paramValuesTableName
public java.lang.String paramValuesTableName(java.lang.String resourceType, QueryParameter queryParm)
Get the parameter values table name (e.g. Patient_STR_VALUES) for the given resource and parameter type. Note that this is now different from the original QuerySegmentAggregator implementation - it does not differentiate on chaining...that is left up to the building logic.- Parameters:
resourceType
-paramType
-- Returns:
-
paramValuesColumnName
public java.lang.String paramValuesColumnName(SearchConstants.Type paramType)
Get the column name to use for the given paramType- Parameters:
paramType
-- Returns:
-
getFilterPredicate
protected WhereFragment getFilterPredicate(QueryData queryData, QueryParameter queryParm) throws FHIRPersistenceException
Get a simple filter predicate which can be used in the WHERE clause of a search query. This is used at the "leaf level" of parameter processing, where the queryParm relates to a single parameter (i.e. it is the caller's responsibility to handle chaining and other more complex behavior.- Parameters:
queryData
-queryParm
-- Returns:
- Throws:
FHIRPersistenceException
-
addIdFilter
protected void addIdFilter(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm) throws FHIRPersistenceException
Add a filter on the LOGICAL_ID for the given query parameter values- Parameters:
queryData
-resourceType
-queryParm
-- Throws:
FHIRPersistenceException
-
getNumberFilter
protected WhereFragment getNumberFilter(QueryParameter queryParm, java.lang.String paramAlias) throws FHIRPersistenceException
Get a filter predicate for the given number query parameter- Parameters:
queryParm
-paramAlias
-- Throws:
FHIRPersistenceException
-
getQuantityFilter
protected WhereFragment getQuantityFilter(QueryParameter queryParm, java.lang.String paramAlias) throws FHIRPersistenceException
Add a filter predicate to the given exists sub-query- Parameters:
queryParm
-paramAlias
-- Throws:
FHIRPersistenceException
-
getDateFilter
protected WhereFragment getDateFilter(QueryParameter queryParm, java.lang.String paramAlias)
Add a filter predicate to the given exists sub-query- Parameters:
queryParm
-paramAlias
-
-
getLocationFilter
protected WhereFragment getLocationFilter(QueryParameter queryParm, java.lang.String paramAlias) throws FHIRPersistenceException
Add a filter predicate to the given exists sub-query- Parameters:
queryParm
-paramAlias
-- Throws:
FHIRPersistenceException
-
getParamAlias
protected java.lang.String getParamAlias(int aliasIndex)
Get the string to use as a parameter table alias for the given aliasIndex value- Parameters:
aliasIndex
-- Returns:
-
getLRAlias
protected java.lang.String getLRAlias(int aliasIndex)
Get the string to use as a logical resource alias for the given aliasIndex value- Parameters:
aliasIndex
-- Returns:
-
getTokenParamTable
protected java.lang.String getTokenParamTable(ExpNode filter, java.lang.String resourceType, java.lang.String paramAlias, boolean filterIsOptimized)
Compute the token parameter table name we want to use to join with. This method inspects the content of the given filterExpNode
. If the filter contains a reference to the TOKEN_VALUE column, the returned table name will be based on xx_TOKEN_VALUES_V, otherwise it will be based on xx_RESOURCE_TOKEN_REFS. The latter is preferable because it eliminates an unnecessary join, improves cardinality estimation and (usually) results in a better execution plan.- Parameters:
filter
-resourceType
-paramAlias
-- Returns:
-
isOptimizedTokenParamFilter
protected boolean isOptimizedTokenParamFilter(ExpNode filter, java.lang.String paramAlias)
Inspect the filter expression to see if it mentions the TOKEN_VALUE or CODE_SYSTEM_ID columns. If neither of these columns is mentioned, we can optimize to use only the xx_resource_token_refs which leads to much better overall cardinality estimation by the query optimizer.- Parameters:
filter
-paramAlias
-- Returns:
-
getRefParamTable
protected java.lang.String getRefParamTable(ExpNode filter, java.lang.String resourceType, java.lang.String paramAlias)
Compute the reference parameter table name we want to use to join with. This method inspects the content of the given filterExpNode
. If the filter contains a reference to the LOGICAL_ID column, the returned table name will be based on xx_REF_VALUES_V, otherwise it will be based on xx_REF_VALUES. The latter is preferable because it eliminates an unnecessary join, improves cardinality estimation and (usually) results in a better execution plan.- Parameters:
filter
-resourceType
-paramAlias
-- Returns:
-
getIdentifierFilter
protected WhereFragment getIdentifierFilter(QueryParameter queryParm, java.lang.String paramAlias) throws FHIRPersistenceException
- Throws:
FHIRPersistenceException
-
getReferenceFilter
protected WhereFragment getReferenceFilter(QueryParameter queryParm, java.lang.String paramAlias) throws FHIRPersistenceException
Create a filter predicate for the given reference query parameter- Parameters:
queryParm
-paramAlias
-- Throws:
FHIRPersistenceException
-
getReferenceFilter
protected WhereFragment getReferenceFilter(QueryParameter queryParm, java.lang.String paramAlias, java.util.List<java.lang.Long> logicalResourceIdList) throws FHIRPersistenceException
- Throws:
FHIRPersistenceException
-
getReferenceStrFilter
protected WhereFragment getReferenceStrFilter(QueryParameter queryParm, java.lang.String paramAlias, java.util.List<java.lang.String> ambiguousResourceReferenceTokenValues) throws FHIRPersistenceException
Create a filter predicate for the given reference query parameter using the ambiguous- Parameters:
queryParm
-paramAlias
-- Throws:
FHIRPersistenceException
-
nullCheck
protected int nullCheck(java.lang.Integer value)
Use -1 as a simple substitute for null literal ids because we know -1 will never exist as a value in the database (for fields populated by sequence values).- Parameters:
value
-- Returns:
-
nullCheck
protected long nullCheck(java.lang.Long value)
Use -1 as a simple substitute for null literal ids because we know -1 will never exist as a value in the database (for fields populated by sequence values).- Parameters:
value
-- Returns:
-
getOperator
protected Operator getOperator(QueryParameter queryParameter)
Get the operator we need to use for matching values for this parameter- Parameters:
queryParameter
-- Returns:
-
getOperator
protected Operator getOperator(QueryParameter queryParm, java.lang.String defaultOverride)
Map the Modifier in the passed Parameter to a supported query operator. If the mapping results in the default operator, override the default operator with the passed operator if the passed operator is not null.- Parameters:
queryParm
- - A valid query Parameter.defaultOverride
- - An operator that should override the default operator.- Returns:
- A supported operator.
-
paramFilter
protected WhereFragment paramFilter(QueryParameter queryParm, java.lang.String paramTableAlias) throws FHIRPersistenceException
Get the filter predicate expression for the given query parameter taking into account its type, modifiers etc.- Parameters:
paramTableAlias
-queryParm
-- Returns:
- a valid expression
- Throws:
FHIRPersistenceException
-
addLocationPosition
public QueryData addLocationPosition(QueryData queryData, java.util.List<QueryParameter> queryParameters) throws FHIRPersistenceException
- Specified by:
addLocationPosition
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addInclusionParam
public QueryData addInclusionParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Special case to handle inclusion related to compartment-based searches- Specified by:
addInclusionParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addIncludeFilter
public QueryData addIncludeFilter(QueryData queryData, InclusionParameter inclusionParm, java.util.List<java.lang.Long> logicalResourceIds) throws FHIRPersistenceException
- Specified by:
addIncludeFilter
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addRevIncludeFilter
public QueryData addRevIncludeFilter(QueryData queryData, InclusionParameter inclusionParm, java.util.List<java.lang.Long> logicalResourceIds) throws FHIRPersistenceException
- Specified by:
addRevIncludeFilter
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addWholeSystemDataFilter
public QueryData addWholeSystemDataFilter(QueryData queryData, java.lang.String resourceType, java.util.List<java.lang.Long> logicalResourceIds) throws FHIRPersistenceException
- Specified by:
addWholeSystemDataFilter
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addWholeSystemResourceTypeFilter
public QueryData addWholeSystemResourceTypeFilter(QueryData queryData, java.util.List<java.lang.Integer> resourceTypeIds) throws FHIRPersistenceException
- Specified by:
addWholeSystemResourceTypeFilter
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addTokenParam
public QueryData addTokenParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Filter the query using the given parameter id and token value- Specified by:
addTokenParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addTagParam
public QueryData addTagParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Filter the query using the given tag query parameter- Specified by:
addTagParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addSecurityParam
public QueryData addSecurityParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Filter the query using the given security query parameter- Specified by:
addSecurityParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addStringParam
public QueryData addStringParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Filter the query using the given string parameter- Specified by:
addStringParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addCanonicalParam
public QueryData addCanonicalParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Filter the query using the given canonical parameter- Specified by:
addCanonicalParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addMissingParam
public QueryData addMissingParam(QueryData queryData, QueryParameter queryParm, boolean isMissing) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Add a missing (NOT EXISTS) parameter clause to the query- Specified by:
addMissingParam
in interfaceSearchQueryVisitor<QueryData>
isMissing
- true if the condition should be that the parameter does not exist- Returns:
- Throws:
FHIRPersistenceException
-
addChained
public QueryData addChained(QueryData queryData, QueryParameter currentParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Add a chain subquery element as part of a chained parameter search- Specified by:
addChained
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addFilter
public void addFilter(QueryData queryData, java.lang.String resourceType, QueryParameter currentParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Add a filter predicate to the given chained sub-query element. This must be the last element of the chain.- Specified by:
addFilter
in interfaceSearchQueryVisitor<QueryData>
- Throws:
FHIRPersistenceException
-
addReverseChained
public QueryData addReverseChained(QueryData queryData, QueryParameter currentParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Add a reverse chain subquery element as part of a chained parameter search- Specified by:
addReverseChained
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addNumberParam
public QueryData addNumberParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Filter the query using the given number parameter- Specified by:
addNumberParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addQuantityParam
public QueryData addQuantityParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Filter the query using the given quantity parameter- Specified by:
addQuantityParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addDateParam
public QueryData addDateParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Filter the query using the given date parameter- Specified by:
addDateParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addLocationParam
public QueryData addLocationParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Filter the query using the given location (lat/lng) param- Specified by:
addLocationParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addReferenceParam
public QueryData addReferenceParam(QueryData queryData, java.lang.String resourceType, QueryParameter queryParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Filter the query using the given reference parameter- Specified by:
addReferenceParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addCompositeParam
public QueryData addCompositeParam(QueryData queryData, QueryParameter queryParm) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Add a composite query parameter filter to the query- Specified by:
addCompositeParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addCompositeParam
public QueryData addCompositeParam(QueryData queryData, QueryParameter queryParm, boolean isMissing) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Add a composite query which only tests missing/not missing, not the actual parameter value- Specified by:
addCompositeParam
in interfaceSearchQueryVisitor<QueryData>
- Returns:
- Throws:
FHIRPersistenceException
-
addSortParam
public void addSortParam(QueryData queryData, java.lang.String code, SearchConstants.Type type, Sort.Direction direction) throws FHIRPersistenceException
Description copied from interface:SearchQueryVisitor
Add the given sort parameter to the sort query- Specified by:
addSortParam
in interfaceSearchQueryVisitor<QueryData>
- Throws:
FHIRPersistenceException
-
getSortParameterTableName
protected java.lang.String getSortParameterTableName(java.lang.String resourceType, java.lang.String code, SearchConstants.Type type) throws FHIRPersistenceException
Returns the name of the database table corresponding to the code and type of the passed sort parameter.- Parameters:
code
- A SortParameter codetype
- A SortParameter type- Returns:
- String - A database table name
- Throws:
FHIRPersistenceException
-
-