UNPKG

cql-execution

Version:

An execution framework for the Clinical Quality Language (CQL)

158 lines (123 loc) 5.04 kB
// Generated by CoffeeScript 1.12.7 (function() { var Expression, ExpressionDef, ExpressionRef, FunctionDef, FunctionRef, IdentifierRef, OperandRef, 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; Expression = require('./expression').Expression; build = require('./builder').build; module.exports.ExpressionDef = ExpressionDef = (function(superClass) { extend(ExpressionDef, superClass); function ExpressionDef(json) { ExpressionDef.__super__.constructor.apply(this, arguments); this.name = json.name; this.context = json.context; this.expression = build(json.expression); } ExpressionDef.prototype.exec = function(ctx) { var ref, value; value = (ref = this.expression) != null ? ref.execute(ctx) : void 0; ctx.rootContext().set(this.name, value); return value; }; return ExpressionDef; })(Expression); module.exports.ExpressionRef = ExpressionRef = (function(superClass) { extend(ExpressionRef, superClass); function ExpressionRef(json) { ExpressionRef.__super__.constructor.apply(this, arguments); this.name = json.name; this.library = json.libraryName; } ExpressionRef.prototype.exec = function(ctx) { var value; ctx = this.library ? ctx.getLibraryContext(this.library) : ctx; value = ctx.get(this.name); if (value instanceof Expression) { value = value.execute(ctx); } return value; }; return ExpressionRef; })(Expression); module.exports.FunctionDef = FunctionDef = (function(superClass) { extend(FunctionDef, superClass); function FunctionDef(json) { FunctionDef.__super__.constructor.apply(this, arguments); this.name = json.name; this.expression = build(json.expression); this.parameters = json.operand; } FunctionDef.prototype.exec = function(ctx) { return this; }; return FunctionDef; })(Expression); module.exports.FunctionRef = FunctionRef = (function(superClass) { extend(FunctionRef, superClass); function FunctionRef(json) { FunctionRef.__super__.constructor.apply(this, arguments); this.name = json.name; this.library = json.libraryName; } FunctionRef.prototype.exec = function(ctx) { var args, child_ctx, functionDef, i, j, len, p, ref, ref1, ref2; functionDef = this.library ? (ref = ctx.get(this.library)) != null ? ref.get(this.name) : void 0 : ctx.get(this.name); args = this.execArgs(ctx); child_ctx = this.library ? (ref1 = ctx.getLibraryContext(this.library)) != null ? ref1.childContext() : void 0 : ctx.childContext(); if (args.length !== functionDef.parameters.length) { throw new Error("incorrect number of arguments supplied"); } ref2 = functionDef.parameters; for (i = j = 0, len = ref2.length; j < len; i = ++j) { p = ref2[i]; child_ctx.set(p.name, args[i]); } return functionDef.expression.execute(child_ctx); }; return FunctionRef; })(Expression); module.exports.OperandRef = OperandRef = (function(superClass) { extend(OperandRef, superClass); function OperandRef(json) { this.name = json.name; } OperandRef.prototype.exec = function(ctx) { return ctx.get(this.name); }; return OperandRef; })(Expression); module.exports.IdentifierRef = IdentifierRef = (function(superClass) { extend(IdentifierRef, superClass); function IdentifierRef(json) { IdentifierRef.__super__.constructor.apply(this, arguments); this.name = json.name; this.library = json.libraryName; } IdentifierRef.prototype.exec = function(ctx) { var _obj, curr_obj, curr_val, j, len, part, parts, ref, ref1, ref2, val; val = this.library ? (ref = ctx.get(this.library)) != null ? ref.get(this.name) : void 0 : ctx.get(this.name); if (val == null) { parts = this.name.split("."); val = ctx.get(part); if ((val != null) && parts.length > 1) { curr_obj = val; curr_val = null; ref1 = parts.slice(1); for (j = 0, len = ref1.length; j < len; j++) { part = ref1[j]; _obj = (ref2 = curr_obj != null ? curr_obj[part] : void 0) != null ? ref2 : curr_obj != null ? typeof curr_obj.get === "function" ? curr_obj.get(part) : void 0 : void 0; curr_obj = _obj instanceof Function ? _obj.call(curr_obj) : _obj; } val = curr_obj; } } if (val instanceof Function) { return val.call(ctx.context_values); } else { return val; } }; return IdentifierRef; })(Expression); }).call(this); //# sourceMappingURL=reusable.js.map