@phema/cql-execution
Version:
An execution framework for the Clinical Quality Language (CQL)
206 lines (150 loc) • 7.43 kB
JavaScript
;
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var _require = require('./expression'),
Expression = _require.Expression;
var Literal = /*#__PURE__*/function (_Expression) {
_inherits(Literal, _Expression);
var _super = _createSuper(Literal);
function Literal(json) {
var _this;
_classCallCheck(this, Literal);
_this = _super.call(this, json);
_this.valueType = json.valueType;
_this.value = json.value;
return _this;
}
_createClass(Literal, [{
key: "exec",
value: function exec(ctx) {
return this.value;
}
}], [{
key: "from",
value: function from(json) {
switch (json.valueType) {
case '{urn:hl7-org:elm-types:r1}Boolean':
return new BooleanLiteral(json);
case '{urn:hl7-org:elm-types:r1}Integer':
return new IntegerLiteral(json);
case '{urn:hl7-org:elm-types:r1}Decimal':
return new DecimalLiteral(json);
case '{urn:hl7-org:elm-types:r1}String':
return new StringLiteral(json);
default:
return new Literal(json);
}
}
}]);
return Literal;
}(Expression); // The following are not defined in ELM, but helpful for execution
var BooleanLiteral = /*#__PURE__*/function (_Literal) {
_inherits(BooleanLiteral, _Literal);
var _super2 = _createSuper(BooleanLiteral);
function BooleanLiteral(json) {
var _this2;
_classCallCheck(this, BooleanLiteral);
_this2 = _super2.call(this, json);
_this2.value = _this2.value === 'true';
return _this2;
} // Define a simple getter to allow type-checking of this class without instanceof
// and in a way that survives minification (as opposed to checking constructor.name)
_createClass(BooleanLiteral, [{
key: "isBooleanLiteral",
get: function get() {
return true;
}
}, {
key: "exec",
value: function exec(ctx) {
return this.value;
}
}]);
return BooleanLiteral;
}(Literal);
var IntegerLiteral = /*#__PURE__*/function (_Literal2) {
_inherits(IntegerLiteral, _Literal2);
var _super3 = _createSuper(IntegerLiteral);
function IntegerLiteral(json) {
var _this3;
_classCallCheck(this, IntegerLiteral);
_this3 = _super3.call(this, json);
_this3.value = parseInt(_this3.value, 10);
return _this3;
} // Define a simple getter to allow type-checking of this class without instanceof
// and in a way that survives minification (as opposed to checking constructor.name)
_createClass(IntegerLiteral, [{
key: "isIntegerLiteral",
get: function get() {
return true;
}
}, {
key: "exec",
value: function exec(ctx) {
return this.value;
}
}]);
return IntegerLiteral;
}(Literal);
var DecimalLiteral = /*#__PURE__*/function (_Literal3) {
_inherits(DecimalLiteral, _Literal3);
var _super4 = _createSuper(DecimalLiteral);
function DecimalLiteral(json) {
var _this4;
_classCallCheck(this, DecimalLiteral);
_this4 = _super4.call(this, json);
_this4.value = parseFloat(_this4.value);
return _this4;
} // Define a simple getter to allow type-checking of this class without instanceof
// and in a way that survives minification (as opposed to checking constructor.name)
_createClass(DecimalLiteral, [{
key: "isDecimalLiteral",
get: function get() {
return true;
}
}, {
key: "exec",
value: function exec(ctx) {
return this.value;
}
}]);
return DecimalLiteral;
}(Literal);
var StringLiteral = /*#__PURE__*/function (_Literal4) {
_inherits(StringLiteral, _Literal4);
var _super5 = _createSuper(StringLiteral);
function StringLiteral(json) {
_classCallCheck(this, StringLiteral);
return _super5.call(this, json);
} // Define a simple getter to allow type-checking of this class without instanceof
// and in a way that survives minification (as opposed to checking constructor.name)
_createClass(StringLiteral, [{
key: "isStringLiteral",
get: function get() {
return true;
}
}, {
key: "exec",
value: function exec(ctx) {
// TODO: Remove these replacements when CQL-to-ELM fixes bug: https://github.com/cqframework/clinical_quality_language/issues/82
return this.value.replace(/\\'/g, "'").replace(/\\"/g, '"');
}
}]);
return StringLiteral;
}(Literal);
module.exports = {
BooleanLiteral: BooleanLiteral,
DecimalLiteral: DecimalLiteral,
IntegerLiteral: IntegerLiteral,
Literal: Literal,
StringLiteral: StringLiteral
};