ezmedicationinput 0.1.66 → 0.2.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 (44) hide show
  1. package/README.md +25 -22
  2. package/dist/advice.d.ts +20 -0
  3. package/dist/body-site-grammar.d.ts +34 -1
  4. package/dist/date-interpretation.d.ts +2 -0
  5. package/dist/dosage-course.d.ts +188 -0
  6. package/dist/fhir.d.ts +144 -9
  7. package/dist/format.d.ts +9 -1
  8. package/dist/hpsg/constructions.d.ts +105 -0
  9. package/dist/hpsg/lexical-classes.d.ts +170 -1
  10. package/dist/hpsg/procedural-context.d.ts +15 -1
  11. package/dist/hpsg/projection.d.ts +10 -2
  12. package/dist/hpsg/rule-context.d.ts +13 -0
  13. package/dist/hpsg/rules/clinical-quantity-rules.d.ts +9 -0
  14. package/dist/hpsg/rules/condition-rules.d.ts +15 -0
  15. package/dist/hpsg/rules/core-rules.d.ts +29 -0
  16. package/dist/hpsg/rules/instruction-rules.d.ts +9 -1
  17. package/dist/hpsg/rules/timing-rules.d.ts +121 -7
  18. package/dist/hpsg/signature.d.ts +342 -4
  19. package/dist/hpsg/type-system.d.ts +16 -1
  20. package/dist/hpsg/unification.d.ts +1 -0
  21. package/dist/i18n.d.ts +2 -0
  22. package/dist/index.cjs +48961 -31422
  23. package/dist/index.d.ts +21 -5
  24. package/dist/index.js +48936 -31421
  25. package/dist/instruction-action-locale-adapter.d.ts +1 -0
  26. package/dist/instruction-action-terminology.d.ts +16 -1
  27. package/dist/instruction-concept-terminology.d.ts +1 -1
  28. package/dist/instruction-graph-fhir.d.ts +1 -1
  29. package/dist/instruction-graph.d.ts +38 -2
  30. package/dist/ir.d.ts +12 -1
  31. package/dist/maps.d.ts +15 -0
  32. package/dist/medication-condition.d.ts +42 -0
  33. package/dist/parser-state.d.ts +5 -1
  34. package/dist/parser.d.ts +5 -2
  35. package/dist/regimen/coordination-scope.d.ts +53 -0
  36. package/dist/regimen/grammar.d.ts +68 -0
  37. package/dist/regimen/parallel-course.d.ts +85 -0
  38. package/dist/regimen/planner.d.ts +19 -0
  39. package/dist/regimen/regimen.d.ts +66 -0
  40. package/dist/schedule.d.ts +9 -6
  41. package/dist/stable-structure.d.ts +23 -1
  42. package/dist/types.d.ts +433 -28
  43. package/dist/utils/strength.d.ts +16 -0
  44. package/package.json +11 -3
@@ -1,5 +1,35 @@
1
+ import { Token } from "../../parser-state";
2
+ import { type AdviceFrame, type CanonicalCalendarEventExpr, type FhirQuantity, type ParseOptions } from "../../types";
1
3
  import { HpsgClauseContext } from "../rule-context";
2
- import { HpsgLexicalRule } from "../signature";
4
+ 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;
16
+ export interface OrdinalWeekStageHeader {
17
+ tokenStart: number;
18
+ tokenEnd: number;
19
+ start: number;
20
+ end: number;
21
+ ordinal: number;
22
+ openEnded: boolean;
23
+ }
24
+ /**
25
+ * Recognize a bounded ordinal-week regimen header as a typed lexical shape.
26
+ * The caller decides whether several headers form a treatment sequence; this
27
+ * matcher does not split text or infer a regimen from a lone occurrence.
28
+ */
29
+ export declare function ordinalWeekStageHeaderAt(tokens: readonly Token[], start: number): OrdinalWeekStageHeader | undefined;
30
+ export declare function ordinalWeekStageHeaders(tokens: readonly Token[]): OrdinalWeekStageHeader[];
31
+ /** A regimen-stage construction requires at least Week 1 + Week 2. */
32
+ export declare function ordinalWeekStageSequence(tokens: readonly Token[]): OrdinalWeekStageHeader[];
3
33
  export declare function multiplicativeDoseFrequencyRule(): HpsgLexicalRule<HpsgClauseContext>;
4
34
  export declare function compactIntervalRule(): HpsgLexicalRule<HpsgClauseContext>;
5
35
  export declare function separatedIntervalRule(): HpsgLexicalRule<HpsgClauseContext>;
