@eka-care/medical-records-ui 1.2.44 → 1.2.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1936,6 +1936,115 @@ function SmartRecordSmartPanel({
1936
1936
 
1937
1937
 
1938
1938
 
1939
+ // src/prescription/markdown.ts
1940
+ var _unified = require('unified');
1941
+ var _remarkparse = require('remark-parse'); var _remarkparse2 = _interopRequireDefault(_remarkparse);
1942
+ var _remarkgfm = require('remark-gfm'); var _remarkgfm2 = _interopRequireDefault(_remarkgfm);
1943
+ var _mdastutiltostring = require('mdast-util-to-string');
1944
+ var BOLD = "**";
1945
+ var FENCE = /^\s*(```|~~~)/;
1946
+ var WORD_CHAR = /[\p{L}\p{N}]/u;
1947
+ var PUNCTUATION = /[^\s\p{L}\p{N}]/u;
1948
+ function remarkNoIndentedCode() {
1949
+ const data = this.data();
1950
+ const extensions = _nullishCoalesce(data.micromarkExtensions, () => ( (data.micromarkExtensions = [])));
1951
+ extensions.push({ disable: { null: ["codeIndented"] } });
1952
+ }
1953
+ var parser = _unified.unified.call(void 0, ).use(_remarkparse2.default).use(_remarkgfm2.default).use(remarkNoIndentedCode);
1954
+ function tidyLine(line) {
1955
+ const parts = line.split(BOLD);
1956
+ if (line.includes("`") || parts.length < 3 || parts.length % 2 === 0) return line;
1957
+ let out = parts[0];
1958
+ for (let i = 1; i < parts.length; i += 2) {
1959
+ const run = parts[i];
1960
+ const body = run.trim();
1961
+ const next = parts[i + 1];
1962
+ if (!body) {
1963
+ out += BOLD + run + BOLD + next;
1964
+ continue;
1965
+ }
1966
+ const hasLead = run !== run.trimStart();
1967
+ const hasTrail = run !== run.trimEnd();
1968
+ if (hasLead && out !== "" && !/\s$/.test(out)) out += " ";
1969
+ const closesOnPunctuation = PUNCTUATION.test(body.slice(-1)) && WORD_CHAR.test(next.charAt(0));
1970
+ const needsGap = next !== "" && !/^\s/.test(next) && (hasTrail || closesOnPunctuation);
1971
+ out += BOLD + body + BOLD + (needsGap ? " " : "") + next;
1972
+ }
1973
+ return out;
1974
+ }
1975
+ function tidyBoldMarkers(markdown) {
1976
+ let inFence = false;
1977
+ return markdown.split("\n").map((line) => {
1978
+ if (FENCE.test(line)) {
1979
+ inFence = !inFence;
1980
+ return line;
1981
+ }
1982
+ return inFence ? line : tidyLine(line);
1983
+ }).join("\n");
1984
+ }
1985
+ var DELIMITER_ROW = /^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)*\|?\s*$/;
1986
+ var UNESCAPED_PIPE = /(?<!\\)\|/;
1987
+ function cellCount(line) {
1988
+ return line.trim().replace(/^\|/, "").replace(/\|$/, "").split(UNESCAPED_PIPE).length;
1989
+ }
1990
+ function withSeparator(block) {
1991
+ const columns = cellCount(block[0]);
1992
+ const isBareTable = block.length >= 2 && columns >= 2 && block.every((line) => line.includes("|") && cellCount(line) === columns) && !block.some((line) => DELIMITER_ROW.test(line));
1993
+ if (!isBareTable) return block;
1994
+ return [block[0], Array(columns).fill("---").join(" | "), ...block.slice(1)];
1995
+ }
1996
+ function addTableSeparators(markdown) {
1997
+ const lines = markdown.split("\n");
1998
+ const out = [];
1999
+ let inFence = false;
2000
+ let i = 0;
2001
+ while (i < lines.length) {
2002
+ if (FENCE.test(lines[i])) {
2003
+ inFence = !inFence;
2004
+ out.push(lines[i++]);
2005
+ continue;
2006
+ }
2007
+ if (inFence || !lines[i].trim()) {
2008
+ out.push(lines[i++]);
2009
+ continue;
2010
+ }
2011
+ let end = i;
2012
+ while (end < lines.length && lines[end].trim() && !FENCE.test(lines[end])) end++;
2013
+ out.push(...withSeparator(lines.slice(i, end)));
2014
+ i = end;
2015
+ }
2016
+ return out.join("\n");
2017
+ }
2018
+ function markdownTable(markdown) {
2019
+ const blocks = parser.parse(markdown).children;
2020
+ const table = blocks[0];
2021
+ if (blocks.length !== 1 || table.type !== "table") return null;
2022
+ const [headers, ...rows] = table.children.map((row) => row.children.map((cell2) => _mdastutiltostring.toString.call(void 0, cell2).trim()));
2023
+ return headers.length >= 2 ? { headers, rows } : null;
2024
+ }
2025
+ function itemText(item) {
2026
+ return item.children.map((child) => child.type === "list" ? listText(child).replace(/^/gm, " ") : blockText(child)).join("\n");
2027
+ }
2028
+ function listText(list) {
2029
+ const start = _nullishCoalesce(list.start, () => ( 1));
2030
+ return list.children.map((item, i) => `${list.ordered ? `${start + i}.` : "-"} ${itemText(item)}`).join("\n");
2031
+ }
2032
+ function blockText(node) {
2033
+ switch (node.type) {
2034
+ case "list":
2035
+ return listText(node);
2036
+ case "blockquote":
2037
+ return node.children.map(blockText).join("\n\n");
2038
+ case "table":
2039
+ return node.children.map((row) => row.children.map((cell2) => _mdastutiltostring.toString.call(void 0, cell2)).join(" | ")).join("\n");
2040
+ default:
2041
+ return _mdastutiltostring.toString.call(void 0, node);
2042
+ }
2043
+ }
2044
+ function markdownToText(markdown) {
2045
+ return parser.parse(tidyBoldMarkers(markdown)).children.map(blockText).filter(Boolean).join("\n\n");
2046
+ }
2047
+
1939
2048
  // src/prescription/fhir-utils.ts
1940
2049
  var EKA_SYSTEM = /eka\.care/i;
1941
2050
  var SNOMED_SYSTEM = /snomed/i;
@@ -2223,7 +2332,7 @@ function socialHistoryRow(obs) {
2223
2332
  function surveyNote(obs) {
2224
2333
  const markdown = _optionalChain([obs, 'access', _155 => _155.valueString, 'optionalAccess', _156 => _156.trim, 'call', _157 => _157()]);
2225
2334
  if (!markdown) return null;
2226
- return { title: _nullishCoalesce(conceptDisplay(obs.code), () => ( "Notes")), markdown };
2335
+ return { title: _nullishCoalesce(conceptDisplay(obs.code), () => ( "Notes")), markdown: addTableSeparators(markdown) };
2227
2336
  }
2228
2337
  var INTERPRETATION = { H: "High", HH: "High", L: "Low", LL: "Low", A: "Abnormal", AA: "Abnormal", N: "Normal" };
2229
2338
  function referenceRangeText(obs) {
@@ -2450,7 +2559,7 @@ function procedureRow(sr) {
2450
2559
  return { procedure_name, timing: "", note: _nullishCoalesce(noteText(sr.note), () => ( "")), ...date ? { date } : {}, procedure_id: codes.eka_code, ...codes };
2451
2560
  }
2452
2561
  function performerName(sr) {
2453
- const performer = _optionalChain([sr, 'access', _206 => _206.performer, 'optionalAccess', _207 => _207.find, 'call', _208 => _208((p) => _optionalChain([p, 'optionalAccess', _209 => _209.display, 'optionalAccess', _210 => _210.trim, 'call', _211 => _211()]) && (!p.reference || p.reference.startsWith("Practitioner/")))]);
2562
+ const performer = _optionalChain([sr, 'access', _206 => _206.performer, 'optionalAccess', _207 => _207.find, 'call', _208 => _208((p) => _optionalChain([p, 'optionalAccess', _209 => _209.display, 'optionalAccess', _210 => _210.trim, 'call', _211 => _211()]) && (!p.reference || /^Practitioner(Role)?\//.test(p.reference)))]);
2454
2563
  return _optionalChain([performer, 'optionalAccess', _212 => _212.display, 'optionalAccess', _213 => _213.trim, 'call', _214 => _214()]) || null;
2455
2564
  }
2456
2565
  function practitionerSpecialties(resources) {
@@ -2583,6 +2692,15 @@ function uniqueKey(base, taken) {
2583
2692
  taken.add(key);
2584
2693
  return key;
2585
2694
  }
2695
+ function tablePayload(table) {
2696
+ const taken = /* @__PURE__ */ new Set();
2697
+ const headers = table.headers.map((header, i) => {
2698
+ const label = header || `Column ${i + 1}`;
2699
+ return col(uniqueKey(slug(label), taken), label);
2700
+ });
2701
+ const rows = table.rows.map((cells) => Object.fromEntries(headers.map((h, i) => [h.key, _nullishCoalesce(cells[i], () => ( ""))])));
2702
+ return { headers, rows };
2703
+ }
2586
2704
  var FOLD_TARGETS = {
2587
2705
  "chief complaint": "symptoms",
2588
2706
  "chief complaints": "symptoms",
@@ -2889,7 +3007,12 @@ function convertPrescriptionBundle(bundle, options = {}) {
2889
3007
  if (inpatient || admissionNoteLines.length) add("ip_admission", "IP Admission", "IP_ADMISSION", admission);
2890
3008
  else order++;
2891
3009
  const taken = new Set(sections.map((s) => s.key));
2892
- for (const note of surveyNotes) add(uniqueKey(slug(note.title), taken), note.title, "NARRATIVE", { markdown: note.markdown });
3010
+ for (const note of surveyNotes) {
3011
+ const key = uniqueKey(slug(note.title), taken);
3012
+ const table = markdownTable(note.markdown);
3013
+ if (table) add(key, note.title, "TABLE", tablePayload(table));
3014
+ else add(key, note.title, "NARRATIVE", { markdown: note.markdown });
3015
+ }
2893
3016
  for (const custom of freeFormSections) add(uniqueKey(slug(custom.title), taken), custom.title, "KEY_VALUE", { items: custom.items });
2894
3017
  return { header, sections, diagnostics };
2895
3018
  }
@@ -2922,8 +3045,9 @@ function cellText(kind, key, value) {
2922
3045
  if (kind === "EXAMINATION_FINDINGS" && key === "status") return capitalize(value);
2923
3046
  return value;
2924
3047
  }
2925
- function visibleColumns(headers, rows) {
2926
- return headers.filter((h, i) => !HIDDEN_COLUMNS.has(h.key) && (i === 0 || rows.some((r) => _optionalChain([r, 'access', _246 => _246[h.key], 'optionalAccess', _247 => _247.trim, 'call', _248 => _248()]))));
3048
+ function visibleColumns(headers, rows, kind) {
3049
+ const keepEmpty = kind === "TABLE";
3050
+ return headers.filter((h, i) => !HIDDEN_COLUMNS.has(h.key) && (keepEmpty || i === 0 || rows.some((r) => _optionalChain([r, 'access', _246 => _246[h.key], 'optionalAccess', _247 => _247.trim, 'call', _248 => _248()]))));
2927
3051
  }
2928
3052
  function rowsToLineItems(headers, rows, skip = []) {
2929
3053
  const [nameColumn, ...rest] = headers.filter((h) => !HIDDEN_COLUMNS.has(h.key) && !skip.includes(h.key));
@@ -2974,75 +3098,6 @@ function sectionFields(section) {
2974
3098
  }
2975
3099
  }
2976
3100
 
2977
- // src/prescription/markdown.ts
2978
- var _unified = require('unified');
2979
- var _remarkparse = require('remark-parse'); var _remarkparse2 = _interopRequireDefault(_remarkparse);
2980
- var _remarkgfm = require('remark-gfm'); var _remarkgfm2 = _interopRequireDefault(_remarkgfm);
2981
- var _mdastutiltostring = require('mdast-util-to-string');
2982
- var BOLD = "**";
2983
- var FENCE = /^\s*(```|~~~)/;
2984
- var WORD_CHAR = /[\p{L}\p{N}]/u;
2985
- var PUNCTUATION = /[^\s\p{L}\p{N}]/u;
2986
- function remarkNoIndentedCode() {
2987
- const data = this.data();
2988
- const extensions = _nullishCoalesce(data.micromarkExtensions, () => ( (data.micromarkExtensions = [])));
2989
- extensions.push({ disable: { null: ["codeIndented"] } });
2990
- }
2991
- var parser = _unified.unified.call(void 0, ).use(_remarkparse2.default).use(_remarkgfm2.default).use(remarkNoIndentedCode);
2992
- function tidyLine(line) {
2993
- const parts = line.split(BOLD);
2994
- if (line.includes("`") || parts.length < 3 || parts.length % 2 === 0) return line;
2995
- let out = parts[0];
2996
- for (let i = 1; i < parts.length; i += 2) {
2997
- const run = parts[i];
2998
- const body = run.trim();
2999
- const next = parts[i + 1];
3000
- if (!body) {
3001
- out += BOLD + run + BOLD + next;
3002
- continue;
3003
- }
3004
- const hasLead = run !== run.trimStart();
3005
- const hasTrail = run !== run.trimEnd();
3006
- if (hasLead && out !== "" && !/\s$/.test(out)) out += " ";
3007
- const closesOnPunctuation = PUNCTUATION.test(body.slice(-1)) && WORD_CHAR.test(next.charAt(0));
3008
- const needsGap = next !== "" && !/^\s/.test(next) && (hasTrail || closesOnPunctuation);
3009
- out += BOLD + body + BOLD + (needsGap ? " " : "") + next;
3010
- }
3011
- return out;
3012
- }
3013
- function tidyBoldMarkers(markdown) {
3014
- let inFence = false;
3015
- return markdown.split("\n").map((line) => {
3016
- if (FENCE.test(line)) {
3017
- inFence = !inFence;
3018
- return line;
3019
- }
3020
- return inFence ? line : tidyLine(line);
3021
- }).join("\n");
3022
- }
3023
- function itemText(item) {
3024
- return item.children.map((child) => child.type === "list" ? listText(child).replace(/^/gm, " ") : blockText(child)).join("\n");
3025
- }
3026
- function listText(list) {
3027
- const start = _nullishCoalesce(list.start, () => ( 1));
3028
- return list.children.map((item, i) => `${list.ordered ? `${start + i}.` : "-"} ${itemText(item)}`).join("\n");
3029
- }
3030
- function blockText(node) {
3031
- switch (node.type) {
3032
- case "list":
3033
- return listText(node);
3034
- case "blockquote":
3035
- return node.children.map(blockText).join("\n\n");
3036
- case "table":
3037
- return node.children.map((row) => row.children.map((cell2) => _mdastutiltostring.toString.call(void 0, cell2)).join(" | ")).join("\n");
3038
- default:
3039
- return _mdastutiltostring.toString.call(void 0, node);
3040
- }
3041
- }
3042
- function markdownToText(markdown) {
3043
- return parser.parse(tidyBoldMarkers(markdown)).children.map(blockText).filter(Boolean).join("\n\n");
3044
- }
3045
-
3046
3101
  // src/prescription/section-text.ts
3047
3102
  function tableLines(section) {
3048
3103
  const payload = section.payload;
@@ -3154,7 +3209,7 @@ function SectionFieldRows({ fields }) {
3154
3209
 
3155
3210
  var MIN_COLUMN_PX = 60;
3156
3211
  function SectionTable({ kind, payload }) {
3157
- const columns = visibleColumns(payload.headers, payload.rows);
3212
+ const columns = visibleColumns(payload.headers, payload.rows, kind);
3158
3213
  const nameKey = _nullishCoalesce(_optionalChain([columns, 'access', _251 => _251[0], 'optionalAccess', _252 => _252.key]), () => ( ""));
3159
3214
  if (columns.length <= 1) {
3160
3215
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "ol", { className: "mr-rx-list", children: payload.rows.map((r, i) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "li", { children: _nullishCoalesce(r[nameKey], () => ( "")) }, i)) });