Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests against local FHIR server #40

Merged
merged 4 commits into from
Mar 13, 2024
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
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.7'

services:
fhir:
container_name: fhir
image: "hapiproject/hapi:latest"
ports:
- "8080:8080"
configs:
- source: hapi
target: /app/config/application.yaml
depends_on:
- db
environment:
JVM_OPTS: "-Xms2g -Xms2g"

db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: admin
POSTGRES_USER: admin
POSTGRES_DB: hapi
volumes:
- ./hapi.postgress.data:/var/lib/postgresql/data

configs:
hapi:
file: ./hapi.application.yaml
13 changes: 13 additions & 0 deletions hapi.application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
spring:
datasource:
url: 'jdbc:postgresql://db:5432/hapi'
username: admin
password: admin
driverClassName: org.postgresql.Driver
jpa:
properties:
hibernate.dialect: ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect
hibernate.search.enabled: false
hapi:
fhir:
reuse_cached_search_results_millis: -1
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
testPathIgnorePatterns: ['dist/*', 'tests/*']
roots: ['<rootDir>/src']
};
4 changes: 2 additions & 2 deletions jest.integration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
globalSetup: './tests/setup.ts',
globalTeardown: './tests/teardown.ts',
testPathIgnorePatterns: ['dist/*'],
testMatch: ['<rootDir>/tests/**/*.test.ts']
testTimeout: 30000,
roots: ['<rootDir>/tests']
};
19 changes: 16 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"url": "git+https://github.com/Outburn-IL/fume-community.git"
},
"dependencies": {
"axios": "^1.1.3",
"axios": "^1.6.7",
"cors": "^2.8.5",
"csvtojson": "^2.0.10",
"dotenv": "^16.4.1",
Expand Down Expand Up @@ -80,6 +80,7 @@
"cross-env": "^7.0.3",
"detect-indent": "^7.0.1",
"detect-newline": "^4.0.1",
"docker-compose": "^0.24.6",
"eslint": "^8.28.0",
"eslint-config-standard-with-typescript": "^23.0.0",
"eslint-plugin-import": "^2.26.0",
Expand Down
10 changes: 10 additions & 0 deletions src/helpers/cache/simpleCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ describe('SimpleCache', () => {
const res = cache.getDict();
expect(res).toEqual({ key: 'apple', key3: 'banana' });
});

test('populate with undefined clears cache', async () => {
const cache = new SimpleCache();
cache.set('key', 'value');
cache.set('key2', 'value2');

cache.populate(undefined as any);
const res = cache.getDict();
expect(res).toEqual({});
});
});
2 changes: 1 addition & 1 deletion src/helpers/cache/simpleCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class SimpleCache<T> implements ICache<T> {
}

populate (dict: Record<string, T>) {
this.cache = dict;
this.cache = dict || {};
}

getDict () {
Expand Down
33 changes: 19 additions & 14 deletions src/helpers/conformance/recacheFromServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,26 @@ export const getAliasResource = async () => {
return undefined;
};
let resource;
const aliasResourceSearch = await getFhirClient().search('ConceptMap', { context: 'http://codes.fume.health|fume', name: 'FumeAliases' });
if (typeof aliasResourceSearch === 'object' && aliasResourceSearch.resourceType === 'Bundle' && typeof aliasResourceSearch.total === 'number') {
if (aliasResourceSearch.total === 1) {
logger.info(`Alias resource found: ${aliasResourceSearch.entry[0].fullUrl as string}`);
resource = aliasResourceSearch.entry[0].resource;
} else {
if (aliasResourceSearch.total === 0) {
logger.info('Alias resource not found');
resource = {};
try {
const aliasResourceSearch = await getFhirClient().search('ConceptMap', { context: 'http://codes.fume.health|fume', name: 'FumeAliases' });
if (typeof aliasResourceSearch === 'object' && aliasResourceSearch.resourceType === 'Bundle' && typeof aliasResourceSearch.total === 'number') {
if (aliasResourceSearch.total === 1) {
logger.info(`Alias resource found: ${aliasResourceSearch.entry[0].fullUrl as string}`);
resource = aliasResourceSearch.entry[0].resource;
} else {
logger.error('Multiple alias resources found on server!');
if (aliasResourceSearch.total === 0) {
logger.info('Alias resource not found');
resource = {};
} else {
logger.error('Multiple alias resources found on server!');
}
}
}
} else {
logger.error('Error fetching alias resource!');
};
} else {
logger.error('Error fetching alias resource!');
};
} catch (e) {
resource = {};
}
return resource;
};

Expand Down Expand Up @@ -146,5 +150,6 @@ export const recacheFromServer = async (): Promise<boolean> => {
logger.error(e);
return false;
};

return true;
};
8 changes: 5 additions & 3 deletions src/helpers/fhirFunctions/translateCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { getLogger } from '../logger';

export const translateCode = async (input: string, tableId: string) => {
const { tables } = getCache();
// fork: os
try {
let map = tables.get(tableId);
if (map === undefined) {
getLogger().info(`Table ${tableId} not cached, trying to fetch from server...`);
map = (await getTable(tableId))[tableId];
tables.set(tableId, map);
const table = await getTable(tableId);
if (table) {
map = table[tableId];
tables.set(tableId, map);
}
};

const mapFiltered = map[input];
Expand Down
2 changes: 2 additions & 0 deletions tests/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const LOCAL_FHIR_SERVER_BASE = 'http://localhost:8080';
export const LOCAL_FHIR_API = `${LOCAL_FHIR_SERVER_BASE}/fhir`;
Loading