cql-execution
Version:
An execution framework for the Clinical Quality Language (CQL)
403 lines (318 loc) • 11.3 kB
JavaScript
// Generated by CoffeeScript 1.12.7
(function() {
var DT, Date, DateFrom, DateTime, DateTimeComponentFrom, DifferenceBetween, DurationBetween, Expression, Literal, Now, SameOrAfter, SameOrBefore, Time, TimeFrom, TimeOfDay, TimezoneFrom, Today, build,
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,
slice = [].slice;
Expression = require('./expression').Expression;
build = require('./builder').build;
Literal = require('./literal').Literal;
DT = require('../datatypes/datatypes');
module.exports.DateTime = DateTime = (function(superClass) {
extend(DateTime, superClass);
DateTime.PROPERTIES = ['year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond', 'timezoneOffset'];
function DateTime(json1) {
this.json = json1;
DateTime.__super__.constructor.apply(this, arguments);
}
Object.defineProperties(DateTime.prototype, {
isDateTime: {
get: function() {
return true;
}
}
});
DateTime.prototype.exec = function(ctx) {
var args, i, len, p, property, ref;
ref = DateTime.PROPERTIES;
for (i = 0, len = ref.length; i < len; i++) {
property = ref[i];
if (this.json[property] != null) {
this[property] = build(this.json[property]);
} else if (property === 'timezoneOffset' && (ctx.getTimezoneOffset() != null)) {
this[property] = Literal.from({
"type": "Literal",
"value": ctx.getTimezoneOffset(),
"valueType": "{urn:hl7-org:elm-types:r1}Integer"
});
}
}
args = (function() {
var j, len1, ref1, results;
ref1 = DateTime.PROPERTIES;
results = [];
for (j = 0, len1 = ref1.length; j < len1; j++) {
p = ref1[j];
results.push(this[p] != null ? this[p].execute(ctx) : void 0);
}
return results;
}).call(this);
return (function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(DT.DateTime, args, function(){});
};
return DateTime;
})(Expression);
module.exports.Date = Date = (function(superClass) {
extend(Date, superClass);
Date.PROPERTIES = ['year', 'month', 'day'];
function Date(json1) {
this.json = json1;
Date.__super__.constructor.apply(this, arguments);
}
Object.defineProperties(Date.prototype, {
isDate: {
get: function() {
return true;
}
}
});
Date.prototype.exec = function(ctx) {
var args, i, len, p, property, ref;
ref = Date.PROPERTIES;
for (i = 0, len = ref.length; i < len; i++) {
property = ref[i];
if (this.json[property] != null) {
this[property] = build(this.json[property]);
}
}
args = (function() {
var j, len1, ref1, results;
ref1 = Date.PROPERTIES;
results = [];
for (j = 0, len1 = ref1.length; j < len1; j++) {
p = ref1[j];
results.push(this[p] != null ? this[p].execute(ctx) : void 0);
}
return results;
}).call(this);
return (function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(DT.Date, args, function(){});
};
return Date;
})(Expression);
module.exports.Time = Time = (function(superClass) {
extend(Time, superClass);
Time.PROPERTIES = ['hour', 'minute', 'second', 'millisecond', 'timezoneOffset'];
function Time(json) {
var i, len, property, ref;
Time.__super__.constructor.apply(this, arguments);
ref = Time.PROPERTIES;
for (i = 0, len = ref.length; i < len; i++) {
property = ref[i];
if (json[property] != null) {
this[property] = build(json[property]);
}
}
}
Object.defineProperties(Time.prototype, {
isTime: {
get: function() {
return true;
}
}
});
Time.prototype.exec = function(ctx) {
var args, p;
args = (function() {
var i, len, ref, results;
ref = Time.PROPERTIES;
results = [];
for (i = 0, len = ref.length; i < len; i++) {
p = ref[i];
results.push(this[p] != null ? this[p].execute(ctx) : void 0);
}
return results;
}).call(this);
return ((function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(DT.DateTime, [0, 1, 1].concat(slice.call(args)), function(){})).getTime();
};
return Time;
})(Expression);
module.exports.Today = Today = (function(superClass) {
extend(Today, superClass);
function Today(json) {
Today.__super__.constructor.apply(this, arguments);
}
Today.prototype.exec = function(ctx) {
return ctx.getExecutionDateTime().getDate();
};
return Today;
})(Expression);
module.exports.Now = Now = (function(superClass) {
extend(Now, superClass);
function Now(json) {
Now.__super__.constructor.apply(this, arguments);
}
Now.prototype.exec = function(ctx) {
return ctx.getExecutionDateTime();
};
return Now;
})(Expression);
module.exports.TimeOfDay = TimeOfDay = (function(superClass) {
extend(TimeOfDay, superClass);
function TimeOfDay(json) {
TimeOfDay.__super__.constructor.apply(this, arguments);
}
TimeOfDay.prototype.exec = function(ctx) {
return ctx.getExecutionDateTime().getTime();
};
return TimeOfDay;
})(Expression);
module.exports.DateTimeComponentFrom = DateTimeComponentFrom = (function(superClass) {
extend(DateTimeComponentFrom, superClass);
function DateTimeComponentFrom(json) {
DateTimeComponentFrom.__super__.constructor.apply(this, arguments);
this.precision = json.precision;
}
DateTimeComponentFrom.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if (arg != null) {
return arg[this.precision.toLowerCase()];
} else {
return null;
}
};
return DateTimeComponentFrom;
})(Expression);
module.exports.DateFrom = DateFrom = (function(superClass) {
extend(DateFrom, superClass);
function DateFrom(json) {
DateFrom.__super__.constructor.apply(this, arguments);
}
DateFrom.prototype.exec = function(ctx) {
var date;
date = this.execArgs(ctx);
if (date != null) {
return date.getDate();
} else {
return null;
}
};
return DateFrom;
})(Expression);
module.exports.TimeFrom = TimeFrom = (function(superClass) {
extend(TimeFrom, superClass);
function TimeFrom(json) {
TimeFrom.__super__.constructor.apply(this, arguments);
}
TimeFrom.prototype.exec = function(ctx) {
var date;
date = this.execArgs(ctx);
if (date != null) {
return date.getTime();
} else {
return null;
}
};
return TimeFrom;
})(Expression);
module.exports.TimezoneFrom = TimezoneFrom = (function(superClass) {
extend(TimezoneFrom, superClass);
function TimezoneFrom(json) {
TimezoneFrom.__super__.constructor.apply(this, arguments);
}
TimezoneFrom.prototype.exec = function(ctx) {
var date;
date = this.execArgs(ctx);
if (date != null) {
return date.timezoneOffset;
} else {
return null;
}
};
return TimezoneFrom;
})(Expression);
module.exports.SameOrAfter = SameOrAfter = (function(superClass) {
extend(SameOrAfter, superClass);
function SameOrAfter(json) {
SameOrAfter.__super__.constructor.apply(this, arguments);
this.precision = json.precision;
}
SameOrAfter.prototype.exec = function(ctx) {
var d1, d2, ref, ref1;
ref = this.execArgs(ctx), d1 = ref[0], d2 = ref[1];
if ((d1 != null) && (d2 != null)) {
return d1.sameOrAfter(d2, (ref1 = this.precision) != null ? ref1.toLowerCase() : void 0);
} else {
return null;
}
};
return SameOrAfter;
})(Expression);
module.exports.SameOrBefore = SameOrBefore = (function(superClass) {
extend(SameOrBefore, superClass);
function SameOrBefore(json) {
SameOrBefore.__super__.constructor.apply(this, arguments);
this.precision = json.precision;
}
SameOrBefore.prototype.exec = function(ctx) {
var d1, d2, ref, ref1;
ref = this.execArgs(ctx), d1 = ref[0], d2 = ref[1];
if ((d1 != null) && (d2 != null)) {
return d1.sameOrBefore(d2, (ref1 = this.precision) != null ? ref1.toLowerCase() : void 0);
} else {
return null;
}
};
return SameOrBefore;
})(Expression);
module.exports.doAfter = function(a, b, precision) {
return a.after(b, precision);
};
module.exports.doBefore = function(a, b, precision) {
return a.before(b, precision);
};
module.exports.DifferenceBetween = DifferenceBetween = (function(superClass) {
extend(DifferenceBetween, superClass);
function DifferenceBetween(json) {
DifferenceBetween.__super__.constructor.apply(this, arguments);
this.precision = json.precision;
}
DifferenceBetween.prototype.exec = function(ctx) {
var args, ref, result;
args = this.execArgs(ctx);
if ((args[0] == null) || (args[1] == null) || typeof args[0].differenceBetween !== 'function' || typeof args[1].differenceBetween !== 'function') {
return null;
}
result = args[0].differenceBetween(args[1], (ref = this.precision) != null ? ref.toLowerCase() : void 0);
if ((result != null) && result.isPoint()) {
return result.low;
} else {
return result;
}
};
return DifferenceBetween;
})(Expression);
module.exports.DurationBetween = DurationBetween = (function(superClass) {
extend(DurationBetween, superClass);
function DurationBetween(json) {
DurationBetween.__super__.constructor.apply(this, arguments);
this.precision = json.precision;
}
DurationBetween.prototype.exec = function(ctx) {
var args, ref, result;
args = this.execArgs(ctx);
if ((args[0] == null) || (args[1] == null) || typeof args[0].durationBetween !== 'function' || typeof args[1].durationBetween !== 'function') {
return null;
}
result = args[0].durationBetween(args[1], (ref = this.precision) != null ? ref.toLowerCase() : void 0);
if ((result != null) && result.isPoint()) {
return result.low;
} else {
return result;
}
};
return DurationBetween;
})(Expression);
}).call(this);
//# sourceMappingURL=datetime.js.map