ezmedicationinput 0.1.67 → 0.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +222 -28
  2. package/dist/adapters/canonical-course.d.ts +128 -0
  3. package/dist/adapters/r5-course.d.ts +24 -0
  4. package/dist/advice.d.ts +52 -1
  5. package/dist/body-site-grammar.d.ts +34 -1
  6. package/dist/body-site-lookup.d.ts +3 -0
  7. package/dist/body-site-spatial.d.ts +6 -2
  8. package/dist/body-site-target.d.ts +9 -3
  9. package/dist/canonical/compile.d.ts +79 -0
  10. package/dist/canonical/course.d.ts +352 -0
  11. package/dist/canonical/format-course.d.ts +36 -0
  12. package/dist/date-interpretation.d.ts +2 -0
  13. package/dist/dosage-course.d.ts +453 -0
  14. package/dist/execution/calendar.d.ts +107 -0
  15. package/dist/execution/engine.d.ts +11 -0
  16. package/dist/fhir-quantity-operator.d.ts +53 -0
  17. package/dist/fhir-translations.d.ts +5 -6
  18. package/dist/fhir.d.ts +233 -13
  19. package/dist/format.d.ts +113 -3
  20. package/dist/hpsg/constructions.d.ts +113 -0
  21. package/dist/hpsg/defaults.d.ts +2 -0
  22. package/dist/hpsg/lexical-classes.d.ts +282 -2
  23. package/dist/hpsg/procedural-context.d.ts +18 -4
  24. package/dist/hpsg/projection.d.ts +38 -3
  25. package/dist/hpsg/rule-context.d.ts +117 -7
  26. package/dist/hpsg/rules/clinical-quantity-rules.d.ts +18 -0
  27. package/dist/hpsg/rules/condition-rules.d.ts +14 -0
  28. package/dist/hpsg/rules/core-rules.d.ts +32 -0
  29. package/dist/hpsg/rules/instruction-rules.d.ts +11 -1
  30. package/dist/hpsg/rules/prn-rules.d.ts +3 -1
  31. package/dist/hpsg/rules/timing-rules.d.ts +138 -8
  32. package/dist/hpsg/signature.d.ts +353 -5
  33. package/dist/hpsg/type-system.d.ts +16 -1
  34. package/dist/hpsg/unification.d.ts +4 -1
  35. package/dist/i18n.d.ts +39 -1
  36. package/dist/index.cjs +65539 -30893
  37. package/dist/index.d.ts +35 -7
  38. package/dist/index.js +65505 -30892
  39. package/dist/instruction-action-locale-adapter.d.ts +32 -3
  40. package/dist/instruction-action-terminology.d.ts +38 -3
  41. package/dist/instruction-concept-terminology.d.ts +8 -1
  42. package/dist/instruction-graph-fhir.d.ts +9 -3
  43. package/dist/instruction-graph.d.ts +85 -7
  44. package/dist/ir.d.ts +13 -2
  45. package/dist/lexer/surface-segmenter.d.ts +1 -1
  46. package/dist/lexer/surface.d.ts +1 -0
  47. package/dist/locale-detection.d.ts +3 -0
  48. package/dist/locales/course/en.d.ts +15 -0
  49. package/dist/locales/course/th.d.ts +12 -0
  50. package/dist/localization.d.ts +73 -0
  51. package/dist/maps.d.ts +24 -1
  52. package/dist/medication-condition.d.ts +42 -0
  53. package/dist/parser-state.d.ts +6 -2
  54. package/dist/parser.d.ts +5 -2
  55. package/dist/regimen/coordination-scope.d.ts +53 -0
  56. package/dist/regimen/grammar.d.ts +79 -0
  57. package/dist/regimen/parallel-course.d.ts +52 -0
  58. package/dist/regimen/planner.d.ts +19 -0
  59. package/dist/regimen/regimen.d.ts +70 -0
  60. package/dist/relation-terminology.d.ts +1 -0
  61. package/dist/schedule.d.ts +12 -5
  62. package/dist/stable-structure.d.ts +23 -1
  63. package/dist/timing-summary.d.ts +82 -1
  64. package/dist/types.d.ts +899 -40
  65. package/dist/unit-lexicon.d.ts +7 -0
  66. package/dist/utils/strength.d.ts +16 -0
  67. package/dist/utils/text.d.ts +3 -0
  68. package/dist/utils/units.d.ts +19 -0
  69. package/package.json +3 -2
package/dist/fhir.d.ts CHANGED
@@ -1,16 +1,208 @@
1
+ import type { ParseOptions } from "./types";
2
+ import type { HpsgClinicalQuantityFeature } from "./hpsg/signature";
1
3
  import { ParserState } from "./parser-state";
