ezmedicationinput 0.3.0-beta.1 → 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 (75) hide show
  1. package/README.md +17 -10
  2. package/dist/adapters/canonical-course.d.ts +7 -4
  3. package/dist/adapters/r5-course.d.ts +5 -2
  4. package/dist/advice-locale-adapter.d.ts +24 -0
  5. package/dist/advice.d.ts +39 -3
  6. package/dist/body-site-grammar.d.ts +21 -2
  7. package/dist/body-site-lookup.d.ts +6 -1
  8. package/dist/body-site-spatial.d.ts +7 -1
  9. package/dist/body-site-target.d.ts +32 -3
  10. package/dist/canonical/compile.d.ts +22 -3
  11. package/dist/canonical/course.d.ts +43 -7
  12. package/dist/canonical/format-course.d.ts +4 -2
  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 +26 -17
  16. package/dist/event-timing-expression.d.ts +26 -1
  17. package/dist/fhir-quantity-operator.d.ts +37 -1
  18. package/dist/fhir-translations.d.ts +1 -1
  19. package/dist/fhir.d.ts +24 -4
  20. package/dist/format.d.ts +23 -24
  21. package/dist/hpsg/constructions.d.ts +24 -5
  22. package/dist/hpsg/lexical-classes.d.ts +94 -33
  23. package/dist/hpsg/method-lexicon.d.ts +3 -0
  24. package/dist/hpsg/procedural-context.d.ts +46 -3
  25. package/dist/hpsg/projection.d.ts +7 -3
  26. package/dist/hpsg/quantity-lexicon.d.ts +51 -0
  27. package/dist/hpsg/rule-context.d.ts +101 -33
  28. package/dist/hpsg/rules/clinical-quantity-rules.d.ts +1 -1
  29. package/dist/hpsg/rules/condition-rules.d.ts +13 -2
  30. package/dist/hpsg/rules/core-rules.d.ts +5 -2
  31. package/dist/hpsg/rules/prn-rules.d.ts +10 -1
  32. package/dist/hpsg/rules/site-rules.d.ts +10 -1
  33. package/dist/hpsg/rules/timing-rules.d.ts +102 -24
  34. package/dist/hpsg/segmenter.d.ts +2 -2
  35. package/dist/hpsg/signature.d.ts +41 -4
  36. package/dist/hpsg/timing-lexicon.d.ts +18 -2
  37. package/dist/i18n.d.ts +7 -7
  38. package/dist/index.cjs +75606 -61766
  39. package/dist/index.d.ts +7 -2
  40. package/dist/index.js +75606 -61766
  41. package/dist/instruction-action-locale-adapter.d.ts +63 -4
  42. package/dist/instruction-action-parser.d.ts +43 -0
  43. package/dist/instruction-action-terminology.d.ts +22 -1
  44. package/dist/instruction-concept-terminology.d.ts +13 -1
  45. package/dist/instruction-graph-fhir.d.ts +4 -2
  46. package/dist/instruction-graph-ownership.d.ts +96 -0
  47. package/dist/instruction-graph.d.ts +19 -42
  48. package/dist/lexer/lex.d.ts +5 -1
  49. package/dist/lexer/locale.d.ts +14 -0
  50. package/dist/lexer/locales/en.d.ts +11 -0
  51. package/dist/lexer/surface.d.ts +3 -1
  52. package/dist/lexer/token-types.d.ts +6 -0
  53. package/dist/locale-detection.d.ts +4 -2
  54. package/dist/locales/clause/en.d.ts +14 -0
  55. package/dist/locales/course/en.d.ts +5 -0
  56. package/dist/localization.d.ts +3 -0
  57. package/dist/localized-timing.d.ts +1 -1
  58. package/dist/maps.d.ts +38 -12
  59. package/dist/medication-condition.d.ts +72 -11
  60. package/dist/parser-state.d.ts +10 -0
  61. package/dist/parser.d.ts +5 -3
  62. package/dist/prn.d.ts +13 -2
  63. package/dist/regimen/coordination-scope.d.ts +13 -1
  64. package/dist/regimen/grammar.d.ts +7 -1
  65. package/dist/regimen/parallel-course.d.ts +6 -2
  66. package/dist/regimen/planner.d.ts +2 -3
  67. package/dist/regimen/regimen.d.ts +2 -0
  68. package/dist/snomed.d.ts +3 -0
  69. package/dist/suggest-locale-adapter.d.ts +15 -0
  70. package/dist/symptom-terminology.d.ts +5 -1
  71. package/dist/timing-summary.d.ts +41 -9
  72. package/dist/types.d.ts +127 -15
  73. package/dist/unit-lexicon.d.ts +2 -6
  74. package/dist/utils/units.d.ts +3 -0
  75. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { type LexToken } from "../lexer/token-types";
