ezmedicationinput 0.1.46 → 0.1.48

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
@@ -40,17 +40,17 @@ var __async = (__this, __arguments, generator) => {
40
40
 
41
41
  // src/prn.ts
42
42
  function getCanonicalPrnReasonText(reason) {
43
- var _a, _b;
44
- return (_b = reason == null ? void 0 : reason.text) != null ? _b : (_a = reason == null ? void 0 : reason.coding) == null ? void 0 : _a.display;
43
+ var _a2, _b;
44
+ return (_b = reason == null ? void 0 : reason.text) != null ? _b : (_a2 = reason == null ? void 0 : reason.coding) == null ? void 0 : _a2.display;
45
45
  }
46
46
  function joinCanonicalPrnReasonTexts(reasons, conjunction = "or") {
47
- var _a;
47
+ var _a2;
48
48
  if (!(reasons == null ? void 0 : reasons.length)) {
49
49
  return void 0;
50
50
  }
51
51
  const texts = [];
52
52
  for (const reason of reasons) {
53
- const text = (_a = getCanonicalPrnReasonText(reason)) == null ? void 0 : _a.trim();
53
+ const text = (_a2 = getCanonicalPrnReasonText(reason)) == null ? void 0 : _a2.trim();
54
54
  if (!text) {
55
55
  continue;
56
56
  }
@@ -81,8 +81,8 @@ function joinCanonicalPrnReasonTexts(reasons, conjunction = "or") {
81
81
  }
82
82
  }
83
83
  function getPreferredCanonicalPrnReasonText(reason, reasons, conjunction = "or") {
84
- var _a;
85
- const direct = (_a = getCanonicalPrnReasonText(reason)) == null ? void 0 : _a.trim();
84
+ var _a2;
85
+ const direct = (_a2 = getCanonicalPrnReasonText(reason)) == null ? void 0 : _a2.trim();
86
86
  if (!(reasons == null ? void 0 : reasons.length)) {
87
87
  return direct;
88
88
  }
@@ -386,10 +386,10 @@ function cloneI18nRecord(i18n) {
386
386
  return i18n ? __spreadValues({}, i18n) : void 0;
387
387
  }
388
388
  function cloneExtension(extension) {
389
- var _a, _b, _c, _d;
389
+ var _a2, _b, _c, _d;
390
390
  return {
391
391
  url: extension.url,
392
- extension: (_a = extension.extension) == null ? void 0 : _a.map(cloneExtension),
392
+ extension: (_a2 = extension.extension) == null ? void 0 : _a2.map(cloneExtension),
393
393
  valueCode: extension.valueCode,
394
394
  valueString: extension.valueString,
395
395
  valueCoding: extension.valueCoding ? {
@@ -404,14 +404,14 @@ function cloneExtension(extension) {
404
404
  text: extension.valueCodeableConcept.text,
405
405
  _text: clonePrimitiveElement(extension.valueCodeableConcept._text),
406
406
  coding: (_c = extension.valueCodeableConcept.coding) == null ? void 0 : _c.map((coding) => {
407
- var _a2;
407
+ var _a3;
408
408
  return {
409
409
  system: coding.system,
410
410
  code: coding.code,
411
411
  display: coding.display,
412
412
  _display: clonePrimitiveElement(coding._display),
413
413
  i18n: cloneI18nRecord(coding.i18n),
414
- extension: (_a2 = coding.extension) == null ? void 0 : _a2.map(cloneExtension)
414
+ extension: (_a3 = coding.extension) == null ? void 0 : _a3.map(cloneExtension)
415
415
  };
416
416
  }),
417
417
  extension: (_d = extension.valueCodeableConcept.extension) == null ? void 0 : _d.map(cloneExtension)
@@ -422,8 +422,8 @@ function cloneExtensions(extensions) {
422
422
  return (extensions == null ? void 0 : extensions.length) ? extensions.map(cloneExtension) : void 0;
423
423
  }
424
424
  function clonePrimitiveElement(element) {
425
- var _a;
426
- if (!((_a = element == null ? void 0 : element.extension) == null ? void 0 : _a.length)) {
425
+ var _a2;
426
+ if (!((_a2 = element == null ? void 0 : element.extension) == null ? void 0 : _a2.length)) {
427
427
  return void 0;
428
428
  }
429
429
  return {
@@ -446,9 +446,9 @@ function buildTranslationExtension(locale, content) {
446
446
  };
447
447
  }
448
448
  function buildTranslationPrimitiveElement(translations, base) {
449
- var _a, _b;
449
+ var _a2, _b;
450
450
  const nextExtensions = [];
451
- const baseExtensions = (_a = base == null ? void 0 : base.extension) != null ? _a : [];
451
+ const baseExtensions = (_a2 = base == null ? void 0 : base.extension) != null ? _a2 : [];
452
452
  for (const extension of baseExtensions) {
453
453
  if (extension.url !== FHIR_TRANSLATION_EXTENSION_URL) {
454
454
  nextExtensions.push(cloneExtension(extension));
@@ -472,8 +472,8 @@ function buildTranslationPrimitiveElement(translations, base) {
472
472
  };
473
473
  }
474
474
  function getTranslationParts(extension) {
475
- var _a, _b;
476
- const parts = (_a = extension.extension) != null ? _a : [];
475
+ var _a2, _b;
476
+ const parts = (_a2 = extension.extension) != null ? _a2 : [];
477
477
  let locale;
478
478
  let content;
479
479
  for (const part of parts) {
@@ -491,9 +491,9 @@ function getTranslationParts(extension) {
491
491
  return { locale, content };
492
492
  }
493
493
  function getPrimitiveTranslation(element, locale) {
494
- var _a;
494
+ var _a2;
495
495
  const targetLocale = normalizeLocaleKey(locale);
496
- if (!targetLocale || !((_a = element == null ? void 0 : element.extension) == null ? void 0 : _a.length)) {
496
+ if (!targetLocale || !((_a2 = element == null ? void 0 : element.extension) == null ? void 0 : _a2.length)) {
497
497
  return void 0;
498
498
  }
499
499
  let languagePrefixMatch;
@@ -548,19 +548,19 @@ function cloneBodySiteCoding(coding) {
548
548
  };
549
549
  }
550
550
  function bodySiteCodingToFhir(coding) {
551
- var _a;
551
+ var _a2;
552
552
  if (!(coding == null ? void 0 : coding.code)) {
553
553
  return void 0;
554
554
  }
555
555
  return {
556
- system: (_a = coding.system) != null ? _a : SNOMED_SYSTEM2,
556
+ system: (_a2 = coding.system) != null ? _a2 : SNOMED_SYSTEM2,
557
557
  code: coding.code,
558
558
  display: coding.display
559
559
  };
560
560
  }
561
561
  function firstCodingWithCode(concept) {
562
- var _a;
563
- return (_a = concept == null ? void 0 : concept.coding) == null ? void 0 : _a.find((coding) => Boolean(coding.code));
562
+ var _a2;
563
+ return (_a2 = concept == null ? void 0 : concept.coding) == null ? void 0 : _a2.find((coding) => Boolean(coding.code));
564
564
  }
565
565
  function cloneBodySiteSpatialRelation(relation) {
566
566
  if (!relation) {
@@ -613,8 +613,8 @@ function buildBodySiteSpatialRelationExtensions(relation) {
613
613
  return extension ? [extension] : void 0;
614
614
  }
615
615
  function parseBodySiteSpatialRelationExtension(concept) {
616
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
617
- const extension = (_a = concept == null ? void 0 : concept.extension) == null ? void 0 : _a.find(
616
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
617
+ const extension = (_a2 = concept == null ? void 0 : concept.extension) == null ? void 0 : _a2.find(
618
618
  (candidate) => candidate.url === BODY_SITE_SPATIAL_RELATION_EXTENSION_URL
619
619
  );
620
620
  if (!((_b = extension == null ? void 0 : extension.extension) == null ? void 0 : _b.length)) {
@@ -667,8 +667,8 @@ function buildSnomedBodySiteLateralityPostcoordinationCode(siteCode, lateralityC
667
667
  return `${siteCode}${SNOMED_LATERALITY_MARKER}${lateralityCode}`;
668
668
  }
669
669
  function parseSnomedBodySiteTopographicalModifierPostcoordinationCode(code) {
670
- var _a;
671
- const markerIndex = (_a = code == null ? void 0 : code.indexOf(SNOMED_TOPOGRAPHICAL_MODIFIER_MARKER)) != null ? _a : -1;
670
+ var _a2;
671
+ const markerIndex = (_a2 = code == null ? void 0 : code.indexOf(SNOMED_TOPOGRAPHICAL_MODIFIER_MARKER)) != null ? _a2 : -1;
672
672
  if (!code || markerIndex < 0) {
673
673
  return void 0;
674
674
  }
@@ -680,8 +680,8 @@ function parseSnomedBodySiteTopographicalModifierPostcoordinationCode(code) {
680
680
  return { siteCode, modifierCode };
681
681
  }
682
682
  function parseSnomedBodySiteLateralityPostcoordinationCode(code) {
683
- var _a;
684
- const markerIndex = (_a = code == null ? void 0 : code.indexOf(SNOMED_LATERALITY_MARKER)) != null ? _a : -1;
683
+ var _a2;
684
+ const markerIndex = (_a2 = code == null ? void 0 : code.indexOf(SNOMED_LATERALITY_MARKER)) != null ? _a2 : -1;
685
685
  if (!code || markerIndex < 0) {
686
686
  return void 0;
687
687
  }
@@ -693,8 +693,8 @@ function parseSnomedBodySiteLateralityPostcoordinationCode(code) {
693
693
  return { siteCode, lateralityCode };
694
694
  }
695
695
  function parseSnomedFindingSitePostcoordinationCode(code) {
696
- var _a;
697
- const markerIndex = (_a = code == null ? void 0 : code.indexOf(SNOMED_FINDING_SITE_ATTRIBUTE_MARKER)) != null ? _a : -1;
696
+ var _a2;
697
+ const markerIndex = (_a2 = code == null ? void 0 : code.indexOf(SNOMED_FINDING_SITE_ATTRIBUTE_MARKER)) != null ? _a2 : -1;
698
698
  if (!code || markerIndex < 0) {
699
699
  return void 0;
700
700
  }
@@ -706,8 +706,8 @@ function parseSnomedFindingSitePostcoordinationCode(code) {
706
706
  return { focusCode, siteCode };
707
707
  }
708
708
  function buildSnomedFindingSiteCoding(params) {
709
- var _a, _b, _c, _d, _e, _f;
710
- const focusCode = (_a = params.focusCoding) == null ? void 0 : _a.code;
709
+ var _a2, _b, _c, _d, _e, _f;
710
+ const focusCode = (_a2 = params.focusCoding) == null ? void 0 : _a2.code;
711
711
  const siteCode = (_b = params.siteCoding) == null ? void 0 : _b.code;
712
712
  if (!focusCode || !siteCode || hasSnomedFindingSitePostcoordination(focusCode)) {
713
713
  return void 0;
@@ -813,10 +813,10 @@ var ROUTE_SNOMED = objectFromEntries(
813
813
  );
814
814
  var ROUTE_TEXT = objectFromEntries(
815
815
  ROUTE_SNOMED_ENTRIES.map(([routeCode, meta]) => {
816
- var _a;
816
+ var _a2;
817
817
  return [
818
818
  routeCode,
819
- (_a = ROUTE_TEXT_OVERRIDES[routeCode]) != null ? _a : defaultRouteText(meta.display)
819
+ (_a2 = ROUTE_TEXT_OVERRIDES[routeCode]) != null ? _a2 : defaultRouteText(meta.display)
820
820
  ];
821
821
  })
822
822
  );
@@ -1044,7 +1044,7 @@ var LATERALIZABLE_DIGIT_BODY_SITES = [
1044
1044
  }
1045
1045
  ];
1046
1046
  function buildLateralizedDigitBodySiteEntries() {
1047
- var _a;
1047
+ var _a2;
1048
1048
  const entries = [];
1049
1049
  for (const site of LATERALIZABLE_DIGIT_BODY_SITES) {
1050
1050
  for (const laterality of BODY_SITE_LATERALITIES) {
@@ -1069,7 +1069,7 @@ function buildLateralizedDigitBodySiteEntries() {
1069
1069
  display: text
1070
1070
  },
1071
1071
  text,
1072
- routeHint: (_a = site.routeHint) != null ? _a : RouteCode["Topical route"]
1072
+ routeHint: (_a2 = site.routeHint) != null ? _a2 : RouteCode["Topical route"]
1073
1073
  }
1074
1074
  });
1075
1075
  }
@@ -2115,6 +2115,18 @@ var STATIC_UNIT_SYNONYMS = {
2115
2115
  capfuls: "capful",
2116
2116
  scoop: "scoop",
2117
2117
  scoops: "scoop",
2118
+ tube: "tube",
2119
+ tubes: "tube",
2120
+ bottle: "bottle",
2121
+ bottles: "bottle",
2122
+ container: "container",
2123
+ containers: "container",
2124
+ jar: "jar",
2125
+ jars: "jar",
2126
+ packet: "packet",
2127
+ packets: "packet",
2128
+ sachet: "sachet",
2129
+ sachets: "sachet",
2118
2130
  application: "application",
2119
2131
  applications: "application",
2120
2132
  ribbon: "ribbon",
@@ -3712,8 +3724,8 @@ var DEFAULT_PRN_REASON_SOURCE = [
3712
3724
  }
3713
3725
  ];
3714
3726
  var DEFAULT_PRN_REASON_ENTRIES = DEFAULT_PRN_REASON_SOURCE.map((source) => {
3715
- var _a, _b, _c;
3716
- const canonicalTerm = (_c = (_b = source.definition.text) != null ? _b : (_a = source.definition.coding) == null ? void 0 : _a.display) != null ? _c : source.names[0];
3727
+ var _a2, _b, _c;
3728
+ const canonicalTerm = (_c = (_b = source.definition.text) != null ? _b : (_a2 = source.definition.coding) == null ? void 0 : _a2.display) != null ? _c : source.names[0];
3717
3729
  const terms = [];
3718
3730
  const seen = /* @__PURE__ */ new Set();
3719
3731
  const pushTerm = (value) => {
@@ -3760,13 +3772,13 @@ var DEFAULT_PRN_REASON_DEFINITIONS = objectFromEntries(
3760
3772
  }, [])
3761
3773
  );
3762
3774
  function findPrnReasonDefinitionByCoding(system, code) {
3763
- var _a;
3764
- return (_a = DEFAULT_PRN_REASON_SOURCE.find(
3775
+ var _a2;
3776
+ return (_a2 = DEFAULT_PRN_REASON_SOURCE.find(
3765
3777
  (source) => {
3766
- var _a2, _b;
3767
- return ((_a2 = source.definition.coding) == null ? void 0 : _a2.system) === system && ((_b = source.definition.coding) == null ? void 0 : _b.code) === code;
3778
+ var _a3, _b;
3779
+ return ((_a3 = source.definition.coding) == null ? void 0 : _a3.system) === system && ((_b = source.definition.coding) == null ? void 0 : _b.code) === code;
3768
3780
  }
3769
- )) == null ? void 0 : _a.definition;
3781
+ )) == null ? void 0 : _a2.definition;
3770
3782
  }
3771
3783
 
3772
3784
  // src/hpsg/lexical-classes.json
@@ -3864,8 +3876,122 @@ var lexical_classes_default = {
3864
3876
  },
3865
3877
  compoundDoseUnits: [
3866
3878
  { head: "cm", tails: ["ribbon", "ribbons"], unit: "cm ribbon" },
3867
- { head: "fingertip", tails: ["unit", "units"], unit: "fingertip unit" }
3879
+ { head: "cm", tails: ["strip", "strips"], unit: "cm strip" },
3880
+ { head: "cm", tails: ["line", "lines"], unit: "cm line" },
3881
+ { head: "inch", tails: ["ribbon", "ribbons", "strip", "strips"], unit: "inch ribbon" },
3882
+ { head: "inch", tails: ["line", "lines"], unit: "inch line" },
3883
+ { head: "fingertip", tails: ["unit", "units"], unit: "FTU" },
3884
+ { head: "eye", tails: ["drop", "drops"], unit: "drop" },
3885
+ { head: "pea-sized", tails: ["amount"], unit: "pea-sized amount" },
3886
+ { head: "\u0E40\u0E21\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27", tails: [], unit: "pea-sized amount" },
3887
+ { head: "\u0E40\u0E21\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27\u0E40\u0E02\u0E35\u0E22\u0E27", tails: [], unit: "pea-sized amount" },
3888
+ { head: "\u0E40\u0E21\u0E25\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27", tails: [], unit: "pea-sized amount" },
3889
+ { head: "\u0E02\u0E19\u0E32\u0E14\u0E40\u0E21\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27", tails: [], unit: "pea-sized amount" },
3890
+ { head: "\u0E02\u0E19\u0E32\u0E14\u0E40\u0E21\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27\u0E40\u0E02\u0E35\u0E22\u0E27", tails: [], unit: "pea-sized amount" },
3891
+ { head: "\u0E02\u0E19\u0E32\u0E14\u0E40\u0E21\u0E25\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27", tails: [], unit: "pea-sized amount" },
3892
+ {
3893
+ head: "pea",
3894
+ tails: [],
3895
+ tailSequences: [["sized", "amount"], ["size", "amount"]],
3896
+ unit: "pea-sized amount"
3897
+ },
3898
+ { head: "hand", tails: ["print", "prints"], unit: "handprint" },
3899
+ { head: "percent", tails: ["bsa", "tbsa"], unit: "% BSA" },
3900
+ { head: "shot", tails: ["glass", "glasses"], unit: "shot glass" },
3901
+ { head: "finger", tails: ["length", "lengths"], unit: "finger length" },
3902
+ { head: "two-finger", tails: ["rule", "method"], unit: "finger length" },
3903
+ {
3904
+ head: "two",
3905
+ tails: [],
3906
+ tailSequences: [["finger", "rule"], ["finger", "method"]],
3907
+ unit: "finger length"
3908
+ },
3909
+ { head: "full", tails: ["applicator", "applicators"], unit: "applicatorful" },
3910
+ {
3911
+ head: "cap",
3912
+ tails: [],
3913
+ tailSequences: [["to", "line"], ["filled", "to", "line"]],
3914
+ unit: "capful"
3915
+ },
3916
+ { head: "stick", tails: ["pack", "packs"], unit: "stick-pack" },
3917
+ { head: "unit-dose", tails: ["vial", "vials"], unit: "vial" },
3918
+ {
3919
+ head: "unit",
3920
+ tails: [],
3921
+ tailSequences: [["dose", "vial"], ["dose", "vials"]],
3922
+ unit: "vial"
3923
+ },
3924
+ { head: "insulin", tails: ["unit", "units"], unit: "U" },
3925
+ { head: "usp", tails: ["unit", "units"], unit: "U" },
3926
+ { head: "pen", tails: ["click", "clicks"], unit: "click" },
3927
+ { head: "dial", tails: ["click", "clicks"], unit: "click" },
3928
+ { head: "transdermal", tails: ["system", "systems"], unit: "patch" }
3868
3929
  ],
3930
+ implicitSingleDoseUnits: ["pea-sized amount", "finger length"],
3931
+ percentBodyAreaUnits: {
3932
+ bsa: "% BSA",
3933
+ tbsa: "% BSA"
3934
+ },
3935
+ doseFractionWords: {
3936
+ half: 0.5,
3937
+ quarter: 0.25,
3938
+ fourth: 0.25,
3939
+ third: 0.3333333333333333,
3940
+ fifth: 0.2,
3941
+ sixth: 0.16666666666666666,
3942
+ seventh: 0.14285714285714285,
3943
+ eighth: 0.125,
3944
+ ninth: 0.1111111111111111,
3945
+ tenth: 0.1,
3946
+ eleventh: 0.09090909090909091,
3947
+ twelfth: 0.08333333333333333,
3948
+ whole: 1,
3949
+ entire: 1,
3950
+ full: 1
3951
+ },
3952
+ doseFractionDenominatorWords: {
3953
+ half: 0.5,
3954
+ halves: 0.5,
3955
+ quarter: 0.25,
3956
+ quarters: 0.25,
3957
+ fourth: 0.25,
3958
+ fourths: 0.25,
3959
+ third: 0.3333333333333333,
3960
+ thirds: 0.3333333333333333,
3961
+ fifth: 0.2,
3962
+ fifths: 0.2,
3963
+ sixth: 0.16666666666666666,
3964
+ sixths: 0.16666666666666666,
3965
+ seventh: 0.14285714285714285,
3966
+ sevenths: 0.14285714285714285,
3967
+ eighth: 0.125,
3968
+ eighths: 0.125,
3969
+ ninth: 0.1111111111111111,
3970
+ ninths: 0.1111111111111111,
3971
+ tenth: 0.1,
3972
+ tenths: 0.1,
3973
+ eleventh: 0.09090909090909091,
3974
+ elevenths: 0.09090909090909091,
3975
+ twelfth: 0.08333333333333333,
3976
+ twelfths: 0.08333333333333333
3977
+ },
3978
+ doseNumberWords: {
3979
+ a: 1,
3980
+ an: 1,
3981
+ one: 1,
3982
+ two: 2,
3983
+ three: 3,
3984
+ four: 4,
3985
+ five: 5,
3986
+ six: 6,
3987
+ seven: 7,
3988
+ eight: 8,
3989
+ nine: 9,
3990
+ ten: 10,
3991
+ eleven: 11,
3992
+ twelve: 12
3993
+ },
3994
+ doseUnitConnectors: ["of", "a", "an", "the"],
3869
3995
  millionDoseMultiplierTokens: ["m"],
3870
3996
  scheduleUnitSeparatorTokens: ["/"],
3871
3997
  compactListSeparators: ["/"],
@@ -3989,6 +4115,7 @@ var lexical_classes_default = {
3989
4115
  "dont",
3990
4116
  "drink",
3991
4117
  "empty",
4118
+ "gently",
3992
4119
  "liberally",
3993
4120
  "may",
3994
4121
  "might",
@@ -4001,10 +4128,24 @@ var lexical_classes_default = {
4001
4128
  "should",
4002
4129
  "slowly",
4003
4130
  "sparingly",
4131
+ "thickly",
4132
+ "thick",
4133
+ "thinly",
4134
+ "thin",
4004
4135
  "use",
4005
4136
  "with",
4006
4137
  "without"
4007
4138
  ],
4139
+ siteTrailingInstructionWords: [
4140
+ "gently",
4141
+ "liberally",
4142
+ "slowly",
4143
+ "sparingly",
4144
+ "thick",
4145
+ "thickly",
4146
+ "thin",
4147
+ "thinly"
4148
+ ],
4008
4149
  workflowContinuationLicenses: ["with each", "after each", "the *event", "sun exposure"],
4009
4150
  asNeededLeadPhrases: ["as needed"],
4010
4151
  prnBreakingCoordinators: [",", "/"],
@@ -4052,9 +4193,9 @@ function routeCodeSet(labels) {
4052
4193
  );
4053
4194
  }
4054
4195
  function eventTimingMap(record) {
4055
- var _a, _b;
4196
+ var _a2, _b;
4056
4197
  const map = /* @__PURE__ */ new Map();
4057
- const nodeEnv = (_b = (_a = globalThis.process) == null ? void 0 : _a.env) == null ? void 0 : _b.NODE_ENV;
4198
+ const nodeEnv = (_b = (_a2 = globalThis.process) == null ? void 0 : _a2.env) == null ? void 0 : _b.NODE_ENV;
4058
4199
  const shouldWarn = nodeEnv !== "production";
4059
4200
  for (const key in record) {
4060
4201
  if (Object.prototype.hasOwnProperty.call(record, key)) {
@@ -4105,6 +4246,15 @@ function stringEntries(record) {
4105
4246
  function numberRecord(record) {
4106
4247
  return __spreadValues({}, record);
4107
4248
  }
4249
+ function numberEntries(record) {
4250
+ const entries = [];
4251
+ for (const key in record) {
4252
+ if (Object.prototype.hasOwnProperty.call(record, key)) {
4253
+ entries.push([key, record[key]]);
4254
+ }
4255
+ }
4256
+ return entries;
4257
+ }
4108
4258
  function periodUnitRecord(record) {
4109
4259
  const result = /* @__PURE__ */ new Map();
4110
4260
  for (const [token, label] of stringEntries(record)) {
@@ -4177,6 +4327,20 @@ var SITE_ROUTE_HINTS_ALLOWED_IN_GRAMMAR = routeCodeSet(lexical_classes_default.s
4177
4327
  var PRODUCT_METHOD_TEXT = lexical_classes_default.productMethodText;
4178
4328
  var PRODUCT_METHOD_THAI = lexical_classes_default.productMethodThai;
4179
4329
  var COMPOUND_DOSE_UNITS = lexical_classes_default.compoundDoseUnits;
4330
+ var IMPLICIT_SINGLE_DOSE_UNITS = setOf(lexical_classes_default.implicitSingleDoseUnits);
4331
+ var PERCENT_BODY_AREA_UNITS = new Map(
4332
+ stringEntries(lexical_classes_default.percentBodyAreaUnits)
4333
+ );
4334
+ var DOSE_FRACTION_WORDS = new Map(
4335
+ numberEntries(lexical_classes_default.doseFractionWords)
4336
+ );
4337
+ var DOSE_FRACTION_DENOMINATOR_WORDS = new Map(
4338
+ numberEntries(lexical_classes_default.doseFractionDenominatorWords)
4339
+ );
4340
+ var DOSE_NUMBER_WORDS = new Map(
4341
+ numberEntries(lexical_classes_default.doseNumberWords)
4342
+ );
4343
+ var DOSE_UNIT_CONNECTORS = setOf(lexical_classes_default.doseUnitConnectors);
4180
4344
  var MILLION_DOSE_MULTIPLIER_TOKENS = setOf(lexical_classes_default.millionDoseMultiplierTokens);
4181
4345
  var SCHEDULE_UNIT_SEPARATOR_TOKENS = setOf(lexical_classes_default.scheduleUnitSeparatorTokens);
4182
4346
  var COMPACT_LIST_SEPARATORS = setOf(lexical_classes_default.compactListSeparators);
@@ -4212,6 +4376,7 @@ var RANGE_CONNECTORS = setOf(lexical_classes_default.rangeConnectors);
4212
4376
  var DURATION_LEAD_TOKENS = setOf(lexical_classes_default.durationLeadTokens);
4213
4377
  var INSTRUCTION_LEADING_SEPARATORS = setOf(lexical_classes_default.instructionLeadingSeparators);
4214
4378
  var INSTRUCTION_START_WORDS = setOf(lexical_classes_default.instructionStartWords);
4379
+ var SITE_TRAILING_INSTRUCTION_WORDS = setOf(lexical_classes_default.siteTrailingInstructionWords);
4215
4380
  var WORKFLOW_CONTINUATION_LICENSES = setOf(lexical_classes_default.workflowContinuationLicenses);
4216
4381
  var AS_NEEDED_LEAD_PHRASES = setOf(lexical_classes_default.asNeededLeadPhrases);
4217
4382
  var PRN_BREAKING_COORDINATORS = setOf(lexical_classes_default.prnBreakingCoordinators);
@@ -4250,7 +4415,7 @@ var HAND_CONTEXT_KEYS = /* @__PURE__ */ new Set(["hand", "hands", "finger", "fin
4250
4415
  var FOOT_CONTEXT_KEYS = /* @__PURE__ */ new Set(["foot", "feet", "toe", "toes", "\u0E19\u0E34\u0E49\u0E27\u0E40\u0E17\u0E49\u0E32", "\u0E40\u0E17\u0E49\u0E32"]);
4251
4416
  var BODY_SITE_ALIAS_INDEXES = /* @__PURE__ */ new WeakMap();
4252
4417
  function buildOrGetBodySiteAliasIndex(map) {
4253
- var _a;
4418
+ var _a2;
4254
4419
  const existing = BODY_SITE_ALIAS_INDEXES.get(map);
4255
4420
  if (existing) {
4256
4421
  return existing;
@@ -4261,7 +4426,7 @@ function buildOrGetBodySiteAliasIndex(map) {
4261
4426
  if (normalizedKey) {
4262
4427
  index.set(normalizedKey, definition);
4263
4428
  }
4264
- for (const alias of (_a = definition.aliases) != null ? _a : []) {
4429
+ for (const alias of (_a2 = definition.aliases) != null ? _a2 : []) {
4265
4430
  const normalizedAlias = normalizeBodySiteKey(alias);
4266
4431
  if (normalizedAlias) {
4267
4432
  index.set(normalizedAlias, definition);
@@ -4322,7 +4487,7 @@ function resolveContextualBodySiteAlias(lookupCanonical, context) {
4322
4487
  return void 0;
4323
4488
  }
4324
4489
  function buildBodySiteCoding(definition) {
4325
- var _a;
4490
+ var _a2;
4326
4491
  const coding = definition == null ? void 0 : definition.coding;
4327
4492
  if (!(coding == null ? void 0 : coding.code)) {
4328
4493
  return void 0;
@@ -4330,24 +4495,24 @@ function buildBodySiteCoding(definition) {
4330
4495
  return {
4331
4496
  code: coding.code,
4332
4497
  display: coding.display,
4333
- system: (_a = coding.system) != null ? _a : SNOMED_SYSTEM3
4498
+ system: (_a2 = coding.system) != null ? _a2 : SNOMED_SYSTEM3
4334
4499
  };
4335
4500
  }
4336
4501
  function cloneBodySiteCode(coding) {
4337
- var _a;
4502
+ var _a2;
4338
4503
  if (!(coding == null ? void 0 : coding.code)) {
4339
4504
  return void 0;
4340
4505
  }
4341
4506
  return {
4342
4507
  code: coding.code,
4343
4508
  display: coding.display,
4344
- system: (_a = coding.system) != null ? _a : SNOMED_SYSTEM3,
4509
+ system: (_a2 = coding.system) != null ? _a2 : SNOMED_SYSTEM3,
4345
4510
  i18n: coding.i18n
4346
4511
  };
4347
4512
  }
4348
4513
  function lookupDefinitionForCanonical(canonical, customSiteMap) {
4349
- var _a;
4350
- return (_a = lookupBodySiteDefinition(customSiteMap, canonical)) != null ? _a : DEFAULT_BODY_SITE_SNOMED[canonical];
4514
+ var _a2;
4515
+ return (_a2 = lookupBodySiteDefinition(customSiteMap, canonical)) != null ? _a2 : DEFAULT_BODY_SITE_SNOMED[canonical];
4351
4516
  }
4352
4517
  function isAdjectivalSitePhrase(phrase) {
4353
4518
  const normalized = phrase.trim().toLowerCase();
@@ -4434,7 +4599,7 @@ function pickPreferredBodySitePhrase(canonical, definition, customSiteMap) {
4434
4599
  return normalizeBodySiteKey(best) === canonical ? void 0 : best;
4435
4600
  }
4436
4601
  function normalizeSiteDisplayText(text, customSiteMap) {
4437
- var _a, _b;
4602
+ var _a2, _b;
4438
4603
  const trimmed = text.trim();
4439
4604
  if (!trimmed) {
4440
4605
  return trimmed;
@@ -4443,13 +4608,13 @@ function normalizeSiteDisplayText(text, customSiteMap) {
4443
4608
  if (!canonicalInput) {
4444
4609
  return trimmed;
4445
4610
  }
4446
- const directDefinition = (_a = lookupBodySiteDefinition(customSiteMap, canonicalInput)) != null ? _a : DEFAULT_BODY_SITE_SNOMED[canonicalInput];
4611
+ const directDefinition = (_a2 = lookupBodySiteDefinition(customSiteMap, canonicalInput)) != null ? _a2 : DEFAULT_BODY_SITE_SNOMED[canonicalInput];
4447
4612
  if (directDefinition) {
4448
4613
  return (_b = directDefinition.text) != null ? _b : canonicalInput;
4449
4614
  }
4450
4615
  const resolvePreferred = (canonical) => {
4451
- var _a2, _b2, _c;
4452
- const definition = (_a2 = lookupBodySiteDefinition(customSiteMap, canonical)) != null ? _a2 : DEFAULT_BODY_SITE_SNOMED[canonical];
4616
+ var _a3, _b2, _c;
4617
+ const definition = (_a3 = lookupBodySiteDefinition(customSiteMap, canonical)) != null ? _a3 : DEFAULT_BODY_SITE_SNOMED[canonical];
4453
4618
  if (!definition) {
4454
4619
  return void 0;
4455
4620
  }
@@ -4558,10 +4723,10 @@ function renderNominalObject(features) {
4558
4723
  return features.article === "bare" ? features.text : `the ${features.text}`;
4559
4724
  }
4560
4725
  function renderBodySiteObject(features) {
4561
- var _a;
4726
+ var _a2;
4562
4727
  switch (features.kind) {
4563
4728
  case "locative":
4564
- return `${(_a = BODY_SITE_LOCATIVE_RENDER_PREPOSITIONS.get(features.relation)) != null ? _a : features.relation} ${renderBodySiteObject(features.target)}`;
4729
+ return `${(_a2 = BODY_SITE_LOCATIVE_RENDER_PREPOSITIONS.get(features.relation)) != null ? _a2 : features.relation} ${renderBodySiteObject(features.target)}`;
4565
4730
  case "partitive":
4566
4731
  return `${features.part.startsWith("both") || features.part.startsWith("bilateral") ? features.part : `the ${features.part}`} of ${renderNominalObject(features.whole)}`;
4567
4732
  case "nominal":
@@ -4597,7 +4762,7 @@ function resolveFeatureCoding(features, customSiteMap) {
4597
4762
  }
4598
4763
  }
4599
4764
  function buildSpatialRelation(features, sourceText, customSiteMap) {
4600
- var _a;
4765
+ var _a2;
4601
4766
  switch (features.kind) {
4602
4767
  case "locative": {
4603
4768
  const relationCoding = BODY_SITE_SPATIAL_RELATION_CODINGS.get(features.relation);
@@ -4610,7 +4775,7 @@ function buildSpatialRelation(features, sourceText, customSiteMap) {
4610
4775
  };
4611
4776
  }
4612
4777
  case "partitive": {
4613
- const relationCoding = BODY_SITE_SPATIAL_RELATION_CODINGS.get((_a = features.relationKey) != null ? _a : features.part);
4778
+ const relationCoding = BODY_SITE_SPATIAL_RELATION_CODINGS.get((_a2 = features.relationKey) != null ? _a2 : features.part);
4614
4779
  if (!relationCoding) {
4615
4780
  return void 0;
4616
4781
  }
@@ -4649,7 +4814,7 @@ function inferPreferredPreposition(canonical, features, definition) {
4649
4814
  return void 0;
4650
4815
  }
4651
4816
  function resolveBodySitePhrase(text, customSiteMap, context) {
4652
- var _a, _b, _c, _d, _e, _f, _g;
4817
+ var _a2, _b, _c, _d, _e, _f, _g;
4653
4818
  const trimmed = text.trim().replace(/\s+/g, " ");
4654
4819
  if (!trimmed) {
4655
4820
  return void 0;
@@ -4659,7 +4824,7 @@ function resolveBodySitePhrase(text, customSiteMap, context) {
4659
4824
  const displaySourceText = contextualCanonical != null ? contextualCanonical : trimmed;
4660
4825
  const displayText = normalizeSiteDisplayText(displaySourceText, customSiteMap);
4661
4826
  const canonical = normalizeBodySiteKey(displayText);
4662
- const definition = (_e = (_d = (_c = (_b = (_a = lookupBodySiteDefinition(customSiteMap, lookupCanonical)) != null ? _a : contextualCanonical ? lookupBodySiteDefinition(customSiteMap, contextualCanonical) : void 0) != null ? _b : contextualCanonical ? DEFAULT_BODY_SITE_SNOMED[contextualCanonical] : void 0) != null ? _c : DEFAULT_BODY_SITE_SNOMED[lookupCanonical]) != null ? _d : lookupBodySiteDefinition(customSiteMap, canonical)) != null ? _e : DEFAULT_BODY_SITE_SNOMED[canonical];
4827
+ const definition = (_e = (_d = (_c = (_b = (_a2 = lookupBodySiteDefinition(customSiteMap, lookupCanonical)) != null ? _a2 : contextualCanonical ? lookupBodySiteDefinition(customSiteMap, contextualCanonical) : void 0) != null ? _b : contextualCanonical ? DEFAULT_BODY_SITE_SNOMED[contextualCanonical] : void 0) != null ? _c : DEFAULT_BODY_SITE_SNOMED[lookupCanonical]) != null ? _d : lookupBodySiteDefinition(customSiteMap, canonical)) != null ? _e : DEFAULT_BODY_SITE_SNOMED[canonical];
4663
4828
  const coding = buildBodySiteCoding(definition);
4664
4829
  const finalDisplayText = (_f = definition == null ? void 0 : definition.text) != null ? _f : displayText;
4665
4830
  const features = parseBodySiteFeatures(finalDisplayText, coding, customSiteMap);
@@ -4789,7 +4954,7 @@ function getMealTimingGroup(when, options) {
4789
4954
  };
4790
4955
  }
4791
4956
  function inferDailyOccurrenceCount(input, options) {
4792
- var _a, _b, _c, _d;
4957
+ var _a2, _b, _c, _d;
4793
4958
  if (!(options == null ? void 0 : options.includeTimesPerDaySummary)) {
4794
4959
  return void 0;
4795
4960
  }
@@ -4799,7 +4964,7 @@ function inferDailyOccurrenceCount(input, options) {
4799
4964
  if (input.period !== void 0 || input.periodMax !== void 0 || input.periodUnit !== void 0) {
4800
4965
  return void 0;
4801
4966
  }
4802
- if (((_b = (_a = input.dayOfWeek) == null ? void 0 : _a.length) != null ? _b : 0) > 0) {
4967
+ if (((_b = (_a2 = input.dayOfWeek) == null ? void 0 : _a2.length) != null ? _b : 0) > 0) {
4803
4968
  return void 0;
4804
4969
  }
4805
4970
  const uniqueWhen2 = uniqueValues((_c = input.when) != null ? _c : []);
@@ -4944,8 +5109,8 @@ var ROUTE_GRAMMAR = {
4944
5109
  }
4945
5110
  };
4946
5111
  function scheduleOf(clause) {
4947
- var _a;
4948
- return (_a = clause.schedule) != null ? _a : {};
5112
+ var _a2;
5113
+ return (_a2 = clause.schedule) != null ? _a2 : {};
4949
5114
  }
4950
5115
  function grammarFromRouteText(text) {
4951
5116
  if (!text) {
@@ -4997,16 +5162,16 @@ function grammarFromRouteText(text) {
4997
5162
  return void 0;
4998
5163
  }
4999
5164
  function resolveRouteGrammar(clause) {
5000
- var _a, _b, _c, _d;
5001
- const routeCode = (_a = clause.route) == null ? void 0 : _a.code;
5165
+ var _a2, _b, _c, _d;
5166
+ const routeCode = (_a2 = clause.route) == null ? void 0 : _a2.code;
5002
5167
  if (routeCode && ROUTE_GRAMMAR[routeCode]) {
5003
5168
  return (_b = ROUTE_GRAMMAR[routeCode]) != null ? _b : DEFAULT_ROUTE_GRAMMAR;
5004
5169
  }
5005
5170
  return (_d = grammarFromRouteText((_c = clause.route) == null ? void 0 : _c.text)) != null ? _d : DEFAULT_ROUTE_GRAMMAR;
5006
5171
  }
5007
5172
  function resolveMethodVerb(clause, grammar) {
5008
- var _a, _b;
5009
- const methodText = (_b = (_a = clause.method) == null ? void 0 : _a.text) == null ? void 0 : _b.trim();
5173
+ var _a2, _b;
5174
+ const methodText = (_b = (_a2 = clause.method) == null ? void 0 : _a2.text) == null ? void 0 : _b.trim();
5010
5175
  if (methodText) {
5011
5176
  return methodText;
5012
5177
  }
@@ -5019,6 +5184,8 @@ function pluralize(unit, value) {
5019
5184
  return "tablet";
5020
5185
  case "cap":
5021
5186
  return "capsule";
5187
+ case "FTU":
5188
+ return "FTU";
5022
5189
  default:
5023
5190
  return unit;
5024
5191
  }
@@ -5026,6 +5193,9 @@ function pluralize(unit, value) {
5026
5193
  if (unit.endsWith(" ribbon")) {
5027
5194
  return unit;
5028
5195
  }
5196
+ if (unit.endsWith(" line")) {
5197
+ return unit;
5198
+ }
5029
5199
  switch (unit) {
5030
5200
  case "tab":
5031
5201
  case "tablet":
@@ -5040,6 +5210,8 @@ function pluralize(unit, value) {
5040
5210
  return "puffs";
5041
5211
  case "patch":
5042
5212
  return "patches";
5213
+ case "ring":
5214
+ return "rings";
5043
5215
  case "drop":
5044
5216
  return "drops";
5045
5217
  case "suppository":
@@ -5054,8 +5226,28 @@ function pluralize(unit, value) {
5054
5226
  return "capfuls";
5055
5227
  case "scoop":
5056
5228
  return "scoops";
5229
+ case "palm":
5230
+ return "palms";
5231
+ case "handprint":
5232
+ return "handprints";
5233
+ case "shot glass":
5234
+ return "shot glasses";
5235
+ case "click":
5236
+ return "clicks";
5237
+ case "vial":
5238
+ return "vials";
5239
+ case "ampule":
5240
+ return "ampules";
5241
+ case "packet":
5242
+ return "packets";
5243
+ case "sachet":
5244
+ return "sachets";
5245
+ case "stick-pack":
5246
+ return "stick-packs";
5057
5247
  case "application":
5058
5248
  return "applications";
5249
+ case "FTU":
5250
+ return "FTU";
5059
5251
  case "fingertip unit":
5060
5252
  return "fingertip units";
5061
5253
  case "finger length":
@@ -5184,12 +5376,12 @@ function describeFrequencyCount(count) {
5184
5376
  return `${stripTrailingZero(count)} times daily`;
5185
5377
  }
5186
5378
  function describeStandaloneOccurrenceCount(schedule) {
5187
- var _a, _b, _c;
5379
+ var _a2, _b, _c;
5188
5380
  const count = schedule == null ? void 0 : schedule.count;
5189
5381
  if (!count || count <= 0) {
5190
5382
  return void 0;
5191
5383
  }
5192
- if ((schedule == null ? void 0 : schedule.frequency) !== void 0 || (schedule == null ? void 0 : schedule.frequencyMax) !== void 0 || (schedule == null ? void 0 : schedule.period) !== void 0 || (schedule == null ? void 0 : schedule.periodMax) !== void 0 || (schedule == null ? void 0 : schedule.periodUnit) !== void 0 || ((_a = schedule == null ? void 0 : schedule.dayOfWeek) == null ? void 0 : _a.length) || ((_b = schedule == null ? void 0 : schedule.when) == null ? void 0 : _b.length) || ((_c = schedule == null ? void 0 : schedule.timeOfDay) == null ? void 0 : _c.length) || (schedule == null ? void 0 : schedule.duration) !== void 0 || (schedule == null ? void 0 : schedule.durationMax) !== void 0 || (schedule == null ? void 0 : schedule.durationUnit) !== void 0 || (schedule == null ? void 0 : schedule.timingCode)) {
5384
+ if ((schedule == null ? void 0 : schedule.frequency) !== void 0 || (schedule == null ? void 0 : schedule.frequencyMax) !== void 0 || (schedule == null ? void 0 : schedule.period) !== void 0 || (schedule == null ? void 0 : schedule.periodMax) !== void 0 || (schedule == null ? void 0 : schedule.periodUnit) !== void 0 || ((_a2 = schedule == null ? void 0 : schedule.dayOfWeek) == null ? void 0 : _a2.length) || ((_b = schedule == null ? void 0 : schedule.when) == null ? void 0 : _b.length) || ((_c = schedule == null ? void 0 : schedule.timeOfDay) == null ? void 0 : _c.length) || (schedule == null ? void 0 : schedule.duration) !== void 0 || (schedule == null ? void 0 : schedule.durationMax) !== void 0 || (schedule == null ? void 0 : schedule.durationUnit) !== void 0 || (schedule == null ? void 0 : schedule.timingCode)) {
5193
5385
  return void 0;
5194
5386
  }
5195
5387
  switch (count) {
@@ -5281,8 +5473,8 @@ function summarizeMealTimingGroup(group) {
5281
5473
  return `${relationText} ${joinWithAnd(group.meals)}`;
5282
5474
  }
5283
5475
  function collectWhenPhrases(schedule, options) {
5284
- var _a, _b, _c;
5285
- const when = (_a = schedule == null ? void 0 : schedule.when) != null ? _a : [];
5476
+ var _a2, _b, _c;
5477
+ const when = (_a2 = schedule == null ? void 0 : schedule.when) != null ? _a2 : [];
5286
5478
  if (!when.length) {
5287
5479
  return [];
5288
5480
  }
@@ -5379,14 +5571,14 @@ function combineFrequencyAndEvents(frequency, events) {
5379
5571
  return { frequency, event: joinWithAnd(events) };
5380
5572
  }
5381
5573
  function buildRoutePhrase(clause, grammar, hasSite) {
5382
- var _a, _b;
5574
+ var _a2, _b;
5383
5575
  if (typeof grammar.routePhrase === "function") {
5384
5576
  return grammar.routePhrase({ hasSite, clause });
5385
5577
  }
5386
5578
  if (typeof grammar.routePhrase === "string") {
5387
5579
  return grammar.routePhrase;
5388
5580
  }
5389
- const text = (_b = (_a = clause.route) == null ? void 0 : _a.text) == null ? void 0 : _b.trim();
5581
+ const text = (_b = (_a2 = clause.route) == null ? void 0 : _a2.text) == null ? void 0 : _b.trim();
5390
5582
  if (!text) {
5391
5583
  return void 0;
5392
5584
  }
@@ -5433,11 +5625,11 @@ var ENGLISH_SPATIAL_PREPOSITIONS = {
5433
5625
  under: "under"
5434
5626
  };
5435
5627
  function renderSpatialSiteEnglish(relation, grammar) {
5436
- var _a, _b, _c, _d;
5628
+ var _a2, _b, _c, _d;
5437
5629
  if (!(relation == null ? void 0 : relation.relationText)) {
5438
5630
  return void 0;
5439
5631
  }
5440
- const rawTarget = (_b = relation.targetText) != null ? _b : (_a = relation.targetCoding) == null ? void 0 : _a.display;
5632
+ const rawTarget = (_b = relation.targetText) != null ? _b : (_a2 = relation.targetCoding) == null ? void 0 : _a2.display;
5441
5633
  if (!rawTarget) {
5442
5634
  return void 0;
5443
5635
  }
@@ -5465,8 +5657,8 @@ function renderSpatialSiteEnglish(relation, grammar) {
5465
5657
  }
5466
5658
  }
5467
5659
  function formatSite(clause, grammar) {
5468
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
5469
- let text = (_b = (_a = clause.site) == null ? void 0 : _a.text) == null ? void 0 : _b.trim();
5660
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
5661
+ let text = (_b = (_a2 = clause.site) == null ? void 0 : _a2.text) == null ? void 0 : _b.trim();
5470
5662
  if (!text) {
5471
5663
  const spatialSite = renderSpatialSiteEnglish((_c = clause.site) == null ? void 0 : _c.spatialRelation, grammar);
5472
5664
  if (spatialSite) {
@@ -5511,8 +5703,8 @@ function formatSite(clause, grammar) {
5511
5703
  return `${preposition} ${noun}`.trim();
5512
5704
  }
5513
5705
  function describeDayOfWeek(schedule) {
5514
- var _a, _b;
5515
- const dayOfWeek = (_a = schedule == null ? void 0 : schedule.dayOfWeek) != null ? _a : [];
5706
+ var _a2, _b;
5707
+ const dayOfWeek = (_a2 = schedule == null ? void 0 : schedule.dayOfWeek) != null ? _a2 : [];
5516
5708
  if (!dayOfWeek.length) {
5517
5709
  return void 0;
5518
5710
  }
@@ -5559,8 +5751,8 @@ function describeDuration(schedule) {
5559
5751
  return `for ${stripTrailingZero(schedule.duration)} ${label(schedule.duration)}`;
5560
5752
  }
5561
5753
  function shouldUseGenericMedicationObject(clause) {
5562
- var _a, _b;
5563
- const methodText = (_b = (_a = clause.method) == null ? void 0 : _a.text) == null ? void 0 : _b.trim();
5754
+ var _a2, _b;
5755
+ const methodText = (_b = (_a2 = clause.method) == null ? void 0 : _a2.text) == null ? void 0 : _b.trim();
5564
5756
  switch (methodText) {
5565
5757
  case "Apply sunscreen":
5566
5758
  case "Reapply sunscreen":
@@ -5571,8 +5763,8 @@ function shouldUseGenericMedicationObject(clause) {
5571
5763
  }
5572
5764
  }
5573
5765
  function shouldSuppressRoutePhrase(clause, grammar, verb) {
5574
- var _a;
5575
- if (((_a = clause.route) == null ? void 0 : _a.code) !== RouteCode["Oral route"]) {
5766
+ var _a2;
5767
+ if (((_a2 = clause.route) == null ? void 0 : _a2.code) !== RouteCode["Oral route"]) {
5576
5768
  return false;
5577
5769
  }
5578
5770
  if (grammar.routePhrase !== "orally") {
@@ -5587,14 +5779,14 @@ function shouldSuppressRoutePhrase(clause, grammar, verb) {
5587
5779
  }
5588
5780
  }
5589
5781
  function formatShort(clause) {
5590
- var _a, _b, _c, _d, _e, _f;
5782
+ var _a2, _b, _c, _d, _e, _f;
5591
5783
  const schedule = scheduleOf(clause);
5592
5784
  const parts = [];
5593
5785
  const dosePart = formatDoseShort(clause.dose);
5594
5786
  if (dosePart) {
5595
5787
  parts.push(dosePart);
5596
5788
  }
5597
- const routeCode = (_a = clause.route) == null ? void 0 : _a.code;
5789
+ const routeCode = (_a2 = clause.route) == null ? void 0 : _a2.code;
5598
5790
  const routeText = (_b = clause.route) == null ? void 0 : _b.text;
5599
5791
  if (routeCode) {
5600
5792
  const short = ROUTE_SHORT[routeCode];
@@ -5652,7 +5844,7 @@ function formatShort(clause) {
5652
5844
  return parts.filter(Boolean).join(" ");
5653
5845
  }
5654
5846
  function formatLong(clause, options) {
5655
- var _a, _b, _c, _d, _e, _f;
5847
+ var _a2, _b, _c, _d, _e, _f;
5656
5848
  const schedule = scheduleOf(clause);
5657
5849
  const grammar = resolveRouteGrammar(clause);
5658
5850
  const verb = resolveMethodVerb(clause, grammar);
@@ -5661,7 +5853,7 @@ function formatLong(clause, options) {
5661
5853
  const sitePart = formatSite(clause, grammar);
5662
5854
  const routePart = shouldSuppressRoutePhrase(clause, grammar, verb) ? void 0 : buildRoutePhrase(clause, grammar, Boolean(sitePart));
5663
5855
  const standaloneOccurrenceCount = describeStandaloneOccurrenceCount(schedule);
5664
- const frequencyPart = (_b = (_a = describeFrequency(schedule)) != null ? _a : standaloneOccurrenceCount) != null ? _b : describeFrequencyCount(inferDailyOccurrenceCount(schedule, options));
5856
+ const frequencyPart = (_b = (_a2 = describeFrequency(schedule)) != null ? _a2 : standaloneOccurrenceCount) != null ? _b : describeFrequencyCount(inferDailyOccurrenceCount(schedule, options));
5665
5857
  const eventParts = collectWhenPhrases(schedule, options);
5666
5858
  if ((_c = schedule.timeOfDay) == null ? void 0 : _c.length) {
5667
5859
  const timeStrings = [];
@@ -5738,8 +5930,8 @@ function formatLong(clause, options) {
5738
5930
  return trailingInstructionText ? `${baseSentence} ${trailingInstructionText}` : baseSentence;
5739
5931
  }
5740
5932
  function formatAdditionalInstructions(clause) {
5741
- var _a, _b, _c, _d, _e, _f;
5742
- const instructions = (_a = clause.additionalInstructions) != null ? _a : [];
5933
+ var _a2, _b, _c, _d, _e, _f;
5934
+ const instructions = (_a2 = clause.additionalInstructions) != null ? _a2 : [];
5743
5935
  if (!instructions.length) {
5744
5936
  return void 0;
5745
5937
  }
@@ -5874,6 +6066,12 @@ var advice_terminology_default = {
5874
6066
  { surface: "whole", lemma: "whole", partOfSpeech: "modifier", semanticClass: "amount_style" },
5875
6067
  { surface: "thin layer", lemma: "thin layer", partOfSpeech: "noun", semanticClass: "amount_style" },
5876
6068
  { surface: "thin film", lemma: "thin film", partOfSpeech: "noun", semanticClass: "amount_style" },
6069
+ { surface: "thin coat", lemma: "thin layer", partOfSpeech: "noun", semanticClass: "amount_style" },
6070
+ { surface: "thinly", lemma: "thin layer", partOfSpeech: "modifier", semanticClass: "amount_style" },
6071
+ { surface: "thick layer", lemma: "thick layer", partOfSpeech: "noun", semanticClass: "amount_style" },
6072
+ { surface: "thick coat", lemma: "thick layer", partOfSpeech: "noun", semanticClass: "amount_style" },
6073
+ { surface: "thickly", lemma: "thick layer", partOfSpeech: "modifier", semanticClass: "amount_style" },
6074
+ { surface: "gently", lemma: "gently", partOfSpeech: "modifier", semanticClass: "manner_style" },
5877
6075
  { surface: "sparingly", lemma: "sparingly", partOfSpeech: "modifier", semanticClass: "amount_style" },
5878
6076
  { surface: "liberally", lemma: "liberally", partOfSpeech: "modifier", semanticClass: "amount_style" },
5879
6077
  { surface: "slowly", lemma: "slowly", partOfSpeech: "modifier", semanticClass: "manner_style" },
@@ -5928,6 +6126,14 @@ var advice_terminology_default = {
5928
6126
  { surface: "dressing", lemma: "dressing", semanticClass: "material", conceptId: "dressing" },
5929
6127
  { surface: "affected area", lemma: "affected area", semanticClass: "site", conceptId: "affected_area" },
5930
6128
  { surface: "affected areas", lemma: "affected area", semanticClass: "site", conceptId: "affected_area" },
6129
+ { surface: "thinly", lemma: "thin layer", semanticClass: "amount_style", conceptId: "thin_layer" },
6130
+ { surface: "thin layer", lemma: "thin layer", semanticClass: "amount_style", conceptId: "thin_layer" },
6131
+ { surface: "thin film", lemma: "thin layer", semanticClass: "amount_style", conceptId: "thin_layer" },
6132
+ { surface: "thin coat", lemma: "thin layer", semanticClass: "amount_style", conceptId: "thin_layer" },
6133
+ { surface: "thickly", lemma: "thick layer", semanticClass: "amount_style", conceptId: "thick_layer" },
6134
+ { surface: "thick layer", lemma: "thick layer", semanticClass: "amount_style", conceptId: "thick_layer" },
6135
+ { surface: "thick coat", lemma: "thick layer", semanticClass: "amount_style", conceptId: "thick_layer" },
6136
+ { surface: "gently", lemma: "gently", semanticClass: "manner_style", conceptId: "gently" },
5931
6137
  { surface: "slowly", lemma: "slowly", semanticClass: "manner_style", conceptId: "slowly" }
5932
6138
  ]
5933
6139
  };
@@ -6549,7 +6755,124 @@ var advice_rules_default = {
6549
6755
  normalizedTexts: [
6550
6756
  "liberally",
6551
6757
  "apply liberally",
6552
- "use liberally"
6758
+ "use liberally",
6759
+ "liberal amount",
6760
+ "a liberal amount",
6761
+ "apply liberal amount",
6762
+ "apply a liberal amount",
6763
+ "use liberal amount",
6764
+ "use a liberal amount",
6765
+ "generous amount",
6766
+ "a generous amount",
6767
+ "apply generous amount",
6768
+ "apply a generous amount",
6769
+ "use generous amount",
6770
+ "use a generous amount"
6771
+ ]
6772
+ }
6773
+ },
6774
+ {
6775
+ id: "thin-layer",
6776
+ definition: {
6777
+ code: "420162004",
6778
+ display: "To be spread thinly",
6779
+ text: "Apply thinly",
6780
+ thai: "\u0E17\u0E32\u0E1A\u0E32\u0E07\u0E46"
6781
+ },
6782
+ frames: [
6783
+ {
6784
+ force: "instruction",
6785
+ predicate: { lemma: "apply", semanticClass: "administration" },
6786
+ args: [{ role: "amount", text: "thin layer", conceptId: "thin_layer" }]
6787
+ }
6788
+ ],
6789
+ matcher: {
6790
+ normalizedTexts: [
6791
+ "thinly",
6792
+ "apply thinly",
6793
+ "use thinly",
6794
+ "thin layer",
6795
+ "a thin layer",
6796
+ "apply thin layer",
6797
+ "apply a thin layer",
6798
+ "use thin layer",
6799
+ "use a thin layer",
6800
+ "thin film",
6801
+ "a thin film",
6802
+ "apply thin film",
6803
+ "apply a thin film",
6804
+ "thin coat",
6805
+ "a thin coat",
6806
+ "apply thin coat",
6807
+ "apply a thin coat",
6808
+ "\u0E17\u0E32\u0E1A\u0E32\u0E07\u0E46",
6809
+ "\u0E17\u0E32\u0E1A\u0E32\u0E07 \u0E46",
6810
+ "\u0E1A\u0E32\u0E07\u0E46",
6811
+ "\u0E1A\u0E32\u0E07 \u0E46"
6812
+ ]
6813
+ }
6814
+ },
6815
+ {
6816
+ id: "gently",
6817
+ definition: {
6818
+ code: "418449005",
6819
+ display: "Gently",
6820
+ text: "Apply gently",
6821
+ thai: "\u0E17\u0E32\u0E40\u0E1A\u0E32\u0E46"
6822
+ },
6823
+ frames: [
6824
+ {
6825
+ force: "instruction",
6826
+ predicate: { lemma: "apply", semanticClass: "administration" },
6827
+ args: [{ role: "free", text: "gently", conceptId: "gently" }]
6828
+ }
6829
+ ],
6830
+ matcher: {
6831
+ normalizedTexts: [
6832
+ "gently",
6833
+ "apply gently",
6834
+ "use gently",
6835
+ "\u0E40\u0E1A\u0E32\u0E46",
6836
+ "\u0E40\u0E1A\u0E32 \u0E46",
6837
+ "\u0E17\u0E32\u0E40\u0E1A\u0E32\u0E46",
6838
+ "\u0E17\u0E32\u0E40\u0E1A\u0E32 \u0E46"
6839
+ ]
6840
+ }
6841
+ },
6842
+ {
6843
+ id: "thick-layer",
6844
+ definition: {
6845
+ code: "246703001",
6846
+ display: "Thick",
6847
+ text: "Apply thickly",
6848
+ thai: "\u0E17\u0E32\u0E2B\u0E19\u0E32\u0E46"
6849
+ },
6850
+ frames: [
6851
+ {
6852
+ force: "instruction",
6853
+ predicate: { lemma: "apply", semanticClass: "administration" },
6854
+ args: [{ role: "amount", text: "thick layer", conceptId: "thick_layer" }]
6855
+ }
6856
+ ],
6857
+ matcher: {
6858
+ normalizedTexts: [
6859
+ "thickly",
6860
+ "apply thickly",
6861
+ "use thickly",
6862
+ "thick layer",
6863
+ "a thick layer",
6864
+ "apply thick layer",
6865
+ "apply a thick layer",
6866
+ "use thick layer",
6867
+ "use a thick layer",
6868
+ "thick coat",
6869
+ "a thick coat",
6870
+ "apply thick coat",
6871
+ "apply a thick coat",
6872
+ "\u0E17\u0E32\u0E2B\u0E19\u0E32\u0E46",
6873
+ "\u0E17\u0E32\u0E2B\u0E19\u0E32 \u0E46",
6874
+ "\u0E2B\u0E19\u0E32\u0E46",
6875
+ "\u0E2B\u0E19\u0E32 \u0E46"
6553
6876
  ]
6554
6877
  }
6555
6878
  },
@@ -6787,7 +7110,8 @@ var PER_SLASH_UNITS = /* @__PURE__ */ new Set([
6787
7110
  "minute",
6788
7111
  "minutes"
6789
7112
  ]);
6790
- var COMPACT_DISCRETE_UNITS_PATTERN = /^(tab|tabs|tablet|tablets|cap|caps|capsule|capsules|mg|mcg|ml|g|drops|drop|puff|puffs|spray|sprays|patch|patches)$/i;
7113
+ var COMPACT_DISCRETE_UNITS_PATTERN = /^(tab|tabs|tablet|tablets|cap|caps|capsule|capsules|mg|mcg|ml|g|drops|drop|gtt|gtts|eyedrop|eyedrops|puff|puffs|spray|sprays|pump|pumps|ftu|ftus|patch|patches|ring|rings|tube|tubes|bottle|bottles|container|containers|palm|palms|handprint|handprints|click|clicks|vial|vials|ampule|ampules|packet|packets|sachet|sachets|stick-pack|stick-packs|pea-sized)$/i;
7114
+ var COMPACT_DISCRETE_UNIT_SUFFIX_PATTERN = /^[A-Za-z-]+$/;
6791
7115
  function classifyLexKind(value) {
6792
7116
  const lower = value.toLowerCase();
6793
7117
  if (/^[0-9]+(?:\.[0-9]+)?$/.test(lower)) {
@@ -6923,7 +7247,7 @@ function splitCompactToken(token) {
6923
7247
  if (/^[0-9]+(?:\.[0-9]+)?$/.test(token)) {
6924
7248
  return [token];
6925
7249
  }
6926
- const compactTimesWord = token.match(/^([0-9]+(?:\.[0-9]+)?[x*])([A-Za-z]+)$/i);
7250
+ const compactTimesWord = token.match(/^([0-9]+(?:\.[0-9]+)?[x*])([A-Za-z-]+)$/i);
6927
7251
  if (compactTimesWord) {
6928
7252
  return [compactTimesWord[1], compactTimesWord[2]];
6929
7253
  }
@@ -6934,11 +7258,11 @@ function splitCompactToken(token) {
6934
7258
  if (/^[A-Za-z]+$/.test(token)) {
6935
7259
  return [token];
6936
7260
  }
6937
- const qRange = token.match(/^q([0-9]+(?:\.[0-9]+)?)-([0-9]+(?:\.[0-9]+)?)([A-Za-z]+)$/i);
7261
+ const qRange = token.match(/^q([0-9]+(?:\.[0-9]+)?)-([0-9]+(?:\.[0-9]+)?)([A-Za-z-]+)$/i);
6938
7262
  if (qRange) {
6939
7263
  return [token.charAt(0), `${qRange[1]}-${qRange[2]}`, qRange[3]];
6940
7264
  }
6941
- const match = token.match(/^([0-9]+(?:\.[0-9]+)?)([A-Za-z]+)$/);
7265
+ const match = token.match(/^([0-9]+(?:\.[0-9]+)?)([A-Za-z-]+)$/);
6942
7266
  if (match) {
6943
7267
  const [, numberPart, suffix] = match;
6944
7268
  if (/^(st|nd|rd|th)$/i.test(suffix)) {
@@ -7115,9 +7439,9 @@ function pushTextToken(output, surface, input) {
7115
7439
  }
7116
7440
  }
7117
7441
  const compactDiscrete = surface.original.match(
7118
- /^([0-9]+(?:\.[0-9]+)?)([A-Za-z]+)$/
7442
+ /^([0-9]+(?:\.[0-9]+)?)([A-Za-z-]+)$/
7119
7443
  );
7120
- if (compactDiscrete && COMPACT_DISCRETE_UNITS_PATTERN.test(compactDiscrete[2])) {
7444
+ if (compactDiscrete && COMPACT_DISCRETE_UNIT_SUFFIX_PATTERN.test(compactDiscrete[2]) && COMPACT_DISCRETE_UNITS_PATTERN.test(compactDiscrete[2])) {
7121
7445
  pushSplitParts(output, surface, [compactDiscrete[1], compactDiscrete[2]], input);
7122
7446
  return;
7123
7447
  }
@@ -7336,9 +7660,11 @@ function cleanFreeText(value) {
7336
7660
  return collapseWhitespace(value.slice(start, end));
7337
7661
  }
7338
7662
  function createDefinitionFromSource(source) {
7663
+ var _a2;
7664
+ const system = ((_a2 = source.system) == null ? void 0 : _a2.trim()) || SNOMED_SYSTEM4;
7339
7665
  return {
7340
7666
  coding: {
7341
- system: SNOMED_SYSTEM4,
7667
+ system,
7342
7668
  code: source.code,
7343
7669
  display: source.display
7344
7670
  },
@@ -7642,9 +7968,9 @@ function matchesAdviceMatcher(frames, normalizedText, matcher) {
7642
7968
  return false;
7643
7969
  }
7644
7970
  function findRuleByCoding(system, code) {
7645
- var _a, _b;
7971
+ var _a2, _b;
7646
7972
  for (const rule of ADDITIONAL_INSTRUCTION_RULES) {
7647
- if (((_a = rule.definition.coding) == null ? void 0 : _a.system) !== system) {
7973
+ if (((_a2 = rule.definition.coding) == null ? void 0 : _a2.system) !== system) {
7648
7974
  continue;
7649
7975
  }
7650
7976
  if (((_b = rule.definition.coding) == null ? void 0 : _b.code) !== code) {
@@ -7757,8 +8083,8 @@ function findVerbLexeme(word) {
7757
8083
  return findNormalizedLexeme(word, "verb");
7758
8084
  }
7759
8085
  function findVerbLemma(word) {
7760
- var _a;
7761
- return (_a = findVerbLexeme(word)) == null ? void 0 : _a.lemma;
8086
+ var _a2;
8087
+ return (_a2 = findVerbLexeme(word)) == null ? void 0 : _a2.lemma;
7762
8088
  }
7763
8089
  function findModalLexeme(word) {
7764
8090
  const entry = findNormalizedLexeme(word, "modifier");
@@ -7870,7 +8196,7 @@ function parseLeadingClauseFeatures(words) {
7870
8196
  };
7871
8197
  }
7872
8198
  function deriveClauseForce(sequenceCount, context, predicateLemma, predicateSemanticClass, polarity, modality) {
7873
- var _a;
8199
+ var _a2;
7874
8200
  if (sequenceCount > 1) {
7875
8201
  return "sequence" /* Sequence */;
7876
8202
  }
@@ -7903,7 +8229,7 @@ function deriveClauseForce(sequenceCount, context, predicateLemma, predicateSema
7903
8229
  default:
7904
8230
  break;
7905
8231
  }
7906
- return (_a = context.defaultForce) != null ? _a : "instruction" /* Instruction */;
8232
+ return (_a2 = context.defaultForce) != null ? _a2 : "instruction" /* Instruction */;
7907
8233
  }
7908
8234
  function containsNegatedVerb(words, lemma) {
7909
8235
  for (let index = 0; index < words.length; index += 1) {
@@ -8172,11 +8498,11 @@ function skipLeadingNoise(words) {
8172
8498
  return cursor;
8173
8499
  }
8174
8500
  function createDefaultForce(sequenceCount, sequenceIndex, context) {
8175
- var _a;
8501
+ var _a2;
8176
8502
  if (sequenceCount > 1 || sequenceIndex > 0) {
8177
8503
  return "sequence" /* Sequence */;
8178
8504
  }
8179
- return (_a = context.defaultForce) != null ? _a : "instruction" /* Instruction */;
8505
+ return (_a2 = context.defaultForce) != null ? _a2 : "instruction" /* Instruction */;
8180
8506
  }
8181
8507
  function tryParseRelationInstruction(sourceText, span, context, sequenceIndex, sequenceCount) {
8182
8508
  const words = normalizeWords(sourceText);
@@ -8541,7 +8867,7 @@ function tryParseClauseInstruction(sourceText, span, context, sequenceIndex, seq
8541
8867
  return frames;
8542
8868
  }
8543
8869
  function parseSequenceFrames(sourceText, span, context) {
8544
- var _a, _b, _c, _d, _e;
8870
+ var _a2, _b, _c, _d, _e;
8545
8871
  const sequenceSegments = splitSequenceSegments(sourceText, span);
8546
8872
  if (!sequenceSegments.length) {
8547
8873
  return [];
@@ -8549,7 +8875,7 @@ function parseSequenceFrames(sourceText, span, context) {
8549
8875
  const frames = [];
8550
8876
  for (let index = 0; index < sequenceSegments.length; index++) {
8551
8877
  const segment = sequenceSegments[index];
8552
- const parsed = (_e = (_d = (_c = (_b = (_a = tryParseRelationInstruction(segment.text, segment.range, context, index, sequenceSegments.length)) != null ? _a : tryParseImplicitConceptInstruction(segment.text, segment.range, context, index, sequenceSegments.length)) != null ? _b : tryParseStyleInstruction(segment.text, segment.range, context, index, sequenceSegments.length)) != null ? _c : tryParseNoObjectInstruction(segment.text, segment.range, index, sequenceSegments.length)) != null ? _d : tryParseEllipticalEffectInstruction(
8878
+ const parsed = (_e = (_d = (_c = (_b = (_a2 = tryParseRelationInstruction(segment.text, segment.range, context, index, sequenceSegments.length)) != null ? _a2 : tryParseImplicitConceptInstruction(segment.text, segment.range, context, index, sequenceSegments.length)) != null ? _b : tryParseStyleInstruction(segment.text, segment.range, context, index, sequenceSegments.length)) != null ? _c : tryParseNoObjectInstruction(segment.text, segment.range, index, sequenceSegments.length)) != null ? _d : tryParseEllipticalEffectInstruction(
8553
8879
  segment.text,
8554
8880
  segment.range,
8555
8881
  context,
@@ -8675,9 +9001,9 @@ function realizeAdviceFramesText(frames) {
8675
9001
  return realized ? capitalizeSentence(realized) : void 0;
8676
9002
  }
8677
9003
  function parseAdditionalInstructions(sourceText, span, context) {
8678
- var _a, _b, _c, _d, _e;
9004
+ var _a2, _b, _c, _d, _e;
8679
9005
  const effectiveContext = {
8680
- defaultPredicate: (_a = context == null ? void 0 : context.defaultPredicate) != null ? _a : DEFAULT_INSTRUCTION_CONTEXT.defaultPredicate,
9006
+ defaultPredicate: (_a2 = context == null ? void 0 : context.defaultPredicate) != null ? _a2 : DEFAULT_INSTRUCTION_CONTEXT.defaultPredicate,
8681
9007
  defaultForce: (_b = context == null ? void 0 : context.defaultForce) != null ? _b : DEFAULT_INSTRUCTION_CONTEXT.defaultForce,
8682
9008
  allowFreeTextFallback: (_c = context == null ? void 0 : context.allowFreeTextFallback) != null ? _c : DEFAULT_INSTRUCTION_CONTEXT.allowFreeTextFallback
8683
9009
  };
@@ -8711,16 +9037,16 @@ function parseAdditionalInstructions(sourceText, span, context) {
8711
9037
  return instructions;
8712
9038
  }
8713
9039
  function findAdditionalInstructionDefinitionByCoding(system, code) {
8714
- var _a;
8715
- return (_a = findRuleByCoding(system, code)) == null ? void 0 : _a.definition;
9040
+ var _a2;
9041
+ return (_a2 = findRuleByCoding(system, code)) == null ? void 0 : _a2.definition;
8716
9042
  }
8717
9043
  function buildAdditionalInstructionFramesFromCoding(system, code, sourceText, span) {
8718
- var _a, _b, _c;
9044
+ var _a2, _b, _c;
8719
9045
  const rule = findRuleByCoding(system, code);
8720
9046
  if (!rule) {
8721
9047
  return void 0;
8722
9048
  }
8723
- const resolvedText = (_c = (_b = sourceText != null ? sourceText : rule.definition.text) != null ? _b : (_a = rule.definition.coding) == null ? void 0 : _a.display) != null ? _c : "";
9049
+ const resolvedText = (_c = (_b = sourceText != null ? sourceText : rule.definition.text) != null ? _b : (_a2 = rule.definition.coding) == null ? void 0 : _a2.display) != null ? _c : "";
8724
9050
  const resolvedSpan = span != null ? span : { start: 0, end: resolvedText.length };
8725
9051
  return instantiateTemplateFrames(rule.frames, resolvedText, resolvedSpan);
8726
9052
  }
@@ -8784,12 +9110,12 @@ function pluralizeBodySiteText(text) {
8784
9110
  return `${normalized}s`;
8785
9111
  }
8786
9112
  function toBodySiteCode(coding) {
8787
- var _a;
9113
+ var _a2;
8788
9114
  if (!(coding == null ? void 0 : coding.code)) {
8789
9115
  return void 0;
8790
9116
  }
8791
9117
  return {
8792
- system: (_a = coding.system) != null ? _a : SNOMED_SYSTEM,
9118
+ system: (_a2 = coding.system) != null ? _a2 : SNOMED_SYSTEM,
8793
9119
  code: coding.code,
8794
9120
  display: coding.display,
8795
9121
  i18n: "i18n" in coding ? coding.i18n : void 0
@@ -8809,11 +9135,11 @@ function resultFromResolved(resolved, matchedText, score) {
8809
9135
  };
8810
9136
  }
8811
9137
  function bodySiteLookupRequest(input, resolved, options) {
8812
- var _a, _b;
9138
+ var _a2, _b;
8813
9139
  const normalized = normalizeBodySiteKey(input);
8814
9140
  return {
8815
9141
  originalText: input,
8816
- text: (_a = resolved == null ? void 0 : resolved.displayText) != null ? _a : input.trim(),
9142
+ text: (_a2 = resolved == null ? void 0 : resolved.displayText) != null ? _a2 : input.trim(),
8817
9143
  normalized,
8818
9144
  canonical: (_b = resolved == null ? void 0 : resolved.canonical) != null ? _b : normalized,
8819
9145
  bodySiteContext: options == null ? void 0 : options.bodySiteContext,
@@ -8821,18 +9147,18 @@ function bodySiteLookupRequest(input, resolved, options) {
8821
9147
  };
8822
9148
  }
8823
9149
  function applyResolverDefinition(result, definition) {
8824
- var _a, _b;
9150
+ var _a2, _b;
8825
9151
  return __spreadProps(__spreadValues({}, result), {
8826
- text: (_a = definition.text) != null ? _a : result.text,
9152
+ text: (_a2 = definition.text) != null ? _a2 : result.text,
8827
9153
  coding: toBodySiteCode(definition.coding),
8828
9154
  spatialRelation: (_b = definition.spatialRelation) != null ? _b : result.spatialRelation,
8829
9155
  definition
8830
9156
  });
8831
9157
  }
8832
9158
  function resultFromResolverDefinition(input, definition) {
8833
- var _a;
9159
+ var _a2;
8834
9160
  const normalized = normalizeBodySiteKey(input);
8835
- const text = (_a = definition.text) != null ? _a : normalized;
9161
+ const text = (_a2 = definition.text) != null ? _a2 : normalized;
8836
9162
  return {
8837
9163
  text,
8838
9164
  canonical: normalizeBodySiteKey(text),
@@ -8888,12 +9214,12 @@ function addCandidate(candidates, phrase, definition) {
8888
9214
  candidates.push({ phrase: normalized, definition });
8889
9215
  }
8890
9216
  function addDefinitionCandidates(candidates, definition) {
8891
- var _a;
9217
+ var _a2;
8892
9218
  if (!definition) {
8893
9219
  return;
8894
9220
  }
8895
9221
  addCandidate(candidates, definition.text, definition);
8896
- for (const alias of (_a = definition.aliases) != null ? _a : []) {
9222
+ for (const alias of (_a2 = definition.aliases) != null ? _a2 : []) {
8897
9223
  addCandidate(candidates, alias, definition);
8898
9224
  }
8899
9225
  }
@@ -8914,21 +9240,21 @@ function collectBodySiteCandidates(siteCodeMap) {
8914
9240
  return candidates;
8915
9241
  }
8916
9242
  function codeFromInput(input, options) {
8917
- var _a;
9243
+ var _a2;
8918
9244
  if (typeof input === "string") {
8919
9245
  const normalized = input.trim();
8920
- return normalized ? { code: normalized, system: (_a = options == null ? void 0 : options.system) != null ? _a : SNOMED_SYSTEM } : void 0;
9246
+ return normalized ? { code: normalized, system: (_a2 = options == null ? void 0 : options.system) != null ? _a2 : SNOMED_SYSTEM } : void 0;
8921
9247
  }
8922
9248
  return toBodySiteCode(input);
8923
9249
  }
8924
9250
  function bodySiteCodeFromInput(input, options) {
8925
- var _a, _b;
9251
+ var _a2, _b;
8926
9252
  const coding = codeFromInput(input, options);
8927
9253
  const shouldParsePostcoordination = (options == null ? void 0 : options.postcoordination) !== false && (options == null ? void 0 : options.parsePostcoordination) !== false;
8928
9254
  const parsedTopographicalModifier = shouldParsePostcoordination ? parseSnomedBodySiteTopographicalModifierPostcoordinationCode(coding == null ? void 0 : coding.code) : void 0;
8929
9255
  if (parsedTopographicalModifier) {
8930
9256
  return {
8931
- system: (_a = coding == null ? void 0 : coding.system) != null ? _a : SNOMED_SYSTEM,
9257
+ system: (_a2 = coding == null ? void 0 : coding.system) != null ? _a2 : SNOMED_SYSTEM,
8932
9258
  code: parsedTopographicalModifier.siteCode
8933
9259
  };
8934
9260
  }
@@ -8956,24 +9282,24 @@ function parsedPostcoordinationForInput(input, options) {
8956
9282
  };
8957
9283
  }
8958
9284
  function findBodySiteTextByCode(coding, siteCodeMap) {
8959
- var _a;
9285
+ var _a2;
8960
9286
  for (const candidate of collectBodySiteCandidates(siteCodeMap)) {
8961
- if (codeMatches(coding, (_a = candidate.definition) == null ? void 0 : _a.coding)) {
9287
+ if (codeMatches(coding, (_a2 = candidate.definition) == null ? void 0 : _a2.coding)) {
8962
9288
  return definitionText(candidate.phrase, candidate.definition);
8963
9289
  }
8964
9290
  }
8965
9291
  return void 0;
8966
9292
  }
8967
9293
  function definitionText(phrase, definition) {
8968
- var _a;
8969
- return (_a = definition == null ? void 0 : definition.text) != null ? _a : normalizeBodySiteKey(phrase);
9294
+ var _a2;
9295
+ return (_a2 = definition == null ? void 0 : definition.text) != null ? _a2 : normalizeBodySiteKey(phrase);
8970
9296
  }
8971
9297
  function codeMatches(left, right) {
8972
- var _a, _b;
9298
+ var _a2, _b;
8973
9299
  if (!(right == null ? void 0 : right.code)) {
8974
9300
  return false;
8975
9301
  }
8976
- const leftSystem = (_a = left.system) != null ? _a : SNOMED_SYSTEM;
9302
+ const leftSystem = (_a2 = left.system) != null ? _a2 : SNOMED_SYSTEM;
8977
9303
  const rightSystem = (_b = right.system) != null ? _b : SNOMED_SYSTEM;
8978
9304
  return left.code === right.code && leftSystem === rightSystem;
8979
9305
  }
@@ -9055,11 +9381,11 @@ function scoreCandidate(query, candidate) {
9055
9381
  return 0;
9056
9382
  }
9057
9383
  function spatialRelationKey(relation) {
9058
- var _a, _b, _c, _d, _e;
9384
+ var _a2, _b, _c, _d, _e;
9059
9385
  if (!relation) {
9060
9386
  return "";
9061
9387
  }
9062
- const relationCode = (_b = (_a = relation.relationCoding) == null ? void 0 : _a.code) != null ? _b : "";
9388
+ const relationCode = (_b = (_a2 = relation.relationCoding) == null ? void 0 : _a2.code) != null ? _b : "";
9063
9389
  const targetCode = (_d = (_c = relation.targetCoding) == null ? void 0 : _c.code) != null ? _d : "";
9064
9390
  return [
9065
9391
  relation.relationText,
@@ -9069,9 +9395,9 @@ function spatialRelationKey(relation) {
9069
9395
  ].join("|");
9070
9396
  }
9071
9397
  function resultKey(result) {
9072
- var _a, _b;
9398
+ var _a2, _b;
9073
9399
  const relation = spatialRelationKey(result.spatialRelation);
9074
- if ((_a = result.coding) == null ? void 0 : _a.code) {
9400
+ if ((_a2 = result.coding) == null ? void 0 : _a2.code) {
9075
9401
  return `${(_b = result.coding.system) != null ? _b : SNOMED_SYSTEM}|${result.coding.code}|${relation}`;
9076
9402
  }
9077
9403
  return `${result.canonical}|${relation}`;
@@ -9102,16 +9428,16 @@ function sortedSetValues(values) {
9102
9428
  return Array.from(values).sort((left, right) => left.localeCompare(right));
9103
9429
  }
9104
9430
  function canBuildTopographicalModifierPostcoordination(relation) {
9105
- var _a, _b;
9106
- if (!((_a = relation == null ? void 0 : relation.relationCoding) == null ? void 0 : _a.code) || !((_b = relation.targetCoding) == null ? void 0 : _b.code)) {
9431
+ var _a2, _b;
9432
+ if (!((_a2 = relation == null ? void 0 : relation.relationCoding) == null ? void 0 : _a2.code) || !((_b = relation.targetCoding) == null ? void 0 : _b.code)) {
9107
9433
  return false;
9108
9434
  }
9109
9435
  return POSTCOORDINATABLE_RELATION_TEXTS.has(normalizeBodySiteKey(relation.relationText)) || POSTCOORDINATABLE_RELATION_CODES.has(relation.relationCoding.code);
9110
9436
  }
9111
9437
  function buildSpatialRelationDisplayText(relation) {
9112
- var _a;
9438
+ var _a2;
9113
9439
  const relationText = normalizeBodySiteKey(relation.relationText);
9114
- const targetText = normalizeBodySiteKey((_a = relation.targetText) != null ? _a : "");
9440
+ const targetText = normalizeBodySiteKey((_a2 = relation.targetText) != null ? _a2 : "");
9115
9441
  if (!relationText || !targetText) {
9116
9442
  return void 0;
9117
9443
  }
@@ -9132,14 +9458,14 @@ function buildSpatialRelationDisplayText(relation) {
9132
9458
  }
9133
9459
  }
9134
9460
  function buildBodySiteTopographicalModifierCoding(relation, display, options) {
9135
- var _a, _b;
9461
+ var _a2, _b;
9136
9462
  if ((options == null ? void 0 : options.postcoordination) === false) {
9137
9463
  return void 0;
9138
9464
  }
9139
9465
  if (!canBuildTopographicalModifierPostcoordination(relation)) {
9140
9466
  return void 0;
9141
9467
  }
9142
- const targetSystem = (_a = relation.targetCoding.system) != null ? _a : SNOMED_SYSTEM;
9468
+ const targetSystem = (_a2 = relation.targetCoding.system) != null ? _a2 : SNOMED_SYSTEM;
9143
9469
  const relationSystem = (_b = relation.relationCoding.system) != null ? _b : SNOMED_SYSTEM;
9144
9470
  if (targetSystem !== SNOMED_SYSTEM || relationSystem !== SNOMED_SYSTEM) {
9145
9471
  return void 0;
@@ -9172,12 +9498,12 @@ function lookupBodySiteAsync(input, options) {
9172
9498
  });
9173
9499
  }
9174
9500
  function getBodySiteCode(input, options) {
9175
- var _a;
9501
+ var _a2;
9176
9502
  const resolved = lookupBodySite(input, options);
9177
9503
  if (!resolved) {
9178
9504
  return void 0;
9179
9505
  }
9180
- return (_a = resolved.coding) != null ? _a : buildBodySiteTopographicalModifierCoding(
9506
+ return (_a2 = resolved.coding) != null ? _a2 : buildBodySiteTopographicalModifierCoding(
9181
9507
  resolved.spatialRelation,
9182
9508
  resolved.text,
9183
9509
  options
@@ -9185,12 +9511,12 @@ function getBodySiteCode(input, options) {
9185
9511
  }
9186
9512
  function getBodySiteCodeAsync(input, options) {
9187
9513
  return __async(this, null, function* () {
9188
- var _a;
9514
+ var _a2;
9189
9515
  const resolved = yield lookupBodySiteAsync(input, options);
9190
9516
  if (!resolved) {
9191
9517
  return void 0;
9192
9518
  }
9193
- return (_a = resolved.coding) != null ? _a : buildBodySiteTopographicalModifierCoding(
9519
+ return (_a2 = resolved.coding) != null ? _a2 : buildBodySiteTopographicalModifierCoding(
9194
9520
  resolved.spatialRelation,
9195
9521
  resolved.text,
9196
9522
  options
@@ -9198,7 +9524,7 @@ function getBodySiteCodeAsync(input, options) {
9198
9524
  });
9199
9525
  }
9200
9526
  function getBodySiteText(input, options) {
9201
- var _a;
9527
+ var _a2;
9202
9528
  const originalCoding = codeFromInput(input, options);
9203
9529
  const coding = bodySiteCodeFromInput(input, options);
9204
9530
  if (!coding) {
@@ -9224,7 +9550,7 @@ function getBodySiteText(input, options) {
9224
9550
  if (!text && parsed.laterality) {
9225
9551
  const baseText = findBodySiteTextByCode(
9226
9552
  {
9227
- system: (_a = originalCoding == null ? void 0 : originalCoding.system) != null ? _a : SNOMED_SYSTEM,
9553
+ system: (_a2 = originalCoding == null ? void 0 : originalCoding.system) != null ? _a2 : SNOMED_SYSTEM,
9228
9554
  code: parsed.laterality.siteCode
9229
9555
  },
9230
9556
  options == null ? void 0 : options.siteCodeMap
@@ -9271,12 +9597,12 @@ function getBodySiteTextAsync(input, options) {
9271
9597
  });
9272
9598
  }
9273
9599
  function suggestBodySites(input, options) {
9274
- var _a;
9600
+ var _a2;
9275
9601
  const query = normalizeBodySiteKey(input);
9276
9602
  if (!query) {
9277
9603
  return [];
9278
9604
  }
9279
- const limit = (_a = options == null ? void 0 : options.limit) != null ? _a : 10;
9605
+ const limit = (_a2 = options == null ? void 0 : options.limit) != null ? _a2 : 10;
9280
9606
  if (limit <= 0) {
9281
9607
  return [];
9282
9608
  }
@@ -9305,8 +9631,8 @@ function suggestBodySiteText(input, options) {
9305
9631
  return uniqueText(suggestBodySites(input, options));
9306
9632
  }
9307
9633
  function listSupportedBodySiteText(options) {
9308
- var _a;
9309
- const limit = (_a = options == null ? void 0 : options.limit) != null ? _a : Number.POSITIVE_INFINITY;
9634
+ var _a2;
9635
+ const limit = (_a2 = options == null ? void 0 : options.limit) != null ? _a2 : Number.POSITIVE_INFINITY;
9310
9636
  if (limit <= 0) {
9311
9637
  return [];
9312
9638
  }
@@ -9377,43 +9703,43 @@ var ParserState = class {
9377
9703
  return this.clause;
9378
9704
  }
9379
9705
  get dose() {
9380
- var _a;
9381
- return (_a = this.clause.dose) == null ? void 0 : _a.value;
9706
+ var _a2;
9707
+ return (_a2 = this.clause.dose) == null ? void 0 : _a2.value;
9382
9708
  }
9383
9709
  set dose(value) {
9384
9710
  this.ensureDose().value = value;
9385
9711
  }
9386
9712
  get doseRange() {
9387
- var _a;
9388
- return (_a = this.clause.dose) == null ? void 0 : _a.range;
9713
+ var _a2;
9714
+ return (_a2 = this.clause.dose) == null ? void 0 : _a2.range;
9389
9715
  }
9390
9716
  set doseRange(value) {
9391
9717
  this.ensureDose().range = value;
9392
9718
  }
9393
9719
  get unit() {
9394
- var _a;
9395
- return (_a = this.clause.dose) == null ? void 0 : _a.unit;
9720
+ var _a2;
9721
+ return (_a2 = this.clause.dose) == null ? void 0 : _a2.unit;
9396
9722
  }
9397
9723
  set unit(value) {
9398
9724
  this.ensureDose().unit = value;
9399
9725
  }
9400
9726
  get routeCode() {
9401
- var _a;
9402
- return (_a = this.clause.route) == null ? void 0 : _a.code;
9727
+ var _a2;
9728
+ return (_a2 = this.clause.route) == null ? void 0 : _a2.code;
9403
9729
  }
9404
9730
  set routeCode(value) {
9405
9731
  this.ensureRoute().code = value;
9406
9732
  }
9407
9733
  get routeText() {
9408
- var _a;
9409
- return (_a = this.clause.route) == null ? void 0 : _a.text;
9734
+ var _a2;
9735
+ return (_a2 = this.clause.route) == null ? void 0 : _a2.text;
9410
9736
  }
9411
9737
  set routeText(value) {
9412
9738
  this.ensureRoute().text = value;
9413
9739
  }
9414
9740
  get methodText() {
9415
- var _a;
9416
- return (_a = this.clause.method) == null ? void 0 : _a.text;
9741
+ var _a2;
9742
+ return (_a2 = this.clause.method) == null ? void 0 : _a2.text;
9417
9743
  }
9418
9744
  set methodText(value) {
9419
9745
  if (value === void 0) {
@@ -9426,8 +9752,8 @@ var ParserState = class {
9426
9752
  this.ensureMethod().text = value;
9427
9753
  }
9428
9754
  get methodTextElement() {
9429
- var _a;
9430
- return (_a = this.clause.method) == null ? void 0 : _a._text;
9755
+ var _a2;
9756
+ return (_a2 = this.clause.method) == null ? void 0 : _a2._text;
9431
9757
  }
9432
9758
  set methodTextElement(value) {
9433
9759
  if (value === void 0) {
@@ -9440,8 +9766,8 @@ var ParserState = class {
9440
9766
  this.ensureMethod()._text = clonePrimitiveElement(value);
9441
9767
  }
9442
9768
  get methodCoding() {
9443
- var _a;
9444
- return (_a = this.clause.method) == null ? void 0 : _a.coding;
9769
+ var _a2;
9770
+ return (_a2 = this.clause.method) == null ? void 0 : _a2.coding;
9445
9771
  }
9446
9772
  set methodCoding(value) {
9447
9773
  if (value === void 0) {
@@ -9460,64 +9786,64 @@ var ParserState = class {
9460
9786
  } : void 0;
9461
9787
  }
9462
9788
  get count() {
9463
- var _a;
9464
- return (_a = this.clause.schedule) == null ? void 0 : _a.count;
9789
+ var _a2;
9790
+ return (_a2 = this.clause.schedule) == null ? void 0 : _a2.count;
9465
9791
  }
9466
9792
  set count(value) {
9467
9793
  this.ensureSchedule().count = value;
9468
9794
  }
9469
9795
  get duration() {
9470
- var _a;
9471
- return (_a = this.clause.schedule) == null ? void 0 : _a.duration;
9796
+ var _a2;
9797
+ return (_a2 = this.clause.schedule) == null ? void 0 : _a2.duration;
9472
9798
  }
9473
9799
  set duration(value) {
9474
9800
  this.ensureSchedule().duration = value;
9475
9801
  }
9476
9802
  get durationMax() {
9477
- var _a;
9478
- return (_a = this.clause.schedule) == null ? void 0 : _a.durationMax;
9803
+ var _a2;
9804
+ return (_a2 = this.clause.schedule) == null ? void 0 : _a2.durationMax;
9479
9805
  }
9480
9806
  set durationMax(value) {
9481
9807
  this.ensureSchedule().durationMax = value;
9482
9808
  }
9483
9809
  get durationUnit() {
9484
- var _a;
9485
- return (_a = this.clause.schedule) == null ? void 0 : _a.durationUnit;
9810
+ var _a2;
9811
+ return (_a2 = this.clause.schedule) == null ? void 0 : _a2.durationUnit;
9486
9812
  }
9487
9813
  set durationUnit(value) {
9488
9814
  this.ensureSchedule().durationUnit = value;
9489
9815
  }
9490
9816
  get frequency() {
9491
- var _a;
9492
- return (_a = this.clause.schedule) == null ? void 0 : _a.frequency;
9817
+ var _a2;
9818
+ return (_a2 = this.clause.schedule) == null ? void 0 : _a2.frequency;
9493
9819
  }
9494
9820
  set frequency(value) {
9495
9821
  this.ensureSchedule().frequency = value;
9496
9822
  }
9497
9823
  get frequencyMax() {
9498
- var _a;
9499
- return (_a = this.clause.schedule) == null ? void 0 : _a.frequencyMax;
9824
+ var _a2;
9825
+ return (_a2 = this.clause.schedule) == null ? void 0 : _a2.frequencyMax;
9500
9826
  }
9501
9827
  set frequencyMax(value) {
9502
9828
  this.ensureSchedule().frequencyMax = value;
9503
9829
  }
9504
9830
  get period() {
9505
- var _a;
9506
- return (_a = this.clause.schedule) == null ? void 0 : _a.period;
9831
+ var _a2;
9832
+ return (_a2 = this.clause.schedule) == null ? void 0 : _a2.period;
9507
9833
  }
9508
9834
  set period(value) {
9509
9835
  this.ensureSchedule().period = value;
9510
9836
  }
9511
9837
  get periodMax() {
9512
- var _a;
9513
- return (_a = this.clause.schedule) == null ? void 0 : _a.periodMax;
9838
+ var _a2;
9839
+ return (_a2 = this.clause.schedule) == null ? void 0 : _a2.periodMax;
9514
9840
  }
9515
9841
  set periodMax(value) {
9516
9842
  this.ensureSchedule().periodMax = value;
9517
9843
  }
9518
9844
  get periodUnit() {
9519
- var _a;
9520
- return (_a = this.clause.schedule) == null ? void 0 : _a.periodUnit;
9845
+ var _a2;
9846
+ return (_a2 = this.clause.schedule) == null ? void 0 : _a2.periodUnit;
9521
9847
  }
9522
9848
  set periodUnit(value) {
9523
9849
  this.ensureSchedule().periodUnit = value;
@@ -9537,22 +9863,22 @@ var ParserState = class {
9537
9863
  return schedule.when;
9538
9864
  }
9539
9865
  get timeOfDay() {
9540
- var _a;
9541
- return (_a = this.clause.schedule) == null ? void 0 : _a.timeOfDay;
9866
+ var _a2;
9867
+ return (_a2 = this.clause.schedule) == null ? void 0 : _a2.timeOfDay;
9542
9868
  }
9543
9869
  set timeOfDay(value) {
9544
9870
  this.ensureSchedule().timeOfDay = value;
9545
9871
  }
9546
9872
  get timingCode() {
9547
- var _a;
9548
- return (_a = this.clause.schedule) == null ? void 0 : _a.timingCode;
9873
+ var _a2;
9874
+ return (_a2 = this.clause.schedule) == null ? void 0 : _a2.timingCode;
9549
9875
  }
9550
9876
  set timingCode(value) {
9551
9877
  this.ensureSchedule().timingCode = value;
9552
9878
  }
9553
9879
  get asNeeded() {
9554
- var _a;
9555
- return (_a = this.clause.prn) == null ? void 0 : _a.enabled;
9880
+ var _a2;
9881
+ return (_a2 = this.clause.prn) == null ? void 0 : _a2.enabled;
9556
9882
  }
9557
9883
  set asNeeded(value) {
9558
9884
  if (value === void 0) {
@@ -9562,13 +9888,13 @@ var ParserState = class {
9562
9888
  this.ensurePrn().enabled = value;
9563
9889
  }
9564
9890
  get asNeededReason() {
9565
- var _a, _b;
9566
- return (_b = (_a = this.clause.prn) == null ? void 0 : _a.reason) == null ? void 0 : _b.text;
9891
+ var _a2, _b;
9892
+ return (_b = (_a2 = this.clause.prn) == null ? void 0 : _a2.reason) == null ? void 0 : _b.text;
9567
9893
  }
9568
9894
  set asNeededReason(value) {
9569
- var _a, _b;
9895
+ var _a2, _b;
9570
9896
  if (value === void 0) {
9571
- if ((_a = this.clause.prn) == null ? void 0 : _a.reason) {
9897
+ if ((_a2 = this.clause.prn) == null ? void 0 : _a2.reason) {
9572
9898
  delete this.clause.prn.reason.text;
9573
9899
  this.cleanupPrn();
9574
9900
  }
@@ -9584,13 +9910,13 @@ var ParserState = class {
9584
9910
  prn.reason.text = value;
9585
9911
  }
9586
9912
  get asNeededReasons() {
9587
- var _a;
9588
- return (_a = this.clause.prn) == null ? void 0 : _a.reasons;
9913
+ var _a2;
9914
+ return (_a2 = this.clause.prn) == null ? void 0 : _a2.reasons;
9589
9915
  }
9590
9916
  set asNeededReasons(value) {
9591
- var _a, _b;
9917
+ var _a2, _b;
9592
9918
  if (!value || !value.length) {
9593
- if ((_a = this.clause.prn) == null ? void 0 : _a.reasons) {
9919
+ if ((_a2 = this.clause.prn) == null ? void 0 : _a2.reasons) {
9594
9920
  delete this.clause.prn.reasons;
9595
9921
  this.cleanupPrn();
9596
9922
  }
@@ -9618,13 +9944,13 @@ var ParserState = class {
9618
9944
  prn.reasons = reasons;
9619
9945
  }
9620
9946
  get asNeededReasonCoding() {
9621
- var _a, _b;
9622
- return (_b = (_a = this.clause.prn) == null ? void 0 : _a.reason) == null ? void 0 : _b.coding;
9947
+ var _a2, _b;
9948
+ return (_b = (_a2 = this.clause.prn) == null ? void 0 : _a2.reason) == null ? void 0 : _b.coding;
9623
9949
  }
9624
9950
  set asNeededReasonCoding(value) {
9625
- var _a, _b;
9951
+ var _a2, _b;
9626
9952
  if (value === void 0) {
9627
- if ((_a = this.clause.prn) == null ? void 0 : _a.reason) {
9953
+ if ((_a2 = this.clause.prn) == null ? void 0 : _a2.reason) {
9628
9954
  delete this.clause.prn.reason.coding;
9629
9955
  this.cleanupPrn();
9630
9956
  }
@@ -9647,22 +9973,22 @@ var ParserState = class {
9647
9973
  } : void 0;
9648
9974
  }
9649
9975
  get siteText() {
9650
- var _a;
9651
- return (_a = this.clause.site) == null ? void 0 : _a.text;
9976
+ var _a2;
9977
+ return (_a2 = this.clause.site) == null ? void 0 : _a2.text;
9652
9978
  }
9653
9979
  set siteText(value) {
9654
9980
  this.ensureSite().text = value;
9655
9981
  }
9656
9982
  get siteSource() {
9657
- var _a;
9658
- return (_a = this.clause.site) == null ? void 0 : _a.source;
9983
+ var _a2;
9984
+ return (_a2 = this.clause.site) == null ? void 0 : _a2.source;
9659
9985
  }
9660
9986
  set siteSource(value) {
9661
9987
  this.ensureSite().source = value;
9662
9988
  }
9663
9989
  get siteCoding() {
9664
- var _a;
9665
- return (_a = this.clause.site) == null ? void 0 : _a.coding;
9990
+ var _a2;
9991
+ return (_a2 = this.clause.site) == null ? void 0 : _a2.coding;
9666
9992
  }
9667
9993
  set siteCoding(value) {
9668
9994
  if (value === void 0) {
@@ -9680,8 +10006,8 @@ var ParserState = class {
9680
10006
  } : void 0;
9681
10007
  }
9682
10008
  get siteSpatialRelation() {
9683
- var _a;
9684
- return (_a = this.clause.site) == null ? void 0 : _a.spatialRelation;
10009
+ var _a2;
10010
+ return (_a2 = this.clause.site) == null ? void 0 : _a2.spatialRelation;
9685
10011
  }
9686
10012
  set siteSpatialRelation(value) {
9687
10013
  if (value === void 0) {
@@ -9763,7 +10089,7 @@ var ParserState = class {
9763
10089
  return this.clause.prn;
9764
10090
  }
9765
10091
  cleanupPrn() {
9766
- var _a;
10092
+ var _a2;
9767
10093
  const prn = this.clause.prn;
9768
10094
  if (!prn) {
9769
10095
  return;
@@ -9771,7 +10097,7 @@ var ParserState = class {
9771
10097
  if (prn.reason && prn.reason.text === void 0 && prn.reason.coding === void 0) {
9772
10098
  delete prn.reason;
9773
10099
  }
9774
- if (((_a = prn.reasons) == null ? void 0 : _a.length) === 0) {
10100
+ if (((_a2 = prn.reasons) == null ? void 0 : _a2.length) === 0) {
9775
10101
  delete prn.reasons;
9776
10102
  }
9777
10103
  if (prn.enabled === void 0 && prn.reason === void 0 && prn.reasons === void 0) {
@@ -9826,8 +10152,8 @@ function createEmptyCanonicalClause(rawText) {
9826
10152
  };
9827
10153
  }
9828
10154
  function selectFirstCodingWithCode(concept) {
9829
- var _a;
9830
- if (!((_a = concept == null ? void 0 : concept.coding) == null ? void 0 : _a.length)) {
10155
+ var _a2;
10156
+ if (!((_a2 = concept == null ? void 0 : concept.coding) == null ? void 0 : _a2.length)) {
9831
10157
  return void 0;
9832
10158
  }
9833
10159
  for (const coding of concept.coding) {
@@ -9838,8 +10164,8 @@ function selectFirstCodingWithCode(concept) {
9838
10164
  return void 0;
9839
10165
  }
9840
10166
  function selectPreferredSiteCoding(site) {
9841
- var _a;
9842
- if (!((_a = site == null ? void 0 : site.coding) == null ? void 0 : _a.length)) {
10167
+ var _a2;
10168
+ if (!((_a2 = site == null ? void 0 : site.coding) == null ? void 0 : _a2.length)) {
9843
10169
  return void 0;
9844
10170
  }
9845
10171
  for (const coding of site.coding) {
@@ -9850,7 +10176,7 @@ function selectPreferredSiteCoding(site) {
9850
10176
  return selectFirstCodingWithCode(site);
9851
10177
  }
9852
10178
  function selectCanonicalSiteCoding(site, options) {
9853
- var _a;
10179
+ var _a2;
9854
10180
  if ((options == null ? void 0 : options.bodySitePostcoordination) === false) {
9855
10181
  return site == null ? void 0 : site.coding;
9856
10182
  }
@@ -9859,16 +10185,16 @@ function selectCanonicalSiteCoding(site, options) {
9859
10185
  site == null ? void 0 : site.text,
9860
10186
  { postcoordination: true }
9861
10187
  );
9862
- return (options == null ? void 0 : options.bodySitePostcoordination) === true ? postcoordinated != null ? postcoordinated : site == null ? void 0 : site.coding : (_a = site == null ? void 0 : site.coding) != null ? _a : postcoordinated;
10188
+ return (options == null ? void 0 : options.bodySitePostcoordination) === true ? postcoordinated != null ? postcoordinated : site == null ? void 0 : site.coding : (_a2 = site == null ? void 0 : site.coding) != null ? _a2 : postcoordinated;
9863
10189
  }
9864
10190
  function buildSiteCodingArray(siteCoding) {
9865
- var _a;
10191
+ var _a2;
9866
10192
  if (!(siteCoding == null ? void 0 : siteCoding.code)) {
9867
10193
  return void 0;
9868
10194
  }
9869
10195
  return [
9870
10196
  {
9871
- system: (_a = siteCoding.system) != null ? _a : SNOMED_SYSTEM5,
10197
+ system: (_a2 = siteCoding.system) != null ? _a2 : SNOMED_SYSTEM5,
9872
10198
  code: siteCoding.code,
9873
10199
  display: siteCoding.display
9874
10200
  }
@@ -9890,12 +10216,12 @@ function lowerFirst(value) {
9890
10216
  return trimmed ? trimmed.charAt(0).toLowerCase() + trimmed.slice(1) : void 0;
9891
10217
  }
9892
10218
  function getSpatialPrnReasonSiteText(spatialRelation) {
9893
- var _a;
10219
+ var _a2;
9894
10220
  const sourceText = lowerFirst(spatialRelation == null ? void 0 : spatialRelation.sourceText);
9895
10221
  if (sourceText) {
9896
10222
  return sourceText;
9897
10223
  }
9898
- const targetText = (_a = lowerFirst(spatialRelation == null ? void 0 : spatialRelation.targetText)) != null ? _a : (spatialRelation == null ? void 0 : spatialRelation.targetCoding) ? getBodySiteText(spatialRelation.targetCoding) : void 0;
10224
+ const targetText = (_a2 = lowerFirst(spatialRelation == null ? void 0 : spatialRelation.targetText)) != null ? _a2 : (spatialRelation == null ? void 0 : spatialRelation.targetCoding) ? getBodySiteText(spatialRelation.targetCoding) : void 0;
9899
10225
  if (!targetText) {
9900
10226
  return void 0;
9901
10227
  }
@@ -9932,7 +10258,7 @@ function getSpatialPrnReasonSiteText(spatialRelation) {
9932
10258
  }
9933
10259
  }
9934
10260
  function getFallbackPrnReasonText(concept) {
9935
- var _a, _b, _c, _d, _e;
10261
+ var _a2, _b, _c, _d, _e;
9936
10262
  if (concept == null ? void 0 : concept.text) {
9937
10263
  return concept.text;
9938
10264
  }
@@ -9944,7 +10270,7 @@ function getFallbackPrnReasonText(concept) {
9944
10270
  return display;
9945
10271
  }
9946
10272
  const parsed = parseSnomedFindingSitePostcoordinationCode(coding == null ? void 0 : coding.code);
9947
- const focus = parsed && ((_a = coding == null ? void 0 : coding.system) != null ? _a : SNOMED_SYSTEM5) === SNOMED_SYSTEM5 ? findPrnReasonDefinitionByCoding(SNOMED_SYSTEM5, parsed.focusCode) : void 0;
10273
+ const focus = parsed && ((_a2 = coding == null ? void 0 : coding.system) != null ? _a2 : SNOMED_SYSTEM5) === SNOMED_SYSTEM5 ? findPrnReasonDefinitionByCoding(SNOMED_SYSTEM5, parsed.focusCode) : void 0;
9948
10274
  const focusText = (_d = lowerFirst((_c = focus == null ? void 0 : focus.text) != null ? _c : (_b = focus == null ? void 0 : focus.coding) == null ? void 0 : _b.display)) != null ? _d : display;
9949
10275
  if (focusText && spatialSiteText) {
9950
10276
  return spatialSiteText.toLowerCase().startsWith(`${focusText.toLowerCase()} `) ? spatialSiteText : `${focusText} ${spatialSiteText}`;
@@ -10016,8 +10342,8 @@ function buildFhirBoundsRange(low, high, unit) {
10016
10342
  };
10017
10343
  }
10018
10344
  function parseFhirDurationUnit(quantity) {
10019
- var _a, _b, _c;
10020
- const candidate = (_c = (_a = quantity == null ? void 0 : quantity.code) == null ? void 0 : _a.trim().toLowerCase()) != null ? _c : (_b = quantity == null ? void 0 : quantity.unit) == null ? void 0 : _b.trim().toLowerCase();
10345
+ var _a2, _b, _c;
10346
+ const candidate = (_c = (_a2 = quantity == null ? void 0 : quantity.code) == null ? void 0 : _a2.trim().toLowerCase()) != null ? _c : (_b = quantity == null ? void 0 : quantity.unit) == null ? void 0 : _b.trim().toLowerCase();
10021
10347
  switch (candidate) {
10022
10348
  case "s":
10023
10349
  case "sec":
@@ -10059,11 +10385,11 @@ function parseFhirDurationUnit(quantity) {
10059
10385
  }
10060
10386
  }
10061
10387
  function extractCanonicalTimingBounds(repeat) {
10062
- var _a;
10388
+ var _a2;
10063
10389
  if (!repeat) {
10064
10390
  return {};
10065
10391
  }
10066
- if (((_a = repeat.boundsDuration) == null ? void 0 : _a.value) !== void 0) {
10392
+ if (((_a2 = repeat.boundsDuration) == null ? void 0 : _a2.value) !== void 0) {
10067
10393
  const durationUnit2 = parseFhirDurationUnit(repeat.boundsDuration);
10068
10394
  if (!durationUnit2) {
10069
10395
  return {};
@@ -10096,9 +10422,9 @@ function extractCanonicalTimingBounds(repeat) {
10096
10422
  };
10097
10423
  }
10098
10424
  function extractCanonicalDoseRange(range) {
10099
- var _a, _b, _c, _d;
10425
+ var _a2, _b, _c, _d;
10100
10426
  const canonicalRange = {};
10101
- const lowUnit = (_a = range.low) == null ? void 0 : _a.unit;
10427
+ const lowUnit = (_a2 = range.low) == null ? void 0 : _a2.unit;
10102
10428
  const highUnit = (_b = range.high) == null ? void 0 : _b.unit;
10103
10429
  if (((_c = range.low) == null ? void 0 : _c.value) !== void 0) {
10104
10430
  canonicalRange.low = range.low.value;
@@ -10131,7 +10457,7 @@ function appendWarning(warnings, warning) {
10131
10457
  return warnings;
10132
10458
  }
10133
10459
  function canonicalToFhir(clause, textOverride, options) {
10134
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G;
10460
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G;
10135
10461
  const dosage = {};
10136
10462
  const repeat = {};
10137
10463
  let hasRepeat = false;
@@ -10169,7 +10495,7 @@ function canonicalToFhir(clause, textOverride, options) {
10169
10495
  repeat.periodMax = schedule.periodMax;
10170
10496
  hasRepeat = true;
10171
10497
  }
10172
- if ((_a = schedule == null ? void 0 : schedule.dayOfWeek) == null ? void 0 : _a.length) {
10498
+ if ((_a2 = schedule == null ? void 0 : schedule.dayOfWeek) == null ? void 0 : _a2.length) {
10173
10499
  repeat.dayOfWeek = [...schedule.dayOfWeek];
10174
10500
  hasRepeat = true;
10175
10501
  }
@@ -10301,8 +10627,8 @@ function canonicalToFhir(clause, textOverride, options) {
10301
10627
  return dosage;
10302
10628
  }
10303
10629
  function canonicalFromFhir(dosage) {
10304
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
10305
- const rawText = (_a = dosage.text) != null ? _a : "";
10630
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
10631
+ const rawText = (_a2 = dosage.text) != null ? _a2 : "";
10306
10632
  const clause = createEmptyCanonicalClause(rawText);
10307
10633
  let routeCode;
10308
10634
  const routeCoding = (_c = (_b = dosage.route) == null ? void 0 : _b.coding) == null ? void 0 : _c.find((code) => code.system === SNOMED_SYSTEM5);
@@ -10380,8 +10706,8 @@ function canonicalFromFhir(dosage) {
10380
10706
  };
10381
10707
  }
10382
10708
  const prnReasons = ((_y = dosage.asNeededFor) == null ? void 0 : _y.length) ? dosage.asNeededFor.map((concept) => {
10383
- var _a2;
10384
- const coding = (_a2 = concept.coding) == null ? void 0 : _a2.find((code) => Boolean(code.code));
10709
+ var _a3;
10710
+ const coding = (_a3 = concept.coding) == null ? void 0 : _a3.find((code) => Boolean(code.code));
10385
10711
  return {
10386
10712
  text: getFallbackPrnReasonText(concept),
10387
10713
  spatialRelation: parseBodySiteSpatialRelationExtension(concept),
@@ -10429,7 +10755,7 @@ function canonicalFromFhir(dosage) {
10429
10755
 
10430
10756
  // src/ir.ts
10431
10757
  function shiftCanonicalSigClauses(clauses, offset) {
10432
- var _a, _b, _c, _d, _e;
10758
+ var _a2, _b, _c, _d, _e;
10433
10759
  for (const clause of clauses) {
10434
10760
  if (clause.span) {
10435
10761
  clause.span = {
@@ -10457,7 +10783,7 @@ function shiftCanonicalSigClauses(clauses, offset) {
10457
10783
  }
10458
10784
  };
10459
10785
  shiftEvidenceSpans(clause.evidence);
10460
- shiftEvidenceSpans((_a = clause.dose) == null ? void 0 : _a.evidence);
10786
+ shiftEvidenceSpans((_a2 = clause.dose) == null ? void 0 : _a2.evidence);
10461
10787
  shiftEvidenceSpans((_b = clause.route) == null ? void 0 : _b.evidence);
10462
10788
  shiftEvidenceSpans((_c = clause.site) == null ? void 0 : _c.evidence);
10463
10789
  shiftEvidenceSpans((_d = clause.schedule) == null ? void 0 : _d.evidence);
@@ -10479,8 +10805,8 @@ function getRegisteredSigLocalizations() {
10479
10805
  return Array.from(REGISTERED_LOCALIZATIONS.values());
10480
10806
  }
10481
10807
  function resolveSigLocalization(locale, config) {
10482
- var _a, _b, _c, _d, _e, _f, _g;
10483
- const normalizedLocale = (_a = config == null ? void 0 : config.locale) != null ? _a : locale;
10808
+ var _a2, _b, _c, _d, _e, _f, _g;
10809
+ const normalizedLocale = (_a2 = config == null ? void 0 : config.locale) != null ? _a2 : locale;
10484
10810
  const targetKey = normalizedLocale == null ? void 0 : normalizedLocale.toLowerCase();
10485
10811
  const base = targetKey ? REGISTERED_LOCALIZATIONS.get(targetKey) : void 0;
10486
10812
  const inherited = (config == null ? void 0 : config.inherit) ? REGISTERED_LOCALIZATIONS.get(config.inherit.toLowerCase()) : void 0;
@@ -10838,10 +11164,10 @@ var THAI_SITE_TRANSLATIONS = {
10838
11164
  hair: "\u0E40\u0E2A\u0E49\u0E19\u0E1C\u0E21"
10839
11165
  };
10840
11166
  var THAI_SITE_CODE_TRANSLATIONS = (() => {
10841
- var _a;
11167
+ var _a2;
10842
11168
  const translations = {};
10843
11169
  for (const { names, definition } of DEFAULT_BODY_SITE_SNOMED_SOURCE) {
10844
- const code = (_a = definition.coding) == null ? void 0 : _a.code;
11170
+ const code = (_a2 = definition.coding) == null ? void 0 : _a2.code;
10845
11171
  if (!code || translations[code]) {
10846
11172
  continue;
10847
11173
  }
@@ -10978,8 +11304,8 @@ var THAI_SITE_FIRST_VERBS = /* @__PURE__ */ new Set([
10978
11304
  "\u0E1E\u0E48\u0E19"
10979
11305
  ]);
10980
11306
  function resolveThaiMethodVerb(clause, grammar) {
10981
- var _a, _b, _c, _d, _e;
10982
- const translatedText = getPrimitiveTranslation((_a = clause.method) == null ? void 0 : _a._text, "th");
11307
+ var _a2, _b, _c, _d, _e;
11308
+ const translatedText = getPrimitiveTranslation((_a2 = clause.method) == null ? void 0 : _a2._text, "th");
10983
11309
  if (translatedText) {
10984
11310
  return translatedText;
10985
11311
  }
@@ -11023,14 +11349,14 @@ function joinThaiVerbAndBody(verb, body) {
11023
11349
  return `${verb} ${trimmedBody}`;
11024
11350
  }
11025
11351
  function shouldUseGenericMedicationObjectThai(clause, verb, explicitDosePart) {
11026
- var _a;
11352
+ var _a2;
11027
11353
  if (explicitDosePart) {
11028
11354
  return false;
11029
11355
  }
11030
11356
  if (THAI_IMPLIED_OBJECT_VERBS.has(verb)) {
11031
11357
  return false;
11032
11358
  }
11033
- switch ((_a = clause.route) == null ? void 0 : _a.code) {
11359
+ switch ((_a2 = clause.route) == null ? void 0 : _a2.code) {
11034
11360
  case RouteCode["Topical route"]:
11035
11361
  case RouteCode["Transdermal route"]:
11036
11362
  case RouteCode["Nasal route"]:
@@ -11044,14 +11370,14 @@ function shouldUseGenericMedicationObjectThai(clause, verb, explicitDosePart) {
11044
11370
  }
11045
11371
  }
11046
11372
  function shouldSuppressRoutePhraseThai(clause, verb, hasSite, explicitDosePart) {
11047
- var _a;
11373
+ var _a2;
11048
11374
  if (hasSite || explicitDosePart) {
11049
11375
  return false;
11050
11376
  }
11051
11377
  if (!THAI_SUPPRESSIBLE_ROUTE_VERBS.has(verb)) {
11052
11378
  return false;
11053
11379
  }
11054
- switch ((_a = clause.route) == null ? void 0 : _a.code) {
11380
+ switch ((_a2 = clause.route) == null ? void 0 : _a2.code) {
11055
11381
  case RouteCode["Topical route"]:
11056
11382
  case RouteCode["Transdermal route"]:
11057
11383
  return true;
@@ -11060,12 +11386,12 @@ function shouldSuppressRoutePhraseThai(clause, verb, hasSite, explicitDosePart)
11060
11386
  }
11061
11387
  }
11062
11388
  function scheduleOf2(clause) {
11063
- var _a;
11064
- return (_a = clause.schedule) != null ? _a : {};
11389
+ var _a2;
11390
+ return (_a2 = clause.schedule) != null ? _a2 : {};
11065
11391
  }
11066
11392
  function resolveRouteGrammarThai(clause) {
11067
- var _a, _b, _c, _d, _e, _f;
11068
- const routeCode = (_a = clause.route) == null ? void 0 : _a.code;
11393
+ var _a2, _b, _c, _d, _e, _f;
11394
+ const routeCode = (_a2 = clause.route) == null ? void 0 : _a2.code;
11069
11395
  if (routeCode && THAI_ROUTE_GRAMMAR[routeCode]) {
11070
11396
  return (_b = THAI_ROUTE_GRAMMAR[routeCode]) != null ? _b : DEFAULT_THAI_ROUTE_GRAMMAR;
11071
11397
  }
@@ -11222,8 +11548,27 @@ function formatUnitThai(unit, _value, style) {
11222
11548
  sprays: { short: "\u0E1E\u0E48\u0E19", long: "\u0E1E\u0E48\u0E19" },
11223
11549
  drop: { short: "\u0E2B\u0E22\u0E14", long: "\u0E2B\u0E22\u0E14" },
11224
11550
  drops: { short: "\u0E2B\u0E22\u0E14", long: "\u0E2B\u0E22\u0E14" },
11551
+ pump: { short: "\u0E1B\u0E31\u0E4A\u0E21", long: "\u0E1B\u0E31\u0E4A\u0E21" },
11552
+ pumps: { short: "\u0E1B\u0E31\u0E4A\u0E21", long: "\u0E1B\u0E31\u0E4A\u0E21" },
11553
+ actuation: { short: "\u0E04\u0E23\u0E31\u0E49\u0E07", long: "\u0E04\u0E23\u0E31\u0E49\u0E07" },
11554
+ ftu: { short: "FTU", long: "FTU" },
11225
11555
  patch: { short: "\u0E41\u0E1C\u0E48\u0E19", long: "\u0E41\u0E1C\u0E48\u0E19\u0E41\u0E1B\u0E30" },
11226
11556
  patches: { short: "\u0E41\u0E1C\u0E48\u0E19", long: "\u0E41\u0E1C\u0E48\u0E19\u0E41\u0E1B\u0E30" },
11557
+ ring: { short: "\u0E27\u0E07", long: "\u0E27\u0E07" },
11558
+ applicatorful: { short: "\u0E41\u0E2D\u0E1B\u0E1E\u0E25\u0E34\u0E40\u0E04\u0E40\u0E15\u0E2D\u0E23\u0E4C", long: "\u0E41\u0E2D\u0E1B\u0E1E\u0E25\u0E34\u0E40\u0E04\u0E40\u0E15\u0E2D\u0E23\u0E4C" },
11559
+ capful: { short: "\u0E1D\u0E32", long: "\u0E1D\u0E32" },
11560
+ scoop: { short: "\u0E0A\u0E49\u0E2D\u0E19\u0E15\u0E27\u0E07", long: "\u0E0A\u0E49\u0E2D\u0E19\u0E15\u0E27\u0E07" },
11561
+ "pea-sized amount": { short: "\u0E02\u0E19\u0E32\u0E14\u0E40\u0E17\u0E48\u0E32\u0E40\u0E21\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27", long: "\u0E02\u0E19\u0E32\u0E14\u0E40\u0E17\u0E48\u0E32\u0E40\u0E21\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27" },
11562
+ palm: { short: "\u0E1D\u0E48\u0E32\u0E21\u0E37\u0E2D", long: "\u0E1D\u0E48\u0E32\u0E21\u0E37\u0E2D" },
11563
+ handprint: { short: "\u0E2B\u0E19\u0E36\u0E48\u0E07\u0E1D\u0E48\u0E32\u0E21\u0E37\u0E2D", long: "\u0E2B\u0E19\u0E36\u0E48\u0E07\u0E1D\u0E48\u0E32\u0E21\u0E37\u0E2D" },
11564
+ "shot glass": { short: "\u0E41\u0E01\u0E49\u0E27\u0E0A\u0E47\u0E2D\u0E15", long: "\u0E41\u0E01\u0E49\u0E27\u0E0A\u0E47\u0E2D\u0E15" },
11565
+ "finger length": { short: "\u0E04\u0E27\u0E32\u0E21\u0E22\u0E32\u0E27\u0E19\u0E34\u0E49\u0E27", long: "\u0E04\u0E27\u0E32\u0E21\u0E22\u0E32\u0E27\u0E19\u0E34\u0E49\u0E27" },
11566
+ click: { short: "\u0E04\u0E25\u0E34\u0E01", long: "\u0E04\u0E25\u0E34\u0E01" },
11567
+ vial: { short: "\u0E02\u0E27\u0E14", long: "\u0E02\u0E27\u0E14" },
11568
+ ampule: { short: "\u0E41\u0E2D\u0E21\u0E1E\u0E39\u0E25", long: "\u0E41\u0E2D\u0E21\u0E1E\u0E39\u0E25" },
11569
+ packet: { short: "\u0E0B\u0E2D\u0E07", long: "\u0E0B\u0E2D\u0E07" },
11570
+ sachet: { short: "\u0E0B\u0E2D\u0E07", long: "\u0E0B\u0E2D\u0E07" },
11571
+ "stick-pack": { short: "\u0E0B\u0E2D\u0E07\u0E41\u0E17\u0E48\u0E07", long: "\u0E0B\u0E2D\u0E07\u0E41\u0E17\u0E48\u0E07" },
11227
11572
  suppository: { short: "\u0E22\u0E32\u0E40\u0E2B\u0E19\u0E47\u0E1A", long: "\u0E22\u0E32\u0E40\u0E2B\u0E19\u0E47\u0E1A" },
11228
11573
  suppositories: { short: "\u0E22\u0E32\u0E40\u0E2B\u0E19\u0E47\u0E1A", long: "\u0E22\u0E32\u0E40\u0E2B\u0E19\u0E47\u0E1A" }
11229
11574
  };
@@ -11231,7 +11576,7 @@ function formatUnitThai(unit, _value, style) {
11231
11576
  return entry ? entry[style] : unit;
11232
11577
  }
11233
11578
  function describeFrequencyThai(schedule) {
11234
- var _a, _b;
11579
+ var _a2, _b;
11235
11580
  const frequency = schedule == null ? void 0 : schedule.frequency;
11236
11581
  const frequencyMax = schedule == null ? void 0 : schedule.frequencyMax;
11237
11582
  const period = schedule == null ? void 0 : schedule.period;
@@ -11248,7 +11593,7 @@ function describeFrequencyThai(schedule) {
11248
11593
  return `\u0E27\u0E31\u0E19\u0E25\u0E30 ${stripTrailingZero2(frequency)} \u0E16\u0E36\u0E07 ${stripTrailingZero2(frequencyMax)} \u0E04\u0E23\u0E31\u0E49\u0E07`;
11249
11594
  }
11250
11595
  if (frequency && periodUnit === "d" /* Day */ && (!period || period === 1)) {
11251
- return (_a = TH_TIMES_PER_DAY[frequency]) != null ? _a : `\u0E27\u0E31\u0E19\u0E25\u0E30 ${stripTrailingZero2(frequency)} \u0E04\u0E23\u0E31\u0E49\u0E07`;
11596
+ return (_a2 = TH_TIMES_PER_DAY[frequency]) != null ? _a2 : `\u0E27\u0E31\u0E19\u0E25\u0E30 ${stripTrailingZero2(frequency)} \u0E04\u0E23\u0E31\u0E49\u0E07`;
11252
11597
  }
11253
11598
  if (periodUnit === "min" /* Minute */ && period) {
11254
11599
  if (periodMax && periodMax !== period) {
@@ -11327,19 +11672,19 @@ function describeFrequencyThai(schedule) {
11327
11672
  return void 0;
11328
11673
  }
11329
11674
  function describeFrequencyCountThai(count) {
11330
- var _a;
11675
+ var _a2;
11331
11676
  if (!count || count <= 0) {
11332
11677
  return void 0;
11333
11678
  }
11334
- return (_a = TH_TIMES_PER_DAY[count]) != null ? _a : `\u0E27\u0E31\u0E19\u0E25\u0E30 ${stripTrailingZero2(count)} \u0E04\u0E23\u0E31\u0E49\u0E07`;
11679
+ return (_a2 = TH_TIMES_PER_DAY[count]) != null ? _a2 : `\u0E27\u0E31\u0E19\u0E25\u0E30 ${stripTrailingZero2(count)} \u0E04\u0E23\u0E31\u0E49\u0E07`;
11335
11680
  }
11336
11681
  function describeStandaloneOccurrenceCountThai(schedule) {
11337
- var _a, _b, _c;
11682
+ var _a2, _b, _c;
11338
11683
  const count = schedule == null ? void 0 : schedule.count;
11339
11684
  if (!count || count <= 0) {
11340
11685
  return void 0;
11341
11686
  }
11342
- if ((schedule == null ? void 0 : schedule.frequency) !== void 0 || (schedule == null ? void 0 : schedule.frequencyMax) !== void 0 || (schedule == null ? void 0 : schedule.period) !== void 0 || (schedule == null ? void 0 : schedule.periodMax) !== void 0 || (schedule == null ? void 0 : schedule.periodUnit) !== void 0 || ((_a = schedule == null ? void 0 : schedule.dayOfWeek) == null ? void 0 : _a.length) || ((_b = schedule == null ? void 0 : schedule.when) == null ? void 0 : _b.length) || ((_c = schedule == null ? void 0 : schedule.timeOfDay) == null ? void 0 : _c.length) || (schedule == null ? void 0 : schedule.duration) !== void 0 || (schedule == null ? void 0 : schedule.durationMax) !== void 0 || (schedule == null ? void 0 : schedule.durationUnit) !== void 0 || (schedule == null ? void 0 : schedule.timingCode)) {
11687
+ if ((schedule == null ? void 0 : schedule.frequency) !== void 0 || (schedule == null ? void 0 : schedule.frequencyMax) !== void 0 || (schedule == null ? void 0 : schedule.period) !== void 0 || (schedule == null ? void 0 : schedule.periodMax) !== void 0 || (schedule == null ? void 0 : schedule.periodUnit) !== void 0 || ((_a2 = schedule == null ? void 0 : schedule.dayOfWeek) == null ? void 0 : _a2.length) || ((_b = schedule == null ? void 0 : schedule.when) == null ? void 0 : _b.length) || ((_c = schedule == null ? void 0 : schedule.timeOfDay) == null ? void 0 : _c.length) || (schedule == null ? void 0 : schedule.duration) !== void 0 || (schedule == null ? void 0 : schedule.durationMax) !== void 0 || (schedule == null ? void 0 : schedule.durationUnit) !== void 0 || (schedule == null ? void 0 : schedule.timingCode)) {
11343
11688
  return void 0;
11344
11689
  }
11345
11690
  return `${stripTrailingZero2(count)} \u0E04\u0E23\u0E31\u0E49\u0E07`;
@@ -11378,8 +11723,8 @@ function summarizeMealTimingGroupThai(group) {
11378
11723
  return `${relationText[group.relation]}${joinMealNamesThai(meals)}`;
11379
11724
  }
11380
11725
  function collectWhenPhrasesThai(schedule, options) {
11381
- var _a;
11382
- const when = (_a = schedule == null ? void 0 : schedule.when) != null ? _a : [];
11726
+ var _a2;
11727
+ const when = (_a2 = schedule == null ? void 0 : schedule.when) != null ? _a2 : [];
11383
11728
  if (!when.length) {
11384
11729
  return [];
11385
11730
  }
@@ -11473,8 +11818,8 @@ function combineFrequencyAndEventsThai(frequency, events) {
11473
11818
  return { frequency, event: joinWithAndThai(events) };
11474
11819
  }
11475
11820
  function isOralRouteThai(clause) {
11476
- var _a, _b, _c;
11477
- if (((_a = clause.route) == null ? void 0 : _a.code) === RouteCode["Oral route"]) {
11821
+ var _a2, _b, _c;
11822
+ if (((_a2 = clause.route) == null ? void 0 : _a2.code) === RouteCode["Oral route"]) {
11478
11823
  return true;
11479
11824
  }
11480
11825
  const text = (_c = (_b = clause.route) == null ? void 0 : _b.text) == null ? void 0 : _c.trim().toLowerCase();
@@ -11484,7 +11829,7 @@ function isOralRouteThai(clause) {
11484
11829
  return text === "po" || text === "oral" || text.includes("mouth") || text.includes("per os");
11485
11830
  }
11486
11831
  function buildRoutePhraseThai(clause, grammar, hasSite) {
11487
- var _a, _b;
11832
+ var _a2, _b;
11488
11833
  if (grammar.verb === "\u0E23\u0E31\u0E1A\u0E1B\u0E23\u0E30\u0E17\u0E32\u0E19" && isOralRouteThai(clause)) {
11489
11834
  return void 0;
11490
11835
  }
@@ -11494,7 +11839,7 @@ function buildRoutePhraseThai(clause, grammar, hasSite) {
11494
11839
  if (typeof grammar.routePhrase === "string") {
11495
11840
  return grammar.routePhrase;
11496
11841
  }
11497
- const text = (_b = (_a = clause.route) == null ? void 0 : _a.text) == null ? void 0 : _b.trim();
11842
+ const text = (_b = (_a2 = clause.route) == null ? void 0 : _a2.text) == null ? void 0 : _b.trim();
11498
11843
  if (!text) {
11499
11844
  return void 0;
11500
11845
  }
@@ -11529,8 +11874,8 @@ function buildRoutePhraseThai(clause, grammar, hasSite) {
11529
11874
  return text;
11530
11875
  }
11531
11876
  function formatSiteThai(clause, grammar) {
11532
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
11533
- const text = ((_b = (_a = clause.site) == null ? void 0 : _a.text) == null ? void 0 : _b.trim()) || ((_e = (_d = (_c = clause.site) == null ? void 0 : _c.coding) == null ? void 0 : _d.display) == null ? void 0 : _e.trim());
11877
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
11878
+ const text = ((_b = (_a2 = clause.site) == null ? void 0 : _a2.text) == null ? void 0 : _b.trim()) || ((_e = (_d = (_c = clause.site) == null ? void 0 : _c.coding) == null ? void 0 : _d.display) == null ? void 0 : _e.trim());
11534
11879
  const lower = text == null ? void 0 : text.toLowerCase();
11535
11880
  const codingCode = (_g = (_f = clause.site) == null ? void 0 : _f.coding) == null ? void 0 : _g.code;
11536
11881
  const routeText = (_i = (_h = clause.route) == null ? void 0 : _h.text) == null ? void 0 : _i.trim().toLowerCase();
@@ -11587,8 +11932,8 @@ var THAI_SPATIAL_TARGET_TRANSLATION_OVERRIDES = {
11587
11932
  belly: "\u0E17\u0E49\u0E2D\u0E07"
11588
11933
  };
11589
11934
  function translateSpatialTargetThai(relation) {
11590
- var _a, _b;
11591
- const normalizedTarget = normalizeBodySiteKey((_a = relation.targetText) != null ? _a : "");
11935
+ var _a2, _b;
11936
+ const normalizedTarget = normalizeBodySiteKey((_a2 = relation.targetText) != null ? _a2 : "");
11592
11937
  const override = THAI_SPATIAL_TARGET_TRANSLATION_OVERRIDES[normalizedTarget];
11593
11938
  return override != null ? override : translateSiteThai(
11594
11939
  relation.targetText,
@@ -11596,8 +11941,8 @@ function translateSpatialTargetThai(relation) {
11596
11941
  );
11597
11942
  }
11598
11943
  function translateSpatialSiteThai(site, relation) {
11599
- var _a;
11600
- const spatialRelation = relation != null ? relation : site ? (_a = resolveBodySitePhrase(site)) == null ? void 0 : _a.spatialRelation : void 0;
11944
+ var _a2;
11945
+ const spatialRelation = relation != null ? relation : site ? (_a2 = resolveBodySitePhrase(site)) == null ? void 0 : _a2.spatialRelation : void 0;
11601
11946
  if (!(spatialRelation == null ? void 0 : spatialRelation.relationText)) {
11602
11947
  return void 0;
11603
11948
  }
@@ -11650,8 +11995,8 @@ function translateSiteThai(site, code, spatialRelation) {
11650
11995
  return site;
11651
11996
  }
11652
11997
  function describeDayOfWeekThai(schedule) {
11653
- var _a;
11654
- const dayOfWeek = (_a = schedule == null ? void 0 : schedule.dayOfWeek) != null ? _a : [];
11998
+ var _a2;
11999
+ const dayOfWeek = (_a2 = schedule == null ? void 0 : schedule.dayOfWeek) != null ? _a2 : [];
11655
12000
  if (!dayOfWeek.length) {
11656
12001
  return void 0;
11657
12002
  }
@@ -11701,7 +12046,7 @@ function describeDurationThai(schedule) {
11701
12046
  return `\u0E40\u0E1B\u0E47\u0E19\u0E40\u0E27\u0E25\u0E32 ${stripTrailingZero2(schedule.duration)} ${label()}`;
11702
12047
  }
11703
12048
  function findPrnReasonDefinitionByPossiblyPostcoordinatedCoding(system, code) {
11704
- var _a;
12049
+ var _a2;
11705
12050
  const direct = findPrnReasonDefinitionByCoding(system, code);
11706
12051
  if (direct) {
11707
12052
  return direct;
@@ -11710,11 +12055,11 @@ function findPrnReasonDefinitionByPossiblyPostcoordinatedCoding(system, code) {
11710
12055
  if (!normalizedSystem.includes("snomed.info/sct")) {
11711
12056
  return void 0;
11712
12057
  }
11713
- return findPrnReasonDefinitionByCoding(system, (_a = code.split(":")[0]) != null ? _a : code);
12058
+ return findPrnReasonDefinitionByCoding(system, (_a2 = code.split(":")[0]) != null ? _a2 : code);
11714
12059
  }
11715
12060
  function translatePrnReasonThai(reason) {
11716
- var _a, _b, _c, _d, _e;
11717
- let text = (_b = reason.text) != null ? _b : (_a = reason.coding) == null ? void 0 : _a.display;
12061
+ var _a2, _b, _c, _d, _e;
12062
+ let text = (_b = reason.text) != null ? _b : (_a2 = reason.coding) == null ? void 0 : _a2.display;
11718
12063
  const coding = reason.coding;
11719
12064
  if (coding == null ? void 0 : coding.code) {
11720
12065
  const definition = findPrnReasonDefinitionByPossiblyPostcoordinatedCoding(
@@ -11730,8 +12075,8 @@ function translatePrnReasonThai(reason) {
11730
12075
  return text;
11731
12076
  }
11732
12077
  function formatAsNeededThai(clause) {
11733
- var _a, _b, _c, _d, _e, _f;
11734
- if (!((_a = clause.prn) == null ? void 0 : _a.enabled)) {
12078
+ var _a2, _b, _c, _d, _e, _f;
12079
+ if (!((_a2 = clause.prn) == null ? void 0 : _a2.enabled)) {
11735
12080
  return void 0;
11736
12081
  }
11737
12082
  if ((_b = clause.prn.reasons) == null ? void 0 : _b.length) {
@@ -11753,14 +12098,14 @@ function formatAsNeededThai(clause) {
11753
12098
  return "\u0E43\u0E0A\u0E49\u0E40\u0E21\u0E37\u0E48\u0E2D\u0E08\u0E33\u0E40\u0E1B\u0E47\u0E19";
11754
12099
  }
11755
12100
  function formatShortThai(clause) {
11756
- var _a, _b, _c, _d, _e, _f;
12101
+ var _a2, _b, _c, _d, _e, _f;
11757
12102
  const schedule = scheduleOf2(clause);
11758
12103
  const parts = [];
11759
12104
  const dose = formatDoseThaiShort(clause.dose);
11760
12105
  if (dose) {
11761
12106
  parts.push(dose);
11762
12107
  }
11763
- if ((_a = clause.route) == null ? void 0 : _a.code) {
12108
+ if ((_a2 = clause.route) == null ? void 0 : _a2.code) {
11764
12109
  const short = ROUTE_SHORT2[clause.route.code];
11765
12110
  if (short) {
11766
12111
  parts.push(short);
@@ -11812,7 +12157,7 @@ function formatShortThai(clause) {
11812
12157
  return parts.filter(Boolean).join(" ");
11813
12158
  }
11814
12159
  function formatLongThai(clause, options) {
11815
- var _a, _b, _c;
12160
+ var _a2, _b, _c;
11816
12161
  const schedule = scheduleOf2(clause);
11817
12162
  const grammar = resolveRouteGrammarThai(clause);
11818
12163
  const verb = resolveThaiMethodVerb(clause, grammar);
@@ -11830,7 +12175,7 @@ function formatLongThai(clause, options) {
11830
12175
  explicitDosePart
11831
12176
  ) ? void 0 : buildRoutePhraseThai(clause, grammar, Boolean(sitePart));
11832
12177
  const standaloneOccurrenceCount = describeStandaloneOccurrenceCountThai(schedule);
11833
- const frequencyPart = (_b = (_a = describeFrequencyThai(schedule)) != null ? _a : standaloneOccurrenceCount) != null ? _b : describeFrequencyCountThai(inferDailyOccurrenceCount(schedule, options));
12178
+ const frequencyPart = (_b = (_a2 = describeFrequencyThai(schedule)) != null ? _a2 : standaloneOccurrenceCount) != null ? _b : describeFrequencyCountThai(inferDailyOccurrenceCount(schedule, options));
11834
12179
  const eventParts = collectWhenPhrasesThai(schedule, options);
11835
12180
  if ((_c = schedule.timeOfDay) == null ? void 0 : _c.length) {
11836
12181
  const timeStrings = [];
@@ -11906,8 +12251,8 @@ function formatLongThai(clause, options) {
11906
12251
  return trailingInstructionText ? `${baseSentence} ${trailingInstructionText}` : baseSentence;
11907
12252
  }
11908
12253
  function formatAdditionalInstructionsThai(clause) {
11909
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11910
- const instructions = (_a = clause.additionalInstructions) != null ? _a : [];
12254
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12255
+ const instructions = (_a2 = clause.additionalInstructions) != null ? _a2 : [];
11911
12256
  if (!instructions.length) {
11912
12257
  return void 0;
11913
12258
  }
@@ -11970,7 +12315,7 @@ function tokenSpanLength(sign) {
11970
12315
  return Math.max(0, sign.span.end - sign.span.start);
11971
12316
  }
11972
12317
  function countSynsemFeatures(sign) {
11973
- var _a;
12318
+ var _a2;
11974
12319
  let count = 0;
11975
12320
  const { head, valence, cont } = sign.synsem;
11976
12321
  if (head.method) count += 1;
@@ -11979,7 +12324,7 @@ function countSynsemFeatures(sign) {
11979
12324
  if (head.schedule) count += 1;
11980
12325
  if (valence.site) count += 1;
11981
12326
  if (valence.prn) count += 1;
11982
- if ((_a = valence.instructions) == null ? void 0 : _a.length) count += 1;
12327
+ if ((_a2 = valence.instructions) == null ? void 0 : _a2.length) count += 1;
11983
12328
  if (valence.patientInstruction) count += 1;
11984
12329
  if (cont.clauseKind) count += 1;
11985
12330
  return count;
@@ -12046,8 +12391,8 @@ function pushUnique(signs, seen, sign) {
12046
12391
  return true;
12047
12392
  }
12048
12393
  function parseHpsgChart(context, grammar, options = {}) {
12049
- var _a, _b;
12050
- const limit = (_a = options.limit) != null ? _a : context.tokens.length;
12394
+ var _a2, _b;
12395
+ const limit = (_a2 = options.limit) != null ? _a2 : context.tokens.length;
12051
12396
  const maxIterations = (_b = options.maxIterations) != null ? _b : Math.max(16, limit * limit * 2);
12052
12397
  const signs = [];
12053
12398
  const seen = /* @__PURE__ */ new Map();
@@ -12094,7 +12439,7 @@ function parseHpsgChart(context, grammar, options = {}) {
12094
12439
 
12095
12440
  // src/hpsg/projection.ts
12096
12441
  function applySchedule(state, schedule, deps) {
12097
- var _a;
12442
+ var _a2;
12098
12443
  if (schedule.timingCode !== void 0) {
12099
12444
  state.timingCode = schedule.timingCode;
12100
12445
  }
@@ -12133,7 +12478,7 @@ function applySchedule(state, schedule, deps) {
12133
12478
  if (schedule.dayOfWeek) {
12134
12479
  deps.addDayOfWeekList(state, schedule.dayOfWeek);
12135
12480
  }
12136
- if ((_a = schedule.timeOfDay) == null ? void 0 : _a.length) {
12481
+ if ((_a2 = schedule.timeOfDay) == null ? void 0 : _a2.length) {
12137
12482
  const existing = state.timeOfDay ? state.timeOfDay.slice() : [];
12138
12483
  for (const time of schedule.timeOfDay) {
12139
12484
  if (existing.indexOf(time) === -1) {
@@ -12151,7 +12496,7 @@ function findTokenByIndex(tokens, tokenIndex) {
12151
12496
  return tokens.find((candidate) => candidate.index === tokenIndex);
12152
12497
  }
12153
12498
  function projectHpsgSignToState(sign, state, tokens, deps) {
12154
- var _a, _b, _c, _d;
12499
+ var _a2, _b, _c, _d;
12155
12500
  const method = sign.synsem.head.method;
12156
12501
  if (method) {
12157
12502
  state.methodVerb = method.verb;
@@ -12195,7 +12540,7 @@ function projectHpsgSignToState(sign, state, tokens, deps) {
12195
12540
  if (prn.reasonText !== void 0) {
12196
12541
  state.asNeededReason = prn.reasonText;
12197
12542
  }
12198
- if ((_a = prn.reasons) == null ? void 0 : _a.length) {
12543
+ if ((_a2 = prn.reasons) == null ? void 0 : _a2.length) {
12199
12544
  state.asNeededReasons = prn.reasons.map((reason) => ({
12200
12545
  text: reason.text
12201
12546
  }));
@@ -12213,8 +12558,8 @@ function projectHpsgSignToState(sign, state, tokens, deps) {
12213
12558
  for (const instruction of instructions) {
12214
12559
  if (!existing.some(
12215
12560
  (candidate) => {
12216
- var _a2, _b2;
12217
- return candidate.text === instruction.text && ((_a2 = candidate.coding) == null ? void 0 : _a2.code) === ((_b2 = instruction.coding) == null ? void 0 : _b2.code);
12561
+ var _a3, _b2;
12562
+ return candidate.text === instruction.text && ((_a3 = candidate.coding) == null ? void 0 : _a3.code) === ((_b2 = instruction.coding) == null ? void 0 : _b2.code);
12218
12563
  }
12219
12564
  )) {
12220
12565
  existing.push({
@@ -12282,13 +12627,13 @@ function mergeOptionalScalar(left, right) {
12282
12627
  return left !== void 0 ? left : right;
12283
12628
  }
12284
12629
  function sameCoding(left, right) {
12285
- var _a, _b;
12630
+ var _a2, _b;
12286
12631
  if (!(left == null ? void 0 : left.code) || !(right == null ? void 0 : right.code)) {
12287
12632
  return (left == null ? void 0 : left.code) === (right == null ? void 0 : right.code);
12288
12633
  }
12289
12634
  const leftVersion = left.version;
12290
12635
  const rightVersion = right.version;
12291
- return left.code === right.code && ((_a = left.system) != null ? _a : "http://snomed.info/sct") === ((_b = right.system) != null ? _b : "http://snomed.info/sct") && leftVersion === rightVersion;
12636
+ return left.code === right.code && ((_a2 = left.system) != null ? _a2 : "http://snomed.info/sct") === ((_b = right.system) != null ? _b : "http://snomed.info/sct") && leftVersion === rightVersion;
12292
12637
  }
12293
12638
  function sameOptionalText(left, right) {
12294
12639
  return (left != null ? left : "") === (right != null ? right : "");
@@ -12384,11 +12729,11 @@ function mergePrnReasons(left, right) {
12384
12729
  return result.length ? result : void 0;
12385
12730
  }
12386
12731
  function samePrnLookupRequest(left, right) {
12387
- var _a, _b, _c, _d, _e, _f, _g, _h;
12732
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
12388
12733
  if (!left || !right) {
12389
12734
  return left === right;
12390
12735
  }
12391
- return left.originalText === right.originalText && left.text === right.text && left.normalized === right.normalized && left.canonical === right.canonical && sameOptionalText(left.headCanonical, right.headCanonical) && sameOptionalText(left.locativeSiteCanonical, right.locativeSiteCanonical) && sameCoding(left.locativeSiteCoding, right.locativeSiteCoding) && sameSpatialRelation(left.locativeSiteSpatialRelation, right.locativeSiteSpatialRelation) && left.isProbe === right.isProbe && left.inputText === right.inputText && sameOptionalText(left.sourceText, right.sourceText) && ((_b = (_a = left.range) == null ? void 0 : _a.start) != null ? _b : -1) === ((_d = (_c = right.range) == null ? void 0 : _c.start) != null ? _d : -1) && ((_f = (_e = left.range) == null ? void 0 : _e.end) != null ? _f : -1) === ((_h = (_g = right.range) == null ? void 0 : _g.end) != null ? _h : -1);
12736
+ return left.originalText === right.originalText && left.text === right.text && left.normalized === right.normalized && left.canonical === right.canonical && sameOptionalText(left.headCanonical, right.headCanonical) && sameOptionalText(left.locativeSiteCanonical, right.locativeSiteCanonical) && sameCoding(left.locativeSiteCoding, right.locativeSiteCoding) && sameSpatialRelation(left.locativeSiteSpatialRelation, right.locativeSiteSpatialRelation) && left.isProbe === right.isProbe && left.inputText === right.inputText && sameOptionalText(left.sourceText, right.sourceText) && ((_b = (_a2 = left.range) == null ? void 0 : _a2.start) != null ? _b : -1) === ((_d = (_c = right.range) == null ? void 0 : _c.start) != null ? _d : -1) && ((_f = (_e = left.range) == null ? void 0 : _e.end) != null ? _f : -1) === ((_h = (_g = right.range) == null ? void 0 : _g.end) != null ? _h : -1);
12392
12737
  }
12393
12738
  function mergePrnLookupRequests(left, right) {
12394
12739
  const result = [];
@@ -12471,7 +12816,7 @@ function mergeSchedule(left, right) {
12471
12816
  };
12472
12817
  }
12473
12818
  function unifySynsem(left, right, context) {
12474
- var _a;
12819
+ var _a2;
12475
12820
  const method = mergeMethod(left.head.method, right.head.method);
12476
12821
  if (method === void 0 && left.head.method && right.head.method) {
12477
12822
  return void 0;
@@ -12513,7 +12858,7 @@ function unifySynsem(left, right, context) {
12513
12858
  )
12514
12859
  },
12515
12860
  cont: {
12516
- clauseKind: (_a = left.cont.clauseKind) != null ? _a : right.cont.clauseKind
12861
+ clauseKind: (_a2 = left.cont.clauseKind) != null ? _a2 : right.cont.clauseKind
12517
12862
  }
12518
12863
  };
12519
12864
  }
@@ -12648,8 +12993,10 @@ var ADMINISTRATION_METHOD_WORDS = /* @__PURE__ */ new Set([
12648
12993
  "spray",
12649
12994
  "take",
12650
12995
  "drink",
12996
+ "inhale",
12651
12997
  "swallow",
12652
12998
  "use",
12999
+ "inject",
12653
13000
  "insert",
12654
13001
  "instill",
12655
13002
  "reapply",
@@ -13010,12 +13357,12 @@ function annotateLexTokens(tokens) {
13010
13357
  return tokens.map((token) => annotateLexToken(token));
13011
13358
  }
13012
13359
  function hasTokenWordClass(token, wordClass) {
13013
- var _a;
13014
- return Boolean(((_a = token == null ? void 0 : token.annotations) == null ? void 0 : _a.wordClasses) && arrayIncludes(token.annotations.wordClasses, wordClass));
13360
+ var _a2;
13361
+ return Boolean(((_a2 = token == null ? void 0 : token.annotations) == null ? void 0 : _a2.wordClasses) && arrayIncludes(token.annotations.wordClasses, wordClass));
13015
13362
  }
13016
13363
  function getDayOfWeekMeaning(token) {
13017
- var _a;
13018
- if ((_a = token == null ? void 0 : token.annotations) == null ? void 0 : _a.dayOfWeek) {
13364
+ var _a2;
13365
+ if ((_a2 = token == null ? void 0 : token.annotations) == null ? void 0 : _a2.dayOfWeek) {
13019
13366
  return token.annotations.dayOfWeek.slice();
13020
13367
  }
13021
13368
  if (!token) {
@@ -13024,8 +13371,8 @@ function getDayOfWeekMeaning(token) {
13024
13371
  return resolveDayMeaning(token.lower);
13025
13372
  }
13026
13373
  function getRouteMeaning(token) {
13027
- var _a, _b;
13028
- if ((_b = (_a = token == null ? void 0 : token.annotations) == null ? void 0 : _a.routeCandidates) == null ? void 0 : _b.length) {
13374
+ var _a2, _b;
13375
+ if ((_b = (_a2 = token == null ? void 0 : token.annotations) == null ? void 0 : _a2.routeCandidates) == null ? void 0 : _b.length) {
13029
13376
  return token.annotations.routeCandidates[0];
13030
13377
  }
13031
13378
  if (!token) {
@@ -13037,8 +13384,8 @@ function getRouteMeaning(token) {
13037
13384
  }) : void 0;
13038
13385
  }
13039
13386
  function getSiteMeaningCandidates(token) {
13040
- var _a, _b;
13041
- if ((_b = (_a = token == null ? void 0 : token.annotations) == null ? void 0 : _a.siteCandidates) == null ? void 0 : _b.length) {
13387
+ var _a2, _b;
13388
+ if ((_b = (_a2 = token == null ? void 0 : token.annotations) == null ? void 0 : _a2.siteCandidates) == null ? void 0 : _b.length) {
13042
13389
  return token.annotations.siteCandidates.slice();
13043
13390
  }
13044
13391
  if (!token) {
@@ -13189,6 +13536,7 @@ function pad2(value) {
13189
13536
  return value < 10 ? `0${value}` : String(value);
13190
13537
  }
13191
13538
  function parseClockToken(token, meridiemToken) {
13539
+ var _a2;
13192
13540
  if (!token) {
13193
13541
  return void 0;
13194
13542
  }
@@ -13196,6 +13544,9 @@ function parseClockToken(token, meridiemToken) {
13196
13544
  if (lower.startsWith("@")) {
13197
13545
  lower = lower.slice(1);
13198
13546
  }
13547
+ if (token.derived && ((_a2 = token.sourceText) == null ? void 0 : _a2.includes("/")) && /^[0-9]+(?:\.[0-9]+)?$/.test(lower)) {
13548
+ return void 0;
13549
+ }
13199
13550
  const meridiem = meridiemToken ? normalizeTokenLower(meridiemToken) : void 0;
13200
13551
  let hour;
13201
13552
  let minute = 0;
@@ -13304,7 +13655,7 @@ function emptySynsem() {
13304
13655
  };
13305
13656
  }
13306
13657
  function lexicalSign(args) {
13307
- var _a, _b;
13658
+ var _a2, _b;
13308
13659
  const tokenIndices = args.tokens.map((token) => token.index).filter((index) => Number.isFinite(index));
13309
13660
  if (!tokenIndices.length) {
13310
13661
  throw new Error(`Cannot build lexical sign for ${args.rule} without token indices.`);
@@ -13316,7 +13667,7 @@ function lexicalSign(args) {
13316
13667
  span: { start, end },
13317
13668
  tokens: args.tokens,
13318
13669
  synsem: args.synsem,
13319
- consumedTokenIndices: (_a = args.consumedTokenIndices) != null ? _a : tokenIndices,
13670
+ consumedTokenIndices: (_a2 = args.consumedTokenIndices) != null ? _a2 : tokenIndices,
13320
13671
  siteTokenIndices: args.siteTokenIndices,
13321
13672
  warnings: args.warnings,
13322
13673
  evidence: [
@@ -13346,8 +13697,8 @@ function timingCodeForDailyFrequency(value) {
13346
13697
  }
13347
13698
  function multiplicativeDoseFrequencyRule() {
13348
13699
  return lexicalRule("hpsg.lex.doseFrequency.multiplicative", (context, start) => {
13349
- var _a;
13350
- const first = (_a = tokensAvailable(context, start, 1)) == null ? void 0 : _a[0];
13700
+ var _a2;
13701
+ const first = (_a2 = tokensAvailable(context, start, 1)) == null ? void 0 : _a2[0];
13351
13702
  if (!first) {
13352
13703
  return [];
13353
13704
  }
@@ -13477,8 +13828,8 @@ function compactIntervalRule() {
13477
13828
  }
13478
13829
  function separatedIntervalRule() {
13479
13830
  return lexicalRule("hpsg.lex.schedule.separatedInterval", (context, start) => {
13480
- var _a;
13481
- const lead = (_a = tokensAvailable(context, start, 1)) == null ? void 0 : _a[0];
13831
+ var _a2;
13832
+ const lead = (_a2 = tokensAvailable(context, start, 1)) == null ? void 0 : _a2[0];
13482
13833
  if (!lead || !EVERY_INTERVAL_TOKENS.has(normalizeTokenLower(lead))) {
13483
13834
  return [];
13484
13835
  }
@@ -13579,8 +13930,8 @@ function separatedIntervalRule() {
13579
13930
  }
13580
13931
  function countFrequencyRule() {
13581
13932
  return lexicalRule("hpsg.lex.schedule.frequency", (context, start) => {
13582
- var _a, _b, _c, _d;
13583
- const token = (_a = tokensAvailable(context, start, 1)) == null ? void 0 : _a[0];
13933
+ var _a2, _b, _c, _d;
13934
+ const token = (_a2 = tokensAvailable(context, start, 1)) == null ? void 0 : _a2[0];
13584
13935
  if (!token) {
13585
13936
  return [];
13586
13937
  }
@@ -13709,8 +14060,8 @@ function countFrequencyRule() {
13709
14060
  }
13710
14061
  function timingLexicalRule() {
13711
14062
  return lexicalRule("hpsg.lex.schedule.timing", (context, start) => {
13712
- var _a;
13713
- const token = (_a = tokensAvailable(context, start, 1)) == null ? void 0 : _a[0];
14063
+ var _a2;
14064
+ const token = (_a2 = tokensAvailable(context, start, 1)) == null ? void 0 : _a2[0];
13714
14065
  if (!token) {
13715
14066
  return [];
13716
14067
  }
@@ -13801,16 +14152,16 @@ function timingLexicalRule() {
13801
14152
  });
13802
14153
  }
13803
14154
  function mealTimingForRelation(relation, meal) {
13804
- var _a;
13805
- return (_a = MEAL_TIMING_BY_RELATION.get(relation)) == null ? void 0 : _a.get(meal);
14155
+ var _a2;
14156
+ return (_a2 = MEAL_TIMING_BY_RELATION.get(relation)) == null ? void 0 : _a2.get(meal);
13806
14157
  }
13807
14158
  function mealRelationFromToken(lower) {
13808
14159
  return MEAL_RELATION_BY_TOKEN.get(lower);
13809
14160
  }
13810
14161
  function eventTimingPhraseRule() {
13811
14162
  return lexicalRule("hpsg.lex.schedule.eventPhrase", (context, start) => {
13812
- var _a;
13813
- const first = (_a = tokensAvailable(context, start, 1)) == null ? void 0 : _a[0];
14163
+ var _a2;
14164
+ const first = (_a2 = tokensAvailable(context, start, 1)) == null ? void 0 : _a2[0];
13814
14165
  if (!first) {
13815
14166
  return [];
13816
14167
  }
@@ -13959,8 +14310,8 @@ function expandDayRange(startDay, endDay) {
13959
14310
  }
13960
14311
  function dayRangeLexicalRule() {
13961
14312
  return lexicalRule("hpsg.lex.schedule.dayRange", (context, start) => {
13962
- var _a;
13963
- const first = (_a = tokensAvailable(context, start, 1)) == null ? void 0 : _a[0];
14313
+ var _a2;
14314
+ const first = (_a2 = tokensAvailable(context, start, 1)) == null ? void 0 : _a2[0];
13964
14315
  if (!first) {
13965
14316
  return [];
13966
14317
  }
@@ -14029,8 +14380,8 @@ function dayRangeLexicalRule() {
14029
14380
  }
14030
14381
  function countAndDurationRule() {
14031
14382
  return lexicalRule("hpsg.lex.schedule.limit", (context, start) => {
14032
- var _a, _b;
14033
- const token = (_a = tokensAvailable(context, start, 1)) == null ? void 0 : _a[0];
14383
+ var _a2, _b;
14384
+ const token = (_a2 = tokensAvailable(context, start, 1)) == null ? void 0 : _a2[0];
14034
14385
  if (!token) {
14035
14386
  return [];
14036
14387
  }
@@ -14238,57 +14589,180 @@ function isScheduleLead(context, index) {
14238
14589
  return false;
14239
14590
  }
14240
14591
 
14592
+ // src/unit-terminology.json
14593
+ var unit_terminology_default = {
14594
+ terms: [
14595
+ { unit: "mg", kind: "metric" },
14596
+ { unit: "g", kind: "metric" },
14597
+ { unit: "kg", kind: "metric" },
14598
+ { unit: "mcg", kind: "metric" },
14599
+ { unit: "ug", kind: "metric" },
14600
+ { unit: "microg", kind: "metric" },
14601
+ { unit: "ng", kind: "metric" },
14602
+ { unit: "mL", kind: "metric" },
14603
+ { unit: "L", kind: "metric" },
14604
+ { unit: "dL", kind: "metric" },
14605
+ { unit: "mcL", kind: "metric" },
14606
+ { unit: "uL", kind: "metric" },
14607
+ { unit: "nL", kind: "metric" },
14608
+ { unit: "cm3", kind: "metric" },
14609
+ { unit: "tsp", kind: "metric", aliases: ["teaspoon"] },
14610
+ { unit: "tbsp", kind: "metric", aliases: ["tablespoon"] },
14611
+ { unit: "U", kind: "biologic_unit", aliases: ["unit", "units"] },
14612
+ { unit: "IU", kind: "biologic_unit", aliases: ["iu", "ius"] },
14613
+ { unit: "puff", kind: "device_actuation", aliases: ["puffs", "inhalation", "inhalations"] },
14614
+ { unit: "spray", kind: "device_actuation", aliases: ["sprays"] },
14615
+ { unit: "pump", kind: "device_actuation", aliases: ["pumps"] },
14616
+ { unit: "actuation", kind: "device_actuation", aliases: ["actuations"] },
14617
+ {
14618
+ unit: "drop",
14619
+ kind: "product_specific_amount",
14620
+ aliases: ["drops", "gtt", "gtts", "eyedrop", "eyedrops"],
14621
+ approximateQuantity: {
14622
+ value: 0.05,
14623
+ unit: "mL",
14624
+ confidence: "approximate",
14625
+ basis: "Generic ophthalmic drop default; product/dropper-specific values should override this",
14626
+ source: "https://pmc.ncbi.nlm.nih.gov/articles/PMC3217709/"
14627
+ }
14628
+ },
14629
+ { unit: "dropperful", kind: "product_specific_amount", aliases: ["dropperfuls"] },
14630
+ {
14631
+ unit: "drop/min",
14632
+ kind: "infusion_rate",
14633
+ aliases: ["drops/min", "gtt/min", "gtts/min", "drop per minute", "drops per minute"],
14634
+ parseAsDose: false
14635
+ },
14636
+ { unit: "applicatorful", kind: "product_specific_amount", aliases: ["applicatorfuls", "applicator", "applicators", "full applicator", "full applicators"] },
14637
+ { unit: "capful", kind: "product_specific_amount", aliases: ["capfuls", "cap to line", "cap filled to line"] },
14638
+ { unit: "scoop", kind: "product_specific_amount", aliases: ["scoops"] },
14639
+ {
14640
+ unit: "pea-sized amount",
14641
+ kind: "product_specific_amount",
14642
+ aliases: [
14643
+ "pea sized amount",
14644
+ "pea-sized",
14645
+ "pea sized",
14646
+ "pea size amount",
14647
+ "pea-size amount",
14648
+ "\u0E40\u0E21\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27",
14649
+ "\u0E40\u0E21\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27\u0E40\u0E02\u0E35\u0E22\u0E27",
14650
+ "\u0E40\u0E21\u0E25\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27",
14651
+ "\u0E02\u0E19\u0E32\u0E14\u0E40\u0E21\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27",
14652
+ "\u0E02\u0E19\u0E32\u0E14\u0E40\u0E21\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27\u0E40\u0E02\u0E35\u0E22\u0E27",
14653
+ "\u0E02\u0E19\u0E32\u0E14\u0E40\u0E21\u0E25\u0E47\u0E14\u0E16\u0E31\u0E48\u0E27"
14654
+ ],
14655
+ approximateQuantity: {
14656
+ value: 0.25,
14657
+ unit: "mL",
14658
+ confidence: "approximate",
14659
+ basis: "Generic pea-sized volume proxy; product labels may define mass and should override when known",
14660
+ source: "https://www.accessdata.fda.gov/drugsatfda_docs/nda/2000/21-108_Renova_Medr_P1.pdf"
14661
+ }
14662
+ },
14663
+ {
14664
+ unit: "shot glass",
14665
+ kind: "product_specific_amount",
14666
+ aliases: ["shotglass", "shot glasses"],
14667
+ approximateQuantity: {
14668
+ value: 29.5735,
14669
+ unit: "mL",
14670
+ confidence: "approximate",
14671
+ basis: "AAD sunscreen full-body adult amount: about 1 ounce, roughly a shot glass",
14672
+ source: "https://www.aad.org/media/stats-sunscreen"
14673
+ }
14674
+ },
14675
+ { unit: "finger length", kind: "product_specific_amount", aliases: ["finger lengths", "two-finger rule", "two finger rule", "two-finger method", "two finger method"] },
14676
+ {
14677
+ unit: "FTU",
14678
+ kind: "product_specific_amount",
14679
+ aliases: ["ftu", "ftus", "f.t.u", "f.t.u.", "fingertip unit", "fingertip units"],
14680
+ approximateQuantity: {
14681
+ value: 0.5,
14682
+ unit: "g",
14683
+ confidence: "approximate",
14684
+ basis: "DermNet adult male fingertip unit default",
14685
+ source: "https://dermnetnz.org/topics/fingertip-unit"
14686
+ }
14687
+ },
14688
+ { unit: "cm ribbon", kind: "length_of_product" },
14689
+ { unit: "inch ribbon", kind: "length_of_product", aliases: ["inch strip"] },
14690
+ { unit: "cm strip", kind: "length_of_product" },
14691
+ { unit: "cm line", kind: "length_of_product" },
14692
+ { unit: "inch line", kind: "length_of_product" },
14693
+ { unit: "palm", kind: "body_area_proxy", aliases: ["palms"] },
14694
+ { unit: "handprint", kind: "body_area_proxy", aliases: ["handprints", "hand print", "hand prints"] },
14695
+ { unit: "% BSA", kind: "body_area_proxy", aliases: ["%BSA", "% TBSA", "%TBSA", "percent BSA", "percent TBSA"] },
14696
+ { unit: "tab", kind: "counted_presentation", aliases: ["tablet"] },
14697
+ { unit: "cap", kind: "counted_presentation", aliases: ["capsule"] },
14698
+ { unit: "patch", kind: "counted_presentation", aliases: ["patches", "system", "systems", "transdermal system", "transdermal systems"] },
14699
+ { unit: "ring", kind: "counted_presentation", aliases: ["rings"] },
14700
+ { unit: "suppository", kind: "counted_presentation", aliases: ["suppositories"] },
14701
+ { unit: "pessary", kind: "counted_presentation", aliases: ["pessaries"] },
14702
+ { unit: "insert", kind: "counted_presentation", aliases: ["inserts"] },
14703
+ { unit: "ovule", kind: "counted_presentation", aliases: ["ovules"] },
14704
+ { unit: "enema", kind: "counted_presentation", aliases: ["enemas"] },
14705
+ { unit: "swab", kind: "counted_presentation", aliases: ["swabs"] },
14706
+ { unit: "pad", kind: "counted_presentation", aliases: ["pads"] },
14707
+ { unit: "wipe", kind: "counted_presentation", aliases: ["wipes"] },
14708
+ { unit: "stick", kind: "counted_presentation", aliases: ["sticks"] },
14709
+ { unit: "stick-pack", kind: "counted_presentation", aliases: ["stick pack", "stick packs", "stick-packs"] },
14710
+ { unit: "implant", kind: "counted_presentation", aliases: ["implants"] },
14711
+ { unit: "pellet", kind: "counted_presentation", aliases: ["pellets"] },
14712
+ { unit: "lozenge", kind: "counted_presentation", aliases: ["lozenges"] },
14713
+ { unit: "troche", kind: "counted_presentation", aliases: ["troches"] },
14714
+ { unit: "wafer", kind: "counted_presentation", aliases: ["wafers"] },
14715
+ { unit: "film", kind: "counted_presentation", aliases: ["films"] },
14716
+ { unit: "strip", kind: "counted_presentation", aliases: ["strips"] },
14717
+ { unit: "softgel", kind: "counted_presentation", aliases: ["softgels"] },
14718
+ { unit: "tube", kind: "counted_presentation", aliases: ["tubes"] },
14719
+ { unit: "bottle", kind: "counted_presentation", aliases: ["bottles"] },
14720
+ { unit: "container", kind: "counted_presentation", aliases: ["containers"] },
14721
+ { unit: "jar", kind: "counted_presentation", aliases: ["jars"] },
14722
+ { unit: "packet", kind: "counted_presentation", aliases: ["packets"] },
14723
+ { unit: "sachet", kind: "counted_presentation", aliases: ["sachets"] },
14724
+ { unit: "vial", kind: "counted_presentation", aliases: ["vials", "unit-dose vial", "unit-dose vials", "unit dose vial", "unit dose vials"] },
14725
+ { unit: "ampule", kind: "counted_presentation", aliases: ["amp", "amps", "ampules", "ampoule", "ampoules"] },
14726
+ { unit: "nebule", kind: "counted_presentation", aliases: ["nebules"] },
14727
+ { unit: "respule", kind: "counted_presentation", aliases: ["respules"] },
14728
+ { unit: "syringe", kind: "counted_presentation", aliases: ["syringes"] },
14729
+ { unit: "pen", kind: "counted_presentation", aliases: ["pens"] },
14730
+ { unit: "cartridge", kind: "counted_presentation", aliases: ["cartridges"] },
14731
+ { unit: "canister", kind: "counted_presentation", aliases: ["canisters"] },
14732
+ { unit: "blister", kind: "counted_presentation", aliases: ["blisters"] },
14733
+ { unit: "bag", kind: "counted_presentation", aliases: ["bags"] },
14734
+ { unit: "pod", kind: "counted_presentation", aliases: ["pods"] },
14735
+ { unit: "click", kind: "device_actuation", aliases: ["clicks", "pen click", "pen clicks", "dial click", "dial clicks"] }
14736
+ ]
14737
+ };
14738
+
14241
14739
  // src/unit-lexicon.ts
14242
14740
  var HOUSEHOLD_VOLUME_UNIT_SET = new Set(
14243
14741
  HOUSEHOLD_VOLUME_UNITS.map((unit) => unit.toLowerCase())
14244
14742
  );
14245
- var DISCRETE_UNIT_SET = /* @__PURE__ */ new Set([
14246
- "tab",
14247
- "tabs",
14248
- "tablet",
14249
- "tablets",
14250
- "cap",
14251
- "caps",
14252
- "capsule",
14253
- "capsules",
14254
- "puff",
14255
- "puffs",
14256
- "spray",
14257
- "sprays",
14258
- "drop",
14259
- "drops",
14260
- "patch",
14261
- "patches",
14262
- "suppository",
14263
- "suppositories",
14264
- "implant",
14265
- "implants",
14266
- "piece",
14267
- "pieces",
14268
- "stick",
14269
- "sticks",
14270
- "pump",
14271
- "pumps",
14272
- "squeeze",
14273
- "squeezes",
14274
- "applicatorful",
14275
- "applicatorfuls",
14276
- "capful",
14277
- "capfuls",
14278
- "scoop",
14279
- "scoops",
14280
- "application",
14281
- "applications",
14282
- "ribbon",
14283
- "pessary",
14284
- "pessaries",
14285
- "lozenge",
14286
- "lozenges"
14743
+ var DOSE_UNIT_TERMINOLOGY = unit_terminology_default.terms;
14744
+ var DOSE_UNIT_TERMINOLOGY_BY_KEY = /* @__PURE__ */ new Map();
14745
+ var DISCRETE_UNIT_KINDS = /* @__PURE__ */ new Set([
14746
+ "biologic_unit",
14747
+ "counted_presentation",
14748
+ "device_actuation",
14749
+ "product_specific_amount",
14750
+ "length_of_product"
14287
14751
  ]);
14752
+ var _a;
14753
+ for (const entry of DOSE_UNIT_TERMINOLOGY) {
14754
+ const keys = [entry.unit, ...(_a = entry.aliases) != null ? _a : []];
14755
+ for (const key of keys) {
14756
+ const normalized = normalizeUnitKey(key);
14757
+ if (normalized) {
14758
+ DOSE_UNIT_TERMINOLOGY_BY_KEY.set(normalized, entry);
14759
+ }
14760
+ }
14761
+ }
14288
14762
  function normalizeUnit(token, options) {
14289
- var _a;
14763
+ var _a2;
14290
14764
  const key = token.trim().toLowerCase();
14291
- const override = enforceHouseholdUnitPolicy((_a = options == null ? void 0 : options.unitMap) == null ? void 0 : _a[key], options);
14765
+ const override = enforceHouseholdUnitPolicy((_a2 = options == null ? void 0 : options.unitMap) == null ? void 0 : _a2[key], options);
14292
14766
  if (override) {
14293
14767
  return override;
14294
14768
  }
@@ -14299,8 +14773,80 @@ function normalizeUnit(token, options) {
14299
14773
  if (defaultUnit) {
14300
14774
  return defaultUnit;
14301
14775
  }
14776
+ const terminologyEntry = getDoseUnitTerminologyEntry(token);
14777
+ const terminologyUnit = (terminologyEntry == null ? void 0 : terminologyEntry.parseAsDose) === false ? void 0 : terminologyEntry == null ? void 0 : terminologyEntry.unit;
14778
+ const policyCheckedTerminologyUnit = enforceHouseholdUnitPolicy(terminologyUnit, options);
14779
+ if (policyCheckedTerminologyUnit) {
14780
+ return policyCheckedTerminologyUnit;
14781
+ }
14302
14782
  return void 0;
14303
14783
  }
14784
+ function normalizeUnitKey(unit) {
14785
+ const normalized = unit == null ? void 0 : unit.trim();
14786
+ return normalized ? normalized.toLowerCase() : void 0;
14787
+ }
14788
+ function unitApproximationOverride(unit, context) {
14789
+ const entries = context == null ? void 0 : context.unitApproximationMap;
14790
+ if (!entries) {
14791
+ return void 0;
14792
+ }
14793
+ const unitKey = normalizeUnitKey(unit);
14794
+ for (const candidateUnit in entries) {
14795
+ if (!Object.prototype.hasOwnProperty.call(entries, candidateUnit)) {
14796
+ continue;
14797
+ }
14798
+ const approximation = entries[candidateUnit];
14799
+ if (normalizeUnitKey(candidateUnit) === unitKey) {
14800
+ return approximation;
14801
+ }
14802
+ }
14803
+ return void 0;
14804
+ }
14805
+ function getDoseUnitTerminologyEntry(unit) {
14806
+ var _a2;
14807
+ if (!unit) {
14808
+ return void 0;
14809
+ }
14810
+ return DOSE_UNIT_TERMINOLOGY_BY_KEY.get((_a2 = normalizeUnitKey(unit)) != null ? _a2 : "");
14811
+ }
14812
+ function getDoseUnitKind(unit) {
14813
+ var _a2;
14814
+ return (_a2 = getDoseUnitTerminologyEntry(unit)) == null ? void 0 : _a2.kind;
14815
+ }
14816
+ function getDoseUnitApproximation(unit, context) {
14817
+ var _a2, _b;
14818
+ if (!unit) {
14819
+ return void 0;
14820
+ }
14821
+ const terminologyEntry = getDoseUnitTerminologyEntry(unit);
14822
+ const override = (_b = unitApproximationOverride(unit, context)) != null ? _b : unitApproximationOverride((_a2 = terminologyEntry == null ? void 0 : terminologyEntry.unit) != null ? _a2 : "", context);
14823
+ if (override) {
14824
+ return override;
14825
+ }
14826
+ return terminologyEntry == null ? void 0 : terminologyEntry.approximateQuantity;
14827
+ }
14828
+ function getDoseUnitSemantics(unit, context) {
14829
+ if (!unit) {
14830
+ return void 0;
14831
+ }
14832
+ const terminologyEntry = getDoseUnitTerminologyEntry(unit);
14833
+ if (!terminologyEntry) {
14834
+ return void 0;
14835
+ }
14836
+ return {
14837
+ unit: terminologyEntry.unit,
14838
+ kind: terminologyEntry.kind,
14839
+ parseAsDose: terminologyEntry.parseAsDose,
14840
+ approximateQuantity: getDoseUnitApproximation(unit, context)
14841
+ };
14842
+ }
14843
+ function listDoseUnitTerminology() {
14844
+ return DOSE_UNIT_TERMINOLOGY.map((entry) => __spreadProps(__spreadValues({}, entry), {
14845
+ aliases: entry.aliases ? [...entry.aliases] : void 0,
14846
+ parseAsDose: entry.parseAsDose,
14847
+ approximateQuantity: entry.approximateQuantity ? __spreadValues({}, entry.approximateQuantity) : void 0
14848
+ }));
14849
+ }
14304
14850
  function enforceHouseholdUnitPolicy(unit, options) {
14305
14851
  if (unit && (options == null ? void 0 : options.allowHouseholdVolumeUnits) === false && HOUSEHOLD_VOLUME_UNIT_SET.has(unit.toLowerCase())) {
14306
14852
  return void 0;
@@ -14311,7 +14857,8 @@ function isDiscreteUnit(unit) {
14311
14857
  if (!unit) {
14312
14858
  return false;
14313
14859
  }
14314
- return DISCRETE_UNIT_SET.has(unit.trim().toLowerCase());
14860
+ const semantics = getDoseUnitSemantics(unit);
14861
+ return Boolean(semantics && DISCRETE_UNIT_KINDS.has(semantics.kind));
14315
14862
  }
14316
14863
 
14317
14864
  // src/hpsg/method-lexicon.ts
@@ -14320,6 +14867,8 @@ var METHOD_ACTION_BY_VERB = {
14320
14867
  apply: "apply" /* Apply */,
14321
14868
  dab: "apply" /* Apply */,
14322
14869
  drink: "swallow" /* Swallow */,
14870
+ inhale: "inhale" /* Inhale */,
14871
+ inject: "inject" /* Inject */,
14323
14872
  insert: "insert" /* Insert */,
14324
14873
  instill: "instill" /* Instill */,
14325
14874
  lather: "wash" /* Wash */,
@@ -14346,6 +14895,18 @@ var METHOD_CODING_BY_ACTION = {
14346
14895
  display: "Apply",
14347
14896
  _display: buildTranslationPrimitiveElement({ th: "\u0E17\u0E32" })
14348
14897
  },
14898
+ ["inhale" /* Inhale */]: {
14899
+ system: SNOMED_SYSTEM6,
14900
+ code: "740666001",
14901
+ display: "Inhale",
14902
+ _display: buildTranslationPrimitiveElement({ th: "\u0E2A\u0E39\u0E14" })
14903
+ },
14904
+ ["inject" /* Inject */]: {
14905
+ system: SNOMED_SYSTEM6,
14906
+ code: "740685003",
14907
+ display: "Inject",
14908
+ _display: buildTranslationPrimitiveElement({ th: "\u0E09\u0E35\u0E14" })
14909
+ },
14349
14910
  ["insert" /* Insert */]: {
14350
14911
  system: SNOMED_SYSTEM6,
14351
14912
  code: "738993004",
@@ -14391,12 +14952,12 @@ function cloneMethodCoding(coding) {
14391
14952
 
14392
14953
  // src/hpsg/rules/product-route.ts
14393
14954
  function productRouteHint(phrase) {
14394
- var _a;
14955
+ var _a2;
14395
14956
  const key = (phrase != null ? phrase : "").trim().replace(/\s+/g, " ").toLowerCase();
14396
14957
  if (!key) {
14397
14958
  return void 0;
14398
14959
  }
14399
- const direct = (_a = PRODUCT_FORM_HINTS[key]) == null ? void 0 : _a.routeHint;
14960
+ const direct = (_a2 = PRODUCT_FORM_HINTS[key]) == null ? void 0 : _a2.routeHint;
14400
14961
  if (direct) {
14401
14962
  return direct;
14402
14963
  }
@@ -14415,23 +14976,23 @@ function isKnownPrnReasonText(text) {
14415
14976
  return Boolean(canonical && DEFAULT_PRN_REASON_DEFINITIONS[canonical]);
14416
14977
  }
14417
14978
  function normalizeLocatedReasonHead(text) {
14418
- var _a;
14979
+ var _a2;
14419
14980
  const canonical = normalizePrnReasonKey(text);
14420
14981
  if (!canonical) {
14421
14982
  return void 0;
14422
14983
  }
14423
- return (_a = PRN_GENERIC_LOCATED_HEADS.get(canonical)) != null ? _a : canonical;
14984
+ return (_a2 = PRN_GENERIC_LOCATED_HEADS.get(canonical)) != null ? _a2 : canonical;
14424
14985
  }
14425
14986
  function isLocatedReasonHead(text) {
14426
14987
  const canonical = normalizeLocatedReasonHead(text);
14427
14988
  return Boolean(canonical && (DEFAULT_PRN_REASON_DEFINITIONS[canonical] || PRN_GENERIC_LOCATED_HEADS.has(canonical)));
14428
14989
  }
14429
14990
  function normalizePredicativeReasonText(text) {
14430
- var _a, _b;
14431
- return (_b = PRN_PREDICATE_REASON_NORMALIZATIONS.get((_a = normalizePrnReasonKey(text)) != null ? _a : "")) != null ? _b : text;
14991
+ var _a2, _b;
14992
+ return (_b = PRN_PREDICATE_REASON_NORMALIZATIONS.get((_a2 = normalizePrnReasonKey(text)) != null ? _a2 : "")) != null ? _b : text;
14432
14993
  }
14433
14994
  function canStartPrnReasonAtom(context, start) {
14434
- var _a, _b, _c;
14995
+ var _a2, _b, _c;
14435
14996
  const first = context.tokens[start];
14436
14997
  if (!first || context.state.consumed.has(first.index)) {
14437
14998
  return false;
@@ -14455,7 +15016,7 @@ function canStartPrnReasonAtom(context, start) {
14455
15016
  return true;
14456
15017
  }
14457
15018
  }
14458
- const resolvedSite = resolveBodySitePhrase(first.original, (_a = context.options) == null ? void 0 : _a.siteCodeMap, {
15019
+ const resolvedSite = resolveBodySitePhrase(first.original, (_a2 = context.options) == null ? void 0 : _a2.siteCodeMap, {
14459
15020
  bodySiteContext: (_c = (_b = context.options) == null ? void 0 : _b.context) == null ? void 0 : _c.bodySiteContext
14460
15021
  });
14461
15022
  return Boolean((resolvedSite == null ? void 0 : resolvedSite.coding) || (resolvedSite == null ? void 0 : resolvedSite.definition));
@@ -14478,7 +15039,7 @@ function canContinuePrnReasonAfterSeparator(context, index) {
14478
15039
  return false;
14479
15040
  }
14480
15041
  function startsDosageSiteComplement(context, start) {
14481
- var _a, _b, _c;
15042
+ var _a2, _b, _c;
14482
15043
  const anchor = context.tokens[start];
14483
15044
  if (!anchor || !PRN_CONDITIONAL_SITE_BOUNDARY_ANCHORS.has(normalizeTokenLower(anchor))) {
14484
15045
  return false;
@@ -14497,7 +15058,7 @@ function startsDosageSiteComplement(context, start) {
14497
15058
  displayTokens.push(token);
14498
15059
  }
14499
15060
  const sourceText = joinTokenText(displayTokens).replace(/[{}]/g, "").trim();
14500
- if (sourceText && resolveBodySitePhrase(sourceText, (_a = context.options) == null ? void 0 : _a.siteCodeMap, {
15061
+ if (sourceText && resolveBodySitePhrase(sourceText, (_a2 = context.options) == null ? void 0 : _a2.siteCodeMap, {
14501
15062
  bodySiteContext: (_c = (_b = context.options) == null ? void 0 : _b.context) == null ? void 0 : _c.bodySiteContext
14502
15063
  })) {
14503
15064
  return true;
@@ -14526,7 +15087,7 @@ function splitPrnReasonParts(tokens) {
14526
15087
  return parts;
14527
15088
  }
14528
15089
  function createPrnReasonRequest(context, text, tokens, headText, siteText) {
14529
- var _a, _b, _c, _d, _e, _f, _g, _h;
15090
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
14530
15091
  const range = rangeFromTokens(tokens);
14531
15092
  const rawText = joinTokenText(tokens);
14532
15093
  const isProbe = rawText.includes("{") || rawText.includes("}");
@@ -14534,7 +15095,7 @@ function createPrnReasonRequest(context, text, tokens, headText, siteText) {
14534
15095
  if (isProbe && range) {
14535
15096
  let start = range.start;
14536
15097
  let end = range.end;
14537
- while (start < end && /[\s{]/.test((_a = context.state.input[start]) != null ? _a : "")) {
15098
+ while (start < end && /[\s{]/.test((_a2 = context.state.input[start]) != null ? _a2 : "")) {
14538
15099
  start += 1;
14539
15100
  }
14540
15101
  while (end > start && /[\s}]/.test((_b = context.state.input[end - 1]) != null ? _b : "")) {
@@ -14576,7 +15137,7 @@ function createPrnReasonRequest(context, text, tokens, headText, siteText) {
14576
15137
  };
14577
15138
  }
14578
15139
  function parseLocatedPrnAtom(context, tokens, previousLocatedHead, options) {
14579
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
15140
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
14580
15141
  const directText = joinTokenText(tokens);
14581
15142
  const cleanDirectText = directText.replace(/[{}]/g, "").replace(/\s+/g, " ").trim();
14582
15143
  if (!cleanDirectText) {
@@ -14601,7 +15162,7 @@ function parseLocatedPrnAtom(context, tokens, previousLocatedHead, options) {
14601
15162
  const headText = joinTokenText(tokens.slice(0, index));
14602
15163
  const normalizedHead = normalizePredicativeReasonText(headText);
14603
15164
  const siteText = joinTokenText(tokens.slice(index));
14604
- if (isLocatedReasonHead(normalizedHead) && resolveBodySitePhrase(siteText, (_a = context.options) == null ? void 0 : _a.siteCodeMap, {
15165
+ if (isLocatedReasonHead(normalizedHead) && resolveBodySitePhrase(siteText, (_a2 = context.options) == null ? void 0 : _a2.siteCodeMap, {
14605
15166
  bodySiteContext: (_c = (_b = context.options) == null ? void 0 : _b.context) == null ? void 0 : _c.bodySiteContext
14606
15167
  })) {
14607
15168
  return createPrnReasonRequest(context, cleanDirectText, tokens, normalizedHead, siteText);
@@ -14653,8 +15214,8 @@ function parsePrnReasonAtoms(context, reasonTokens, options) {
14653
15214
  }
14654
15215
  function prnLexicalRule() {
14655
15216
  return lexicalRule("hpsg.lex.prn", (context, start) => {
14656
- var _a, _b;
14657
- const lead = (_a = tokensAvailable(context, start, 1)) == null ? void 0 : _a[0];
15217
+ var _a2, _b;
15218
+ const lead = (_a2 = tokensAvailable(context, start, 1)) == null ? void 0 : _a2[0];
14658
15219
  if (!lead) {
14659
15220
  return [];
14660
15221
  }
@@ -14768,7 +15329,7 @@ function prnLexicalRule() {
14768
15329
  var INSTRUCTION_PREDICATES = ["take", "apply", "use"];
14769
15330
  function workflowLexicalRule() {
14770
15331
  return lexicalRule("hpsg.lex.patientInstruction.workflow", (context, start) => {
14771
- var _a, _b;
15332
+ var _a2, _b;
14772
15333
  let cursor = start;
14773
15334
  const consumed = [];
14774
15335
  while (cursor < context.limit) {
@@ -14808,7 +15369,7 @@ function workflowLexicalRule() {
14808
15369
  if (bodyTokens.length && isInstructionSeparator(token)) {
14809
15370
  break;
14810
15371
  }
14811
- if (bodyTokens.length && isScheduleLead(context, cursor) && !(((_a = bodyTokens[bodyTokens.length - 1]) == null ? void 0 : _a.kind) === "NUMBER" /* Number */ && mapIntervalUnit(lower)) && !WORKFLOW_CONTINUATION_LICENSES.has(`${previousLower} ${lower}`) && !(previousLower && WORKFLOW_CONTINUATION_LICENSES.has(`${previousLower} *event`) && EVENT_TIMING_TOKENS[lower]) && !WORKFLOW_CONTINUATION_LICENSES.has(`${lower} ${nextLower}`)) {
15372
+ if (bodyTokens.length && isScheduleLead(context, cursor) && !(((_a2 = bodyTokens[bodyTokens.length - 1]) == null ? void 0 : _a2.kind) === "NUMBER" /* Number */ && mapIntervalUnit(lower)) && !WORKFLOW_CONTINUATION_LICENSES.has(`${previousLower} ${lower}`) && !(previousLower && WORKFLOW_CONTINUATION_LICENSES.has(`${previousLower} *event`) && EVENT_TIMING_TOKENS[lower]) && !WORKFLOW_CONTINUATION_LICENSES.has(`${lower} ${nextLower}`)) {
14812
15373
  break;
14813
15374
  }
14814
15375
  if (LIST_SEPARATORS.has(lower) && bodyTokens.length && !WORKFLOW_NOUNS.has(normalizeTokenLower((_b = context.tokens[cursor + 1]) != null ? _b : token))) {
@@ -14869,8 +15430,8 @@ function parseInstructionCandidates(text, range) {
14869
15430
  }));
14870
15431
  const score = instructions.reduce(
14871
15432
  (sum, instruction) => {
14872
- var _a, _b;
14873
- return sum + (((_a = instruction.coding) == null ? void 0 : _a.code) ? 4 : 0) + (((_b = instruction.frames) == null ? void 0 : _b.length) ? 2 : 0) + (instruction.text ? 1 : 0);
15433
+ var _a2, _b;
15434
+ return sum + (((_a2 = instruction.coding) == null ? void 0 : _a2.code) ? 4 : 0) + (((_b = instruction.frames) == null ? void 0 : _b.length) ? 2 : 0) + (instruction.text ? 1 : 0);
14874
15435
  },
14875
15436
  0
14876
15437
  );
@@ -14881,6 +15442,23 @@ function parseInstructionCandidates(text, range) {
14881
15442
  }
14882
15443
  return best;
14883
15444
  }
15445
+ function bodyParsesAsStyleInstruction(context, bodyTokens) {
15446
+ const range = rangeFromTokens(bodyTokens);
15447
+ const text = range ? context.state.input.slice(range.start, range.end).replace(/\s+/g, " ").trim() : joinTokenText(bodyTokens);
15448
+ if (!range || !text) {
15449
+ return false;
15450
+ }
15451
+ return parseInstructionCandidates(text, range).some(
15452
+ (instruction) => {
15453
+ var _a2;
15454
+ return (_a2 = instruction.frames) == null ? void 0 : _a2.some(
15455
+ (frame) => !frame.relation && frame.predicate.semanticClass === "administration" && frame.args.length > 0 && frame.args.every(
15456
+ (arg) => arg.role === "amount" /* Amount */ || arg.role === "free" /* Free */
15457
+ )
15458
+ );
15459
+ }
15460
+ );
15461
+ }
14884
15462
  function instructionLexicalRule() {
14885
15463
  return lexicalRule("hpsg.lex.instruction", (context, start) => {
14886
15464
  const first = context.tokens[start];
@@ -14915,6 +15493,9 @@ function instructionLexicalRule() {
14915
15493
  if (bodyTokens.length && isScheduleLead(context, cursor)) {
14916
15494
  break;
14917
15495
  }
15496
+ if (bodyTokens.length && SITE_ANCHORS.has(normalizeTokenLower(token)) && bodyParsesAsStyleInstruction(context, bodyTokens)) {
15497
+ break;
15498
+ }
14918
15499
  bodyTokens.push(token);
14919
15500
  }
14920
15501
  if (!bodyTokens.length) {
@@ -14931,8 +15512,8 @@ function instructionLexicalRule() {
14931
15512
  }
14932
15513
  const hasStructuredInstruction = instructions.some(
14933
15514
  (instruction) => {
14934
- var _a, _b;
14935
- return ((_a = instruction.coding) == null ? void 0 : _a.code) || ((_b = instruction.frames) == null ? void 0 : _b.length);
15515
+ var _a2, _b;
15516
+ return ((_a2 = instruction.coding) == null ? void 0 : _a2.code) || ((_b = instruction.frames) == null ? void 0 : _b.length);
14936
15517
  }
14937
15518
  );
14938
15519
  if (!hasStructuredInstruction && !consumed.length) {
@@ -14956,12 +15537,12 @@ function instructionLexicalRule() {
14956
15537
 
14957
15538
  // src/context.ts
14958
15539
  function normalizeDosageForm(form) {
14959
- var _a;
15540
+ var _a2;
14960
15541
  if (!form) {
14961
15542
  return void 0;
14962
15543
  }
14963
15544
  const key = form.trim().toLowerCase();
14964
- return (_a = KNOWN_DOSAGE_FORMS_TO_DOSE[key]) != null ? _a : key;
15545
+ return (_a2 = KNOWN_DOSAGE_FORMS_TO_DOSE[key]) != null ? _a2 : key;
14965
15546
  }
14966
15547
  function inferUnitFromContext(ctx) {
14967
15548
  if (!ctx) {
@@ -14985,7 +15566,7 @@ function inferUnitFromContext(ctx) {
14985
15566
  return void 0;
14986
15567
  }
14987
15568
  function inferRouteFromContext(ctx) {
14988
- var _a;
15569
+ var _a2;
14989
15570
  if (!(ctx == null ? void 0 : ctx.dosageForm)) {
14990
15571
  return void 0;
14991
15572
  }
@@ -14995,29 +15576,29 @@ function inferRouteFromContext(ctx) {
14995
15576
  }
14996
15577
  const snomed = KNOWN_TMT_DOSAGE_FORM_TO_SNOMED_ROUTE[normalized];
14997
15578
  if (!snomed) {
14998
- return (_a = DEFAULT_ROUTE_SYNONYMS[normalized]) == null ? void 0 : _a.code;
15579
+ return (_a2 = DEFAULT_ROUTE_SYNONYMS[normalized]) == null ? void 0 : _a2.code;
14999
15580
  }
15000
15581
  return ROUTE_BY_SNOMED[snomed];
15001
15582
  }
15002
15583
 
15003
15584
  // src/hpsg/rules/site-rules.ts
15004
15585
  function siteBoundary(lower, context) {
15005
- var _a, _b, _c;
15006
- const siteLike = Boolean(resolveBodySitePhrase(lower, (_a = context.options) == null ? void 0 : _a.siteCodeMap, {
15586
+ var _a2, _b, _c;
15587
+ const siteLike = Boolean(resolveBodySitePhrase(lower, (_a2 = context.options) == null ? void 0 : _a2.siteCodeMap, {
15007
15588
  bodySiteContext: (_c = (_b = context.options) == null ? void 0 : _b.context) == null ? void 0 : _c.bodySiteContext
15008
15589
  }));
15009
- return isPunctuation(lower) || PRN_LEADS.has(lower) || PRN_STANDALONE_REASON_LEADS.has(lower) || DURATION_LEAD_TOKENS.has(lower) || Boolean(
15010
- METHOD_ACTION_BY_VERB[lower] || DEFAULT_ROUTE_SYNONYMS[lower] && !siteLike || productRouteHint(lower) || normalizeUnit(lower, context.options) || TIMING_ABBREVIATIONS[lower] || WORD_FREQUENCIES[lower] || FREQUENCY_SIMPLE_WORDS[lower] !== void 0 || FREQUENCY_NUMBER_WORDS[lower] !== void 0 || FREQUENCY_TIMES_WORDS.has(lower) || EVENT_TIMING_TOKENS[lower] || isClockLikeLower(lower) || isAmPmLower(lower) || EVERY_INTERVAL_TOKENS.has(lower) || mapFrequencyAdverb(lower) || mapIntervalUnit(lower)
15590
+ return isPunctuation(lower) || PRN_LEADS.has(lower) || PRN_STANDALONE_REASON_LEADS.has(lower) || DURATION_LEAD_TOKENS.has(lower) || SITE_TRAILING_INSTRUCTION_WORDS.has(lower) || Boolean(
15591
+ METHOD_ACTION_BY_VERB[lower] || DEFAULT_ROUTE_SYNONYMS[lower] && !siteLike || productRouteHint(lower) || normalizeUnit(lower, context.options) && !siteLike || TIMING_ABBREVIATIONS[lower] || WORD_FREQUENCIES[lower] || FREQUENCY_SIMPLE_WORDS[lower] !== void 0 || FREQUENCY_NUMBER_WORDS[lower] !== void 0 || FREQUENCY_TIMES_WORDS.has(lower) || EVENT_TIMING_TOKENS[lower] || isClockLikeLower(lower) || isAmPmLower(lower) || EVERY_INTERVAL_TOKENS.has(lower) || mapFrequencyAdverb(lower) || mapIntervalUnit(lower)
15011
15592
  );
15012
15593
  }
15013
15594
  function trimBraceRange(input, range) {
15014
- var _a, _b;
15595
+ var _a2, _b;
15015
15596
  if (!range) {
15016
15597
  return void 0;
15017
15598
  }
15018
15599
  let start = range.start;
15019
15600
  let end = range.end;
15020
- while (start < end && /[\s{}]/.test((_a = input[start]) != null ? _a : "")) {
15601
+ while (start < end && /[\s{}]/.test((_a2 = input[start]) != null ? _a2 : "")) {
15021
15602
  start += 1;
15022
15603
  }
15023
15604
  while (end > start && /[\s{}]/.test((_b = input[end - 1]) != null ? _b : "")) {
@@ -15054,8 +15635,8 @@ function hasSystemicCueBeforeSiteAbbreviation(context, start) {
15054
15635
  return sawNonOcularDose;
15055
15636
  }
15056
15637
  function contextSuggestsNonOcularSite(context) {
15057
- var _a, _b, _c, _d, _e, _f;
15058
- const dosageForm = (_c = (_b = (_a = context.options) == null ? void 0 : _a.context) == null ? void 0 : _b.dosageForm) == null ? void 0 : _c.trim().toLowerCase().replace(/\s+/g, " ");
15638
+ var _a2, _b, _c, _d, _e, _f;
15639
+ const dosageForm = (_c = (_b = (_a2 = context.options) == null ? void 0 : _a2.context) == null ? void 0 : _b.dosageForm) == null ? void 0 : _c.trim().toLowerCase().replace(/\s+/g, " ");
15059
15640
  const route = (_f = inferRouteFromContext((_e = (_d = context.options) == null ? void 0 : _d.context) != null ? _e : void 0)) != null ? _f : dosageForm ? productRouteHint(dosageForm) : void 0;
15060
15641
  return Boolean(route && !OCULAR_ROUTE_CODES.has(route));
15061
15642
  }
@@ -15064,8 +15645,8 @@ function shouldSuppressEyeSiteAbbreviation(context, start, lower) {
15064
15645
  }
15065
15646
  function siteLexicalRule() {
15066
15647
  return lexicalRule("hpsg.lex.site", (context, start) => {
15067
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
15068
- const token = (_a = tokensAvailable(context, start, 1)) == null ? void 0 : _a[0];
15648
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
15649
+ const token = (_a2 = tokensAvailable(context, start, 1)) == null ? void 0 : _a2[0];
15069
15650
  if (!token) {
15070
15651
  return [];
15071
15652
  }
@@ -15203,9 +15784,9 @@ function siteLexicalRule() {
15203
15784
  }
15204
15785
  function bareSiteLexicalRule() {
15205
15786
  return lexicalRule("hpsg.lex.site.bare", (context, start) => {
15206
- var _a, _b, _c, _d, _e, _f, _g, _h;
15787
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
15207
15788
  const signs = [];
15208
- const first = (_a = tokensAvailable(context, start, 1)) == null ? void 0 : _a[0];
15789
+ const first = (_a2 = tokensAvailable(context, start, 1)) == null ? void 0 : _a2[0];
15209
15790
  if (!first) {
15210
15791
  return [];
15211
15792
  }
@@ -15280,7 +15861,7 @@ function bareSiteLexicalRule() {
15280
15861
  // src/hpsg/rules/core-rules.ts
15281
15862
  function methodLexicalRule() {
15282
15863
  return lexicalRule("hpsg.lex.method", (context, start) => {
15283
- var _a;
15864
+ var _a2;
15284
15865
  const tokens = tokensAvailable(context, start, 1);
15285
15866
  const token = tokens == null ? void 0 : tokens[0];
15286
15867
  if (!tokens || !token) {
@@ -15291,7 +15872,7 @@ function methodLexicalRule() {
15291
15872
  return [];
15292
15873
  }
15293
15874
  const action = METHOD_ACTION_BY_VERB[verb];
15294
- const route = (_a = getRouteMeaning(token)) != null ? _a : action === "apply" /* Apply */ ? { code: RouteCode["Topical route"], text: ROUTE_TEXT[RouteCode["Topical route"]] } : void 0;
15875
+ const route = (_a2 = getRouteMeaning(token)) != null ? _a2 : action === "apply" /* Apply */ ? { code: RouteCode["Topical route"], text: ROUTE_TEXT[RouteCode["Topical route"]] } : void 0;
15295
15876
  return [
15296
15877
  lexicalSign({
15297
15878
  type: "method-sign",
@@ -15315,7 +15896,7 @@ function methodLexicalRule() {
15315
15896
  }
15316
15897
  function routeLexicalRule() {
15317
15898
  return lexicalRule("hpsg.lex.route", (context, start) => {
15318
- var _a;
15899
+ var _a2;
15319
15900
  const signs = [];
15320
15901
  const maxSpan = Math.min(24, context.limit - start);
15321
15902
  for (let span = maxSpan; span >= 1; span -= 1) {
@@ -15332,13 +15913,13 @@ function routeLexicalRule() {
15332
15913
  }
15333
15914
  const routeCandidates = routePhraseCandidates(phrase);
15334
15915
  const customCode = routeCandidates.map((candidate) => {
15335
- var _a2, _b;
15336
- return (_b = (_a2 = context.options) == null ? void 0 : _a2.routeMap) == null ? void 0 : _b[candidate];
15916
+ var _a3, _b;
15917
+ return (_b = (_a3 = context.options) == null ? void 0 : _a3.routeMap) == null ? void 0 : _b[candidate];
15337
15918
  }).find((code) => Boolean(code));
15338
15919
  const tokenRoute = span === 1 ? getRouteMeaning(tokens[0]) : void 0;
15339
15920
  const routeFromSitePreposition = routeFromSitePrepositionPhrase(tokens, context);
15340
15921
  const synonym = routeCandidates.map((candidate) => DEFAULT_ROUTE_SYNONYMS[candidate]).find(Boolean);
15341
- const route = customCode ? { code: customCode, text: ROUTE_TEXT[customCode] } : (_a = tokenRoute != null ? tokenRoute : synonym) != null ? _a : routeFromSitePreposition;
15922
+ const route = customCode ? { code: customCode, text: ROUTE_TEXT[customCode] } : (_a2 = tokenRoute != null ? tokenRoute : synonym) != null ? _a2 : routeFromSitePreposition;
15342
15923
  if (!route) {
15343
15924
  continue;
15344
15925
  }
@@ -15365,7 +15946,7 @@ function routeLexicalRule() {
15365
15946
  });
15366
15947
  }
15367
15948
  function routeTokenIsPartitiveSiteHead(context, start, span) {
15368
- var _a, _b, _c;
15949
+ var _a2, _b, _c;
15369
15950
  if (span !== 1) {
15370
15951
  return false;
15371
15952
  }
@@ -15385,7 +15966,7 @@ function routeTokenIsPartitiveSiteHead(context, start, span) {
15385
15966
  if (tokens.some((token) => context.state.consumed.has(token.index))) {
15386
15967
  return false;
15387
15968
  }
15388
- const resolved = resolveBodySitePhrase(joinTokenText(tokens), (_a = context.options) == null ? void 0 : _a.siteCodeMap, {
15969
+ const resolved = resolveBodySitePhrase(joinTokenText(tokens), (_a2 = context.options) == null ? void 0 : _a2.siteCodeMap, {
15389
15970
  bodySiteContext: (_c = (_b = context.options) == null ? void 0 : _b.context) == null ? void 0 : _c.bodySiteContext
15390
15971
  });
15391
15972
  if ((resolved == null ? void 0 : resolved.features.kind) === "partitive") {
@@ -15395,12 +15976,12 @@ function routeTokenIsPartitiveSiteHead(context, start, span) {
15395
15976
  return false;
15396
15977
  }
15397
15978
  function routeFromSitePrepositionPhrase(tokens, context) {
15398
- var _a, _b, _c, _d, _e, _f, _g;
15979
+ var _a2, _b, _c, _d, _e, _f, _g;
15399
15980
  if (tokens.length < 2 || !ROUTE_SITE_PREPOSITIONS.has(normalizeTokenLower(tokens[0]))) {
15400
15981
  return void 0;
15401
15982
  }
15402
15983
  const siteText = tokens.slice(1).map((token) => token.original).join(" ");
15403
- const resolved = resolveBodySitePhrase(siteText, (_a = context.options) == null ? void 0 : _a.siteCodeMap, {
15984
+ const resolved = resolveBodySitePhrase(siteText, (_a2 = context.options) == null ? void 0 : _a2.siteCodeMap, {
15404
15985
  bodySiteContext: (_c = (_b = context.options) == null ? void 0 : _b.context) == null ? void 0 : _c.bodySiteContext
15405
15986
  });
15406
15987
  const routeHint = (_g = (_d = resolved == null ? void 0 : resolved.definition) == null ? void 0 : _d.routeHint) != null ? _g : (_f = DEFAULT_BODY_SITE_SNOMED[(_e = resolved == null ? void 0 : resolved.canonical) != null ? _e : ""]) == null ? void 0 : _f.routeHint;
@@ -15421,8 +16002,8 @@ function routePhraseCandidates(phrase) {
15421
16002
  }
15422
16003
  function fillerLexicalRule() {
15423
16004
  return lexicalRule("hpsg.lex.filler.medicationObject", (context, start) => {
15424
- var _a;
15425
- const token = (_a = tokensAvailable(context, start, 1)) == null ? void 0 : _a[0];
16005
+ var _a2;
16006
+ const token = (_a2 = tokensAvailable(context, start, 1)) == null ? void 0 : _a2[0];
15426
16007
  if (!token || !MEDICATION_OBJECT_FILLERS.has(normalizeTokenLower(token))) {
15427
16008
  return [];
15428
16009
  }
@@ -15439,7 +16020,7 @@ function fillerLexicalRule() {
15439
16020
  }
15440
16021
  function productLexicalRule() {
15441
16022
  return lexicalRule("hpsg.lex.product", (context, start) => {
15442
- var _a;
16023
+ var _a2;
15443
16024
  const signs = [];
15444
16025
  const maxSpan = Math.min(4, context.limit - start);
15445
16026
  for (let span = maxSpan; span >= 1; span -= 1) {
@@ -15457,7 +16038,7 @@ function productLexicalRule() {
15457
16038
  }
15458
16039
  const previous = context.tokens[start - 1];
15459
16040
  const previousVerb = previous && METHOD_ACTION_BY_VERB[normalizeTokenLower(previous)] ? normalizeTokenLower(previous) : void 0;
15460
- const methodText = previousVerb ? (_a = PRODUCT_METHOD_TEXT[previousVerb]) == null ? void 0 : _a[phrase] : void 0;
16041
+ const methodText = previousVerb ? (_a2 = PRODUCT_METHOD_TEXT[previousVerb]) == null ? void 0 : _a2[phrase] : void 0;
15461
16042
  signs.push(
15462
16043
  lexicalSign({
15463
16044
  type: "phrase-sign",
@@ -15482,21 +16063,53 @@ function productLexicalRule() {
15482
16063
  return signs;
15483
16064
  });
15484
16065
  }
16066
+ function matchCompoundDoseUnit(context, start, lower) {
16067
+ var _a2;
16068
+ for (const compound of COMPOUND_DOSE_UNITS) {
16069
+ if (compound.head !== lower) {
16070
+ continue;
16071
+ }
16072
+ const sequences = (_a2 = compound.tailSequences) != null ? _a2 : [];
16073
+ for (const sequence of sequences) {
16074
+ const matchedTokens = [];
16075
+ let matched = true;
16076
+ for (let offset = 0; offset < sequence.length; offset += 1) {
16077
+ const candidate = context.tokens[start + 1 + offset];
16078
+ if (!candidate || context.state.consumed.has(candidate.index) || normalizeTokenLower(candidate) !== sequence[offset]) {
16079
+ matched = false;
16080
+ break;
16081
+ }
16082
+ matchedTokens.push(candidate);
16083
+ }
16084
+ if (matched) {
16085
+ const head = context.tokens[start];
16086
+ return head ? { unit: compound.unit, tokens: [head, ...matchedTokens] } : void 0;
16087
+ }
16088
+ }
16089
+ const next = context.tokens[start + 1];
16090
+ if (next && !context.state.consumed.has(next.index)) {
16091
+ const nextLower = normalizeTokenLower(next);
16092
+ if (compound.tails.indexOf(nextLower) !== -1) {
16093
+ const head = context.tokens[start];
16094
+ return head ? { unit: compound.unit, tokens: [head, next] } : void 0;
16095
+ }
16096
+ }
16097
+ }
16098
+ return void 0;
16099
+ }
15485
16100
  function unitAfter(context, start) {
15486
16101
  const token = context.tokens[start];
15487
16102
  if (!token || context.state.consumed.has(token.index)) {
15488
16103
  return void 0;
15489
16104
  }
15490
16105
  const lower = normalizeTokenLower(token);
15491
- const compound = COMPOUND_DOSE_UNITS.find((entry) => entry.head === lower);
16106
+ if (DOSE_UNIT_CONNECTORS.has(lower)) {
16107
+ const nested = unitAfter(context, start + 1);
16108
+ return nested ? { unit: nested.unit, tokens: [token, ...nested.tokens] } : void 0;
16109
+ }
16110
+ const compound = matchCompoundDoseUnit(context, start, lower);
15492
16111
  if (compound) {
15493
- const next = context.tokens[start + 1];
15494
- if (next && !context.state.consumed.has(next.index)) {
15495
- const nextLower = normalizeTokenLower(next);
15496
- if (compound.tails.indexOf(nextLower) !== -1) {
15497
- return { unit: compound.unit, tokens: [token, next] };
15498
- }
15499
- }
16112
+ return compound;
15500
16113
  }
15501
16114
  const direct = normalizeUnit(lower, context.options);
15502
16115
  if (direct) {
@@ -15504,6 +16117,48 @@ function unitAfter(context, start) {
15504
16117
  }
15505
16118
  return void 0;
15506
16119
  }
16120
+ function doseNumeratorValue(token, lower) {
16121
+ if (token.kind === "NUMBER" /* Number */ && token.value !== void 0) {
16122
+ return token.value;
16123
+ }
16124
+ return DOSE_NUMBER_WORDS.get(lower);
16125
+ }
16126
+ function percentBodyAreaDoseAfter(context, start, lower) {
16127
+ const percentMatch = lower.match(/^([0-9]+(?:\.[0-9]+)?)%$/);
16128
+ if (!percentMatch) {
16129
+ return void 0;
16130
+ }
16131
+ const unitToken = context.tokens[start + 1];
16132
+ if (!unitToken || context.state.consumed.has(unitToken.index)) {
16133
+ return void 0;
16134
+ }
16135
+ const unit = PERCENT_BODY_AREA_UNITS.get(normalizeTokenLower(unitToken));
16136
+ if (!unit) {
16137
+ return void 0;
16138
+ }
16139
+ const token = context.tokens[start];
16140
+ if (!token) {
16141
+ return void 0;
16142
+ }
16143
+ return [
16144
+ lexicalSign({
16145
+ type: "dose-sign",
16146
+ rule: "hpsg.lex.dose.percentBodyArea",
16147
+ tokens: [token, unitToken],
16148
+ synsem: {
16149
+ head: {
16150
+ dose: {
16151
+ value: parseFloat(percentMatch[1]),
16152
+ unit
16153
+ }
16154
+ },
16155
+ valence: {},
16156
+ cont: { clauseKind: "administration" }
16157
+ },
16158
+ score: 10
16159
+ })
16160
+ ];
16161
+ }
15507
16162
  function doseLexicalRule() {
15508
16163
  return lexicalRule("hpsg.lex.dose", (context, start) => {
15509
16164
  const tokens = tokensAvailable(context, start, 1);
@@ -15515,6 +16170,35 @@ function doseLexicalRule() {
15515
16170
  if (isClockDoseContext(context, start, lower)) {
15516
16171
  return [];
15517
16172
  }
16173
+ const percentBodyAreaDose = percentBodyAreaDoseAfter(context, start, lower);
16174
+ if (percentBodyAreaDose) {
16175
+ return percentBodyAreaDose;
16176
+ }
16177
+ const numerator = doseNumeratorValue(token, lower);
16178
+ const denominatorToken = context.tokens[start + 1];
16179
+ const denominatorLower = denominatorToken && !context.state.consumed.has(denominatorToken.index) ? normalizeTokenLower(denominatorToken) : void 0;
16180
+ const denominator = denominatorLower ? DOSE_FRACTION_DENOMINATOR_WORDS.get(denominatorLower) : void 0;
16181
+ if (numerator !== void 0 && denominatorToken && denominator !== void 0) {
16182
+ const unit2 = unitAfter(context, start + 2);
16183
+ return [
16184
+ lexicalSign({
16185
+ type: "dose-sign",
16186
+ rule: "hpsg.lex.dose.wordFractionNumerator",
16187
+ tokens: unit2 ? [token, denominatorToken, ...unit2.tokens] : [token, denominatorToken],
16188
+ synsem: {
16189
+ head: {
16190
+ dose: {
16191
+ value: numerator * denominator,
16192
+ unit: unit2 == null ? void 0 : unit2.unit
16193
+ }
16194
+ },
16195
+ valence: {},
16196
+ cont: { clauseKind: "administration" }
16197
+ },
16198
+ score: unit2 ? 10 : 5
16199
+ })
16200
+ ];
16201
+ }
15518
16202
  const range = parseNumericRange(lower);
15519
16203
  if (range) {
15520
16204
  const unit2 = unitAfter(context, start + 1);
@@ -15559,6 +16243,49 @@ function doseLexicalRule() {
15559
16243
  })
15560
16244
  ];
15561
16245
  }
16246
+ const wordFraction = DOSE_FRACTION_WORDS.get(lower);
16247
+ if (wordFraction !== void 0) {
16248
+ const unit2 = unitAfter(context, start + 1);
16249
+ return [
16250
+ lexicalSign({
16251
+ type: "dose-sign",
16252
+ rule: "hpsg.lex.dose.wordFraction",
16253
+ tokens: unit2 ? [...tokens, ...unit2.tokens] : tokens,
16254
+ synsem: {
16255
+ head: {
16256
+ dose: {
16257
+ value: wordFraction,
16258
+ unit: unit2 == null ? void 0 : unit2.unit
16259
+ }
16260
+ },
16261
+ valence: {},
16262
+ cont: { clauseKind: "administration" }
16263
+ },
16264
+ score: unit2 ? 9 : 4
16265
+ })
16266
+ ];
16267
+ }
16268
+ const implicitUnit = unitAfter(context, start);
16269
+ if (implicitUnit && IMPLICIT_SINGLE_DOSE_UNITS.has(implicitUnit.unit)) {
16270
+ return [
16271
+ lexicalSign({
16272
+ type: "dose-sign",
16273
+ rule: "hpsg.lex.dose.implicitSingleUnit",
16274
+ tokens: implicitUnit.tokens,
16275
+ synsem: {
16276
+ head: {
16277
+ dose: {
16278
+ value: 1,
16279
+ unit: implicitUnit.unit
16280
+ }
16281
+ },
16282
+ valence: {},
16283
+ cont: { clauseKind: "administration" }
16284
+ },
16285
+ score: 9
16286
+ })
16287
+ ];
16288
+ }
15562
16289
  if (token.kind !== "NUMBER" /* Number */ || token.value === void 0) {
15563
16290
  const timesMatch = lower.match(/^([0-9]+(?:\.[0-9]+)?)[x*]$/);
15564
16291
  if (!timesMatch) {
@@ -15639,8 +16366,8 @@ function isClockDoseContext(context, start, lower) {
15639
16366
  }
15640
16367
  function connectorLexicalRule() {
15641
16368
  return lexicalRule("hpsg.lex.connector", (context, start) => {
15642
- var _a;
15643
- const token = (_a = tokensAvailable(context, start, 1)) == null ? void 0 : _a[0];
16369
+ var _a2;
16370
+ const token = (_a2 = tokensAvailable(context, start, 1)) == null ? void 0 : _a2[0];
15644
16371
  if (!token) {
15645
16372
  return [];
15646
16373
  }
@@ -15693,13 +16420,13 @@ function buildGrammar(context) {
15693
16420
  };
15694
16421
  }
15695
16422
  function hasUsefulAnalysis(sign) {
15696
- var _a;
16423
+ var _a2;
15697
16424
  if (!sign) {
15698
16425
  return false;
15699
16426
  }
15700
16427
  const { head, valence } = sign.synsem;
15701
16428
  return Boolean(
15702
- head.method || head.route || head.dose || head.schedule || valence.site || valence.prn || ((_a = valence.instructions) == null ? void 0 : _a.length) || valence.patientInstruction
16429
+ head.method || head.route || head.dose || head.schedule || valence.site || valence.prn || ((_a2 = valence.instructions) == null ? void 0 : _a2.length) || valence.patientInstruction
15703
16430
  );
15704
16431
  }
15705
16432
  function parseHpsgClause(context) {
@@ -15745,7 +16472,7 @@ function applyRouteDefault(state, context, deps) {
15745
16472
  }
15746
16473
  }
15747
16474
  function applyUnitDefault(state, tokens, context, options) {
15748
- var _a;
16475
+ var _a2;
15749
16476
  if (state.unit !== void 0 || state.dose === void 0 && state.doseRange === void 0) {
15750
16477
  return;
15751
16478
  }
@@ -15760,12 +16487,12 @@ function applyUnitDefault(state, tokens, context, options) {
15760
16487
  return;
15761
16488
  }
15762
16489
  }
15763
- state.unit = (_a = enforceHouseholdUnitPolicy(inferUnitFromContext(context), options)) != null ? _a : enforceHouseholdUnitPolicy(inferUnitFromRoute(state), options);
16490
+ state.unit = (_a2 = enforceHouseholdUnitPolicy(inferUnitFromContext(context), options)) != null ? _a2 : enforceHouseholdUnitPolicy(inferUnitFromRoute(state), options);
15764
16491
  }
15765
16492
  function applySingleDoseDefault(state, options) {
15766
- var _a, _b;
16493
+ var _a2, _b;
15767
16494
  if ((options == null ? void 0 : options.assumeSingleDiscreteDose) && state.unit === void 0) {
15768
- state.unit = (_b = enforceHouseholdUnitPolicy(inferUnitFromContext((_a = options.context) != null ? _a : void 0), options)) != null ? _b : enforceHouseholdUnitPolicy(inferUnitFromRoute(state), options);
16495
+ state.unit = (_b = enforceHouseholdUnitPolicy(inferUnitFromContext((_a2 = options.context) != null ? _a2 : void 0), options)) != null ? _b : enforceHouseholdUnitPolicy(inferUnitFromRoute(state), options);
15769
16496
  }
15770
16497
  if ((options == null ? void 0 : options.assumeSingleDiscreteDose) && state.dose === void 0 && state.doseRange === void 0 && state.unit !== void 0 && isDiscreteUnit(state.unit)) {
15771
16498
  state.dose = 1;
@@ -15779,14 +16506,14 @@ var ROUTE_REDUNDANT_SITE_CODES = {
15779
16506
  [RouteCode["Oral route"]]: /* @__PURE__ */ new Set(["123851003"])
15780
16507
  };
15781
16508
  function applyRouteSiteDefault(state) {
15782
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
16509
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
15783
16510
  if (!state.routeCode) {
15784
16511
  return;
15785
16512
  }
15786
16513
  const redundantCodes = ROUTE_REDUNDANT_SITE_CODES[state.routeCode];
15787
16514
  if (state.siteText && redundantCodes) {
15788
16515
  const currentDefinition = DEFAULT_BODY_SITE_SNOMED[state.siteText.trim().toLowerCase()];
15789
- const currentCode = (_c = (_a = state.siteCoding) == null ? void 0 : _a.code) != null ? _c : (_b = currentDefinition == null ? void 0 : currentDefinition.coding) == null ? void 0 : _b.code;
16516
+ const currentCode = (_c = (_a2 = state.siteCoding) == null ? void 0 : _a2.code) != null ? _c : (_b = currentDefinition == null ? void 0 : currentDefinition.coding) == null ? void 0 : _b.code;
15790
16517
  if (currentCode && redundantCodes.has(currentCode)) {
15791
16518
  state.siteText = void 0;
15792
16519
  state.siteCoding = void 0;
@@ -15821,9 +16548,9 @@ function applyRouteSiteDefault(state) {
15821
16548
  }
15822
16549
  }
15823
16550
  function hasStructuredTiming(state) {
15824
- var _a;
16551
+ var _a2;
15825
16552
  return Boolean(
15826
- state.count !== void 0 || state.duration !== void 0 || state.durationMax !== void 0 || state.durationUnit !== void 0 || state.frequency !== void 0 || state.frequencyMax !== void 0 || state.period !== void 0 || state.periodMax !== void 0 || state.periodUnit !== void 0 || state.timingCode !== void 0 || state.dayOfWeek.length || state.when.length || ((_a = state.timeOfDay) == null ? void 0 : _a.length)
16553
+ state.count !== void 0 || state.duration !== void 0 || state.durationMax !== void 0 || state.durationUnit !== void 0 || state.frequency !== void 0 || state.frequencyMax !== void 0 || state.period !== void 0 || state.periodMax !== void 0 || state.periodUnit !== void 0 || state.timingCode !== void 0 || state.dayOfWeek.length || state.when.length || ((_a2 = state.timeOfDay) == null ? void 0 : _a2.length)
15827
16554
  );
15828
16555
  }
15829
16556
  function addWarning(state, warning) {
@@ -15917,10 +16644,10 @@ function normalizedFormSet(values) {
15917
16644
  return result;
15918
16645
  }
15919
16646
  function smartMealExpansionAllowed(state, options) {
15920
- var _a, _b, _c;
16647
+ var _a2, _b, _c;
15921
16648
  const scope = options.smartMealExpansionScope;
15922
16649
  const route = state.routeCode;
15923
- const dosageForm = normalizeDosageForm((_a = options.context) == null ? void 0 : _a.dosageForm);
16650
+ const dosageForm = normalizeDosageForm((_a2 = options.context) == null ? void 0 : _a2.dosageForm);
15924
16651
  const excludedRoutes = new Set((_b = scope == null ? void 0 : scope.excludeRoutes) != null ? _b : []);
15925
16652
  const includedRoutes = new Set((_c = scope == null ? void 0 : scope.includeRoutes) != null ? _c : []);
15926
16653
  const excludedForms = normalizedFormSet(scope == null ? void 0 : scope.excludeDosageForms);
@@ -15946,8 +16673,8 @@ function mealPair(options) {
15946
16673
  return options.twoPerDayPair === "breakfast+lunch" ? ["CM" /* Breakfast */, "CD" /* Lunch */] : ["CM" /* Breakfast */, "CV" /* Dinner */];
15947
16674
  }
15948
16675
  function relationForContext(options) {
15949
- var _a;
15950
- const relation = (_a = options.context) == null ? void 0 : _a.mealRelation;
16676
+ var _a2;
16677
+ const relation = (_a2 = options.context) == null ? void 0 : _a2.mealRelation;
15951
16678
  return relation === "AC" /* Before Meal */ || relation === "PC" /* After Meal */ || relation === "C" /* Meal */ ? relation : "C" /* Meal */;
15952
16679
  }
15953
16680
  function expandRelationByFrequency(relation, frequency, options) {
@@ -15957,13 +16684,13 @@ function expandRelationByFrequency(relation, frequency, options) {
15957
16684
  const baseMeals = frequency === 1 ? ["CM" /* Breakfast */] : frequency === 2 ? [...mealPair(options)] : frequency === 3 ? [...WITH_MEALS] : [...WITH_MEALS, "HS" /* Before Sleep */];
15958
16685
  const related = MEAL_RELATION_CODES[relation];
15959
16686
  return baseMeals.map((meal) => {
15960
- var _a;
16687
+ var _a2;
15961
16688
  const index = SPECIFIC_MEAL_INDEX[meal];
15962
- return index === void 0 ? meal : (_a = related[index]) != null ? _a : meal;
16689
+ return index === void 0 ? meal : (_a2 = related[index]) != null ? _a2 : meal;
15963
16690
  });
15964
16691
  }
15965
16692
  function normalizeMealRelations(when, options) {
15966
- var _a;
16693
+ var _a2;
15967
16694
  let relation;
15968
16695
  for (const code of when) {
15969
16696
  if (code === "AC" /* Before Meal */ || code === "PC" /* After Meal */ || code === "C" /* Meal */) {
@@ -15990,7 +16717,7 @@ function normalizeMealRelations(when, options) {
15990
16717
  continue;
15991
16718
  }
15992
16719
  const index = SPECIFIC_MEAL_INDEX[code];
15993
- normalized.push(index === void 0 ? code : (_a = related[index]) != null ? _a : code);
16720
+ normalized.push(index === void 0 ? code : (_a2 = related[index]) != null ? _a2 : code);
15994
16721
  }
15995
16722
  return normalized.length ? normalized : when;
15996
16723
  }
@@ -16002,8 +16729,8 @@ function clockMinutes(clock) {
16002
16729
  return parseInt(match[1], 10) * 60 + parseInt(match[2], 10);
16003
16730
  }
16004
16731
  function sortWhenCodes(when, options) {
16005
- var _a;
16006
- const clock = __spreadValues(__spreadValues({}, DEFAULT_EVENT_CLOCK), (_a = options == null ? void 0 : options.eventClock) != null ? _a : {});
16732
+ var _a2;
16733
+ const clock = __spreadValues(__spreadValues({}, DEFAULT_EVENT_CLOCK), (_a2 = options == null ? void 0 : options.eventClock) != null ? _a2 : {});
16007
16734
  return when.map((code, index) => ({ code, index })).sort((left, right) => {
16008
16735
  const diff = clockMinutes(clock[left.code]) - clockMinutes(clock[right.code]);
16009
16736
  return diff || left.index - right.index;
@@ -16059,15 +16786,15 @@ function applySmartMealExpansion(state, options) {
16059
16786
  replaceWhen(state, sortWhenCodes(uniqueWhen(normalizeMealRelations(when, options)), options));
16060
16787
  }
16061
16788
  function applyWeeklyDefaultForDayFilters(state) {
16062
- var _a;
16063
- if (state.dayOfWeek.length && state.frequency === void 0 && state.frequencyMax === void 0 && state.period === void 0 && state.periodMax === void 0 && state.periodUnit === void 0 && !state.when.length && !((_a = state.timeOfDay) == null ? void 0 : _a.length)) {
16789
+ var _a2;
16790
+ if (state.dayOfWeek.length && state.frequency === void 0 && state.frequencyMax === void 0 && state.period === void 0 && state.periodMax === void 0 && state.periodUnit === void 0 && !state.when.length && !((_a2 = state.timeOfDay) == null ? void 0 : _a2.length)) {
16064
16791
  state.period = 1;
16065
16792
  state.periodUnit = "wk" /* Week */;
16066
16793
  }
16067
16794
  }
16068
16795
  function applyHpsgDefaultConstraints(state, tokens, options, deps) {
16069
- var _a;
16070
- const context = (_a = options == null ? void 0 : options.context) != null ? _a : void 0;
16796
+ var _a2;
16797
+ const context = (_a2 = options == null ? void 0 : options.context) != null ? _a2 : void 0;
16071
16798
  applyRouteDefault(state, context, deps);
16072
16799
  applyUnitDefault(state, tokens, context, options);
16073
16800
  applySingleDoseDefault(state, options);
@@ -16087,15 +16814,15 @@ function pushUniqueCanonical(canonicals, value) {
16087
16814
  canonicals.push(normalized);
16088
16815
  }
16089
16816
  function pushUniqueCoding(codings, coding) {
16090
- var _a;
16817
+ var _a2;
16091
16818
  if (!(coding == null ? void 0 : coding.code)) {
16092
16819
  return;
16093
16820
  }
16094
- const system = (_a = coding.system) != null ? _a : SNOMED_SYSTEM7;
16821
+ const system = (_a2 = coding.system) != null ? _a2 : SNOMED_SYSTEM7;
16095
16822
  if (codings.some(
16096
16823
  (candidate) => {
16097
- var _a2;
16098
- return candidate.code === coding.code && ((_a2 = candidate.system) != null ? _a2 : SNOMED_SYSTEM7) === system;
16824
+ var _a3;
16825
+ return candidate.code === coding.code && ((_a3 = candidate.system) != null ? _a3 : SNOMED_SYSTEM7) === system;
16099
16826
  }
16100
16827
  )) {
16101
16828
  return;
@@ -16132,10 +16859,10 @@ function pushResolvedSite(canonicals, codings, value) {
16132
16859
  pushSpatialRelationTarget(canonicals, codings, resolvedSite.spatialRelation);
16133
16860
  }
16134
16861
  function collectParsedBodySiteCandidates(internal) {
16135
- var _a, _b, _c, _d;
16862
+ var _a2, _b, _c, _d;
16136
16863
  const canonicals = [];
16137
16864
  const codings = [];
16138
- const normalizedSiteText = normalizeBodySiteKey((_a = internal.siteText) != null ? _a : "");
16865
+ const normalizedSiteText = normalizeBodySiteKey((_a2 = internal.siteText) != null ? _a2 : "");
16139
16866
  const siteCodingDisplay = (_b = internal.siteCoding) == null ? void 0 : _b.display;
16140
16867
  const normalizedSiteCodingDisplay = siteCodingDisplay ? normalizeBodySiteKey(siteCodingDisplay) : "";
16141
16868
  pushResolvedSite(
@@ -16208,8 +16935,8 @@ function collectPrnReasonLookupCanonicals(request) {
16208
16935
  return canonicals;
16209
16936
  }
16210
16937
  function buildPostcoordinatedPrnReasonDefinition(request, definition, hasExactCombinedDefinition) {
16211
- var _a, _b;
16212
- if (hasExactCombinedDefinition || !((_a = definition == null ? void 0 : definition.coding) == null ? void 0 : _a.code) || hasSnomedFindingSitePostcoordination(definition.coding.code) || !request.headCanonical || !((_b = request.locativeSiteCoding) == null ? void 0 : _b.code)) {
16938
+ var _a2, _b;
16939
+ if (hasExactCombinedDefinition || !((_a2 = definition == null ? void 0 : definition.coding) == null ? void 0 : _a2.code) || hasSnomedFindingSitePostcoordination(definition.coding.code) || !request.headCanonical || !((_b = request.locativeSiteCoding) == null ? void 0 : _b.code)) {
16213
16940
  return definition;
16214
16941
  }
16215
16942
  const coding = buildSnomedFindingSiteCoding({
@@ -16339,12 +17066,12 @@ function pickPrnReasonSelection(selections, request) {
16339
17066
  return void 0;
16340
17067
  }
16341
17068
  function applyPrnReasonDefinition(internal, definition) {
16342
- var _a;
17069
+ var _a2;
16343
17070
  const coding = definition.coding;
16344
17071
  internal.asNeededReasonCoding = (coding == null ? void 0 : coding.code) ? {
16345
17072
  code: coding.code,
16346
17073
  display: coding.display,
16347
- system: (_a = coding.system) != null ? _a : SNOMED_SYSTEM8,
17074
+ system: (_a2 = coding.system) != null ? _a2 : SNOMED_SYSTEM8,
16348
17075
  extension: cloneExtensions(coding.extension),
16349
17076
  i18n: definition == null ? void 0 : definition.i18n
16350
17077
  } : void 0;
@@ -16471,7 +17198,7 @@ function splitCoordinatedPrnReasonText(text) {
16471
17198
  return void 0;
16472
17199
  }
16473
17200
  function maybeApplyCoordinatedPrnReasonsSync(internal, options) {
16474
- var _a, _b;
17201
+ var _a2, _b;
16475
17202
  const text = internal.asNeededReason;
16476
17203
  if (!text || internal.asNeededReasonCoding) {
16477
17204
  return;
@@ -16486,7 +17213,7 @@ function maybeApplyCoordinatedPrnReasonsSync(internal, options) {
16486
17213
  const definition = resolvePrnReasonDefinitionSyncForRequest(internal, request, options);
16487
17214
  reasons.push({
16488
17215
  text: part,
16489
- coding: ((_a = definition == null ? void 0 : definition.coding) == null ? void 0 : _a.code) ? {
17216
+ coding: ((_a2 = definition == null ? void 0 : definition.coding) == null ? void 0 : _a2.code) ? {
16490
17217
  code: definition.coding.code,
16491
17218
  display: definition.coding.display,
16492
17219
  system: (_b = definition.coding.system) != null ? _b : SNOMED_SYSTEM8,
@@ -16499,7 +17226,7 @@ function maybeApplyCoordinatedPrnReasonsSync(internal, options) {
16499
17226
  }
16500
17227
  function maybeApplyCoordinatedPrnReasonsAsync(internal, options) {
16501
17228
  return __async(this, null, function* () {
16502
- var _a, _b;
17229
+ var _a2, _b;
16503
17230
  const text = internal.asNeededReason;
16504
17231
  if (!text || internal.asNeededReasonCoding) {
16505
17232
  return;
@@ -16514,7 +17241,7 @@ function maybeApplyCoordinatedPrnReasonsAsync(internal, options) {
16514
17241
  const definition = yield resolvePrnReasonDefinitionAsyncForRequest(internal, request, options);
16515
17242
  reasons.push({
16516
17243
  text: part,
16517
- coding: ((_a = definition == null ? void 0 : definition.coding) == null ? void 0 : _a.code) ? {
17244
+ coding: ((_a2 = definition == null ? void 0 : definition.coding) == null ? void 0 : _a2.code) ? {
16518
17245
  code: definition.coding.code,
16519
17246
  display: definition.coding.display,
16520
17247
  system: (_b = definition.coding.system) != null ? _b : SNOMED_SYSTEM8,
@@ -16527,11 +17254,11 @@ function maybeApplyCoordinatedPrnReasonsAsync(internal, options) {
16527
17254
  });
16528
17255
  }
16529
17256
  function uniquePrnReasonRequests(requests) {
16530
- var _a, _b, _c, _d;
17257
+ var _a2, _b, _c, _d;
16531
17258
  const result = [];
16532
17259
  const seen = /* @__PURE__ */ new Set();
16533
17260
  for (const request of requests != null ? requests : []) {
16534
- const key = `${(_b = (_a = request.range) == null ? void 0 : _a.start) != null ? _b : ""}:${(_d = (_c = request.range) == null ? void 0 : _c.end) != null ? _d : ""}:${request.text}`;
17261
+ const key = `${(_b = (_a2 = request.range) == null ? void 0 : _a2.start) != null ? _b : ""}:${(_d = (_c = request.range) == null ? void 0 : _c.end) != null ? _d : ""}:${request.text}`;
16535
17262
  if (seen.has(key)) {
16536
17263
  continue;
16537
17264
  }
@@ -16541,20 +17268,20 @@ function uniquePrnReasonRequests(requests) {
16541
17268
  return result;
16542
17269
  }
16543
17270
  function codingFromPrnDefinition(definition) {
16544
- var _a;
17271
+ var _a2;
16545
17272
  const coding = definition == null ? void 0 : definition.coding;
16546
17273
  return (coding == null ? void 0 : coding.code) ? {
16547
17274
  code: coding.code,
16548
17275
  display: coding.display,
16549
- system: (_a = coding.system) != null ? _a : SNOMED_SYSTEM8,
17276
+ system: (_a2 = coding.system) != null ? _a2 : SNOMED_SYSTEM8,
16550
17277
  extension: cloneExtensions(coding.extension),
16551
17278
  i18n: definition == null ? void 0 : definition.i18n
16552
17279
  } : void 0;
16553
17280
  }
16554
17281
  function joinPrnReasonTexts(reasons) {
16555
17282
  const texts = reasons.map((reason) => {
16556
- var _a;
16557
- return (_a = reason.text) == null ? void 0 : _a.trim();
17283
+ var _a2;
17284
+ return (_a2 = reason.text) == null ? void 0 : _a2.trim();
16558
17285
  }).filter((text) => Boolean(text));
16559
17286
  switch (texts.length) {
16560
17287
  case 0:
@@ -16615,7 +17342,7 @@ function collectSuggestionsForRequestAsync(internal, request, resolution, option
16615
17342
  });
16616
17343
  }
16617
17344
  function runMultiplePrnReasonResolutionSync(internal, requests, options) {
16618
- var _a;
17345
+ var _a2;
16619
17346
  internal.prnReasonLookups = [];
16620
17347
  internal.asNeeded = true;
16621
17348
  const reasons = [];
@@ -16631,14 +17358,14 @@ function runMultiplePrnReasonResolutionSync(internal, requests, options) {
16631
17358
  internal.asNeededReasons = reasons;
16632
17359
  internal.asNeededReason = joinPrnReasonTexts(reasons);
16633
17360
  if (reasons.length === 1) {
16634
- internal.asNeededReasonCoding = (_a = reasons[0]) == null ? void 0 : _a.coding;
17361
+ internal.asNeededReasonCoding = (_a2 = reasons[0]) == null ? void 0 : _a2.coding;
16635
17362
  } else {
16636
17363
  internal.asNeededReasonCoding = void 0;
16637
17364
  }
16638
17365
  }
16639
17366
  function runMultiplePrnReasonResolutionAsync(internal, requests, options) {
16640
17367
  return __async(this, null, function* () {
16641
- var _a;
17368
+ var _a2;
16642
17369
  internal.prnReasonLookups = [];
16643
17370
  internal.asNeeded = true;
16644
17371
  const reasons = [];
@@ -16654,16 +17381,16 @@ function runMultiplePrnReasonResolutionAsync(internal, requests, options) {
16654
17381
  internal.asNeededReasons = reasons;
16655
17382
  internal.asNeededReason = joinPrnReasonTexts(reasons);
16656
17383
  if (reasons.length === 1) {
16657
- internal.asNeededReasonCoding = (_a = reasons[0]) == null ? void 0 : _a.coding;
17384
+ internal.asNeededReasonCoding = (_a2 = reasons[0]) == null ? void 0 : _a2.coding;
16658
17385
  } else {
16659
17386
  internal.asNeededReasonCoding = void 0;
16660
17387
  }
16661
17388
  });
16662
17389
  }
16663
17390
  function definitionToPrnSuggestion(definition) {
16664
- var _a, _b, _c, _d;
17391
+ var _a2, _b, _c, _d;
16665
17392
  return {
16666
- coding: ((_a = definition.coding) == null ? void 0 : _a.code) ? {
17393
+ coding: ((_a2 = definition.coding) == null ? void 0 : _a2.code) ? {
16667
17394
  code: definition.coding.code,
16668
17395
  display: definition.coding.display,
16669
17396
  system: (_b = definition.coding.system) != null ? _b : SNOMED_SYSTEM8,
@@ -16673,12 +17400,12 @@ function definitionToPrnSuggestion(definition) {
16673
17400
  };
16674
17401
  }
16675
17402
  function addReasonSuggestionToMap(map, suggestion) {
16676
- var _a;
17403
+ var _a2;
16677
17404
  if (!suggestion) {
16678
17405
  return;
16679
17406
  }
16680
17407
  const coding = suggestion.coding;
16681
- const key = (coding == null ? void 0 : coding.code) ? `${(_a = coding.system) != null ? _a : SNOMED_SYSTEM8}|${coding.code}` : suggestion.text ? `text:${suggestion.text.toLowerCase()}` : void 0;
17408
+ const key = (coding == null ? void 0 : coding.code) ? `${(_a2 = coding.system) != null ? _a2 : SNOMED_SYSTEM8}|${coding.code}` : suggestion.text ? `text:${suggestion.text.toLowerCase()}` : void 0;
16682
17409
  if (!key || map.has(key)) {
16683
17410
  return;
16684
17411
  }
@@ -16730,7 +17457,7 @@ function collectDefaultPrnReasonDefinitions(request) {
16730
17457
  return Array.from(seen);
16731
17458
  }
16732
17459
  function runPrnReasonResolutionSync(internal, options) {
16733
- var _a, _b, _c;
17460
+ var _a2, _b, _c;
16734
17461
  const requests = uniquePrnReasonRequests(internal.prnReasonLookupRequests);
16735
17462
  if (requests.length) {
16736
17463
  runMultiplePrnReasonResolutionSync(internal, requests, options);
@@ -16744,7 +17471,7 @@ function runPrnReasonResolutionSync(internal, options) {
16744
17471
  const canonicals = collectPrnReasonLookupCanonicals(request);
16745
17472
  const combinedCanonical = buildCombinedPrnReasonCanonical(request);
16746
17473
  const selection = pickPrnReasonSelection(options == null ? void 0 : options.prnReasonSelections, request);
16747
- const exactCustomDefinition = (_a = lookupPrnReasonDefinition(options == null ? void 0 : options.prnReasonMap, request.canonical)) != null ? _a : lookupPrnReasonDefinition(options == null ? void 0 : options.prnReasonMap, combinedCanonical != null ? combinedCanonical : "");
17474
+ const exactCustomDefinition = (_a2 = lookupPrnReasonDefinition(options == null ? void 0 : options.prnReasonMap, request.canonical)) != null ? _a2 : lookupPrnReasonDefinition(options == null ? void 0 : options.prnReasonMap, combinedCanonical != null ? combinedCanonical : "");
16748
17475
  const customDefinition = lookupPrnReasonDefinition(options == null ? void 0 : options.prnReasonMap, canonicals);
16749
17476
  const inferredDefinition = inferSiteSpecificPrnReasonDefinition(internal, request);
16750
17477
  let resolution = selection != null ? selection : customDefinition;
@@ -16825,7 +17552,7 @@ function runPrnReasonResolutionSync(internal, options) {
16825
17552
  }
16826
17553
  function runPrnReasonResolutionAsync(internal, options) {
16827
17554
  return __async(this, null, function* () {
16828
- var _a, _b, _c;
17555
+ var _a2, _b, _c;
16829
17556
  const requests = uniquePrnReasonRequests(internal.prnReasonLookupRequests);
16830
17557
  if (requests.length) {
16831
17558
  yield runMultiplePrnReasonResolutionAsync(internal, requests, options);
@@ -16839,7 +17566,7 @@ function runPrnReasonResolutionAsync(internal, options) {
16839
17566
  const canonicals = collectPrnReasonLookupCanonicals(request);
16840
17567
  const combinedCanonical = buildCombinedPrnReasonCanonical(request);
16841
17568
  const selection = pickPrnReasonSelection(options == null ? void 0 : options.prnReasonSelections, request);
16842
- const exactCustomDefinition = (_a = lookupPrnReasonDefinition(options == null ? void 0 : options.prnReasonMap, request.canonical)) != null ? _a : lookupPrnReasonDefinition(options == null ? void 0 : options.prnReasonMap, combinedCanonical != null ? combinedCanonical : "");
17569
+ const exactCustomDefinition = (_a2 = lookupPrnReasonDefinition(options == null ? void 0 : options.prnReasonMap, request.canonical)) != null ? _a2 : lookupPrnReasonDefinition(options == null ? void 0 : options.prnReasonMap, combinedCanonical != null ? combinedCanonical : "");
16843
17570
  const customDefinition = lookupPrnReasonDefinition(options == null ? void 0 : options.prnReasonMap, canonicals);
16844
17571
  const inferredDefinition = inferSiteSpecificPrnReasonDefinition(internal, request);
16845
17572
  let resolution = selection != null ? selection : customDefinition;
@@ -17123,12 +17850,12 @@ function pickSiteSelection(selections, request) {
17123
17850
  return void 0;
17124
17851
  }
17125
17852
  function applySiteDefinition(internal, definition) {
17126
- var _a, _b, _c;
17853
+ var _a2, _b, _c;
17127
17854
  const coding = definition.coding;
17128
17855
  internal.siteCoding = (coding == null ? void 0 : coding.code) ? {
17129
17856
  code: coding.code,
17130
17857
  display: coding.display,
17131
- system: (_a = coding.system) != null ? _a : SNOMED_SYSTEM9
17858
+ system: (_a2 = coding.system) != null ? _a2 : SNOMED_SYSTEM9
17132
17859
  } : void 0;
17133
17860
  if (definition.text) {
17134
17861
  internal.siteText = definition.text;
@@ -17142,12 +17869,12 @@ function applySiteDefinition(internal, definition) {
17142
17869
  }
17143
17870
  }
17144
17871
  function definitionToSuggestion(definition, omitRedundantText = false) {
17145
- var _a, _b;
17872
+ var _a2, _b;
17146
17873
  const coding = definition.coding;
17147
17874
  if (!(coding == null ? void 0 : coding.code)) {
17148
17875
  return void 0;
17149
17876
  }
17150
- const text = omitRedundantText && definition.text && definition.text.trim().toLowerCase() !== ((_a = coding.display) == null ? void 0 : _a.trim().toLowerCase()) ? definition.text : omitRedundantText ? void 0 : definition.text;
17877
+ const text = omitRedundantText && definition.text && definition.text.trim().toLowerCase() !== ((_a2 = coding.display) == null ? void 0 : _a2.trim().toLowerCase()) ? definition.text : omitRedundantText ? void 0 : definition.text;
17151
17878
  return {
17152
17879
  coding: {
17153
17880
  code: coding.code,
@@ -17158,7 +17885,7 @@ function definitionToSuggestion(definition, omitRedundantText = false) {
17158
17885
  };
17159
17886
  }
17160
17887
  function addSuggestionToMap(map, suggestion) {
17161
- var _a, _b;
17888
+ var _a2, _b;
17162
17889
  if (!suggestion) {
17163
17890
  return;
17164
17891
  }
@@ -17166,7 +17893,7 @@ function addSuggestionToMap(map, suggestion) {
17166
17893
  if (!(coding == null ? void 0 : coding.code)) {
17167
17894
  return;
17168
17895
  }
17169
- const key = `${(_a = coding.system) != null ? _a : SNOMED_SYSTEM9}|${coding.code}`;
17896
+ const key = `${(_a2 = coding.system) != null ? _a2 : SNOMED_SYSTEM9}|${coding.code}`;
17170
17897
  if (!map.has(key)) {
17171
17898
  map.set(key, {
17172
17899
  coding: {
@@ -17244,6 +17971,8 @@ var METHOD_TEXT_BY_VERB = {
17244
17971
  var METHOD_THAI_BY_VERB = {
17245
17972
  apply: "\u0E17\u0E32",
17246
17973
  drink: "\u0E23\u0E31\u0E1A\u0E1B\u0E23\u0E30\u0E17\u0E32\u0E19",
17974
+ inhale: "\u0E2A\u0E39\u0E14",
17975
+ inject: "\u0E09\u0E35\u0E14",
17247
17976
  insert: "\u0E2A\u0E2D\u0E14",
17248
17977
  instill: "\u0E2B\u0E22\u0E2D\u0E14",
17249
17978
  spray: "\u0E1E\u0E48\u0E19",
@@ -17255,7 +17984,7 @@ function tokenize(input) {
17255
17984
  return annotateLexTokens(lexInput(input));
17256
17985
  }
17257
17986
  function buildCustomSiteHints(map) {
17258
- var _a, _b;
17987
+ var _a2, _b;
17259
17988
  if (!map) {
17260
17989
  return void 0;
17261
17990
  }
@@ -17277,7 +18006,7 @@ function buildCustomSiteHints(map) {
17277
18006
  continue;
17278
18007
  }
17279
18008
  push(key);
17280
- (_a = definition.aliases) == null ? void 0 : _a.forEach(push);
18009
+ (_a2 = definition.aliases) == null ? void 0 : _a2.forEach(push);
17281
18010
  push(definition.text);
17282
18011
  push((_b = definition.coding) == null ? void 0 : _b.display);
17283
18012
  }
@@ -17299,11 +18028,11 @@ function addDayOfWeekList(state, days) {
17299
18028
  }
17300
18029
  }
17301
18030
  function isCompatibleRouteRefinement(current, next) {
17302
- var _a;
18031
+ var _a2;
17303
18032
  if (current === void 0 || current === next) {
17304
18033
  return true;
17305
18034
  }
17306
- return Boolean((_a = ROUTE_REFINEMENTS.get(current)) == null ? void 0 : _a.has(next));
18035
+ return Boolean((_a2 = ROUTE_REFINEMENTS.get(current)) == null ? void 0 : _a2.has(next));
17307
18036
  }
17308
18037
  function setRoute(state, code, text) {
17309
18038
  if (!isCompatibleRouteRefinement(state.routeCode, code)) {
@@ -17313,12 +18042,12 @@ function setRoute(state, code, text) {
17313
18042
  state.routeText = text != null ? text : ROUTE_TEXT[code];
17314
18043
  }
17315
18044
  function refreshMethodSurface(state) {
17316
- var _a;
18045
+ var _a2;
17317
18046
  const verb = state.methodVerb;
17318
18047
  if (!verb) {
17319
18048
  return;
17320
18049
  }
17321
- state.methodText = (_a = METHOD_TEXT_BY_VERB[verb]) != null ? _a : verb.charAt(0).toUpperCase() + verb.slice(1);
18050
+ state.methodText = (_a2 = METHOD_TEXT_BY_VERB[verb]) != null ? _a2 : verb.charAt(0).toUpperCase() + verb.slice(1);
17322
18051
  const thai = METHOD_THAI_BY_VERB[verb];
17323
18052
  state.methodTextElement = thai ? buildTranslationPrimitiveElement({ th: thai }) : void 0;
17324
18053
  }
@@ -17341,13 +18070,13 @@ function recordEvidence(state, rule, startIndex, endIndex) {
17341
18070
  });
17342
18071
  }
17343
18072
  function computeTrimmedInputRange(input) {
17344
- var _a;
18073
+ var _a2;
17345
18074
  const start = input.search(/\S/);
17346
18075
  if (start === -1) {
17347
18076
  return void 0;
17348
18077
  }
17349
18078
  let end = input.length;
17350
- while (end > start && /\s/.test((_a = input[end - 1]) != null ? _a : "")) {
18079
+ while (end > start && /\s/.test((_a2 = input[end - 1]) != null ? _a2 : "")) {
17351
18080
  end -= 1;
17352
18081
  }
17353
18082
  return { start, end };
@@ -17398,11 +18127,11 @@ function collectLeftovers(state) {
17398
18127
  return leftovers;
17399
18128
  }
17400
18129
  function cleanupClause(state) {
17401
- var _a, _b, _c;
18130
+ var _a2, _b, _c;
17402
18131
  const clause = state.primaryClause;
17403
18132
  const schedule = clause.schedule;
17404
18133
  if (schedule) {
17405
- if (!((_a = schedule.dayOfWeek) == null ? void 0 : _a.length)) delete schedule.dayOfWeek;
18134
+ if (!((_a2 = schedule.dayOfWeek) == null ? void 0 : _a2.length)) delete schedule.dayOfWeek;
17406
18135
  if (!((_b = schedule.when) == null ? void 0 : _b.length)) delete schedule.when;
17407
18136
  if (!((_c = schedule.timeOfDay) == null ? void 0 : _c.length)) delete schedule.timeOfDay;
17408
18137
  if (schedule.count === void 0 && schedule.duration === void 0 && schedule.durationMax === void 0 && schedule.durationUnit === void 0 && schedule.frequency === void 0 && schedule.frequencyMax === void 0 && schedule.period === void 0 && schedule.periodMax === void 0 && schedule.periodUnit === void 0 && schedule.timingCode === void 0 && !schedule.dayOfWeek && !schedule.when && !schedule.timeOfDay) {
@@ -17471,12 +18200,12 @@ function seedKnownRouteFromSurface(state) {
17471
18200
  }
17472
18201
  }
17473
18202
  function seedKnownSiteCoding(state) {
17474
- var _a, _b;
18203
+ var _a2, _b;
17475
18204
  if (!state.siteText || state.siteCoding) {
17476
18205
  return;
17477
18206
  }
17478
18207
  const definition = DEFAULT_BODY_SITE_SNOMED[normalizeBodySiteKey(state.siteText)];
17479
- if (!((_a = definition == null ? void 0 : definition.coding) == null ? void 0 : _a.code)) {
18208
+ if (!((_a2 = definition == null ? void 0 : definition.coding) == null ? void 0 : _a2.code)) {
17480
18209
  return;
17481
18210
  }
17482
18211
  state.siteCoding = {
@@ -17542,12 +18271,12 @@ function parsesAsInstructionContinuation(input, tokens, index) {
17542
18271
  allowFreeTextFallback: false
17543
18272
  });
17544
18273
  return instructions.some((instruction) => {
17545
- var _a;
17546
- return ((_a = instruction.coding) == null ? void 0 : _a.code) || instruction.frames.length;
18274
+ var _a2;
18275
+ return ((_a2 = instruction.coding) == null ? void 0 : _a2.code) || instruction.frames.length;
17547
18276
  });
17548
18277
  }
17549
18278
  function isCommaClauseBoundary(input, tokens, index) {
17550
- var _a;
18279
+ var _a2;
17551
18280
  const token = tokens[index];
17552
18281
  if (!token || token.original !== ",") {
17553
18282
  return false;
@@ -17558,7 +18287,7 @@ function isCommaClauseBoundary(input, tokens, index) {
17558
18287
  }
17559
18288
  const lower = next.lower.replace(/[.,;:]/g, "");
17560
18289
  const rawLower = next.lower.replace(/^\.+|\.+$/g, "");
17561
- const following = (_a = tokens[index + 2]) == null ? void 0 : _a.lower.replace(/^\.+|\.+$/g, "");
18290
+ const following = (_a2 = tokens[index + 2]) == null ? void 0 : _a2.lower.replace(/^\.+|\.+$/g, "");
17562
18291
  if (/^[0-9]{1,2}[:.][0-9]{2}$/.test(rawLower) || /^[0-9]{1,2}$/.test(rawLower) && Boolean(following && MERIDIEM_TOKENS.has(following))) {
17563
18292
  return false;
17564
18293
  }
@@ -17577,7 +18306,7 @@ function isCommaClauseBoundary(input, tokens, index) {
17577
18306
  return true;
17578
18307
  }
17579
18308
  function isSlashClauseBoundary(tokens, index) {
17580
- var _a;
18309
+ var _a2;
17581
18310
  const token = tokens[index];
17582
18311
  if (!token || token.original !== "/") {
17583
18312
  return false;
@@ -17587,7 +18316,7 @@ function isSlashClauseBoundary(tokens, index) {
17587
18316
  return false;
17588
18317
  }
17589
18318
  const previous = tokens[index - 1];
17590
- const previousLower = (_a = previous == null ? void 0 : previous.lower.replace(/[.,;:]/g, "")) != null ? _a : "";
18319
+ const previousLower = (_a2 = previous == null ? void 0 : previous.lower.replace(/[.,;:]/g, "")) != null ? _a2 : "";
17591
18320
  const lower = next.lower.replace(/[.,;:]/g, "");
17592
18321
  if (/^\d+(?:\.\d+)?$/.test(previousLower) && /^\d+(?:\.\d+)?$/.test(lower)) {
17593
18322
  return false;
@@ -17595,10 +18324,10 @@ function isSlashClauseBoundary(tokens, index) {
17595
18324
  return /^\d/.test(lower) || CLAUSE_LEAD_WORDS.has(lower);
17596
18325
  }
17597
18326
  function pushSegment(segments, input, start, end) {
17598
- var _a, _b;
18327
+ var _a2, _b;
17599
18328
  let trimmedStart = start;
17600
18329
  let trimmedEnd = end;
17601
- while (trimmedStart < trimmedEnd && /\s/.test((_a = input[trimmedStart]) != null ? _a : "")) {
18330
+ while (trimmedStart < trimmedEnd && /\s/.test((_a2 = input[trimmedStart]) != null ? _a2 : "")) {
17602
18331
  trimmedStart += 1;
17603
18332
  }
17604
18333
  while (trimmedEnd > trimmedStart && /\s/.test((_b = input[trimmedEnd - 1]) != null ? _b : "")) {
@@ -17702,7 +18431,7 @@ var DEFAULT_UNIT_ROUTE_ORDER = [
17702
18431
  { unit: "patch", routeCode: RouteCode["Transdermal route"] }
17703
18432
  ];
17704
18433
  var ROUTE_TOKEN_BY_UNIT = (() => {
17705
- var _a, _b, _c;
18434
+ var _a2, _b, _c;
17706
18435
  const map = /* @__PURE__ */ new Map();
17707
18436
  const assign = (unit, token) => {
17708
18437
  if (!unit || !token) {
@@ -17723,7 +18452,7 @@ var ROUTE_TOKEN_BY_UNIT = (() => {
17723
18452
  if (!unit) {
17724
18453
  continue;
17725
18454
  }
17726
- const token = (_a = ROUTE_TOKEN_BY_CODE[routeCode]) != null ? _a : ROUTE_TEXT[routeCode];
18455
+ const token = (_a2 = ROUTE_TOKEN_BY_CODE[routeCode]) != null ? _a2 : ROUTE_TEXT[routeCode];
17727
18456
  assign(unit, token);
17728
18457
  }
17729
18458
  for (const preference of DEFAULT_UNIT_ROUTE_ORDER) {
@@ -17857,7 +18586,7 @@ var UNIT_LOOKUP = (() => {
17857
18586
  return { canonicalByKey, variantsByCanonical };
17858
18587
  })();
17859
18588
  function resolveCanonicalUnit(unit) {
17860
- var _a;
18589
+ var _a2;
17861
18590
  if (!unit) {
17862
18591
  return void 0;
17863
18592
  }
@@ -17865,7 +18594,7 @@ function resolveCanonicalUnit(unit) {
17865
18594
  if (!normalized) {
17866
18595
  return void 0;
17867
18596
  }
17868
- return (_a = UNIT_LOOKUP.canonicalByKey.get(normalized)) != null ? _a : normalizeSpacing(unit);
18597
+ return (_a2 = UNIT_LOOKUP.canonicalByKey.get(normalized)) != null ? _a2 : normalizeSpacing(unit);
17869
18598
  }
17870
18599
  function normalizeKey(value) {
17871
18600
  return value.trim().toLowerCase();
@@ -17904,8 +18633,8 @@ function removeDashes(value) {
17904
18633
  }
17905
18634
  var UNIT_VARIANT_CACHE = /* @__PURE__ */ new Map();
17906
18635
  function getUnitVariants(unit) {
17907
- var _a;
17908
- const canonical = (_a = resolveCanonicalUnit(unit)) != null ? _a : normalizeSpacing(unit);
18636
+ var _a2;
18637
+ const canonical = (_a2 = resolveCanonicalUnit(unit)) != null ? _a2 : normalizeSpacing(unit);
17909
18638
  const normalizedCanonical = normalizeKey(canonical);
17910
18639
  const cached = UNIT_VARIANT_CACHE.get(normalizedCanonical);
17911
18640
  if (cached) {
@@ -18055,11 +18784,11 @@ function tokensMatch(prefixTokens, candidateTokens) {
18055
18784
  return prefixIndex >= prefixTokens.length;
18056
18785
  }
18057
18786
  function buildUnitRoutePairs(contextUnit, options) {
18058
- var _a, _b;
18787
+ var _a2, _b;
18059
18788
  const pairs = [];
18060
18789
  const seen = /* @__PURE__ */ new Set();
18061
18790
  const addPair = (unit, routeOverride) => {
18062
- var _a2;
18791
+ var _a3;
18063
18792
  const canonicalUnit = resolveCanonicalUnit(unit);
18064
18793
  if (!canonicalUnit) {
18065
18794
  return;
@@ -18068,7 +18797,7 @@ function buildUnitRoutePairs(contextUnit, options) {
18068
18797
  if ((options == null ? void 0 : options.allowHouseholdVolumeUnits) === false && HOUSEHOLD_VOLUME_UNIT_SET2.has(normalizedUnit)) {
18069
18798
  return;
18070
18799
  }
18071
- const resolvedRoute = (_a2 = routeOverride != null ? routeOverride : ROUTE_TOKEN_BY_UNIT.get(normalizedUnit)) != null ? _a2 : "po";
18800
+ const resolvedRoute = (_a3 = routeOverride != null ? routeOverride : ROUTE_TOKEN_BY_UNIT.get(normalizedUnit)) != null ? _a3 : "po";
18072
18801
  const cleanRoute = normalizeSpacing(resolvedRoute);
18073
18802
  if (!cleanRoute) {
18074
18803
  return;
@@ -18083,7 +18812,7 @@ function buildUnitRoutePairs(contextUnit, options) {
18083
18812
  };
18084
18813
  addPair(contextUnit);
18085
18814
  for (const preference of DEFAULT_UNIT_ROUTE_ORDER) {
18086
- const routeToken = (_b = (_a = preference.routeToken) != null ? _a : ROUTE_TOKEN_BY_CODE[preference.routeCode]) != null ? _b : ROUTE_TEXT[preference.routeCode];
18815
+ const routeToken = (_b = (_a2 = preference.routeToken) != null ? _a2 : ROUTE_TOKEN_BY_CODE[preference.routeCode]) != null ? _b : ROUTE_TEXT[preference.routeCode];
18087
18816
  addPair(preference.unit, routeToken);
18088
18817
  }
18089
18818
  return pairs;
@@ -18309,7 +19038,7 @@ function generateCandidateDirections(pairs, doseValues, prnReasons, intervalToke
18309
19038
  return suggestions;
18310
19039
  }
18311
19040
  function matchesPrefix(_candidate, candidateLower, context) {
18312
- var _a, _b, _c, _d, _e, _f;
19041
+ var _a2, _b, _c, _d, _e, _f;
18313
19042
  if (!context.raw) {
18314
19043
  return true;
18315
19044
  }
@@ -18321,7 +19050,7 @@ function matchesPrefix(_candidate, candidateLower, context) {
18321
19050
  }
18322
19051
  const fingerprint = getCandidateFingerprint(candidateLower);
18323
19052
  if (context.requiresCompact) {
18324
- const compactCandidate = (_a = fingerprint.compact) != null ? _a : fingerprint.compact = removeWhitespaceCharacters(candidateLower);
19053
+ const compactCandidate = (_a2 = fingerprint.compact) != null ? _a2 : fingerprint.compact = removeWhitespaceCharacters(candidateLower);
18325
19054
  if (compactCandidate.startsWith(context.compact)) {
18326
19055
  return true;
18327
19056
  }
@@ -18396,7 +19125,7 @@ function collectMatchedCandidates(candidates, limit, matcher) {
18396
19125
  return suggestions;
18397
19126
  }
18398
19127
  function buildMealDashCoreVariants(prefixCore) {
18399
- var _a;
19128
+ var _a2;
18400
19129
  if (!prefixCore.includes("-") || prefixCore.includes("--")) {
18401
19130
  return [];
18402
19131
  }
@@ -18404,7 +19133,7 @@ function buildMealDashCoreVariants(prefixCore) {
18404
19133
  if (slots.length < 2 || slots.length > 4) {
18405
19134
  return [];
18406
19135
  }
18407
- if (!/^[0-9]+(?:\.[0-9]+)?$/.test((_a = slots[0]) != null ? _a : "")) {
19136
+ if (!/^[0-9]+(?:\.[0-9]+)?$/.test((_a2 = slots[0]) != null ? _a2 : "")) {
18408
19137
  return [];
18409
19138
  }
18410
19139
  for (let i = 1; i < slots.length; i += 1) {
@@ -18477,7 +19206,7 @@ function suggestMealDashSyntax(prefix, limit, matcher) {
18477
19206
  return collectMatchedCandidates(candidates, limit, matcher);
18478
19207
  }
18479
19208
  function suggestCompactOralMealTiming(prefix, limit, matcher) {
18480
- var _a, _b;
19209
+ var _a2, _b;
18481
19210
  const match = prefix.match(
18482
19211
  /^(\d+(?:\.\d+)?)\s*(?:po\s*(c|ac|pc)|po(c|ac|pc))$/
18483
19212
  );
@@ -18485,14 +19214,14 @@ function suggestCompactOralMealTiming(prefix, limit, matcher) {
18485
19214
  return void 0;
18486
19215
  }
18487
19216
  const dose = normalizeSpacing(match[1]);
18488
- const timing = ((_b = (_a = match[2]) != null ? _a : match[3]) != null ? _b : "").toLowerCase();
19217
+ const timing = ((_b = (_a2 = match[2]) != null ? _a2 : match[3]) != null ? _b : "").toLowerCase();
18489
19218
  const orderedTimings = timing === "c" ? ["c", "ac", "pc"] : timing === "ac" ? ["ac", "c", "pc"] : timing === "pc" ? ["pc", "c", "ac"] : ["c", "ac", "pc"];
18490
19219
  const candidates = orderedTimings.map((token) => `${dose} po ${token}`);
18491
19220
  return collectMatchedCandidates(candidates, limit, matcher);
18492
19221
  }
18493
19222
  function suggestSig(input, options) {
18494
- var _a, _b;
18495
- const limit = (_a = options == null ? void 0 : options.limit) != null ? _a : DEFAULT_LIMIT;
19223
+ var _a2, _b;
19224
+ const limit = (_a2 = options == null ? void 0 : options.limit) != null ? _a2 : DEFAULT_LIMIT;
18496
19225
  if (limit <= 0) {
18497
19226
  return [];
18498
19227
  }
@@ -18581,10 +19310,10 @@ function getUnitCategory(unit) {
18581
19310
  return "other";
18582
19311
  }
18583
19312
  function getBaseUnitFactor(unit) {
18584
- var _a, _b;
19313
+ var _a2, _b;
18585
19314
  if (!unit) return 1;
18586
19315
  const u = unit.toLowerCase();
18587
- return (_b = (_a = MASS_UNITS[u]) != null ? _a : VOLUME_UNITS[u]) != null ? _b : 1;
19316
+ return (_b = (_a2 = MASS_UNITS[u]) != null ? _a2 : VOLUME_UNITS[u]) != null ? _b : 1;
18588
19317
  }
18589
19318
  function convertValue(value, fromUnit, toUnit, strength) {
18590
19319
  const f = fromUnit.toLowerCase();
@@ -18622,16 +19351,16 @@ function convertValue(value, fromUnit, toUnit, strength) {
18622
19351
 
18623
19352
  // src/utils/strength.ts
18624
19353
  function parseStrength(strength, context) {
18625
- var _a, _b, _c;
19354
+ var _a2, _b, _c;
18626
19355
  const ratio = parseStrengthIntoRatio(strength, context);
18627
19356
  if (!ratio) return {};
18628
- if (((_a = ratio.denominator) == null ? void 0 : _a.value) === 1 && (((_b = ratio.denominator) == null ? void 0 : _b.unit) === "unit" || !((_c = ratio.denominator) == null ? void 0 : _c.unit))) {
19357
+ if (((_a2 = ratio.denominator) == null ? void 0 : _a2.value) === 1 && (((_b = ratio.denominator) == null ? void 0 : _b.unit) === "unit" || !((_c = ratio.denominator) == null ? void 0 : _c.unit))) {
18629
19358
  return { strengthQuantity: ratio.numerator };
18630
19359
  }
18631
19360
  return { strengthRatio: ratio };
18632
19361
  }
18633
19362
  function parseStrengthIntoRatio(strength, context) {
18634
- var _a, _b, _c, _d, _e;
19363
+ var _a2, _b, _c, _d, _e;
18635
19364
  const parts = strength.split("+").map((p) => p.trim());
18636
19365
  let totalMgPerMlOrG = 0;
18637
19366
  let hasVolume = false;
@@ -18641,7 +19370,7 @@ function parseStrengthIntoRatio(strength, context) {
18641
19370
  let targetDenValue;
18642
19371
  for (const part of parts) {
18643
19372
  const ratio = parseSingleStrengthPart(part, context);
18644
- if (!ratio || !((_a = ratio.numerator) == null ? void 0 : _a.value) || ratio.numerator.value === 0) continue;
19373
+ if (!ratio || !((_a2 = ratio.numerator) == null ? void 0 : _a2.value) || ratio.numerator.value === 0) continue;
18645
19374
  const nUnit = ratio.numerator.unit;
18646
19375
  const dUnit = ((_b = ratio.denominator) == null ? void 0 : _b.unit) || "unit";
18647
19376
  const dCat = getUnitCategory(dUnit);
@@ -18716,7 +19445,7 @@ function isSolidDosageForm(form) {
18716
19445
  return false;
18717
19446
  }
18718
19447
  function parseSingleStrengthPart(part, context) {
18719
- var _a, _b;
19448
+ var _a2, _b;
18720
19449
  const p = part.trim();
18721
19450
  const percentMatch = p.match(/^(\d+(?:\.\d+)?)\s*%$/);
18722
19451
  if (percentMatch) {
@@ -18731,7 +19460,7 @@ function parseSingleStrengthPart(part, context) {
18731
19460
  return {
18732
19461
  numerator: {
18733
19462
  value: parseFloat(ratioMatch[1]),
18734
- unit: ((_a = ratioMatch[2]) == null ? void 0 : _a.trim()) || "mg"
19463
+ unit: ((_a2 = ratioMatch[2]) == null ? void 0 : _a2.trim()) || "mg"
18735
19464
  },
18736
19465
  denominator: {
18737
19466
  value: ratioMatch[3] ? parseFloat(ratioMatch[3]) : 1,
@@ -18769,6 +19498,7 @@ var DEFAULT_FREQUENCY_DEFAULTS = {
18769
19498
  };
18770
19499
  var SECONDS_PER_MINUTE = 60;
18771
19500
  var MINUTES_PER_DAY = 24 * 60;
19501
+ var TOTAL_UNITS_PRECISION = 1e12;
18772
19502
  var dateTimeFormatCache = /* @__PURE__ */ new Map();
18773
19503
  var weekdayFormatCache = /* @__PURE__ */ new Map();
18774
19504
  function pad(value, length = 2) {
@@ -18795,7 +19525,7 @@ function formatToParts(formatter, date) {
18795
19525
  ];
18796
19526
  }
18797
19527
  function normalizeClock(clock) {
18798
- var _a;
19528
+ var _a2;
18799
19529
  const parts = clock.split(":");
18800
19530
  if (parts.length < 2 || parts.length > 3) {
18801
19531
  throw new Error(`Invalid clock value: ${clock}`);
@@ -18803,7 +19533,7 @@ function normalizeClock(clock) {
18803
19533
  const [hourPart, minutePart, secondPart] = [
18804
19534
  parts[0],
18805
19535
  parts[1],
18806
- (_a = parts[2]) != null ? _a : "00"
19536
+ (_a2 = parts[2]) != null ? _a2 : "00"
18807
19537
  ];
18808
19538
  const hour = Number(hourPart);
18809
19539
  const minute = Number(minutePart);
@@ -18845,7 +19575,7 @@ function getWeekdayFormat(timeZone) {
18845
19575
  return formatter;
18846
19576
  }
18847
19577
  function getTimeParts(date, timeZone) {
18848
- var _a, _b;
19578
+ var _a2, _b;
18849
19579
  const formatter = getDateTimeFormat(timeZone);
18850
19580
  const parts = {};
18851
19581
  const rawParts = formatToParts(formatter, date);
@@ -18883,7 +19613,7 @@ function getTimeParts(date, timeZone) {
18883
19613
  }
18884
19614
  }
18885
19615
  parts.hour = 0;
18886
- parts.minute = (_a = parts.minute) != null ? _a : 0;
19616
+ parts.minute = (_a2 = parts.minute) != null ? _a2 : 0;
18887
19617
  parts.second = (_b = parts.second) != null ? _b : 0;
18888
19618
  }
18889
19619
  if (parts.year === void 0 || parts.month === void 0 || parts.day === void 0 || parts.hour === void 0 || parts.minute === void 0 || parts.second === void 0) {
@@ -18921,10 +19651,10 @@ function makeZonedDate(timeZone, year, month, day, hour, minute, second) {
18921
19651
  return candidate;
18922
19652
  }
18923
19653
  function makeZonedDateFromDay(base, timeZone, clock) {
18924
- var _a, _b, _c;
19654
+ var _a2, _b, _c;
18925
19655
  const { year, month, day } = getTimeParts(base, timeZone);
18926
19656
  const parts = clock.split(":").map((value) => Number(value));
18927
- const hour = (_a = parts[0]) != null ? _a : 0;
19657
+ const hour = (_a2 = parts[0]) != null ? _a2 : 0;
18928
19658
  const minute = (_b = parts[1]) != null ? _b : 0;
18929
19659
  const second = (_c = parts[2]) != null ? _c : 0;
18930
19660
  return makeZonedDate(timeZone, year, month, day, hour, minute, second);
@@ -19020,6 +19750,49 @@ function coerceDate(value, label) {
19020
19750
  }
19021
19751
  return date;
19022
19752
  }
19753
+ function roundCalculatedUnits(value) {
19754
+ if (!Number.isFinite(value)) {
19755
+ return value;
19756
+ }
19757
+ return Math.round((value + Number.EPSILON) * TOTAL_UNITS_PRECISION) / TOTAL_UNITS_PRECISION;
19758
+ }
19759
+ function resolveContextStrengthRatio(context) {
19760
+ var _a2, _b;
19761
+ if (!context) {
19762
+ return void 0;
19763
+ }
19764
+ return (_b = context.strengthRatio) != null ? _b : context.strength ? (_a2 = parseStrengthIntoRatio(context.strength, context)) != null ? _a2 : void 0 : void 0;
19765
+ }
19766
+ function estimateIngredientQuantity(quantity, context) {
19767
+ if (quantity.value === void 0 || !quantity.unit) {
19768
+ return void 0;
19769
+ }
19770
+ const strength = resolveContextStrengthRatio(context);
19771
+ const numerator = strength == null ? void 0 : strength.numerator;
19772
+ const denominator = strength == null ? void 0 : strength.denominator;
19773
+ if (!(numerator == null ? void 0 : numerator.unit) || numerator.value === void 0 || !(denominator == null ? void 0 : denominator.unit) || denominator.value === void 0) {
19774
+ return void 0;
19775
+ }
19776
+ const converted = convertValue(
19777
+ quantity.value,
19778
+ quantity.unit,
19779
+ numerator.unit,
19780
+ {
19781
+ numerator: { value: numerator.value, unit: numerator.unit },
19782
+ denominator: { value: denominator.value, unit: denominator.unit }
19783
+ }
19784
+ );
19785
+ if (converted === null) {
19786
+ return void 0;
19787
+ }
19788
+ return {
19789
+ value: roundCalculatedUnits(converted),
19790
+ unit: numerator.unit,
19791
+ confidence: quantity.confidence,
19792
+ basis: quantity.basis,
19793
+ source: quantity.source
19794
+ };
19795
+ }
19023
19796
  function applyOffset(clock, offsetMinutes) {
19024
19797
  const [hour, minute, second] = clock.split(":").map((part) => Number(part));
19025
19798
  let totalMinutes = hour * SECONDS_PER_MINUTE + minute + offsetMinutes;
@@ -19040,8 +19813,8 @@ function applyOffset(clock, offsetMinutes) {
19040
19813
  };
19041
19814
  }
19042
19815
  function parseBoundsDurationUnit(quantity) {
19043
- var _a, _b, _c;
19044
- const candidate = (_c = (_a = quantity == null ? void 0 : quantity.code) == null ? void 0 : _a.trim().toLowerCase()) != null ? _c : (_b = quantity == null ? void 0 : quantity.unit) == null ? void 0 : _b.trim().toLowerCase();
19816
+ var _a2, _b, _c;
19817
+ const candidate = (_c = (_a2 = quantity == null ? void 0 : quantity.code) == null ? void 0 : _a2.trim().toLowerCase()) != null ? _c : (_b = quantity == null ? void 0 : quantity.unit) == null ? void 0 : _b.trim().toLowerCase();
19045
19818
  switch (candidate) {
19046
19819
  case "s":
19047
19820
  case "sec":
@@ -19083,11 +19856,11 @@ function parseBoundsDurationUnit(quantity) {
19083
19856
  }
19084
19857
  }
19085
19858
  function resolveRepeatBoundsDuration(repeat) {
19086
- var _a, _b, _c, _d;
19859
+ var _a2, _b, _c, _d;
19087
19860
  if (!repeat) {
19088
19861
  return {};
19089
19862
  }
19090
- if (((_a = repeat.boundsDuration) == null ? void 0 : _a.value) !== void 0) {
19863
+ if (((_a2 = repeat.boundsDuration) == null ? void 0 : _a2.value) !== void 0) {
19091
19864
  return {
19092
19865
  value: repeat.boundsDuration.value,
19093
19866
  unit: parseBoundsDurationUnit(repeat.boundsDuration)
@@ -19103,9 +19876,9 @@ function resolveRepeatBoundsDuration(repeat) {
19103
19876
  };
19104
19877
  }
19105
19878
  function resolveRepeatDurationCapEnd(repeat, anchor, timeZone) {
19106
- var _a, _b;
19879
+ var _a2, _b;
19107
19880
  const bounds = resolveRepeatBoundsDuration(repeat);
19108
- const durationValue = (_a = bounds.max) != null ? _a : bounds.value;
19881
+ const durationValue = (_a2 = bounds.max) != null ? _a2 : bounds.value;
19109
19882
  const durationUnit = bounds.unit;
19110
19883
  if (durationValue === void 0 || !Number.isFinite(durationValue) || durationValue <= 0 || !durationUnit) {
19111
19884
  return null;
@@ -19120,14 +19893,14 @@ function resolveRepeatDurationCapEnd(repeat, anchor, timeZone) {
19120
19893
  return (_b = stepper(anchor)) != null ? _b : null;
19121
19894
  }
19122
19895
  function resolveDayFilteredSeriesRepeat(repeat, enforceDayFilter) {
19123
- var _a, _b, _c, _d;
19896
+ var _a2, _b, _c, _d;
19124
19897
  if (!enforceDayFilter) {
19125
19898
  return void 0;
19126
19899
  }
19127
19900
  if (repeat.frequency) {
19128
19901
  return void 0;
19129
19902
  }
19130
- if (((_b = (_a = repeat.when) == null ? void 0 : _a.length) != null ? _b : 0) > 0 || ((_d = (_c = repeat.timeOfDay) == null ? void 0 : _c.length) != null ? _d : 0) > 0) {
19903
+ if (((_b = (_a2 = repeat.when) == null ? void 0 : _a2.length) != null ? _b : 0) > 0 || ((_d = (_c = repeat.timeOfDay) == null ? void 0 : _c.length) != null ? _d : 0) > 0) {
19131
19904
  return void 0;
19132
19905
  }
19133
19906
  switch (repeat.periodUnit) {
@@ -19142,19 +19915,19 @@ function resolveDayFilteredSeriesRepeat(repeat, enforceDayFilter) {
19142
19915
  }
19143
19916
  }
19144
19917
  function isSingleAdministrationRepeat(repeat) {
19145
- var _a, _b, _c, _d, _e, _f;
19146
- return repeat.count === 1 && repeat.frequency === void 0 && repeat.frequencyMax === void 0 && repeat.period === void 0 && repeat.periodMax === void 0 && repeat.periodUnit === void 0 && ((_b = (_a = repeat.dayOfWeek) == null ? void 0 : _a.length) != null ? _b : 0) === 0 && ((_d = (_c = repeat.when) == null ? void 0 : _c.length) != null ? _d : 0) === 0 && ((_f = (_e = repeat.timeOfDay) == null ? void 0 : _e.length) != null ? _f : 0) === 0;
19918
+ var _a2, _b, _c, _d, _e, _f;
19919
+ return repeat.count === 1 && repeat.frequency === void 0 && repeat.frequencyMax === void 0 && repeat.period === void 0 && repeat.periodMax === void 0 && repeat.periodUnit === void 0 && ((_b = (_a2 = repeat.dayOfWeek) == null ? void 0 : _a2.length) != null ? _b : 0) === 0 && ((_d = (_c = repeat.when) == null ? void 0 : _c.length) != null ? _d : 0) === 0 && ((_f = (_e = repeat.timeOfDay) == null ? void 0 : _e.length) != null ? _f : 0) === 0;
19147
19920
  }
19148
19921
  function hasUnresolvedRelationalInstruction(dosage) {
19149
- var _a, _b, _c, _d, _e, _f;
19922
+ var _a2, _b, _c, _d, _e, _f;
19150
19923
  const texts = [];
19151
- if ((_a = dosage.patientInstruction) == null ? void 0 : _a.trim()) {
19924
+ if ((_a2 = dosage.patientInstruction) == null ? void 0 : _a2.trim()) {
19152
19925
  texts.push(dosage.patientInstruction.trim());
19153
19926
  }
19154
19927
  for (const instruction of (_b = dosage.additionalInstruction) != null ? _b : []) {
19155
19928
  const text = ((_c = instruction.text) == null ? void 0 : _c.trim()) || ((_f = (_e = (_d = instruction.coding) == null ? void 0 : _d.find((coding) => {
19156
- var _a2;
19157
- return (_a2 = coding.display) == null ? void 0 : _a2.trim();
19929
+ var _a3;
19930
+ return (_a3 = coding.display) == null ? void 0 : _a3.trim();
19158
19931
  })) == null ? void 0 : _e.display) == null ? void 0 : _f.trim());
19159
19932
  if (text) {
19160
19933
  texts.push(text);
@@ -19196,8 +19969,8 @@ var SPECIFIC_AFTER_MEALS = {
19196
19969
  ["PCV" /* After Dinner */]: "CV" /* Dinner */
19197
19970
  };
19198
19971
  function expandTiming(code, config, repeat) {
19199
- var _a, _b, _c, _d, _e, _f, _g, _h;
19200
- const mealOffsets = (_a = config.mealOffsets) != null ? _a : {};
19972
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
19973
+ const mealOffsets = (_a2 = config.mealOffsets) != null ? _a2 : {};
19201
19974
  const eventClock = (_b = config.eventClock) != null ? _b : {};
19202
19975
  const normalized = [];
19203
19976
  const clockValue = eventClock[code];
@@ -19246,8 +20019,8 @@ function expandTiming(code, config, repeat) {
19246
20019
  }
19247
20020
  if (repeat.offset && normalized.length) {
19248
20021
  return normalized.map((entry) => {
19249
- var _a2;
19250
- const adjusted = applyOffset(entry.time, (_a2 = repeat.offset) != null ? _a2 : 0);
20022
+ var _a3;
20023
+ const adjusted = applyOffset(entry.time, (_a3 = repeat.offset) != null ? _a3 : 0);
19251
20024
  return {
19252
20025
  time: adjusted.time,
19253
20026
  dayShift: entry.dayShift + adjusted.dayShift
@@ -19312,9 +20085,9 @@ function inferWhenFallbackEntries(whenCodes, repeat) {
19312
20085
  const entries = [];
19313
20086
  const seen = /* @__PURE__ */ new Set();
19314
20087
  const addClock = (clock) => {
19315
- var _a;
20088
+ var _a2;
19316
20089
  const normalized = normalizeClock(clock);
19317
- const adjusted = repeat.offset ? applyOffset(normalized, (_a = repeat.offset) != null ? _a : 0) : { time: normalized, dayShift: 0 };
20090
+ const adjusted = repeat.offset ? applyOffset(normalized, (_a2 = repeat.offset) != null ? _a2 : 0) : { time: normalized, dayShift: 0 };
19318
20091
  const key = `${adjusted.dayShift}|${adjusted.time}`;
19319
20092
  if (seen.has(key)) {
19320
20093
  return;
@@ -19342,13 +20115,13 @@ function inferWhenFallbackEntries(whenCodes, repeat) {
19342
20115
  });
19343
20116
  }
19344
20117
  function mergeFrequencyDefaults(base, override) {
19345
- var _a, _b, _c, _d;
20118
+ var _a2, _b, _c, _d;
19346
20119
  if (!base && !override) {
19347
20120
  return void 0;
19348
20121
  }
19349
20122
  const merged = {};
19350
20123
  if ((base == null ? void 0 : base.byCode) || (override == null ? void 0 : override.byCode)) {
19351
- merged.byCode = __spreadValues(__spreadValues({}, (_a = base == null ? void 0 : base.byCode) != null ? _a : {}), (_b = override == null ? void 0 : override.byCode) != null ? _b : {});
20124
+ merged.byCode = __spreadValues(__spreadValues({}, (_a2 = base == null ? void 0 : base.byCode) != null ? _a2 : {}), (_b = override == null ? void 0 : override.byCode) != null ? _b : {});
19352
20125
  }
19353
20126
  if ((base == null ? void 0 : base.byFrequency) || (override == null ? void 0 : override.byFrequency)) {
19354
20127
  merged.byFrequency = __spreadValues(__spreadValues({}, (_c = base == null ? void 0 : base.byFrequency) != null ? _c : {}), (_d = override == null ? void 0 : override.byFrequency) != null ? _d : {});
@@ -19375,9 +20148,9 @@ function inferDailyFrequencyClocks(frequency) {
19375
20148
  return Array.from(clocks).sort();
19376
20149
  }
19377
20150
  function resolveFrequencyClocks(timing, config) {
19378
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
20151
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
19379
20152
  const defaults = {
19380
- byCode: __spreadValues(__spreadValues({}, DEFAULT_FREQUENCY_DEFAULTS.byCode), (_b = (_a = config.frequencyDefaults) == null ? void 0 : _a.byCode) != null ? _b : {}),
20153
+ byCode: __spreadValues(__spreadValues({}, DEFAULT_FREQUENCY_DEFAULTS.byCode), (_b = (_a2 = config.frequencyDefaults) == null ? void 0 : _a2.byCode) != null ? _b : {}),
19381
20154
  byFrequency: __spreadValues(__spreadValues({}, DEFAULT_FREQUENCY_DEFAULTS.byFrequency), (_d = (_c = config.frequencyDefaults) == null ? void 0 : _c.byFrequency) != null ? _d : {})
19382
20155
  };
19383
20156
  const collected = /* @__PURE__ */ new Set();
@@ -19411,14 +20184,14 @@ function resolveFrequencyClocks(timing, config) {
19411
20184
  return Array.from(collected).sort();
19412
20185
  }
19413
20186
  function nextDueDoses(dosage, options) {
19414
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
20187
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
19415
20188
  if (!options || typeof options !== "object") {
19416
20189
  throw new Error("Options argument is required for nextDueDoses");
19417
20190
  }
19418
20191
  if (options.from === void 0) {
19419
20192
  throw new Error("The 'from' option is required for nextDueDoses");
19420
20193
  }
19421
- const limit = (_a = options.limit) != null ? _a : 10;
20194
+ const limit = (_a2 = options.limit) != null ? _a2 : 10;
19422
20195
  if (!Number.isFinite(limit) || limit <= 0) {
19423
20196
  return [];
19424
20197
  }
@@ -19647,7 +20420,7 @@ function nextDueDoses(dosage, options) {
19647
20420
  return [];
19648
20421
  }
19649
20422
  function derivePriorCountFromHistory(timing, repeat, config, orderedAt, from, timeZone) {
19650
- var _a, _b, _c;
20423
+ var _a2, _b, _c;
19651
20424
  if (from <= orderedAt) {
19652
20425
  return 0;
19653
20426
  }
@@ -19655,7 +20428,7 @@ function derivePriorCountFromHistory(timing, repeat, config, orderedAt, from, ti
19655
20428
  if (normalizedCount === 0) {
19656
20429
  return 0;
19657
20430
  }
19658
- const dayFilter = new Set(((_a = repeat.dayOfWeek) != null ? _a : []).map((day) => day.toLowerCase()));
20431
+ const dayFilter = new Set(((_a2 = repeat.dayOfWeek) != null ? _a2 : []).map((day) => day.toLowerCase()));
19659
20432
  const enforceDayFilter = dayFilter.size > 0;
19660
20433
  const dayFilteredSeriesRepeat = resolveDayFilteredSeriesRepeat(repeat, enforceDayFilter);
19661
20434
  const seen = /* @__PURE__ */ new Set();
@@ -19999,7 +20772,7 @@ function toLocalClock(date, timeZone) {
19999
20772
  return `${h}:${m}:${s}`;
20000
20773
  }
20001
20774
  function countScheduleEvents(dosage, from, to, config, baseTime, orderedAt, limit) {
20002
- var _a, _b, _c;
20775
+ var _a2, _b, _c;
20003
20776
  const timing = dosage.timing;
20004
20777
  const repeat = timing == null ? void 0 : timing.repeat;
20005
20778
  if (!timing || !repeat) return 0;
@@ -20007,7 +20780,7 @@ function countScheduleEvents(dosage, from, to, config, baseTime, orderedAt, limi
20007
20780
  if (normalizedCount === 0) {
20008
20781
  return 0;
20009
20782
  }
20010
- const dayFilter = new Set(((_a = repeat.dayOfWeek) != null ? _a : []).map((day) => day.toLowerCase()));
20783
+ const dayFilter = new Set(((_a2 = repeat.dayOfWeek) != null ? _a2 : []).map((day) => day.toLowerCase()));
20011
20784
  const enforceDayFilter = dayFilter.size > 0;
20012
20785
  const dayFilteredSeriesRepeat = resolveDayFilteredSeriesRepeat(repeat, enforceDayFilter);
20013
20786
  const seen = /* @__PURE__ */ new Set();
@@ -20146,12 +20919,12 @@ function countScheduleEvents(dosage, from, to, config, baseTime, orderedAt, limi
20146
20919
  return count;
20147
20920
  }
20148
20921
  function calculateTotalUnitsSingle(options) {
20149
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
20922
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
20150
20923
  const { dosage, durationValue, durationUnit, roundToMultiple, context } = options;
20151
20924
  const from = coerceDate(options.from, "from");
20152
20925
  const orderedAtDate = options.orderedAt === void 0 ? null : coerceDate(options.orderedAt, "orderedAt");
20153
20926
  const providedConfig = options.config;
20154
- const timeZone = (_a = options.timeZone) != null ? _a : providedConfig == null ? void 0 : providedConfig.timeZone;
20927
+ const timeZone = (_a2 = options.timeZone) != null ? _a2 : providedConfig == null ? void 0 : providedConfig.timeZone;
20155
20928
  if (!timeZone) {
20156
20929
  throw new Error("timeZone is required for calculateTotalUnits");
20157
20930
  }
@@ -20189,31 +20962,61 @@ function calculateTotalUnitsSingle(options) {
20189
20962
  2e3
20190
20963
  );
20191
20964
  const doseQuantity = (_j = (_i = (_h = (_g = dosage.doseAndRate) == null ? void 0 : _g[0]) == null ? void 0 : _h.doseQuantity) == null ? void 0 : _i.value) != null ? _j : 0;
20192
- let totalUnits = count * doseQuantity;
20965
+ let totalUnits = roundCalculatedUnits(count * doseQuantity);
20193
20966
  if (roundToMultiple && roundToMultiple > 0) {
20194
- totalUnits = Math.ceil(totalUnits / roundToMultiple) * roundToMultiple;
20967
+ totalUnits = roundCalculatedUnits(Math.ceil(totalUnits / roundToMultiple) * roundToMultiple);
20195
20968
  }
20196
20969
  const result = { totalUnits };
20197
20970
  const containerValue = context == null ? void 0 : context.containerValue;
20198
20971
  const containerUnit = context == null ? void 0 : context.containerUnit;
20972
+ const packageUnit = context == null ? void 0 : context.packageUnit;
20199
20973
  const doseUnit = (_m = (_l = (_k = dosage.doseAndRate) == null ? void 0 : _k[0]) == null ? void 0 : _l.doseQuantity) == null ? void 0 : _m.unit;
20974
+ const unitSemantics = getDoseUnitSemantics(doseUnit, context);
20975
+ if (unitSemantics == null ? void 0 : unitSemantics.approximateQuantity) {
20976
+ const approximation = unitSemantics.approximateQuantity;
20977
+ result.totalApproximateQuantity = {
20978
+ value: roundCalculatedUnits(totalUnits * approximation.value),
20979
+ unit: approximation.unit,
20980
+ confidence: approximation.confidence,
20981
+ basis: approximation.basis,
20982
+ source: approximation.source
20983
+ };
20984
+ result.totalApproximateIngredientQuantity = estimateIngredientQuantity(
20985
+ result.totalApproximateQuantity,
20986
+ context
20987
+ );
20988
+ }
20200
20989
  if (containerValue && containerValue > 0) {
20201
20990
  let effectiveUnits = totalUnits;
20202
- if (containerUnit && doseUnit && containerUnit !== doseUnit) {
20203
- let strength = context == null ? void 0 : context.strengthRatio;
20204
- if (!strength && (context == null ? void 0 : context.strength)) {
20205
- strength = parseStrengthIntoRatio(context.strength, context) || void 0;
20991
+ let effectiveContainerValue = containerValue;
20992
+ if (containerUnit && ((_n = result.totalApproximateQuantity) == null ? void 0 : _n.unit) && result.totalApproximateQuantity.value !== void 0 && result.totalApproximateQuantity.unit.trim().toLowerCase() === containerUnit.trim().toLowerCase()) {
20993
+ effectiveUnits = result.totalApproximateQuantity.value;
20994
+ result.totalContainerQuantity = {
20995
+ value: result.totalApproximateQuantity.value,
20996
+ unit: containerUnit
20997
+ };
20998
+ } else if (packageUnit && doseUnit && doseUnit.trim().toLowerCase() === packageUnit.trim().toLowerCase()) {
20999
+ effectiveUnits = totalUnits;
21000
+ effectiveContainerValue = 1;
21001
+ if (containerUnit) {
21002
+ result.totalContainerQuantity = {
21003
+ value: roundCalculatedUnits(totalUnits * containerValue),
21004
+ unit: containerUnit
21005
+ };
20206
21006
  }
21007
+ } else if (containerUnit && doseUnit && containerUnit !== doseUnit) {
21008
+ const strength = resolveContextStrengthRatio(context);
20207
21009
  const converted = convertValue(totalUnits, doseUnit, containerUnit, strength);
20208
21010
  if (converted !== null) {
20209
21011
  effectiveUnits = converted;
20210
21012
  }
20211
21013
  }
20212
- result.totalContainers = Math.ceil(effectiveUnits / containerValue);
21014
+ result.totalContainers = Math.ceil(effectiveUnits / effectiveContainerValue);
20213
21015
  }
20214
21016
  return result;
20215
21017
  }
20216
21018
  function calculateTotalUnits(options) {
21019
+ var _a2, _b, _c, _d, _e, _f;
20217
21020
  if (Array.isArray(options.dosage)) {
20218
21021
  const hasAnyDosage = options.dosage.length > 0;
20219
21022
  if (!hasAnyDosage) {
@@ -20221,18 +21024,62 @@ function calculateTotalUnits(options) {
20221
21024
  }
20222
21025
  let totalUnits = 0;
20223
21026
  let totalContainers = 0;
21027
+ let totalContainerQuantity;
21028
+ let totalApproximateQuantity;
21029
+ let totalApproximateIngredientQuantity;
21030
+ let mixedTotalContainerQuantities = false;
21031
+ let mixedApproximateQuantities = false;
21032
+ let mixedApproximateIngredientQuantities = false;
20224
21033
  let sawContainers = false;
20225
21034
  for (const dosage of options.dosage) {
20226
21035
  const result = calculateTotalUnitsSingle(__spreadProps(__spreadValues({}, options), {
20227
21036
  dosage
20228
21037
  }));
20229
- totalUnits += result.totalUnits;
21038
+ totalUnits = roundCalculatedUnits(totalUnits + result.totalUnits);
21039
+ if (result.totalApproximateQuantity && !mixedApproximateQuantities) {
21040
+ if (totalApproximateQuantity && totalApproximateQuantity.unit === result.totalApproximateQuantity.unit && totalApproximateQuantity.confidence === result.totalApproximateQuantity.confidence && totalApproximateQuantity.basis === result.totalApproximateQuantity.basis && totalApproximateQuantity.source === result.totalApproximateQuantity.source) {
21041
+ totalApproximateQuantity.value = roundCalculatedUnits(
21042
+ ((_a2 = totalApproximateQuantity.value) != null ? _a2 : 0) + ((_b = result.totalApproximateQuantity.value) != null ? _b : 0)
21043
+ );
21044
+ } else if (!totalApproximateQuantity) {
21045
+ totalApproximateQuantity = __spreadValues({}, result.totalApproximateQuantity);
21046
+ } else {
21047
+ totalApproximateQuantity = void 0;
21048
+ mixedApproximateQuantities = true;
21049
+ }
21050
+ }
21051
+ if (result.totalApproximateIngredientQuantity && !mixedApproximateIngredientQuantities) {
21052
+ if (totalApproximateIngredientQuantity && totalApproximateIngredientQuantity.unit === result.totalApproximateIngredientQuantity.unit && totalApproximateIngredientQuantity.confidence === result.totalApproximateIngredientQuantity.confidence && totalApproximateIngredientQuantity.basis === result.totalApproximateIngredientQuantity.basis && totalApproximateIngredientQuantity.source === result.totalApproximateIngredientQuantity.source) {
21053
+ totalApproximateIngredientQuantity.value = roundCalculatedUnits(
21054
+ ((_c = totalApproximateIngredientQuantity.value) != null ? _c : 0) + ((_d = result.totalApproximateIngredientQuantity.value) != null ? _d : 0)
21055
+ );
21056
+ } else if (!totalApproximateIngredientQuantity) {
21057
+ totalApproximateIngredientQuantity = __spreadValues({}, result.totalApproximateIngredientQuantity);
21058
+ } else {
21059
+ totalApproximateIngredientQuantity = void 0;
21060
+ mixedApproximateIngredientQuantities = true;
21061
+ }
21062
+ }
20230
21063
  if (result.totalContainers !== void 0) {
20231
21064
  totalContainers += result.totalContainers;
20232
21065
  sawContainers = true;
20233
21066
  }
21067
+ if (result.totalContainerQuantity && !mixedTotalContainerQuantities) {
21068
+ if (totalContainerQuantity && totalContainerQuantity.unit === result.totalContainerQuantity.unit && totalContainerQuantity.system === result.totalContainerQuantity.system && totalContainerQuantity.code === result.totalContainerQuantity.code) {
21069
+ totalContainerQuantity.value = roundCalculatedUnits(
21070
+ ((_e = totalContainerQuantity.value) != null ? _e : 0) + ((_f = result.totalContainerQuantity.value) != null ? _f : 0)
21071
+ );
21072
+ } else if (!totalContainerQuantity) {
21073
+ totalContainerQuantity = __spreadValues({}, result.totalContainerQuantity);
21074
+ } else {
21075
+ totalContainerQuantity = void 0;
21076
+ mixedTotalContainerQuantities = true;
21077
+ }
21078
+ }
20234
21079
  }
20235
- return sawContainers ? { totalUnits, totalContainers } : { totalUnits };
21080
+ return __spreadValues(__spreadValues(__spreadValues(__spreadValues({
21081
+ totalUnits
21082
+ }, sawContainers ? { totalContainers } : {}), !mixedTotalContainerQuantities && totalContainerQuantity ? { totalContainerQuantity } : {}), !mixedApproximateQuantities && totalApproximateQuantity ? { totalApproximateQuantity } : {}), !mixedApproximateIngredientQuantities && totalApproximateIngredientQuantity ? { totalApproximateIngredientQuantity } : {});
20236
21083
  }
20237
21084
  return calculateTotalUnitsSingle(options);
20238
21085
  }
@@ -20433,8 +21280,8 @@ function uniqueStrings(values) {
20433
21280
  return output;
20434
21281
  }
20435
21282
  function mergeParseResults(base, next, options) {
20436
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
20437
- const baseRepeat = (_b = (_a = base.fhir.timing) == null ? void 0 : _a.repeat) != null ? _b : {};
21283
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
21284
+ const baseRepeat = (_b = (_a2 = base.fhir.timing) == null ? void 0 : _a2.repeat) != null ? _b : {};
20438
21285
  const nextRepeat = (_d = (_c = next.fhir.timing) == null ? void 0 : _c.repeat) != null ? _d : {};
20439
21286
  const mergedWhen = uniqueStrings([...(_e = baseRepeat.when) != null ? _e : [], ...(_f = nextRepeat.when) != null ? _f : []]);
20440
21287
  const mergedTimeOfDay = uniqueStrings([...(_g = baseRepeat.timeOfDay) != null ? _g : [], ...(_h = nextRepeat.timeOfDay) != null ? _h : []]).sort();
@@ -20593,8 +21440,8 @@ function formatSig(dosage, style = "short", options) {
20593
21440
  return formatCanonicalClause(clause, style, localization, options);
20594
21441
  }
20595
21442
  function formatSigBatch(dosages, style = "short", options) {
20596
- var _a;
20597
- const separator = (_a = options == null ? void 0 : options.separator) != null ? _a : ", ";
21443
+ var _a2;
21444
+ const separator = (_a2 = options == null ? void 0 : options.separator) != null ? _a2 : ", ";
20598
21445
  const formatted = [];
20599
21446
  for (const dosage of dosages) {
20600
21447
  const text = formatSig(dosage, style, options);
@@ -20609,7 +21456,7 @@ function formatParseBatch(batch, style = "short", separator = ", ") {
20609
21456
  return texts.join(separator);
20610
21457
  }
20611
21458
  function fromFhirDosage(dosage, options) {
20612
- var _a;
21459
+ var _a2;
20613
21460
  const clause = canonicalFromFhir(dosage);
20614
21461
  const localization = resolveSigLocalization(options == null ? void 0 : options.locale, options == null ? void 0 : options.i18n);
20615
21462
  const shortText = formatCanonicalClause(clause, "short", localization, options);
@@ -20620,10 +21467,10 @@ function fromFhirDosage(dosage, options) {
20620
21467
  fhir: dosage,
20621
21468
  shortText,
20622
21469
  longText,
20623
- warnings: (_a = clause.warnings) != null ? _a : [],
21470
+ warnings: (_a2 = clause.warnings) != null ? _a2 : [],
20624
21471
  meta: {
20625
21472
  consumedTokens: [],
20626
- normalized: buildNormalizedMetaFromClause(clause, dosage),
21473
+ normalized: buildNormalizedMetaFromClause(clause, dosage, options),
20627
21474
  canonical: {
20628
21475
  clauses: [clause]
20629
21476
  }
@@ -20645,8 +21492,8 @@ function createEmptyCanonicalClause2(rawText) {
20645
21492
  };
20646
21493
  }
20647
21494
  function getPrimaryClause(clauses, rawText) {
20648
- var _a;
20649
- return (_a = clauses[0]) != null ? _a : createEmptyCanonicalClause2(rawText);
21495
+ var _a2;
21496
+ return (_a2 = clauses[0]) != null ? _a2 : createEmptyCanonicalClause2(rawText);
20650
21497
  }
20651
21498
  function cloneCoding2(coding) {
20652
21499
  if (!(coding == null ? void 0 : coding.code) && !(coding == null ? void 0 : coding.display) && !(coding == null ? void 0 : coding.system)) {
@@ -20669,32 +21516,36 @@ function cloneBodySiteCoding2(coding) {
20669
21516
  system: coding.system
20670
21517
  };
20671
21518
  }
20672
- function buildNormalizedMetaFromClause(clause, fhir) {
20673
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E;
20674
- const additionalInstructions = ((_a = clause.additionalInstructions) == null ? void 0 : _a.length) ? clause.additionalInstructions.map((instruction) => ({
21519
+ function buildNormalizedMetaFromClause(clause, fhir, options) {
21520
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
21521
+ const additionalInstructions = ((_a2 = clause.additionalInstructions) == null ? void 0 : _a2.length) ? clause.additionalInstructions.map((instruction) => ({
20675
21522
  text: instruction.text,
20676
21523
  coding: cloneCoding2(instruction.coding)
20677
21524
  })) : void 0;
20678
21525
  const siteCoding = (_e = cloneBodySiteCoding2((_b = clause.site) == null ? void 0 : _b.coding)) != null ? _e : cloneBodySiteCoding2((_d = (_c = fhir == null ? void 0 : fhir.site) == null ? void 0 : _c.coding) == null ? void 0 : _d[0]);
21526
+ const parseContext = options && "context" in options ? options.context : void 0;
21527
+ const unitSemantics = getDoseUnitSemantics((_f = clause.dose) == null ? void 0 : _f.unit, parseContext);
20679
21528
  return {
20680
- route: (_f = clause.route) == null ? void 0 : _f.code,
20681
- unit: (_g = clause.dose) == null ? void 0 : _g.unit,
20682
- site: ((_h = clause.site) == null ? void 0 : _h.text) || ((_j = (_i = clause.site) == null ? void 0 : _i.coding) == null ? void 0 : _j.code) || ((_k = clause.site) == null ? void 0 : _k.spatialRelation) ? {
20683
- text: (_l = clause.site) == null ? void 0 : _l.text,
21529
+ route: (_g = clause.route) == null ? void 0 : _g.code,
21530
+ unit: (_h = clause.dose) == null ? void 0 : _h.unit,
21531
+ unitKind: unitSemantics == null ? void 0 : unitSemantics.kind,
21532
+ unitSemantics,
21533
+ site: ((_i = clause.site) == null ? void 0 : _i.text) || ((_k = (_j = clause.site) == null ? void 0 : _j.coding) == null ? void 0 : _k.code) || ((_l = clause.site) == null ? void 0 : _l.spatialRelation) ? {
21534
+ text: (_m = clause.site) == null ? void 0 : _m.text,
20684
21535
  coding: siteCoding,
20685
- spatialRelation: cloneBodySiteSpatialRelation((_m = clause.site) == null ? void 0 : _m.spatialRelation)
21536
+ spatialRelation: cloneBodySiteSpatialRelation((_n = clause.site) == null ? void 0 : _n.spatialRelation)
20686
21537
  } : void 0,
20687
- method: ((_n = clause.method) == null ? void 0 : _n.text) || ((_p = (_o = clause.method) == null ? void 0 : _o.coding) == null ? void 0 : _p.code) ? {
20688
- text: (_q = clause.method) == null ? void 0 : _q.text,
20689
- coding: cloneCoding2((_r = clause.method) == null ? void 0 : _r.coding)
21538
+ method: ((_o = clause.method) == null ? void 0 : _o.text) || ((_q = (_p = clause.method) == null ? void 0 : _p.coding) == null ? void 0 : _q.code) ? {
21539
+ text: (_r = clause.method) == null ? void 0 : _r.text,
21540
+ coding: cloneCoding2((_s = clause.method) == null ? void 0 : _s.coding)
20690
21541
  } : void 0,
20691
21542
  patientInstruction: clause.patientInstruction,
20692
- prnReason: ((_t = (_s = clause.prn) == null ? void 0 : _s.reason) == null ? void 0 : _t.text) || ((_w = (_v = (_u = clause.prn) == null ? void 0 : _u.reason) == null ? void 0 : _v.coding) == null ? void 0 : _w.code) ? {
20693
- text: (_y = (_x = clause.prn) == null ? void 0 : _x.reason) == null ? void 0 : _y.text,
20694
- coding: cloneCoding2((_A = (_z = clause.prn) == null ? void 0 : _z.reason) == null ? void 0 : _A.coding),
20695
- spatialRelation: cloneBodySiteSpatialRelation((_C = (_B = clause.prn) == null ? void 0 : _B.reason) == null ? void 0 : _C.spatialRelation)
21543
+ prnReason: ((_u = (_t = clause.prn) == null ? void 0 : _t.reason) == null ? void 0 : _u.text) || ((_x = (_w = (_v = clause.prn) == null ? void 0 : _v.reason) == null ? void 0 : _w.coding) == null ? void 0 : _x.code) ? {
21544
+ text: (_z = (_y = clause.prn) == null ? void 0 : _y.reason) == null ? void 0 : _z.text,
21545
+ coding: cloneCoding2((_B = (_A = clause.prn) == null ? void 0 : _A.reason) == null ? void 0 : _B.coding),
21546
+ spatialRelation: cloneBodySiteSpatialRelation((_D = (_C = clause.prn) == null ? void 0 : _C.reason) == null ? void 0 : _D.spatialRelation)
20696
21547
  } : void 0,
20697
- prnReasons: ((_E = (_D = clause.prn) == null ? void 0 : _D.reasons) == null ? void 0 : _E.length) ? clause.prn.reasons.map((reason) => ({
21548
+ prnReasons: ((_F = (_E = clause.prn) == null ? void 0 : _E.reasons) == null ? void 0 : _F.length) ? clause.prn.reasons.map((reason) => ({
20698
21549
  text: reason.text,
20699
21550
  coding: cloneCoding2(reason.coding),
20700
21551
  spatialRelation: cloneBodySiteSpatialRelation(reason.spatialRelation)
@@ -20764,7 +21615,7 @@ function buildParseResult(state, options) {
20764
21615
  meta: {
20765
21616
  consumedTokens,
20766
21617
  leftoverText: leftoverParts.length ? leftoverParts.join(" ") : void 0,
20767
- normalized: buildNormalizedMetaFromClause(clause, fhir),
21618
+ normalized: buildNormalizedMetaFromClause(clause, fhir, options),
20768
21619
  canonical: {
20769
21620
  clauses: canonicalClauses
20770
21621
  },
@@ -20844,10 +21695,10 @@ function resolvePrimaryParseResult(results, input, options) {
20844
21695
  return buildParseResult(state, options);
20845
21696
  }
20846
21697
  function buildSemanticLintIssues(result, input, fallbackRange) {
20847
- var _a;
21698
+ var _a2;
20848
21699
  const issues = [];
20849
21700
  const clause = result.meta.canonical.clauses[0];
20850
- const range = (_a = clause == null ? void 0 : clause.span) != null ? _a : fallbackRange;
21701
+ const range = (_a2 = clause == null ? void 0 : clause.span) != null ? _a2 : fallbackRange;
20851
21702
  const text = range ? input.slice(range.start, range.end) : input;
20852
21703
  const trimmedText = text.trim() || text;
20853
21704
  const tokens = trimmedText ? trimmedText.split(/\s+/).filter((part) => part.length > 0) : [];
@@ -20932,11 +21783,15 @@ export {
20932
21783
  getBodySiteCodeAsync,
20933
21784
  getBodySiteText,
20934
21785
  getBodySiteTextAsync,
21786
+ getDoseUnitApproximation,
21787
+ getDoseUnitKind,
21788
+ getDoseUnitSemantics,
20935
21789
  getRegisteredSigLocalizations,
20936
21790
  hasSnomedBodySiteLateralityPostcoordination,
20937
21791
  hasSnomedFindingSitePostcoordination,
20938
21792
  hasSnomedTopographicalModifierPostcoordination,
20939
21793
  lintSig,
21794
+ listDoseUnitTerminology,
20940
21795
  listSupportedBodySiteGrammar,
20941
21796
  listSupportedBodySiteText,
20942
21797
  lookupBodySite,