2
- import { CanonicalOccurrenceCapExpr, CanonicalSigClause, FhirDosage, FhirTimingRepeat } from "./types";
3
- export declare const TIMING_FREQUENCY_MIN_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-frequency-min";
4
- export declare const TIMING_OFFSET_MIN_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-offset-min";
5
- export declare const TIMING_OFFSET_MAX_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-offset-max";
6
- export declare const TIMING_OFFSET_EXACT_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-offset-exact";
7
- export declare const TIMING_ACTIVITY_WINDOW_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-activity-window";
8
- export declare const TIMING_OCCURRENCE_CAP_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-occurrence-cap";
9
- export declare const TIMING_EVENT_CALENDAR_SOURCE_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-event-calendar-source";
10
- export declare const PRN_TRIGGER_PHASE_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-prn-trigger-phase";
11
- export declare function getExactTimingOffsetMinutes(repeat: FhirTimingRepeat | undefined): number | undefined;
12
- export declare function getTimingOccurrenceCap(repeat: FhirTimingRepeat | undefined): CanonicalOccurrenceCapExpr | undefined;
4
+ import { CanonicalAdditionalInstructionExpr, CanonicalInstructionGraph, CanonicalActivityTimingExpr, CanonicalCycleDayConstraint, CanonicalOccurrenceCapExpr, CanonicalDoseRange, CanonicalSigClause, CanonicalScheduleExpr, EventTiming, FhirCodeableConcept, FhirR6CodeableConcept, FhirDosage, FhirExtension, FhirR6Extension, FhirR6Dosage, FhirR6Quantity, FhirRange, FhirR6Range, FhirTiming, FhirTimingRepeat, FhirR6TimingRepeat } from "./types";
5
+ /** Known modifier: an independent cadence is restricted by unresolved cycle days. */
6
+ export declare const CYCLE_DAY_ELIGIBILITY_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-cycle-day-eligibility";
7
+ /** Read the recognized cycle constraint without interpreting narrative text.
8
+ * @param dosage Editable R5/R6-compatible dosage with a retained known modifier.
9
+ */
10
+ export declare function getCycleDayConstraint(dosage: FhirDosage | FhirR6Dosage): CanonicalCycleDayConstraint | undefined;
11
+ /** Preserve the source-decided cycle restriction as a genuine dosage modifier.
12
+ * @param constraint Recognized cycle ordinals and the unresolved calendar dependency.
13
+ */
14
+ export declare function cycleDayConstraintExtension(constraint: CanonicalCycleDayConstraint, previous?: FhirExtension): FhirExtension;
15
+ export declare const TIMING_FREQUENCY_MIN_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-frequency-min";
16
+ /** Qualified per-administration duration, independent of a scalar rate denominator. */
17
+ export declare const TIMING_ADMINISTRATION_DURATION_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:timing-administration-duration";
18
+ /** Decode one classified marker without flattening independent endpoints. */
19
+ export declare function parseTimingAdministrationDuration(extension: FhirR6Extension | undefined, current?: Pick<FhirTimingRepeat, "duration" | "durationMax" | "durationUnit">): (Partial<NonNullable<HpsgClinicalQuantityFeature["administrationDuration"]>> & {
20
+ range?: import("./canonical/course").CanonicalRange;
21
+ }) | undefined;
22
+ /** Modifier: each retained base-schedule opportunity occurs this many minutes later. */
23
+ export declare const ADMINISTRATION_OFFSET_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-administration-offset";
24
+ export declare function getAdministrationOffsetMinutes(dosage: FhirDosage | FhirR6Dosage): number | undefined;
25
+ /** Modifier retaining a course duration alongside its absolute calendar bounds. */
26
+ export declare const ANCHORED_COURSE_DURATION_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-anchored-course-duration";
27
+ /** Read the authored temporal quantity without reconstructing it from dates or text.
28
+ * @param dosage R5/R6-compatible dosage containing the known duration modifier.
29
+ * @returns The retained duration quantity or range, when supplied.
30
+ */
31
+ export declare function getAnchoredCourseDuration(dosage: Pick<FhirR6Dosage, "modifierExtension"> & {
32
+ timing?: {
33
+ repeat?: {
34
+ boundsRange?: FhirR6Range;
35
+ boundsDuration?: FhirR6Quantity;
36
+ };
37
+ };
38
+ }): Pick<FhirR6Extension, "valueQuantity" | "valueRange"> | undefined;
39
+ /** Core Range endpoints share one unit identity. The known duration modifier
40
+ * keeps both authored endpoints as active quantities when the wire range needs
41
+ * a common label or cannot express mixed elapsed/calendar units. */
42
+ export declare function projectCourseDurationRange(range: FhirRange): {
43
+ range: FhirRange;
44
+ source?: FhirExtension;
45
+ };
46
+ export declare function projectCourseDurationRange(range: FhirR6Range): {
47
+ range: FhirR6Range;
48
+ source?: FhirR6Extension;
49
+ };
50
+ export declare const TIMING_OFFSET_MIN_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-offset-min";
51
+ export declare const TIMING_OFFSET_MAX_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-offset-max";
52
+ export declare const TIMING_OFFSET_EXACT_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-offset-exact";
53
+ export declare const TIMING_ACTIVITY_WINDOW_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-activity-window";
54
+ /** Recurring administration opportunity window; distinct from a punctual
55
+ * FHIR Timing.repeat.when WAKE or HS administration. */
56
+ export declare const TIMING_EVENT_WINDOW_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-event-window";
57
+ /** Independent clocks combined with event anchors share one recurrence/count.
58
+ * R5 and the current R6 pin forbid both core fields in that recurrence (tim-10). */
59
+ export declare const TIMING_ADDITIONAL_CLOCK_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-additional-clock";
60
+ /** Wire primitive arrays contain metadata-only null positions. The clinical
61
+ * event list keeps values only, while the owning Timing retains wire positions. */
62
+ export declare function getTimingEvents(timing: Pick<FhirTiming, "event"> | undefined): string[] | undefined;
63
+ /** Core clock values take priority over the bridge. Null primitive positions
64
+ * carry metadata only; an explicitly empty clock array remains an empty field. */
65
+ export declare function getTimingClocks(repeat: Pick<FhirR6TimingRepeat, "timeOfDay" | "extension"> | undefined): string[] | undefined;
66
+ /** Independent event and clock opportunities share one wire recurrence.
67
+ * The original wire repeat distinguishes a bridge read from a current core edit;
68
+ * no administration/count/cap is split, and retired carriers cannot revive. */
69
+ export declare function projectTimingClocks<T extends Pick<FhirR6TimingRepeat, "timeOfDay" | "_timeOfDay" | "when" | "_when" | "extension">>(repeat: T, wireSource?: Pick<FhirTimingRepeat, "timeOfDay">, target?: "r5" | "r6"): T;
70
+ export declare const TIMING_CLOCK_WINDOW_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-clock-window";
71
+ /** Read a local-clock recurrence window from structural timing metadata.
72
+ * @param repeat FHIR Timing.repeat containing a typed window extension.
73
+ * @returns Source clock endpoints and explicit endpoint inclusivity.
74
+ */
75
+ export declare function getTimingClockWindow(repeat: FhirR6TimingRepeat | undefined): {
76
+ start: string;
77
+ end: string;
78
+ endInclusive: boolean;
79
+ } | undefined;
80
+ /** Standard HL7 extension for day-of-month timing (repeatable positive integer). */
81
+ export declare const TIMING_DAY_OF_MONTH_EXTENSION_URL = "http://hl7.org/fhir/StructureDefinition/timing-dayOfMonth";
82
+ /** Retrieve bounded executable month-day selection without interpreting prose.
83
+ * Unknown and malformed extensions remain in the original FHIR object.
84
+ * @param repeat Original FHIR R5/R6 Timing.repeat with optional standard extensions.
85
+ * @returns Sorted unique calendar days, or undefined when none are recognized.
86
+ */
87
+ export declare function getTimingMonthDays(repeat: FhirR6TimingRepeat | undefined): number[] | undefined;
88
+ export declare const TIMING_WEEKDAY_ORDINAL_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-weekday-ordinal";
89
+ /** Read the explicitly encoded ordinal, independent of prose and scheduling anchors.
90
+ * @param repeat Typed FHIR timing repeat containing an optional ordinal extension.
91
+ * @returns The source weekday occurrence, including -1 for last, when valid.
92
+ */
93
+ export declare function getTimingWeekdayOrdinal(repeat: FhirR6TimingRepeat | undefined): -1 | 1 | 2 | 3 | 4 | 5 | undefined;
94
+ /** Read an explicitly encoded daily event window without examining SIG text. */
95
+ export declare function getTimingEventWindow(repeat: FhirR6TimingRepeat | undefined): {
96
+ start: EventTiming;
97
+ end: EventTiming;
98
+ } | undefined;
99
+ export declare const TIMING_OCCURRENCE_CAP_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-occurrence-cap";
100
+ /** Internal current recurrence fact; deliberately absent from public index exports. */
101
+ export declare const TIMING_SHARED_COUNT_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-shared-count";
102
+ export declare const TIMING_EVENT_CALENDAR_SOURCE_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-event-calendar-source";
103
+ export declare const PRN_TRIGGER_PHASE_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-prn-trigger-phase";
104
+ export declare const BODY_SITE_RESTRICTION_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-body-site-restriction";
105
+ export declare const INFUSION_CARRIER_MATERIAL_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-infusion-carrier-material";
106
+ /** Draft FHIR R5 extension definition, produced from the same typed child
107
+ * contract as the live encoder. Carrier material is a descriptive vehicle
108
+ * role, not a verified drug code or a modified administration choice.
109
+ * External HL7 conformance validation remains a separate release check.
110
+ */
111
+ export declare function buildInfusionCarrierMaterialStructureDefinition(): {
112
+ resourceType: "StructureDefinition";
113
+ id: string;
114
+ url: string;
115
+ name: string;
116
+ title: string;
117
+ status: "draft";
118
+ description: string;
119
+ kind: "complex-type";
120
+ abstract: boolean;
121
+ type: string;
122
+ baseDefinition: string;
123
+ derivation: "constraint";
124
+ context: {
125
+ type: "element";
126
+ expression: string;
127
+ }[];
128
+ differential: {
129
+ element: ({
130
+ id: string;
131
+ path: string;
132
+ sliceName: string;
133
+ min: number;
134
+ max: string;
135
+ type: {
136
+ code: string;
137
+ }[];
138
+ fixedUri?: undefined;
139
+ } | {
140
+ id: string;
141
+ path: string;
142
+ max: string;
143
+ sliceName?: undefined;
144
+ min?: undefined;
145
+ type?: undefined;
146
+ fixedUri?: undefined;
147
+ } | {
148
+ id: string;
149
+ path: string;
150
+ fixedUri: string;
151
+ sliceName?: undefined;
152
+ min?: undefined;
153
+ max?: undefined;
154
+ type?: undefined;
155
+ } | {
156
+ id: string;
157
+ path: string;
158
+ min: number;
159
+ max: string;
160
+ type: {
161
+ code: "string" | "integer";
162
+ }[];
163
+ sliceName?: undefined;
164
+ fixedUri?: undefined;
165
+ } | {
166
+ id: string;
167
+ path: string;
168
+ isModifier: boolean;
169
+ slicing?: undefined;
170
+ } | {
171
+ id: string;
172
+ path: string;
173
+ slicing: {
174
+ discriminator: {
175
+ type: string;
176
+ path: string;
177
+ }[];
178
+ ordered: boolean;
179
+ rules: string;
180
+ };
181
+ isModifier?: undefined;
182
+ })[];
183
+ };
184
+ };
185
+ /** Preserve a clinically named vehicle without claiming it has a verified
186
+ * terminology identity. This describes the volume-owned material and never
187
+ * changes dose/rate scheduling or converts a vehicle into the active drug.
188
+ */
189
+ export declare function infusionCarrierMaterialExtension(material: NonNullable<HpsgClinicalQuantityFeature["carrierMaterial"]>): FhirExtension;
190
+ /** Reconstitute dimensional R5 meaning only where the role and amount were
191
+ * explicitly supplied. Other external rateRatio dosages remain untouched.
192
+ */
193
+ export declare function clinicalCarrierQuantityFromFhir(dosage: FhirDosage): HpsgClinicalQuantityFeature | undefined;
194
+ export declare function parsePrnTriggerPhase(concept: FhirR6CodeableConcept | undefined): "onset" | undefined;
195
+ export declare function getExactTimingOffsetMinutes(repeat: FhirR6TimingRepeat | undefined): number | undefined;
196
+ /** Read the explicit shared allowance, never derive membership from source or phase IDs. */
197
+ export declare function getTimingSharedCount(repeat: FhirR6TimingRepeat | undefined): CanonicalScheduleExpr["sharedCount"];
198
+ export declare function getTimingOccurrenceCap(repeat: FhirR6TimingRepeat | undefined): CanonicalOccurrenceCapExpr | undefined;
199
+ /** Read typed activity-event relations from Timing extensions without parsing
200
+ * narrative instructions or inferring an activity's calendar instant.
201
+ */
202
+ export declare function parseActivityTimingExtensions(repeat: FhirR6TimingRepeat | undefined): CanonicalActivityTimingExpr[] | undefined;
13
203
  export interface FhirProjectionOptions {
204
+ /** Typed regimen-graph sequence; serialized without inferring phase meaning. */
205
+ sequence?: number;
14
206
  /**
15
207
  * Defaults to true. When true, structured spatial body-site phrases such as
16
208
  * "top of head" can emit a SNOMED topographical modifier expression in
@@ -23,7 +215,35 @@ export interface FhirProjectionOptions {
23
215
  */
24
216
  includeTranslationExtensions?: boolean;
25
217
  }
