UNPKG

terra-clinical-result

Version:

The Terra Clinical Result package is a collection of standardized views for presenting clinical results documented to a Patient's Medical Chart, such as Vital Signs, Laboratory Results, and Discretely Documented Values

94 lines (89 loc) 5.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sanitizeResult = exports.isEmpty = exports.default = exports.checkTypeNumeric = exports.checkIsStatusInError = exports.ConditionalWrapper = void 0; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /** * Returns a boolean after checking supplied value is not undefined, null, or empty string. * @param {string} value to test * @returns {boolean} empty|true || not-empty|false */ var isEmpty = exports.isEmpty = function isEmpty(str) { return !str || str.length === 0; }; /** * Returns a boolean after check to see if a clinical result has included a resultData.status value that is equal to 'entered-in-error' * @param {object} Observation.propTypes.result * @returns {boolean} status is in-error|true || not in-error|false */ var checkIsStatusInError = exports.checkIsStatusInError = function checkIsStatusInError(status) { var resultStatus = !isEmpty(status) ? status.trim().toLowerCase() : undefined; return resultStatus === 'entered-in-error'; }; /** * Returns a boolean after check to see if a clinical result is type numeric * @param {object} Observation.propTypes.result * @return {boolean} is numeric|true || not numeric|false */ var checkTypeNumeric = exports.checkTypeNumeric = function checkTypeNumeric(resultData) { var isNumeric = !isEmpty(resultData.isNumeric) ? resultData.isNumeric === true : false; return isNumeric; }; /* * Returns a copy of the object with additional parameters with trimmed values and informational booleans * @param {object} observationPropShape * @return {object} is an object with added trimmed values and information. */ var sanitizeResult = exports.sanitizeResult = function sanitizeResult(data) { if (!data) { return {}; } var returnResult = _objectSpread({}, data); returnResult.noData = data.resultNoData === true; if (!returnResult.noData) { var result = data.result, status = data.status, conceptDisplay = data.conceptDisplay, datetimeDisplay = data.datetimeDisplay; if (!isEmpty(result.unit)) { returnResult.cleanedUnit = result.unit.trim().toLowerCase(); } if (!isEmpty(status)) { returnResult.statusInError = checkIsStatusInError(status); } if (!isEmpty(conceptDisplay)) { returnResult.cleanedConceptDisplay = conceptDisplay.trim().toLowerCase(); } if (!isEmpty(datetimeDisplay)) { returnResult.cleanedDatetimeDisplay = datetimeDisplay.trim().toLowerCase(); } } return returnResult; }; /** * Private component to generate a new react.node with wrapper element around children content, dependant on a supplied condition. * Credit to Steufken, Olivier. “Conditionally Wrap an Element in React.” Medium, Hackages Blog, 30 Apr. 2019, blog.hackages.io/conditionally-wrap-an-element-in-react-a8b9a47fab2. * @param {boolean} result of condition to test --> wraps|true || does not wrap|false * @param {function} wrapper function with html to insert children inside of * @param {object} React.Node of children content * @returns {object} React.Node with either children-only or wrapped-children content */ var ConditionalWrapper = exports.ConditionalWrapper = function ConditionalWrapper(_ref) { var condition = _ref.condition, wrapper = _ref.wrapper, children = _ref.children; return condition ? wrapper(children) : children; }; var ClinicalResultUtils = { isEmpty: isEmpty, checkIsStatusInError: checkIsStatusInError, checkTypeNumeric: checkTypeNumeric, ConditionalWrapper: ConditionalWrapper }; var _default = exports.default = ClinicalResultUtils;