healthone
Version:
Health One format library for JavaScript
2 lines • 3.04 kB
JavaScript
const _excluded=["descriptor"],_excluded2=["speciality","text"],_excluded3=["sections"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],-1===b.indexOf(c)&&{}.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c={};for(var d in a)if({}.hasOwnProperty.call(a,d)){if(-1!==b.indexOf(d))continue;c[d]=a[d]}return c}import mergeWith from"lodash.mergewith/index.js";function customizer(a,b){if(Array.isArray(a))return a.concat(b)}export default function insertRecord(a,b){let{descriptor:c}=b,d=_objectWithoutProperties(b,_excluded);const{kind:e}=a;if(d.reference!==a.reference)throw new Error(`Invalid record reference '${d.reference}'. Current reference is '${a.reference}'.`);switch(c){case"L1":{if("report"===e)throw new Error(`Invalid record descriptor '${c}' for a report document.`);return _objectSpread(_objectSpread({},mergeWith({},a,d,customizer)),{},{kind:"lab"})}case"L2":case"L3":case"L5":{if("lab"===e)throw new Error(`Invalid record descriptor '${c}' for a lab document.`);if(void 0!==a.speciality&&d.speciality!==a.speciality)throw new Error(`Invalid record speciality '${d.speciality}'. Current speciality is '${a.speciality}'.`);const{speciality:b,text:f}=d,g=_objectWithoutProperties(d,_excluded2);if(a.sections!==void 0){const{sections:c}=a,d=_objectWithoutProperties(a,_excluded3),e=c.slice(0,-1),h=c.at(-1);if(b===h.speciality)return _objectSpread(_objectSpread({},mergeWith({},d,g,{sections:[...e,mergeWith({},h,{text:f},customizer)]},customizer)),{},{kind:"report"})}return _objectSpread(_objectSpread({},mergeWith({},a,g,{sections:[{speciality:b,text:f}]},customizer)),{},{kind:"report"})}default:return mergeWith({},a,d,customizer)}}
//# sourceMappingURL=insertRecord.js.map