fume-fhir-converter
Version:
FHIR-Utilized Mapping Engine - Community
71 lines • 2.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/**
* © Copyright Outburn Ltd. 2022-2024 All Rights Reserved
* Project name: FUME-COMMUNITY
*/
const axios_1 = tslib_1.__importDefault(require("axios"));
const docker_compose_1 = require("docker-compose");
const path_1 = tslib_1.__importDefault(require("path"));
const server_1 = require("../src/server");
const config_1 = require("./config");
/**
* Disable axios cache during integration tests
* @param config
* @returns
*/
const originalCreate = axios_1.default.create;
axios_1.default.create = function createPatchedAxios(config) {
const instance = originalCreate(config);
instance.interceptors.request.use((request) => {
request.headers['Cache-Control'] = 'no-cache';
return request;
});
return instance;
};
/**
* Awaits for the FHIR server to start and for its API to be available
* @param maxAttempts
* @param currentAttempt
* @returns
*/
async function waitForFhirApi(maxAttempts, currentAttempt = 1) {
try {
console.log(`Attempt ${currentAttempt} to query FHIR API...`);
await axios_1.default.get(config_1.LOCAL_FHIR_SERVER_BASE);
}
catch (error) {
console.error(`Attempt ${currentAttempt} failed:`, error.message);
if (currentAttempt >= maxAttempts) {
throw new Error(`Failed to query FHIR API after ${maxAttempts} attempts`);
}
await new Promise(resolve => setTimeout(resolve, 5000));
return waitForFhirApi(maxAttempts, currentAttempt + 1);
}
}
async function setup() {
console.log('Starting FHIR server (using docker compose V2)...');
await docker_compose_1.v2.upAll({
cwd: path_1.default.join(__dirname),
config: 'docker-compose.yml',
log: true
});
const result = await docker_compose_1.v2.ps({ cwd: path_1.default.join(__dirname) });
globalThis.services = result.data.services;
globalThis.services.forEach((service) => {
console.log(service.name, service.command, service.state, service.ports);
});
console.log('Waiting for startup of FHIR server!');
await waitForFhirApi(30);
console.log('starting server...');
globalThis.fumeServer = new server_1.FumeServer();
await globalThis.fumeServer.warmUp({
FHIR_SERVER_BASE: config_1.LOCAL_FHIR_API,
FHIR_PACKAGES: 'il.core.fhir.r4@0.14.2,fume.outburn.r4@0.1.0,il.tasmc.fhir.r4@0.1.1'
});
globalThis.app = globalThis.fumeServer.getExpressApp();
console.log('server started!');
}
exports.default = setup;
//# sourceMappingURL=setup.js.map