healthone
Version:
Health One format library for JavaScript
1 lines • 4.13 kB
Source Map (JSON)
{"version":3,"file":"parse.cjs","names":["parse","string","options","expandAndMergeOptions","defaultParseOptions","lines","match","newline","Array","from","parseLines","report","lineno","line","enumerate","parts","split","separator","length","end","constructor","prototype","String","Error","record","parseRecord","descriptor","sanitizeReport","reference","identifier","insertRecord","insertLine","kind","anomalies","count","filter","result","flag","results"],"sources":["../../src/parse.js"],"sourcesContent":["import {count} from '@iterable-iterator/cardinality';\nimport {filter} from '@iterable-iterator/filter';\nimport {enumerate} from '@iterable-iterator/zip';\n\nimport defaultParseOptions from './defaultParseOptions.js';\nimport expandAndMergeOptions from './expandAndMergeOptions.js';\nimport parseRecord from './parseRecord.js';\nimport insertRecord from './insertRecord.js';\nimport insertLine from './insertLine.js';\n\nexport default function parse(string, options) {\n\toptions = expandAndMergeOptions(defaultParseOptions, options);\n\tconst lines = string.match(options.newline);\n\treturn Array.from(parseLines(lines, options));\n}\n\nfunction* parseLines(lines, options) {\n\tlet report = null;\n\n\tfor (const [lineno, line] of enumerate(lines, 1)) {\n\t\tconst parts = line.split(options.separator);\n\n\t\tif (\n\t\t\tparts.length === 1 &&\n\t\t\toptions.end.constructor.prototype === String.prototype\n\t\t)\n\t\t\tif (parts[0] === options.end) break;\n\t\t\telse if (options.end === undefined) break; // Accept any ending\n\n\t\tif (parts.length < 3) {\n\t\t\tthrow new Error(\n\t\t\t\t`Line ${lineno} consists of less than three parts separated by '\\\\'`,\n\t\t\t);\n\t\t}\n\n\t\tconst record = parseRecord(parts, options);\n\n\t\tif (record.descriptor === 'A1') {\n\t\t\tif (report !== null) yield sanitizeReport(report);\n\t\t\treport = {\n\t\t\t\treference: record.reference,\n\t\t\t\tidentifier: record.identifier,\n\t\t\t\tlines: [line],\n\t\t\t};\n\t\t} else if (report === null) {\n\t\t\tthrow new Error(`Document did not start with 'A1\\\\': ${lineno}`);\n\t\t} else {\n\t\t\treport = insertRecord(report, record);\n\t\t\treport = insertLine(report, line);\n\t\t}\n\t}\n\n\tif (report !== null) yield sanitizeReport(report);\n}\n\nfunction sanitizeReport(report) {\n\tif (report.kind === 'lab') {\n\t\treturn {\n\t\t\t...report,\n\t\t\tanomalies: count(filter((result) => result.flag === '*', report.results)),\n\t\t};\n\t}\n\n\treturn report;\n}\n"],"mappings":"+pBAUe,QAAS,CAAAA,KAAKA,CAACC,CAAM,CAAEC,CAAO,CAAE,CAC9CA,CAAO,CAAG,GAAAC,8BAAqB,EAACC,4BAAmB,CAAEF,CAAO,CAAC,CAC7D,KAAM,CAAAG,CAAK,CAAGJ,CAAM,CAACK,KAAK,CAACJ,CAAO,CAACK,OAAO,CAAC,CAC3C,MAAO,CAAAC,KAAK,CAACC,IAAI,CAACC,UAAU,CAACL,CAAK,CAAEH,CAAO,CAAC,CAC7C,CAEA,SAAUQ,UAAUA,CAACL,CAAK,CAAEH,CAAO,CAAE,CACpC,GAAI,CAAAS,CAAM,CAAG,IAAI,CAEjB,IAAK,KAAM,CAACC,CAAM,CAAEC,CAAI,CAAC,EAAI,GAAAC,cAAS,EAACT,CAAK,CAAE,CAAC,CAAC,CAAE,CACjD,KAAM,CAAAU,CAAK,CAAGF,CAAI,CAACG,KAAK,CAACd,CAAO,CAACe,SAAS,CAAC,CAE3C,GACkB,CAAC,GAAlBF,CAAK,CAACG,MAAY,EAClBhB,CAAO,CAACiB,GAAG,CAACC,WAAW,CAACC,SAAS,GAAKC,MAAM,CAACD,SAAS,CAEtD,GAAIN,CAAK,CAAC,CAAC,CAAC,GAAKb,CAAO,CAACiB,GAAG,CAAE,MAAM,IAC/B,IAAIjB,CAAO,CAACiB,GAAG,SAAc,CAAE,MAAO;AAE5C,GAAmB,CAAC,CAAhBJ,CAAK,CAACG,MAAU,CACnB,KAAM,IAAI,CAAAK,KAAK,CACd,QAAQX,CAAM,sDACf,CAAC,CAGF,KAAM,CAAAY,CAAM,CAAG,GAAAC,oBAAW,EAACV,CAAK,CAAEb,CAAO,CAAC,CAE1C,GAA0B,IAA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