healthone
Version:
Health One format library for JavaScript
1 lines • 4.86 kB
Source Map (JSON)
{"version":3,"file":"insertRecord.cjs","names":["_index","_interopRequireDefault","require","Object","defineProperty","exports","value","default","insertRecord","a","__esModule","customizer","objectValue","srcValue","Array","isArray","concat","report","descriptor","record","kind","reference","Error","mergeWith","speciality","text","rest","sections","metadata","head","slice","last","at"],"sources":["../../src/insertRecord.js"],"sourcesContent":["import assert from 'node:assert';\n\nimport mergeWith from 'lodash.mergewith/index.js';\n\nfunction customizer(objectValue, srcValue) {\n\tif (Array.isArray(objectValue)) {\n\t\treturn objectValue.concat(srcValue);\n\t}\n}\n\nexport default function insertRecord(report, {descriptor, ...record}) {\n\tconst {kind} = report;\n\n\tif (record.reference !== report.reference) {\n\t\tthrow new Error(\n\t\t\t`Invalid record reference '${record.reference}'. Current reference is '${report.reference}'.`,\n\t\t);\n\t}\n\n\tswitch (descriptor) {\n\t\tcase 'L1': {\n\t\t\tif (kind === 'report')\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid record descriptor '${descriptor}' for a report document.`,\n\t\t\t\t);\n\t\t\treturn {\n\t\t\t\t...mergeWith({}, report, record, customizer),\n\t\t\t\tkind: 'lab',\n\t\t\t};\n\t\t}\n\n\t\tcase 'L2':\n\t\tcase 'L3':\n\t\tcase 'L5': {\n\t\t\tif (kind === 'lab')\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid record descriptor '${descriptor}' for a lab document.`,\n\t\t\t\t);\n\t\t\tif (\n\t\t\t\treport.speciality !== undefined &&\n\t\t\t\trecord.speciality !== report.speciality\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid record speciality '${record.speciality}'. Current speciality is '${report.speciality}'.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst {speciality, text, ...rest} = record;\n\n\t\t\tif (report.sections !== undefined) {\n\t\t\t\tconst {sections, ...metadata} = report;\n\t\t\t\tassert(sections.length > 0);\n\n\t\t\t\tconst head = sections.slice(0, -1);\n\t\t\t\tconst last = sections.at(-1);\n\n\t\t\t\tif (speciality === last.speciality) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...mergeWith(\n\t\t\t\t\t\t\t{},\n\t\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\t\trest,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tsections: [...head, mergeWith({}, last, {text}, customizer)],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcustomizer,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tkind: 'report',\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...mergeWith(\n\t\t\t\t\t{},\n\t\t\t\t\treport,\n\t\t\t\t\trest,\n\t\t\t\t\t{\n\t\t\t\t\t\tsections: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tspeciality,\n\t\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\tcustomizer,\n\t\t\t\t),\n\t\t\t\tkind: 'report',\n\t\t\t};\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn mergeWith({}, report, record, customizer);\n\t\t}\n\t}\n}\n"],"mappings":"aAEA,IAAAA,MAAA,CAAAC,sBAAA,CAAAC,OAAA,+BAAkDC,MAAA,CAAAC,cAAA,CAAAC,OAAA,eAAAC,KAAA,MAAAD,OAAA,CAAAE,OAAA,CAAAC,YAAA,UAAAP,uBAAAQ,CAAA,SAAAA,CAAA,EAAAA,CAAA,CAAAC,UAAA,CAAAD,CAAA,EAAAF,OAAA,CAAAE,CAAA,EAElD,QAAS,CAAAE,UAAUA,CAACC,CAAW,CAAEC,CAAQ,CAAE,CAC1C,GAAIC,KAAK,CAACC,OAAO,CAACH,CAAW,CAAC,CAC7B,MAAO,CAAAA,CAAW,CAACI,MAAM,CAACH,CAAQ,CAEpC,CAEe,QAAS,CAAAL,YAAYA,CAACS,CAA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