Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

feat: use sessionId as search preference #130

Merged
merged 2 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"aws-elasticsearch-connector": "^8.2.0",
"aws-sdk": "^2.1000.0",
"date-fns": "^2.19.0",
"fhir-works-on-aws-interface": "^11.1.0",
"fhir-works-on-aws-interface": "^11.3.0",
"flat": "^5.0.2",
"lodash": "^4.17.20",
"nearley": "^2.20.0"
Expand Down
19 changes: 19 additions & 0 deletions src/__snapshots__/elasticSearchService.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ Array [
"body": Array [
Object {
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
},
Object {
"query": Object {
Expand Down Expand Up @@ -469,6 +470,7 @@ Array [
"body": Array [
Object {
"index": "organization-alias",
"preference": "CUSTOMER_SESSION_ID",
},
Object {
"query": Object {
Expand Down Expand Up @@ -516,6 +518,7 @@ Array [
},
"from": 0,
"index": "medicationrequest-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -1855,6 +1858,7 @@ Array [
},
"from": 2,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 10,
"track_total_hits": true,
},
Expand Down Expand Up @@ -1896,6 +1900,7 @@ Array [
},
"from": 2,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 10,
"track_total_hits": true,
},
Expand Down Expand Up @@ -1923,6 +1928,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -1963,6 +1969,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -2000,6 +2007,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -2076,6 +2084,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -2144,6 +2153,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -2194,6 +2204,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -2260,6 +2271,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -2310,6 +2322,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -2370,6 +2383,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -2438,6 +2452,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -2478,6 +2493,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -2514,6 +2530,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -2550,6 +2567,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down Expand Up @@ -2577,6 +2595,7 @@ Array [
},
"from": 0,
"index": "patient-alias",
"preference": "CUSTOMER_SESSION_ID",
"size": 20,
"track_total_hits": true,
},
Expand Down
2 changes: 2 additions & 0 deletions src/elasticSearchService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('typeSearch', () => {
baseUrl: 'https://base-url.com',
queryParams,
allowedResourceTypes: ALLOWED_RESOURCE_TYPES,
sessionId: 'CUSTOMER_SESSION_ID',
});

expect((ElasticSearch.search as jest.Mock).mock.calls).toMatchSnapshot();
Expand Down Expand Up @@ -587,6 +588,7 @@ describe('typeSearch', () => {
baseUrl: 'https://base-url.com',
queryParams: { ...queryParams },
allowedResourceTypes: ALLOWED_RESOURCE_TYPES,
sessionId: 'CUSTOMER_SESSION_ID',
});

expect((ElasticSearch.search as jest.Mock).mock.calls).toMatchSnapshot('search queries');
Expand Down
6 changes: 5 additions & 1 deletion src/elasticSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export class ElasticSearchService implements Search {
const searchQueryWithAlias = {
...searchQuery.queryRequest,
index: getAliasName(searchQuery.resourceType, request.tenantId),
...(request.sessionId && { preference: request.sessionId }),
rsmayda marked this conversation as resolved.
Show resolved Hide resolved
};

if (logger.isDebugEnabled()) {
Expand Down Expand Up @@ -281,7 +282,10 @@ export class ElasticSearchService implements Search {
logger.debug(`Elastic msearch query: ${JSON.stringify(searchQueriesWithAlias, null, 2)}`);
}
const apiResponse = await this.esClient.msearch({
body: searchQueriesWithAlias.flatMap((query) => [{ index: query.index }, { query: query.body!.query }]),
body: searchQueriesWithAlias.flatMap((query) => [
{ index: query.index, ...(request.sessionId && { preference: request.sessionId }) },
{ query: query.body!.query },
]),
});

return (apiResponse.body.responses as any[])
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1993,10 +1993,10 @@ fecha@^4.2.0:
resolved "https://registry.yarnpkg.com/fecha/-/fecha-4.2.1.tgz#0a83ad8f86ef62a091e22bb5a039cd03d23eecce"
integrity sha512-MMMQ0ludy/nBs1/o0zVOiKTpG7qMbonKUzjJgQFEuvq6INZ1OraKPRAWkBq5vlKLOUMpmNYG1JoN3oDPUQ9m3Q==

fhir-works-on-aws-interface@^11.1.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/fhir-works-on-aws-interface/-/fhir-works-on-aws-interface-11.1.0.tgz#5950cb0538f831b6b2b34a0c83ab411c5a4e521c"
integrity sha512-wqLc3AFX8NwHQl5Ps406ozwz5LqXqKzXynicHbmsM8e29Hsb8tGS8+p2sXvhG9y+/DBj7QJljcJYN69F0eBt0g==
fhir-works-on-aws-interface@^11.3.0:
version "11.3.0"
resolved "https://registry.yarnpkg.com/fhir-works-on-aws-interface/-/fhir-works-on-aws-interface-11.3.0.tgz#2a02162ee19cfb188d564d37925ead98aef10915"
integrity sha512-d3QtB0HsjRsDbFZm6IxH0s9nZpndWej01rnJKpXg7RFjepPDRztu+bNo/Me3hwxVexiCgOIVLxXs4DqAPRHEKA==
dependencies:
winston "^3.3.3"
winston-transport "^4.4.0"
Expand Down