cql-execution
Version:
An execution framework for the Clinical Quality Language (CQL)
349 lines (275 loc) • 10 kB
JavaScript
// Generated by CoffeeScript 1.12.7
(function() {
var AnyInValueSet, CalculateAge, CalculateAgeAt, Code, CodeDef, CodeRef, CodeSystemDef, Concept, ConceptDef, ConceptRef, Expression, InValueSet, ValueSetDef, ValueSetRef, build, dt,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Expression = require('./expression').Expression;
dt = require('../datatypes/datatypes');
build = require('./builder').build;
module.exports.ValueSetDef = ValueSetDef = (function(superClass) {
extend(ValueSetDef, superClass);
function ValueSetDef(json) {
ValueSetDef.__super__.constructor.apply(this, arguments);
this.name = json.name;
this.id = json.id;
this.version = json.version;
}
ValueSetDef.prototype.exec = function(ctx) {
var ref, valueset;
valueset = (ref = ctx.codeService.findValueSet(this.id, this.version)) != null ? ref : new dt.ValueSet(this.id, this.version);
ctx.rootContext().set(this.name, valueset);
return valueset;
};
return ValueSetDef;
})(Expression);
module.exports.ValueSetRef = ValueSetRef = (function(superClass) {
extend(ValueSetRef, superClass);
function ValueSetRef(json) {
ValueSetRef.__super__.constructor.apply(this, arguments);
this.name = json.name;
this.libraryName = json.libraryName;
}
ValueSetRef.prototype.exec = function(ctx) {
var valueset;
valueset = ctx.getValueSet(this.name, this.libraryName);
if (valueset instanceof Expression) {
valueset = valueset.execute(ctx);
}
return valueset;
};
return ValueSetRef;
})(Expression);
module.exports.AnyInValueSet = AnyInValueSet = (function(superClass) {
extend(AnyInValueSet, superClass);
function AnyInValueSet(json) {
AnyInValueSet.__super__.constructor.apply(this, arguments);
this.codes = build(json.codes);
this.valueset = new ValueSetRef(json.valueset);
}
AnyInValueSet.prototype.exec = function(ctx) {
var code, codes, i, len, valueset;
valueset = this.valueset.execute(ctx);
if (!((valueset != null) && valueset.isValueSet)) {
throw new Error("ValueSet must be provided to InValueSet function");
}
codes = this.codes.exec(ctx);
for (i = 0, len = codes.length; i < len; i++) {
code = codes[i];
if (valueset.hasMatch(code)) {
return true;
}
}
return false;
};
return AnyInValueSet;
})(Expression);
module.exports.InValueSet = InValueSet = (function(superClass) {
extend(InValueSet, superClass);
function InValueSet(json) {
InValueSet.__super__.constructor.apply(this, arguments);
this.code = build(json.code);
this.valueset = new ValueSetRef(json.valueset);
}
InValueSet.prototype.exec = function(ctx) {
var code, valueset;
if (this.code == null) {
return false;
}
if (this.valueset == null) {
throw new Error("ValueSet must be provided to InValueSet function");
}
code = this.code.execute(ctx);
if (code == null) {
return false;
}
valueset = this.valueset.execute(ctx);
if (!((valueset != null) && valueset.isValueSet)) {
throw new Error("ValueSet must be provided to InValueSet function");
}
return valueset.hasMatch(code);
};
return InValueSet;
})(Expression);
module.exports.CodeSystemDef = CodeSystemDef = (function(superClass) {
extend(CodeSystemDef, superClass);
function CodeSystemDef(json) {
CodeSystemDef.__super__.constructor.apply(this, arguments);
this.name = json.name;
this.id = json.id;
this.version = json.version;
}
CodeSystemDef.prototype.exec = function(ctx) {
return new dt.CodeSystem(this.id, this.version);
};
return CodeSystemDef;
})(Expression);
module.exports.CodeDef = CodeDef = (function(superClass) {
extend(CodeDef, superClass);
function CodeDef(json) {
CodeDef.__super__.constructor.apply(this, arguments);
this.name = json.name;
this.id = json.id;
this.systemName = json.codeSystem.name;
this.display = json.display;
}
CodeDef.prototype.exec = function(ctx) {
var ref, system;
system = (ref = ctx.getCodeSystem(this.systemName)) != null ? ref.execute(ctx) : void 0;
return new dt.Code(this.id, system.id, system.version, this.display);
};
return CodeDef;
})(Expression);
module.exports.CodeRef = CodeRef = (function(superClass) {
extend(CodeRef, superClass);
function CodeRef(json) {
CodeRef.__super__.constructor.apply(this, arguments);
this.name = json.name;
this.library = json.libraryName;
}
CodeRef.prototype.exec = function(ctx) {
var ref;
ctx = this.library ? ctx.getLibraryContext(this.library) : ctx;
return (ref = ctx.getCode(this.name)) != null ? ref.execute(ctx) : void 0;
};
return CodeRef;
})(Expression);
module.exports.Code = Code = (function(superClass) {
extend(Code, superClass);
function Code(json) {
Code.__super__.constructor.apply(this, arguments);
this.code = json.code;
this.systemName = json.system.name;
this.version = json.version;
this.display = json.display;
}
Object.defineProperties(Code.prototype, {
isCode: {
get: function() {
return true;
}
}
});
Code.prototype.exec = function(ctx) {
var ref, system;
system = (ref = ctx.getCodeSystem(this.systemName)) != null ? ref.id : void 0;
return new dt.Code(this.code, system, this.version, this.display);
};
return Code;
})(Expression);
module.exports.ConceptDef = ConceptDef = (function(superClass) {
extend(ConceptDef, superClass);
function ConceptDef(json) {
ConceptDef.__super__.constructor.apply(this, arguments);
this.name = json.name;
this.display = json.display;
this.codes = json.code;
}
ConceptDef.prototype.exec = function(ctx) {
var code, codes;
codes = (function() {
var i, len, ref, ref1, results;
ref = this.codes;
results = [];
for (i = 0, len = ref.length; i < len; i++) {
code = ref[i];
results.push((ref1 = ctx.getCode(code.name)) != null ? ref1.execute(ctx) : void 0);
}
return results;
}).call(this);
return new dt.Concept(codes, this.display);
};
return ConceptDef;
})(Expression);
module.exports.ConceptRef = ConceptRef = (function(superClass) {
extend(ConceptRef, superClass);
function ConceptRef(json) {
ConceptRef.__super__.constructor.apply(this, arguments);
this.name = json.name;
}
ConceptRef.prototype.exec = function(ctx) {
var ref;
return (ref = ctx.getConcept(this.name)) != null ? ref.execute(ctx) : void 0;
};
return ConceptRef;
})(Expression);
module.exports.Concept = Concept = (function(superClass) {
extend(Concept, superClass);
function Concept(json) {
Concept.__super__.constructor.apply(this, arguments);
this.codes = json.code;
this.display = json.display;
}
Object.defineProperties(Concept.prototype, {
isConcept: {
get: function() {
return true;
}
}
});
Concept.prototype.toCode = function(ctx, code) {
var ref, system;
system = (ref = ctx.getCodeSystem(code.system.name)) != null ? ref.id : void 0;
return new dt.Code(code.code, system, code.version, code.display);
};
Concept.prototype.exec = function(ctx) {
var code, codes;
codes = (function() {
var i, len, ref, results;
ref = this.codes;
results = [];
for (i = 0, len = ref.length; i < len; i++) {
code = ref[i];
results.push(this.toCode(ctx, code));
}
return results;
}).call(this);
return new dt.Concept(codes, this.display);
};
return Concept;
})(Expression);
module.exports.CalculateAge = CalculateAge = (function(superClass) {
extend(CalculateAge, superClass);
function CalculateAge(json) {
CalculateAge.__super__.constructor.apply(this, arguments);
this.precision = json.precision;
}
CalculateAge.prototype.exec = function(ctx) {
var date1, date2, result;
date1 = this.execArgs(ctx);
date2 = dt.DateTime.fromJSDate(ctx.getExecutionDateTime());
result = date1 != null ? date1.durationBetween(date2, this.precision.toLowerCase()) : void 0;
if ((result != null) && result.isPoint()) {
return result.low;
} else {
return result;
}
};
return CalculateAge;
})(Expression);
module.exports.CalculateAgeAt = CalculateAgeAt = (function(superClass) {
extend(CalculateAgeAt, superClass);
function CalculateAgeAt(json) {
CalculateAgeAt.__super__.constructor.apply(this, arguments);
this.precision = json.precision;
}
CalculateAgeAt.prototype.exec = function(ctx) {
var date1, date2, ref, result;
ref = this.execArgs(ctx), date1 = ref[0], date2 = ref[1];
if ((date1 != null) && (date2 != null)) {
if (date2.isDate && date1.isDateTime) {
date1 = date1.getDate();
}
result = date1.durationBetween(date2, this.precision.toLowerCase());
if ((result != null) && result.isPoint()) {
return result.low;
} else {
return result;
}
} else {
return null;
}
};
return CalculateAgeAt;
})(Expression);
}).call(this);
//# sourceMappingURL=clinical.js.map