ezmedicationinput 0.1.12 → 0.1.13

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.
@@ -38,4 +38,5 @@ export interface ParsedSigInternal {
38
38
  siteCoding?: FhirCoding;
39
39
  siteLookupRequest?: SiteCodeLookupRequest;
40
40
  siteLookups: SiteLookupDetail[];
41
+ customSiteHints?: Set<string>;
41
42
  }
package/dist/parser.js CHANGED
@@ -20,6 +20,28 @@ const types_1 = require("./types");
20
20
  const object_1 = require("./utils/object");
21
21
  const array_1 = require("./utils/array");
22
22
  const SNOMED_SYSTEM = "http://snomed.info/sct";
23
+ function buildCustomSiteHints(map) {
24
+ if (!map) {
25
+ return undefined;
26
+ }
27
+ const hints = new Set();
28
+ for (const key of Object.keys(map)) {
29
+ const normalized = (0, maps_1.normalizeBodySiteKey)(key);
30
+ if (!normalized) {
31
+ continue;
32
+ }
33
+ for (const part of normalized.split(" ")) {
34
+ if (part) {
35
+ hints.add(part);
36
+ }
37
+ }
38
+ }
39
+ return hints;
40
+ }
41
+ function isBodySiteHint(word, customSiteHints) {
42
+ var _a;
43
+ return BODY_SITE_HINTS.has(word) || ((_a = customSiteHints === null || customSiteHints === void 0 ? void 0 : customSiteHints.has(word)) !== null && _a !== void 0 ? _a : false);
44
+ }
23
45
  const BODY_SITE_HINTS = new Set([
24
46
  "left",
25
47
  "right",
@@ -362,7 +384,7 @@ function hasBodySiteContextBefore(internal, tokens, index) {
362
384
  continue;
363
385
  }
364
386
  const normalized = normalizeTokenLower(token);
365
- if (BODY_SITE_HINTS.has(normalized)) {
387
+ if (isBodySiteHint(normalized, internal.customSiteHints)) {
366
388
  return true;
367
389
  }
368
390
  if (EYE_SITE_TOKENS[normalized]) {
@@ -399,7 +421,7 @@ function hasBodySiteContextAfter(internal, tokens, index) {
399
421
  if (SITE_FILLER_WORDS.has(normalized)) {
400
422
  continue;
401
423
  }
402
- if (BODY_SITE_HINTS.has(normalized)) {
424
+ if (isBodySiteHint(normalized, internal.customSiteHints)) {
403
425
  return true;
404
426
  }
405
427
  if (seenConnector) {
@@ -481,7 +503,7 @@ function shouldTreatEyeTokenAsSite(internal, tokens, index, context) {
481
503
  if (SITE_CONNECTORS.has(normalized)) {
482
504
  continue;
483
505
  }
484
- if (BODY_SITE_HINTS.has(normalized)) {
506
+ if (isBodySiteHint(normalized, internal.customSiteHints)) {
485
507
  return false;
486
508
  }
487
509
  if (EYE_SITE_TOKENS[normalized]) {
@@ -1248,7 +1270,8 @@ function parseInternal(input, options) {
1248
1270
  when: [],
1249
1271
  warnings: [],
1250
1272
  siteTokenIndices: new Set(),
1251
- siteLookups: []
1273
+ siteLookups: [],
1274
+ customSiteHints: buildCustomSiteHints(options === null || options === void 0 ? void 0 : options.siteCodeMap)
1252
1275
  };
1253
1276
  const context = (_a = options === null || options === void 0 ? void 0 : options.context) !== null && _a !== void 0 ? _a : undefined;
1254
1277
  const customRouteMap = (options === null || options === void 0 ? void 0 : options.routeMap)
@@ -1366,7 +1389,7 @@ function parseInternal(input, options) {
1366
1389
  setRoute(internal, synonym.code, synonym.text);
1367
1390
  for (const part of slice) {
1368
1391
  mark(internal.consumed, part);
1369
- if (BODY_SITE_HINTS.has(part.lower)) {
1392
+ if (isBodySiteHint(part.lower, internal.customSiteHints)) {
1370
1393
  internal.siteTokenIndices.add(part.index);
1371
1394
  }
1372
1395
  }
@@ -1710,7 +1733,7 @@ function parseInternal(input, options) {
1710
1733
  const siteCandidateIndices = new Set();
1711
1734
  for (const token of leftoverTokens) {
1712
1735
  const normalized = normalizeTokenLower(token);
1713
- if (BODY_SITE_HINTS.has(normalized)) {
1736
+ if (isBodySiteHint(normalized, internal.customSiteHints)) {
1714
1737
  siteCandidateIndices.add(token.index);
1715
1738
  }
1716
1739
  }
@@ -1728,7 +1751,7 @@ function parseInternal(input, options) {
1728
1751
  }
1729
1752
  const lower = normalizeTokenLower(token);
1730
1753
  if (SITE_CONNECTORS.has(lower) ||
1731
- BODY_SITE_HINTS.has(lower) ||
1754
+ isBodySiteHint(lower, internal.customSiteHints) ||
1732
1755
  ROUTE_DESCRIPTOR_FILLER_WORDS.has(lower)) {
1733
1756
  indicesToInclude.add(token.index);
1734
1757
  prev -= 1;
@@ -1744,7 +1767,7 @@ function parseInternal(input, options) {
1744
1767
  }
1745
1768
  const lower = normalizeTokenLower(token);
1746
1769
  if (SITE_CONNECTORS.has(lower) ||
1747
- BODY_SITE_HINTS.has(lower) ||
1770
+ isBodySiteHint(lower, internal.customSiteHints) ||
1748
1771
  ROUTE_DESCRIPTOR_FILLER_WORDS.has(lower)) {
1749
1772
  indicesToInclude.add(token.index);
1750
1773
  next += 1;
@@ -1802,7 +1825,7 @@ function parseInternal(input, options) {
1802
1825
  const normalizedLower = sanitized.toLowerCase();
1803
1826
  const strippedDescriptor = normalizeRouteDescriptorPhrase(normalizedLower);
1804
1827
  const siteWords = normalizedLower.split(/\s+/).filter((word) => word.length > 0);
1805
- const hasNonSiteWords = siteWords.some((word) => !BODY_SITE_HINTS.has(word));
1828
+ const hasNonSiteWords = siteWords.some((word) => !isBodySiteHint(word, internal.customSiteHints));
1806
1829
  const shouldAttemptRouteDescriptor = strippedDescriptor !== normalizedLower || hasNonSiteWords || strippedDescriptor === "mouth";
1807
1830
  const appliedRouteDescriptor = shouldAttemptRouteDescriptor && maybeApplyRouteDescriptor(sanitized);
1808
1831
  if (!appliedRouteDescriptor) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ezmedicationinput",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "Parse concise medication sigs into FHIR R5 Dosage JSON",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",