ezmedicationinput 0.1.18 → 0.1.19
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/parser.js +24 -20
- package/package.json +1 -1
package/dist/parser.js
CHANGED
|
@@ -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);
|
|
@@ -1949,22 +1953,10 @@ function parseInternal(input, options) {
|
|
|
1949
1953
|
}
|
|
1950
1954
|
}
|
|
1951
1955
|
if (reasonTokens.length > 0) {
|
|
1952
|
-
const
|
|
1953
|
-
if (
|
|
1954
|
-
for (
|
|
1955
|
-
|
|
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;
|
|
1964
|
-
}
|
|
1965
|
-
else {
|
|
1966
|
-
range = undefined;
|
|
1967
|
-
sourceText = undefined;
|
|
1956
|
+
const suffixTokens = findTrailingPrnSiteSuffix(reasonObjects, internal, options);
|
|
1957
|
+
if (suffixTokens === null || suffixTokens === void 0 ? void 0 : suffixTokens.length) {
|
|
1958
|
+
for (const token of suffixTokens) {
|
|
1959
|
+
prnSiteSuffixIndices.add(token.index);
|
|
1968
1960
|
}
|
|
1969
1961
|
}
|
|
1970
1962
|
}
|
|
@@ -2003,21 +1995,31 @@ function parseInternal(input, options) {
|
|
|
2003
1995
|
// Determine site text from leftover tokens (excluding PRN reason tokens)
|
|
2004
1996
|
const leftoverTokens = tokens.filter((t) => !internal.consumed.has(t.index));
|
|
2005
1997
|
const siteCandidateIndices = new Set();
|
|
1998
|
+
const leftoverSiteIndices = new Set();
|
|
2006
1999
|
for (const token of leftoverTokens) {
|
|
2000
|
+
if (prnSiteSuffixIndices.has(token.index)) {
|
|
2001
|
+
continue;
|
|
2002
|
+
}
|
|
2007
2003
|
const normalized = normalizeTokenLower(token);
|
|
2008
2004
|
if (isBodySiteHint(normalized, internal.customSiteHints)) {
|
|
2009
2005
|
siteCandidateIndices.add(token.index);
|
|
2006
|
+
leftoverSiteIndices.add(token.index);
|
|
2010
2007
|
continue;
|
|
2011
2008
|
}
|
|
2012
2009
|
if (SITE_CONNECTORS.has(normalized)) {
|
|
2013
2010
|
const next = tokens[token.index + 1];
|
|
2014
|
-
if (next && !internal.consumed.has(next.index)) {
|
|
2011
|
+
if (next && !internal.consumed.has(next.index) && !prnSiteSuffixIndices.has(next.index)) {
|
|
2015
2012
|
siteCandidateIndices.add(next.index);
|
|
2016
2013
|
}
|
|
2017
2014
|
}
|
|
2018
2015
|
}
|
|
2019
|
-
|
|
2020
|
-
|
|
2016
|
+
if (leftoverSiteIndices.size === 0) {
|
|
2017
|
+
for (const idx of internal.siteTokenIndices) {
|
|
2018
|
+
if (prnSiteSuffixIndices.has(idx)) {
|
|
2019
|
+
continue;
|
|
2020
|
+
}
|
|
2021
|
+
siteCandidateIndices.add(idx);
|
|
2022
|
+
}
|
|
2021
2023
|
}
|
|
2022
2024
|
if (siteCandidateIndices.size > 0) {
|
|
2023
2025
|
const indicesToInclude = new Set(siteCandidateIndices);
|
|
@@ -2903,6 +2905,7 @@ function findTrailingPrnSiteSuffix(tokens, internal, options) {
|
|
|
2903
2905
|
}
|
|
2904
2906
|
const suffixTokens = tokens.slice(suffixStart);
|
|
2905
2907
|
const siteWords = [];
|
|
2908
|
+
const siteHintTokens = [];
|
|
2906
2909
|
for (const token of suffixTokens) {
|
|
2907
2910
|
const trimmed = token.original.trim();
|
|
2908
2911
|
if (!trimmed) {
|
|
@@ -2914,6 +2917,7 @@ function findTrailingPrnSiteSuffix(tokens, internal, options) {
|
|
|
2914
2917
|
ROUTE_DESCRIPTOR_FILLER_WORDS.has(lower)) {
|
|
2915
2918
|
continue;
|
|
2916
2919
|
}
|
|
2920
|
+
siteHintTokens.push(token);
|
|
2917
2921
|
siteWords.push(trimmed);
|
|
2918
2922
|
}
|
|
2919
2923
|
if (!siteWords.length) {
|
|
@@ -2928,7 +2932,7 @@ function findTrailingPrnSiteSuffix(tokens, internal, options) {
|
|
|
2928
2932
|
if (!definition) {
|
|
2929
2933
|
return undefined;
|
|
2930
2934
|
}
|
|
2931
|
-
return
|
|
2935
|
+
return siteHintTokens;
|
|
2932
2936
|
}
|
|
2933
2937
|
function lookupPrnReasonDefinition(map, canonical) {
|
|
2934
2938
|
if (!map) {
|