ezmedicationinput 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +216 -18
  2. package/dist/adapters/canonical-course.d.ts +131 -0
  3. package/dist/adapters/r5-course.d.ts +27 -0
  4. package/dist/advice-locale-adapter.d.ts +24 -0
  5. package/dist/advice.d.ts +73 -6
  6. package/dist/body-site-grammar.d.ts +21 -2
  7. package/dist/body-site-lookup.d.ts +8 -0
  8. package/dist/body-site-spatial.d.ts +12 -2
  9. package/dist/body-site-target.d.ts +38 -3
  10. package/dist/canonical/compile.d.ts +98 -0
  11. package/dist/canonical/course.d.ts +388 -0
  12. package/dist/canonical/format-course.d.ts +38 -0
  13. package/dist/clause-tail-grammar.d.ts +2 -0
  14. package/dist/date-interpretation.d.ts +36 -2
  15. package/dist/dosage-course.d.ts +304 -30
  16. package/dist/event-timing-expression.d.ts +26 -1
  17. package/dist/execution/calendar.d.ts +107 -0
  18. package/dist/execution/engine.d.ts +11 -0
  19. package/dist/fhir-quantity-operator.d.ts +89 -0
  20. package/dist/fhir-translations.d.ts +5 -6
  21. package/dist/fhir.d.ts +119 -14
  22. package/dist/format.d.ts +106 -5
  23. package/dist/hpsg/constructions.d.ts +35 -8
  24. package/dist/hpsg/defaults.d.ts +2 -0
  25. package/dist/hpsg/lexical-classes.d.ts +196 -24
  26. package/dist/hpsg/method-lexicon.d.ts +3 -0
  27. package/dist/hpsg/procedural-context.d.ts +48 -5
  28. package/dist/hpsg/projection.d.ts +32 -1
  29. package/dist/hpsg/quantity-lexicon.d.ts +51 -0
  30. package/dist/hpsg/rule-context.d.ts +172 -7
  31. package/dist/hpsg/rules/clinical-quantity-rules.d.ts +16 -7
  32. package/dist/hpsg/rules/condition-rules.d.ts +13 -3
  33. package/dist/hpsg/rules/core-rules.d.ts +8 -2
  34. package/dist/hpsg/rules/instruction-rules.d.ts +2 -0
  35. package/dist/hpsg/rules/prn-rules.d.ts +12 -1
  36. package/dist/hpsg/rules/site-rules.d.ts +10 -1
  37. package/dist/hpsg/rules/timing-rules.d.ts +116 -22
  38. package/dist/hpsg/segmenter.d.ts +2 -2
  39. package/dist/hpsg/signature.d.ts +54 -7
  40. package/dist/hpsg/timing-lexicon.d.ts +18 -2
  41. package/dist/hpsg/unification.d.ts +3 -1
  42. package/dist/i18n.d.ts +37 -1
  43. package/dist/index.cjs +83231 -52284
  44. package/dist/index.d.ts +26 -9
  45. package/dist/index.js +83222 -52284
  46. package/dist/instruction-action-locale-adapter.d.ts +92 -5
  47. package/dist/instruction-action-parser.d.ts +43 -0
  48. package/dist/instruction-action-terminology.d.ts +44 -3
  49. package/dist/instruction-concept-terminology.d.ts +20 -1
  50. package/dist/instruction-graph-fhir.d.ts +10 -2
  51. package/dist/instruction-graph-ownership.d.ts +96 -0
  52. package/dist/instruction-graph.d.ts +68 -49
  53. package/dist/ir.d.ts +1 -1
  54. package/dist/lexer/lex.d.ts +5 -1
  55. package/dist/lexer/locale.d.ts +14 -0
  56. package/dist/lexer/locales/en.d.ts +11 -0
  57. package/dist/lexer/surface-segmenter.d.ts +1 -1
  58. package/dist/lexer/surface.d.ts +4 -1
  59. package/dist/lexer/token-types.d.ts +6 -0
  60. package/dist/locale-detection.d.ts +5 -0
  61. package/dist/locales/clause/en.d.ts +14 -0
  62. package/dist/locales/course/en.d.ts +20 -0
  63. package/dist/locales/course/th.d.ts +12 -0
  64. package/dist/localization.d.ts +76 -0
  65. package/dist/localized-timing.d.ts +1 -1
  66. package/dist/maps.d.ts +44 -10
  67. package/dist/medication-condition.d.ts +72 -11
  68. package/dist/parser-state.d.ts +12 -2
  69. package/dist/parser.d.ts +5 -3
  70. package/dist/prn.d.ts +13 -2
  71. package/dist/regimen/coordination-scope.d.ts +13 -1
  72. package/dist/regimen/grammar.d.ts +18 -1
  73. package/dist/regimen/parallel-course.d.ts +13 -42
  74. package/dist/regimen/planner.d.ts +2 -3
  75. package/dist/regimen/regimen.d.ts +8 -2
  76. package/dist/relation-terminology.d.ts +1 -0
  77. package/dist/schedule.d.ts +14 -10
  78. package/dist/snomed.d.ts +3 -0
  79. package/dist/suggest-locale-adapter.d.ts +15 -0
  80. package/dist/symptom-terminology.d.ts +5 -1
  81. package/dist/timing-summary.d.ts +114 -1
  82. package/dist/types.d.ts +627 -61
  83. package/dist/unit-lexicon.d.ts +4 -1
  84. package/dist/utils/text.d.ts +3 -0
  85. package/dist/utils/units.d.ts +22 -0
  86. package/package.json +1 -1