218
+ export declare function createEmptyCanonicalClause(rawText: string): CanonicalSigClause;
219
+ export declare function extractCanonicalDoseRange(range: FhirRange): {
220
+ range?: CanonicalDoseRange;
221
+ unit?: string;
222
+ warning?: string;
223
+ };
224
+ /** Shared FHIR terminology/source serializer for BOTH output versions.
225
+ * This serializes coded context only; no course, dose or scheduling semantics
226
+ * are read back from this interchange object. R5/R6 adapters own their own
227
+ * quantity and timing choices around the same exact clinical code payload. */
228
+ export declare function serializeCanonicalContext(clause: CanonicalSigClause, options?: FhirProjectionOptions): Pick<FhirDosage, "extension" | "route" | "site" | "method" | "additionalInstruction" | "asNeeded" | "asNeededFor" | "patientInstruction">;
229
+ /** Core Timing offsets require a nonnegative integer and a qualified event anchor. */
230
+ export declare function canUseCoreTimingOffset(when: readonly (string | null)[] | undefined, offset: number | undefined): boolean;
231
+ /** Shared wire Timing/source metadata serializer. This projects the already
232
+ * scoped canonical schedule; it never parses or interprets external dosage.
233
+ * R5 and current-R6 adapters independently choose their Quantity encodings. */
234
+ export declare function serializeCanonicalSchedule(schedule: CanonicalSigClause["schedule"], options?: FhirProjectionOptions, clinicalQuantity?: HpsgClinicalQuantityFeature, asNeeded?: boolean): Pick<FhirDosage, "timing" | "modifierExtension">;
235
+ /** Project only independent typed warnings; related actions keep their graph scope.
236
+ * Existing standard entries are never rewritten or removed. Generated wording
237
+ * comes from the selected action/arguments, not the graph's authored source.
238
+ */
239
+ export declare function independentGraphWarningAdvice(graph: CanonicalInstructionGraph | undefined, typed: readonly CanonicalAdditionalInstructionExpr[] | undefined): FhirCodeableConcept[] | undefined;
26
240
  export declare function canonicalToFhir(clause: CanonicalSigClause, textOverride?: string, options?: FhirProjectionOptions): FhirDosage;
