cql-execution
Version:
An execution framework for the Clinical Quality Language (CQL)
106 lines • 4.19 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Library = void 0;
const expressions_1 = require("./expressions");
class Library {
constructor(json, libraryManager) {
var _a, _b;
this.source = json;
// identifier
this.name = (_a = json.library.identifier) === null || _a === void 0 ? void 0 : _a.id;
this.version = (_b = json.library.identifier) === null || _b === void 0 ? void 0 : _b.version;
// usings
const usingDefs = (json.library.usings && json.library.usings.def) || [];
this.usings = usingDefs
.filter((u) => u.localIdentifier !== 'System')
.map((u) => {
return { name: u.localIdentifier, version: u.version };
});
// parameters
const paramDefs = (json.library.parameters && json.library.parameters.def) || [];
this.parameters = {};
for (const param of paramDefs) {
this.parameters[param.name] = new expressions_1.ParameterDef(param);
}
// code systems
const csDefs = (json.library.codeSystems && json.library.codeSystems.def) || [];
this.codesystems = {};
for (const codesystem of csDefs) {
this.codesystems[codesystem.name] = new expressions_1.CodeSystemDef(codesystem);
}
// value sets
const vsDefs = (json.library.valueSets && json.library.valueSets.def) || [];
this.valuesets = {};
for (const valueset of vsDefs) {
this.valuesets[valueset.name] = new expressions_1.ValueSetDef(valueset);
}
// codes
const codeDefs = (json.library.codes && json.library.codes.def) || [];
this.codes = {};
for (const code of codeDefs) {
this.codes[code.name] = new expressions_1.CodeDef(code);
}
// concepts
const conceptDefs = (json.library.concepts && json.library.concepts.def) || [];
this.concepts = {};
for (const concept of conceptDefs) {
this.concepts[concept.name] = new expressions_1.ConceptDef(concept);
}
// expressions
const exprDefs = (json.library.statements && json.library.statements.def) || [];
this.expressions = {};
this.functions = {};
for (const expr of exprDefs) {
if (expr.type === 'FunctionDef') {
if (!this.functions[expr.name]) {
this.functions[expr.name] = [];
}
this.functions[expr.name].push(new expressions_1.FunctionDef(expr));
}
else {
this.expressions[expr.name] = new expressions_1.ExpressionDef(expr);
}
}
// includes
const inclDefs = (json.library.includes && json.library.includes.def) || [];
this.includes = {};
for (const incl of inclDefs) {
if (libraryManager) {
this.includes[incl.localIdentifier] = libraryManager.resolve(incl.path, incl.version);
}
}
}
getFunction(identifier) {
return this.functions[identifier];
}
get(identifier) {
return (this.expressions[identifier] || this.includes[identifier] || this.getFunction(identifier));
}
getValueSet(identifier, libraryName) {
if (libraryName && this.includes[libraryName]) {
return this.includes[libraryName].valuesets[identifier];
}
else if (libraryName == null || libraryName === this.name) {
return this.valuesets[identifier];
}
}
getCodeSystem(identifier, libraryName) {
if (libraryName && this.includes[libraryName]) {
return this.includes[libraryName].codesystems[identifier];
}
else if (libraryName == null || libraryName === this.name) {
return this.codesystems[identifier];
}
}
getCode(identifier) {
return this.codes[identifier];
}
getConcept(identifier) {
return this.concepts[identifier];
}
getParameter(name) {
return this.parameters[name];
}
}
exports.Library = Library;
//# sourceMappingURL=library.js.map