ezmedicationinput 0.1.67 → 0.3.0-beta.1

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 (69) hide show
  1. package/README.md +222 -28
  2. package/dist/adapters/canonical-course.d.ts +128 -0
  3. package/dist/adapters/r5-course.d.ts +24 -0
  4. package/dist/advice.d.ts +52 -1
  5. package/dist/body-site-grammar.d.ts +34 -1
  6. package/dist/body-site-lookup.d.ts +3 -0
  7. package/dist/body-site-spatial.d.ts +6 -2
  8. package/dist/body-site-target.d.ts +9 -3
  9. package/dist/canonical/compile.d.ts +79 -0
  10. package/dist/canonical/course.d.ts +352 -0
  11. package/dist/canonical/format-course.d.ts +36 -0
  12. package/dist/date-interpretation.d.ts +2 -0
  13. package/dist/dosage-course.d.ts +453 -0
  14. package/dist/execution/calendar.d.ts +107 -0
  15. package/dist/execution/engine.d.ts +11 -0
  16. package/dist/fhir-quantity-operator.d.ts +53 -0
  17. package/dist/fhir-translations.d.ts +5 -6
  18. package/dist/fhir.d.ts +233 -13
  19. package/dist/format.d.ts +113 -3
  20. package/dist/hpsg/constructions.d.ts +113 -0
  21. package/dist/hpsg/defaults.d.ts +2 -0
  22. package/dist/hpsg/lexical-classes.d.ts +282 -2
  23. package/dist/hpsg/procedural-context.d.ts +18 -4
  24. package/dist/hpsg/projection.d.ts +38 -3
  25. package/dist/hpsg/rule-context.d.ts +117 -7
  26. package/dist/hpsg/rules/clinical-quantity-rules.d.ts +18 -0
  27. package/dist/hpsg/rules/condition-rules.d.ts +14 -0
  28. package/dist/hpsg/rules/core-rules.d.ts +32 -0
  29. package/dist/hpsg/rules/instruction-rules.d.ts +11 -1
  30. package/dist/hpsg/rules/prn-rules.d.ts +3 -1
  31. package/dist/hpsg/rules/timing-rules.d.ts +138 -8
  32. package/dist/hpsg/signature.d.ts +353 -5
  33. package/dist/hpsg/type-system.d.ts +16 -1
  34. package/dist/hpsg/unification.d.ts +4 -1
  35. package/dist/i18n.d.ts +39 -1
  36. package/dist/index.cjs +65539 -30893
  37. package/dist/index.d.ts +35 -7
  38. package/dist/index.js +65505 -30892
  39. package/dist/instruction-action-locale-adapter.d.ts +32 -3
  40. package/dist/instruction-action-terminology.d.ts +38 -3
  41. package/dist/instruction-concept-terminology.d.ts +8 -1
  42. package/dist/instruction-graph-fhir.d.ts +9 -3
  43. package/dist/instruction-graph.d.ts +85 -7
  44. package/dist/ir.d.ts +13 -2
  45. package/dist/lexer/surface-segmenter.d.ts +1 -1
  46. package/dist/lexer/surface.d.ts +1 -0
  47. package/dist/locale-detection.d.ts +3 -0
  48. package/dist/locales/course/en.d.ts +15 -0
  49. package/dist/locales/course/th.d.ts +12 -0
  50. package/dist/localization.d.ts +73 -0
  51. package/dist/maps.d.ts +24 -1
  52. package/dist/medication-condition.d.ts +42 -0
  53. package/dist/parser-state.d.ts +6 -2
  54. package/dist/parser.d.ts +5 -2
  55. package/dist/regimen/coordination-scope.d.ts +53 -0
  56. package/dist/regimen/grammar.d.ts +79 -0
  57. package/dist/regimen/parallel-course.d.ts +52 -0
  58. package/dist/regimen/planner.d.ts +19 -0
  59. package/dist/regimen/regimen.d.ts +70 -0
  60. package/dist/relation-terminology.d.ts +1 -0
  61. package/dist/schedule.d.ts +12 -5
  62. package/dist/stable-structure.d.ts +23 -1
  63. package/dist/timing-summary.d.ts +82 -1
  64. package/dist/types.d.ts +899 -40
  65. package/dist/unit-lexicon.d.ts +7 -0
  66. package/dist/utils/strength.d.ts +16 -0
  67. package/dist/utils/text.d.ts +3 -0
  68. package/dist/utils/units.d.ts +19 -0
  69. package/package.json +3 -2
@@ -1,5 +1,10 @@
1
- import { AdviceModality, AdvicePolarity, EventTiming } from "../types";
1
+ import { type LexToken } from "../lexer/token-types";
2
+ import { AdviceForce, AdviceModality, AdvicePolarity, AdviceRelation, EventTiming, FhirDayOfWeek, FhirPeriodUnit, type FhirPrimitiveElement } from "../types";
2
3
  export { ACTION_SEQUENCE_MARKERS } from "../relation-terminology";
4
+ type MaximumPeriodPreposition = {
5
+ unitDenominator?: boolean;
6
+ rolling?: boolean;
7
+ };
3
8
  type MealRelation = "before" | "after" | "with";
4
9
  type MealTimingByRelation = Map<MealRelation, Map<EventTiming, EventTiming>>;
5
10
  type BodySiteFeatureKind = "nominal" | "partitive" | "locative";
@@ -8,6 +13,19 @@ type ContextualPrnReasonLead = {
8
13
  canonical: string;
9
14
  requiresKnownReason?: boolean;
10
15
  };
