ezmedicationinput 0.1.18 → 0.1.20

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/maps.js CHANGED
@@ -1349,6 +1349,17 @@ const DEFAULT_PRN_REASON_SOURCE = [
1349
1349
  text: "Constipation"
1350
1350
  }
1351
1351
  },
1352
+ {
1353
+ names: ["irritation", "irritated"],
1354
+ definition: {
1355
+ coding: {
1356
+ system: SNOMED_SYSTEM,
1357
+ code: "257553007",
1358
+ display: "Irritation"
1359
+ },
1360
+ text: "Irritation"
1361
+ }
1362
+ },
1352
1363
  {
1353
1364
  names: ["dyspnea", "shortness of breath", "sob", "breathlessness"],
1354
1365
  definition: {
package/dist/parser.js CHANGED
@@ -1413,7 +1413,7 @@ function applyCountLimit(internal, value) {
1413
1413
  return true;
1414
1414
  }
1415
1415
  function parseInternal(input, options) {
1416
- var _a, _b, _c, _d, _e, _f;
1416
+ var _a, _b, _c, _d, _e, _f, _g;
1417
1417
  const tokens = tokenize(input);
1418
1418
  const internal = {
1419
1419
  input,
@@ -1445,6 +1445,7 @@ function parseInternal(input, options) {
1445
1445
  }
1446
1446
  // PRN detection
1447
1447
  let prnReasonStart;
1448
+ const prnSiteSuffixIndices = new Set();
1448
1449
  for (let i = 0; i < tokens.length; i++) {
1449
1450
  const token = tokens[i];
1450
1451
  if (token.lower === "prn") {
@@ -1529,6 +1530,9 @@ function parseInternal(input, options) {
1529
1530
  };
1530
1531
  // Process tokens sequentially
1531
1532
  const tryRouteSynonym = (startIndex) => {
1533
+ if (prnReasonStart !== undefined && startIndex >= prnReasonStart) {
1534
+ return false;
1535
+ }
1532
1536
  const maxSpan = Math.min(24, tokens.length - startIndex);
1533
1537
  for (let span = maxSpan; span >= 1; span--) {
1534
1538
  const slice = tokens.slice(startIndex, startIndex + span);
@@ -1948,23 +1952,23 @@ function parseInternal(input, options) {
1948
1952
  }
1949
1953
  }
1950
1954
  }
1955
+ let canonicalPrefix;
1951
1956
  if (reasonTokens.length > 0) {
1952
- const siteStart = findTrailingPrnSiteSuffix(reasonObjects, internal, options);
1953
- if (siteStart !== undefined) {
1954
- for (let i = siteStart; i < reasonObjects.length; i++) {
1955
- internal.consumed.delete(reasonObjects[i].index);
1956
- }
1957
- reasonObjects.splice(siteStart);
1958
- reasonTokens.splice(siteStart);
1959
- reasonIndices.splice(siteStart);
1960
- if (reasonTokens.length > 0) {
1961
- sortedIndices = reasonIndices.slice().sort((a, b) => a - b);
1962
- range = computeTokenRange(internal.input, tokens, sortedIndices);
1963
- sourceText = range ? internal.input.slice(range.start, range.end) : undefined;
1957
+ const suffixInfo = findTrailingPrnSiteSuffix(reasonObjects, internal, options);
1958
+ if ((_g = suffixInfo === null || suffixInfo === void 0 ? void 0 : suffixInfo.tokens) === null || _g === void 0 ? void 0 : _g.length) {
1959
+ for (const token of suffixInfo.tokens) {
1960
+ prnSiteSuffixIndices.add(token.index);
1964
1961
  }
1965
- else {
1966
- range = undefined;
1967
- sourceText = undefined;
1962
+ }
1963
+ if (suffixInfo && suffixInfo.startIndex > 0) {
1964
+ const prefixTokens = reasonObjects
1965
+ .slice(0, suffixInfo.startIndex)
1966
+ .map((token) => token.original)
1967
+ .join(" ")
1968
+ .replace(/\s+/g, " ")
1969
+ .trim();
1970
+ if (prefixTokens) {
1971
+ canonicalPrefix = prefixTokens.replace(/[{}]/g, " ").replace(/\s+/g, " ").trim();
1968
1972
  }
1969
1973
  }
1970
1974
  }
@@ -1982,8 +1986,9 @@ function parseInternal(input, options) {
1982
1986
  const text = sanitized || joined;
1983
1987
  internal.asNeededReason = text;
1984
1988
  const normalized = text.toLowerCase();
1985
- const canonical = sanitized
1986
- ? (0, maps_1.normalizePrnReasonKey)(sanitized)
1989
+ const canonicalSource = canonicalPrefix || sanitized || text;
1990
+ const canonical = canonicalSource
1991
+ ? (0, maps_1.normalizePrnReasonKey)(canonicalSource)
1987
1992
  : (0, maps_1.normalizePrnReasonKey)(text);
1988
1993
  internal.prnReasonLookupRequest = {
1989
1994
  originalText: joined,
@@ -2003,21 +2008,31 @@ function parseInternal(input, options) {
2003
2008
  // Determine site text from leftover tokens (excluding PRN reason tokens)
2004
2009
  const leftoverTokens = tokens.filter((t) => !internal.consumed.has(t.index));
2005
2010
  const siteCandidateIndices = new Set();
2011
+ const leftoverSiteIndices = new Set();
2006
2012
  for (const token of leftoverTokens) {
2013
+ if (prnSiteSuffixIndices.has(token.index)) {
2014
+ continue;
2015
+ }
2007
2016
  const normalized = normalizeTokenLower(token);
2008
2017
  if (isBodySiteHint(normalized, internal.customSiteHints)) {
2009
2018
  siteCandidateIndices.add(token.index);
2019
+ leftoverSiteIndices.add(token.index);
2010
2020
  continue;
2011
2021
  }
2012
2022
  if (SITE_CONNECTORS.has(normalized)) {
2013
2023
  const next = tokens[token.index + 1];
2014
- if (next && !internal.consumed.has(next.index)) {
2024
+ if (next && !internal.consumed.has(next.index) && !prnSiteSuffixIndices.has(next.index)) {
2015
2025
  siteCandidateIndices.add(next.index);
2016
2026
  }
2017
2027
  }
2018
2028
  }
2019
- for (const idx of internal.siteTokenIndices) {
2020
- siteCandidateIndices.add(idx);
2029
+ if (leftoverSiteIndices.size === 0) {
2030
+ for (const idx of internal.siteTokenIndices) {
2031
+ if (prnSiteSuffixIndices.has(idx)) {
2032
+ continue;
2033
+ }
2034
+ siteCandidateIndices.add(idx);
2035
+ }
2021
2036
  }
2022
2037
  if (siteCandidateIndices.size > 0) {
2023
2038
  const indicesToInclude = new Set(siteCandidateIndices);
@@ -2903,6 +2918,7 @@ function findTrailingPrnSiteSuffix(tokens, internal, options) {
2903
2918
  }
2904
2919
  const suffixTokens = tokens.slice(suffixStart);
2905
2920
  const siteWords = [];
2921
+ const siteHintTokens = [];
2906
2922
  for (const token of suffixTokens) {
2907
2923
  const trimmed = token.original.trim();
2908
2924
  if (!trimmed) {
@@ -2914,6 +2930,7 @@ function findTrailingPrnSiteSuffix(tokens, internal, options) {
2914
2930
  ROUTE_DESCRIPTOR_FILLER_WORDS.has(lower)) {
2915
2931
  continue;
2916
2932
  }
2933
+ siteHintTokens.push(token);
2917
2934
  siteWords.push(trimmed);
2918
2935
  }
2919
2936
  if (!siteWords.length) {
@@ -2928,7 +2945,10 @@ function findTrailingPrnSiteSuffix(tokens, internal, options) {
2928
2945
  if (!definition) {
2929
2946
  return undefined;
2930
2947
  }
2931
- return suffixStart;
2948
+ return {
2949
+ tokens: siteHintTokens,
2950
+ startIndex: suffixStart
2951
+ };
2932
2952
  }
2933
2953
  function lookupPrnReasonDefinition(map, canonical) {
2934
2954
  if (!map) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ezmedicationinput",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "Parse concise medication sigs into FHIR R5 Dosage JSON",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",