in src/elasticSearchService.ts [256:311]
private async getChainedParametersQuery(
parsedChainParameters: ChainParameter[],
request: TypeSearchRequest,
filters: any[] = [],
): Promise<{}> {
let combinedChainedParameters = {};
// eslint-disable-next-line no-restricted-syntax
for (const { chain, initialValue } of parsedChainParameters) {
let stepValue = initialValue;
let chainComplete = true;
const lastChain: { resourceType: string; searchParam: string } = chain.pop()!;
// eslint-disable-next-line no-restricted-syntax
for (const { resourceType, searchParam } of chain) {
const stepRequest: TypeSearchRequest = {
...request,
resourceType,
queryParams: { [searchParam]: stepValue },
};
const stepQuery = buildQueryForAllSearchParameters(
this.fhirSearchParametersRegistry,
stepRequest,
this.useKeywordSubFields,
filters,
);
const params: Query = {
resourceType,
queryRequest: {
size: MAX_CHAINED_PARAMS_RESULT,
track_total_hits: true,
body: {
query: stepQuery,
fields: ['id'],
_source: false,
},
},
};
// eslint-disable-next-line no-await-in-loop
const { total, hits } = await this.executeQuery(params, request);
if (total === 0) {
chainComplete = false;
break;
}
if (total > MAX_CHAINED_PARAMS_RESULT) {
throw new InvalidSearchParameterError(
`Chained parameter ${searchParam} result in more than ${MAX_CHAINED_PARAMS_RESULT} ${resourceType} resource. Please provide more precise queries.`,
);
}
stepValue = hits.map((hit) => `${resourceType}/${hit.fields.id[0]}`);
}
if (chainComplete) {
combinedChainedParameters = merge(combinedChainedParameters, { [lastChain.searchParam]: stepValue });
}
}
return combinedChainedParameters;
}