@@ -23,12 +53,6 @@ export declare function alternateEventCadenceRule(): HpsgLexicalRule<HpsgClauseC
23
53
  export declare function calendarDateListRule(): HpsgLexicalRule<HpsgClauseContext>;
24
54
  export declare function timingLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
25
55
  export declare function quantityFirstActivityTimingRule(): HpsgLexicalRule<HpsgClauseContext>;
26
- /**
27
- * Quantity-first event offsets are the ordinary English inverse of
28
- * relation-first forms: `30 min before breakfast`, `half an hour after food`.
29
- * They project to the same canonical event-offset feature as `before meals
30
- * 30 minutes`, so ordering is grammar rather than a separate semantic model.
31
- */
32
56
  export declare function quantityFirstEventOffsetRule(): HpsgLexicalRule<HpsgClauseContext>;
33
57
  /**
34
58
  * Relative event offsets are timing semantics, not treatment duration.
@@ -36,7 +60,97 @@ export declare function quantityFirstEventOffsetRule(): HpsgLexicalRule<HpsgClau
36
60
  */
37
61
  export declare function eventOffsetRule(): HpsgLexicalRule<HpsgClauseContext>;
38
62
  export declare function eventTimingPhraseRule(): HpsgLexicalRule<HpsgClauseContext>;
63
+ /** A calendar-month day range is a recurrence selector, never a dose range.
64
+ * Both the headed day noun and its explicit monthly complement must be present,
65
+ * so ordinary “1–14 tablets”, duration ranges and menstrual cycle offsets
66
+ * cannot satisfy this constituent.
67
+ * @returns A lexical rule yielding typed calendar-day membership.
68
+ */
69
+ export declare function monthlyDayOfMonthLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
39
70
  export declare function dayRangeLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
71
+ /**
72
+ * A maximum medication quantity is a typed schedule adjunct, not another
73
+ * administration dose. The full lexical sign owns its source span so a
74
+ * trailing cap cannot be reparsed from Dosage.text after FHIR projection.
75
+ */
76
+ export declare function maximumDosePerPeriodRule(): HpsgLexicalRule<HpsgClauseContext>;
77
+ /** Does a source lead license a new treatment-relative phase onset? No
78
+ * arbitrary numeric quantity or isolated "in/from" qualifies.
79
+ */
80
+ export declare function treatmentRelativePeriodStartAt(tokens: readonly Token[], start: number): {
81
+ tokenEnd: number;
82
+ offsetDays: number;
83
+ } | undefined;
84
+ /**
85
+ * A duration noun phrase contributes a quantity and a time dimension. Its
86
+ * governing construction decides whether it is an active course, a rest
87
+ * interval, or a local procedural duration; the lexical daughter does not.
88
+ * @param tokens Existing normalized source tokens, never retokenized text.
89
+ * @param start First token of the duration daughter.
90
+ * @param limit Exclusive end of the containing constituent.
91
+ */
92
+ export declare function durationNominalAt(tokens: readonly Token[], start: number, limit?: number): HpsgSign | undefined;
40
93
  export declare function countAndDurationRule(): HpsgLexicalRule<HpsgClauseContext>;
41
94
  export declare function timeOfDayRule(): HpsgLexicalRule<HpsgClauseContext>;
42
95
  export declare function isScheduleLead(context: HpsgClauseContext, index: number): boolean;
