fume-fhir-converter
Version:
FHIR-Utilized Mapping Engine - Community
47 lines • 2.14 kB
JavaScript
;
/**
* © Copyright Outburn Ltd. 2022-2024 All Rights Reserved
* Project name: FUME-COMMUNITY
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertInputToJson = exports.parseCsv = void 0;
const logger_1 = require("../logger");
const csvToJson_1 = require("./csvToJson");
Object.defineProperty(exports, "parseCsv", { enumerable: true, get: function () { return csvToJson_1.parseCsv; } });
const hl7v2_1 = require("./hl7v2");
const xml_1 = require("./xml");
const convertInputToJson = async (input, contentType) => {
if (!contentType || contentType === '') {
(0, logger_1.getLogger)().info('Content-Type is empty - defaulting to \'application/json\'');
contentType = 'application/json';
}
let inputJson;
if (contentType.startsWith('x-application/hl7-v2+er7')) {
(0, logger_1.getLogger)().info('Content-Type suggests HL7 V2.x message');
(0, logger_1.getLogger)().info('Trying to parse V2 message as JSON...');
inputJson = await (0, hl7v2_1.v2json)(input);
(0, logger_1.getLogger)().info('Parsed V2 message');
}
else if (contentType.startsWith('text/csv')) {
(0, logger_1.getLogger)().info('Content-Type suggests CSV input');
(0, logger_1.getLogger)().info('Trying to parse CSV to JSON...');
inputJson = await (0, csvToJson_1.parseCsv)(input);
(0, logger_1.getLogger)().info('Parsed CSV to JSON');
}
else if (contentType.startsWith('application/xml')) {
(0, logger_1.getLogger)().info('Content-Type suggests XML input');
(0, logger_1.getLogger)().info('Trying to parse XML to JSON...');
inputJson = (0, xml_1.parseXml)(input);
(0, logger_1.getLogger)().info('Parsed XML to JSON');
}
else if (contentType.startsWith('application/json')) {
(0, logger_1.getLogger)().info('Content-Type suggests JSON input');
inputJson = input;
}
else {
throw new Error(`Unsupported Content-Type: '${contentType}'`);
}
return inputJson;
};
exports.convertInputToJson = convertInputToJson;
//# sourceMappingURL=index.js.map