cql-execution
Version:
An execution framework for the Clinical Quality Language (CQL)
659 lines (522 loc) • 18.7 kB
JavaScript
// Generated by CoffeeScript 1.12.7
(function() {
var As, Concept, Convert, ConvertsToBoolean, ConvertsToDate, ConvertsToDateTime, ConvertsToDecimal, ConvertsToInteger, ConvertsToQuantity, ConvertsToRatio, ConvertsToString, ConvertsToTime, Date, DateTime, Expression, FunctionRef, IntervalTypeSpecifier, Is, ListTypeSpecifier, NamedTypeSpecifier, Ratio, ToBoolean, ToConcept, ToDate, ToDateTime, ToDecimal, ToInteger, ToQuantity, ToRatio, ToString, ToTime, TupleTypeSpecifier, UnimplementedExpression, canConvertToType, isValidDecimal, isValidInteger, limitDecimalPrecision, normalizeMillisecondsField, parseQuantity, ref, ref1, ref2,
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;
ref = require('./expression'), Expression = ref.Expression, UnimplementedExpression = ref.UnimplementedExpression;
FunctionRef = require('./reusable').FunctionRef;
ref1 = require('../datatypes/datetime'), DateTime = ref1.DateTime, Date = ref1.Date;
Concept = require('../datatypes/clinical').Concept;
parseQuantity = require('./quantity').parseQuantity;
ref2 = require('../util/math'), isValidDecimal = ref2.isValidDecimal, isValidInteger = ref2.isValidInteger, limitDecimalPrecision = ref2.limitDecimalPrecision;
normalizeMillisecondsField = require('../util/util').normalizeMillisecondsField;
Ratio = require('./ratio').Ratio;
module.exports.As = As = (function(superClass) {
extend(As, superClass);
function As(json) {
var ref3;
As.__super__.constructor.apply(this, arguments);
this.asType = json.asType;
this.asTypeSpecifier = json.asTypeSpecifier;
this.strict = (ref3 = json.strict) != null ? ref3 : false;
}
As.prototype.exec = function(ctx) {
return this.execArgs(ctx);
};
return As;
})(Expression);
module.exports.ToBoolean = ToBoolean = (function(superClass) {
extend(ToBoolean, superClass);
function ToBoolean(json) {
ToBoolean.__super__.constructor.apply(this, arguments);
}
ToBoolean.prototype.exec = function(ctx) {
var arg, strArg;
arg = this.execArgs(ctx);
if ((arg != null) && typeof arg !== 'undefined') {
strArg = arg.toString().toLowerCase();
if (strArg === "true" || strArg === "t" || strArg === "yes" || strArg === "y" || strArg === "1") {
return true;
} else if (strArg === "false" || strArg === "f" || strArg === "no" || strArg === "n" || strArg === "0") {
return false;
} else {
return null;
}
} else {
return null;
}
};
return ToBoolean;
})(Expression);
module.exports.ToConcept = ToConcept = (function(superClass) {
extend(ToConcept, superClass);
function ToConcept(json) {
ToConcept.__super__.constructor.apply(this, arguments);
}
ToConcept.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if ((arg != null) && typeof arg !== 'undefined') {
return new Concept([arg], arg.display);
} else {
return null;
}
};
return ToConcept;
})(Expression);
module.exports.ToDate = ToDate = (function(superClass) {
extend(ToDate, superClass);
function ToDate(json) {
ToDate.__super__.constructor.apply(this, arguments);
}
ToDate.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if (arg == null) {
return null;
} else if (arg.isDateTime) {
return arg.getDate();
} else {
return Date.parse(arg.toString());
}
};
return ToDate;
})(Expression);
module.exports.ToDateTime = ToDateTime = (function(superClass) {
extend(ToDateTime, superClass);
function ToDateTime(json) {
ToDateTime.__super__.constructor.apply(this, arguments);
}
ToDateTime.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if (arg == null) {
return null;
} else if (arg.isDate) {
return arg.getDateTime();
} else {
return DateTime.parse(arg.toString());
}
};
return ToDateTime;
})(Expression);
module.exports.ToDecimal = ToDecimal = (function(superClass) {
extend(ToDecimal, superClass);
function ToDecimal(json) {
ToDecimal.__super__.constructor.apply(this, arguments);
}
ToDecimal.prototype.exec = function(ctx) {
var arg, decimal;
arg = this.execArgs(ctx);
if ((arg != null) && typeof arg !== 'undefined') {
decimal = parseFloat(arg.toString());
decimal = limitDecimalPrecision(decimal);
if (isValidDecimal(decimal)) {
return decimal;
}
}
return null;
};
return ToDecimal;
})(Expression);
module.exports.ToInteger = ToInteger = (function(superClass) {
extend(ToInteger, superClass);
function ToInteger(json) {
ToInteger.__super__.constructor.apply(this, arguments);
}
ToInteger.prototype.exec = function(ctx) {
var arg, integer;
arg = this.execArgs(ctx);
if ((arg != null) && typeof arg !== 'undefined') {
integer = parseInt(arg.toString());
if (isValidInteger(integer)) {
return integer;
}
}
return null;
};
return ToInteger;
})(Expression);
module.exports.ToQuantity = ToQuantity = (function(superClass) {
extend(ToQuantity, superClass);
function ToQuantity(json) {
ToQuantity.__super__.constructor.apply(this, arguments);
}
ToQuantity.prototype.exec = function(ctx) {
var arg, quantity;
arg = this.execArgs(ctx);
if ((arg != null) && typeof arg !== 'undefined') {
quantity = parseQuantity(arg.toString());
return quantity;
} else {
return null;
}
};
return ToQuantity;
})(Expression);
module.exports.ToRatio = ToRatio = (function(superClass) {
extend(ToRatio, superClass);
function ToRatio(json) {
ToRatio.__super__.constructor.apply(this, arguments);
}
ToRatio.prototype.exec = function(ctx) {
var arg, denominator, numerator, splitRatioString;
arg = this.execArgs(ctx);
if (arg != null) {
try {
splitRatioString = arg.toString().match(/^(\d+(\.\d+)?\s*('.+')?)\s*:\s*(\d+(\.\d+)?\s*('.+')?)$/);
if (splitRatioString == null) {
return null;
}
numerator = parseQuantity(splitRatioString[1]);
denominator = parseQuantity(splitRatioString[4]);
} catch (error) {
return null;
}
if (!((numerator != null) && (denominator != null))) {
return null;
}
return new Ratio({
numerator: numerator,
denominator: denominator
});
} else {
return null;
}
};
return ToRatio;
})(Expression);
module.exports.ToString = ToString = (function(superClass) {
extend(ToString, superClass);
function ToString(json) {
ToString.__super__.constructor.apply(this, arguments);
}
ToString.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if ((arg != null) && typeof arg !== 'undefined') {
return arg.toString();
} else {
return null;
}
};
return ToString;
})(Expression);
module.exports.ToTime = ToTime = (function(superClass) {
extend(ToTime, superClass);
function ToTime(json) {
ToTime.__super__.constructor.apply(this, arguments);
}
ToTime.prototype.exec = function(ctx) {
var arg, hours, matches, milliseconds, minutes, seconds, timeString, timezoneOffset, tz;
arg = this.execArgs(ctx);
if ((arg != null) && typeof arg !== 'undefined') {
timeString = arg.toString();
matches = /T((\d{2})(\:(\d{2})(\:(\d{2})(\.(\d+))?)?)?)?(Z|(([+-])(\d{2})(\:?(\d{2}))?))?/.exec(timeString);
if (matches == null) {
return null;
}
hours = matches[2];
minutes = matches[4];
seconds = matches[6];
if (hours != null) {
if (!(hours >= 0 && hours <= 23)) {
return null;
}
hours = parseInt(hours, 10);
}
if (minutes != null) {
if (!(minutes >= 0 && minutes <= 59)) {
return null;
}
minutes = parseInt(minutes, 10);
}
if (seconds != null) {
if (!(seconds >= 0 && seconds <= 59)) {
return null;
}
seconds = parseInt(seconds, 10);
}
milliseconds = matches[8];
if (milliseconds != null) {
milliseconds = parseInt(normalizeMillisecondsField(milliseconds));
}
if (matches[11] != null) {
tz = parseInt(matches[12], 10) + (matches[14] != null ? parseInt(matches[14], 10) / 60 : 0);
timezoneOffset = matches[11] === '+' ? tz : tz * -1;
} else if (matches[9] === 'Z') {
timezoneOffset = 0;
}
return new DateTime(0, 1, 1, hours, minutes, seconds, milliseconds, timezoneOffset);
} else {
return null;
}
};
return ToTime;
})(Expression);
module.exports.Convert = Convert = (function(superClass) {
extend(Convert, superClass);
function Convert(json) {
Convert.__super__.constructor.apply(this, arguments);
this.operand = json.operand;
this.toType = json.toType;
}
Convert.prototype.exec = function(ctx) {
switch (this.toType) {
case "{urn:hl7-org:elm-types:r1}Boolean":
return new ToBoolean({
"type": "ToBoolean",
"operand": this.operand
}).execute(ctx);
case "{urn:hl7-org:elm-types:r1}Concept":
return new ToConcept({
"type": "ToConcept",
"operand": this.operand
}).execute(ctx);
case "{urn:hl7-org:elm-types:r1}Decimal":
return new ToDecimal({
"type": "ToDecimal",
"operand": this.operand
}).execute(ctx);
case "{urn:hl7-org:elm-types:r1}Integer":
return new ToInteger({
"type": "ToInteger",
"operand": this.operand
}).execute(ctx);
case "{urn:hl7-org:elm-types:r1}String":
return new ToString({
"type": "ToString",
"operand": this.operand
}).execute(ctx);
case "{urn:hl7-org:elm-types:r1}Quantity":
return new ToQuantity({
"type": "ToQuantity",
"operand": this.operand
}).execute(ctx);
case "{urn:hl7-org:elm-types:r1}DateTime":
return new ToDateTime({
"type": "ToDateTime",
"operand": this.operand
}).execute(ctx);
case "{urn:hl7-org:elm-types:r1}Date":
return new ToDate({
"type": "ToDate",
"operand": this.operand
}).execute(ctx);
case "{urn:hl7-org:elm-types:r1}Time":
return new ToTime({
"type": "ToTime",
"operand": this.operand
}).execute(ctx);
default:
return this.execArgs(ctx);
}
};
return Convert;
})(Expression);
module.exports.ConvertsToBoolean = ConvertsToBoolean = (function(superClass) {
extend(ConvertsToBoolean, superClass);
function ConvertsToBoolean(json) {
ConvertsToBoolean.__super__.constructor.apply(this, arguments);
this.operand = json.operand;
}
ConvertsToBoolean.prototype.exec = function(ctx) {
var operatorValue;
operatorValue = this.execArgs(ctx);
if (operatorValue === null) {
return null;
} else {
return canConvertToType(ToBoolean, this.operand, ctx);
}
};
return ConvertsToBoolean;
})(Expression);
module.exports.ConvertsToDate = ConvertsToDate = (function(superClass) {
extend(ConvertsToDate, superClass);
function ConvertsToDate(json) {
ConvertsToDate.__super__.constructor.apply(this, arguments);
this.operand = json.operand;
}
ConvertsToDate.prototype.exec = function(ctx) {
var operatorValue;
operatorValue = this.execArgs(ctx);
if (operatorValue === null) {
return null;
} else {
return canConvertToType(ToDate, this.operand, ctx);
}
};
return ConvertsToDate;
})(Expression);
module.exports.ConvertsToDateTime = ConvertsToDateTime = (function(superClass) {
extend(ConvertsToDateTime, superClass);
function ConvertsToDateTime(json) {
ConvertsToDateTime.__super__.constructor.apply(this, arguments);
this.operand = json.operand;
}
ConvertsToDateTime.prototype.exec = function(ctx) {
var operatorValue;
operatorValue = this.execArgs(ctx);
if (operatorValue === null) {
return null;
} else {
return canConvertToType(ToDateTime, this.operand, ctx);
}
};
return ConvertsToDateTime;
})(Expression);
module.exports.ConvertsToDecimal = ConvertsToDecimal = (function(superClass) {
extend(ConvertsToDecimal, superClass);
function ConvertsToDecimal(json) {
ConvertsToDecimal.__super__.constructor.apply(this, arguments);
this.operand = json.operand;
}
ConvertsToDecimal.prototype.exec = function(ctx) {
var operatorValue;
operatorValue = this.execArgs(ctx);
if (operatorValue === null) {
return null;
} else {
return canConvertToType(ToDecimal, this.operand, ctx);
}
};
return ConvertsToDecimal;
})(Expression);
module.exports.ConvertsToInteger = ConvertsToInteger = (function(superClass) {
extend(ConvertsToInteger, superClass);
function ConvertsToInteger(json) {
ConvertsToInteger.__super__.constructor.apply(this, arguments);
this.operand = json.operand;
}
ConvertsToInteger.prototype.exec = function(ctx) {
var operatorValue;
operatorValue = this.execArgs(ctx);
if (operatorValue === null) {
return null;
} else {
return canConvertToType(ToInteger, this.operand, ctx);
}
};
return ConvertsToInteger;
})(Expression);
module.exports.ConvertsToQuantity = ConvertsToQuantity = (function(superClass) {
extend(ConvertsToQuantity, superClass);
function ConvertsToQuantity(json) {
ConvertsToQuantity.__super__.constructor.apply(this, arguments);
this.operand = json.operand;
}
ConvertsToQuantity.prototype.exec = function(ctx) {
var operatorValue;
operatorValue = this.execArgs(ctx);
if (operatorValue === null) {
return null;
} else {
return canConvertToType(ToQuantity, this.operand, ctx);
}
};
return ConvertsToQuantity;
})(Expression);
module.exports.ConvertsToRatio = ConvertsToRatio = (function(superClass) {
extend(ConvertsToRatio, superClass);
function ConvertsToRatio(json) {
ConvertsToRatio.__super__.constructor.apply(this, arguments);
this.operand = json.operand;
}
ConvertsToRatio.prototype.exec = function(ctx) {
var operatorValue;
operatorValue = this.execArgs(ctx);
if (operatorValue === null) {
return null;
} else {
return canConvertToType(ToRatio, this.operand, ctx);
}
};
return ConvertsToRatio;
})(Expression);
module.exports.ConvertsToString = ConvertsToString = (function(superClass) {
extend(ConvertsToString, superClass);
function ConvertsToString(json) {
ConvertsToString.__super__.constructor.apply(this, arguments);
this.operand = json.operand;
}
ConvertsToString.prototype.exec = function(ctx) {
var operatorValue;
operatorValue = this.execArgs(ctx);
if (operatorValue === null) {
return null;
} else {
return canConvertToType(ToString, this.operand, ctx);
}
};
return ConvertsToString;
})(Expression);
module.exports.ConvertsToTime = ConvertsToTime = (function(superClass) {
extend(ConvertsToTime, superClass);
function ConvertsToTime(json) {
ConvertsToTime.__super__.constructor.apply(this, arguments);
this.operand = json.operand;
}
ConvertsToTime.prototype.exec = function(ctx) {
var operatorValue;
operatorValue = this.execArgs(ctx);
if (operatorValue === null) {
return null;
} else {
return canConvertToType(ToTime, this.operand, ctx);
}
};
return ConvertsToTime;
})(Expression);
canConvertToType = function(toFunction, operand, ctx) {
var value;
try {
value = new toFunction({
"type": toFunction.name,
"operand": operand
}).execute(ctx);
if (value != null) {
return true;
} else {
return false;
}
} catch (error) {
return false;
}
};
module.exports.Is = Is = (function(superClass) {
extend(Is, superClass);
function Is() {
return Is.__super__.constructor.apply(this, arguments);
}
return Is;
})(UnimplementedExpression);
module.exports.IntervalTypeSpecifier = IntervalTypeSpecifier = (function(superClass) {
extend(IntervalTypeSpecifier, superClass);
function IntervalTypeSpecifier() {
return IntervalTypeSpecifier.__super__.constructor.apply(this, arguments);
}
return IntervalTypeSpecifier;
})(UnimplementedExpression);
module.exports.ListTypeSpecifier = ListTypeSpecifier = (function(superClass) {
extend(ListTypeSpecifier, superClass);
function ListTypeSpecifier() {
return ListTypeSpecifier.__super__.constructor.apply(this, arguments);
}
return ListTypeSpecifier;
})(UnimplementedExpression);
module.exports.NamedTypeSpecifier = NamedTypeSpecifier = (function(superClass) {
extend(NamedTypeSpecifier, superClass);
function NamedTypeSpecifier() {
return NamedTypeSpecifier.__super__.constructor.apply(this, arguments);
}
return NamedTypeSpecifier;
})(UnimplementedExpression);
module.exports.TupleTypeSpecifier = TupleTypeSpecifier = (function(superClass) {
extend(TupleTypeSpecifier, superClass);
function TupleTypeSpecifier() {
return TupleTypeSpecifier.__super__.constructor.apply(this, arguments);
}
return TupleTypeSpecifier;
})(UnimplementedExpression);
}).call(this);
//# sourceMappingURL=type.js.map