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
@@ -4,7 +4,7 @@ import { HpsgDimensionalQuantityTerm, HpsgLexicalRule, HpsgSign } from "../signa
4
4
  export declare function volumeOrMassTerm(value: number, raw: string): HpsgDimensionalQuantityTerm | undefined;
5
5
  export declare function clinicalRatePeriodUnit(raw: string): FhirPeriodUnit.Hour | FhirPeriodUnit.Minute | undefined;
6
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): {
7
+ export declare function clinicalRateHeadAt(context: HpsgClauseContext, phraseStart: number, end: number, allowPrecedingDose?: boolean, period?: number, routeIsRateHead?: boolean): {
8
8
  licensed: boolean;
9
9
  rateSpecific: boolean;
10
10
  marker: number | undefined;
@@ -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,9 +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;
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;
14
25
  export declare function medicationGuardLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
15
26
  export declare function weekdayComplementReferenceLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
16
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`;
@@ -1,4 +1,5 @@
1
1
  import { Token } from "../../parser-state";
2
+ import { type TextRange } from "../../types";
2
3
  import { HpsgClauseContext } from "../rule-context";
3
4
  import { HpsgLexicalRule, HpsgSign } from "../signature";
4
5
  export declare function startsMaximumCountLead(context: HpsgClauseContext, start: number): boolean;
@@ -11,6 +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>;
14
- /** Share a PRN daughter requested before chart admission by scope ownership. */
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. */
15
24
  export declare function prnAt(context: HpsgClauseContext, start: number): HpsgSign[];
16
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, maximumCountLeadAt, maximumDosePerPeriodAt, maximumDosePeriodAt } 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,6 +21,11 @@ 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>;
@@ -37,18 +33,24 @@ export declare function separatedIntervalRule(): HpsgLexicalRule<HpsgClauseConte
37
33
  export declare function maximumOccurrenceAt(context: Parameters<typeof maximumCountLeadAt>[0], start: number, lead?: {
38
34
  tokens: Token[];
39
35
  headStart: number;
36
+ comparative: boolean;
40
37
  } | undefined): {
41
38
  tokens: Token[];
42
39
  headStart: number;
43
40
  count: number;
44
- implicitOccurrence: boolean;
41
+ occurrenceScope: "generic" | "medication";
42
+ comparative: boolean;
45
43
  period?: NonNullable<ReturnType<typeof maximumDosePeriodAt>>;
46
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";
47
49
  /** A comparative maximum needs a complete preceding predicate and its own
48
50
  * complete daughter. A conjunction alone cannot detach a count prefix from
49
51
  * an opaque Boolean predicate. Explicit separators/maximum heads retain their
50
52
  * independent instruction license. */
51
- export declare function isIndependentMaximum(context: Parameters<typeof maximumCountLeadAt>[0], start: number, maximum: NonNullable<ReturnType<typeof maximumOccurrenceAt> | ReturnType<typeof maximumDosePerPeriodAt>>, completePredicate?: boolean): boolean;
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;
52
54
  export declare function separatedFrequencyRangeRule(): HpsgLexicalRule<HpsgClauseContext>;
53
55
  /**
54
56
  * A distributive cadence followed directly by a discrete unit licenses an
@@ -56,18 +58,86 @@ export declare function separatedFrequencyRangeRule(): HpsgLexicalRule<HpsgClaus
56
58
  * than globally treating every bare unit as one dose.
57
59
  */
58
60
  export declare function cadenceFirstImplicitSingleDoseRule(): HpsgLexicalRule<HpsgClauseContext>;
59
- /**
60
- * Parses languages and clinical shorthand that place the cadence adverb before
61
- * the count, e.g. `daily 2 times`. Thai `วันละ 2 ครั้ง` is normalized by the
62
- * locale lexer to exactly this feature sequence, without pretending Thai has
63
- * English word order.
64
- */
65
61
  export declare function cadenceFirstFrequencyRule(): HpsgLexicalRule<HpsgClauseContext>;
66
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;
67
69
  export declare function countFrequencyRule(): HpsgLexicalRule<HpsgClauseContext>;
68
70
  export declare function alternateEventCadenceRule(): HpsgLexicalRule<HpsgClauseContext>;
69
71
  export declare function calendarDateListRule(): HpsgLexicalRule<HpsgClauseContext>;
70
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;
71
141
  export declare function quantityFirstActivityTimingRule(): HpsgLexicalRule<HpsgClauseContext>;
72
142
  export declare function quantityFirstEventOffsetRule(): HpsgLexicalRule<HpsgClauseContext>;
73
143
  /**
@@ -83,6 +153,13 @@ export declare function eventTimingPhraseRule(): HpsgLexicalRule<HpsgClauseConte
83
153
  * @returns A lexical rule yielding typed calendar-day membership.
84
154
  */
85
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;
86
163
  export declare function dayRangeLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
87
164
  /**
88
165
  * A maximum medication quantity is a typed schedule adjunct, not another
@@ -121,10 +198,11 @@ export interface HpsgRecurringCourseConstituent {
121
198
  /** Cheap lexical activation only; the course construction must still compose. */
122
199
  export declare function hasRecurringCourseCue(tokens: readonly Token[], options?: ParseOptions): boolean;
123
200
  /** A registered withholding head selects one complete finite duration NP.
124
- * Objects such as breath, conditional tails, and negative directives cannot
125
- * 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. */
126
203
  export declare function finiteTreatmentPauseAt(context: HpsgClauseContext, frame: AdviceFrame, start: number): {
127
- actionEnd: number;
204
+ headTokens: Token[];
205
+ headSide: "left" | "right";
128
206
  duration: HpsgSign;
129
207
  pause: {
130
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";
@@ -1,8 +1,8 @@
1
1
  import type { HpsgSigSegment } from "./segmenter";
2
- import type { CanonicalSigClause, ParseOptions } from "../types";
2
+ import type { CanonicalEvidence, CanonicalSigClause, CanonicalScheduleExpr, ParseOptions } from "../types";
3
3
  import type { MedicationDateListMatch } from "../date-interpretation";
4
4
  import { AdviceFrame, AdviceRelation, CanonicalDoseRange, CanonicalClinicalAdjuncts, CanonicalAdditionalInstructionExpr, CanonicalActivityTimingExpr, CanonicalCalendarEventExpr, CanonicalCycleDayConstraint, CanonicalDosePeriodMaximumExpr, CanonicalOccurrenceCapExpr, AdministrationTargetCoordinationKind, CanonicalScheduleSemanticField, CanonicalLexicalCategory, BodySiteRestriction, BodySiteRestrictionPredicate, BodySiteSpatialRelation, EventTiming, FhirCoding, FhirDayOfWeek, FhirPeriodUnit, FhirPrimitiveElement, FhirQuantity, MedicationCondition, RouteCode, PrnReasonLookupRequest, SiteCodeLookupRequest, TextRange } from "../types";
5
- import { Token } from "../parser-state";
5
+ import { Token, type ParserState } from "../parser-state";
6
6
  import type { HpsgFeatureNode } from "./type-system";
7
7
  export type HpsgType = "sign" | "word-sign" | "phrase-sign" | "headed-phrase" | "head-complement-phrase" | "head-adjunct-phrase" | "head-marker-phrase" | "procedure-sequence-phrase" | "conditional-instruction-phrase" | "coordination-phrase" | "site-coordination-phrase" | "clause-sign" | "administration-clause" | "method-sign" | "route-sign" | "site-sign" | "site-relative-marker-sign" | "site-predicate-sign" | "site-relative-clause" | "restricted-site-phrase" | "recurring-course-phrase" | "dose-sign" | "schedule-sign" | "prn-sign" | "instruction-sign" | "conditional-sign" | "clinical-adjunct-sign" | "guard-predicate-sign" | "guard-operator-sign" | "guard-marker-sign" | "guard-predicate-phrase" | "guard-coordination-tail" | "guard-negation-phrase" | "medication-guard-phrase" | "adjustment-sign" | "connector-sign";
8
8
  export interface HpsgEvidence {
@@ -143,7 +143,8 @@ export interface HpsgClinicalAdjunctFeature {
143
143
  /** Lexical provenance and typed clinical role are distinct. */
144
144
  evidence: Array<{
145
145
  rule: string;
146
- kind: "condition" | "calendar-exclusion" | "treatment-pause" | "unresolved";
146
+ kind: NonNullable<CanonicalEvidence["clinicalKind"]>;
147
+ /** First range owns the selected clinical extent; subsequent ranges retain ancillary source. */
147
148
  ranges: TextRange[];
148
149
  }>;
149
150
  }
@@ -169,6 +170,8 @@ export interface HpsgDoseFeature {
169
170
  clinicalQuantity?: HpsgClinicalQuantityFeature;
170
171
  /** Number of administrations dividing a stated period-total quantity. */
171
172
  divisionCount?: number;
173
+ /** Authored complement retained when no compatible period total selects its count. */
174
+ divisionInstruction?: HpsgInstructionFeature;
172
175
  }
173
176
  export type HpsgClinicalQuantityDimension = "mass" | "volume" | "biologic-activity" | "administration-unit" | "patient-mass" | "time";
174
177
  /** Authored quantity label plus any FHIR unit coding that cannot be regenerated from it. */
@@ -194,12 +197,15 @@ export interface HpsgClinicalQuantityFeature {
194
197
  projectedDose?: HpsgCodedQuantityTerm;
195
198
  /** Carrier amount used for an administration rate when it differs from the active drug dose. */
196
199
  rateNumerator?: HpsgCodedQuantityTerm;
200
+ /** Authored vehicle volume when no point runtime denominator is supplied. */
201
+ carrierVolume?: HpsgCodedQuantityTerm;
197
202
  /** Source-backed vehicle NP scoped to the carrier volume, not the active drug.
198
203
  * It is descriptive and uncoded unless terminology separately confirms it. */
199
204
  carrierMaterial?: {
200
205
  text: string;
201
206
  range?: TextRange;
202
207
  };
208
+ /** Positive license for explicit period-total division; the legacy name is not limited to days. */
203
209
  dailyTotal?: boolean;
204
210
  dividedDoseCount?: number;
205
211
  administrationDuration?: {
@@ -220,6 +226,10 @@ declare module "../types" {
220
226
  interface CanonicalSigClause {
221
227
  clinicalQuantity?: HpsgClinicalQuantityFeature;
222
228
  }
229
+ interface CanonicalScheduleExpr {
230
+ /** Grammar-owned continuing onset, distinct from one dated occurrence. */
231
+ openEndedStart?: true;
232
+ }
223
233
  }
224
234
  export interface HpsgScheduleFeature {
225
235
  cycleDayConstraint?: CanonicalCycleDayConstraint;
@@ -249,11 +259,27 @@ export interface HpsgScheduleFeature {
249
259
  duration?: number;
250
260
  durationMax?: number;
251
261
  durationUnit?: FhirPeriodUnit;
262
+ durationMaxUnit?: FhirPeriodUnit;
263
+ /** Runtime selected by an explicit local method, independent of course bounds. */
264
+ administrationDuration?: number;
265
+ administrationDurationMax?: number;
266
+ administrationDurationComparator?: CanonicalScheduleExpr["administrationDurationComparator"];
267
+ administrationDurationRange?: CanonicalScheduleExpr["administrationDurationRange"];
268
+ administrationDurationUnit?: FhirPeriodUnit;
252
269
  /** Elapsed delay before one administration, not a course duration. */
253
270
  administrationOffsetMinutes?: number;
271
+ /** Selected lexical interval retained until the regimen construction owns its scope. */
272
+ relativeAdministrationInterval?: {
273
+ value: number;
274
+ unit: FhirPeriodUnit;
275
+ };
254
276
  boundsStart?: string;
277
+ /** The selected start construction explicitly continues beyond its date. */
278
+ openEndedStart?: true;
255
279
  boundsEnd?: string;
256
280
  frequency?: number;
281
+ /** All divided administrations occur on the first day of each whole civil-day interval. */
282
+ frequencyWithinDay?: true;
257
283
  frequencyMax?: number;
258
284
  period?: number;
259
285
  periodMax?: number;
@@ -274,6 +300,7 @@ export interface HpsgScheduleFeature {
274
300
  };
275
301
  occurrenceCap?: CanonicalOccurrenceCapExpr;
276
302
  maxDosePerPeriod?: CanonicalDosePeriodMaximumExpr[];
303
+ maxDosePerAdministration?: CanonicalScheduleExpr["maxDosePerAdministration"];
277
304
  }
278
305
  export interface HpsgSynsem {
279
306
  head: {
@@ -374,6 +401,12 @@ export interface BoundarySite extends Range {
374
401
  lastTokenIndex: number;
375
402
  rightIndex: number;
376
403
  kind: BoundaryKind;
404
+ /** Selected lexical relation; surface remains the authored source. */
405
+ connectorKind?: CoordinationConnectorKind;
406
+ /** Typed antecedent complement selected by an explicit alternative marker. */
407
+ complementCondition?: MedicationCondition;
408
+ /** The selected antecedent is invariant within its calendar day. */
409
+ complementDayConstant?: boolean;
377
410
  surface: string;
378
411
  }
379
412
  export interface Evidence {
@@ -389,7 +422,7 @@ export interface Proposal {
389
422
  /** Typed boundary license to inherit a following sibling's course duration. */
390
423
  inheritFollowingDuration?: boolean;
391
424
  /** Typed construction license, never inferred from its display rule id. */
392
- semanticLicense?: "dose-continuation" | "target-transition" | "delayed-target" | "event-timing-ellipsis" | "interval-origin";
425
+ semanticLicense?: "dose-continuation" | "target-transition" | "delayed-target" | "event-timing-ellipsis" | "additive-timing" | "interval-origin" | "withholding-target";
393
426
  evidence: Evidence[];
394
427
  }
395
428
  export interface BoundaryDecision {
@@ -422,6 +455,7 @@ export interface ProbeSummary extends Range {
422
455
  coordination: 'conjunction' | 'disjunction' | 'mixed';
423
456
  }>;
424
457
  clause: CanonicalSigClause;
458
+ relativeAdministrationInterval?: ParserState["relativeAdministrationInterval"];
425
459
  }
426
460
  export interface PlannerMetrics {
427
461
  lexicalPasses: number;
@@ -461,6 +495,9 @@ export interface BoundaryRelation {
461
495
  connectorKind: CoordinationConnectorKind;
462
496
  rule: string;
463
497
  semanticLicense?: Proposal["semanticLicense"];
498
+ complementCondition?: MedicationCondition;
499
+ /** The selected antecedent is invariant within its calendar day. */
500
+ complementDayConstant?: boolean;
464
501
  range: Range;
465
502
  }
466
503
  /** Typed facts consumed by cross-clause HPSG coordination constructions. */
@@ -1,5 +1,6 @@
1
+ import { type LexToken } from "../lexer/token-types";
1
2
  import { ParserState } from "../parser-state";
2
- import { FhirPeriodUnit } from "../types";
3
+ import { EventTiming, FhirPeriodUnit } from "../types";
3
4
  import { HpsgScheduleFeature } from "./signature";
4
5
  export declare const EVERY_INTERVAL_TOKENS: Set<string>;
5
6
  export declare const COUNT_MARKER_TOKENS: Set<string>;
@@ -25,8 +26,23 @@ export declare function normalizeMixedPeriodRange(low: number, lowUnit: FhirPeri
25
26
  } | undefined;
26
27
  export declare function periodUnitSuffix(unit: FhirPeriodUnit): string | undefined;
27
28
  export declare function applyPeriod(internal: ParserState, period: number, unit: FhirPeriodUnit): void;
28
- export declare function buildPeriodScheduleFeature(period: number, unit: FhirPeriodUnit): HpsgScheduleFeature;
29
+ export declare function buildPeriodScheduleFeature(period: number, unit: FhirPeriodUnit, when?: EventTiming): HpsgScheduleFeature;
29
30
  export declare function mapIntervalUnit(token: string): FhirPeriodUnit.Minute | FhirPeriodUnit.Hour | FhirPeriodUnit.Day | FhirPeriodUnit.Week | FhirPeriodUnit.Month | undefined;
31
+ /** Bounded lexical constituent for a fronted following treatment course.
32
+ * The planner reuses its source extent; duration consumers retain the
33
+ * same selected numeric daughter.
34
+ * @param tokens Source lexical tokens.
35
+ * @param start Candidate duration-lead index.
36
+ */
37
+ export declare function followingCourseDurationHeaderAt(tokens: readonly LexToken[], start: number): {
38
+ valueIndex: number;
39
+ tokenEnd: number;
40
+ implicitSingle?: boolean;
41
+ range?: {
42
+ low: number;
43
+ high: number;
44
+ };
45
+ } | undefined;
30
46
  export declare function mapFrequencyAdverb(token: string): FhirPeriodUnit | undefined;
31
47
  export declare function parseNumericRange(token: string): {
32
48
  low: number;
package/dist/i18n.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { formatLong as formatLongEnglish, formatShort as formatShortEnglish } from "./locales/clause/en";
1
2
  import type { CourseLanguage } from "./localization";
2
3
  import { ENGLISH_CLAUSE_TIMING } from "./locales/course/en";
3
4
  export type { CourseLanguage } from "./localization";
@@ -46,13 +47,17 @@ export interface SigLocalizationConfig extends Partial<Omit<SigLocalization, "lo
46
47
  inherit?: string;
47
48
  }
48
49
  interface NativeClauseRendering {
49
- long?: typeof formatLongThai;
50
- short?: typeof formatShortThai;
50
+ course: CourseLanguage;
51
+ long: typeof formatLongEnglish;
52
+ short: typeof formatShortEnglish;
51
53
  timing: typeof ENGLISH_CLAUSE_TIMING;
54
+ dose: NonNullable<SigLocalization["formatDose"]>;
52
55
  }
53
56
  export declare function registerSigLocalization(localization: SigLocalization): void;
54
57
  export declare function getRegisteredSigLocalizations(): SigLocalization[];
55
58
  export declare function resolveNativeClauseRendering(localization?: SigLocalization): NativeClauseRendering;
59
+ /** Optional rich-amount formatting uses the same provider-owned stock fallback. */
60
+ export declare function resolveSigDoseFormatter(localization?: SigLocalization): NonNullable<SigLocalization["formatDose"]>;
56
61
  export declare function resolveSigLocalization(locale?: string, config?: SigLocalizationConfig): SigLocalization | undefined;
57
62
  export declare function hasClauseFormatOverride(localization: SigLocalization | undefined, style: "short" | "long"): boolean;
58
63
  /** Resolve the course facet once at a public formatting boundary. Reuse the
@@ -66,8 +71,3 @@ export declare function resolveSigTranslation(locale?: string, config?: SigTrans
66
71
  export declare const DAY_NAMES_THAI: Record<string, string>;
67
72
  export declare const THAI_SITE_TRANSLATIONS: Record<string, string>;
68
73
  export declare function joinWithAndThai(parts: string[]): string;
69
- declare function formatShortThai(clause: CanonicalSigClause, words?: CourseLanguage, resolvedMethod?: MedicationInstructionActionDefinition): string;
70
- declare function formatLongThai(clause: CanonicalSigClause, options?: TimingSummaryOptions, words?: CourseLanguage, resolvedMethod?: MedicationInstructionActionDefinition, authoredPrimary?: string, deferredDirections?: {
71
- text?: string;
72
- current?: string;
73
- }): string;