96
+ export declare function openEndedScheduleRule(): HpsgLexicalRule<HpsgClauseContext>;
97
+ /** A licensed active/rest/repeat phrase, with both duration daughters retained. */
98
+ export interface HpsgRecurringCourseConstituent {
99
+ sign: HpsgSign;
100
+ onDuration: FhirQuantity;
101
+ offDuration: FhirQuantity;
102
+ repeatCycle: FhirQuantity;
103
+ repeatCount?: number;
104
+ }
105
+ /** Cheap lexical activation only; the course construction must still compose. */
106
+ export declare function hasRecurringCourseCue(tokens: readonly Token[], options?: ParseOptions): boolean;
107
+ /** A registered withholding head selects one complete finite duration NP.
108
+ * Objects such as breath, conditional tails, and negative directives cannot
109
+ * satisfy this medication-pause valence. Both daughters remain in the chart. */
110
+ export declare function finiteTreatmentPauseAt(context: HpsgClauseContext, frame: AdviceFrame, start: number): {
111
+ actionEnd: number;
112
+ duration: HpsgSign;
113
+ pause: {
114
+ durationDays: number;
115
+ range: {
116
+ start: number;
117
+ end: number;
118
+ };
119
+ };
120
+ } | undefined;
121
+ /**
122
+ * Compose duration + stopped-duration + repetition as one headed course
123
+ * phrase. Ordinary duration morphology, registered action meaning and shared
124
+ * discourse markers are the only language authorities; no whole-SIG regex.
125
+ * @param input Unchanged source for lexical action aliases and provenance.
126
+ * @param tokens Existing normalized source tokens.
127
+ * @param start Candidate active-duration daughter.
128
+ * @param options Caller terminology, including registered action synonyms.
129
+ */
130
+ export declare function recurringCourseAt(input: string, tokens: readonly Token[], start: number, options?: ParseOptions): HpsgRecurringCourseConstituent | undefined;
131
+ /** Share the same selected cycle constituents with segmentation and the chart. */
132
+ export declare function recurringCourseConstituents(input: string, tokens: readonly Token[], options?: ParseOptions): HpsgRecurringCourseConstituent[];
133
+ export interface CycleSchedule {
134
+ start: number;
135
+ end: number;
136
+ sourceText: string;
137
+ days: number[];
138
+ cycles: number;
139
+ periodDays?: number;
140
+ anchor?: string;
141
+ events: CanonicalCalendarEventExpr[];
142
+ error?: string;
143
+ kind?: 'calendar-days' | 'recurring-on-off';
144
+ onDuration?: FhirQuantity;
145
+ offDuration?: FhirQuantity;
146
+ repeatCycle?: FhirQuantity;
147
+ repeatCount?: number;
148
+ unbounded?: boolean;
149
+ /** Selected HPSG phrase reused by chart ownership and schedule projection. */
150
+ sign?: HpsgSign;
151
+ }
152
+ /** Recognize finite anchored cycle/day-offset expressions; never guess an absent anchor or cycle length. */
153
+ export declare function recognizeCycles(input: string, options?: ParseOptions, sourceTokens?: readonly Token[]): CycleSchedule[];
154
+ /** Finite cycles emit exact events; recurring active/rest cycles emit their
155
+ * typed active duration and whole-course repeat interval on the same sign. */
156
+ export declare function cycleScheduleRule(): HpsgLexicalRule<HpsgClauseContext>;
@@ -1,15 +1,22 @@
1
- import { AdviceFrame, AdviceRelation, CanonicalDoseRange, CanonicalAdditionalInstructionExpr, CanonicalActivityTimingExpr, CanonicalCalendarEventExpr, CanonicalOccurrenceCapExpr, BodySiteSpatialRelation, EventTiming, FhirCoding, FhirDayOfWeek, FhirPeriodUnit, FhirPrimitiveElement, RouteCode, PrnReasonLookupRequest, SiteCodeLookupRequest } from "../types";
1
+ import type { HpsgSigSegment } from "./segmenter";
2
+ import type { CanonicalSigClause, ParseOptions } from "../types";
3
+ import type { MedicationDateListMatch } from "../date-interpretation";
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";
2
5
  import { Token } from "../parser-state";
3
6
  import type { HpsgFeatureNode } from "./type-system";
4
- 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" | "clause-sign" | "administration-clause" | "method-sign" | "route-sign" | "site-sign" | "dose-sign" | "schedule-sign" | "prn-sign" | "instruction-sign" | "conditional-sign" | "adjustment-sign" | "connector-sign";
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";
5
8
  export interface HpsgEvidence {
6
9
  rule: string;
10
+ /** Canonical provenance comes from the typed lexical sign, not its rule ID. */
11
+ lexicalCategory?: CanonicalLexicalCategory;
7
12
  tokenIndices: number[];
8
13
  /** Lexical evidence that a schedule field is an inferred, construction-local default. */
9
14
  scheduleDefault?: "daily-frequency";
15
+ /** Exact typed schedule fields contributed by this lexical evidence. */
16
+ scheduleFields?: CanonicalScheduleSemanticField[];
10
17
  }
11
18
  export type HpsgConstructionKind = "head-complement" | "head-adjunct" | "head-marker" | "procedure-sequence" | "conditional-instruction" | "coordination" | "administration-clause" | "generic";