2
- import { AdviceForce, AdviceModality, AdvicePolarity, AdviceRelation, EventTiming, FhirDayOfWeek, FhirPeriodUnit, type FhirPrimitiveElement } from "../types";
2
+ import { AdviceForce, AdviceModality, AdvicePolarity, AdviceRelation, EventTiming, FhirPeriodUnit, type FhirPrimitiveElement } from "../types";
3
3
  export { ACTION_SEQUENCE_MARKERS } from "../relation-terminology";
4
4
  type MaximumPeriodPreposition = {
5
5
  unitDenominator?: boolean;
@@ -54,6 +54,7 @@ export declare const BODY_SITE_PARTITIVE_CONNECTORS: Set<string>;
54
54
  export declare const BODY_SITE_BARE_NOMINAL_PREFIXES: Set<string>;
55
55
  export declare const BODY_SITE_BARE_NOMINAL_PREFIX_I18N: Record<string, Record<string, string>>;
56
56
  export declare const BODY_SITE_ATTRIBUTIVE_MODIFIERS: Set<string>;
57
+ export declare const BODY_SITE_POSTPOSITIVE_MODIFIERS: Set<string>;
57
58
  export declare const BODY_SITE_ATTRIBUTIVE_MODIFIER_I18N: Record<string, Record<string, string>>;
58
59
  export declare const OTIC_SITE_WORDS: Set<string>;
59
60
  export declare const OPHTHALMIC_SITE_WORDS: Set<string>;
@@ -66,6 +67,7 @@ export declare function methodAuxiliaryVerbsForLocale(locale: string): ReadonlyS
66
67
  export declare const COORDINATED_NOUN_METHOD_VERBS: Set<string>;
67
68
  export declare const METHOD_NOUN_LEFT_CONTEXT: Map<string, Set<string>>;
68
69
  export declare const PRODUCT_EXTERNAL_MODIFIERS: Set<string>;
70
+ export declare const ROUTE_GOVERNORS: Set<string>;
69
71
  export declare const ROUTE_SITE_PREPOSITIONS: Set<string>;
70
72
  export declare const SITE_DISPLAY_FILLERS: Set<string>;
71
73
  export declare const SITE_MULTIPLICITY_WORDS: Set<string>;
@@ -104,12 +106,21 @@ export declare const IMPLICIT_SINGLE_DOSE_UNITS: Set<string>;
104
106
  export declare const PERCENT_BODY_AREA_UNITS: Map<string, string>;
105
107
  export declare const DOSE_FRACTION_WORDS: Map<string, number>;
106
108
  export declare const DOSE_FRACTION_DENOMINATOR_WORDS: Map<string, number>;
109
+ export declare const DOSE_DIVISION_HEADS: Set<string>;
110
+ export declare const DOSE_DIVISION_CONNECTORS: Set<string>;
111
+ export declare const DOSE_DIVISION_MODIFIERS: Set<string>;
112
+ export declare const DOSE_DIVISION_PARTICIPLES: Set<string>;
113
+ export declare const DOSE_DIVISION_NOUNS: Set<string>;
107
114
  export declare const DOSE_ADDITIVE_QUANTITY_CONNECTORS: Set<string>;
108
115
  export declare const DOSE_FRACTION_ARTICLES: Set<string>;
109
116
  export declare const DOSE_NUMBER_WORDS: Map<string, number>;
110
117
  export declare const DOSE_UNIT_CONNECTORS: Set<string>;
111
118
  /** Calendar dayparts are not elapsed periods for rolling medication limits. */
112
- export declare const DAYPART_INTERVAL_TOKENS: Set<string>;
119
+ export declare const DAYPART_INTERVAL_TOKENS: Map<string, EventTiming>;
120
+ /** Elapsed runtime introducers for the existing infusion construction. */
121
+ export declare const INFUSION_DURATION_LEADS: Map<string, {
122
+ unheaded?: boolean;
123
+ }>;
113
124
  export declare const MILLION_DOSE_MULTIPLIER_TOKENS: Set<string>;
114
125
  export declare const SCHEDULE_UNIT_SEPARATOR_TOKENS: Set<string>;
115
126
  export declare const COMPACT_LIST_SEPARATORS: Set<string>;
@@ -135,15 +146,30 @@ export declare const FREQUENCY_NUMBER_WORDS_DATA: Record<string, number>;
135
146
  /** Coded course-end events remain advisory until an actual bound is known. */
136
147
  export declare const OPEN_ENDED_COURSE_END_CONDITIONS: ({
137
148
  kind: string;
149
+ nominals: string[];
138
150
  modifiers: string[];
139
151
  heads: string[];
140
152
  code: string;
141
153
  display: string;
142
154
  i18n: {
155
+ en: string;
143
156
  th: string;
144
157
  };
145
158
  subjects?: undefined;
146
159
  predicates?: undefined;
160
+ } | {
161
+ kind: string;
162
+ heads: string[];
163
+ display: string;
164
+ i18n: {
165
+ en: string;
166
+ th: string;
167
+ };
168
+ nominals?: undefined;
169
+ modifiers?: undefined;
170
+ code?: undefined;
171
+ subjects?: undefined;
172
+ predicates?: undefined;
147
173
  } | {
148
174
  kind: string;
149
175
  subjects: string[];
@@ -152,7 +178,9 @@ export declare const OPEN_ENDED_COURSE_END_CONDITIONS: ({
152
178
  display: string;
153
179
  i18n: {
154
180
  th: string;
181
+ en?: undefined;
155
182
  };
183
+ nominals?: undefined;
156
184
  modifiers?: undefined;
157
185
  heads?: undefined;
158
186
  } | {
@@ -163,11 +191,15 @@ export declare const OPEN_ENDED_COURSE_END_CONDITIONS: ({
163
191
  display: string;
164
192
  i18n: {
165
193
  th: string;
194
+ en?: undefined;
166
195
  };
196
+ nominals?: undefined;
167
197
  modifiers?: undefined;
168
198
  heads?: undefined;
169
199
  })[];
200
+ export declare const OPEN_ENDED_COURSE_END_LEADS: Set<string>;
170
201
  /** Nominal quantifiers and event membership for typed medication-dose references. */
202
+ export declare const DOSE_TARGET_NOMINAL_MODIFIERS: Set<string>;
171
203
  export declare const DOSE_TARGET_SLOT_HEADS: Set<string>;
172
204
  export declare const DOSE_TARGET_QUANTIFIERS: Map<string, "all" | "both">;
173
205
  /** Broad named dayparts can select a unique already stated clock, never invent one. */
@@ -175,22 +207,18 @@ export declare const DOSE_TARGET_DAYPART_CLOCK_RANGES: Map<EventTiming, {
175
207
  startHour: number;
176
208
  endHour: number;
177
209
  }>;
210
+ /** Select an existing clock within a named daypart, including one crossing midnight. */
211
+ export declare function clockHourInRange(hour: number, range: {
212
+ startHour: number;
213
+ endHour: number;
214
+ }): boolean;
178
215
  /** Meridiem nominals select existing clock slots without asserting a meal time. */
179
216
  export declare const DOSE_TARGET_MERIDIEM_CLOCK_RANGES: Map<string, {
180
217
  startHour: number;
181
218
  endHour: number;
182
219
  }>;
183
220
  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;
221
+ export declare const CALENDAR_EXCLUSION_TOKENS: Set<string>;
194
222
  export declare const CALENDAR_EXCLUSION_DAY_HEADS: Set<string>;
195
223
  export declare const CALENDAR_UNIVERSAL_DAY_QUANTIFIERS: Set<string>;
196
224
  export declare const CALENDAR_COMPLEMENT_DAY_MODIFIERS: Set<string>;
@@ -209,13 +237,15 @@ export declare const ANTE_MERIDIEM_TOKENS: Set<string>;
209
237
  export declare const POST_MERIDIEM_TOKENS: Set<string>;
210
238
  export declare const MERIDIEM_TOKENS: Set<string>;
211
239
  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;
240
+ /** Full clock lists share the existing spaced and compact list separators. */
241
+ export declare function isClockListSeparator(value: string): boolean;
242
+ /** Both typed event daughters must carry their provider's punctuation license. */
243
+ export declare function isCompactDaypartListSeparator(separator: LexToken | undefined, left: LexToken | undefined, right: LexToken | undefined): boolean;
216
244
  /** Existing rate-head surfaces retain their registered action valence. */
217
245
  export declare const CLINICAL_RATE_ADMINISTRATION_HEADS: Map<string, string>;
218
246
  export declare const MEDICATION_OBJECT_FILLERS: Set<string>;
247
+ export declare const MEDICATION_OBJECT_MODIFIERS: Set<string>;
248
+ export declare const COURSE_CONTINUATION_MODIFIERS: Set<string>;
219
249
  /** Typed resultative adjustment leads; the following cadence owns the new phase. */
220
250
  export declare const PHASE_ADJUSTMENT_LEAD_SEQUENCES: string[][];
221
251
  export declare const PHASE_ADDITION_LEAD_SEQUENCES: string[][];
@@ -246,7 +276,17 @@ export declare const CALENDAR_MONTH_DAY_FRAMES: {
246
276
  listConnectors: string[];
247
277
  };
248
278
  export declare const RANGE_CONNECTORS: Set<string>;
279
+ export declare const RANGE_HEAD_CONNECTORS: Map<string, string>;
249
280
  export declare const DURATION_LEAD_TOKENS: ReadonlySet<string>;
281
+ /** Temporal quantity governors bound their own nominal, independently of course admission. */
282
+ export declare const DURATION_ARGUMENT_LEAD_TOKENS: ReadonlySet<string>;
283
+ /** Compact count-per-period notation, distinct from a compound dose unit.
284
+ * Canonical lexer aliases and the schedule rule use this same lexical fact. */
285
+ export declare function compactFrequencyParts(surface: string): {
286
+ frequency: number;
287
+ frequencyMax?: number;
288
+ unitSurface: string;
289
+ } | undefined;
250
290
  /** Complete compact interval token shared by grammar and timing preview.
251
291
  * Consumers retain the existing unit admission and cadence normalization. */
252
292
  export declare function compactIntervalParts(surface: string): {
@@ -269,12 +309,25 @@ export declare const EVENT_OFFSET_ARTICLES: Set<string>;
269
309
  export declare const INSTRUCTION_LEADING_SEPARATORS: Set<string>;
270
310
  export declare const INSTRUCTION_START_WORDS: Set<string>;
271
311
  export declare const POSITIVE_DIRECTIVE_MARKERS: Set<string>;
312
+ export declare const ACTION_DIRECTIVE_SUBJECTS: Set<string>;
272
313
  export declare const ACTION_DIRECTIVE_PREFIXES: {
273
314
  parts: readonly string[];
274
315
  polarity: AdvicePolarity | undefined;
275
316
  modality: AdviceModality | undefined;
276
317
  force: AdviceForce | undefined;
277
- complement: "contact-clause" | undefined;
318
+ requiresDirectiveBoundary: boolean;
319
+ requiresCoordination: boolean;
320
+ complement: "activity" | "contact-clause" | undefined;
321
+ }[];
322
+ /** Additional negative prefixes are licensed only after an existing coordination connector. */
323
+ export declare const ACTION_COORDINATED_DIRECTIVE_PREFIXES: {
324
+ parts: readonly string[];
325
+ polarity: AdvicePolarity | undefined;
326
+ modality: AdviceModality | undefined;
327
+ force: AdviceForce | undefined;
328
+ requiresDirectiveBoundary: boolean;
329
+ requiresCoordination: boolean;
330
+ complement: "activity" | "contact-clause" | undefined;
278
331
  }[];
279
332
  export declare const NEGATIVE_ACTION_DIRECTIVE_LEADS: Set<string>;
280
333
  export declare const ACTION_COORDINATION_CONNECTORS: Set<string>;
@@ -296,6 +349,7 @@ export declare const NEXT_DAY_START_LEADS: Set<string>;
296
349
  /** Typed derivation identity shared by lexical timing and phase composition. */
297
350
  export declare const NEXT_DAY_SCHEDULE_RULE = "hpsg.lex.schedule.nextDay";
298
351
  export declare const NEXT_DAY_ONSET_RULE = "hpsg.lex.schedule.nextDay.onset";
352
+ export declare const PAIRED_REPEATED_DURATION_RULE = "hpsg.lex.schedule.duration.pairedRepeated";
299
353
  export declare function isNextDayScheduleRule(rule: string): boolean;
300
354
  export declare const FIXED_CLOCK_DAYPART_QUALIFICATION_RULE = "hpsg.cx.schedule.fixed-clock-daypart-qualification";
301
355
  export declare const ACTION_COORDINATION_CONNECTOR_I18N: Record<string, Record<string, string>>;
@@ -354,25 +408,19 @@ export declare const HARD_SEGMENT_BOUNDARY_TOKENS: Set<string>;
354
408
  export declare const CLAUSE_LEAD_WORDS: Set<string>;
355
409
  export declare const LATERAL_MODIFIER_WORDS: Set<string>;
356
410
  /** 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
411
  /** Declarative surface vocabulary for calendar-date relations for typed calendar constituents. */
368
412
  export declare const TEMPORAL_DATE_RELATION_SOURCES: {
369
- readonly startInclusive: string;
370
- readonly startExclusive: string;
371
- readonly endInclusive: string;
372
- readonly endExclusive: string;
413
+ startInclusive: string;
414
+ startExclusive: string;
415
+ endInclusive: string;
416
+ endExclusive: string;
373
417
  };
374
418
  export declare const TEMPORAL_RELATION_LEAD_WORDS: Set<string>;
375
- export declare const OPEN_ENDED_WORDS: Set<string>;
419
+ export declare const OPEN_ENDED_MARKERS: readonly {
420
+ parts: readonly string[];
421
+ requiresStartRelation?: boolean;
422
+ excludedPredecessors?: readonly string[];
423
+ }[];
376
424
  /** Resolve the duration-complement sense of a polysemous continuation head.
377
425
  * A physical attachment still requires its object and is not licensed by this
378
426
  * time-quantity valence. One source constituent is shared by action sense
@@ -388,7 +436,7 @@ export declare function courseContinuationDurationAt(tokens: readonly Pick<LexTo
388
436
  unit: FhirPeriodUnit;
389
437
  } | undefined;
390
438
  /** One range daughter shared by ordinary doses and dimensional quantities. */
391
- export declare function doseRangeNumberAt(tokens: readonly LexToken[], start: number, limit: number): {
439
+ export declare function doseRangeNumberAt(tokens: readonly LexToken[], start: number, limit: number, allowMillion?: boolean, wordValue?: (token: LexToken) => number | undefined): {
392
440
  range: {
393
441
  low: number;
394
442
  high: number;
@@ -437,6 +485,11 @@ export declare function fractionalDoseNumberAt(tokens: readonly LexToken[], star
437
485
  /** One bounded quantity-prefix lexeme shared by scalar and dimensional
438
486
  * rules. It identifies source tokens; it does not assign a unit or dose.
439
487
  * Duration daughters disable medication scaling so m remains their unit. */
488
+ /** Select the registered comparison prefix before its complete numeric daughter. */
489
+ export declare function doseComparatorPrefixAt(tokens: readonly LexToken[], start: number, limit: number, lower: string): {
490
+ comparator: "<" | "<=" | ">" | ">=" | "~";
491
+ numericIndex: number;
492
+ } | undefined;
440
493
  export declare function doseComparatorNumberAt(tokens: readonly LexToken[], start: number, limit: number, lower: string, allowMillion?: boolean): {
441
494
  comparator: "<" | "<=" | ">" | ">=" | "~";
442
495
  value: number;
@@ -448,3 +501,11 @@ export declare function parseClockToken<T extends LexToken>(token: T | undefined
448
501
  value: string;
449
502
  tokens: T[];
450
503
  } | undefined;
504
+ /** The existing clock grammar together with its registered unit suffix. */
505
+ export declare function parseClockAt<T extends LexToken>(tokens: readonly T[], start: number, limit?: number, consumed?: ReadonlySet<number>): {
506
+ value: string;
507
+ tokens: T[];
508
+ } | undefined;
509
+ export declare const BODY_SITE_SPATIAL_HEADS: Set<string>;
510
+ export declare const BODY_SITE_PARTITIVE_HEAD_LEMMAS: Readonly<Record<string, string>>;
511
+ export declare const BODY_SITE_ATTRIBUTIVE_LATERALITY: Map<string, string>;
@@ -1,4 +1,5 @@
1
1
  import { FhirCoding, MedicationInstructionActionDefinition, ParseOptions, RouteCode } from "../types";
2
+ import { type LexToken } from "../lexer/token-types";
2
3
  export type MethodAction = string;
3
4
  declare function cloneMethodCoding(coding: FhirCoding | undefined): FhirCoding | undefined;
4
5
  /**
@@ -10,6 +11,8 @@ export declare const METHOD_CODING_BY_ACTION: Record<string, FhirCoding>;
10
11
  export declare const METHOD_ACTIONS_WITHOUT_IMPLICIT_ROUTE: Set<string>;
11
12
  export declare const METHOD_ROUTE_OVERRIDE_BY_VERB: Partial<Record<string, RouteCode>>;
12
13
  export declare function resolveMedicationAdministrationMethod(surface: string, options?: ParseOptions): MedicationInstructionActionDefinition | undefined;
14
+ /** A licensed support head and method retain one complete source constituent. */
15
+ export declare function resolveCompoundMedicationMethod(lead: LexToken, following: LexToken | undefined, options?: ParseOptions, productComplement?: boolean): MedicationInstructionActionDefinition | undefined;
13
16
  export declare function isMedicationAdministrationMethod(surface: string, options?: ParseOptions): boolean;
14
17
  export declare function medicationAdministrationMethodCoding(surface: string, options?: ParseOptions): FhirCoding | undefined;
15
18
  export { cloneMethodCoding };
@@ -1,24 +1,67 @@
1
+ import { type InstructionActionProgram } from "../instruction-action-parser";
2
+ import { frameActionDefinition } from "../instruction-graph";
1
3
  import { type AdviceFrame } from "../types";
2
4
  import { type HpsgClauseContext } from "./rule-context";
5
+ type OpaqueSpans = NonNullable<InstructionActionProgram["opaqueSpans"]>;
6
+ type ProceduralProgram = InstructionActionProgram & {
7
+ frontedConditionSpans?: OpaqueSpans;
8
+ };
3
9
  /**
4
10
  * Parse procedural semantics once per ParserState and share the result across
5
11
  * HPSG lexical constructions and graph finalization. Keeping this cache in
6
12
  * the HPSG context avoids independently parsing the same action program.
7
13
  */
8
- export declare function getProceduralFrames(context: Pick<HpsgClauseContext, "state" | "options">): AdviceFrame[];
14
+ export declare function getProceduralActionProgram(context: Pick<HpsgClauseContext, "state" | "options" | "rawTokens">, plannedProgram?: InstructionActionProgram): ProceduralProgram;
15
+ /** Before chart admission, a complete typed PRN nominal can own source that
16
+ * generic action fallback left opaque. The remaining fronted conditions retain
17
+ * their full spans and the existing subset cache. */
18
+ export declare function resolveOpaquePrnNominals(context: HpsgClauseContext): ProceduralProgram;
19
+ export declare function getProceduralFrames(context: Pick<HpsgClauseContext, "state" | "options" | "rawTokens">): AdviceFrame[];
20
+ /** An explicitly sequenced undosed administration can select a measured
21
+ * preparation. Its material quantities and independently named use stay local. */
22
+ export declare function selectedPreparationAmount(context: Pick<HpsgClauseContext, "tokens" | "options">, frame: AdviceFrame, program: InstructionActionProgram): AdviceFrame["args"][number] | undefined;
23
+ type PreparedUseContext = HpsgClauseContext | Pick<HpsgClauseContext, "tokens" | "options">;
24
+ /** A selected undosed use consumes the previously measured preparation.
25
+ * Its Immediate is local when an independent recurrence, Time or PRN already
26
+ * licenses use; without those, the authored Immediate is executable. */
27
+ export declare function isPreparedMedicationUse(context: PreparedUseContext, frame: AdviceFrame, program: InstructionActionProgram): boolean;
28
+ /** Exact nominal source ownership. A medication noun in some other argument
29
+ * (e.g. an AFTER-taking activity) does not make the held object a drug dose. */
30
+ export declare function actionArgumentSpan(input: string, frame: AdviceFrame, argument: AdviceFrame["args"][number]): {
31
+ start: number;
32
+ end: number;
33
+ } | undefined;
9
34
  /** Existing action-sequence relation shared by condition closure and lexical ownership. */
10
35
  export declare function instructionActionsAreSequenced(context: HpsgClauseContext, startSource: number, endSource: number): boolean;
36
+ /** An independent typed maximum closes the same conditional source scope
37
+ * as a hard clause boundary. Incomplete and predicate-owned counts do not. */
38
+ export declare function hasConditionalAdviceBoundary(context: HpsgClauseContext, start: number, end: number, predicateEnd?: number, prnStart?: number): boolean;
11
39
  /** Compose the consecutive action daughters selected by one fronted condition. */
12
- export declare function proceduralInstructionProgram(context: HpsgClauseContext, firstTargetIndex: number, frames: AdviceFrame[]): AdviceFrame[];
40
+ export declare function proceduralInstructionProgram(context: HpsgClauseContext, firstTargetIndex: number, frames: AdviceFrame[], end?: number): AdviceFrame[];
41
+ /** A written dose outside an already selected action can supply an omitted
42
+ * administration head. The quantity rule remains its semantic owner. */
43
+ export declare function unownedDoseLexicalEnd(context: Pick<HpsgClauseContext, "tokens" | "options"> & {
44
+ limit?: number;
45
+ }, frames: readonly AdviceFrame[], start: number, limit?: number): number | undefined;
46
+ /** A measured procedure's independently selected cadence licenses exact
47
+ * elapsed coverage. Without that proof, retain ordinary primary selection.
48
+ * Methods with registered administration runtime keep their timing owner. */
49
+ export declare function localAdministrationDurationSpan(frame: AdviceFrame, definition: ReturnType<typeof frameActionDefinition>, program: InstructionActionProgram): import("../types").TextRange | undefined;
13
50
  /** Return the conditional's existing action owner, if it is advice rather
14
51
  * than a newly quantified administration. */
52
+ export declare function conditionalAdviceProgramAt(context: HpsgClauseContext, index: number): AdviceFrame[] | undefined;
53
+ export declare function hasSelectedProcedurePrn(context: HpsgClauseContext, index: number): boolean;
15
54
  export declare function conditionalAdviceOwnerAt(context: HpsgClauseContext, index: number): AdviceFrame | undefined;
16
55
  /** Whether this existing action daughter is governed as conditional advice. */
17
56
  export declare function isConditionalAdviceFrame(context: HpsgClauseContext, frame: AdviceFrame): boolean;
57
+ /** A complete Activity can be local to a prepared use. A leading
58
+ * Immediate can also close that use before its adjacent measured daughter. */
59
+ export declare function preparedUseOwnsActivity(context: HpsgClauseContext, start: number, end: number, measured?: boolean): boolean;
18
60
  /** Resolve attachment for an already recognized temporal activity nominal.
19
61
  * A fronted adjunct lies outside its following procedure's own action span. */
20
62
  export declare function followingProcedureOwnsTemporalAdjunct(context: HpsgClauseContext, start: number, end: number): boolean;
21
63
  export type HpsgAttachmentClass = "administration" | "procedure";
22
- export declare function sourceRangeAttachmentClass(context: HpsgClauseContext, start: number, end: number): HpsgAttachmentClass;
64
+ export declare function sourceRangeAttachmentClass(context: HpsgClauseContext, start: number, end: number, selectedNominal?: boolean, selectedPhaseOnset?: boolean, selectedSchedule?: boolean): HpsgAttachmentClass;
23
65
  /** A temporal linker between two complete action events is not an opaque condition. */
24
66
  export declare function actionEventRelationAt(context: HpsgClauseContext, index: number): import("../types").AdviceRelation | undefined;
67
+ export {};
@@ -32,16 +32,20 @@ export declare function cloneSiteRestrictions(restrictions: NonNullable<HpsgSign
32
32
  sourceText: string;
33
33
  }[] | undefined;
34
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. */
35
+ /** A single dated clock locates an elapsed administration, including its
36
+ * authored start date; it does not supply a repeat cadence. Independent
37
+ * cadence, course bounds and additional slots retain recurring ownership. */
38
38
  export declare function hasRecurringAdministrationSchedule(schedule: HpsgScheduleFeature | undefined, positionsRepeat?: boolean): boolean;
39
39
  export declare function projectHpsgSignToState(sign: HpsgSign, state: ParserState, tokens: Token[], deps: HpsgProjectionDeps): void;
40
+ /** The selected member of a retained source conjunction, without inferring a
41
+ * new target from coding, text, or a later rendering. */
42
+ export declare function selectedAdministrationTargetIndex(clause: CanonicalSigClause): number | undefined;
40
43
  /**
41
44
  * Return the FHIR projection alternatives licensed by the typed HPSG site
42
45
  * coordination. A disjunction is deliberately one retained canonical clause;
43
46
  * it is never converted into simultaneous administrations.
44
47
  */
48
+ export declare function unexpandedAdministrationTargets(clauses: readonly CanonicalSigClause[]): readonly CanonicalSiteExpr[] | undefined;
45
49
  export declare function administrationTargetProjections(clauses: readonly CanonicalSigClause[]): Array<CanonicalSiteExpr | undefined>;
46
50
  /** Pure pre-FHIR projection from one typed conjunction to one singular site. */
47
51
  export declare function projectAdministrationTargetClauses(clauses: readonly CanonicalSigClause[], target: CanonicalSiteExpr | undefined): CanonicalSigClause[];
@@ -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,7 +1,11 @@
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 { EventTiming, FhirPeriodUnit, 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";
8
+ import { MEAL_RELATION_BY_TOKEN } from "./lexical-classes";
5
9
  export { normalizeTokenLower, parseClockToken } from "./lexical-classes";
6
10
  import { HpsgLexicalRule, HpsgSign } from "./signature";
7
11
  import { HpsgProjectionDeps } from "./projection";
@@ -9,6 +13,8 @@ import { HpsgUnificationContext } from "./unification";
9
13
  export interface HpsgClauseContext {
10
14
  state: ParserState;
11
15
  tokens: Token[];
16
+ /** Completed lexical tokens for the same clause, before semantic annotation. */
17
+ rawTokens?: LexToken[];
12
18
  options?: ParseOptions;
13
19
  dateSpans: MedicationDateListMatch[];
14
20
  limit: number;
@@ -16,11 +22,22 @@ export interface HpsgClauseContext {
16
22
  clinicalCache: {
17
23
  /** Existing lexical matches requested early by instruction body lookahead. */
18
24
  quantityLookahead?: Map<number, HpsgSign[]>;
19
- /** PRN daughters requested early by conditional target ownership. */
25
+ /** PRN daughters after final conditional-owner admission. */
20
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[]>;
21
38
  medicationGuardScanned?: true;
22
39
  medicationGuard?: ParsedMedicationGuard;
23
- /** Tokens owned by a complete dimensional quantity or cumulative limit.
40
+ /** Tokens owned by a complete medication range, dimensional quantity or cumulative limit.
24
41
  * Numeric, site and advice fallbacks must not detach its daughters. */
25
42
  quantityTokenIndices?: Set<number>;
26
43
  /** A recognized per-time expression still owns its numeral when no rate
@@ -39,13 +56,54 @@ export declare function isMedicationGuardMarker(context: HpsgClauseContext, star
39
56
  export declare function startsMedicationGuard(context: HpsgClauseContext, start: number): boolean;
40
57
  export declare function sourceRangeOverlapsContextDate(context: HpsgClauseContext, start: number, end: number): boolean;
41
58
  export declare function isPunctuation(lower: string): boolean;
42
- /** The selected action lexicon licenses its elapsed-duration complement. */
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;
43
77
  export declare function precedingMethodOwnsAdministrationDuration(context: HpsgClauseContext, start: number, relation: string): boolean;
44
78
  export declare function isClockLikeLower(lower: string): boolean;
45
79
  export declare function isAmPmLower(lower: string): boolean;
46
80
  export declare function isAnteMeridiemLower(lower: string): boolean;
47
81
  export declare function isPostMeridiemLower(lower: string): boolean;
48
- export declare function tokensAvailable(context: HpsgClauseContext, start: number, span: number): Token[] | undefined;
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;
106
+ } | undefined;
49
107
  export declare function rangeFromTokens(tokens: Token[]): {
50
108
  start: number;
51
109
  end: number;
@@ -54,47 +112,50 @@ export declare function splitByLexicalSeparators(text: string, separators: Reado
54
112
  export declare function hasLexicalSeparator(text: string, separators: ReadonlySet<string>): boolean;
55
113
  export declare function joinTokenText(tokens: Token[]): string;
56
114
  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
115
  /** Shared numeric-word inventory: clinical quantities and ordinary timing
67
116
  * interpret the same lexical number daughters, without string special cases. */
68
117
  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): {
118
+ /** Seconds are an existing action duration, without broadening cadence units. */
119
+ declare function clinicalDurationUnit(surface: string): FhirPeriodUnit | undefined;
120
+ export interface ClinicalDurationMatch {
71
121
  value: number;
72
- unit: FhirPeriodUnit.Minute | FhirPeriodUnit.Hour | FhirPeriodUnit.Day | FhirPeriodUnit.Week | FhirPeriodUnit.Month;
122
+ maximum?: number;
123
+ unit: FhirPeriodUnit;
73
124
  unitSurface: string;
74
- comparator: "<" | "<=" | ">=" | ">" | "~" | undefined;
125
+ comparator?: CanonicalScheduleExpr["administrationDurationComparator"];
126
+ range?: CanonicalScheduleExpr["administrationDurationRange"];
75
127
  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): {
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): {
79
135
  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;
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
+ };
88
149
  end: number;
89
150
  } | 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
151
  /** A maximum head owns its leading separators and coordinated attachment. */
94
152
  export declare function maximumCountLeadAt(context: QuantityLexicalContext, start: number, firstLower?: string): {
95
153
  tokens: Token[];
96
154
  headStart: number;
155
+ comparative: boolean;
97
156
  } | undefined;
157
+ /** Maximum abbreviations share one optional trailing punctuation token. */
158
+ export declare function maximumCountValueIndex(context: QuantityLexicalContext, lead: NonNullable<ReturnType<typeof maximumCountLeadAt>>): number;
98
159
  export declare function occurrenceCapPeriodAt(context: QuantityLexicalContext, start: number): {
99
160
  tokens: Token[];
100
161
  period: number;
@@ -107,8 +168,12 @@ type MaximumDosePeriod = ({
107
168
  } | {
108
169
  tokens: Token[];
109
170
  daypart: true;
171
+ } | {
172
+ tokens: Token[];
173
+ administration: true;
110
174
  }) & {
111
175
  unitDenominator?: boolean;
176
+ numericWindow?: true;
112
177
  rolling?: true;
113
178
  };
114
179
  /** The existing compact maximum denominator is shared by quantity and count nouns. */
@@ -121,6 +186,7 @@ export declare function maximumDosePeriodAt(context: QuantityLexicalContext, sta
121
186
  export declare function maximumDosePerPeriodAt(context: QuantityLexicalContext, start: number, maximumHead?: {
122
187
  tokens: Token[];
123
188
  headStart: number;
189
+ comparative: boolean;
124
190
  } | undefined): {
125
191
  tokens: Token[];
126
192
  amount: number;
@@ -128,12 +194,14 @@ export declare function maximumDosePerPeriodAt(context: QuantityLexicalContext,
128
194
  period: MaximumDosePeriod;
129
195
  headStart: number;
130
196
  comparative: boolean;
197
+ rateDenominator: boolean;
131
198
  } | undefined;
132
199
  /** Numeric and locale-licensed named clocks share one end complement owner. */
133
- export declare function courseEndClockAt(tokens: readonly Token[], start: number, limit?: number): {
200
+ export declare function courseEndClockAt(tokens: readonly Token[], start: number, limit?: number, endLead?: Token): {
134
201
  tokens: Token[];
135
202
  value?: string;
136
203
  event?: EventTiming;
204
+ relation?: ReturnType<typeof MEAL_RELATION_BY_TOKEN.get>;
137
205
  } | undefined;
138
206
  /** A daypart inside UNTIL + NEXT is an end complement, not a recurring event. */
139
207
  export declare function isEndBoundDaypartAt(tokens: readonly Token[], head: number): boolean;