@@ -0,0 +1,51 @@
1
+ import type { Token } from "../parser-state";
2
+ import type { CanonicalDoseRange, ParseOptions } from "../types";
3
+ import type { HpsgSign, HpsgDimensionalQuantityTerm } from "./signature";
4
+ /** Complete amount morphology is available before grammar construction. The
5
+ * optional admitted signs preserve the richer HPSG lookahead's ownership. */
6
+ export interface QuantityLexicalContext {
7
+ tokens: readonly Token[];
8
+ options?: ParseOptions;
9
+ limit?: number;
10
+ state?: {
11
+ consumed: ReadonlySet<number>;
12
+ };
13
+ clinicalCache?: {
14
+ quantityLookahead?: ReadonlyMap<number, readonly HpsgSign[]>;
15
+ };
16
+ }
17
+ export declare function quantityTokenAvailable(context: QuantityLexicalContext, index: number): boolean;
18
+ export declare function doseNumberValue(token: Token | undefined): number | undefined;
19
+ /** One plain numeric daughter shared by active amounts, carrier volumes and limits. */
20
+ export declare function plainClinicalNumberAt(context: QuantityLexicalContext, start: number, initial?: number): {
21
+ value: number;
22
+ numericIndex: number;
23
+ mixed: boolean;
24
+ fractional: boolean;
25
+ } | undefined;
26
+ /** The optional article or partitive belongs to the following medication unit. */
27
+ export declare function doseUnitIndexAfter(context: QuantityLexicalContext, start: number): number | undefined;
28
+ /** Explicit compound medication units share one declared lexical span. Context-
29
+ * licensed bare units remain the responsibility of their admitting construction.
30
+ * A selecting construction may expose the final word before its attached complement. */
31
+ export declare function compoundDoseUnitAt(context: QuantityLexicalContext, start: number, terminalUnit?: (index: number, surface: string) => string | undefined): {
32
+ unit: string;
33
+ end: number;
34
+ } | undefined;
35
+ export declare function clinicalMassTerm(value: number, raw: string): HpsgDimensionalQuantityTerm | undefined;
36
+ /** The same patient-mass denominator qualifies administered amounts and
37
+ * quantity ceilings. Cadence remains owned by the selecting construction. */
38
+ export declare function normalizeClinicalDoseUnit(raw: string, options?: ParseOptions): string | undefined;
39
+ export declare function directDoseUnitAfter(context: QuantityLexicalContext, start: number, terminalUnit?: (index: number, surface: string) => string | undefined): {
40
+ unit: string;
41
+ end: number;
42
+ } | undefined;
43
+ /** A complete medication amount owns its numeric daughters, connectors and unit.
44
+ * Consumers use the same bounded end before considering another constituent. */
45
+ export declare function medicationAmountAt(context: QuantityLexicalContext, index: number): {
46
+ end: number;
47
+ unit?: string;
48
+ range?: CanonicalDoseRange;
49
+ rangeConnectorIndex?: number;
50
+ } | undefined;
51
+ export declare function hasPrecedingMedicationAmount(context: QuantityLexicalContext, before: number): boolean;
@@ -1,20 +1,48 @@
1
+ import { type QuantityLexicalContext } from "./quantity-lexicon";
2
+ export { quantityTokenAvailable, doseNumberValue, plainClinicalNumberAt, doseUnitIndexAfter, compoundDoseUnitAt, directDoseUnitAfter, medicationAmountAt, hasPrecedingMedicationAmount } from "./quantity-lexicon";
1
3
  import { Token, ParserState } from "../parser-state";
2
- import { ParseOptions } from "../types";
4
+ import { type FhirCoding, EventTiming, FhirPeriodUnit, ParseOptions, type CanonicalScheduleExpr, type MedicationInstructionActionDefinition } from "../types";
5
+ import { type LexToken } from "../lexer/token-types";
3
6
  import type { MedicationDateListMatch } from "../date-interpretation";
4
7
  import { type ParsedMedicationGuard } from "./constructions";
5
- import { HpsgLexicalRule } from "./signature";
8
+ import { MEAL_RELATION_BY_TOKEN } from "./lexical-classes";
9
+ export { normalizeTokenLower, parseClockToken } from "./lexical-classes";
10
+ import { HpsgLexicalRule, HpsgSign } from "./signature";
6
11
  import { HpsgProjectionDeps } from "./projection";
7
12
  import { HpsgUnificationContext } from "./unification";