16
+ export type SiteRelativeMarkerLexeme = {
17
+ surface: string;
18
+ relation: "where";
19
+ };
20
+ export type SiteRestrictionPredicateIntroducer = {
21
+ parts: string[];
22
+ form: "existential";
23
+ };
24
+ export type SiteRestrictionPredicateLexeme = {
25
+ lemma: string;
26
+ form: "state";
27
+ i18n?: Record<string, string>;
28
+ };
11
29
  type CompoundDoseUnit = {
12
30
  head: string;
13
31
  tails: string[];
@@ -23,6 +41,11 @@ export type InstructionQuantityUnitLabel = {
23
41
  }>;
24
42
  };
25
43
  export declare const SITE_ANCHORS: Set<string>;
44
+ /** Clause markers and standalone qualifiers share the relation registry. */
45
+ export declare const SITE_RELATIVE_MARKERS: Map<string, SiteRelativeMarkerLexeme>;
46
+ export declare const SITE_RESTRICTION_PREDICATE_INTRODUCERS: SiteRestrictionPredicateIntroducer[];
47
+ export declare const SITE_RESTRICTION_PREDICATES: Map<string, SiteRestrictionPredicateLexeme>;
48
+ export declare const SITE_RESTRICTION_PREDICATES_BY_LEMMA: Map<string, SiteRestrictionPredicateLexeme>;
26
49
  export declare const SITE_SELF_DISPLAY_ANCHORS: Set<string>;
27
50
  export declare const SITE_FILLERS: Set<string>;
28
51
  export declare const BODY_SITE_PARTITIVE_HEADS: Set<string>;
@@ -68,24 +91,40 @@ export declare const PRN_DEFAULT_SITE_CONNECTOR: string;
68
91
  export declare const PRN_COMPACT_REASON_SEPARATORS: Set<string>;
69
92
  export declare const SITE_ROUTE_HINTS_ALLOWED_IN_GRAMMAR: Set<import("../types").SNOMEDCTRouteCodes>;
70
93
  export declare const PRODUCT_METHOD_REALIZATIONS: Record<string, Partial<Record<string, Record<string, string>>>>;
71
- export declare function productMethodRealizations(verb: string, product: string): Record<string, string> | undefined;
94
+ export declare function productMethodRealization(verb: string, product: string): {
95
+ text: string;
96
+ textElement?: FhirPrimitiveElement;
97
+ } | undefined;
72
98
  export declare const PRODUCT_FORM_MODIFIERS: Set<string>;
99
+ export declare const PRODUCT_SOURCE_PREPOSITIONS: Set<string>;
73
100
  export declare const COMPOUND_DOSE_UNITS: CompoundDoseUnit[];
101
+ export declare const QUALITATIVE_DOSE_MODIFIERS: Set<string>;
102
+ export declare const QUALITATIVE_DOSE_UNITS: Set<string>;
74
103
  export declare const IMPLICIT_SINGLE_DOSE_UNITS: Set<string>;
75
104
  export declare const PERCENT_BODY_AREA_UNITS: Map<string, string>;
76
105
  export declare const DOSE_FRACTION_WORDS: Map<string, number>;
77
106
  export declare const DOSE_FRACTION_DENOMINATOR_WORDS: Map<string, number>;
107
+ export declare const DOSE_ADDITIVE_QUANTITY_CONNECTORS: Set<string>;
108
+ export declare const DOSE_FRACTION_ARTICLES: Set<string>;
78
109
  export declare const DOSE_NUMBER_WORDS: Map<string, number>;
79
110
  export declare const DOSE_UNIT_CONNECTORS: Set<string>;
111
+ /** Calendar dayparts are not elapsed periods for rolling medication limits. */
112
+ export declare const DAYPART_INTERVAL_TOKENS: Set<string>;
80
113
  export declare const MILLION_DOSE_MULTIPLIER_TOKENS: Set<string>;
81
114
  export declare const SCHEDULE_UNIT_SEPARATOR_TOKENS: Set<string>;
82
115
  export declare const COMPACT_LIST_SEPARATORS: Set<string>;
83
116
  export declare const EVERY_INTERVAL_TOKENS_DATA: Set<string>;
84
117
  export declare const COUNT_MARKER_TOKENS_DATA: Set<string>;
85
118
  export declare const COUNT_CONNECTOR_WORDS_DATA: Set<string>;
119
+ /** Restrictive supplemental-quantity modifiers shared by dose and action NPs. */
120
+ export declare const SUPPLEMENTAL_DOSE_MODIFIERS: Set<string>;
86
121
  export declare const MAXIMUM_COUNT_LEAD_TOKENS: Set<string>;
87
122
  export declare const MAXIMUM_COUNT_LEAD_SEQUENCES: string[][];
123
+ export declare const MAXIMUM_COUNT_LEAD_FIRST_TOKENS: Set<string>;
88
124
  export declare const OCCURRENCE_COUNT_WORDS: Set<string>;