27
241
  export declare function toFhir(state: ParserState): FhirDosage;
28
- export declare function canonicalFromFhir(dosage: FhirDosage): CanonicalSigClause;
29
- export declare function parserStateFromFhir(dosage: FhirDosage): ParserState;
242
+ /** Decode common coded source annotations for either FHIR version.
243
+ * No dose, rate, Timing, course, or compatibility marker is interpreted here.
244
+ * Native-course import supplies an R6 CodeableReference's concept explicitly. */
245
+ export declare function deserializeCanonicalContext(dosage: Pick<FhirR6Dosage, "text" | "route" | "method" | "asNeeded" | "asNeededFor" | "additionalInstruction" | "patientInstruction" | "extension"> & {
246
+ site?: FhirR6CodeableConcept;
247
+ }, options?: ParseOptions): CanonicalSigClause;
248
+ export declare function canonicalFromFhir(dosage: FhirDosage, options?: ParseOptions): CanonicalSigClause;
249
+ export declare function parserStateFromFhir(dosage: FhirDosage, options?: ParseOptions): ParserState;
package/dist/format.d.ts CHANGED
@@ -1,6 +1,116 @@
1
+ import type { CourseLanguage } from "./localization";
1
2
  import { ParserState } from "./parser-state";
2
- import type { SigLocalization } from "./i18n";
3
- import { CanonicalSigClause } from "./types";
3
+ import { type SigLocalization, type SigLongContext, type SigDoseScope } from "./i18n";
4
+ import { type InstructionGraphPrimaryCondition } from "./instruction-graph";
5
+ import { type AdviceFrame, type CanonicalAdditionalInstructionExpr, CanonicalDoseExpr, CanonicalScheduleExpr, CanonicalSigClause, EventTiming, FhirPeriodUnit, type MedicationCondition, type FhirDayOfWeek } from "./types";
4
6
  import { type TimingSummaryOptions } from "./timing-summary";
