@phema/cql-execution
Version:
An execution framework for the Clinical Quality Language (CQL)
119 lines (92 loc) • 4.02 kB
JavaScript
;
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function removeNulls(things) {
return things.filter(function (x) {
return x != null;
});
}
function numerical_sort(things, direction) {
return things.sort(function (a, b) {
if (direction == null || direction === 'asc') {
return a - b;
} else {
return b - a;
}
});
}
function isNull(value) {
return value === null;
}
var typeIsArray = Array.isArray || function (value) {
return {}.toString.call(value) === '[object Array]';
};
function allTrue(things) {
if (typeIsArray(things)) {
return things.every(function (x) {
return x;
});
} else {
return things;
}
}
function anyTrue(things) {
if (typeIsArray(things)) {
return things.some(function (x) {
return x;
});
} else {
return things;
}
} //The export below is to make it easier if js Date is overwritten with CQL Date
var jsDate = Date;
function normalizeMillisecondsFieldInString(string, msString) {
// TODO: verify we are only removing numeral digits
var timezoneField;
msString = normalizeMillisecondsField(msString);
var _string$split = string.split('.'),
_string$split2 = _slicedToArray(_string$split, 2),
beforeMs = _string$split2[0],
msAndAfter = _string$split2[1];
var timezoneSeparator = getTimezoneSeparatorFromString(msAndAfter);
if (timezoneSeparator) {
timezoneField = msAndAfter != null ? msAndAfter.split(timezoneSeparator)[1] : undefined;
}
if (timezoneField == null) {
timezoneField = '';
}
return string = beforeMs + '.' + msString + timezoneSeparator + timezoneField;
}
function normalizeMillisecondsField(msString) {
// fix up milliseconds by padding zeros and/or truncating (5 --> 500, 50 --> 500, 54321 --> 543, etc.)
return msString = (msString + '00').substring(0, 3);
}
function getTimezoneSeparatorFromString(string) {
if (string != null) {
var matches = string.match(/-/);
if (matches && matches.length === 1) {
return '-';
}
matches = string.match(/\+/);
if (matches && matches.length === 1) {
return '+';
}
}
return '';
}
module.exports = {
removeNulls: removeNulls,
numerical_sort: numerical_sort,
isNull: isNull,
typeIsArray: typeIsArray,
allTrue: allTrue,
anyTrue: anyTrue,
jsDate: jsDate,
normalizeMillisecondsFieldInString: normalizeMillisecondsFieldInString,
normalizeMillisecondsField: normalizeMillisecondsField,
getTimezoneSeparatorFromString: getTimezoneSeparatorFromString
};