fume-fhir-converter
Version:
FHIR-Utilized Mapping Engine - Community
34 lines • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.capabilities = void 0;
const tslib_1 = require("tslib");
/**
* © Copyright Outburn Ltd. 2022-2024 All Rights Reserved
* Project name: FUME-COMMUNITY
*/
const fhirServer_1 = require("../fhirServer");
const thrower_1 = tslib_1.__importDefault(require("../thrower"));
// cached copy of the capability statement resource
let capabilityStatement = {};
const capabilities = async () => {
// check if capability statement cached copy is empty
if (Object.keys(capabilityStatement).length === 0) {
// try to fetch from server
try {
capabilityStatement = await (0, fhirServer_1.getFhirClient)().read('metadata');
}
catch (error) {
return thrower_1.default.throwRuntimeError(`Failed to fetch CapabilityStatement from FHIR server. ${JSON.stringify(error)}`);
}
}
;
// check that the object is actually a capability statement
if (!capabilityStatement?.resourceType || typeof capabilityStatement.resourceType !== 'string' || capabilityStatement.resourceType !== 'CapabilityStatement') {
return thrower_1.default.throwRuntimeError('Invalid response from FHIR server: The \'/metadata\' endpoint did not return a CapabilityStatement resource');
}
;
// return the cached capability statement
return capabilityStatement;
};
exports.capabilities = capabilities;
//# sourceMappingURL=capabilities.js.map