8
13
  export interface HpsgClauseContext {
9
14
  state: ParserState;
10
15
  tokens: Token[];
16
+ /** Completed lexical tokens for the same clause, before semantic annotation. */
17
+ rawTokens?: LexToken[];
11
18
  options?: ParseOptions;
12
19
  dateSpans: MedicationDateListMatch[];
13
20
  limit: number;
14
21
  deps: HpsgProjectionDeps & HpsgUnificationContext;
15
22
  clinicalCache: {
23
+ /** Existing lexical matches requested early by instruction body lookahead. */
24
+ quantityLookahead?: Map<number, HpsgSign[]>;
25
+ /** PRN daughters after final conditional-owner admission. */
26
+ prnLookahead?: Map<number, HpsgSign[]>;
27
+ /** Nominal PRN daughters retained independently of final admission. */
28
+ prnNominalLookahead?: Map<number, HpsgSign[]>;
29
+ /** Route ownership is shared by chart admission and adjacent lexical consumers. */
30
+ routeLookahead?: Map<number, HpsgSign[]>;
31
+ /** Product signs requested early by a competing instruction head. */
32
+ productLookahead?: Map<number, HpsgSign[]>;
33
+ /** Complete administration schedules already admitted by the lexical chart.
34
+ * Generic source-tail fallback cannot detach their internal words. */
35
+ scheduleTokenIndices?: Set<number>;
36
+ /** Typed nominal signs requested before generic instruction fallback. */
37
+ siteLookahead?: Map<number, HpsgSign[]>;
16
38
  medicationGuardScanned?: true;
17
39
  medicationGuard?: ParsedMedicationGuard;
40
+ /** Tokens owned by a complete medication range, dimensional quantity or cumulative limit.
41
+ * Numeric, site and advice fallbacks must not detach its daughters. */
42
+ quantityTokenIndices?: Set<number>;
43
+ /** A recognized per-time expression still owns its numeral when no rate
44
+ * head licenses it. Scalar-dose fallback must not detach that numeral. */
45
+ unlicensedRateTokenIndices?: Set<number>;
18
46
  };
19
47
  project?: boolean;
20
48
  }
@@ -27,17 +55,55 @@ export declare function medicationGuardForContext(context: HpsgClauseContext): P
27
55
  export declare function isMedicationGuardMarker(context: HpsgClauseContext, start: number): boolean;
28
56
  export declare function startsMedicationGuard(context: HpsgClauseContext, start: number): boolean;
29
57
  export declare function sourceRangeOverlapsContextDate(context: HpsgClauseContext, start: number, end: number): boolean;
30
- export declare function normalizeTokenLower(token: Token): string;
31
58
  export declare function isPunctuation(lower: string): boolean;
59
+ /** Registered, immediate treatment origin following a temporal quantity. */
60
+ export declare function immediateTreatmentOriginAt(context: QuantityLexicalContext, start: number): boolean;
61
+ /** An interval origin cannot displace an explicitly introduced runtime. */
62
+ export declare function treatmentStartOriginAt(context: HpsgClauseContext, start: number, durationStart: number): boolean;
63
+ /** Infusion quantities and runtime lookahead share the same elapsed nominal. */
64
+ export declare function infusionDurationAt(context: HpsgClauseContext, start: number, allowRange?: boolean): {
65
+ unit: FhirPeriodUnit.Second | FhirPeriodUnit.Minute | FhirPeriodUnit.Hour;
66
+ value: number;
67
+ maximum?: number;
68
+ unitSurface: string;
69
+ comparator?: CanonicalScheduleExpr["administrationDurationComparator"];
70
+ range?: CanonicalScheduleExpr["administrationDurationRange"];
71
+ end: number;
72
+ } | undefined;
73
+ /** The nearest selected action or clause boundary owns a following complement. */
74
+ export declare function precedingMedicationInstructionAction(context: HpsgClauseContext, start: number): MedicationInstructionActionDefinition | undefined;
75
+ /** The selected action licenses both the current duration and any disambiguating runtime. */
76
+ export declare function selectedMethodOwnsAdministrationDuration(context: HpsgClauseContext, start: number, relation: string, definition: MedicationInstructionActionDefinition | undefined): boolean;
77
+ export declare function precedingMethodOwnsAdministrationDuration(context: HpsgClauseContext, start: number, relation: string): boolean;
32
78
  export declare function isClockLikeLower(lower: string): boolean;
33
79
  export declare function isAmPmLower(lower: string): boolean;
34
80
  export declare function isAnteMeridiemLower(lower: string): boolean;
35
81
  export declare function isPostMeridiemLower(lower: string): boolean;