12
- export type HpsgConstructionOperation = "unify" | "scope";
19
+ export type HpsgConstructionOperation = "unify" | "scope" | "form-site-relative" | "restrict-site" | "repeat-course";
13
20
  export interface HpsgConstruction {
14
21
  kind: HpsgConstructionKind;
15
22
  operation?: HpsgConstructionOperation;
@@ -29,14 +36,36 @@ export interface HpsgRouteFeature {
29
36
  attachmentClass?: "administration" | "procedure";
30
37
  text?: string;
31
38
  }
32
- export interface HpsgSiteFeature {
39
+ export interface HpsgAdministrationTargetFeature {
33
40
  attachmentClass?: "administration" | "procedure";
34
41
  text?: string;
35
42
  i18n?: Record<string, string>;
36
43
  source?: "abbreviation" | "text" | "selection" | "resolver";
37
44
  coding?: FhirCoding;
38
45
  spatialRelation?: BodySiteSpatialRelation;
46
+ restrictions?: BodySiteRestriction[];
39
47
  lookupRequest?: SiteCodeLookupRequest;
48
+ administrationTargetCount?: number;
49
+ range?: TextRange;
50
+ }
51
+ export interface HpsgSiteCoordinationFeature {
52
+ coordination: AdministrationTargetCoordinationKind;
53
+ sourceText: string;
54
+ range: TextRange;
55
+ targets: HpsgAdministrationTargetFeature[];
56
+ }
57
+ export interface HpsgSiteFeature extends HpsgAdministrationTargetFeature {
58
+ coordination?: HpsgSiteCoordinationFeature;
59
+ }
60
+ export interface HpsgCoordinationMarkerFeature {
61
+ coordination: Exclude<AdministrationTargetCoordinationKind, "mixed">;
62
+ }
63
+ export interface HpsgSiteRelativeMarkerFeature {
64
+ relation: BodySiteRestriction["relation"];
65
+ range: TextRange;
66
+ }
67
+ export interface HpsgSitePredicateFeature extends BodySiteRestrictionPredicate {
68
+ range: TextRange;
40
69
  }
41
70
  export interface HpsgPrnFeature {
42
71
  enabled: true;
@@ -66,6 +95,56 @@ export interface HpsgConditionFeature {
66
95
  safety: boolean;
67
96
  frames: AdviceFrame[];
68
97
  }
98
+ /**
99
+ * A medication-level guard or calendar omission contributed by a lexical
100
+ * sign. This is distinct from HpsgConditionFeature, which scopes procedural
101
+ * instruction programs such as "if irritation occurs, stop use".
102
+ */
103
+ /** A predicate daughter can require a measurement head from an adjacent
104
+ * coordinate. Only the HPSG coordination construction may discharge it. */
105
+ export type HpsgGuardExpression = {
106
+ kind: "predicate";
107
+ value: MedicationCondition;
108
+ dayInvariant?: true;
109
+ } | {
110
+ kind: "measurement-complement";
111
+ operation: "gt" | "ge" | "lt" | "le" | "eq";
112
+ value: number;
113
+ unit?: string;
114
+ text: string;
115
+ } | {
116
+ kind: "coordination";
117
+ operator: "all" | "any";
118
+ parts: HpsgGuardExpression[];
119
+ } | {
120
+ kind: "negation";
121
+ operand: HpsgGuardExpression;
122
+ };
123
+ /** Internal conditional constituent features, never a second FHIR schema. */
124
+ export interface HpsgGuardFeature {
125
+ expression?: HpsgGuardExpression;
126
+ operator?: "all" | "any" | "not";
127
+ marker?: "if" | "only-if" | "unless";
128
+ licensesBareIf?: true;
129
+ }
130
+ export interface HpsgClinicalAdjunctFeature {
131
+ treatmentPause?: CanonicalClinicalAdjuncts["treatmentPause"];
132
+ condition?: MedicationCondition;
133
+ /** Day-domain meaning retained separately for typed anaphoric complements. */
134
+ calendarDayCondition?: MedicationCondition;
135
+ conditionTarget?: CanonicalClinicalAdjuncts["conditionTarget"];
136
+ excludedDates?: string[];
137
+ excludedWeekdays?: FhirDayOfWeek[];
138
+ /** Recognized adjunct boundary whose payload remains intentionally editable. */
139
+ unresolved?: true;
140
+ localRanges: TextRange[];
141
+ /** Lexical provenance and typed clinical role are distinct. */
142
+ evidence: Array<{
143
+ rule: string;
144
+ kind: "condition" | "calendar-exclusion" | "treatment-pause" | "unresolved";
145
+ ranges: TextRange[];
146
+ }>;
147
+ }
69
148
  export interface HpsgScopedAdministrationFeature {
70
149
  condition: HpsgConditionFeature;
71
150
  head: HpsgSynsem["head"];
@@ -79,15 +158,89 @@ export interface HpsgDoseFeature {
79
158
  value?: number;
80
159
  range?: CanonicalDoseRange;
81
160
  unit?: string;
161
+ /**
162
+ * Dimensionally typed clinical quantity contributed by the grammar. This
163
+ * remains distinct from `value`/`unit`: an infusion rate must never be
164
+ * projected through the ordinary doseQuantity path.
165
+ */
166
+ clinicalQuantity?: HpsgClinicalQuantityFeature;
167
+ /** Number of administrations dividing a stated period-total quantity. */
168
+ divisionCount?: number;
169
+ }
170
+ export type HpsgClinicalQuantityDimension = "mass" | "volume" | "biologic-activity" | "administration-unit" | "patient-mass" | "time";
171
+ /** Authored quantity label plus any FHIR unit coding that cannot be regenerated from it. */
172
+ export interface HpsgCodedQuantityTerm {
173
+ value: number;
174
+ unit: string;
175
+ system?: string;
176
+ code?: string;
177
+ }
178
+ export interface HpsgDimensionalQuantityTerm extends HpsgCodedQuantityTerm {
179
+ dimension: HpsgClinicalQuantityDimension;
180
+ }
181
+ export interface HpsgClinicalQuantityFeature {
182
+ representation: "dose" | "rate-quantity" | "dose-with-rate-ratio";
183
+ status: "resolved" | "incomplete" | "unsupported";
184
+ numerator: HpsgDimensionalQuantityTerm;
185
+ denominators: HpsgDimensionalQuantityTerm[];
186
+ /** Per-administration value after an explicit daily total is divided. */
187
+ projectedDose?: HpsgCodedQuantityTerm;
188
+ /** Carrier amount used for an administration rate when it differs from the active drug dose. */
189
+ rateNumerator?: HpsgCodedQuantityTerm;
190
+ /** Source-backed vehicle NP scoped to the carrier volume, not the active drug.
191
+ * It is descriptive and uncoded unless terminology separately confirms it. */
192
+ carrierMaterial?: {
193
+ text: string;
194
+ range?: TextRange;
195
+ };
196
+ dailyTotal?: boolean;
197
+ dividedDoseCount?: number;
198
+ administrationDuration?: {
199
+ value: number;
200
+ unit: FhirPeriodUnit;
201
+ };
202
+ requiresPatientWeight?: true;
203
+ reviewReason?: "incomplete-weight-based-dose" | "unsupported-weight-based-rate";
204
+ }
205
+ /**
206
+ * The public canonical schema predates rate parsing. Declaration merging
207
+ * exposes the typed grammar contribution without forcing it into the scalar
208
+ * CanonicalDoseExpr shape. FHIR lowering can therefore distinguish a dose,
209
+ * a rateQuantity, and a dose/rateRatio without reparsing source text.
210
+ */
211
+ declare module "../types" {
212
+ interface CanonicalSigClause {
213
+ clinicalQuantity?: HpsgClinicalQuantityFeature;
214
+ }
82
215
  }
83
216
  export interface HpsgScheduleFeature {
217
+ cycleDayConstraint?: CanonicalCycleDayConstraint;
218
+ /** Typed whole-course interval for a recurring active/rest construction. */
219
+ repeatCycle?: FhirQuantity;
220
+ /** Explicit finite number of whole-course repetitions; absent means unbounded. */
221
+ repeatCount?: number;
222
+ /** Explicit local-clock interval window; not a list of endpoint doses. */
223
+ clockWindow?: {
224
+ start: string;
225
+ end: string;
226
+ endInclusive: boolean;
227
+ };
228
+ /** Weekday occurrence in each month; -1 denotes the last occurrence. */
229
+ weekdayOrdinal?: -1 | 1 | 2 | 3 | 4 | 5;
230
+ timingReference?: "previous" | "previous-weekday-complement";
231
+ /** Source-relative phase onset, in elapsed days from treatment start. */
232
+ treatmentStartOffsetDays?: number;
84
233
  attachmentClass?: "administration" | "procedure";
234
+ /** Exact source owned by this schedule construction, retained for generic attachment arbitration. */
235
+ sourceRanges?: TextRange[];
85
236
  timingCode?: string;
86
237
  count?: number;
87
238
  countMax?: number;
88
239
  duration?: number;
89
240
  durationMax?: number;
90
241
  durationUnit?: FhirPeriodUnit;
242
+ /** Elapsed delay before one administration, not a course duration. */
243
+ administrationOffsetMinutes?: number;
91
244
  boundsStart?: string;
92
245
  boundsEnd?: string;
93
246
  frequency?: number;
@@ -100,10 +253,17 @@ export interface HpsgScheduleFeature {
100
253
  offsetMax?: number;
101
254
  when?: EventTiming[];
102
255
  dayOfWeek?: FhirDayOfWeek[];
256
+ /** Recurring calendar dates of each month; e.g. days 1–14. */
257
+ dayOfMonth?: number[];
103
258
  timeOfDay?: string[];
104
259
  calendarEvents?: CanonicalCalendarEventExpr[];
105
260
  activityTiming?: CanonicalActivityTimingExpr[];
261
+ eventWindow?: {
262
+ start: EventTiming;
263
+ end: EventTiming;
264
+ };
106
265
  occurrenceCap?: CanonicalOccurrenceCapExpr;
266
+ maxDosePerPeriod?: CanonicalDosePeriodMaximumExpr[];
107
267
  }
108
268
  export interface HpsgSynsem {
109
269
  head: {
@@ -119,10 +279,18 @@ export interface HpsgSynsem {
119
279
  patientInstruction?: HpsgPatientInstructionFeature;
120
280
  };
121
281
  cont: {
282
+ /** Source operation on the preceding regimen, resolved before projection. */
283
+ regimenAdjustment?: "replace" | "add" | "replace-target";
122
284
  clauseKind?: "administration";
123
285
  condition?: HpsgConditionFeature;
286
+ clinicalAdjunct?: HpsgClinicalAdjunctFeature;
287
+ guard?: HpsgGuardFeature;
124
288
  scopedAdministrations?: HpsgScopedAdministrationFeature[];
125
289
  scopeClosed?: true;
290
+ coordinationMarker?: HpsgCoordinationMarkerFeature;
291
+ siteRelativeMarker?: HpsgSiteRelativeMarkerFeature;
292
+ sitePredicate?: HpsgSitePredicateFeature;
293
+ siteRestriction?: BodySiteRestriction;
126
294
  };
127
295
  nonlocal?: {
128
296
  scopeRequirements?: HpsgConditionFeature[];
@@ -165,6 +333,7 @@ export declare function emptySynsem(): HpsgSynsem;
165
333
  export declare function lexicalSign(args: {
166
334
  type: HpsgType;
167
335
  rule: string;
336
+ lexicalCategory?: CanonicalLexicalCategory;
168
337
  tokens: Token[];
169
338
  synsem: HpsgSynsem;
170
339
  consumedTokenIndices?: number[];
@@ -172,4 +341,173 @@ export declare function lexicalSign(args: {
172
341
  warnings?: string[];
173
342
  score?: number;
174
343
  scheduleDefault?: HpsgEvidence["scheduleDefault"];
344
+ scheduleFields?: CanonicalScheduleSemanticField[];
175
345
  }): HpsgSign;
346
+ /** Cross-clause HPSG construction facts and source-boundary plans. */
347
+ export interface Range {
348
+ start: number;
349
+ end: number;
350
+ }
351
+ export type StructureKind = 'cycle-schedule' | 'target-list' | 'calendar-date-list' | 'clock-list' | 'weekday-list' | 'numeric-quantity' | 'parenthesized' | 'calendar-exclusion' | 'fronted-conditional-clause' | 'procedural-argument' | 'clinical-condition' | 'event-timing-list';
352
+ export interface StructuralClaim extends Range {
353
+ id: string;
354
+ kind: StructureKind;
355
+ policy: 'no-external-split';
356
+ producer: string;
357
+ resolved: boolean;
358
+ }
359
+ export type BoundaryKind = 'coordination' | 'alternative' | 'sequence' | 'comma' | 'hard' | 'slash' | 'adjacent-dose' | 'punctuation';
360
+ export type CoordinationConnectorKind = 'conjunction' | 'disjunction' | 'unknown';
361
+ export type RegimenRelation = 'sequence' | 'coordination' | 'alternative' | 'shared-duration' | 'independent';
362
+ export interface BoundarySite extends Range {
363
+ tokenIndex: number;
364
+ lastTokenIndex: number;
365
+ rightIndex: number;
366
+ kind: BoundaryKind;
367
+ surface: string;
368
+ }
369
+ export interface Evidence {
370
+ feature: string;
371
+ value: string | number | boolean | readonly string[];
372
+ range?: Range;
373
+ }
374
+ export interface Proposal {
375
+ action: 'keep' | 'split';
376
+ rule: string;
377
+ priority: number;
378
+ relation?: RegimenRelation;
379
+ /** Typed boundary license to inherit a following sibling's course duration. */
380
+ inheritFollowingDuration?: boolean;
381
+ /** Typed construction license, never inferred from its display rule id. */
382
+ semanticLicense?: "dose-continuation" | "target-transition" | "delayed-target" | "event-timing-ellipsis" | "interval-origin";
383
+ evidence: Evidence[];
384
+ }
385
+ export interface BoundaryDecision {
386
+ site: BoundarySite;
387
+ selected: Proposal;
388
+ alternatives: Proposal[];
389
+ conflict: boolean;
390
+ rejectedRules?: Array<{
391
+ rule: string;
392
+ failedConstraints: string[];
393
+ }>;
394
+ }
395
+ export interface ProbeSummary extends Range {
396
+ complete: boolean;
397
+ hasHead: boolean;
398
+ hasDose: boolean;
399
+ hasSchedule: boolean;
400
+ hasRecurringCadence: boolean;
401
+ hasDates: boolean;
402
+ hasClocks: boolean;
403
+ hasOffset: boolean;
404
+ method: boolean;
405
+ prn: boolean;
406
+ clocks: readonly string[];
407
+ conditionStarts: readonly number[];
408
+ targets: readonly string[];
409
+ hasTargets: boolean;
410
+ siteCoordinations: Array<Range & {
411
+ type: 'site-coordination-phrase';
412
+ coordination: 'conjunction' | 'disjunction' | 'mixed';
413
+ }>;
414
+ clause: CanonicalSigClause;
415
+ }
416
+ export interface PlannerMetrics {
417
+ lexicalPasses: number;
418
+ dateScans: number;
419
+ actionScans: number;
420
+ clauseProbes: number;
421
+ siteCoordinationProbes: number;
422
+ probeCacheHits: number;
423
+ probedTokens: number;
424
+ candidates: number;
425
+ claimedCandidates: number;
426
+ }
427
+ export interface BoundaryPlan {
428
+ experimental: true;
429
+ segments: HpsgSigSegment[];
430
+ claims: StructuralClaim[];
431
+ decisions: BoundaryDecision[];
432
+ relations: BoundaryRelation[];
433
+ metrics: PlannerMetrics;
434
+ }
435
+ export interface PlannerOptions {
436
+ trace?: boolean;
437
+ ownership?: boolean;
438
+ cache?: boolean;
439
+ }
440
+ export interface PlanningInput {
441
+ input: string;
442
+ options?: ParseOptions;
443
+ tokens: Token[];
444
+ dateSpans?: MedicationDateListMatch[];
445
+ }
446
+ /** A licensed relation connects segment identities, never reconstructed from display text. */
447
+ export interface BoundaryRelation {
448
+ from: number;
449
+ to: number;
450
+ kind: RegimenRelation;
451
+ connectorKind: CoordinationConnectorKind;
452
+ rule: string;
453
+ semanticLicense?: Proposal["semanticLicense"];
454
+ range: Range;
455
+ }
456
+ /** Typed facts consumed by cross-clause HPSG coordination constructions. */
457
+ export interface CoordinationScopeFacts {
458
+ relation: BoundaryRelation;
459
+ adjacent: boolean;
460
+ leftComplete: boolean;
461
+ rightComplete: boolean;
462
+ leftExplicitDose: boolean;
463
+ rightExplicitDose: boolean;
464
+ leftExplicitHead: boolean;
465
+ /** An available typed method, whether explicit or inherited from an earlier daughter. */
466
+ leftHasMethod: boolean;
467
+ leftAdministrationContext: boolean;
468
+ rightExplicitHead: boolean;
469
+ leftHasSite: boolean;
470
+ rightHasSite: boolean;
471
+ targetsDistinct: boolean;
472
+ leftHasSchedule: boolean;
473
+ rightHasSchedule: boolean;
474
+ leftHasCadence: boolean;
475
+ rightHasCadence: boolean;
476
+ /** An independently scoped administration modifier without an invented cadence. */
477
+ rightHasAdministrationAdjunct?: boolean;
478
+ leftHasCourseDuration: boolean;
479
+ rightHasCourseDuration: boolean;
480
+ leftHasPrn: boolean;
481
+ rightHasPrn: boolean;
482
+ leftHasFrontedSchedule: boolean;
483
+ leftHasFrontedPrn: boolean;
484
+ rightHasTrailingSchedule: boolean;
485
+ rightHasTrailingCourseDuration: boolean;
486
+ rightHasTrailingPrn: boolean;
487
+ /** A typed, exact trailing clinical predicate/exclusion whose mother scope is unresolved. */
488
+ rightHasTrailingSafetyGuard: boolean;
489
+ }
490
+ /** Typed facts for a terminal negative instruction scoped over one regimen. */
491
+ export interface TrailingInstructionScopeFacts {
492
+ /** HPSG parsed a local negative action after the terminal semicolon. */
493
+ localNegativeAction: boolean;
494
+ /** The terminal action is separated from the administration by grammar evidence. */
495
+ semicolonDelimited: boolean;
496
+ /** Segment relations connect this recipient to the terminal donor. */
497
+ related: boolean;
498
+ /** Route identity is shared with the terminal administration. */
499
+ sameRoute: boolean;
500
+ /** Missing methods are compatible; two explicit methods must agree. */
501
+ compatibleMethod: boolean;
502
+ relationPath: readonly BoundaryRelation[];
503
+ }
504
+ export type RegimenSemanticOperation = 'share-trailing-cadence' | 'share-trailing-adjuncts' | 'share-trailing-course-duration' | 'share-trailing-instruction' | 'share-leading-adjuncts' | 'preserve-disjunctive-dosages' | 'inherit-event-timing-administration' | 'inherit-event-timing-and-share-trailing-course-duration' | 'inherit-administration-head' | 'inherit-administration-head-and-share-trailing-course-duration' | 'preserve-ambiguous-shared-guard';
505
+ export interface RegimenSemanticConstruction {
506
+ id: string;
507
+ priority: number;
508
+ operation: RegimenSemanticOperation;
509
+ }
510
+ export interface RegimenSemanticSelection {
511
+ construction: RegimenSemanticConstruction;
512
+ evidence: Evidence[];
513
+ }
@@ -44,5 +44,20 @@ export declare function featureAtom(value: unknown, type?: HpsgFeatureAtom["type
44
44
  export declare function validateFeatureStructureShallow(value: HpsgFeatureNode, typeSystem: HpsgTypeSystem, path?: string): HpsgFeatureValidationIssue[];
45
45
  export declare function validateFeatureStructure(value: HpsgFeatureValue, typeSystem: HpsgTypeSystem, path?: string, visited?: Set<HpsgFeatureNode>): HpsgFeatureValidationIssue[];
46
46
  export declare function unifyFeatureStructures(left: HpsgFeatureValue, right: HpsgFeatureValue, typeSystem: HpsgTypeSystem): HpsgUnificationResult;
47
- export declare function canonicalFeatureStructure(value: HpsgFeatureValue): string;
47
+ /** A structured diagnostic view, with explicit references for reentrant nodes. */
48
+ export type CanonicalFeatureView = {
49
+ atom: string;
50
+ value: unknown;
51
+ } | {
52
+ ref: number;
53
+ } | {
54
+ id: number;
55
+ type: string;
56
+ features: Record<string, CanonicalFeatureView>;
57
+ };
58
+ /** Export an inspectable graph, not a serialized string. Consumers that need a
59
+ * wire/log format can encode it at their own I/O boundary.
60
+ * @param value Feature graph to inspect outside the unifier.
61
+ */
62
+ export declare function canonicalFeatureStructure(value: HpsgFeatureValue): CanonicalFeatureView;
48
63
  export declare const HPSG_TYPE_SYSTEM: HpsgTypeSystem;
@@ -3,6 +3,7 @@ import { RouteCode } from "../types";
3
3
  export interface HpsgUnificationContext {
4
4
  normalizeSiteText(text: string): string;
5
5
  isCompatibleRouteRefinement(current: RouteCode | undefined, next: RouteCode): boolean;
6
+ sourceText?(start: number, end: number): string;
6
7
  }
7
8
  export declare function unifySynsem(left: HpsgSynsem, right: HpsgSynsem, context: HpsgUnificationContext): HpsgSynsem | undefined;
8
9
  export declare function combineSigns(left: HpsgSign, right: HpsgSign, context: HpsgUnificationContext, rule: string): HpsgSign | undefined;
package/dist/i18n.d.ts CHANGED
@@ -32,4 +32,6 @@ export type SigTranslationConfig = SigLocalizationConfig;
32
32
  export declare const registerSigTranslation: typeof registerSigLocalization;
33
33
  export declare const getRegisteredSigTranslations: typeof getRegisteredSigLocalizations;
34
34
  export declare function resolveSigTranslation(locale?: string, config?: SigTranslationConfig): SigTranslation | undefined;
35
+ export declare const DAY_NAMES_THAI: Record<string, string>;
35
36
  export declare const THAI_SITE_TRANSLATIONS: Record<string, string>;
37
+ export declare function joinWithAndThai(parts: string[]): string;