5
- export declare function formatCanonicalClause(clause: CanonicalSigClause, style: "short" | "long", localization?: SigLocalization, options?: TimingSummaryOptions): string;
7
+ export declare const DAY_NAMES: Record<string, string>;
8
+ /** A method can name a registered manner rather than an action head. */
9
+ export declare function registeredMethodManner(method: CanonicalSigClause["method"], resolvedMethod?: SigLongContext["resolvedMethod"]): import("./types").AdditionalInstructionDefinition | undefined;
10
+ export declare function alternateDayEvent(schedule: CanonicalScheduleExpr | undefined): EventTiming | undefined;
11
+ /** Daily recurrence applies to every explicit clock, not one occurrence in total.
12
+ * Presentation may say "daily at ..." without rewriting the stored frequency.
13
+ * Explicit ranges and counts other than one retain their authored summary.
14
+ * @param schedule Typed timing to realize; source text is never inspected.
15
+ */
16
+ export declare function hasDailyRecurrenceAcrossClocks(schedule: CanonicalScheduleExpr | undefined): boolean;
17
+ type FrequencyDisplayMode = "daily" | "daily-count" | "daily-range" | "daily-maximum" | "period" | "period-maximum" | "alternate-days" | "calendar-count" | "calendar-range" | "calendar-maximum" | "code" | "code-period" | "count" | "count-bounds";
18
+ interface FrequencyDisplay {
19
+ mode: FrequencyDisplayMode;
20
+ countPrefix: "none" | "count" | "range" | "maximum";
21
+ frequency?: number;
22
+ frequencyMax?: number;
23
+ period?: number;
24
+ periodMax?: number;
25
+ periodUnit?: FhirPeriodUnit;
26
+ rangeEnd?: number;
27
+ timingCode?: string;
28
+ codePeriod?: {
29
+ period: number;
30
+ periodUnit: FhirPeriodUnit;
31
+ };
32
+ }
33
+ /** Select clinical display meaning once; each locale retains its wording. */
34
+ export declare function frequencyDisplay(schedule: CanonicalScheduleExpr | undefined, uppercaseTimingCode?: boolean): FrequencyDisplay | undefined;
35
+ export declare function standaloneOccurrenceCount(schedule: CanonicalScheduleExpr | undefined): number | undefined;
36
+ /** A typed scalar/range, or an already complete native rich amount, can be
37
+ * labelled without selecting it as the administration's prescribed dose. */
38
+ export declare function formatDoseEnglish(dose: CanonicalDoseExpr | string, style: "short" | "long", scope?: SigDoseScope): string | undefined;
39
+ export declare function joinWithAnd(parts: string[]): string;
40
+ /** Discrete doses distribute across paired targets; metric amounts are totals. */
41
+ export declare function doseUnitUsesTargetScope(unit: string | undefined): boolean;
42
+ /** Whether the recurrence supports describing selected days as occurring each month. */
43
+ export declare function dayOfMonthUsesSingleMonth(schedule: CanonicalScheduleExpr | undefined): boolean;
44
+ export declare function formatDurationShort(schedule: CanonicalScheduleExpr): string | undefined;
45
+ export interface DurationWording {
46
+ readonly locale: string;
47
+ readonly coursePrefix: string;
48
+ readonly administrationPrefix: string;
49
+ readonly administrationShortPrefix: string;
50
+ readonly range: string;
51
+ readonly upper: string;
52
+ readonly lower: string;
53
+ administrationUnit(unit: FhirPeriodUnit, value: number | undefined, maximum: number | undefined, short: boolean, words: CourseLanguage): string;
54
+ }
55
+ export declare function describeDuration(schedule: CanonicalScheduleExpr | undefined, words: CourseLanguage, text?: DurationWording): string | undefined;
56
+ export declare function describeAdministrationDuration(schedule: CanonicalScheduleExpr | undefined, short?: boolean, words?: CourseLanguage, text?: DurationWording, prefix?: string): string | undefined;
57
+ /** Preserve free labels; recognized cadence prose yields to a typed recurrence. */
58
+ export declare function independentTimingText(code: string | undefined, recurrence?: Pick<CanonicalScheduleExpr, "frequency" | "frequencyMax" | "period" | "periodMax" | "periodUnit">): string | undefined;
59
+ export declare function timingCodeMatchesRecurrence(schedule: Pick<CanonicalScheduleExpr, "timingCode" | "frequency" | "frequencyMax" | "period" | "periodMax" | "periodUnit" | "when" | "timeOfDay">, code?: string | undefined): boolean;
60
+ /** A code-only event supplies display meaning without changing authored timing. */
61
+ export declare function timingEventPreviewSchedule(schedule: CanonicalScheduleExpr | undefined): CanonicalScheduleExpr | undefined;
62
+ interface LongAdministrationTimingParts {
63
+ frequency?: string;
64
+ event?: string;
65
+ eventWindow?: string;
66
+ clockWindow?: string;
67
+ activities: string[];
68
+ calendarEvents?: string;
69
+ dayOfWeek?: string;
70
+ dayOfMonth?: string;
71
+ calendarBounds?: string;
72
+ count?: string;
73
+ administrationDuration?: string;
74
+ duration?: string;
75
+ occurrenceCap?: string;
76
+ }
77
+ interface RichAdministrationParts {
78
+ route?: string;
79
+ frequencyWithoutEvent?: string;
80
+ independentTiming?: string;
81
+ clock?: string;
82
+ asNeeded?: string;
83
+ site?: string;
84
+ coversSingleEvent: boolean;
85
+ }
86
+ /** Locale realizers supply words; their clinical timing order is shared. */
87
+ export declare function describeClockWindow(schedule: CanonicalScheduleExpr | undefined, timing?: {
88
+ sharedAdministration: (body: string, total?: string) => string;
89
+ clockWindow: (start: string, end: string, inclusive: boolean) => string;
90
+ offset: (minutes: number) => string;
91
+ dayShift: (days: number) => string;
92
+ }): string | undefined;
93
+ export declare function appendLongAdministrationTiming(parts: string[], timing: LongAdministrationTimingParts, richTiming?: RichAdministrationParts): void;
94
+ export declare function richGraphAdministrationTail(clause: CanonicalSigClause, action: AdviceFrame, timing: LongAdministrationTimingParts, parts: RichAdministrationParts): string[];
95
+ export declare function instructionGraphMatchesDose(clause: CanonicalSigClause): boolean;
96
+ export declare function instructionGraphActionHasSequenceSuccessor(clause: CanonicalSigClause, action: AdviceFrame | undefined): boolean;
97
+ export declare function hasExplicitAdministrationMethod(clause: CanonicalSigClause): boolean;
98
+ export declare function instructionGraphCanStandAlone(clause: CanonicalSigClause, timingText: string | undefined, graphRepresentsDose: boolean, richPrimaryAction: AdviceFrame | undefined, graphText: string | undefined, primaryConditions: InstructionGraphPrimaryCondition[] | undefined): boolean;
99
+ /** Calendar qualifiers use locale-owned labels and stay on their medication
100
+ * primary before independent instructions are composed. */
101
+ export declare function appendClinicalCalendarText(text: string, dates: readonly string[] | undefined, weekdays: readonly FhirDayOfWeek[] | undefined, words: CourseLanguage): string;
102
+ /** A source-only primary and its recognized cadence describe one medication.
103
+ * Qualify that complete primary before independent advice is composed. */
104
+ export declare function composeNativePrimaryDirections(rendered: string, authored: string | undefined, condition: MedicationCondition | undefined, words: CourseLanguage, deferredDirections?: {
105
+ text?: string;
106
+ current?: string;
107
+ }, clause?: CanonicalSigClause): string;
108
+ export declare function isEmptyStomachInstruction(instruction: CanonicalAdditionalInstructionExpr): boolean;
109
+ export declare function formatNativeCanonicalClause(clause: CanonicalSigClause, style: "short" | "long", localization?: SigLocalization, options?: TimingSummaryOptions, authoredPrimary?: string, deferredDirections?: {
110
+ text?: string;
111
+ current?: string;
112
+ }, sharedCountAlreadyDisplayed?: boolean): string;
113
+ export declare function formatCanonicalClause(clause: CanonicalSigClause, style: "short" | "long", localization?: SigLocalization, options?: TimingSummaryOptions, nativeDefault?: (target: "short" | "long") => string): string;
6
114
  export declare function formatInternal(internal: ParserState, style: "short" | "long", localization?: SigLocalization, options?: TimingSummaryOptions): string;
