ezmedicationinput 0.1.56 → 0.1.58

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
@@ -1783,7 +1783,8 @@ var instruction_action_terminology_default = {
1783
1783
  },
1784
1784
  aliases: [
1785
1785
  "drink",
1786
- "\u0E14\u0E37\u0E48\u0E21"
1786
+ "\u0E14\u0E37\u0E48\u0E21",
1787
+ "drinking"
1787
1788
  ],
1788
1789
  procedural: false,
1789
1790
  acceptsAmount: true,
@@ -3316,6 +3317,19 @@ var instruction_concept_terminology_default = {
3316
3317
  "\u0E41\u0E1C\u0E48\u0E19\u0E43\u0E2B\u0E21\u0E48"
3317
3318
  ]
3318
3319
  },
3320
+ {
3321
+ code: "thoroughly",
3322
+ role: "manner",
3323
+ display: "thoroughly",
3324
+ i18n: {
3325
+ th: "\u0E43\u0E2B\u0E49\u0E17\u0E31\u0E48\u0E27"
3326
+ },
3327
+ aliases: [
3328
+ "thoroughly",
3329
+ "\u0E43\u0E2B\u0E49\u0E17\u0E31\u0E48\u0E27",
3330
+ "\u0E2D\u0E22\u0E48\u0E32\u0E07\u0E17\u0E31\u0E48\u0E27\u0E16\u0E36\u0E07"
3331
+ ]
3332
+ },
3319
3333
  {
3320
3334
  code: "clean-result",
3321
3335
  role: "result",
@@ -3399,6 +3413,21 @@ var instruction_concept_terminology_default = {
3399
3413
  "sleep",
3400
3414
  "\u0E19\u0E2D\u0E19"
3401
3415
  ]
3416
+ },
3417
+ {
3418
+ code: "dissolved",
3419
+ role: "result",
3420
+ display: "dissolved",
3421
+ i18n: {
3422
+ th: "\u0E25\u0E30\u0E25\u0E32\u0E22\u0E2B\u0E21\u0E14"
3423
+ },
3424
+ aliases: [
3425
+ "dissolved",
3426
+ "fully dissolved",
3427
+ "completely dissolved",
3428
+ "\u0E25\u0E30\u0E25\u0E32\u0E22\u0E2B\u0E21\u0E14",
3429
+ "\u0E25\u0E30\u0E25\u0E32\u0E22\u0E08\u0E19\u0E2B\u0E21\u0E14"
3430
+ ]
3402
3431
  }
3403
3432
  ]
3404
3433
  };
@@ -3967,7 +3996,10 @@ var symptom_terminology_default = {
3967
3996
  "pain",
3968
3997
  "ache",
3969
3998
  "aches",
3970
- "pains"
3999
+ "pains",
4000
+ "painful",
4001
+ "hurt",
4002
+ "hurts"
3971
4003
  ],
3972
4004
  definition: {
3973
4005
  coding: {
@@ -3982,6 +4014,10 @@ var symptom_terminology_default = {
3982
4014
  ],
3983
4015
  i18n: {
3984
4016
  th: "\u0E1B\u0E27\u0E14"
4017
+ },
4018
+ conditionI18n: {
4019
+ en: "painful",
4020
+ th: "\u0E1B\u0E27\u0E14"
3985
4021
  }
3986
4022
  }
3987
4023
  },
@@ -6986,7 +7022,11 @@ var DEFAULT_BODY_SITE_SNOMED_SOURCE = [
6986
7022
  },
6987
7023
  {
6988
7024
  names: ["tongue", "tongues"],
6989
- definition: { coding: { code: "21974007", display: "Tongue" }, routeHint: RouteCode["Sublingual route"] }
7025
+ definition: {
7026
+ coding: { code: "21974007", display: "Tongue" },
7027
+ i18n: { th: "\u0E25\u0E34\u0E49\u0E19" },
7028
+ routeHint: RouteCode["Sublingual route"]
7029
+ }
6990
7030
  },
