fume-fhir-converter
Version:
FHIR-Utilized Mapping Engine - Community
136 lines • 5.61 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/**
* © Copyright Outburn Ltd. 2022-2024 All Rights Reserved
* Project name: FUME-COMMUNITY
*/
const globals_1 = require("@jest/globals");
const axios_1 = tslib_1.__importDefault(require("axios"));
const supertest_1 = tslib_1.__importDefault(require("supertest"));
const config_1 = require("../config");
const getResourceFileContents_1 = require("../utils/getResourceFileContents");
const patientExpression = `Instance: $uuid('1')
InstanceOf: Patient
* active = true
* name
* given = given
* family = family
`;
describe('api tests', () => {
beforeAll(async () => {
const testMapping = (0, getResourceFileContents_1.getResourceFileContents)('json', 'test-mapping-route.json');
const mappingAsFunction = (0, getResourceFileContents_1.getResourceFileContents)('json', 'mapping-as-function.json');
const parsedtestMapping = JSON.parse(testMapping);
const parsedmappingAsFunction = JSON.parse(mappingAsFunction);
await axios_1.default.put(`${config_1.LOCAL_FHIR_API}/StructureMap/testMappingRoute`, parsedtestMapping);
await axios_1.default.put(`${config_1.LOCAL_FHIR_API}/StructureMap/testMappingAsFunction`, parsedmappingAsFunction);
// "'testing binding of $a: ' + $a"
const mapping1 = await axios_1.default.get(`${config_1.LOCAL_FHIR_API}/StructureMap/testMappingRoute`);
const mapping2 = await axios_1.default.get(`${config_1.LOCAL_FHIR_API}/StructureMap/testMappingAsFunction`);
expect(mapping1.status).toBe(200);
expect(mapping2.status).toBe(200);
await (0, supertest_1.default)(globalThis.app).get('/recache');
});
afterAll(async () => {
await axios_1.default.delete(`${config_1.LOCAL_FHIR_API}/StructureMap/testMappingRoute`);
await axios_1.default.delete(`${config_1.LOCAL_FHIR_API}/StructureMap/testMappingAsFunction`);
await (0, supertest_1.default)(globalThis.app).get('/recache');
});
(0, globals_1.test)('get mapping that does not exist', async () => {
await (0, supertest_1.default)(globalThis.app).get('/Mapping/11925e4e-6ac0-4a38-a817-9a1524c9e1aa').expect(404);
});
(0, globals_1.test)('get mapping that does exist', async () => {
const res = await (0, supertest_1.default)(globalThis.app).get('/Mapping/testMappingRoute')
.expect('Content-Type', 'application/vnd.outburn.fume; charset=utf-8');
expect(res.text).toBe(patientExpression);
;
});
(0, globals_1.test)('execute existing test mapping', async () => {
const res = await (0, supertest_1.default)(globalThis.app).post('/Mapping/testMappingRoute').send({
given: 'a', family: 'B'
});
expect(res.body).toStrictEqual({
resourceType: 'Patient',
id: '356a192b-7913-504c-9457-4d18c28d46e6',
active: true,
name: [
{
given: [
'a'
],
family: 'B'
}
]
});
});
(0, globals_1.test)('execute existing test mapping as function', async () => {
const res = await (0, supertest_1.default)(globalThis.app).post('/').send({
input: {
given: 'a', family: 'B'
},
contentType: 'application/json',
fume: '$testMappingRoute($)'
});
expect(res.body).toStrictEqual({
resourceType: 'Patient',
id: '356a192b-7913-504c-9457-4d18c28d46e6',
active: true,
name: [
{
given: [
'a'
],
family: 'B'
}
]
});
});
(0, globals_1.test)('execute mapping as function and pass bindings', async () => {
const res = await (0, supertest_1.default)(globalThis.app).post('/').send({
input: {},
contentType: 'application/json',
fume: '$testMappingAsFunction({}, { "a": "a" })'
});
expect(res.body).toBe('testing binding of $a: a');
});
(0, globals_1.test)('execute existing mapping with CSV input', async () => {
const res = await (0, supertest_1.default)(globalThis.app)
.post('/Mapping/testMappingRoute')
.set('Content-Type', 'text/csv')
.send('given,family\r\na,B');
expect(res.body).toStrictEqual({
resourceType: 'Patient',
id: '356a192b-7913-504c-9457-4d18c28d46e6',
active: true,
name: [
{
given: [
'a'
],
family: 'B'
}
]
});
});
(0, globals_1.test)('execute existing mapping with XML input', async () => {
const res = await (0, supertest_1.default)(globalThis.app)
.post('/Mapping/testMappingRoute')
.set('Content-Type', 'application/xml')
.send('<root><given>a</given><family value="B" /></root>');
expect(res.body).toStrictEqual({
resourceType: 'Patient',
id: '356a192b-7913-504c-9457-4d18c28d46e6',
active: true,
name: [
{
given: [
'a'
],
family: 'B'
}
]
});
});
});
//# sourceMappingURL=mapping.test.js.map