115
+ export declare function stripTrailingZero(value: number): string;
116
+ export {};
@@ -1,6 +1,119 @@
1
+ import type { Token } from "../parser-state";
2
+ import type { MedicationCondition, ParseOptions } from "../types";
3
+ import { AdviceArgumentRole, AdviceRelation, type AdviceArgument, type AdviceFrame } from "../types";
1
4
  import type { HpsgConstruction, HpsgSign, HpsgType } from "./signature";
5
+ import type { BoundaryRelation, CoordinationScopeFacts, RegimenSemanticSelection } from "./signature";
2
6
  export interface HpsgConstructionSelection {
3
7
  motherType: HpsgType;
4
8
  construction: HpsgConstruction;
5
9
  }
10
+ export interface HpsgCoordinationScopeSelection extends HpsgConstructionSelection {
11
+ semantic: RegimenSemanticSelection;
12
+ }
13
+ /** Typed daughter facts for one administration with coordinated timing anchors. */
14
+ export interface HpsgTimingAnchorCoordinationFacts {
15
+ relation?: BoundaryRelation;
16
+ sameSourceExpansion: boolean;
17
+ adjacent: boolean;
18
+ leftComplete: boolean;
19
+ rightComplete: boolean;
20
+ sameAdministration: boolean;
21
+ compatibleMethod: boolean;
22
+ leftHasMethod: boolean;
23
+ rightHasMethod: boolean;
24
+ leftAnchorOnly: boolean;
25
+ rightAnchorOnly: boolean;
26
+ sameScheduleContext: boolean;
27
+ addsAnchor: boolean;
28
+ /** The left event is already the first equal-dose occurrence of the right interval. */
29
+ originOfRightInterval?: boolean;
30
+ }
31
+ export interface HpsgTimingAnchorCoordinationSelection extends HpsgConstructionSelection {
32
+ id: "hpsg.cx.regimen.coordinated-timing-anchors" | "hpsg.cx.regimen.interval-origin";
33
+ scheduleComposition: "union-anchors" | "right-interval";
34
+ }
6
35
  export declare function selectHpsgConstruction(left: HpsgSign, right: HpsgSign): HpsgConstructionSelection | undefined;
