UNPKG

cql-execution

Version:

An execution framework for the Clinical Quality Language (CQL)

367 lines (290 loc) 9.02 kB
// Generated by CoffeeScript 1.12.7 (function() { var Current, Distinct, Exists, Expression, Filter, First, Flatten, ForEach, IndexOf, Last, List, SingletonFrom, Times, ToList, UnimplementedExpression, ValueSet, build, doContains, doDistinct, doIncludes, equals, 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; ref = require('./expression'), Expression = ref.Expression, UnimplementedExpression = ref.UnimplementedExpression; ValueSet = require('../datatypes/datatypes').ValueSet; build = require('./builder').build; typeIsArray = require('../util/util').typeIsArray; equals = require('../util/comparison').equals; module.exports.List = List = (function(superClass) { extend(List, superClass); function List(json) { var ref1; List.__super__.constructor.apply(this, arguments); this.elements = (ref1 = build(json.element)) != null ? ref1 : []; } Object.defineProperties(List.prototype, { isList: { get: function() { return true; } } }); List.prototype.exec = function(ctx) { var item, j, len, ref1, results; ref1 = this.elements; results = []; for (j = 0, len = ref1.length; j < len; j++) { item = ref1[j]; results.push(item.execute(ctx)); } return results; }; return List; })(Expression); module.exports.Exists = Exists = (function(superClass) { extend(Exists, superClass); function Exists(json) { Exists.__super__.constructor.apply(this, arguments); } Exists.prototype.exec = function(ctx) { var item, j, len, list; list = this.execArgs(ctx); if ((list != null ? list.length : void 0) > 0) { for (j = 0, len = list.length; j < len; j++) { item = list[j]; if (item !== null) { return true; } } } return false; }; return Exists; })(Expression); module.exports.doUnion = function(a, b) { return doDistinct(a.concat(b)); }; module.exports.doExcept = function(a, b) { var itm, j, len, results, setList; setList = doDistinct(a); results = []; for (j = 0, len = setList.length; j < len; j++) { itm = setList[j]; if (!doContains(b, itm)) { results.push(itm); } } return results; }; module.exports.doIntersect = function(a, b) { var itm, j, len, results, setList; setList = doDistinct(a); results = []; for (j = 0, len = setList.length; j < len; j++) { itm = setList[j]; if (doContains(b, itm)) { results.push(itm); } } return results; }; module.exports.Times = Times = (function(superClass) { extend(Times, superClass); function Times() { return Times.__super__.constructor.apply(this, arguments); } return Times; })(UnimplementedExpression); module.exports.Filter = Filter = (function(superClass) { extend(Filter, superClass); function Filter() { return Filter.__super__.constructor.apply(this, arguments); } return Filter; })(UnimplementedExpression); module.exports.SingletonFrom = SingletonFrom = (function(superClass) { extend(SingletonFrom, superClass); function SingletonFrom(json) { SingletonFrom.__super__.constructor.apply(this, arguments); } SingletonFrom.prototype.exec = function(ctx) { var arg; arg = this.execArgs(ctx); if ((arg != null) && arg.length > 1) { throw new Error('IllegalArgument: \'SingletonFrom\' requires a 0 or 1 arg array'); } else if ((arg != null) && arg.length === 1) { return arg[0]; } else { return null; } }; return SingletonFrom; })(Expression); module.exports.ToList = ToList = (function(superClass) { extend(ToList, superClass); function ToList(json) { ToList.__super__.constructor.apply(this, arguments); } ToList.prototype.exec = function(ctx) { var arg; arg = this.execArgs(ctx); if (arg != null) { return [arg]; } else { return []; } }; return ToList; })(Expression); module.exports.IndexOf = IndexOf = (function(superClass) { extend(IndexOf, superClass); function IndexOf(json) { IndexOf.__super__.constructor.apply(this, arguments); this.source = build(json.source); this.element = build(json.element); } IndexOf.prototype.exec = function(ctx) { var el, i, index, itm, j, len, src; src = this.source.exec(ctx); el = this.element.exec(ctx); if ((src == null) || (el == null)) { return null; } for (i = j = 0, len = src.length; j < len; i = ++j) { itm = src[i]; if (equals(itm, el)) { index = i; break; } } if (index != null) { return index; } else { return -1; } }; return IndexOf; })(Expression); module.exports.doContains = doContains = function(container, item) { var element, j, len; for (j = 0, len = container.length; j < len; j++) { element = container[j]; if (equals(element, item)) { return true; } } return false; }; module.exports.doIncludes = doIncludes = function(list, sublist) { return sublist.every(function(x) { return doContains(list, x); }); }; module.exports.doProperIncludes = function(list, sublist) { return list.length > sublist.length && doIncludes(list, sublist); }; module.exports.ForEach = ForEach = (function(superClass) { extend(ForEach, superClass); function ForEach() { return ForEach.__super__.constructor.apply(this, arguments); } return ForEach; })(UnimplementedExpression); module.exports.Flatten = Flatten = (function(superClass) { extend(Flatten, superClass); function Flatten(json) { Flatten.__super__.constructor.apply(this, arguments); } Flatten.prototype.exec = function(ctx) { var arg; arg = this.execArgs(ctx); if (typeIsArray(arg) && (arg.every(function(x) { return typeIsArray(x); }))) { return arg.reduce((function(x, y) { return x.concat(y); }), []); } else { return arg; } }; return Flatten; })(Expression); module.exports.Distinct = Distinct = (function(superClass) { extend(Distinct, superClass); function Distinct(json) { Distinct.__super__.constructor.apply(this, arguments); } Distinct.prototype.exec = function(ctx) { var result; result = this.execArgs(ctx); if (result == null) { return null; } return doDistinct(result); }; return Distinct; })(Expression); doDistinct = function(list) { var firstNullFound, item, j, len, seen, setList; seen = []; list.filter(function(item) { var isNew; isNew = seen.every(function(seenItem) { return !equals(item, seenItem); }); if (isNew) { seen.push(item); } return isNew; }); firstNullFound = false; setList = []; for (j = 0, len = seen.length; j < len; j++) { item = seen[j]; if (item !== null) { setList.push(item); } if (item === null && !firstNullFound) { setList.push(item); firstNullFound = true; } } return setList; }; module.exports.Current = Current = (function(superClass) { extend(Current, superClass); function Current() { return Current.__super__.constructor.apply(this, arguments); } return Current; })(UnimplementedExpression); module.exports.First = First = (function(superClass) { extend(First, superClass); function First(json) { First.__super__.constructor.apply(this, arguments); this.source = build(json.source); } First.prototype.exec = function(ctx) { var src; src = this.source.exec(ctx); if ((src != null) && typeIsArray(src) && src.length > 0) { return src[0]; } else { return null; } }; return First; })(Expression); module.exports.Last = Last = (function(superClass) { extend(Last, superClass); function Last(json) { Last.__super__.constructor.apply(this, arguments); this.source = build(json.source); } Last.prototype.exec = function(ctx) { var src; src = this.source.exec(ctx); if ((src != null) && typeIsArray(src) && src.length > 0) { return src[src.length - 1]; } else { return null; } }; return Last; })(Expression); }).call(this); //# sourceMappingURL=list.js.map