36
- export declare function parseClockToken(token: Token | undefined, meridiemToken?: Token | undefined): {
37
- value: string;
38
- tokens: Token[];
82
+ export declare function tokensAvailable(context: QuantityLexicalContext, start: number, span: number): Token[] | undefined;
83
+ /** Read the longest registered activity noun while retaining original tokens.
84
+ * @param context Shared clause and caller vocabulary.
85
+ * @param start First noun token, after any separate nominal modifier.
86
+ * @param prefixLength Length of a source-attached lexical modifier already interpreted by its construction.
87
+ */
88
+ export declare function activityConceptAt(context: QuantityLexicalContext, start: number, prefixLength?: number): {
89
+ length: number;
90
+ display: string;
91
+ i18n?: Record<string, string>;
92
+ coding?: FhirCoding;
93
+ } | undefined;
94
+ /** The existing activity noun plus optional event phase is one temporal nominal.
95
+ * Shared with opaque-source admission so a declared event does not lose its owner. */
96
+ export declare function activityEventNominalAt(context: QuantityLexicalContext, start: number): {
97
+ start: number;
98
+ activity: {
99
+ length: number;
100
+ display: string;
101
+ i18n?: Record<string, string>;
102
+ coding?: FhirCoding;
103
+ } | undefined;
104
+ hasEventPhase: boolean;
105
+ end: number;
39
106
  } | undefined;
40
- export declare function tokensAvailable(context: HpsgClauseContext, start: number, span: number): Token[] | undefined;
41
107
  export declare function rangeFromTokens(tokens: Token[]): {
42
108
  start: number;
43
109
  end: number;
@@ -46,3 +112,102 @@ export declare function splitByLexicalSeparators(text: string, separators: Reado
46
112
  export declare function hasLexicalSeparator(text: string, separators: ReadonlySet<string>): boolean;
47
113
  export declare function joinTokenText(tokens: Token[]): string;
48
114
  export declare function lexicalRule(id: string, match: HpsgLexicalRule<HpsgClauseContext>["match"]): HpsgLexicalRule<HpsgClauseContext>;
115
+ /** Shared numeric-word inventory: clinical quantities and ordinary timing
116
+ * interpret the same lexical number daughters, without string special cases. */
117
+ export declare function clinicalDurationNumber(token: Token | undefined): number | undefined;
118
+ /** Seconds are an existing action duration, without broadening cadence units. */
119
+ declare function clinicalDurationUnit(surface: string): FhirPeriodUnit | undefined;
120
+ export interface ClinicalDurationMatch {
121
+ value: number;
122
+ maximum?: number;
123
+ unit: FhirPeriodUnit;
124
+ unitSurface: string;
125
+ comparator?: CanonicalScheduleExpr["administrationDurationComparator"];
126
+ range?: CanonicalScheduleExpr["administrationDurationRange"];
127
+ end: number;
128
+ }
129
+ /** One elapsed-duration daughter shared by infusion amounts and dose-limit periods. */
130
+ export declare function clinicalDurationAt(context: QuantityLexicalContext, start: number, allowRange?: boolean, unitForSurface?: typeof clinicalDurationUnit): ClinicalDurationMatch | undefined;
131
+ /** Compare fixed elapsed measures without replacing the authored unit. */
132
+ export declare function elapsedDurationInUnit(value: number, from: FhirPeriodUnit, to: FhirPeriodUnit): number | undefined;
133
+ /** Read the upper duration only. Compare compatible units and keep both authored endpoints. */
134
+ export declare function clinicalDurationRangeAfter(context: QuantityLexicalContext, lower: ClinicalDurationMatch, unitForSurface?: typeof clinicalDurationUnit, pairedConnector?: string): {
135
+ value: number;
136
+ maximum: number;
137
+ unit: FhirPeriodUnit;
138
+ unitSurface: string;
139
+ range: {
140
+ low: {
141
+ value: number;
142
+ unit: FhirPeriodUnit;
143
+ };
144
+ high: {
145
+ value: number;
146
+ unit: FhirPeriodUnit;
147
+ };
148
+ };
149
+ end: number;
150
+ } | undefined;
151
+ /** A maximum head owns its leading separators and coordinated attachment. */
152
+ export declare function maximumCountLeadAt(context: QuantityLexicalContext, start: number, firstLower?: string): {
153
+ tokens: Token[];
154
+ headStart: number;
155
+ comparative: boolean;
156
+ } | undefined;
157
+ /** Maximum abbreviations share one optional trailing punctuation token. */
158
+ export declare function maximumCountValueIndex(context: QuantityLexicalContext, lead: NonNullable<ReturnType<typeof maximumCountLeadAt>>): number;
159
+ export declare function occurrenceCapPeriodAt(context: QuantityLexicalContext, start: number): {
160
+ tokens: Token[];
161
+ period: number;
162
+ periodUnit: FhirPeriodUnit;
163
+ } | undefined;
164
+ type MaximumDosePeriod = ({
165
+ tokens: Token[];
166
+ period: number;
167
+ periodUnit: FhirPeriodUnit;
168
+ } | {
169
+ tokens: Token[];
170
+ daypart: true;
171
+ } | {
172
+ tokens: Token[];
173
+ administration: true;
174
+ }) & {
175
+ unitDenominator?: boolean;
176
+ numericWindow?: true;
177
+ rolling?: true;
178
+ };
179
+ /** The existing compact maximum denominator is shared by quantity and count nouns. */
180
+ export declare function compactMaximumPeriodAt(context: QuantityLexicalContext, unitIndex: number, unitSurface: string): {
181
+ unitSurface: string;
182
+ period: MaximumDosePeriod;
183
+ } | undefined;
184
+ export declare function maximumDosePeriodAt(context: QuantityLexicalContext, start: number): MaximumDosePeriod | undefined;
185
+ /** Shared lexical constituent: a dose limit owns both its amount and period. */
186
+ export declare function maximumDosePerPeriodAt(context: QuantityLexicalContext, start: number, maximumHead?: {
187
+ tokens: Token[];
188
+ headStart: number;
189
+ comparative: boolean;
190
+ } | undefined): {
191
+ tokens: Token[];
192
+ amount: number;
193
+ unit: string;
194
+ period: MaximumDosePeriod;
195
+ headStart: number;
196
+ comparative: boolean;
197
+ rateDenominator: boolean;
198
+ } | undefined;
199
+ /** Numeric and locale-licensed named clocks share one end complement owner. */
200
+ export declare function courseEndClockAt(tokens: readonly Token[], start: number, limit?: number, endLead?: Token): {
201
+ tokens: Token[];
202
+ value?: string;
203
+ event?: EventTiming;
204
+ relation?: ReturnType<typeof MEAL_RELATION_BY_TOKEN.get>;
205
+ } | undefined;
206
+ /** A daypart inside UNTIL + NEXT is an end complement, not a recurring event. */
207
+ export declare function isEndBoundDaypartAt(tokens: readonly Token[], head: number): boolean;
208
+ /** Bounded NEXT + day/daypart nominal, with an optional locale article. */
209
+ export declare function nextDayOnsetAt(tokens: readonly Token[], start: number, limit: number): {
210
+ headIndex: number;
211
+ tokenEnd: number;
212
+ explicitStart: boolean;
213
+ } | undefined;
@@ -1,9 +1,18 @@
1
+ import { FhirPeriodUnit } from "../../types";
1
2
  import { HpsgClauseContext } from "../rule-context";
2
- import { HpsgLexicalRule } from "../signature";
3
- /**
4
- * Bounded lexical/construction contribution for safety-critical medication
5
- * quantities. It never searches the full clause and only accepts explicit
6
- * dimensional forms; unsupported weight suffixes remain typed unresolved
7
- * evidence instead of an ordinary dose.
8
- */
3
+ import { HpsgDimensionalQuantityTerm, HpsgLexicalRule, HpsgSign } from "../signature";
4
+ export declare function volumeOrMassTerm(value: number, raw: string): HpsgDimensionalQuantityTerm | undefined;
5
+ export declare function clinicalRatePeriodUnit(raw: string): FhirPeriodUnit.Hour | FhirPeriodUnit.Minute | undefined;
6
+ /** Shared lexical rate-head ownership, including a local route or AT marker. */
7
+ export declare function clinicalRateHeadAt(context: HpsgClauseContext, phraseStart: number, end: number, allowPrecedingDose?: boolean, period?: number, routeIsRateHead?: boolean): {
8
+ licensed: boolean;
9
+ rateSpecific: boolean;
10
+ marker: number | undefined;
11
+ };
12
+ /** Bounded dimensional quantity construction; unresolved weight amounts
13
+ * remain typed rates instead of fabricated scalar administrations. */
14
+ /** Instruction lookahead asks the same typed quantity owner before absorbing
15
+ * a later body token. Each start is matched once in this chart context; the
16
+ * normal lexical enumeration then reuses the sign, without a pre-scan. */
17
+ export declare function clinicalQuantityAt(context: HpsgClauseContext, start: number): HpsgSign[];
9
18
  export declare function clinicalQuantityLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
@@ -1,3 +1,4 @@
1
+ export { actionArgumentSpan } from "../procedural-context";
1
2
  import { FhirDayOfWeek, ParseOptions } from "../../types";
2
3
  import { MedicationDateListMatch } from "../../date-interpretation";
3
4
  import { HpsgClauseContext } from "../rule-context";
@@ -8,10 +9,19 @@ export interface CalendarExclusion {
8
9
  excluded: FhirDayOfWeek[];
9
10
  dates: string[];
10
11
  }
11
- export declare function containsCalendarExclusionCue(source: string): boolean;
12
+ export declare function containsCalendarExclusionCue(source: string, locale?: string): boolean;
13
+ /** Whole-source admission searches the provider cue independently of local
14
+ * sticky anchoring. Registration derives this stateless search expression. */
15
+ export declare function calendarExclusionSourceCue(source: string, locale?: string): {
16
+ start: number;
17
+ end: number;
18
+ } | undefined;
19
+ export declare function containsCalendarExclusionSourceCue(source: string, locale?: string): boolean;
12
20
  /** Resolve the lexical payload for a typed calendar-exclusion sign. */
13
- export declare function matchCalendarExclusion(source: string, options?: ParseOptions, knownDateSpans?: MedicationDateListMatch[], scopeEnd?: number, from?: number): CalendarExclusion | undefined;
14
- /** Medication guards are lexical adjuncts, separate from procedural IF scope. */
21
+ export declare function matchCalendarExclusion(source: string, options?: ParseOptions, knownDateSpans?: MedicationDateListMatch[], scopeEnd?: number, from?: number, selectedCue?: {
22
+ start: number;
23
+ end: number;
24
+ }): CalendarExclusion | undefined;
15
25
  export declare function medicationGuardLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
16
26
  export declare function weekdayComplementReferenceLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
17
27
  export declare function calendarExclusionLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
@@ -20,9 +20,12 @@ export declare function phaseAdjustmentAt(tokens: readonly Token[], start: numbe
20
20
  export declare function phaseAdjustmentLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
21
21
  export declare function directiveMarkerLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
22
22
  export declare function methodLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
23
- export declare function routeLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
23
+ /** An exact end lets an adjacent constituent request this same route owner. */
24
+ export declare function routeLexicalRule(exactEnd?: number): HpsgLexicalRule<HpsgClauseContext>;
25
+ /** Complete governed route boundary; the route lexical rule still owns its value. */
26
+ export declare function governedRouteLexicalEnd(tokens: readonly Token[], start: number, options?: ParseOptions, limit?: number): number | undefined;
24
27
  export declare function fillerLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
25
- export declare function productLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
28
+ export declare function productLexicalRule(cacheLookahead?: boolean): HpsgLexicalRule<HpsgClauseContext>;
26
29
  /**
27
30
  * Return the end of a bounded, explicit scalar-dose head for regimen boundary
28
31
  * candidacy. This uses the same HPSG quantity lexemes as `doseLexicalRule`;
@@ -34,6 +37,9 @@ export declare function productLexicalRule(): HpsgLexicalRule<HpsgClauseContext>
34
37
  * dose head.
35
38
  */
36
39
  export declare function explicitDoseLexicalEnd(tokens: readonly Token[], start: number, options?: ParseOptions, limit?: number): number | undefined;
40
+ /** A written unit or the existing medication context can complete a numeric
41
+ * dose daughter. This is boundary admission; the dose rule still owns its value. */
42
+ export declare function contextualDoseLexicalEnd(tokens: Token[], start: number, options?: ParseOptions, limit?: number): number | undefined;
37
43
  export declare function perTargetCountDoseRule(): HpsgLexicalRule<HpsgClauseContext>;
38
44
  export declare function doseLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
39
45
  export declare function connectorLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
@@ -1,5 +1,7 @@
1
+ import { AdviceFrame } from "../../types";
1
2
  import { HpsgClauseContext } from "../rule-context";
2
3
  import { HpsgLexicalRule, type HpsgSign } from "../signature";
4
+ export declare function isProceduralInstructionFrame(context: HpsgClauseContext, frame: AdviceFrame): boolean;
3
5
  export declare function proceduralActionLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
4
6
  export declare function workflowLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
5
7
  /** Compose ON/ONLY ON/EXCEPT with a registered activity and DAY noun.
@@ -1,6 +1,7 @@
1
1
  import { Token } from "../../parser-state";
2
+ import { type TextRange } from "../../types";
2
3
  import { HpsgClauseContext } from "../rule-context";
3
- import { HpsgLexicalRule } from "../signature";
4
+ import { HpsgLexicalRule, HpsgSign } from "../signature";
4
5
  export declare function startsMaximumCountLead(context: HpsgClauseContext, start: number): boolean;
5
6
  export declare function symptomAdjustmentLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
6
7
  export declare function matchContextualPrnReasonLead(context: HpsgClauseContext, start: number): {
@@ -11,4 +12,14 @@ export declare function matchContextualPrnReasonLead(context: HpsgClauseContext,
11
12
  export declare function tokenBelongsToContextualPrnReasonLead(context: HpsgClauseContext, tokenIndex: number): boolean;
12
13
  export declare function hasSymptomOnsetPrnAt(context: HpsgClauseContext, start: number): boolean;
13
14
  export declare function symptomOnsetPrnRule(): HpsgLexicalRule<HpsgClauseContext>;
15
+ /** Offer an established indication before the conditional target is selected. */
16
+ export declare function hasKnownPrnNominalBefore(context: HpsgClauseContext, start: number, boundary: number): boolean;
17
+ /** Existing maximum-boundary callers use the same complete nominal proof. */
18
+ export declare const prnEndsBeforeMaximum: typeof hasKnownPrnNominalBefore;
19
+ /** A complete indication owns an internal unresolved nominal before generic
20
+ * action fallback. Conditional leads additionally need an established symptom
21
+ * focus; an explicit PRN lead may retain authored unknown indications. */
22
+ export declare function prnNominalOwnsOpaqueRange(context: HpsgClauseContext, start: number, range: TextRange): number | undefined;
23
+ /** Share final PRN admission without promoting nominal boundary evidence. */
24
+ export declare function prnAt(context: HpsgClauseContext, start: number): HpsgSign[];
14
25
  export declare function prnLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
@@ -1,4 +1,13 @@
1
1
  import { HpsgClauseContext } from "../rule-context";
2
2
  import { HpsgLexicalRule } from "../signature";
3
- export declare function siteLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
3
+ /** Opaque-source admission defers to the same relative-site daughters as the chart. */
4
+ export declare function siteRelativeHasSign(context: HpsgClauseContext, start: number): boolean;
5
+ /** An explicit selected argument governor owns its site constituent. Without
6
+ * one, procedure-owned anatomy cannot become the medication site. */
7
+ export declare function siteLexicalRule(governorStart?: number): HpsgLexicalRule<HpsgClauseContext>;
8
+ /** Instruction fallback defers to the same typed site sign used by the chart.
9
+ * This bounded lexical lookahead does not enter chart selection or reparse actions. */
10
+ export declare function siteModifierHasSign(context: HpsgClauseContext, start: number): boolean;
11
+ /** Share the actual selected nominal owner with adjacent opaque-source admission. */
12
+ export declare function bareSiteHasSign(context: HpsgClauseContext, start: number): boolean;
4
13
  export declare function bareSiteLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
@@ -1,18 +1,9 @@
1
+ import { type QuantityLexicalContext } from "../quantity-lexicon";
1
2
  import { Token } from "../../parser-state";
2
- import { type AdviceFrame, type CanonicalCalendarEventExpr, type FhirQuantity, type ParseOptions } from "../../types";
3
- import { HpsgClauseContext } from "../rule-context";
3
+ import { type AdviceFrame, AdviceRelation, EventTiming, FhirDayOfWeek, FhirPeriodUnit, type CanonicalCalendarEventExpr, type CanonicalAdditionalInstructionExpr, type FhirQuantity, type ParseOptions } from "../../types";
4
+ import { HpsgClauseContext, maximumCountLeadAt, maximumDosePerPeriodAt, maximumDosePeriodAt, clinicalDurationAt } from "../rule-context";
4
5
  import { HpsgLexicalRule, HpsgSign } from "../signature";
5
- /** Bounded lexical constituent for a fronted following treatment course.
6
- * The planner reuses its source extent; duration semantics remain owned by
7
- * the ordinary duration lexical rule.
8
- * @param tokens Source lexical tokens.
9
- * @param start Candidate duration-lead index.
10
- */
11
- export declare function followingCourseDurationHeaderAt(tokens: readonly Token[], start: number): {
12
- valueIndex: number;
13
- tokenEnd: number;
14
- implicitSingle?: boolean;
15
- } | undefined;
6
+ export { followingCourseDurationHeaderAt } from "../timing-lexicon";
16
7
  export interface OrdinalWeekStageHeader {
17
8
  tokenStart: number;
18
9
  tokenEnd: number;
@@ -30,9 +21,36 @@ export declare function ordinalWeekStageHeaderAt(tokens: readonly Token[], start
30
21
  export declare function ordinalWeekStageHeaders(tokens: readonly Token[]): OrdinalWeekStageHeader[];
31
22
  /** A regimen-stage construction requires at least Week 1 + Week 2. */
32
23
  export declare function ordinalWeekStageSequence(tokens: readonly Token[]): OrdinalWeekStageHeader[];
24
+ export declare function monthlyOrdinalWeekdayParts(context: HpsgClauseContext, start: number): {
25
+ members: Token[];
26
+ weekday: FhirDayOfWeek;
27
+ ordinal: 1 | 2 | 3 | 4 | -1;
28
+ } | undefined;
33
29
  export declare function multiplicativeDoseFrequencyRule(): HpsgLexicalRule<HpsgClauseContext>;
34
30
  export declare function compactIntervalRule(): HpsgLexicalRule<HpsgClauseContext>;
35
31
  export declare function separatedIntervalRule(): HpsgLexicalRule<HpsgClauseContext>;
32
+ /** One complete occurrence maximum is shared by the schedule chart and guard scope. */
33
+ export declare function maximumOccurrenceAt(context: Parameters<typeof maximumCountLeadAt>[0], start: number, lead?: {
34
+ tokens: Token[];
35
+ headStart: number;
36
+ comparative: boolean;
37
+ } | undefined): {
38
+ tokens: Token[];
39
+ headStart: number;
40
+ count: number;
41
+ occurrenceScope: "generic" | "medication";
42
+ comparative: boolean;
43
+ period?: NonNullable<ReturnType<typeof maximumDosePeriodAt>>;
44
+ } | undefined;
45
+ /** Evidence from the selected final predicate, without reparsing its text.
46
+ * An ordinary condition can still take an episode count; a measurement or
47
+ * lexical PRN condition has already supplied its complete complement. */
48
+ export type MaximumPredicateScope = "unresolved" | "condition" | "measurement" | "prn";
49
+ /** A comparative maximum needs a complete preceding predicate and its own
50
+ * complete daughter. A conjunction alone cannot detach a count prefix from
51
+ * an opaque Boolean predicate. Explicit separators/maximum heads retain their
52
+ * independent instruction license. */
53
+ export declare function isIndependentMaximum(context: Parameters<typeof maximumCountLeadAt>[0], start: number, maximum: NonNullable<ReturnType<typeof maximumOccurrenceAt> | ReturnType<typeof maximumDosePerPeriodAt>>, predicateScope?: MaximumPredicateScope, endSource?: number): boolean;
36
54
  export declare function separatedFrequencyRangeRule(): HpsgLexicalRule<HpsgClauseContext>;
37
55
  /**
38
56
  * A distributive cadence followed directly by a discrete unit licenses an
@@ -40,18 +58,86 @@ export declare function separatedFrequencyRangeRule(): HpsgLexicalRule<HpsgClaus
40
58
  * than globally treating every bare unit as one dose.
41
59
  */
42
60
  export declare function cadenceFirstImplicitSingleDoseRule(): HpsgLexicalRule<HpsgClauseContext>;
43
- /**
44
- * Parses languages and clinical shorthand that place the cadence adverb before
45
- * the count, e.g. `daily 2 times`. Thai `วันละ 2 ครั้ง` is normalized by the
46
- * locale lexer to exactly this feature sequence, without pretending Thai has
47
- * English word order.
48
- */
49
61
  export declare function cadenceFirstFrequencyRule(): HpsgLexicalRule<HpsgClauseContext>;
50
62
  export declare function singleOccurrencePhraseRule(): HpsgLexicalRule<HpsgClauseContext>;
63
+ /** Complete declared cardinal/cadence nominal, shared with local action
64
+ * boundaries. HPSG's contextual ownership guards remain at its lexical rule. */
65
+ export declare function countFrequencyNominalAt(context: QuantityLexicalContext, start: number): HpsgSign | undefined;
66
+ /** Complete recurrence morphology shared with action-valence boundaries.
67
+ * The lexical productions below still own the schedule meaning and evidence. */
68
+ export declare function cadenceNominalEnd(context: QuantityLexicalContext, start: number): number | undefined;
51
69
  export declare function countFrequencyRule(): HpsgLexicalRule<HpsgClauseContext>;
52
70
  export declare function alternateEventCadenceRule(): HpsgLexicalRule<HpsgClauseContext>;
53
71
  export declare function calendarDateListRule(): HpsgLexicalRule<HpsgClauseContext>;
54
72
  export declare function timingLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
73
+ /** The same relation-selected event owns bare, immediate, and quantified
74
+ * timing constituents. Sleep and wake keep their established lexical aliases. */
75
+ export declare function relatedEventTimingExpression(parts: readonly string[], relation: "before" | "after" | "with"): {
76
+ timing: EventTiming;
77
+ length: number;
78
+ } | undefined;
79
+ interface QualifiedEventAdvice {
80
+ start: number;
81
+ end: number;
82
+ frame?: AdviceFrame;
83
+ alternative?: true;
84
+ registeredInstruction?: CanonicalAdditionalInstructionExpr;
85
+ }
86
+ /** A selected MealState owns its complete nominal before a contained generic
87
+ * event. Reuse the selected argument's provider and occurrence proof; unheaded
88
+ * stock compounds keep their existing lexical fallback. */
89
+ export declare function qualifiedEventAdviceAt(context: HpsgClauseContext, index: number): QualifiedEventAdvice | undefined;
90
+ interface CoordinatedRelatedEvents {
91
+ timings: EventTiming[];
92
+ members: Token[];
93
+ next: number;
94
+ }
95
+ /**
96
+ * Compose a relation-scoped list of event daughters. English commonly names
97
+ * every meal (`breakfast, lunch and dinner`), while Thai commonly shares the
98
+ * nominal head (`อาหารเช้า กลางวัน และเย็น`). Both are the same typed list;
99
+ * disjunction remains outside this conjunctive construction.
100
+ */
101
+ export declare function coordinatedRelatedEventsAt(context: QuantityLexicalContext, start: number, relation: "before" | "after" | "with", measuredOffset?: boolean): CoordinatedRelatedEvents | undefined;
102
+ type EventOffsetQuantity = {
103
+ value: number;
104
+ unit: FhirPeriodUnit;
105
+ bound: "minimum" | "maximum" | undefined;
106
+ next: number;
107
+ comparator?: NonNullable<ReturnType<typeof clinicalDurationAt>>["comparator"];
108
+ ranged?: boolean;
109
+ minutes?: number;
110
+ };
111
+ export declare function eventOffsetQuantityAt(context: QuantityLexicalContext, start: number): EventOffsetQuantity | undefined;
112
+ export declare function semanticActivityWindowAt(context: QuantityLexicalContext, start: number, includeRegisteredActivity?: boolean): {
113
+ definition: {
114
+ parts: string[];
115
+ text: string;
116
+ offsetOnly: boolean;
117
+ i18n: {
118
+ th: string;
119
+ } | undefined;
120
+ relation: "before" | "after" | undefined;
121
+ activity: string | undefined;
122
+ eventWindow: {
123
+ start: EventTiming;
124
+ end: EventTiming;
125
+ } | undefined;
126
+ };
127
+ tokens: Token[];
128
+ relation: "before" | "after";
129
+ activity: undefined;
130
+ } | {
131
+ definition: undefined;
132
+ tokens: Token[];
133
+ relation: AdviceRelation.Before | AdviceRelation.After;
134
+ activity: {
135
+ length: number;
136
+ display: string;
137
+ i18n?: Record<string, string>;
138
+ coding?: import("../../types").FhirCoding;
139
+ } | undefined;
140
+ } | undefined;
55
141
  export declare function quantityFirstActivityTimingRule(): HpsgLexicalRule<HpsgClauseContext>;
56
142
  export declare function quantityFirstEventOffsetRule(): HpsgLexicalRule<HpsgClauseContext>;
57
143
  /**
@@ -67,6 +153,13 @@ export declare function eventTimingPhraseRule(): HpsgLexicalRule<HpsgClauseConte
67
153
  * @returns A lexical rule yielding typed calendar-day membership.
68
154
  */
69
155
  export declare function monthlyDayOfMonthLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
156
+ /** Conjunction and juxtaposition compose already registered weekday atoms.
157
+ * An authored disjunction remains a choice, not a set of excluded days. */
158
+ export declare function weekdayNominalAt(context: QuantityLexicalContext, start: number): {
159
+ end: number;
160
+ dayOfWeek: FhirDayOfWeek[];
161
+ alternative: boolean;
162
+ } | undefined;
70
163
  export declare function dayRangeLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
71
164
  /**
72
165
  * A maximum medication quantity is a typed schedule adjunct, not another
@@ -105,10 +198,11 @@ export interface HpsgRecurringCourseConstituent {
105
198
  /** Cheap lexical activation only; the course construction must still compose. */
106
199
  export declare function hasRecurringCourseCue(tokens: readonly Token[], options?: ParseOptions): boolean;
107
200
  /** A registered withholding head selects one complete finite duration NP.
108
- * Objects such as breath, conditional tails, and negative directives cannot
109
- * satisfy this medication-pause valence. Both daughters remain in the chart. */
201
+ * Selected Duration arguments retain their registered head/complement order;
202
+ * objects, conditional tails, and negative directives are not medication pauses. */
110
203
  export declare function finiteTreatmentPauseAt(context: HpsgClauseContext, frame: AdviceFrame, start: number): {
111
- actionEnd: number;
204
+ headTokens: Token[];
205
+ headSide: "left" | "right";
112
206
  duration: HpsgSign;
113
207
  pause: {
114
208
  durationDays: number;
@@ -1,4 +1,3 @@
1
- import { ParseOptions } from "../types";
2
1
  export interface HpsgSigSegment {
3
2
  text: string;
4
3
  start: number;
@@ -6,4 +5,5 @@ export interface HpsgSigSegment {
6
5
  /** A trailing duration on the next heterogeneous dose applies to this sibling too. */
7
6
  inheritTrailingDurationFromNext?: boolean;
8
7
  }
9
- export declare function parseSigSegments(input: string, options?: ParseOptions): HpsgSigSegment[];
8
+ /** Compatibility segment view; the production boundary planner owns segmentation. */
9
+ export { parseSigSegments } from "../regimen/planner";