36
+ /**
37
+ * Select a construction over two already chart-parsed administration clauses.
38
+ * This is the cross-clause counterpart of `selectHpsgConstruction`: the chart
39
+ * daughters retain their own dose/site values while the licensed adjunct
40
+ * daughter scopes over the coordinated phrase. An alternative has no head:
41
+ * neither daughter is privileged as the executable administration.
42
+ */
43
+ export declare function selectHpsgCoordinationScopeConstruction(facts: CoordinationScopeFacts): HpsgCoordinationScopeSelection | undefined;
44
+ /**
45
+ * License two complete administration daughters as one dosage with coordinated
46
+ * timing anchors. Sequence and alternative relations remain separate phases;
47
+ * a meal-dash expansion is already one source construction and needs no
48
+ * surface connector relation.
49
+ */
50
+ export declare function selectHpsgTimingAnchorCoordinationConstruction(facts: HpsgTimingAnchorCoordinationFacts): HpsgTimingAnchorCoordinationSelection | undefined;
51
+ /** Source-typed calendar alternatives can omit a shared clock and head. */
52
+ export interface HpsgCalendarClockEllipsisFacts {
53
+ relation: BoundaryRelation;
54
+ adjacent: boolean;
55
+ calendarAlternatives: boolean;
56
+ compatibleAdministration: boolean;
57
+ omittedHead: boolean;
58
+ omittedClock: boolean;
59
+ /** Every antecedent contributes its clock; absence or disagreement blocks binding. */
60
+ donorClocks: readonly (string | undefined)[];
61
+ }
62
+ export declare function selectHpsgCalendarClockEllipsisConstruction(facts: HpsgCalendarClockEllipsisFacts): (HpsgConstructionSelection & {
63
+ id: string;
64
+ timeOfDay: string[];
65
+ }) | undefined;
66
+ /**
67
+ * A shared directive scopes over coordinated action daughters. An explicit
68
+ * directive on the right starts its own scope; sequencing is not coordination.
69
+ * A trailing duration is an adjunct of the coordinated prohibition, not a
70
+ * medication-course bound. This construction consumes typed action meaning.
71
+ */
72
+ export declare function composeCoordinatedActionDirective(left: AdviceFrame, right: AdviceFrame, coordination: "conjunction" | "disjunction" | "unknown", explicitRightDirective: boolean): readonly [AdviceFrame, AdviceFrame];
73
+ /** A contact clause licenses a preposed physical theme, as in a directive
74
+ * preventing a bottle tip from touching the eye. A nominal and contact head
75
+ * are required; the causative marker cannot turn an ordinary GIVE into this
76
+ * construction or spread negation to an unrelated following action.
77
+ */
78
+ export declare function licensesPreposedContactTheme(role: AdviceArgumentRole, semanticClass?: string): boolean;
79
+ /** Compose the two contact participants under their existing directive scope. */
80
+ export declare function composePreposedContactTheme(frame: AdviceFrame, theme: AdviceArgument): AdviceFrame;
81
+ export interface ParsedMedicationGuard {
82
+ condition: MedicationCondition;
83
+ start: number;
84
+ markerEnd: number;
85
+ end: number;
86
+ text: string;
87
+ otherwiseHold: boolean;
88
+ otherwise?: {
89
+ start: number;
90
+ end: number;
91
+ };
92
+ alternative?: {
93
+ start: number;
94
+ end: number;
95
+ };
96
+ /** Authoritative typed derivation reused by the main clause chart. */
97
+ sign: HpsgSign;
98
+ }
99
+ export declare function guardHasMeasurement(value: MedicationCondition): boolean;
100
+ /** Attach already typed procedural withholding/target scope to the same guard
101
+ * derivation. This retains the predicate daughters in the clause feature graph.
102
+ * @param guard Selected conditional head/predicate analysis.
103
+ * @param scope Existing clinical scope sign (including otherwise-hold ownership).
104
+ */
105
+ export declare function scopeMedicationGuardSign(guard: ParsedMedicationGuard, scope: HpsgSign): HpsgSign;
106
+ /** Single source of medication-guard meaning: lexical daughters compose via
107
+ * HPSG predicate/coordination/head constructions, reused by planner and chart.
108
+ * @param source Exact clinician text.
109
+ * @param existingTokens Already-lexed tokens when the caller has a source context.
110
+ * @param withholdingConsequent License supplied only by a typed medication-withholding action daughter.
111
+ * @param options Registered action vocabulary used by the enclosing clause.
112
+ * @param scope An already selected conditional relation and optional closed predicate span.
113
+ */
114
+ export declare function parseMedicationGuard(source: string, existingTokens?: Token[], withholdingConsequent?: true, options?: ParseOptions, scope?: {
115
+ relation: AdviceRelation;
116
+ start: number;
117
+ markerEnd: number;
118
+ end?: number;
119
+ }): ParsedMedicationGuard | undefined;
@@ -3,6 +3,8 @@ import { ParseOptions, RouteCode } from "../types";
3
3
  export interface HpsgDefaultConstraintDeps {
4
4
  setRoute: (state: ParserState, code: RouteCode, text?: string) => void;
5
5
  }
6
+ /** Resolve the duration under the selected local or inherited administration head. */
7
+ export declare function applyAdministrationDurationSemantics(state: ParserState, options?: ParseOptions, inheritedMethod?: boolean): void;
6
8
  export declare function applyHpsgDefaultConstraints(state: ParserState, tokens: readonly {
7
9
  lower: string;
8
10
  canonical?: string;