cql-execution
Version:
An execution framework for the Clinical Quality Language (CQL)
79 lines (67 loc) • 2.55 kB
JavaScript
// Generated by CoffeeScript 1.12.7
(function() {
var Expression, Retrieve, build, typeIsArray,
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;
build = require('./builder').build;
typeIsArray = require('../util/util').typeIsArray;
module.exports.Retrieve = Retrieve = (function(superClass) {
extend(Retrieve, superClass);
function Retrieve(json) {
Retrieve.__super__.constructor.apply(this, arguments);
this.datatype = json.dataType;
this.templateId = json.templateId;
this.codeProperty = json.codeProperty;
this.codes = build(json.codes);
this.dateProperty = json.dateProperty;
this.dateRange = build(json.dateRange);
}
Retrieve.prototype.exec = function(ctx) {
var codes, r, range, records, ref;
records = ctx.findRecords((ref = this.templateId) != null ? ref : this.datatype);
codes = this.codes;
if (this.codes && typeof this.codes.exec === 'function') {
codes = this.codes.execute(ctx);
if (codes == null) {
return [];
}
}
if (codes) {
records = records.filter((function(_this) {
return function(r) {
return _this.recordMatchesCodesOrVS(r, codes);
};
})(this));
}
if (this.dateRange && this.dateProperty) {
range = this.dateRange.execute(ctx);
records = (function() {
var i, len, results;
results = [];
for (i = 0, len = records.length; i < len; i++) {
r = records[i];
if (range.includes(r.getDateOrInterval(this.dateProperty))) {
results.push(r);
}
}
return results;
}).call(this);
}
return records;
};
Retrieve.prototype.recordMatchesCodesOrVS = function(record, codes) {
if (typeIsArray(codes)) {
return codes.some((function(_this) {
return function(c) {
return c.hasMatch(record.getCode(_this.codeProperty));
};
})(this));
} else {
return codes.hasMatch(record.getCode(this.codeProperty));
}
};
return Retrieve;
})(Expression);
}).call(this);
//# sourceMappingURL=external.js.map