125
+ export declare const OCCURRENCE_COUNT_MODIFIERS: Set<string>;
126
+ export declare const MAXIMUM_PERIOD_PREPOSITIONS: Map<string, MaximumPeriodPreposition>;
127
+ export declare const MAXIMUM_PERIOD_MODIFIERS: Set<string>;
89
128
  export declare const OCCURRENCE_CAP_PERIOD_PHRASES: {
90
129
  parts: string[];
91
130
  period: number;
@@ -93,6 +132,69 @@ export declare const OCCURRENCE_CAP_PERIOD_PHRASES: {
93
132
  }[];
94
133
  export declare const FREQUENCY_SIMPLE_WORDS_DATA: Record<string, number>;
95
134
  export declare const FREQUENCY_NUMBER_WORDS_DATA: Record<string, number>;
135
+ /** Coded course-end events remain advisory until an actual bound is known. */
136
+ export declare const OPEN_ENDED_COURSE_END_CONDITIONS: ({
137
+ kind: string;
138
+ modifiers: string[];
139
+ heads: string[];
140
+ code: string;
141
+ display: string;
142
+ i18n: {
143
+ th: string;
144
+ };
145
+ subjects?: undefined;
146
+ predicates?: undefined;
147
+ } | {
148
+ kind: string;
149
+ subjects: string[];
150
+ predicates: string[];
151
+ code: string;
152
+ display: string;
153
+ i18n: {
154
+ th: string;
155
+ };
156
+ modifiers?: undefined;
157
+ heads?: undefined;
158
+ } | {
159
+ kind: string;
160
+ subjects: string[];
161
+ predicates: string[];
162
+ code: null;
163
+ display: string;
164
+ i18n: {
165
+ th: string;
166
+ };
167
+ modifiers?: undefined;
168
+ heads?: undefined;
169
+ })[];
170
+ /** Nominal quantifiers and event membership for typed medication-dose references. */
171
+ export declare const DOSE_TARGET_SLOT_HEADS: Set<string>;
172
+ export declare const DOSE_TARGET_QUANTIFIERS: Map<string, "all" | "both">;
173
+ /** Broad named dayparts can select a unique already stated clock, never invent one. */
174
+ export declare const DOSE_TARGET_DAYPART_CLOCK_RANGES: Map<EventTiming, {
175
+ startHour: number;
176
+ endHour: number;
177
+ }>;
178
+ /** Meridiem nominals select existing clock slots without asserting a meal time. */
179
+ export declare const DOSE_TARGET_MERIDIEM_CLOCK_RANGES: Map<string, {
180
+ startHour: number;
181
+ endHour: number;
182
+ }>;
183
+ export declare const DOSE_TARGET_EVENT_MEMBERS: Map<EventTiming, readonly EventTiming[]>;
184
+ export declare const CALENDAR_WEEKDAY_LEXEMES: {
185
+ day: FhirDayOfWeek;
186
+ patterns: RegExp[];
187
+ }[];
188
+ export declare const CALENDAR_WEEKDAY_GROUPS: {
189
+ pattern: RegExp;
190
+ days: FhirDayOfWeek[];
191
+ }[];
192
+ export declare const CALENDAR_DAY_LIST_CONNECTORS: RegExp;
193
+ export declare const CALENDAR_EXCLUSION_CUE: RegExp;
194
+ export declare const CALENDAR_EXCLUSION_DAY_HEADS: Set<string>;
195
+ export declare const CALENDAR_UNIVERSAL_DAY_QUANTIFIERS: Set<string>;
196
+ export declare const CALENDAR_COMPLEMENT_DAY_MODIFIERS: Set<string>;
197
+ export declare const CALENDAR_COMPLEMENT_DETERMINERS: Set<string>;
96
198
  export declare const FREQUENCY_TIMES_WORDS_DATA: Set<string>;
97
199
  export declare const FREQUENCY_CONNECTOR_WORDS_DATA: Set<string>;
98
200
  export declare const FREQUENCY_ALTERNATIVE_CONNECTORS: Set<string>;
@@ -101,26 +203,68 @@ export declare const FREQUENCY_ADVERB_UNITS_DATA: Map<string, string>;
101
203
  export declare const INTERVAL_UNIT_TOKENS_DATA: Map<string, string>;
102
204
  export declare const WORKFLOW_START_WORDS: Set<string>;
103
205
  export declare const WORKFLOW_NOUNS: Set<string>;
206
+ /** Finite event-phase verbs that complete a workflow temporal noun phrase. */
207
+ export declare const WORKFLOW_EVENT_PHASE_VERBS: Set<string>;
104
208
  export declare const ANTE_MERIDIEM_TOKENS: Set<string>;
105
209
  export declare const POST_MERIDIEM_TOKENS: Set<string>;
106
210
  export declare const MERIDIEM_TOKENS: Set<string>;
107
211
  export declare const LIST_SEPARATORS: Set<string>;
212
+ /** Thai daypart daughters license their compact conjunction punctuation.
213
+ * Numeric dose slots and non-Thai time ranges do not use this lexical sense.
214
+ */
215
+ export declare function isThaiDaypartListSeparator(separator: LexToken | undefined, left: LexToken | undefined, right: LexToken | undefined): boolean;
216
+ /** Existing rate-head surfaces retain their registered action valence. */
217
+ export declare const CLINICAL_RATE_ADMINISTRATION_HEADS: Map<string, string>;
108
218
  export declare const MEDICATION_OBJECT_FILLERS: Set<string>;
219
+ /** Typed resultative adjustment leads; the following cadence owns the new phase. */
220
+ export declare const PHASE_ADJUSTMENT_LEAD_SEQUENCES: string[][];
221
+ export declare const PHASE_ADDITION_LEAD_SEQUENCES: string[][];
222
+ /** Lexically marked reference to clock/event anchors of a preceding phase. */
223
+ export declare const TIMING_ANAPHORA_PHRASES: string[][];
109
224
  export declare const CLOCK_LEAD_TOKENS: Set<string>;
110
225
  export declare const EVENT_PREPOSITIONS: Set<string>;
111
226
  export declare const EVENT_ARTICLE_TOKENS: Set<string>;
227
+ export declare const INSTRUCTION_NOMINAL_ARTICLES: Set<string>;
112
228
  export declare const FIXED_EVENT_PHRASES: Map<string, EventTiming>;
113
229
  export declare const MEAL_RELATION_BY_TOKEN: Map<string, MealRelation>;
114
230
  export declare const MEAL_TIMING_BY_RELATION: MealTimingByRelation;
231
+ /** Realize the existing meal lexicon's instruction wording and translations.
232
+ * Typed qualification and offset scope remain with the HPSG construction. */
233
+ export declare function mealInstructionWording(events: readonly EventTiming[], sourceText: string): {
234
+ text: string;
235
+ i18n?: Record<string, string>;
236
+ };
115
237
  export declare const SLEEP_EVENT_ALIASES: Set<string>;
116
238
  export declare const WAKE_EVENT_ALIASES: Set<string>;
117
239
  export declare const FOOD_EVENT_ALIASES: Set<string>;
118
240
  export declare const DAY_RANGE_CONNECTORS: Set<string>;
241
+ /** Typed calendar-month day nouns; prefix + numeric range + monthly daughter. */
242
+ export declare const CALENDAR_MONTH_DAY_FRAMES: {
243
+ prefixes: string[][];
244
+ suffixes: string[][];
245
+ rangeConnectors: string[];
246
+ listConnectors: string[];
247
+ };
119
248
  export declare const RANGE_CONNECTORS: Set<string>;
120
249
  export declare const DURATION_LEAD_TOKENS: ReadonlySet<string>;
250
+ /** Complete compact interval token shared by grammar and timing preview.
251
+ * Consumers retain the existing unit admission and cadence normalization. */
252
+ export declare function compactIntervalParts(surface: string): {
253
+ period: number;
254
+ periodMax?: number;
255
+ unitSurface: string;
256
+ } | undefined;
257
+ /** Shared source-lexical reading of an unspaced headed duration NP.
258
+ * HPSG schedule and procedural action grammar consume the same daughter.
259
+ * No semantic meaning is assigned until each consumer licenses the unit. */
260
+ export declare function compactDurationParts(surface: string): {
261
+ value: number;
262
+ unitSurface: string;
263
+ } | undefined;
121
264
  export declare const EVENT_OFFSET_MINIMUM_LEAD_SEQUENCES: string[][];
122
265
  export declare const EVENT_OFFSET_MAXIMUM_LEAD_SEQUENCES: string[][];
123
266
  export declare const EVENT_OFFSET_FRACTIONS: Map<string, number>;
267
+ export declare const RELATIVE_INTERVAL_TRAILING_RELATIONS: Map<string, AdviceRelation>;
124
268
  export declare const EVENT_OFFSET_ARTICLES: Set<string>;
125
269
  export declare const INSTRUCTION_LEADING_SEPARATORS: Set<string>;
126
270
  export declare const INSTRUCTION_START_WORDS: Set<string>;
@@ -129,10 +273,35 @@ export declare const ACTION_DIRECTIVE_PREFIXES: {
129
273
  parts: readonly string[];
130
274
  polarity: AdvicePolarity | undefined;
131
275
  modality: AdviceModality | undefined;
276
+ force: AdviceForce | undefined;
277
+ complement: "contact-clause" | undefined;
132
278
  }[];
279
+ export declare const NEGATIVE_ACTION_DIRECTIVE_LEADS: Set<string>;
133
280
  export declare const ACTION_COORDINATION_CONNECTORS: Set<string>;
281
+ /** Closed-class contrast that connects two instructions, not a new action. */
282
+ export declare const ACTION_DISCOURSE_CONNECTORS: Set<string>;
283
+ /** Compositional phrasal sequencers; single-token THEN remains the relation lexicon's authority. */
284
+ export declare const TRAILING_PHASE_RELATION_ADVERBS: Set<string>;
285
+ export declare const REGIMEN_SEQUENCE_CONNECTOR_PHRASES: readonly (readonly string[])[];
286
+ export declare function sequenceConnectorEnd(tokens: readonly LexToken[], start: number): number | undefined;
287
+ /** Count nouns select whole treatment cycles rather than doses or days. */
288
+ export declare const CYCLE_COUNT_HEADS: Set<string>;
289
+ /** Cheap source-lexical gate for typed treatment-relative phase onsets. */
290
+ export declare const TREATMENT_PERIOD_START_LEADS: Set<string>;
291
+ export declare const RELATIVE_TIME_END_LEADS: Set<string>;
292
+ export declare const NEXT_DAY_MODIFIERS: Set<string>;
293
+ export declare const NEXT_DAY_HEADS: Set<string>;
294
+ export declare const NEXT_DAY_PREPOSITIONS: Set<string>;
295
+ export declare const NEXT_DAY_START_LEADS: Set<string>;
296
+ /** Typed derivation identity shared by lexical timing and phase composition. */
297
+ export declare const NEXT_DAY_SCHEDULE_RULE = "hpsg.lex.schedule.nextDay";
298
+ export declare const NEXT_DAY_ONSET_RULE = "hpsg.lex.schedule.nextDay.onset";
299
+ export declare function isNextDayScheduleRule(rule: string): boolean;
300
+ export declare const FIXED_CLOCK_DAYPART_QUALIFICATION_RULE = "hpsg.cx.schedule.fixed-clock-daypart-qualification";
134
301
  export declare const ACTION_COORDINATION_CONNECTOR_I18N: Record<string, Record<string, string>>;
302
+ export declare function coordinationConnectorKind(surface: string): "conjunction" | "disjunction" | "unknown";
135
303
  export declare const ACTION_SEQUENCE_RELATION_TOKENS: ReadonlySet<string>;
304
+ export declare const COURSE_DURATION_UNITS: Set<string>;
136
305
  export declare const INSTRUCTION_DURATION_UNITS: Map<string, string>;
137
306
  export declare const INSTRUCTION_DURATION_APPROXIMATION_LEADS: Set<string>;
138
307
  export declare const INSTRUCTION_QUANTITY_UNIT_LABELS: Map<string, InstructionQuantityUnitLabel>;
@@ -144,6 +313,18 @@ export declare const ALTERNATE_EVENT_CADENCES: {
144
313
  period: number;
145
314
  periodUnit: string;
146
315
  }[];
316
+ /** Day-membership adjuncts around registered activity nouns; never calendar inference. */
317
+ export declare const ACTIVITY_DAY_ADJUNCTS: {
318
+ negativeNounPrefixes: string[];
319
+ negativeNounTokens: string[];
320
+ dayRelativeTokens: string[];
321
+ dayTokens: string[];
322
+ frames: {
323
+ parts: string[];
324
+ dayFirst: boolean;
325
+ exclude: boolean;
326
+ }[];
327
+ };
147
328
  export declare const ADMINISTRATION_WINDOW_INSTRUCTIONS: {
148
329
  parts: string[];
149
330
  text: string;
@@ -153,6 +334,10 @@ export declare const ADMINISTRATION_WINDOW_INSTRUCTIONS: {
153
334
  } | undefined;
154
335
  relation: "before" | "after" | undefined;
155
336
  activity: string | undefined;
337
+ eventWindow: {
338
+ start: EventTiming;
339
+ end: EventTiming;
340
+ } | undefined;
156
341
  }[];
157
342
  export declare const SITE_TRAILING_INSTRUCTION_WORDS: Set<string>;
158
343
  export declare const WORKFLOW_CONTINUATION_LICENSES: Set<string>;
@@ -168,3 +353,98 @@ export declare const OCULAR_ROUTE_CODES: Set<import("../types").SNOMEDCTRouteCod
168
353
  export declare const HARD_SEGMENT_BOUNDARY_TOKENS: Set<string>;
169
354
  export declare const CLAUSE_LEAD_WORDS: Set<string>;
170
355
  export declare const LATERAL_MODIFIER_WORDS: Set<string>;
356
+ /** Explicit temporal construction vocabulary; no medication or specialty-specific dispatch. */
357
+ export declare const CYCLE_WORDS: {
358
+ name: string;
359
+ dayLead: string;
360
+ dayPart: string;
361
+ listSeparator: string;
362
+ periodLead: string;
363
+ periodUnit: string;
364
+ startLead: string;
365
+ repeatCount: string;
366
+ };
367
+ /** Declarative surface vocabulary for calendar-date relations for typed calendar constituents. */
368
+ export declare const TEMPORAL_DATE_RELATION_SOURCES: {
369
+ readonly startInclusive: string;
370
+ readonly startExclusive: string;
371
+ readonly endInclusive: string;
372
+ readonly endExclusive: string;
373
+ };
374
+ export declare const TEMPORAL_RELATION_LEAD_WORDS: Set<string>;
375
+ export declare const OPEN_ENDED_WORDS: Set<string>;
376
+ /** Resolve the duration-complement sense of a polysemous continuation head.
377
+ * A physical attachment still requires its object and is not licensed by this
378
+ * time-quantity valence. One source constituent is shared by action sense
379
+ * selection and the HPSG schedule lexicon, avoiding competing ownership.
380
+ * @param tokens Source-preserving normalized lexical tokens.
381
+ * @param start Candidate head; never searches later unrelated text.
382
+ * @param limit Exclusive constituent boundary.
383
+ * @returns Complete duration daughter, or undefined for an object/negated sense.
384
+ */
385
+ export declare function courseContinuationDurationAt(tokens: readonly Pick<LexToken, "lower" | "canonical" | "kind" | "value">[], start: number, limit?: number): {
386
+ end: number;
387
+ value: number;
388
+ unit: FhirPeriodUnit;
389
+ } | undefined;
390
+ /** One range daughter shared by ordinary doses and dimensional quantities. */
391
+ export declare function doseRangeNumberAt(tokens: readonly LexToken[], start: number, limit: number): {
392
+ range: {
393
+ low: number;
394
+ high: number;
395
+ };
396
+ numericIndex: number;
397
+ } | undefined;
398
+ /** Authored comparative dose NPs. Only complete number+medication-unit
399
+ * constituents are licensed; "about 3 weeks" stays temporal, and no
400
+ * second text-level dose parser runs after HPSG.
401
+ */
402
+ type DoseComparator = "<" | "<=" | ">" | ">=" | "~";
403
+ export declare const DOSE_COMPARATOR_PREFIXES: Map<string, {
404
+ words: readonly string[];
405
+ comparator: DoseComparator;
406
+ }[]>;
407
+ export declare const DOSE_COMPARATOR_SYMBOLS: Record<string, DoseComparator>;
408
+ /** Shared WHOLE + connector + optional article + fraction head. The
409
+ * caller still owns its medication unit; this cannot swallow two independently
410
+ * unit-bearing coordinated doses. Returns the last number token it owns. */
411
+ export declare function additiveDoseNumberAt(tokens: readonly LexToken[], start: number, limit: number, whole: number, allowMillion?: boolean): {
412
+ value: number;
413
+ numericIndex: number;
414
+ } | undefined;
415
+ /** A million is a numeric multiplier, never a medication unit.
416
+ * Shared by exact/comparative scalar and dimensional quantities. Source
417
+ * position advances past a separately spelled multiplier only when present. */
418
+ export declare function millionDoseNumberAt(tokens: readonly LexToken[], start: number, limit: number, value: number): {
419
+ value: number;
420
+ numericIndex: number;
421
+ } | undefined;
422
+ /** Numeric source token with an attached unit, e.g. 0.1mcg/kg.
423
+ * A prefix comparator is optional and remains owned by its outer lexeme.
424
+ * This is a bounded token form, never a second whole-SIG parser. */
425
+ export declare function attachedNumberUnitAt(lower: string): {
426
+ value: number;
427
+ rawUnit: string;
428
+ } | undefined;
429
+ /** A compact million suffix shares the attached-numeral decimal shape.
430
+ * The leading decimal point is numeric evidence, never punctuation. */
431
+ export declare function compactMillionDoseNumber(lower: string): number | undefined;
432
+ /** A denominator word belongs to the numeric head before its unit connector. */
433
+ export declare function fractionalDoseNumberAt(tokens: readonly LexToken[], start: number, limit: number, value: number, allowMillion?: boolean): {
434
+ value: number;
435
+ numericIndex: number;
436
+ } | undefined;
437
+ /** One bounded quantity-prefix lexeme shared by scalar and dimensional
438
+ * rules. It identifies source tokens; it does not assign a unit or dose.
439
+ * Duration daughters disable medication scaling so m remains their unit. */
440
+ export declare function doseComparatorNumberAt(tokens: readonly LexToken[], start: number, limit: number, lower: string, allowMillion?: boolean): {
441
+ comparator: "<" | "<=" | ">" | ">=" | "~";
442
+ value: number;
443
+ numericIndex: number;
444
+ rawUnit?: string;
445
+ } | undefined;
446
+ export declare function normalizeTokenLower(token: LexToken): string;
447
+ export declare function parseClockToken<T extends LexToken>(token: T | undefined, meridiemToken?: T | undefined): {
448
+ value: string;
449
+ tokens: T[];
450
+ } | undefined;
@@ -1,10 +1,24 @@
1
1
  import { type AdviceFrame } from "../types";
2
- import type { HpsgClauseContext } from "./rule-context";
2
+ import { type HpsgClauseContext } from "./rule-context";
3
3
  /**
4
4
  * Parse procedural semantics once per ParserState and share the result across
5
- * HPSG lexical constructions. Keeping this cache at the HPSG context layer
6
- * avoids each rule family independently running the instruction parser.
5
+ * HPSG lexical constructions and graph finalization. Keeping this cache in
6
+ * the HPSG context avoids independently parsing the same action program.
7
7
  */
8
- export declare function getProceduralFrames(context: HpsgClauseContext): AdviceFrame[];
8
+ export declare function getProceduralFrames(context: Pick<HpsgClauseContext, "state" | "options">): AdviceFrame[];
9
+ /** Existing action-sequence relation shared by condition closure and lexical ownership. */
10
+ export declare function instructionActionsAreSequenced(context: HpsgClauseContext, startSource: number, endSource: number): boolean;
11
+ /** Compose the consecutive action daughters selected by one fronted condition. */
12
+ export declare function proceduralInstructionProgram(context: HpsgClauseContext, firstTargetIndex: number, frames: AdviceFrame[]): AdviceFrame[];
13
+ /** Return the conditional's existing action owner, if it is advice rather
14
+ * than a newly quantified administration. */
15
+ export declare function conditionalAdviceOwnerAt(context: HpsgClauseContext, index: number): AdviceFrame | undefined;
16
+ /** Whether this existing action daughter is governed as conditional advice. */
17
+ export declare function isConditionalAdviceFrame(context: HpsgClauseContext, frame: AdviceFrame): boolean;
18
+ /** Resolve attachment for an already recognized temporal activity nominal.
19
+ * A fronted adjunct lies outside its following procedure's own action span. */
20
+ export declare function followingProcedureOwnsTemporalAdjunct(context: HpsgClauseContext, start: number, end: number): boolean;
9
21
  export type HpsgAttachmentClass = "administration" | "procedure";
10
22
  export declare function sourceRangeAttachmentClass(context: HpsgClauseContext, start: number, end: number): HpsgAttachmentClass;
23
+ /** A temporal linker between two complete action events is not an opaque condition. */
24
+ export declare function actionEventRelationAt(context: HpsgClauseContext, index: number): import("../types").AdviceRelation | undefined;
@@ -1,12 +1,47 @@
1
1
  import { ParserState, Token } from "../parser-state";
2
- import { EventTiming, FhirDayOfWeek, RouteCode } from "../types";
3
- import { HpsgSign } from "./signature";
2
+ import { EventTiming, FhirDayOfWeek, RouteCode, type CanonicalSigClause, type CanonicalSiteExpr, type CanonicalLexicalCategory, type CanonicalScheduleSemanticField } from "../types";
3
+ import { HpsgScheduleFeature, HpsgSign } from "./signature";
4
4
  export interface HpsgProjectionDeps {
5
5
  addDayOfWeekList: (state: ParserState, days: FhirDayOfWeek[]) => void;
6
6
  addWhen: (target: EventTiming[], whenCode: EventTiming) => void;
7
7
  markToken: (state: ParserState, token: Token) => void;
8
- recordEvidence: (state: ParserState, rule: string, startIndex: number, endIndex: number) => void;
8
+ recordEvidence: (state: ParserState, rule: string, startIndex: number, endIndex: number, scheduleFields?: CanonicalScheduleSemanticField[], lexicalCategory?: CanonicalLexicalCategory) => void;
9
9
  refreshMethodSurface: (state: ParserState) => void;
10
10
  setRoute: (state: ParserState, code: RouteCode, text?: string) => void;
11
11
  }
12
+ export declare function cloneSiteRestrictions(restrictions: NonNullable<HpsgSign["synsem"]["valence"]["site"]>["restrictions"]): {
13
+ range: {
14
+ start: number;
15
+ end: number;
16
+ } | undefined;
17
+ markerRange: {
18
+ start: number;
19
+ end: number;
20
+ } | undefined;
21
+ predicate: {
22
+ range: {
23
+ start: number;
24
+ end: number;
25
+ } | undefined;
26
+ text: string;
27
+ lemma?: string;
28
+ form: import("../types").BodySiteRestrictionPredicateForm;
29
+ focusText?: string;
30
+ };
31
+ relation: "where";
32
+ sourceText: string;
33
+ }[] | undefined;
34
+ export declare function hasRecurringSchedule(schedule: HpsgScheduleFeature | undefined, positionsRepeat?: boolean): boolean;
35
+ /** A single dated clock locates an elapsed administration; it does not
36
+ * supply a repeat cadence. Course bounds and independent recurrences retain
37
+ * their usual ownership of clock slots. */
38
+ export declare function hasRecurringAdministrationSchedule(schedule: HpsgScheduleFeature | undefined, positionsRepeat?: boolean): boolean;
12
39
  export declare function projectHpsgSignToState(sign: HpsgSign, state: ParserState, tokens: Token[], deps: HpsgProjectionDeps): void;
40
+ /**
41
+ * Return the FHIR projection alternatives licensed by the typed HPSG site
42
+ * coordination. A disjunction is deliberately one retained canonical clause;
43
+ * it is never converted into simultaneous administrations.
44
+ */
45
+ export declare function administrationTargetProjections(clauses: readonly CanonicalSigClause[]): Array<CanonicalSiteExpr | undefined>;
46
+ /** Pure pre-FHIR projection from one typed conjunction to one singular site. */
47
+ export declare function projectAdministrationTargetClauses(clauses: readonly CanonicalSigClause[], target: CanonicalSiteExpr | undefined): CanonicalSigClause[];
@@ -1,7 +1,9 @@
1
1
  import { Token, ParserState } from "../parser-state";
2
- import { ParseOptions } from "../types";
2
+ import { EventTiming, FhirPeriodUnit, ParseOptions } from "../types";
3
3
  import type { MedicationDateListMatch } from "../date-interpretation";
4
- import { HpsgLexicalRule } from "./signature";
4
+ import { type ParsedMedicationGuard } from "./constructions";
5
+ export { normalizeTokenLower, parseClockToken } from "./lexical-classes";
6
+ import { HpsgLexicalRule, HpsgSign } from "./signature";
5
7
  import { HpsgProjectionDeps } from "./projection";
6
8
  import { HpsgUnificationContext } from "./unification";
7
9
  export interface HpsgClauseContext {
@@ -11,19 +13,38 @@ export interface HpsgClauseContext {
11
13
  dateSpans: MedicationDateListMatch[];
12
14
  limit: number;
13
15
  deps: HpsgProjectionDeps & HpsgUnificationContext;
16
+ clinicalCache: {
17
+ /** Existing lexical matches requested early by instruction body lookahead. */
18
+ quantityLookahead?: Map<number, HpsgSign[]>;
19
+ /** PRN daughters requested early by conditional target ownership. */
20
+ prnLookahead?: Map<number, HpsgSign[]>;
21
+ medicationGuardScanned?: true;
22
+ medicationGuard?: ParsedMedicationGuard;
23
+ /** Tokens owned by a complete dimensional quantity or cumulative limit.
24
+ * Numeric, site and advice fallbacks must not detach its daughters. */
25
+ quantityTokenIndices?: Set<number>;
26
+ /** A recognized per-time expression still owns its numeral when no rate
27
+ * head licenses it. Scalar-dose fallback must not detach that numeral. */
28
+ unlicensedRateTokenIndices?: Set<number>;
29
+ };
14
30
  project?: boolean;
15
31
  }
32
+ export declare function medicationGuardForContext(context: HpsgClauseContext): ParsedMedicationGuard | undefined;
33
+ /** A marker phrase owns each of its lexical tokens, including IF inside
34
+ * ONLY IF. Such a token cannot independently introduce a PRN phrase.
35
+ * @param context Shared cached typed guard producer.
36
+ * @param start Candidate lexical token index.
37
+ */
38
+ export declare function isMedicationGuardMarker(context: HpsgClauseContext, start: number): boolean;
39
+ export declare function startsMedicationGuard(context: HpsgClauseContext, start: number): boolean;
16
40
  export declare function sourceRangeOverlapsContextDate(context: HpsgClauseContext, start: number, end: number): boolean;
17
- export declare function normalizeTokenLower(token: Token): string;
18
41
  export declare function isPunctuation(lower: string): boolean;
42
+ /** The selected action lexicon licenses its elapsed-duration complement. */
43
+ export declare function precedingMethodOwnsAdministrationDuration(context: HpsgClauseContext, start: number, relation: string): boolean;
19
44
  export declare function isClockLikeLower(lower: string): boolean;
20
45
  export declare function isAmPmLower(lower: string): boolean;
21
46
  export declare function isAnteMeridiemLower(lower: string): boolean;
22
47
  export declare function isPostMeridiemLower(lower: string): boolean;
23
- export declare function parseClockToken(token: Token | undefined, meridiemToken?: Token | undefined): {
24
- value: string;
25
- tokens: Token[];
26
- } | undefined;
27
48
  export declare function tokensAvailable(context: HpsgClauseContext, start: number, span: number): Token[] | undefined;
28
49
  export declare function rangeFromTokens(tokens: Token[]): {
29
50
  start: number;
@@ -33,3 +54,92 @@ export declare function splitByLexicalSeparators(text: string, separators: Reado
33
54
  export declare function hasLexicalSeparator(text: string, separators: ReadonlySet<string>): boolean;
34
55
  export declare function joinTokenText(tokens: Token[]): string;
35
56
  export declare function lexicalRule(id: string, match: HpsgLexicalRule<HpsgClauseContext>["match"]): HpsgLexicalRule<HpsgClauseContext>;
57
+ interface QuantityLexicalContext {
58
+ tokens: Token[];
59
+ options?: ParseOptions;
60
+ limit?: number;
61
+ state?: Pick<ParserState, "consumed">;
62
+ clinicalCache?: HpsgClauseContext["clinicalCache"];
63
+ }
64
+ export declare function quantityTokenAvailable(context: QuantityLexicalContext, index: number): boolean;
65
+ export declare function doseNumberValue(token: Token | undefined): number | undefined;
66
+ /** Shared numeric-word inventory: clinical quantities and ordinary timing
67
+ * interpret the same lexical number daughters, without string special cases. */
68
+ export declare function clinicalDurationNumber(token: Token | undefined): number | undefined;
69
+ /** One elapsed-duration daughter shared by infusion amounts and dose-limit periods. */
70
+ export declare function clinicalDurationAt(context: QuantityLexicalContext, start: number): {
71
+ value: number;
72
+ unit: FhirPeriodUnit.Minute | FhirPeriodUnit.Hour | FhirPeriodUnit.Day | FhirPeriodUnit.Week | FhirPeriodUnit.Month;
73
+ unitSurface: string;
74
+ comparator: "<" | "<=" | ">=" | ">" | "~" | undefined;
75
+ end: number;
76
+ } | undefined;
77
+ /** One plain numeric daughter shared by active amounts, carrier volumes and limits. */
78
+ export declare function plainClinicalNumberAt(context: QuantityLexicalContext, start: number, initial?: number): {
79
+ value: number;
80
+ numericIndex: number;
81
+ mixed: boolean;
82
+ fractional: boolean;
83
+ } | undefined;
84
+ /** The optional article or partitive belongs to the following medication unit. */
85
+ export declare function doseUnitIndexAfter(context: QuantityLexicalContext, start: number): number | undefined;
86
+ export declare function directDoseUnitAfter(context: QuantityLexicalContext, start: number): {
87
+ unit: string;
88
+ end: number;
89
+ } | undefined;
90
+ /** The same lexical medication amount owns administration heads and dose caps. */
91
+ export declare function medicationAmountAt(context: QuantityLexicalContext, index: number): boolean;
92
+ export declare function hasPrecedingMedicationAmount(context: QuantityLexicalContext, before: number): boolean;
93
+ /** A maximum head owns its leading separators and coordinated attachment. */
94
+ export declare function maximumCountLeadAt(context: QuantityLexicalContext, start: number, firstLower?: string): {
95
+ tokens: Token[];
96
+ headStart: number;
97
+ } | undefined;
98
+ export declare function occurrenceCapPeriodAt(context: QuantityLexicalContext, start: number): {
99
+ tokens: Token[];
100
+ period: number;
101
+ periodUnit: FhirPeriodUnit;
102
+ } | undefined;
103
+ type MaximumDosePeriod = ({
104
+ tokens: Token[];
105
+ period: number;
106
+ periodUnit: FhirPeriodUnit;
107
+ } | {
108
+ tokens: Token[];
109
+ daypart: true;
110
+ }) & {
111
+ unitDenominator?: boolean;
112
+ rolling?: true;
113
+ };
114
+ /** The existing compact maximum denominator is shared by quantity and count nouns. */
115
+ export declare function compactMaximumPeriodAt(context: QuantityLexicalContext, unitIndex: number, unitSurface: string): {
116
+ unitSurface: string;
117
+ period: MaximumDosePeriod;
118
+ } | undefined;
119
+ export declare function maximumDosePeriodAt(context: QuantityLexicalContext, start: number): MaximumDosePeriod | undefined;
120
+ /** Shared lexical constituent: a dose limit owns both its amount and period. */
121
+ export declare function maximumDosePerPeriodAt(context: QuantityLexicalContext, start: number, maximumHead?: {
122
+ tokens: Token[];
123
+ headStart: number;
124
+ } | undefined): {
125
+ tokens: Token[];
126
+ amount: number;
127
+ unit: string;
128
+ period: MaximumDosePeriod;
129
+ headStart: number;
130
+ comparative: boolean;
131
+ } | undefined;
132
+ /** Numeric and locale-licensed named clocks share one end complement owner. */
133
+ export declare function courseEndClockAt(tokens: readonly Token[], start: number, limit?: number): {
134
+ tokens: Token[];
135
+ value?: string;
136
+ event?: EventTiming;
137
+ } | undefined;
138
+ /** A daypart inside UNTIL + NEXT is an end complement, not a recurring event. */
139
+ export declare function isEndBoundDaypartAt(tokens: readonly Token[], head: number): boolean;
140
+ /** Bounded NEXT + day/daypart nominal, with an optional locale article. */
141
+ export declare function nextDayOnsetAt(tokens: readonly Token[], start: number, limit: number): {
142
+ headIndex: number;
143
+ tokenEnd: number;
144
+ explicitStart: boolean;
145
+ } | undefined;
@@ -0,0 +1,18 @@
1
+ import { FhirPeriodUnit } from "../../types";
2
+ import { HpsgClauseContext } from "../rule-context";
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): {
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[];
18
+ export declare function clinicalQuantityLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
@@ -1,4 +1,18 @@
1
+ import { FhirDayOfWeek, ParseOptions } from "../../types";
2
+ import { MedicationDateListMatch } from "../../date-interpretation";
1
3
  import { HpsgClauseContext } from "../rule-context";
2
4
  import { HpsgConditionFeature, HpsgLexicalRule } from "../signature";
5
+ export interface CalendarExclusion {
6
+ start: number;
7
+ end: number;
8
+ excluded: FhirDayOfWeek[];
9
+ dates: string[];
10
+ }
11
+ export declare function containsCalendarExclusionCue(source: string): boolean;
12
+ /** 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
+ export declare function medicationGuardLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
15
+ export declare function weekdayComplementReferenceLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
16
+ export declare function calendarExclusionLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
3
17
  export declare function conditionLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
4
18
  export declare function getConditionFeatures(context: HpsgClauseContext): HpsgConditionFeature[];