6991
7031
  {
6992
7032
  names: ["lip", "lips"],
@@ -7652,6 +7692,10 @@ var DEFAULT_BODY_SITE_SNOMED_SOURCE = [
7652
7692
  names: [
7653
7693
  "interdigital spaces",
7654
7694
  "interdigital space",
7695
+ "interdigital web spaces",
7696
+ "interdigital web space",
7697
+ "web spaces",
7698
+ "web space",
7655
7699
  "\u0E23\u0E30\u0E2B\u0E27\u0E48\u0E32\u0E07\u0E23\u0E48\u0E2D\u0E07\u0E19\u0E34\u0E49\u0E27",
7656
7700
  "\u0E23\u0E48\u0E2D\u0E07\u0E19\u0E34\u0E49\u0E27",
7657
7701
  "\u0E0B\u0E2D\u0E01\u0E19\u0E34\u0E49\u0E27",
@@ -9731,7 +9775,8 @@ var relation_terminology_default = {
9731
9775
  {
9732
9776
  canonical: "outside",
9733
9777
  aliases: [
9734
- "outside"
9778
+ "outside",
9779
+ "outside of"
9735
9780
  ],
9736
9781
  locative: true,
9737
9782
  realization: {
@@ -10006,6 +10051,46 @@ var relation_terminology_default = {
10006
10051
  strategy: "prefix"
10007
10052
  }
10008
10053
  }
10054
+ },
10055
+ {
10056
+ canonical: "at",
10057
+ aliases: [
10058
+ "at"
10059
+ ],
10060
+ realization: {
10061
+ en: {
10062
+ surface: "at",
10063
+ strategy: "prefix"
10064
+ },
10065
+ th: {
10066
+ surface: "\u0E15\u0E23\u0E07",
10067
+ strategy: "prefix",
10068
+ omitOuterSitePreposition: true
10069
+ }
10070
+ },
10071
+ grammar: {
10072
+ qualifierTarget: "site"
10073
+ }
10074
+ },
10075
+ {
10076
+ canonical: "where",
10077
+ aliases: [
10078
+ "where"
10079
+ ],
10080
+ realization: {
10081
+ en: {
10082
+ surface: "where",
10083
+ strategy: "prefix"
10084
+ },
10085
+ th: {
10086
+ surface: "\u0E17\u0E35\u0E48",
10087
+ strategy: "prefix",
10088
+ omitOuterSitePreposition: true
10089
+ }
10090
+ },
10091
+ grammar: {
10092
+ qualifierTarget: "symptom"
10093
+ }
10009
10094
  }
10010
10095
  ]
10011
10096
  };
@@ -10146,6 +10231,10 @@ for (const relation of ADVICE_RELATION_VALUES) {
10146
10231
  }
10147
10232
  var ACTION_SEQUENCE_MARKERS = ACTION_SEQUENCE_MARKERS_INTERNAL;
10148
10233
  var ACTION_SEQUENCE_RELATION_SURFACES = ACTION_SEQUENCE_RELATION_SURFACES_INTERNAL;
10234
+ function resolveActionRelationSurfaceCandidates(surface) {
10235
+ var _a26;
10236
+ return (_a26 = ACTION_RELATION_INDEX.get(normalize(surface))) != null ? _a26 : [];
10237
+ }
10149
10238
  function resolveActionRelationSurface(surface, preferredSemanticClasses) {
10150
10239
  var _a26, _b3;
10151
10240
  const normalized = normalize(surface);
@@ -12483,6 +12572,7 @@ function matchBodySiteLocativeRelation(words, start = 0) {
12483
12572
  return relation ? { relation, length: 1 } : void 0;
12484
12573
  }
12485
12574
  function parseBodySiteFeatures(text, coding, customSiteMap) {
12575
+ var _a26;
12486
12576
  const normalized = normalizeBodySiteKey(text);
12487
12577
  if (!normalized) {
12488
12578
  return buildNominalFeatures(text, normalized, coding, customSiteMap);
@@ -12531,30 +12621,49 @@ function parseBodySiteFeatures(text, coding, customSiteMap) {
12531
12621
  whole: buildNominalFeatures(wholeText, normalizeBodySiteKey(wholeText), void 0, customSiteMap)
12532
12622
  };
12533
12623
  }
12624
+ if (words.length > 1 && (firstWord === "left" || firstWord === "right") && !lookupDefinitionForCanonical(normalized, customSiteMap)) {
12625
+ const wholeText = words.slice(1).join(" ");
12626
+ const wholeCanonical = normalizeBodySiteKey(wholeText);
12627
+ const wholeDefinition = lookupDefinitionForCanonical(wholeCanonical, customSiteMap);
12628
+ if (((_a26 = wholeDefinition == null ? void 0 : wholeDefinition.coding) == null ? void 0 : _a26.code) || (wholeDefinition == null ? void 0 : wholeDefinition.routeHint)) {
12629
+ return {
12630
+ kind: "partitive",
12631
+ part: `${firstWord} side`,
12632
+ relationKey: "side",
12633
+ whole: buildNominalFeatures(wholeText, wholeCanonical, void 0, customSiteMap),
12634
+ attributive: true
12635
+ };
12636
+ }
12637
+ }
12534
12638
  return buildNominalFeatures(text, normalized, coding, customSiteMap);
12535
12639
  }
12536
12640
  function renderNominalObject(features) {
12537
12641
  return features.article === "bare" ? features.text : `the ${features.text}`;
12538
12642
  }
12539
12643
  function renderBodySiteObject(features) {
12540
- var _a26, _b3;
12644
+ var _a26, _b3, _c2;
12541
12645
  switch (features.kind) {
12542
12646
  case "locative": {
12543
12647
  const surface = (_b3 = (_a26 = getBodySiteRelationRealization(features.relation, "en")) == null ? void 0 : _a26.surface) != null ? _b3 : features.relation;
12544
12648
  return `${surface} ${renderBodySiteObject(features.target)}`;
12545
12649
  }
12546
12650
  case "partitive":
12651
+ if (features.attributive) {
12652
+ const side = (_c2 = features.part.split(/\s+/u)[0]) != null ? _c2 : features.part;
12653
+ return features.whole.article === "bare" ? `${side} ${features.whole.text}` : `the ${side} ${features.whole.text}`;
12654
+ }
12547
12655
  return `${features.part.startsWith("both") || features.part.startsWith("bilateral") ? features.part : `the ${features.part}`} of ${renderNominalObject(features.whole)}`;
12548
12656
  case "nominal":
12549
12657
  return renderNominalObject(features);
12550
12658
  }
12551
12659
  }
12552
12660
  function featureDisplayText(features) {
12661
+ var _a26;
12553
12662
  switch (features.kind) {
12554
12663
  case "locative":
12555
12664
  return `${features.relation} ${featureDisplayText(features.target)}`;
12556
12665
  case "partitive":
12557
- return `${features.part} of ${features.whole.text}`;
12666
+ return features.attributive ? `${(_a26 = features.part.split(/\s+/u)[0]) != null ? _a26 : features.part} ${features.whole.text}` : `${features.part} of ${features.whole.text}`;
12558
12667
  case "nominal":
12559
12668
  return features.text;
12560
12669
  }
@@ -12629,6 +12738,103 @@ function inferPreferredPreposition(canonical, features, definition) {
12629
12738
  }
12630
12739
  return void 0;
12631
12740
  }
12741
+ function withBodySiteQualifier(features, qualifier) {
12742
+ return __spreadProps(__spreadValues({}, features), { qualifier });
12743
+ }
12744
+ var BODY_SITE_QUALIFIER_MATCHERS = (() => {
12745
+ var _a26, _b3;
12746
+ const matchers = [];
12747
+ const seen = /* @__PURE__ */ new Set();
12748
+ for (const definition of listBodySiteRelationDefinitions()) {
12749
+ const target = definition.grammar.qualifierTarget;
12750
+ if (!target) continue;
12751
+ const surfaces = [
12752
+ definition.canonical,
12753
+ ...definition.aliases,
12754
+ (_a26 = definition.realization.en) == null ? void 0 : _a26.surface,
12755
+ (_b3 = definition.realization.th) == null ? void 0 : _b3.surface
12756
+ ];
12757
+ for (const surface of surfaces) {
12758
+ const normalizedSurface = surface ? normalizeBodySiteKey(surface) : "";
12759
+ if (!normalizedSurface) continue;
12760
+ const key2 = `${definition.canonical}|${target}|${normalizedSurface}`;
12761
+ if (seen.has(key2)) continue;
12762
+ seen.add(key2);
12763
+ matchers.push({
12764
+ relation: definition.canonical,
12765
+ target,
12766
+ marker: ` ${normalizedSurface} `
12767
+ });
12768
+ }
12769
+ }
12770
+ return matchers.sort((left, right) => right.marker.length - left.marker.length);
12771
+ })();
12772
+ function matchBodySiteQualifier(lookupCanonical) {
12773
+ let best;
12774
+ for (const matcher of BODY_SITE_QUALIFIER_MATCHERS) {
12775
+ const index = lookupCanonical.lastIndexOf(matcher.marker);
12776
+ if (index <= 0 || index + matcher.marker.length >= lookupCanonical.length) continue;
12777
+ const candidate = {
12778
+ relation: matcher.relation,
12779
+ target: matcher.target,
12780
+ start: index,
12781
+ end: index + matcher.marker.length
12782
+ };
12783
+ if (!best || candidate.start > best.start || candidate.start === best.start && candidate.end > best.end) best = candidate;
12784
+ }
12785
+ return best;
12786
+ }
12787
+ function qualifiedBodySitePhrase(lookupCanonical, customSiteMap, context) {
12788
+ var _a26, _b3, _c2, _d, _e, _f, _g, _h;
12789
+ const match = matchBodySiteQualifier(lookupCanonical);
12790
+ if (!match) return void 0;
12791
+ const base = resolveBodySitePhrase(lookupCanonical.slice(0, match.start), customSiteMap, context);
12792
+ if (!base) return void 0;
12793
+ const targetText = lookupCanonical.slice(match.end);
12794
+ const realization = getBodySiteRelationRealization(match.relation, "en");
12795
+ if (!realization) return void 0;
12796
+ if (match.target === "symptom") {
12797
+ const symptom = resolveSymptomDefinition(targetText);
12798
+ if (!symptom) return void 0;
12799
+ const conditionText = (_d = (_c2 = (_a26 = symptom.conditionI18n) == null ? void 0 : _a26.en) != null ? _c2 : (_b3 = symptom.text) == null ? void 0 : _b3.toLowerCase()) != null ? _d : targetText;
12800
+ const qualifier2 = {
12801
+ kind: "symptom",
12802
+ relation: match.relation,
12803
+ text: targetText,
12804
+ canonical: (_f = (_e = symptom.text) == null ? void 0 : _e.toLowerCase()) != null ? _f : targetText,
12805
+ coding: symptom.coding ? __spreadValues({}, symptom.coding) : void 0,
12806
+ i18n: __spreadValues(__spreadValues({ en: conditionText }, (_g = symptom.i18n) != null ? _g : {}), (_h = symptom.conditionI18n) != null ? _h : {})
12807
+ };
12808
+ return __spreadProps(__spreadValues({}, base), {
12809
+ lookupCanonical,
12810
+ resolutionCanonical: `${base.resolutionCanonical} ${match.relation} ${qualifier2.canonical}`,
12811
+ canonical: `${base.canonical} ${match.relation} ${qualifier2.canonical}`,
12812
+ displayText: `${base.displayText} ${realization.surface} ${conditionText}`,
12813
+ features: withBodySiteQualifier(base.features, qualifier2),
12814
+ englishObjectText: `${base.englishObjectText} ${realization.surface} ${conditionText}`
12815
+ });
12816
+ }
12817
+ const target = resolveBodySitePhrase(targetText, customSiteMap, context);
12818
+ if (!target) return void 0;
12819
+ if (base.resolutionCanonical === target.resolutionCanonical) return base;
12820
+ if (!(base.coding || base.definition || base.spatialRelation)) return void 0;
12821
+ if (!(target.coding || target.definition || target.spatialRelation)) return void 0;
12822
+ const qualifier = {
12823
+ kind: "site",
12824
+ relation: match.relation,
12825
+ text: target.displayText,
12826
+ targetText: target.displayText,
12827
+ targetCoding: target.coding ? __spreadValues({}, target.coding) : void 0
12828
+ };
12829
+ return __spreadProps(__spreadValues({}, base), {
12830
+ lookupCanonical,
12831
+ resolutionCanonical: `${base.resolutionCanonical} ${match.relation} ${target.resolutionCanonical}`,
12832
+ canonical: `${base.canonical} ${match.relation} ${target.canonical}`,
12833
+ displayText: `${base.displayText} ${realization.surface} ${target.displayText}`,
12834
+ features: withBodySiteQualifier(base.features, qualifier),
12835
+ englishObjectText: `${base.englishObjectText} ${realization.surface} ${target.englishObjectText}`
12836
+ });
12837
+ }
12632
12838
  function resolveBodySitePhrase(text, customSiteMap, context) {
12633
12839
  var _a26, _b3, _c2, _d, _e, _f, _g, _h;
12634
12840
  const trimmed = text.trim().replace(/\s+/g, " ");
@@ -12636,6 +12842,8 @@ function resolveBodySitePhrase(text, customSiteMap, context) {
12636
12842
  return void 0;
12637
12843
  }
12638
12844
  const lookupCanonical = normalizeBodySiteKey(trimmed);
12845
+ const qualified = qualifiedBodySitePhrase(lookupCanonical, customSiteMap, context);
12846
+ if (qualified) return qualified;
12639
12847
  const contextualCanonical = resolveContextualBodySiteAlias(lookupCanonical, context);
12640
12848
  const displaySourceText = contextualCanonical != null ? contextualCanonical : trimmed;
12641
12849
  const displayText = normalizeSiteDisplayText(displaySourceText, customSiteMap);
@@ -12643,9 +12851,17 @@ function resolveBodySitePhrase(text, customSiteMap, context) {
12643
12851
  const directDefinition = (_e = (_d = (_c2 = (_b3 = (_a26 = lookupBodySiteDefinition(customSiteMap, lookupCanonical)) != null ? _a26 : contextualCanonical ? lookupBodySiteDefinition(customSiteMap, contextualCanonical) : void 0) != null ? _b3 : contextualCanonical ? DEFAULT_BODY_SITE_SNOMED[contextualCanonical] : void 0) != null ? _c2 : DEFAULT_BODY_SITE_SNOMED[lookupCanonical]) != null ? _d : lookupBodySiteDefinition(customSiteMap, canonical)) != null ? _e : DEFAULT_BODY_SITE_SNOMED[canonical];
12644
12852
  const preliminaryFeatures = parseBodySiteFeatures(displayText, void 0, customSiteMap);
12645
12853
  const terminal = directDefinition || !(context == null ? void 0 : context.allowTerminalModifierInheritance) || preliminaryFeatures.kind !== "nominal" || !terminalInheritanceIsLicensed(canonical) ? void 0 : longestTerminalBodySiteDefinition(canonical, customSiteMap);
12646
- const definition = directDefinition != null ? directDefinition : terminal == null ? void 0 : terminal.definition;
12647
- const coding = buildBodySiteCoding(definition);
12854
+ const baseDefinition = directDefinition != null ? directDefinition : terminal == null ? void 0 : terminal.definition;
12648
12855
  const finalDisplayText = (_f = directDefinition == null ? void 0 : directDefinition.text) != null ? _f : displayText;
12856
+ let inheritedDefinition;
12857
+ if (!baseDefinition) {
12858
+ const candidateFeatures = parseBodySiteFeatures(finalDisplayText, void 0, customSiteMap);
12859
+ if (candidateFeatures.kind === "partitive" && candidateFeatures.attributive) {
12860
+ inheritedDefinition = lookupDefinitionForCanonical(candidateFeatures.whole.canonical, customSiteMap);
12861
+ }
12862
+ }
12863
+ const definition = baseDefinition != null ? baseDefinition : inheritedDefinition;
12864
+ const coding = buildBodySiteCoding(definition);
12649
12865
  const features = parseBodySiteFeatures(finalDisplayText, coding, customSiteMap);
12650
12866
  const spatialRelation = (_g = definition == null ? void 0 : definition.spatialRelation) != null ? _g : buildSpatialRelation(features, finalDisplayText, customSiteMap);
12651
12867
  return {
@@ -15782,6 +15998,139 @@ function resolveEventTimingExpression(parts, start = 0, endExclusive = parts.len
15782
15998
  return direct ? { timing: direct, length: 1 } : void 0;
15783
15999
  }
15784
16000
 
16001
+ // src/hpsg/timing-lexicon.ts
16002
+ var EVERY_INTERVAL_TOKENS = EVERY_INTERVAL_TOKENS_DATA;
16003
+ var COUNT_MARKER_TOKENS = COUNT_MARKER_TOKENS_DATA;
16004
+ var FREQUENCY_SIMPLE_WORDS = FREQUENCY_SIMPLE_WORDS_DATA;
16005
+ var FREQUENCY_NUMBER_WORDS = FREQUENCY_NUMBER_WORDS_DATA;
16006
+ var FREQUENCY_TIMES_WORDS = FREQUENCY_TIMES_WORDS_DATA;
16007
+ var FREQUENCY_CONNECTOR_WORDS = FREQUENCY_CONNECTOR_WORDS_DATA;
16008
+ function mapPeriodUnitLabel(label) {
16009
+ return FhirPeriodUnit[label];
16010
+ }
16011
+ var FREQUENCY_ADVERB_UNITS = new Map(
16012
+ Array.from(FREQUENCY_ADVERB_UNITS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
16013
+ );
16014
+ var INTERVAL_UNITS = new Map(
16015
+ Array.from(INTERVAL_UNIT_TOKENS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
16016
+ );
16017
+ function normalizePeriodValue(value, unit) {
16018
+ if (unit === "h" /* Hour */ && (!Number.isInteger(value) || value < 1)) {
16019
+ return { value: Math.round(value * 60 * 1e3) / 1e3, unit: "min" /* Minute */ };
16020
+ }
16021
+ return { value, unit };
16022
+ }
16023
+ function normalizePeriodRange(low, high, unit) {
16024
+ if (unit === "h" /* Hour */ && (!Number.isInteger(low) || !Number.isInteger(high) || low < 1 || high < 1)) {
16025
+ return {
16026
+ low: Math.round(low * 60 * 1e3) / 1e3,
16027
+ high: Math.round(high * 60 * 1e3) / 1e3,
16028
+ unit: "min" /* Minute */
16029
+ };
16030
+ }
16031
+ return { low, high, unit };
16032
+ }
16033
+ var FIXED_PERIOD_SECONDS = {
16034
+ ["s" /* Second */]: 1,
16035
+ ["min" /* Minute */]: 60,
16036
+ ["h" /* Hour */]: 60 * 60,
16037
+ ["d" /* Day */]: 24 * 60 * 60,
16038
+ ["wk" /* Week */]: 7 * 24 * 60 * 60
16039
+ };
16040
+ function normalizeMixedPeriodRange(low, lowUnit, high, highUnit) {
16041
+ if (lowUnit === highUnit) {
16042
+ const normalized = normalizePeriodRange(low, high, lowUnit);
16043
+ return normalized.low <= normalized.high ? normalized : void 0;
16044
+ }
16045
+ const lowScale = FIXED_PERIOD_SECONDS[lowUnit];
16046
+ const highScale = FIXED_PERIOD_SECONDS[highUnit];
16047
+ if (!lowScale || !highScale) return void 0;
16048
+ const unit = lowScale <= highScale ? lowUnit : highUnit;
16049
+ const unitScale = FIXED_PERIOD_SECONDS[unit];
16050
+ const normalizedLow = Math.round(low * lowScale / unitScale * 1e3) / 1e3;
16051
+ const normalizedHigh = Math.round(high * highScale / unitScale * 1e3) / 1e3;
16052
+ if (normalizedLow > normalizedHigh) return void 0;
16053
+ return { low: normalizedLow, high: normalizedHigh, unit };
16054
+ }
16055
+ function periodUnitSuffix(unit) {
16056
+ switch (unit) {
16057
+ case "min" /* Minute */:
16058
+ return "min";
16059
+ case "h" /* Hour */:
16060
+ return "h";
16061
+ case "d" /* Day */:
16062
+ return "d";
16063
+ case "wk" /* Week */:
16064
+ return "wk";
16065
+ case "mo" /* Month */:
16066
+ return "mo";
16067
+ case "a" /* Year */:
16068
+ return "a";
16069
+ default:
16070
+ return void 0;
16071
+ }
16072
+ }
16073
+ function deriveDefaultTimingForPeriod(value, unit, currentTimingCode) {
16074
+ let timingCode = currentTimingCode;
16075
+ const suffix = periodUnitSuffix(unit);
16076
+ if (suffix) {
16077
+ const key2 = `q${value}${suffix}`;
16078
+ const descriptor = TIMING_ABBREVIATIONS[key2];
16079
+ if (descriptor == null ? void 0 : descriptor.code) {
16080
+ timingCode = timingCode != null ? timingCode : descriptor.code;
16081
+ }
16082
+ }
16083
+ if (unit === "wk" /* Week */ && value === 1) {
16084
+ timingCode = timingCode != null ? timingCode : "WK";
16085
+ }
16086
+ if (unit === "mo" /* Month */ && value === 1) {
16087
+ timingCode = timingCode != null ? timingCode : "MO";
16088
+ }
16089
+ return {
16090
+ frequency: unit === "d" /* Day */ && value === 1 ? 1 : void 0,
16091
+ timingCode
16092
+ };
16093
+ }
16094
+ function buildPeriodScheduleFeature(period, unit) {
16095
+ const normalized = normalizePeriodValue(period, unit);
16096
+ const defaults = deriveDefaultTimingForPeriod(normalized.value, normalized.unit);
16097
+ return {
16098
+ period: normalized.value,
16099
+ periodUnit: normalized.unit,
16100
+ frequency: defaults.frequency,
16101
+ timingCode: defaults.timingCode
16102
+ };
16103
+ }
16104
+ function mapIntervalUnit(token) {
16105
+ const unit = INTERVAL_UNITS.get(token);
16106
+ return unit === "min" /* Minute */ || unit === "h" /* Hour */ || unit === "d" /* Day */ || unit === "wk" /* Week */ || unit === "mo" /* Month */ ? unit : void 0;
16107
+ }
16108
+ function mapFrequencyAdverb(token) {
16109
+ return FREQUENCY_ADVERB_UNITS.get(token);
16110
+ }
16111
+ function parseNumericRange(token) {
16112
+ const rangeMatch = token.match(/^([0-9]+(?:\.[0-9]+)?)[-–—]([0-9]+(?:\.[0-9]+)?)$/);
16113
+ if (!rangeMatch) {
16114
+ return void 0;
16115
+ }
16116
+ const low = parseFloat(rangeMatch[1]);
16117
+ const high = parseFloat(rangeMatch[2]);
16118
+ if (!Number.isFinite(low) || !Number.isFinite(high) || high < low) {
16119
+ return void 0;
16120
+ }
16121
+ return { low, high };
16122
+ }
16123
+ function buildDurationScheduleFeature(value, unit, max) {
16124
+ if (value === void 0 || !Number.isFinite(value) || value <= 0 || !unit) {
16125
+ return void 0;
16126
+ }
16127
+ return {
16128
+ duration: value,
16129
+ durationMax: max !== void 0 && Number.isFinite(max) && max > value ? max : void 0,
16130
+ durationUnit: unit
16131
+ };
16132
+ }
16133
+
15785
16134
  // src/instruction-graph.ts
15786
16135
  var SNOMED_SYSTEM4 = "http://snomed.info/sct";
15787
16136
  var ACTION_ROUTE_TAIL_SURFACES = /* @__PURE__ */ new Set([
@@ -16665,6 +17014,9 @@ function buildActionFrame(parts, segmentStart, segmentEnd, input, offset, sequen
16665
17014
  const conditionalTail = relationHasGrammarFeature(rawRelation, "conditionalTail");
16666
17015
  const secondaryConditionalTail = relationHasGrammarFeature(nextRelation, "conditionalTail");
16667
17016
  const relation = conditionalTail ? void 0 : rawRelation;
17017
+ const secondaryActivityTarget = nextRelationIndex >= 0 ? resolveMedicationInstructionAction(key(parts[nextRelationIndex + 1]), options) : void 0;
17018
+ const secondaryActivityRelation = nextRelationIndex >= 0 && secondaryActivityTarget && relationHasGrammarFeature(nextRelation, "activityFallback") ? nextRelation : void 0;
17019
+ const frameRelation = secondaryActivityRelation != null ? secondaryActivityRelation : relation;
16668
17020
  const amount = definition.acceptsAmount ? parseQuantityArgument(parts, argumentStart, segmentEnd, input, offset, options) : void 0;
16669
17021
  const duration = parseAnyDurationArgument(parts, argumentStart, segmentEnd, input, offset);
16670
17022
  let semanticEnd = conditionalTail && relIndex >= 0 ? relIndex : secondaryConditionalTail && nextRelationIndex >= 0 ? nextRelationIndex : segmentEnd;
@@ -16687,6 +17039,16 @@ function buildActionFrame(parts, segmentStart, segmentEnd, input, offset, sequen
16687
17039
  separableParticleIndex: actionMatch.separableParticleIndex
16688
17040
  });
16689
17041
  const args = parsed.args;
17042
+ if (secondaryActivityRelation && nextRelationIndex >= 0) {
17043
+ pushArgument(args, argumentFromParts(
17044
+ parts,
17045
+ nextRelationIndex + 1,
17046
+ segmentEnd,
17047
+ input,
17048
+ "activity" /* Activity */,
17049
+ options
17050
+ ));
17051
+ }
16690
17052
  if (definition.argumentParser === "preposed-duration" && !args.some((arg) => arg.role === "duration" /* Duration */)) {
16691
17053
  return void 0;
16692
17054
  }
@@ -16717,7 +17079,7 @@ function buildActionFrame(parts, segmentStart, segmentEnd, input, offset, sequen
16717
17079
  }) : void 0,
16718
17080
  codings
16719
17081
  },
16720
- relation,
17082
+ relation: frameRelation,
16721
17083
  args,
16722
17084
  span,
16723
17085
  sourceText: input.slice(span.start - offset, span.end - offset),
@@ -16842,8 +17204,17 @@ function actionTailIsRegimenModifier(parts, actionStart, index, definition) {
16842
17204
  return true;
16843
17205
  }
16844
17206
  if (ACTION_ROUTE_TAIL_SURFACES.has(token)) return true;
16845
- const timing = Boolean(TIMING_ABBREVIATIONS[token] || WORD_FREQUENCIES[token] || EVENT_TIMING_TOKENS[token]);
16846
- if (!timing) return false;
17207
+ const timing = Boolean(
17208
+ TIMING_ABBREVIATIONS[token] || WORD_FREQUENCIES[token] || EVENT_TIMING_TOKENS[token] || FREQUENCY_SIMPLE_WORDS[token] !== void 0
17209
+ );
17210
+ if (!timing) {
17211
+ const previous = parts[index - 1];
17212
+ if (!previous || !/^[,;:]$/u.test(previous.original.trim())) return false;
17213
+ const relation = resolveActionRelationSurface(token);
17214
+ if (!relation) return false;
17215
+ const eventTail = parts.slice(index + 1, Math.min(parts.length, index + 4));
17216
+ if (!eventTail.some((part) => Boolean(EVENT_TIMING_TOKENS[key(part)]))) return false;
17217
+ }
16847
17218
  if ((definition == null ? void 0 : definition.argumentParser) === "object-time") return false;
16848
17219
  return !actionHasLocalRelationBefore(parts, actionStart, index);
16849
17220
  }
@@ -16884,6 +17255,10 @@ function parseInstructionActions(sourceText, baseOffset = 0, options) {
16884
17255
  end = ACTION_COORDINATION_CONNECTORS.has(previousKey) ? index - 1 : index;
16885
17256
  break;
16886
17257
  }
17258
+ if (/^[,;:]$/u.test(currentKey) && INSTRUCTION_START_WORDS.has(key(parts[index + 1]))) {
17259
+ end = index;
17260
+ break;
17261
+ }
16887
17262
  if (ACTION_DIRECTIVE_BOUNDARIES.has(currentKey) && !prefixedActionAt(parts, index, options) && !resultativeLeadAt(parts, index, options)) {
16888
17263
  end = index;
16889
17264
  break;
@@ -17422,15 +17797,26 @@ function promoteDoseFromDefiningAction(clause, actions, options) {
17422
17797
  }
17423
17798
  function canonicalPrimaryAdministrationSpan(clause, frames) {
17424
17799
  const semantic = frames.filter((frame) => frame.polarity !== "negate" /* Negate */ && actionMatchesCanonicalMethod(frame, clause)).slice().sort((left, right) => left.span.start - right.span.start || left.span.end - right.span.end)[0];
17425
- if (semantic) return { start: semantic.span.start, end: semantic.span.end };
17426
- const spans = [];
17800
+ if (semantic) {
17801
+ let best;
17802
+ for (const evidence of clause.evidence) {
17803
+ if (evidence.rule !== "hpsg.lex.method") continue;
17804
+ for (const span of evidence.spans) {
17805
+ if (span.start < semantic.span.start || semantic.span.end < span.end) continue;
17806
+ const candidate = { start: span.start, end: span.end };
17807
+ if (!best || candidate.end - candidate.start < best.end - best.start || candidate.end - candidate.start === best.end - best.start && candidate.start < best.start) {
17808
+ best = candidate;
17809
+ }
17810
+ }
17811
+ }
17812
+ return best != null ? best : { start: semantic.span.start, end: semantic.span.end };
17813
+ }
17427
17814
  for (const evidence of clause.evidence) {
17428
17815
  if (evidence.rule !== "hpsg.lex.method") continue;
17429
- for (const span of evidence.spans) spans.push({ start: span.start, end: span.end });
17816
+ const span = evidence.spans[0];
17817
+ if (span) return { start: span.start, end: span.end };
17430
17818
  }
17431
- if (!spans.length) return void 0;
17432
- spans.sort((left, right) => left.start - right.start || left.end - right.end);
17433
- return spans[0];
17819
+ return void 0;
17434
17820
  }
17435
17821
  function buildInstructionGraph(input, clause, options) {
17436
17822
  const actions = [];
@@ -17578,7 +17964,7 @@ function actionLabel(frame, locale, roundtripSafe = false) {
17578
17964
  return (_i = (_h = (_g = (_f = (_d = (_c2 = roundtripSafe ? (_a26 = definition == null ? void 0 : definition.roundtripI18n) == null ? void 0 : _a26[language] : void 0) != null ? _c2 : (_b3 = frame.predicate.i18n) == null ? void 0 : _b3[language]) != null ? _d : language === "en" ? frame.predicate.display : void 0) != null ? _f : (_e = definition == null ? void 0 : definition.i18n) == null ? void 0 : _e[language]) != null ? _g : definition == null ? void 0 : definition.display) != null ? _h : frame.predicate.display) != null ? _i : frame.predicate.lemma;
17579
17965
  }
17580
17966
  var DEFAULT_ACTION_REALIZER = (c) => {
17581
- var _a26, _b3, _c2, _d;
17967
+ var _a26, _b3, _c2, _d, _e;
17582
17968
  const objectArgs = c.frame.args.filter(
17583
17969
  (arg) => arg.role === "theme" /* Theme */ || arg.role === "object" /* Object */ || arg.role === "site" /* Site */ || arg.role === "substance" /* Substance */
17584
17970
  );
@@ -17591,7 +17977,9 @@ var DEFAULT_ACTION_REALIZER = (c) => {
17591
17977
  const relationTargetArg = objectArgs.length > 1 ? objectArgs[1] : void 0;
17592
17978
  const relationTarget = relationTargetArg ? translatedArgument(relationTargetArg, c.locale) : void 0;
17593
17979
  const withTarget = relationHasGrammarFeature(c.frame.relation, "accompanimentComplement") ? relationTarget : void 0;
17594
- return c.thai ? `${c.label}${object != null ? object : ""}${amount ? ` ${amount}` : ""}${c.duration ? ` ${c.duration}` : ""}${withTarget ? `\u0E23\u0E48\u0E27\u0E21\u0E01\u0E31\u0E1A${withTarget}` : ""}` : `${c.label}${object ? ` ${object}` : ""}${amount ? ` ${amount}` : ""}${c.duration ? ` for ${c.duration}` : ""}${withTarget ? ` with ${withTarget}` : ""}`;
17980
+ const activityRelation = c.activity && relationHasGrammarFeature(c.frame.relation, "activityFallback") ? (_e = localizeAdviceRelation(c.frame.relation, c.locale)) != null ? _e : c.frame.relation : void 0;
17981
+ const activitySuffix = activityRelation && c.activity ? c.thai ? `${activityRelation}${c.activity}` : ` ${activityRelation} ${c.activity}` : "";
17982
+ return c.thai ? `${c.label}${object != null ? object : ""}${amount ? ` ${amount}` : ""}${c.duration ? ` ${c.duration}` : ""}${withTarget ? `\u0E23\u0E48\u0E27\u0E21\u0E01\u0E31\u0E1A${withTarget}` : ""}${activitySuffix}` : `${c.label}${object ? ` ${object}` : ""}${amount ? ` ${amount}` : ""}${c.duration ? ` for ${c.duration}` : ""}${withTarget ? ` with ${withTarget}` : ""}${activitySuffix}`;
17595
17983
  };
17596
17984
  var SOURCE_FAITHFUL_REALIZER = (c) => {
17597
17985
  const sourceIsThai = /[\u0E00-\u0E7F]/.test(c.frame.sourceText);
@@ -17633,6 +18021,7 @@ var RESULT_REALIZER = (c) => c.thai ? `${c.label}${c.result ? `\u0E43\u0E2B\u0E4
17633
18021
  var SITE_RELATION_REALIZER = (c) => {
17634
18022
  var _a26, _b3, _c2, _d, _e, _f, _g, _h, _i;
17635
18023
  const relationTarget = (_a26 = c.time) != null ? _a26 : c.activity;
18024
+ const mannerSuffix = c.manner ? c.thai ? c.manner : ` ${c.manner}` : "";
17636
18025
  if (relationTarget) {
17637
18026
  const siteArg = c.frame.args.find((arg) => arg.role === "site" /* Site */);
17638
18027
  const suppressThaiSite = Boolean(
@@ -17642,22 +18031,22 @@ var SITE_RELATION_REALIZER = (c) => {
17642
18031
  if (c.time && relationHasGrammarFeature(c.frame.relation, "directTimeRealization")) {
17643
18032
  if (c.thai) {
17644
18033
  const timePhrase2 = c.time === "\u0E01\u0E25\u0E32\u0E07\u0E04\u0E37\u0E19" ? "\u0E15\u0E2D\u0E19\u0E01\u0E25\u0E32\u0E07\u0E04\u0E37\u0E19" : c.time === "\u0E19\u0E2D\u0E19" || c.time === "bedtime" ? "\u0E01\u0E48\u0E2D\u0E19\u0E19\u0E2D\u0E19" : c.time;
17645
- return `${c.label}${target}${timePhrase2}`;
18034
+ return `${c.label}${target}${mannerSuffix}${timePhrase2}`;
17646
18035
  }
17647
18036
  const lower = c.time.toLowerCase();
17648
18037
  const timePhrase = lower === "night" ? "at night" : lower === "bed" || lower === "bedtime" || lower === "sleep" ? "at bedtime" : /^(?:the )?(?:morning|afternoon|evening)$/.test(lower) ? `in ${lower.startsWith("the ") ? lower : `the ${lower}`}` : `at ${c.time}`;
17649
- return `${c.label}${target} ${timePhrase}`;
18038
+ return `${c.label}${target}${mannerSuffix} ${timePhrase}`;
17650
18039
  }
17651
18040
  const semanticRelation = (_f = (_e = c.frame.relation) != null ? _e : getUniqueAdviceRelationByGrammarFeature("defaultSiteRelation")) != null ? _f : (() => {
17652
18041
  throw new Error("Missing declarative default site relation");
17653
18042
  })();
17654
18043
  const relationProfile = (_h = (_g = getAdviceRelationDefinition(semanticRelation)) == null ? void 0 : _g.grammar.timeRealizationProfile) != null ? _h : "default";
17655
18044
  const relationText = (_i = localizeAdviceRelation(semanticRelation, c.locale, relationProfile)) != null ? _i : semanticRelation;
17656
- return c.thai ? `${c.label}${target}${relationText}${relationTarget}` : `${c.label}${target} ${relationText} ${relationTarget}`;
18045
+ return c.thai ? `${c.label}${target}${mannerSuffix}${relationText}${relationTarget}` : `${c.label}${target}${mannerSuffix} ${relationText} ${relationTarget}`;
17657
18046
  }
17658
18047
  const resultSuffix = c.result ? c.thai ? `\u0E43\u0E2B\u0E49${c.result}` : ` until ${c.result}` : "";
17659
- if (c.site) return c.thai ? `${c.label}${c.site}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label} ${c.site}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
17660
- return c.thai ? `${c.label}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
18048
+ if (c.site) return c.thai ? `${c.label}${c.site}${mannerSuffix}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label} ${c.site}${mannerSuffix}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
18049
+ return c.thai ? `${c.label}${mannerSuffix}${c.substance ? `\u0E14\u0E49\u0E27\u0E22${c.substance}` : ""}${resultSuffix}` : `${c.label}${mannerSuffix}${c.substance ? ` with ${c.substance}` : ""}${resultSuffix}`;
17661
18050
  };
17662
18051
  var OBJECT_AMOUNT_MATERIAL_REALIZER = (c) => {
17663
18052
  var _a26;
@@ -17721,13 +18110,17 @@ var LEAVE_DURATION_REALIZER = (c) => {
17721
18110
  };
17722
18111
  var DURATION_REALIZER = (c) => c.thai ? `${c.label}${c.duration ? ` ${c.duration}` : ""}` : `${c.label}${c.duration ? ` for ${c.duration}` : ""}`;
17723
18112
  var DURATION_ACTIVITY_REALIZER = (c) => {
17724
- var _a26;
17725
- if (!c.activity) return `${c.label}${c.duration ? ` ${c.duration}` : ""}`;
17726
- if (relationHasSemanticClass(c.frame.relation, "interval")) {
17727
- const relation = (_a26 = localizeAdviceRelation(c.frame.relation, c.locale)) != null ? _a26 : c.frame.relation;
17728
- return c.thai ? `${c.label}${c.duration ? ` ${c.duration}` : ""} ${relation}${c.activity}` : `${c.label}${c.duration ? ` ${c.duration}` : ""} ${relation} ${c.activity}`;
18113
+ var _a26, _b3;
18114
+ const target = (_a26 = c.activity) != null ? _a26 : c.result;
18115
+ if (!target) return `${c.label}${c.duration ? ` ${c.duration}` : ""}`;
18116
+ if (c.frame.relation) {
18117
+ const relation = (_b3 = localizeAdviceRelation(c.frame.relation, c.locale)) != null ? _b3 : c.frame.relation;
18118
+ if (relationHasSemanticClass(c.frame.relation, "interval")) {
18119
+ return c.thai ? `${c.label}${c.duration ? ` ${c.duration}` : ""} ${relation}${target}` : `${c.label}${c.duration ? ` ${c.duration}` : ""} ${relation} ${target}`;
18120
+ }
18121
+ return c.thai ? `${c.label}${c.duration ? ` ${c.duration}` : ""}${relation}${target}` : `${c.label}${c.duration ? ` ${c.duration}` : ""} ${relation} ${target}`;
17729
18122
  }
17730
- return `${c.label}${c.duration ? ` ${c.duration}` : ""} ${c.activity}`;
18123
+ return `${c.label}${c.duration ? ` ${c.duration}` : ""} ${target}`;
17731
18124
  };
17732
18125
  var ACTIVITY_REALIZER = (c) => {
17733
18126
  var _a26, _b3, _c2;
@@ -17816,6 +18209,7 @@ function realizeAction(frame, locale, roundtripSafe = false) {
17816
18209
  const time = timeArg ? thai && /[\u0E00-\u0E7F]/u.test(timeArg.text) ? timeArg.text : translatedArgument(timeArg, locale) : void 0;
17817
18210
  const duration = first("duration" /* Duration */);
17818
18211
  const material = first("material" /* Material */);
18212
+ const manner = first("manner" /* Manner */);
17819
18213
  if (frame.polarity === "negate" /* Negate */) {
17820
18214
  const object = (_c2 = (_b3 = site != null ? site : theme) != null ? _b3 : substance) != null ? _c2 : material;
17821
18215
  const relationTarget = activity != null ? activity : time;
@@ -17854,6 +18248,7 @@ function realizeAction(frame, locale, roundtripSafe = false) {
17854
18248
  time,
17855
18249
  duration,
17856
18250
  material,
18251
+ manner,
17857
18252
  realizerConfig: (_i = frame.predicate.realizerConfig) != null ? _i : definition == null ? void 0 : definition.realizerConfig,
17858
18253
  definition
17859
18254
  });
@@ -17896,6 +18291,28 @@ function instructionGraphRepresentsText(graph, text) {
17896
18291
  return Boolean(candidate && (candidate === normalized || candidate.includes(normalized)));
17897
18292
  });
17898
18293
  }
18294
+ function instructionGraphTextParticipatesInRelation(graph, text) {
18295
+ var _a26, _b3;
18296
+ const normalized = normalizedInstructionSurface(text);
18297
+ if (!normalized) return false;
18298
+ const compact = (value) => value.replace(/\s+/gu, "");
18299
+ const matchingIndices = [];
18300
+ for (let index = 0; index < graph.actions.length; index += 1) {
18301
+ const source = normalizedInstructionSurface((_b3 = (_a26 = graph.actions[index]) == null ? void 0 : _a26.sourceText) != null ? _b3 : "");
18302
+ if (!source) continue;
18303
+ if (source === normalized || compact(source).includes(compact(normalized)) || compact(normalized).includes(compact(source))) {
18304
+ matchingIndices.push(index);
18305
+ }
18306
+ }
18307
+ return matchingIndices.some(
18308
+ (index) => {
18309
+ var _a27, _b4;
18310
+ return (_b4 = (_a27 = graph.relations) == null ? void 0 : _a27.some(
18311
+ (relation) => relation.fromActionIndex === index || relation.toActionIndex === index
18312
+ )) != null ? _b4 : false;
18313
+ }
18314
+ );
18315
+ }
17899
18316
  function instructionGraphSingleActionRepresentsText(graph, text) {
17900
18317
  const normalized = normalizedInstructionSurface(text);
17901
18318
  if (!normalized) return false;
@@ -18095,6 +18512,28 @@ function instructionGraphRichPrimaryAction(clause) {
18095
18512
  return (rich || suppliesMissingHead) && (!dose || matchesDose(action));
18096
18513
  });
18097
18514
  }
18515
+ function instructionGraphRoundTripPrimaryAction(clause) {
18516
+ const graph = clause.instructionGraph;
18517
+ const primary = graph == null ? void 0 : graph.primaryAdministrationSpan;
18518
+ if (!graph || !primary) return void 0;
18519
+ return graph.actions.find((action) => {
18520
+ if (action.span.end <= primary.start || action.span.start >= primary.end) return false;
18521
+ const hasLocalRelation = relationHasGrammarFeature(action.relation, "roundtripRichRelation");
18522
+ const hasRichArgument = action.args.some(
18523
+ (arg) => [
18524
+ "time" /* Time */,
18525
+ "duration" /* Duration */,
18526
+ "material" /* Material */,
18527
+ "activity" /* Activity */,
18528
+ "result" /* Result */,
18529
+ "destination" /* Destination */,
18530
+ "substance" /* Substance */,
18531
+ "manner" /* Manner */
18532
+ ].indexOf(arg.role) >= 0 || (arg.role === "object" /* Object */ || arg.role === "theme" /* Theme */) && /\b(?:new|replacement|another|fresh)\b/i.test(arg.text)
18533
+ );
18534
+ return hasLocalRelation || hasRichArgument;
18535
+ });
18536
+ }
18098
18537
  function instructionGraphPrimaryAdministrationModality(clause) {
18099
18538
  var _a26;
18100
18539
  const graph = clause.instructionGraph;
@@ -19226,7 +19665,7 @@ function applyEnglishAdministrationModality(verb, clause) {
19226
19665
  return `${prefix} ${verb.charAt(0).toLowerCase()}${verb.slice(1)}`;
19227
19666
  }
19228
19667
  function formatLong(clause, options) {
19229
- var _a26, _b3, _c2, _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, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z;
19668
+ var _a26, _b3, _c2, _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, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X;
19230
19669
  const schedule = scheduleOf(clause);
19231
19670
  const grammar = resolveRouteGrammar(clause);
19232
19671
  const baseVerb = resolveMethodVerb(clause, grammar);
@@ -19354,36 +19793,19 @@ function formatLong(clause, options) {
19354
19793
  const richGraphAdministrationSentence = richPrimaryGraphText ? formatPatientInstructionSentence(
19355
19794
  [richPrimaryGraphText, ...graphRegimenTail].filter(Boolean).join(" ")
19356
19795
  ) : void 0;
19357
- const primaryGraphAction = roundTrip && ((_s = clause.instructionGraph) == null ? void 0 : _s.primaryAdministrationSpan) ? clause.instructionGraph.actions.find((action) => {
19358
- var _a27;
19359
- const primary = (_a27 = clause.instructionGraph) == null ? void 0 : _a27.primaryAdministrationSpan;
19360
- if (!primary || action.span.end <= primary.start || action.span.start >= primary.end) return false;
19361
- const hasLocalRelation = relationHasGrammarFeature(action.relation, "roundtripRichRelation");
19362
- const hasRichArgument = action.args.some(
19363
- (arg) => [
19364
- "time" /* Time */,
19365
- "duration" /* Duration */,
19366
- "material" /* Material */,
19367
- "activity" /* Activity */,
19368
- "result" /* Result */,
19369
- "destination" /* Destination */,
19370
- "substance" /* Substance */,
19371
- "manner" /* Manner */
19372
- ].indexOf(arg.role) >= 0 || (arg.role === "object" /* Object */ || arg.role === "theme" /* Theme */) && /\b(?:new|replacement|another|fresh)\b/i.test(arg.text)
19373
- );
19374
- return hasLocalRelation || hasRichArgument;
19375
- }) : void 0;
19796
+ const primaryGraphAction = roundTrip ? instructionGraphRoundTripPrimaryAction(clause) : void 0;
19376
19797
  const instructionPhrases = [];
19377
19798
  const hasCodedAdditionalInstruction = Boolean(
19378
- (_t = clause.additionalInstructions) == null ? void 0 : _t.some((instruction) => {
19799
+ (_s = clause.additionalInstructions) == null ? void 0 : _s.some((instruction) => {
19379
19800
  var _a27;
19380
19801
  return (_a27 = instruction.coding) == null ? void 0 : _a27.code;
19381
19802
  })
19382
19803
  );
19383
19804
  const normalizeInstruction = (value) => value.toLowerCase().replace(/[\s,;:.()]+/g, " ").trim();
19384
- const graphWarnings = (_v = (_u = clause.instructionGraph) == null ? void 0 : _u.actions.filter(
19805
+ const graphWarnings = (_u = (_t = clause.instructionGraph) == null ? void 0 : _t.actions.filter(
19385
19806
  (action) => action.polarity === "negate" /* Negate */
19386
- )) != null ? _v : [];
19807
+ )) != null ? _u : [];
19808
+ const positionedGraph = Boolean((_v = clause.instructionGraph) == null ? void 0 : _v.primaryAdministrationSpan);
19387
19809
  const graphOwnedAdditional = ((_w = clause.additionalInstructions) != null ? _w : []).filter((instruction) => {
19388
19810
  var _a27, _b4;
19389
19811
  if (((_a27 = instruction.coding) == null ? void 0 : _a27.code) || !instruction.text || !clause.instructionGraph) return false;
@@ -19392,7 +19814,7 @@ function formatLong(clause, options) {
19392
19814
  const source = normalizeInstruction(action.sourceText);
19393
19815
  return source === normalized || source.includes(normalized) || normalized.includes(source);
19394
19816
  });
19395
- return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
19817
+ return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || positionedGraph && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text) && instructionGraphTextParticipatesInRelation(clause.instructionGraph, instruction.text) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
19396
19818
  });
19397
19819
  const additionalForDirectRendering = ((_x = clause.additionalInstructions) != null ? _x : []).filter(
19398
19820
  (instruction) => graphOwnedAdditional.indexOf(instruction) === -1 && instruction !== integratedThinLayer
@@ -19419,7 +19841,6 @@ function formatLong(clause, options) {
19419
19841
  });
19420
19842
  })
19421
19843
  );
19422
- const positionedGraph = Boolean((_A = clause.instructionGraph) == null ? void 0 : _A.primaryAdministrationSpan);
19423
19844
  const positionedRoundTrip = Boolean(roundTrip && positionedGraph);
19424
19845
  const graphWholeInstruction = clause.instructionGraph && !positionedGraph && !hasCodedAdditionalInstruction && allAdditionalRepresentedByGraphWarnings ? realizeInstructionGraph(clause.instructionGraph, "en", {
19425
19846
  includeWarnings: true,
@@ -19466,18 +19887,18 @@ function formatLong(clause, options) {
19466
19887
  omitSourceTexts: postGraphOmissions,
19467
19888
  position: "post"
19468
19889
  }) : void 0;
19469
- const graphInstruction = (_B = graphWholeInstruction != null ? graphWholeInstruction : postGraphInstruction) != null ? _B : !positionedGraph && clause.instructionGraph && instructionGraphHasNovelNonWarningContent(clause.instructionGraph, representedInstructionTexts) ? realizeInstructionGraph(clause.instructionGraph, "en", {
19890
+ const graphInstruction = (_A = graphWholeInstruction != null ? graphWholeInstruction : postGraphInstruction) != null ? _A : !positionedGraph && clause.instructionGraph && instructionGraphHasNovelNonWarningContent(clause.instructionGraph, representedInstructionTexts) ? realizeInstructionGraph(clause.instructionGraph, "en", {
19470
19891
  includeWarnings: false,
19471
19892
  omitCanonicalAdministration: clause,
19472
19893
  preferSourceText: roundTrip,
19473
19894
  roundtripSafe: roundTrip,
19474
19895
  omitSourceTexts: postGraphOmissions
19475
19896
  }) : void 0;
19476
- const primarySpanForFlow = (_C = clause.instructionGraph) == null ? void 0 : _C.primaryAdministrationSpan;
19477
- const graphActionsForFlow = (_E = (_D = clause.instructionGraph) == null ? void 0 : _D.actions) != null ? _E : [];
19897
+ const primarySpanForFlow = (_B = clause.instructionGraph) == null ? void 0 : _B.primaryAdministrationSpan;
19898
+ const graphActionsForFlow = (_D = (_C = clause.instructionGraph) == null ? void 0 : _C.actions) != null ? _D : [];
19478
19899
  const lastPreActionForFlow = primarySpanForFlow ? graphActionsForFlow.filter((action) => action.span.end <= primarySpanForFlow.start).sort((a, b) => b.span.end - a.span.end)[0] : void 0;
19479
19900
  const firstPostActionForFlow = primarySpanForFlow ? graphActionsForFlow.filter((action) => action.span.start >= primarySpanForFlow.end).sort((a, b) => a.span.start - b.span.start)[0] : void 0;
19480
- const graphFlowSource = (_G = (_F = clause.instructionGraph) == null ? void 0 : _F.sourceText) != null ? _G : clause.rawText;
19901
+ const graphFlowSource = (_F = (_E = clause.instructionGraph) == null ? void 0 : _E.sourceText) != null ? _F : clause.rawText;
19481
19902
  const noStrongBoundaryForFlow = (start, end) => !/[.!?;]/u.test(graphFlowSource.slice(start, end));
19482
19903
  const preFlowsIntoAdministration = Boolean(
19483
19904
  !roundTrip && preGraphInstruction && primarySpanForFlow && lastPreActionForFlow && lastPreActionForFlow.polarity !== "negate" /* Negate */ && noStrongBoundaryForFlow(lastPreActionForFlow.span.end, primarySpanForFlow.start)
@@ -19493,9 +19914,9 @@ function formatLong(clause, options) {
19493
19914
  );
19494
19915
  if (patientInstruction) instructionPhrases.push(patientInstruction);
19495
19916
  const trailingInstructionText = instructionPhrases.join(" ").trim() || void 0;
19496
- const hasExplicitMethod = Boolean(((_I = (_H = clause.method) == null ? void 0 : _H.text) == null ? void 0 : _I.trim()) || ((_K = (_J = clause.method) == null ? void 0 : _J.coding) == null ? void 0 : _K.code));
19497
- const graphSourceIsEnglish = !((_L = clause.instructionGraph) == null ? void 0 : _L.sourceLocale) || !clause.instructionGraph.sourceLocale.toLowerCase().startsWith("th");
19498
- if (roundTrip && !hasExplicitMethod && graphSourceIsEnglish && ((_M = clause.instructionGraph) == null ? void 0 : _M.sourceText.trim())) {
19917
+ const hasExplicitMethod = Boolean(((_H = (_G = clause.method) == null ? void 0 : _G.text) == null ? void 0 : _H.trim()) || ((_J = (_I = clause.method) == null ? void 0 : _I.coding) == null ? void 0 : _J.code));
19918
+ const graphSourceIsEnglish = !((_K = clause.instructionGraph) == null ? void 0 : _K.sourceLocale) || !clause.instructionGraph.sourceLocale.toLowerCase().startsWith("th");
19919
+ if (roundTrip && !hasExplicitMethod && graphSourceIsEnglish && ((_L = clause.instructionGraph) == null ? void 0 : _L.sourceText.trim())) {
19499
19920
  return clause.instructionGraph.sourceText.trim();
19500
19921
  }
19501
19922
  if (!canonicalClauseHasAdministrationSemantics(clause)) {
@@ -19505,10 +19926,20 @@ function formatLong(clause, options) {
19505
19926
  roundtripSafe: roundTrip
19506
19927
  }) : void 0;
19507
19928
  const wholeGraphText = formatPatientInstructionSentence(wholeGraph);
19508
- return (_N = wholeGraphText != null ? wholeGraphText : trailingInstructionText) != null ? _N : `${verb}.`;
19929
+ const parts = [];
19930
+ for (const value of [wholeGraphText, ...instructionPhrases]) {
19931
+ if (!value) continue;
19932
+ const normalized = normalizeInstruction(value);
19933
+ if (parts.some((existing) => {
19934
+ const candidate = normalizeInstruction(existing);
19935
+ return candidate === normalized || candidate.includes(normalized) || normalized.includes(candidate);
19936
+ })) continue;
19937
+ parts.push(value);
19938
+ }
19939
+ return parts.join(" ").trim() || `${verb}.`;
19509
19940
  }
19510
19941
  const leadingInstructionText = preFlowsIntoAdministration ? void 0 : preGraphInstruction ? formatPatientInstructionSentence(preGraphInstruction) : void 0;
19511
- const graphRepresentsDose = !clause.dose || Boolean((_O = clause.instructionGraph) == null ? void 0 : _O.actions.some(
19942
+ const graphRepresentsDose = !clause.dose || Boolean((_M = clause.instructionGraph) == null ? void 0 : _M.actions.some(
19512
19943
  (action) => action.args.some(
19513
19944
  (arg) => {
19514
19945
  var _a27, _b4, _c3, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2;
@@ -19517,26 +19948,26 @@ function formatLong(clause, options) {
19517
19948
  )
19518
19949
  ));
19519
19950
  const hasAdministrationTiming = Boolean(
19520
- schedule.frequency !== void 0 || schedule.frequencyMax !== void 0 || schedule.period !== void 0 || schedule.periodMax !== void 0 || ((_P = schedule.when) == null ? void 0 : _P.length) || ((_Q = schedule.dayOfWeek) == null ? void 0 : _Q.length) || ((_R = schedule.timeOfDay) == null ? void 0 : _R.length) || schedule.count !== void 0 || schedule.countMax !== void 0 || schedule.timingCode || schedule.duration !== void 0 || schedule.durationMax !== void 0 || schedule.durationUnit !== void 0 || schedule.offset !== void 0 || schedule.offsetMin !== void 0 || schedule.offsetMax !== void 0 || Boolean((_S = schedule.activityTiming) == null ? void 0 : _S.length) || schedule.occurrenceCap !== void 0
19951
+ schedule.frequency !== void 0 || schedule.frequencyMax !== void 0 || schedule.period !== void 0 || schedule.periodMax !== void 0 || ((_N = schedule.when) == null ? void 0 : _N.length) || ((_O = schedule.dayOfWeek) == null ? void 0 : _O.length) || ((_P = schedule.timeOfDay) == null ? void 0 : _P.length) || schedule.count !== void 0 || schedule.countMax !== void 0 || schedule.timingCode || schedule.duration !== void 0 || schedule.durationMax !== void 0 || schedule.durationUnit !== void 0 || schedule.offset !== void 0 || schedule.offsetMin !== void 0 || schedule.offsetMax !== void 0 || Boolean((_Q = schedule.activityTiming) == null ? void 0 : _Q.length) || schedule.occurrenceCap !== void 0
19521
19952
  );
19522
19953
  const graphCanStandAlone = Boolean(
19523
- !hasExplicitMethod && trailingInstructionText && ((_T = clause.instructionGraph) == null ? void 0 : _T.actions.length) && !clause.route && !clause.site && !hasAdministrationTiming && graphRepresentsDose
19954
+ !hasExplicitMethod && trailingInstructionText && ((_R = clause.instructionGraph) == null ? void 0 : _R.actions.length) && !clause.route && !clause.site && !hasAdministrationTiming && graphRepresentsDose
19524
19955
  );
19525
19956
  if (graphCanStandAlone) return trailingInstructionText;
19526
19957
  const primarySourceSentence = primaryGraphAction ? formatPatientInstructionSentence(primaryGraphAction.sourceText) : void 0;
19527
- const primaryActionIndex = primaryGraphAction ? (_U = clause.instructionGraph) == null ? void 0 : _U.actions.indexOf(primaryGraphAction) : void 0;
19528
- const entersPrimaryWithThen = primaryActionIndex !== void 0 && primaryActionIndex >= 0 ? (_W = (_V = clause.instructionGraph) == null ? void 0 : _V.relations) == null ? void 0 : _W.some(
19958
+ const primaryActionIndex = primaryGraphAction ? (_S = clause.instructionGraph) == null ? void 0 : _S.actions.indexOf(primaryGraphAction) : void 0;
19959
+ const entersPrimaryWithThen = primaryActionIndex !== void 0 && primaryActionIndex >= 0 ? (_U = (_T = clause.instructionGraph) == null ? void 0 : _T.relations) == null ? void 0 : _U.some(
19529
19960
  (relation) => relationHasSemanticClass(relation.kind, "sequence") && relation.toActionIndex === primaryActionIndex && relation.fromActionIndex !== void 0
19530
19961
  ) : false;
19531
19962
  const richPrimaryActionIndex = richPrimaryGraphAction && clause.instructionGraph ? clause.instructionGraph.actions.indexOf(richPrimaryGraphAction) : -1;
19532
19963
  const graphContinuesWithThen = richPrimaryActionIndex >= 0 && Boolean(
19533
- (_Y = (_X = clause.instructionGraph) == null ? void 0 : _X.relations) == null ? void 0 : _Y.some(
19964
+ (_W = (_V = clause.instructionGraph) == null ? void 0 : _V.relations) == null ? void 0 : _W.some(
19534
19965
  (relation) => relationHasSemanticClass(relation.kind, "sequence") && relation.fromActionIndex === richPrimaryActionIndex
19535
19966
  )
19536
19967
  );
19537
19968
  const sequenceRelation = getUniqueAdviceRelationByGrammarFeature("defaultSequenceRelation");
19538
19969
  if (!sequenceRelation) throw new Error("Missing declarative default sequence relation");
19539
- const sequenceSurface = (_Z = localizeAdviceRelation(sequenceRelation, "en")) != null ? _Z : sequenceRelation;
19970
+ const sequenceSurface = (_X = localizeAdviceRelation(sequenceRelation, "en")) != null ? _X : sequenceRelation;
19540
19971
  const compose = (base) => {
19541
19972
  var _a27;
19542
19973
  let effectiveBase = (_a27 = richGraphAdministrationSentence != null ? richGraphAdministrationSentence : primarySourceSentence) != null ? _a27 : base;
@@ -19682,8 +20113,8 @@ var advice_terminology_default = {
19682
20113
  { surface: "drive", lemma: "drive", partOfSpeech: "verb", semanticClass: "activity" },
19683
20114
  { surface: "driving", lemma: "drive", partOfSpeech: "verb", semanticClass: "activity" },
19684
20115
  { surface: "eat", lemma: "eat", partOfSpeech: "verb", semanticClass: "ingest" },
19685
- { surface: "cause", lemma: "cause", partOfSpeech: "verb", semanticClass: "effect", realizerProfile: "effect" },
19686
- { surface: "causes", lemma: "cause", partOfSpeech: "verb", semanticClass: "effect" },
20116
+ { surface: "cause", lemma: "cause", partOfSpeech: "verb", semanticClass: "effect", realizerProfile: "effect", i18n: { th: "\u0E17\u0E33\u0E43\u0E2B\u0E49\u0E40\u0E01\u0E34\u0E14" } },
20117
+ { surface: "causes", lemma: "cause", partOfSpeech: "verb", semanticClass: "effect", realizerProfile: "effect", i18n: { th: "\u0E17\u0E33\u0E43\u0E2B\u0E49\u0E40\u0E01\u0E34\u0E14" } },
19687
20118
  { surface: "use", lemma: "use", partOfSpeech: "verb", semanticClass: "administration" },
19688
20119
  { surface: "take", lemma: "take", partOfSpeech: "verb", semanticClass: "administration" },
19689
20120
  { surface: "apply", lemma: "apply", partOfSpeech: "verb", semanticClass: "administration" },
@@ -20517,6 +20948,7 @@ function mapSemanticClassToRole(semanticClass) {
20517
20948
  return (_a26 = enumValue(AdviceArgumentRole, configured)) != null ? _a26 : "object" /* Object */;
20518
20949
  }
20519
20950
  function classifyArgument(text) {
20951
+ var _a26, _b3, _c2, _d, _e;
20520
20952
  const cleaned = cleanFreeText(text);
20521
20953
  const normalized = normalizeAdditionalInstructionKey(cleaned);
20522
20954
  if (!normalized) {
@@ -20531,6 +20963,21 @@ function classifyArgument(text) {
20531
20963
  concept.conceptId
20532
20964
  );
20533
20965
  }
20966
+ const symptom = resolveSymptomDefinition(normalized);
20967
+ if (symptom) {
20968
+ const coding = symptom.coding ? __spreadValues({}, symptom.coding) : void 0;
20969
+ return {
20970
+ role: "object" /* Object */,
20971
+ text: cleaned,
20972
+ normalized: (_b3 = (_a26 = symptom.text) == null ? void 0 : _a26.toLowerCase()) != null ? _b3 : normalized,
20973
+ conceptId: (_d = (_c2 = coding == null ? void 0 : coding.code) != null ? _c2 : symptom.text) != null ? _d : normalized,
20974
+ coding,
20975
+ codings: coding ? [coding] : void 0,
20976
+ i18n: __spreadValues({
20977
+ en: symptom.text ? symptom.text.charAt(0).toLowerCase() + symptom.text.slice(1) : cleaned
20978
+ }, (_e = symptom.i18n) != null ? _e : {})
20979
+ };
20980
+ }
20534
20981
  const parts = normalized.split(" ");
20535
20982
  if (parts.length >= 2) {
20536
20983
  const first = parts[0];
@@ -21170,8 +21617,9 @@ var AVOIDANCE_ADVICE_PREDICATE_REALIZER = ({ frame, argText, modalityText }) =>
21170
21617
  };
21171
21618
  var EFFECT_ADVICE_PREDICATE_REALIZER = ({ frame, argText, modalityText }) => {
21172
21619
  const effectiveModality = modalityText != null ? modalityText : capitalizeSentence("may" /* May */);
21173
- const predicate = `${effectiveModality} ${frame.predicate.lemma}`;
21174
- return argText ? `${predicate} ${argText}` : predicate;
21620
+ const thai = /[\u0E00-\u0E7F]/u.test(frame.predicate.lemma);
21621
+ const predicate = thai ? `${effectiveModality}${frame.predicate.lemma}` : `${effectiveModality} ${frame.predicate.lemma}`;
21622
+ return argText ? `${predicate}${thai ? "" : " "}${argText}` : predicate;
21175
21623
  };
21176
21624
  var ADVICE_PREDICATE_REALIZERS = {
21177
21625
  default: DEFAULT_ADVICE_PREDICATE_REALIZER,
@@ -24850,7 +25298,7 @@ function buildRoutePhraseThai(clause, grammar, hasSite) {
24850
25298
  return text;
24851
25299
  }
24852
25300
  function formatSiteThai(clause, grammar) {
24853
- var _a26, _b3, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
25301
+ var _a26, _b3, _c2, _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;
24854
25302
  const text = ((_b3 = (_a26 = clause.site) == null ? void 0 : _a26.text) == null ? void 0 : _b3.trim()) || ((_e = (_d = (_c2 = clause.site) == null ? void 0 : _c2.coding) == null ? void 0 : _d.display) == null ? void 0 : _e.trim());
24855
25303
  const lower = text == null ? void 0 : text.toLowerCase();
24856
25304
  const codingCode = (_g = (_f = clause.site) == null ? void 0 : _f.coding) == null ? void 0 : _g.code;
@@ -24865,20 +25313,22 @@ function formatSiteThai(clause, grammar) {
24865
25313
  if (isVaginalRoute && isVaginaSite) {
24866
25314
  return void 0;
24867
25315
  }
24868
- const translated = (_u = (_r = (_n = perTargetSiteThai(clause)) != null ? _n : (_m = (_l = clause.site) == null ? void 0 : _l.i18n) == null ? void 0 : _m.th) != null ? _r : (_q = (_p = (_o = clause.site) == null ? void 0 : _o.coding) == null ? void 0 : _p.i18n) == null ? void 0 : _q.th) != null ? _u : text ? translateSiteThai(text, codingCode, (_s = clause.site) == null ? void 0 : _s.spatialRelation) : translateSpatialSiteThai(void 0, (_t = clause.site) == null ? void 0 : _t.spatialRelation);
25316
+ const resolvedSite = text ? resolveBodySitePhrase(text) : void 0;
25317
+ const structuralTranslation = ((_l = clause.site) == null ? void 0 : _l.spatialRelation) || (resolvedSite == null ? void 0 : resolvedSite.features.qualifier) ? text ? translateSiteThai(text, codingCode, (_m = clause.site) == null ? void 0 : _m.spatialRelation) : translateSpatialSiteThai(void 0, (_n = clause.site) == null ? void 0 : _n.spatialRelation) : void 0;
25318
+ const translated = (_y = (_v = (_r = (_o = perTargetSiteThai(clause)) != null ? _o : structuralTranslation) != null ? _r : (_q = (_p = clause.site) == null ? void 0 : _p.i18n) == null ? void 0 : _q.th) != null ? _v : (_u = (_t = (_s = clause.site) == null ? void 0 : _s.coding) == null ? void 0 : _t.i18n) == null ? void 0 : _u.th) != null ? _y : text ? translateSiteThai(text, codingCode, (_w = clause.site) == null ? void 0 : _w.spatialRelation) : translateSpatialSiteThai(void 0, (_x = clause.site) == null ? void 0 : _x.spatialRelation);
24869
25319
  if (!translated) {
24870
25320
  return void 0;
24871
25321
  }
24872
- if (((_v = clause.route) == null ? void 0 : _v.code) === RouteCode["Nasal route"]) {
25322
+ if (((_z = clause.route) == null ? void 0 : _z.code) === RouteCode["Nasal route"]) {
24873
25323
  return `\u0E40\u0E02\u0E49\u0E32${translated}`;
24874
25324
  }
24875
- const spatialRelation = (_w = clause.site) == null ? void 0 : _w.spatialRelation;
25325
+ const spatialRelation = (_A = clause.site) == null ? void 0 : _A.spatialRelation;
24876
25326
  const spatialRealization = (spatialRelation == null ? void 0 : spatialRelation.relationText) ? getBodySiteRelationRealization(spatialRelation.relationText, "th") : void 0;
24877
25327
  const spatialTargetThai = spatialRelation ? translateSpatialTargetThai(spatialRelation) : void 0;
24878
25328
  if (spatialRealization && (spatialRealization.omitOuterSitePreposition || (spatialTargetThai == null ? void 0 : spatialTargetThai.startsWith("\u0E1A\u0E23\u0E34\u0E40\u0E27\u0E13")))) {
24879
25329
  return translated;
24880
25330
  }
24881
- const preposition = (_x = grammar.sitePreposition) != null ? _x : "\u0E17\u0E35\u0E48";
25331
+ const preposition = (_B = grammar.sitePreposition) != null ? _B : "\u0E17\u0E35\u0E48";
24882
25332
  if (translated.startsWith(preposition)) {
24883
25333
  return translated;
24884
25334
  }
@@ -24922,6 +25372,18 @@ function translateSpatialSiteThai(site, relation) {
24922
25372
  }
24923
25373
  return realization.strategy === "suffix" ? `${target}${realization.surface}` : `${realization.surface}${target}`;
24924
25374
  }
25375
+ function appendBodySiteQualifierThai(base, qualifier) {
25376
+ var _a26, _b3, _c2, _d;
25377
+ if (!qualifier) return base;
25378
+ const realization = getBodySiteRelationRealization(qualifier.relation, "th");
25379
+ if (!realization) return base;
25380
+ const relation = realization.surface;
25381
+ if (qualifier.kind === "symptom") {
25382
+ return `${base}${relation}${(_b3 = (_a26 = qualifier.i18n) == null ? void 0 : _a26.th) != null ? _b3 : qualifier.text}`;
25383
+ }
25384
+ const target = (_d = translateSiteThai(qualifier.targetText, (_c2 = qualifier.targetCoding) == null ? void 0 : _c2.code)) != null ? _d : qualifier.targetText;
25385
+ return `${base}${relation}${target}`;
25386
+ }
24925
25387
  function translateSiteThai(site, code, spatialRelation) {
24926
25388
  if (!site) {
24927
25389
  if (code) {
@@ -24933,25 +25395,28 @@ function translateSiteThai(site, code, spatialRelation) {
24933
25395
  if (!normalized) {
24934
25396
  return site;
24935
25397
  }
25398
+ const resolvedPhrase = resolveBodySitePhrase(site);
25399
+ const qualifier = resolvedPhrase == null ? void 0 : resolvedPhrase.features.qualifier;
25400
+ const qualified = (value) => appendBodySiteQualifierThai(value, qualifier);
24936
25401
  const spatial = translateSpatialSiteThai(site, spatialRelation);
24937
25402
  if (spatial) {
24938
- return spatial;
25403
+ return qualified(spatial);
24939
25404
  }
24940
25405
  if (code) {
24941
25406
  const translatedByCode = THAI_SITE_CODE_TRANSLATIONS[code];
24942
25407
  if (translatedByCode) {
24943
- return translatedByCode;
25408
+ return qualified(translatedByCode);
24944
25409
  }
24945
25410
  }
24946
25411
  const definitionTranslation = THAI_SITE_DEFINITION_TRANSLATIONS[normalized];
24947
25412
  if (definitionTranslation) {
24948
- return definitionTranslation;
25413
+ return qualified(definitionTranslation);
24949
25414
  }
24950
25415
  const direct = THAI_SITE_TRANSLATIONS[normalized];
24951
25416
  if (direct) {
24952
- return direct;
25417
+ return qualified(direct);
24953
25418
  }
24954
- return site;
25419
+ return qualified(site);
24955
25420
  }
24956
25421
  function describeDayOfWeekThai(schedule) {
24957
25422
  var _a26;
@@ -25278,7 +25743,7 @@ function formatLongThai(clause, options) {
25278
25743
  segments.push(sitePart);
25279
25744
  }
25280
25745
  const body = segments.filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
25281
- const richPrimaryGraphAction = (options == null ? void 0 : options.realizationMode) !== "roundtrip" ? instructionGraphRichPrimaryAction(clause) : void 0;
25746
+ const richPrimaryGraphAction = (options == null ? void 0 : options.realizationMode) === "roundtrip" ? instructionGraphRoundTripPrimaryAction(clause) : instructionGraphRichPrimaryAction(clause);
25282
25747
  const richPrimaryGraphText = richPrimaryGraphAction ? realizeInstructionAction(richPrimaryGraphAction, "th") : void 0;
25283
25748
  const richPrimaryHasSite = Boolean(
25284
25749
  richPrimaryGraphAction == null ? void 0 : richPrimaryGraphAction.args.some((arg) => arg.role === "site" /* Site */)
@@ -25315,7 +25780,8 @@ function formatLongThai(clause, options) {
25315
25780
  }
25316
25781
  const richGraphAdministrationText = richPrimaryGraphText ? [richPrimaryGraphText, ...graphRegimenTail].filter(Boolean).join(" ").replace(/\s+/g, " ").trim() : void 0;
25317
25782
  const roundTrip = (options == null ? void 0 : options.realizationMode) === "roundtrip";
25318
- const graphOwnedAdditional = ((_k = clause.additionalInstructions) != null ? _k : []).filter((instruction) => {
25783
+ const positionedGraph = Boolean((_k = clause.instructionGraph) == null ? void 0 : _k.primaryAdministrationSpan);
25784
+ const graphOwnedAdditional = ((_l = clause.additionalInstructions) != null ? _l : []).filter((instruction) => {
25319
25785
  var _a27, _b4;
25320
25786
  if (((_a27 = instruction.coding) == null ? void 0 : _a27.code) || !instruction.text || !clause.instructionGraph) return false;
25321
25787
  const normalized = instruction.text.toLowerCase().replace(/[\s,;:.()]+/g, " ").trim();
@@ -25323,9 +25789,9 @@ function formatLongThai(clause, options) {
25323
25789
  const source = action.sourceText.toLowerCase().replace(/[\s,;:.()]+/g, " ").trim();
25324
25790
  return source === normalized || source.includes(normalized) || normalized.includes(source);
25325
25791
  });
25326
- return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
25792
+ return instructionGraphRepresentsText(clause.instructionGraph, instruction.text) && (representedByWarning || !((_b4 = instruction.frames) == null ? void 0 : _b4.length) || positionedGraph && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text) && instructionGraphTextParticipatesInRelation(clause.instructionGraph, instruction.text) || !canonicalClauseHasAdministrationSemantics(clause) && instructionGraphSingleActionRepresentsText(clause.instructionGraph, instruction.text));
25327
25793
  });
25328
- const directAdditional = ((_l = clause.additionalInstructions) != null ? _l : []).filter(
25794
+ const directAdditional = ((_m = clause.additionalInstructions) != null ? _m : []).filter(
25329
25795
  (instruction) => graphOwnedAdditional.indexOf(instruction) === -1 && !integratedQualifiers.has(instruction)
25330
25796
  );
25331
25797
  const additionalSemanticSourceTexts = directAdditional.map((instruction) => {
@@ -25333,14 +25799,13 @@ function formatLongThai(clause, options) {
25333
25799
  return (_a27 = instruction.text) == null ? void 0 : _a27.trim();
25334
25800
  }).filter((text) => Boolean(text));
25335
25801
  for (const instruction of directAdditional) {
25336
- for (const frame of (_m = instruction.frames) != null ? _m : []) {
25337
- const source = (_n = frame.sourceText) == null ? void 0 : _n.trim();
25802
+ for (const frame of (_n = instruction.frames) != null ? _n : []) {
25803
+ const source = (_o = frame.sourceText) == null ? void 0 : _o.trim();
25338
25804
  if (source && additionalSemanticSourceTexts.indexOf(source) === -1) {
25339
25805
  additionalSemanticSourceTexts.push(source);
25340
25806
  }
25341
25807
  }
25342
25808
  }
25343
- const positionedGraph = Boolean((_o = clause.instructionGraph) == null ? void 0 : _o.primaryAdministrationSpan);
25344
25809
  const graphRealizationOmissions = richPrimaryGraphAction ? [...additionalSemanticSourceTexts, richPrimaryGraphAction.sourceText] : additionalSemanticSourceTexts;
25345
25810
  const graphRealizationOptions = {
25346
25811
  includeWarnings: true,
@@ -25402,7 +25867,24 @@ function formatLongThai(clause, options) {
25402
25867
  roundtripSafe: roundTrip
25403
25868
  }) : void 0;
25404
25869
  const wholeGraphText = formatPatientInstructionSentence2(wholeGraph);
25405
- return wholeGraphText != null ? wholeGraphText : [leadingInstructionText, trailingInstructionText].filter(Boolean).join(" ").trim() || `${verb}.`;
25870
+ const parts = [];
25871
+ const normalizedInstruction2 = (value) => value.toLowerCase().replace(/[\s,;:.()]+/gu, " ").trim();
25872
+ for (const value of [
25873
+ leadingInstructionText,
25874
+ wholeGraphText,
25875
+ directInstruction,
25876
+ graphInstructionText,
25877
+ fallbackPatientInstruction
25878
+ ]) {
25879
+ if (!value) continue;
25880
+ const normalized = normalizedInstruction2(value);
25881
+ if (parts.some((existing) => {
25882
+ const candidate = normalizedInstruction2(existing);
25883
+ return candidate === normalized || candidate.includes(normalized) || normalized.includes(candidate);
25884
+ })) continue;
25885
+ parts.push(value);
25886
+ }
25887
+ return parts.join(" ").trim() || `${verb}.`;
25406
25888
  }
25407
25889
  const hasExplicitMethod = Boolean(((_z = (_y = clause.method) == null ? void 0 : _y.text) == null ? void 0 : _z.trim()) || ((_B = (_A = clause.method) == null ? void 0 : _A.coding) == null ? void 0 : _B.code));
25408
25890
  const graphRepresentsDose = !clause.dose || Boolean((_C = clause.instructionGraph) == null ? void 0 : _C.actions.some(
@@ -26998,19 +27480,45 @@ function unifySynsem(left, right, context) {
26998
27480
  }
26999
27481
  };
27000
27482
  }
27483
+ function hasDailyFrequencyDefaultEvidence(sign) {
27484
+ return sign.evidence.some((item) => item.scheduleDefault === "daily-frequency");
27485
+ }
27486
+ function schedulePeriodMatches(left, right) {
27487
+ return left.period !== void 0 && right.period !== void 0 && left.period === right.period && left.periodUnit !== void 0 && left.periodUnit === right.periodUnit;
27488
+ }
27489
+ function refinedDailyCadenceSynsem(cadenceSign, explicitSign) {
27490
+ const cadence = cadenceSign.synsem.head.schedule;
27491
+ const explicit = explicitSign.synsem.head.schedule;
27492
+ if (!cadence || !explicit || !hasDailyFrequencyDefaultEvidence(cadenceSign)) return void 0;
27493
+ if (cadence.frequency !== 1 || explicit.frequency === void 0 || explicit.frequency === 1) return void 0;
27494
+ if (!schedulePeriodMatches(cadence, explicit)) return void 0;
27495
+ return __spreadProps(__spreadValues({}, cadenceSign.synsem), {
27496
+ head: __spreadProps(__spreadValues({}, cadenceSign.synsem.head), {
27497
+ schedule: __spreadProps(__spreadValues({}, cadence), { frequency: void 0, timingCode: void 0 })
27498
+ })
27499
+ });
27500
+ }
27501
+ function scheduleRefinementSynsems(left, right) {
27502
+ const refinedLeft = refinedDailyCadenceSynsem(left, right);
27503
+ if (refinedLeft) return { left: refinedLeft, right: right.synsem, refined: true };
27504
+ const refinedRight = refinedDailyCadenceSynsem(right, left);
27505
+ if (refinedRight) return { left: left.synsem, right: refinedRight, refined: true };
27506
+ return { left: left.synsem, right: right.synsem, refined: false };
27507
+ }
27001
27508
  function combineSigns(left, right, context, rule) {
27002
27509
  const selectedConstruction = selectHpsgConstruction(left, right);
27003
27510
  if (!selectedConstruction) return void 0;
27004
27511
  const target = selectedConstruction.construction.headSide === "left" ? left : right;
27005
27512
  const condition = selectedConstruction.construction.headSide === "left" ? right : left;
27006
- const synsem = selectedConstruction.construction.operation === "scope" ? scopeSynsem(condition, target) : unifySynsem(left.synsem, right.synsem, context);
27513
+ const refinement = scheduleRefinementSynsems(left, right);
27514
+ const synsem = selectedConstruction.construction.operation === "scope" ? scopeSynsem(condition, target) : unifySynsem(refinement.left, refinement.right, context);
27007
27515
  if (!synsem) return void 0;
27008
27516
  const fs = combineSignFeatureStructures(
27009
27517
  left.fs,
27010
27518
  right.fs,
27011
27519
  selectedConstruction.motherType,
27012
27520
  selectedConstruction.construction.headSide,
27013
- selectedConstruction.construction.operation === "scope" ? synsem : void 0
27521
+ selectedConstruction.construction.operation === "scope" || refinement.refined ? synsem : void 0
27014
27522
  );
27015
27523
  if (!fs) {
27016
27524
  return void 0;
@@ -27506,117 +28014,6 @@ function getPrimarySiteMeaningCandidate(token) {
27506
28014
  return candidates && candidates.length > 0 ? candidates[0] : void 0;
27507
28015
  }
27508
28016
 
27509
- // src/hpsg/timing-lexicon.ts
27510
- var EVERY_INTERVAL_TOKENS = EVERY_INTERVAL_TOKENS_DATA;
27511
- var COUNT_MARKER_TOKENS = COUNT_MARKER_TOKENS_DATA;
27512
- var FREQUENCY_SIMPLE_WORDS = FREQUENCY_SIMPLE_WORDS_DATA;
27513
- var FREQUENCY_NUMBER_WORDS = FREQUENCY_NUMBER_WORDS_DATA;
27514
- var FREQUENCY_TIMES_WORDS = FREQUENCY_TIMES_WORDS_DATA;
27515
- var FREQUENCY_CONNECTOR_WORDS = FREQUENCY_CONNECTOR_WORDS_DATA;
27516
- function mapPeriodUnitLabel(label) {
27517
- return FhirPeriodUnit[label];
27518
- }
27519
- var FREQUENCY_ADVERB_UNITS = new Map(
27520
- Array.from(FREQUENCY_ADVERB_UNITS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
27521
- );
27522
- var INTERVAL_UNITS = new Map(
27523
- Array.from(INTERVAL_UNIT_TOKENS_DATA.entries()).map(([token, label]) => [token, mapPeriodUnitLabel(label)]).filter((entry) => Boolean(entry[1]))
27524
- );
27525
- function normalizePeriodValue(value, unit) {
27526
- if (unit === "h" /* Hour */ && (!Number.isInteger(value) || value < 1)) {
27527
- return { value: Math.round(value * 60 * 1e3) / 1e3, unit: "min" /* Minute */ };
27528
- }
27529
- return { value, unit };
27530
- }
27531
- function normalizePeriodRange(low, high, unit) {
27532
- if (unit === "h" /* Hour */ && (!Number.isInteger(low) || !Number.isInteger(high) || low < 1 || high < 1)) {
27533
- return {
27534
- low: Math.round(low * 60 * 1e3) / 1e3,
27535
- high: Math.round(high * 60 * 1e3) / 1e3,
27536
- unit: "min" /* Minute */
27537
- };
27538
- }
27539
- return { low, high, unit };
27540
- }
27541
- function periodUnitSuffix(unit) {
27542
- switch (unit) {
27543
- case "min" /* Minute */:
27544
- return "min";
27545
- case "h" /* Hour */:
27546
- return "h";
27547
- case "d" /* Day */:
27548
- return "d";
27549
- case "wk" /* Week */:
27550
- return "wk";
27551
- case "mo" /* Month */:
27552
- return "mo";
27553
- case "a" /* Year */:
27554
- return "a";
27555
- default:
27556
- return void 0;
27557
- }
27558
- }
27559
- function deriveDefaultTimingForPeriod(value, unit, currentTimingCode) {
27560
- let timingCode = currentTimingCode;
27561
- const suffix = periodUnitSuffix(unit);
27562
- if (suffix) {
27563
- const key2 = `q${value}${suffix}`;
27564
- const descriptor = TIMING_ABBREVIATIONS[key2];
27565
- if (descriptor == null ? void 0 : descriptor.code) {
27566
- timingCode = timingCode != null ? timingCode : descriptor.code;
27567
- }
27568
- }
27569
- if (unit === "wk" /* Week */ && value === 1) {
27570
- timingCode = timingCode != null ? timingCode : "WK";
27571
- }
27572
- if (unit === "mo" /* Month */ && value === 1) {
27573
- timingCode = timingCode != null ? timingCode : "MO";
27574
- }
27575
- return {
27576
- frequency: unit === "d" /* Day */ && value === 1 ? 1 : void 0,
27577
- timingCode
27578
- };
27579
- }
27580
- function buildPeriodScheduleFeature(period, unit) {
27581
- const normalized = normalizePeriodValue(period, unit);
27582
- const defaults = deriveDefaultTimingForPeriod(normalized.value, normalized.unit);
27583
- return {
27584
- period: normalized.value,
27585
- periodUnit: normalized.unit,
27586
- frequency: defaults.frequency,
27587
- timingCode: defaults.timingCode
27588
- };
27589
- }
27590
- function mapIntervalUnit(token) {
27591
- const unit = INTERVAL_UNITS.get(token);
27592
- return unit === "min" /* Minute */ || unit === "h" /* Hour */ || unit === "d" /* Day */ || unit === "wk" /* Week */ || unit === "mo" /* Month */ ? unit : void 0;
27593
- }
27594
- function mapFrequencyAdverb(token) {
27595
- return FREQUENCY_ADVERB_UNITS.get(token);
27596
- }
27597
- function parseNumericRange(token) {
27598
- const rangeMatch = token.match(/^([0-9]+(?:\.[0-9]+)?)[-–—]([0-9]+(?:\.[0-9]+)?)$/);
27599
- if (!rangeMatch) {
27600
- return void 0;
27601
- }
27602
- const low = parseFloat(rangeMatch[1]);
27603
- const high = parseFloat(rangeMatch[2]);
27604
- if (!Number.isFinite(low) || !Number.isFinite(high) || high < low) {
27605
- return void 0;
27606
- }
27607
- return { low, high };
27608
- }
27609
- function buildDurationScheduleFeature(value, unit, max) {
27610
- if (value === void 0 || !Number.isFinite(value) || value <= 0 || !unit) {
27611
- return void 0;
27612
- }
27613
- return {
27614
- duration: value,
27615
- durationMax: max !== void 0 && Number.isFinite(max) && max > value ? max : void 0,
27616
- durationUnit: unit
27617
- };
27618
- }
27619
-
27620
28017
  // src/hpsg/rule-context.ts
27621
28018
  function normalizeTokenLower(token) {
27622
28019
  var _a26;
@@ -27793,7 +28190,8 @@ function lexicalSign(args) {
27793
28190
  evidence: [
27794
28191
  {
27795
28192
  rule: args.rule,
27796
- tokenIndices
28193
+ tokenIndices,
28194
+ scheduleDefault: args.scheduleDefault
27797
28195
  }
27798
28196
  ],
27799
28197
  score: (_b3 = args.score) != null ? _b3 : 1
@@ -28079,11 +28477,44 @@ function separatedIntervalRule() {
28079
28477
  valence: {},
28080
28478
  cont: { clauseKind: "administration" }
28081
28479
  },
28480
+ scheduleDefault: directUnit === "d" /* Day */ ? "daily-frequency" : void 0,
28082
28481
  score: 9
28083
28482
  })
28084
28483
  ];
28085
28484
  }
28086
28485
  const unitToken = context.tokens[start + 2];
28486
+ const explicitLowUnit = unitToken && !context.state.consumed.has(unitToken.index) ? mapIntervalUnit(normalizeTokenLower(unitToken)) : void 0;
28487
+ const explicitRangeConnectorToken = context.tokens[start + 3];
28488
+ const explicitRangeConnector = explicitRangeConnectorToken && !context.state.consumed.has(explicitRangeConnectorToken.index) ? normalizeTokenLower(explicitRangeConnectorToken) : void 0;
28489
+ const explicitHighToken = context.tokens[start + 4];
28490
+ const explicitHighLower = explicitHighToken && !context.state.consumed.has(explicitHighToken.index) ? normalizeTokenLower(explicitHighToken) : void 0;
28491
+ const explicitHighUnitToken = context.tokens[start + 5];
28492
+ const explicitHighUnit = explicitHighUnitToken && !context.state.consumed.has(explicitHighUnitToken.index) ? mapIntervalUnit(normalizeTokenLower(explicitHighUnitToken)) : void 0;
28493
+ if (explicitLowUnit && explicitRangeConnector && RANGE_CONNECTORS.has(explicitRangeConnector) && explicitHighToken && explicitHighLower && explicitHighUnit && explicitHighUnitToken && /^[0-9]+(?:\.[0-9]+)?$/.test(quantityLower) && /^[0-9]+(?:\.[0-9]+)?$/.test(explicitHighLower)) {
28494
+ const normalizedRange = normalizeMixedPeriodRange(
28495
+ parseFloat(quantityLower),
28496
+ explicitLowUnit,
28497
+ parseFloat(explicitHighLower),
28498
+ explicitHighUnit
28499
+ );
28500
+ if (normalizedRange) {
28501
+ return [lexicalSign({
28502
+ type: "schedule-sign",
28503
+ rule: "hpsg.lex.schedule.separatedMixedUnitIntervalRange",
28504
+ tokens: [lead, quantity, unitToken, explicitRangeConnectorToken, explicitHighToken, explicitHighUnitToken],
28505
+ synsem: {
28506
+ head: { schedule: {
28507
+ period: normalizedRange.low,
28508
+ periodMax: normalizedRange.high,
28509
+ periodUnit: normalizedRange.unit
28510
+ } },
28511
+ valence: {},
28512
+ cont: { clauseKind: "administration" }
28513
+ },
28514
+ score: 14
28515
+ })];
28516
+ }
28517
+ }
28087
28518
  const rangeConnector = unitToken && !context.state.consumed.has(unitToken.index) ? normalizeTokenLower(unitToken) : void 0;
28088
28519
  const highToken = context.tokens[start + 3];
28089
28520
  const highLower = highToken && !context.state.consumed.has(highToken.index) ? normalizeTokenLower(highToken) : void 0;
@@ -30819,6 +31250,28 @@ function anchoredModifierLeadsToResolvableSite(context, start) {
30819
31250
  }
30820
31251
  return false;
30821
31252
  }
31253
+ function relationIntroducesNonSiteComplement(context, index) {
31254
+ const token = context.tokens[index];
31255
+ if (!token) return false;
31256
+ const relations = resolveActionRelationSurfaceCandidates(normalizeTokenLower(token));
31257
+ if (!relations.length) return false;
31258
+ for (let cursor = index + 1; cursor < Math.min(context.limit, index + 4); cursor += 1) {
31259
+ const candidate = context.tokens[cursor];
31260
+ if (!candidate || context.state.consumed.has(candidate.index) || isPunctuation(normalizeTokenLower(candidate))) {
31261
+ break;
31262
+ }
31263
+ if (EVENT_TIMING_TOKENS[normalizeTokenLower(candidate)]) return true;
31264
+ }
31265
+ return false;
31266
+ }
31267
+ function coordinationStartsAction(context, index) {
31268
+ const token = context.tokens[index];
31269
+ if (!token || !ACTION_COORDINATION_CONNECTORS.has(normalizeTokenLower(token))) return false;
31270
+ const next = context.tokens[index + 1];
31271
+ return Boolean(
31272
+ next && !context.state.consumed.has(next.index) && resolveMedicationInstructionAction(normalizeTokenLower(next), context.options)
31273
+ );
31274
+ }
30822
31275
  function siteBoundary(lower, context) {
30823
31276
  var _a26, _b3, _c2;
30824
31277
  if (SITE_MULTIPLICITY_WORDS.has(lower)) {
@@ -30875,6 +31328,21 @@ function hasSystemicCueBeforeSiteAbbreviation(context, start) {
30875
31328
  }
30876
31329
  return sawNonOcularDose;
30877
31330
  }
31331
+ function anchorTargetsTypedNonSiteConcept(context, start) {
31332
+ var _a26;
31333
+ const current = (_a26 = tokensAvailable(context, start, 1)) == null ? void 0 : _a26[0];
31334
+ if (!current || !resolveActionRelationSurface(normalizeTokenLower(current))) return false;
31335
+ for (let cursor = start + 1; cursor < Math.min(context.limit, start + 4); cursor += 1) {
31336
+ const candidate = context.tokens[cursor];
31337
+ if (!candidate || context.state.consumed.has(candidate.index)) break;
31338
+ const lower = normalizeTokenLower(candidate);
31339
+ if (isPunctuation(lower)) break;
31340
+ const concept = resolveMedicationInstructionConcept(lower, context.options);
31341
+ if (!concept) continue;
31342
+ return concept.role !== "site" /* Site */ && concept.role !== "destination" /* Destination */;
31343
+ }
31344
+ return false;
31345
+ }
30878
31346
  function contextSuggestsNonOcularSite(context) {
30879
31347
  var _a26, _b3, _c2, _d, _e, _f;
30880
31348
  const dosageForm = (_c2 = (_b3 = (_a26 = context.options) == null ? void 0 : _a26.context) == null ? void 0 : _b3.dosageForm) == null ? void 0 : _c2.trim().toLowerCase().replace(/\s+/g, " ");
@@ -30893,7 +31361,7 @@ function siteLexicalRule() {
30893
31361
  }
30894
31362
  const signs = [];
30895
31363
  const lower = normalizeTokenLower(token);
30896
- if (tokenBelongsToContextualPrnReasonLead(context, start)) {
31364
+ if (tokenBelongsToContextualPrnReasonLead(context, start) || anchorTargetsTypedNonSiteConcept(context, start)) {
30897
31365
  return signs;
30898
31366
  }
30899
31367
  const siteCandidate = getPrimarySiteMeaningCandidate(token);
@@ -30936,11 +31404,12 @@ function siteLexicalRule() {
30936
31404
  if (candidate.kind === "NUMBER" /* Number */) {
30937
31405
  break;
30938
31406
  }
30939
- if (getDayOfWeekMeaning(candidate)) {
31407
+ if (getDayOfWeekMeaning(candidate) || ACTION_SEQUENCE_MARKERS.has(candidateLower)) {
30940
31408
  break;
30941
31409
  }
31410
+ if (coordinationStartsAction(context, cursor)) break;
30942
31411
  const siteModifierCanBridgeBoundary = (SITE_SELF_DISPLAY_ANCHORS.has(candidateLower) || EXTERNAL_SITE_LOCATIVE_PREFIXES.has(candidateLower) || BODY_SITE_ATTRIBUTIVE_MODIFIERS.has(candidateLower)) && anchoredModifierLeadsToResolvableSite(context, cursor);
30943
- if (siteBoundary(candidateLower, context) && (isPunctuation(candidateLower) || !siteModifierCanBridgeBoundary)) {
31412
+ if ((siteBoundary(candidateLower, context) || relationIntroducesNonSiteComplement(context, cursor)) && (isPunctuation(candidateLower) || !siteModifierCanBridgeBoundary)) {
30944
31413
  const next = context.tokens[cursor + 1];
30945
31414
  const nextLower = next && !context.state.consumed.has(next.index) ? normalizeTokenLower(next) : void 0;
30946
31415
  const continuedText = nextLower ? [...displayTokens, next].map((part) => part.original).join(" ") : "";