UNPKG

fume-fhir-converter

Version:

FHIR-Utilized Mapping Engine - Community

48 lines 2.5 kB
"use strict"; /** * © Copyright Outburn Ltd. 2022-2023 All Rights Reserved * Project name: FUME */ /* eslint-disable */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getMandatoriesOfStructure = void 0; const tslib_1 = require("tslib"); const getSnapshot_1 = require("../parser/getSnapshot"); const stringFunctions_1 = require("../stringFunctions"); const getMandatoriesOfElement_1 = require("./getMandatoriesOfElement"); const returnPathWithoutX_1 = require("../parser/returnPathWithoutX"); const stringFunctions_2 = require("../stringFunctions"); const conformance_1 = require("../conformance"); const logger_1 = require("../logger"); const config_1 = tslib_1.__importDefault(require("../../config")); const dev = process.env.NODE_ENV === 'dev'; const getMandatoriesOfStructure = async (structId) => { if (dev) console.log({ func: exports.getMandatoriesOfStructure, structId }); const snapshot = await (0, getSnapshot_1.getSnapshot)(structId, config_1.default.getFhirVersion(), (0, conformance_1.getFhirPackageIndex)(), (0, logger_1.getLogger)()); const rootMandatories = snapshot.snapshot.element.filter(item => item.min > 0 && item.id.split('.').length === 2); const res = {}; for (const item of rootMandatories) { const typeCount = item.type.length; const isPoly = item.id.endsWith('[x]'); const idSuffixRaw = item.id.substring(item.id.indexOf(snapshot.type) + snapshot.type.length + 1); const idSuffix = isPoly && typeCount === 1 ? (0, returnPathWithoutX_1.returnPathWithoutX)(idSuffixRaw) + (0, stringFunctions_2.initCapOnce)(item.type[0].code) : idSuffixRaw; if (dev) console.log({ itemId: item.id, idSuffix }); // if id suffix ends with [x] and there's a single type - fix the id accordingly const val = await (0, getMandatoriesOfElement_1.getMandatoriesOfElement)(structId, idSuffix); if (val) { if (item.base.max > '1' || item.base.max === '*' || item.max > '1' || item.max === '*') { res[idSuffix] = [val]; } else { res[idSuffix] = val; } } } if (Object.keys(res).length > 0) { return Object.assign({}, ...Object.entries(res).map(([key, value]) => ({ [(0, stringFunctions_1.replaceColonsWithBrackets)(key)]: value }))); } }; exports.getMandatoriesOfStructure = getMandatoriesOfStructure; //# sourceMappingURL=getMandatoriesOfStructure.js.map