ezmedicationinput 0.1.26 → 0.1.27

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.
Files changed (2) hide show
  1. package/dist/parser.js +30 -8
  2. package/package.json +1 -1
package/dist/parser.js CHANGED
@@ -1657,7 +1657,7 @@ function applyCountLimit(internal, value) {
1657
1657
  return true;
1658
1658
  }
1659
1659
  function parseInternal(input, options) {
1660
- var _a, _b, _c, _d, _e, _f, _g;
1660
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1661
1661
  const tokens = tokenize(input);
1662
1662
  const internal = {
1663
1663
  input,
@@ -1695,15 +1695,20 @@ function parseInternal(input, options) {
1695
1695
  if (token.lower === "prn") {
1696
1696
  internal.asNeeded = true;
1697
1697
  mark(internal.consumed, token);
1698
- prnReasonStart = i + 1;
1698
+ let reasonIndex = i + 1;
1699
+ if (((_b = tokens[reasonIndex]) === null || _b === void 0 ? void 0 : _b.lower) === "for") {
1700
+ mark(internal.consumed, tokens[reasonIndex]);
1701
+ reasonIndex += 1;
1702
+ }
1703
+ prnReasonStart = reasonIndex;
1699
1704
  break;
1700
1705
  }
1701
- if (token.lower === "as" && ((_b = tokens[i + 1]) === null || _b === void 0 ? void 0 : _b.lower) === "needed") {
1706
+ if (token.lower === "as" && ((_c = tokens[i + 1]) === null || _c === void 0 ? void 0 : _c.lower) === "needed") {
1702
1707
  internal.asNeeded = true;
1703
1708
  mark(internal.consumed, token);
1704
1709
  mark(internal.consumed, tokens[i + 1]);
1705
1710
  let reasonIndex = i + 2;
1706
- if (((_c = tokens[reasonIndex]) === null || _c === void 0 ? void 0 : _c.lower) === "for") {
1711
+ if (((_d = tokens[reasonIndex]) === null || _d === void 0 ? void 0 : _d.lower) === "for") {
1707
1712
  mark(internal.consumed, tokens[reasonIndex]);
1708
1713
  reasonIndex += 1;
1709
1714
  }
@@ -1898,7 +1903,7 @@ function parseInternal(input, options) {
1898
1903
  // Frequency abbreviation map
1899
1904
  const freqDescriptor = normalizedLower === "od"
1900
1905
  ? undefined
1901
- : (_d = maps_1.TIMING_ABBREVIATIONS[token.lower]) !== null && _d !== void 0 ? _d : maps_1.TIMING_ABBREVIATIONS[normalizedLower];
1906
+ : (_e = maps_1.TIMING_ABBREVIATIONS[token.lower]) !== null && _e !== void 0 ? _e : maps_1.TIMING_ABBREVIATIONS[normalizedLower];
1902
1907
  if (freqDescriptor) {
1903
1908
  applyFrequencyDescriptor(internal, token, freqDescriptor, options);
1904
1909
  continue;
@@ -1927,7 +1932,7 @@ function parseInternal(input, options) {
1927
1932
  if (nextToken && !internal.consumed.has(nextToken.index)) {
1928
1933
  const lowerNext = nextToken.lower;
1929
1934
  const combo = `${token.lower} ${lowerNext}`;
1930
- const comboWhen = (_e = COMBO_EVENT_TIMINGS[combo]) !== null && _e !== void 0 ? _e : maps_1.EVENT_TIMING_TOKENS[combo];
1935
+ const comboWhen = (_f = COMBO_EVENT_TIMINGS[combo]) !== null && _f !== void 0 ? _f : maps_1.EVENT_TIMING_TOKENS[combo];
1931
1936
  if (comboWhen) {
1932
1937
  applyWhenToken(internal, token, comboWhen);
1933
1938
  mark(internal.consumed, nextToken);
@@ -1940,7 +1945,7 @@ function parseInternal(input, options) {
1940
1945
  continue;
1941
1946
  }
1942
1947
  }
1943
- const customWhen = (_f = options === null || options === void 0 ? void 0 : options.whenMap) === null || _f === void 0 ? void 0 : _f[token.lower];
1948
+ const customWhen = (_g = options === null || options === void 0 ? void 0 : options.whenMap) === null || _g === void 0 ? void 0 : _g[token.lower];
1944
1949
  if (customWhen) {
1945
1950
  applyWhenToken(internal, token, customWhen);
1946
1951
  continue;
@@ -2237,6 +2242,23 @@ function parseInternal(input, options) {
2237
2242
  // If it is a reclaimable connector, we can pull it back into the reason
2238
2243
  // if it helps form a coherent phrase like 'irritation at rectum'.
2239
2244
  }
2245
+ // If we haven't started collecting the reason yet, we should skip introductory
2246
+ // connectors to avoid phrases like "as needed for if pain".
2247
+ const PRN_INTRODUCTIONS = new Set(["for", "if", "when", "upon", "due", "to"]);
2248
+ if (reasonTokens.length === 0 && PRN_INTRODUCTIONS.has(token.lower)) {
2249
+ // Special handling for "due to" - if we skipped "due", we should also skip "to"
2250
+ if (token.lower === "due") {
2251
+ const next = tokens[i + 1];
2252
+ if (next && next.lower === "to") {
2253
+ mark(internal.consumed, token);
2254
+ mark(internal.consumed, next);
2255
+ i++; // skip next token in loop
2256
+ continue;
2257
+ }
2258
+ }
2259
+ mark(internal.consumed, token);
2260
+ continue;
2261
+ }
2240
2262
  reasonTokens.push(token.original);
2241
2263
  reasonIndices.push(token.index);
2242
2264
  reasonObjects.push(token);
@@ -2285,7 +2307,7 @@ function parseInternal(input, options) {
2285
2307
  let canonicalPrefix;
2286
2308
  if (reasonTokens.length > 0) {
2287
2309
  const suffixInfo = findTrailingPrnSiteSuffix(reasonObjects, internal, options);
2288
- if ((_g = suffixInfo === null || suffixInfo === void 0 ? void 0 : suffixInfo.tokens) === null || _g === void 0 ? void 0 : _g.length) {
2310
+ if ((_h = suffixInfo === null || suffixInfo === void 0 ? void 0 : suffixInfo.tokens) === null || _h === void 0 ? void 0 : _h.length) {
2289
2311
  for (const token of suffixInfo.tokens) {
2290
2312
  prnSiteSuffixIndices.add(token.index);
2291
2313
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ezmedicationinput",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "description": "Parse concise medication sigs into FHIR R5 Dosage JSON",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",