cql-execution
Version:
An execution framework for the Clinical Quality Language (CQL)
520 lines (401 loc) • 12.7 kB
JavaScript
// Generated by CoffeeScript 1.12.7
(function() {
var Abs, Add, Ceiling, Divide, Exp, Expression, Floor, Ln, Log, MathUtil, MaxValue, MinValue, Modulo, Multiply, Negate, Power, Predecessor, Quantity, Round, Subtract, Successor, Truncate, TruncatedDivide, allTrue, anyTrue, build, ref, 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;
ref = require('../util/util'), typeIsArray = ref.typeIsArray, allTrue = ref.allTrue, anyTrue = ref.anyTrue;
build = require('./builder').build;
MathUtil = require('../util/math');
Quantity = require('./quantity');
module.exports.Add = Add = (function(superClass) {
extend(Add, superClass);
function Add(json) {
Add.__super__.constructor.apply(this, arguments);
}
Add.prototype.exec = function(ctx) {
var args;
args = this.execArgs(ctx);
if ((args == null) || args.some(function(x) {
return x == null;
})) {
return null;
} else {
return args != null ? args.reduce(function(x, y) {
if (x.isQuantity || x.isDateTime || x.isDate) {
return Quantity.doAddition(x, y);
} else {
return x + y;
}
}) : void 0;
}
};
return Add;
})(Expression);
module.exports.Subtract = Subtract = (function(superClass) {
extend(Subtract, superClass);
function Subtract(json) {
Subtract.__super__.constructor.apply(this, arguments);
}
Subtract.prototype.exec = function(ctx) {
var args;
args = this.execArgs(ctx);
if ((args == null) || args.some(function(x) {
return x == null;
})) {
return null;
} else {
return args.reduce(function(x, y) {
if (x.isQuantity || x.isDateTime || x.isDate) {
return Quantity.doSubtraction(x, y);
} else {
return x - y;
}
});
}
};
return Subtract;
})(Expression);
module.exports.Multiply = Multiply = (function(superClass) {
extend(Multiply, superClass);
function Multiply(json) {
Multiply.__super__.constructor.apply(this, arguments);
}
Multiply.prototype.exec = function(ctx) {
var args;
args = this.execArgs(ctx);
if ((args == null) || args.some(function(x) {
return x == null;
})) {
return null;
} else {
return args != null ? args.reduce(function(x, y) {
if (x.isQuantity || y.isQuantity) {
return Quantity.doMultiplication(x, y);
} else {
return x * y;
}
}) : void 0;
}
};
return Multiply;
})(Expression);
module.exports.Divide = Divide = (function(superClass) {
extend(Divide, superClass);
function Divide(json) {
Divide.__super__.constructor.apply(this, arguments);
}
Divide.prototype.exec = function(ctx) {
var args;
args = this.execArgs(ctx);
if ((args == null) || args.some(function(x) {
return x == null;
})) {
return null;
} else {
return args != null ? args.reduce(function(x, y) {
if (x.isQuantity) {
return Quantity.doDivision(x, y);
} else {
return x / y;
}
}) : void 0;
}
};
return Divide;
})(Expression);
module.exports.TruncatedDivide = TruncatedDivide = (function(superClass) {
extend(TruncatedDivide, superClass);
function TruncatedDivide(json) {
TruncatedDivide.__super__.constructor.apply(this, arguments);
}
TruncatedDivide.prototype.exec = function(ctx) {
var args;
args = this.execArgs(ctx);
if ((args == null) || args.some(function(x) {
return x == null;
})) {
return null;
} else {
return Math.floor(args.reduce(function(x, y) {
return x / y;
}));
}
};
return TruncatedDivide;
})(Expression);
module.exports.Modulo = Modulo = (function(superClass) {
extend(Modulo, superClass);
function Modulo(json) {
Modulo.__super__.constructor.apply(this, arguments);
}
Modulo.prototype.exec = function(ctx) {
var args;
args = this.execArgs(ctx);
if ((args == null) || args.some(function(x) {
return x == null;
})) {
return null;
} else {
return args.reduce(function(x, y) {
return x % y;
});
}
};
return Modulo;
})(Expression);
module.exports.Ceiling = Ceiling = (function(superClass) {
extend(Ceiling, superClass);
function Ceiling(json) {
Ceiling.__super__.constructor.apply(this, arguments);
}
Ceiling.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if (arg == null) {
return null;
} else {
return Math.ceil(arg);
}
};
return Ceiling;
})(Expression);
module.exports.Floor = Floor = (function(superClass) {
extend(Floor, superClass);
function Floor(json) {
Floor.__super__.constructor.apply(this, arguments);
}
Floor.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if (arg == null) {
return null;
} else {
return Math.floor(arg);
}
};
return Floor;
})(Expression);
module.exports.Truncate = Truncate = (function(superClass) {
extend(Truncate, superClass);
function Truncate() {
return Truncate.__super__.constructor.apply(this, arguments);
}
return Truncate;
})(Floor);
module.exports.Abs = Abs = (function(superClass) {
extend(Abs, superClass);
function Abs(json) {
Abs.__super__.constructor.apply(this, arguments);
}
Abs.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if (arg == null) {
return null;
} else if (arg.isQuantity) {
return Quantity.createQuantity(Math.abs(arg.value), arg.unit);
} else {
return Math.abs(arg);
}
};
return Abs;
})(Expression);
module.exports.Negate = Negate = (function(superClass) {
extend(Negate, superClass);
function Negate(json) {
Negate.__super__.constructor.apply(this, arguments);
}
Negate.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if (arg == null) {
return null;
} else if (arg.isQuantity) {
return Quantity.createQuantity(arg.value * -1, arg.unit);
} else {
return arg * -1;
}
};
return Negate;
})(Expression);
module.exports.Round = Round = (function(superClass) {
extend(Round, superClass);
function Round(json) {
Round.__super__.constructor.apply(this, arguments);
this.precision = build(json.precision);
}
Round.prototype.exec = function(ctx) {
var arg, dec;
arg = this.execArgs(ctx);
if (arg == null) {
return null;
} else {
dec = this.precision != null ? this.precision.execute(ctx) : 0;
return Math.round(arg * Math.pow(10, dec)) / Math.pow(10, dec);
}
};
return Round;
})(Expression);
module.exports.Ln = Ln = (function(superClass) {
extend(Ln, superClass);
function Ln(json) {
Ln.__super__.constructor.apply(this, arguments);
}
Ln.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if (arg == null) {
return null;
} else {
return Math.log(arg);
}
};
return Ln;
})(Expression);
module.exports.Exp = Exp = (function(superClass) {
extend(Exp, superClass);
function Exp(json) {
Exp.__super__.constructor.apply(this, arguments);
}
Exp.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if (arg == null) {
return null;
} else {
return Math.exp(arg);
}
};
return Exp;
})(Expression);
module.exports.Log = Log = (function(superClass) {
extend(Log, superClass);
function Log(json) {
Log.__super__.constructor.apply(this, arguments);
}
Log.prototype.exec = function(ctx) {
var args;
args = this.execArgs(ctx);
if ((args == null) || args.some(function(x) {
return x == null;
})) {
return null;
} else {
return args.reduce(function(x, y) {
return Math.log(x) / Math.log(y);
});
}
};
return Log;
})(Expression);
module.exports.Power = Power = (function(superClass) {
extend(Power, superClass);
function Power(json) {
Power.__super__.constructor.apply(this, arguments);
}
Power.prototype.exec = function(ctx) {
var args;
args = this.execArgs(ctx);
if ((args == null) || args.some(function(x) {
return x == null;
})) {
return null;
} else {
return args.reduce(function(x, y) {
return Math.pow(x, y);
});
}
};
return Power;
})(Expression);
module.exports.MinValue = MinValue = (function(superClass) {
var MIN_VALUES;
extend(MinValue, superClass);
MIN_VALUES = {};
MIN_VALUES['{urn:hl7-org:elm-types:r1}Integer'] = MathUtil.MIN_INT_VALUE;
MIN_VALUES['{urn:hl7-org:elm-types:r1}Decimal'] = MathUtil.MIN_FLOAT_VALUE;
MIN_VALUES['{urn:hl7-org:elm-types:r1}DateTime'] = MathUtil.MIN_DATE_VALUE;
MIN_VALUES['{urn:hl7-org:elm-types:r1}Time'] = MathUtil.MIN_TIME_VALUE;
function MinValue(json) {
MinValue.__super__.constructor.apply(this, arguments);
this.valueType = json.valueType;
}
MinValue.prototype.exec = function(ctx) {
var minDateTime;
if (MIN_VALUES[this.valueType]) {
if (this.valueType === '{urn:hl7-org:elm-types:r1}DateTime') {
minDateTime = MIN_VALUES[this.valueType].copy();
minDateTime.timezoneOffset = ctx.getTimezoneOffset();
return minDateTime;
} else {
return MIN_VALUES[this.valueType];
}
} else {
throw new Error("Minimum not supported for " + this.valueType);
}
};
return MinValue;
})(Expression);
module.exports.MaxValue = MaxValue = (function(superClass) {
var MAX_VALUES;
extend(MaxValue, superClass);
MAX_VALUES = {};
MAX_VALUES['{urn:hl7-org:elm-types:r1}Integer'] = MathUtil.MAX_INT_VALUE;
MAX_VALUES['{urn:hl7-org:elm-types:r1}Decimal'] = MathUtil.MAX_FLOAT_VALUE;
MAX_VALUES['{urn:hl7-org:elm-types:r1}DateTime'] = MathUtil.MAX_DATE_VALUE;
MAX_VALUES['{urn:hl7-org:elm-types:r1}Time'] = MathUtil.MAX_TIME_VALUE;
function MaxValue(json) {
MaxValue.__super__.constructor.apply(this, arguments);
this.valueType = json.valueType;
}
MaxValue.prototype.exec = function(ctx) {
var maxDateTime;
if (MAX_VALUES[this.valueType] != null) {
if (this.valueType === '{urn:hl7-org:elm-types:r1}DateTime') {
maxDateTime = MAX_VALUES[this.valueType].copy();
maxDateTime.timezoneOffset = ctx.getTimezoneOffset();
return maxDateTime;
} else {
return MAX_VALUES[this.valueType];
}
} else {
throw new Error("Maximum not supported for " + this.valueType);
}
};
return MaxValue;
})(Expression);
module.exports.Successor = Successor = (function(superClass) {
extend(Successor, superClass);
function Successor(json) {
Successor.__super__.constructor.apply(this, arguments);
}
Successor.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if (arg == null) {
return null;
} else {
return MathUtil.successor(arg);
}
};
return Successor;
})(Expression);
module.exports.Predecessor = Predecessor = (function(superClass) {
extend(Predecessor, superClass);
function Predecessor(json) {
Predecessor.__super__.constructor.apply(this, arguments);
}
Predecessor.prototype.exec = function(ctx) {
var arg;
arg = this.execArgs(ctx);
if (arg == null) {
return null;
} else {
return MathUtil.predecessor(arg);
}
};
return Predecessor;
})(Expression);
}).call(this);
//# sourceMappingURL=arithmetic.js.map