Skip to content

Commit ec67ee4

Browse files
authored
Merge pull request #6 from Health-Informatics-UoN/fix/build
change elasticsearch client
2 parents e35115c + 2a5c4c5 commit ec67ee4

3 files changed

Lines changed: 19 additions & 18 deletions

File tree

.github/workflows/build.open-case-reports.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
pull_request:
66
paths:
7-
- .
7+
- '**'
88
- .github/workflows/omop-case-reports.yml
99

1010
env:

lib/elasticsearch.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { Client } from '@elastic/elasticsearch';
2-
const isDev = process.env.NODE_ENV === 'development';
3-
export const es = new Client({
4-
node: process.env.ELASTICSEARCH_URL,
5-
auth: {
6-
username: process.env.ELASTICSEARCH_USERNAME!,
7-
password: process.env.ELASTICSEARCH_PASSWORD!,
8-
},
9-
tls: isDev
10-
? { rejectUnauthorized: false }
11-
: undefined,
12-
});
1+
import { Client } from "@elastic/elasticsearch";
2+
const isDev = process.env.NODE_ENV === "development";
3+
4+
export function getElasticClient() {
5+
return new Client({
6+
node: process.env.ELASTICSEARCH_URL,
7+
auth: {
8+
username: process.env.ELASTICSEARCH_USERNAME!,
9+
password: process.env.ELASTICSEARCH_PASSWORD!,
10+
},
11+
tls: isDev ? { rejectUnauthorized: false } : undefined,
12+
});
13+
}

lib/services/conceptsService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { es } from "@/lib/elasticsearch";
1+
import { getElasticClient } from "@/lib/elasticsearch";
22

33
export async function getConcepts(domain?: string) {
44
const must: any[] = [];
55

66
if (domain && domain !== "All") {
77
must.push({ term: { "domain.keyword": domain } });
88
}
9-
10-
const result = await es.search({
9+
10+
const result = await getElasticClient().search({
1111
index: "notes_nlp",
1212
size: 0,
1313
query: {
@@ -41,7 +41,7 @@ export async function getConcepts(domain?: string) {
4141
}
4242

4343
export async function getNotesForConcept(conceptId: string) {
44-
const resultConcept = await es.search({
44+
const resultConcept = await getElasticClient().search({
4545
index: "notes_nlp",
4646
size: 100,
4747
query: {
@@ -56,7 +56,7 @@ export async function getNotesForConcept(conceptId: string) {
5656

5757
if (noteIds.length === 0) return [];
5858

59-
const notes = await es.search({
59+
const notes = await getElasticClient().search({
6060
index: "notes",
6161
size: 100,
6262
query: {

0 commit comments

Comments
 (0)