ezmedicationinput 0.2.0 → 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 (86) hide show
  1. package/README.md +216 -18
  2. package/dist/adapters/canonical-course.d.ts +131 -0
  3. package/dist/adapters/r5-course.d.ts +27 -0
  4. package/dist/advice-locale-adapter.d.ts +24 -0
  5. package/dist/advice.d.ts +73 -6
  6. package/dist/body-site-grammar.d.ts +21 -2
  7. package/dist/body-site-lookup.d.ts +8 -0
  8. package/dist/body-site-spatial.d.ts +12 -2
  9. package/dist/body-site-target.d.ts +38 -3
  10. package/dist/canonical/compile.d.ts +98 -0
  11. package/dist/canonical/course.d.ts +388 -0
  12. package/dist/canonical/format-course.d.ts +38 -0
  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 +304 -30
  16. package/dist/event-timing-expression.d.ts +26 -1
  17. package/dist/execution/calendar.d.ts +107 -0
  18. package/dist/execution/engine.d.ts +11 -0
  19. package/dist/fhir-quantity-operator.d.ts +89 -0
  20. package/dist/fhir-translations.d.ts +5 -6
  21. package/dist/fhir.d.ts +119 -14
  22. package/dist/format.d.ts +106 -5
  23. package/dist/hpsg/constructions.d.ts +35 -8
  24. package/dist/hpsg/defaults.d.ts +2 -0
  25. package/dist/hpsg/lexical-classes.d.ts +196 -24
  26. package/dist/hpsg/method-lexicon.d.ts +3 -0
  27. package/dist/hpsg/procedural-context.d.ts +48 -5
  28. package/dist/hpsg/projection.d.ts +32 -1
  29. package/dist/hpsg/quantity-lexicon.d.ts +51 -0
  30. package/dist/hpsg/rule-context.d.ts +172 -7
  31. package/dist/hpsg/rules/clinical-quantity-rules.d.ts +16 -7
  32. package/dist/hpsg/rules/condition-rules.d.ts +13 -3
  33. package/dist/hpsg/rules/core-rules.d.ts +8 -2
  34. package/dist/hpsg/rules/instruction-rules.d.ts +2 -0
  35. package/dist/hpsg/rules/prn-rules.d.ts +12 -1
  36. package/dist/hpsg/rules/site-rules.d.ts +10 -1
  37. package/dist/hpsg/rules/timing-rules.d.ts +116 -22
  38. package/dist/hpsg/segmenter.d.ts +2 -2
  39. package/dist/hpsg/signature.d.ts +54 -7
  40. package/dist/hpsg/timing-lexicon.d.ts +18 -2
  41. package/dist/hpsg/unification.d.ts +3 -1
  42. package/dist/i18n.d.ts +37 -1
  43. package/dist/index.cjs +83231 -52284
  44. package/dist/index.d.ts +26 -9
  45. package/dist/index.js +83222 -52284
  46. package/dist/instruction-action-locale-adapter.d.ts +92 -5
  47. package/dist/instruction-action-parser.d.ts +43 -0
  48. package/dist/instruction-action-terminology.d.ts +44 -3
  49. package/dist/instruction-concept-terminology.d.ts +20 -1
  50. package/dist/instruction-graph-fhir.d.ts +10 -2
  51. package/dist/instruction-graph-ownership.d.ts +96 -0
  52. package/dist/instruction-graph.d.ts +68 -49
  53. package/dist/ir.d.ts +1 -1
  54. package/dist/lexer/lex.d.ts +5 -1
  55. package/dist/lexer/locale.d.ts +14 -0
  56. package/dist/lexer/locales/en.d.ts +11 -0
  57. package/dist/lexer/surface-segmenter.d.ts +1 -1
  58. package/dist/lexer/surface.d.ts +4 -1
  59. package/dist/lexer/token-types.d.ts +6 -0
  60. package/dist/locale-detection.d.ts +5 -0
  61. package/dist/locales/clause/en.d.ts +14 -0
  62. package/dist/locales/course/en.d.ts +20 -0
  63. package/dist/locales/course/th.d.ts +12 -0
  64. package/dist/localization.d.ts +76 -0
  65. package/dist/localized-timing.d.ts +1 -1
  66. package/dist/maps.d.ts +44 -10
  67. package/dist/medication-condition.d.ts +72 -11
  68. package/dist/parser-state.d.ts +12 -2
  69. package/dist/parser.d.ts +5 -3
  70. package/dist/prn.d.ts +13 -2
  71. package/dist/regimen/coordination-scope.d.ts +13 -1
  72. package/dist/regimen/grammar.d.ts +18 -1
  73. package/dist/regimen/parallel-course.d.ts +13 -42
  74. package/dist/regimen/planner.d.ts +2 -3
  75. package/dist/regimen/regimen.d.ts +8 -2
  76. package/dist/relation-terminology.d.ts +1 -0
  77. package/dist/schedule.d.ts +14 -10
  78. package/dist/snomed.d.ts +3 -0
  79. package/dist/suggest-locale-adapter.d.ts +15 -0
  80. package/dist/symptom-terminology.d.ts +5 -1
  81. package/dist/timing-summary.d.ts +114 -1
  82. package/dist/types.d.ts +627 -61
  83. package/dist/unit-lexicon.d.ts +4 -1
  84. package/dist/utils/text.d.ts +3 -0
  85. package/dist/utils/units.d.ts +22 -0
  86. package/package.json +1 -1
@@ -0,0 +1,38 @@
1
+ /** Native clinical course realization. This module reads canonical facts
2
+ * and the existing grammar renderer, never FHIR rows or persistence markers.
3
+ * Display stays separate from executable interpretation: unknown expressions
4
+ * and boundaries remain visible without inventing values or event dates. */
5
+ import type { FormatBatchOptions, FormatOptions, MedicationCondition, FhirDayOfWeek, CanonicalSigClause, CanonicalScheduleExpr } from "../types";
6
+ import type { CanonicalCourse, CanonicalAdministration, CanonicalRange, CanonicalExpression, CanonicalSafety } from "./course";
7
+ import { type SigLocalization, type CourseLanguage } from "../i18n";
8
+ /** Resolved once per invocation; recursive clinical composition reuses it. */
9
+ interface CourseFormatEnvironment {
10
+ localization?: SigLocalization;
11
+ words: CourseLanguage;
12
+ }
13
+ export declare function joinGeneratedClauses(clauses: readonly string[], separator?: string): string;
14
+ export declare function appendMedicationExcludedDatesText(text: string, dates: readonly string[], options?: FormatOptions, environment?: CourseFormatEnvironment): string;
15
+ /** The locale owns weekday vocabulary; clinical exclusion membership is
16
+ * walked once instead of repeatedly looking through prior array members. */
17
+ export declare function appendMedicationExcludedWeekdaysText(text: string, days: readonly FhirDayOfWeek[], options?: FormatOptions, environment?: CourseFormatEnvironment): string;
18
+ export declare function appendMedicationConditionText(text: string, condition: MedicationCondition, options?: FormatOptions, environment?: CourseFormatEnvironment): string;
19
+ /** Show an imported expression without evaluating it or inventing a dose.
20
+ * Referenced/named expressions are usable structured data too. */
21
+ export declare function unevaluatedExpressionText(expression: CanonicalExpression, kind: "dose" | "rate", words?: CourseLanguage): string;
22
+ /** Source-less native dose/rate ranges retain both independently authored
23
+ * endpoints and their unit/operators, never a guessed shared unit or value. */
24
+ export declare function rateRangePreview(range: CanonicalRange): string | undefined;
25
+ export declare function prefersSourceInstruction(course: CanonicalCourse): boolean;
26
+ /** Unconditional membership owns a shared allowance across every selectable path. */
27
+ export declare function formatCourseChoices<T>(members: readonly T[], render: (member: T, sharedCountAlreadyDisplayed?: boolean) => string, choiceOf: (member: T) => CanonicalAdministration["choice"], words: CourseLanguage, separator?: string, courseLabels?: ReadonlyMap<string, ReadonlyMap<string, string>>, sharedCountOf?: (member: T) => CanonicalScheduleExpr["sharedCount"], memberFormatOverride?: boolean, localization?: SigLocalization): string;
28
+ /** Transient renderer result for callers retaining independently authored text. */
29
+ interface AuthoredDirectionsState {
30
+ text: string;
31
+ rendered: boolean;
32
+ headerRendered?: boolean;
33
+ /** Locale-selected authored wording, supplied by the public interchange boundary. */
34
+ displayText?: string;
35
+ }
36
+ export declare function formatCanonicalAdministration(a: CanonicalAdministration, style?: "short" | "long", options?: FormatOptions, compiled?: ReadonlyMap<CanonicalAdministration, CanonicalSigClause>, authored?: AuthoredDirectionsState, stageSafety?: CanonicalSafety): string;
37
+ export declare function formatCanonicalCourse(oneOrCourse: CanonicalCourse, style?: "short" | "long", options?: FormatBatchOptions, compiled?: ReadonlyMap<CanonicalAdministration, CanonicalSigClause>, authored?: AuthoredDirectionsState): string;
38
+ export {};
@@ -6,6 +6,8 @@ export interface TailTokenSegment {
6
6
  tokens: Token[];
7
7
  leadingSeparatorTokens: Token[];
8
8
  range: TextRange;
9
+ /** Original coordinates belong to this text; display text may normalize whitespace. */
10
+ sourceText: string;
9
11
  text: string;
10
12
  }
11
13
  export interface ParsedInstructionTokenSegment {
@@ -1,3 +1,4 @@
1
+ import { TEMPORAL_DATE_RELATION_SOURCES } from "./hpsg/lexical-classes";
1
2
  import { CanonicalCalendarEventExpr, MedicationDateResolver, ParseOptions } from "./types";
2
3
  export type MedicationDateRelation = "event" | "start-inclusive" | "start-exclusive" | "end-inclusive" | "end-exclusive";
3
4
  export interface MedicationDateListMatch {
@@ -10,13 +11,46 @@ export interface MedicationDateListMatch {
10
11
  events: CanonicalCalendarEventExpr[];
11
12
  unresolved: boolean;
12
13
  }
14
+ export interface MedicationDateLexicon {
15
+ months?: ReadonlyArray<{
16
+ month: number;
17
+ forms: readonly string[];
18
+ }>;
19
+ listSeparator?: string;
20
+ eventLead?: string;
21
+ endInclusiveExtra?: string;
22
+ monthBoundary?: string;
23
+ relations?: Partial<typeof TEMPORAL_DATE_RELATION_SOURCES>;
24
+ }
25
+ export interface MedicationDateLexicalFeatures {
26
+ namedMonths: ReadonlyMap<string, number>;
27
+ monthToken: RegExp;
28
+ textualDmy: RegExp;
29
+ textualMdy: RegExp;
30
+ components: RegExp;
31
+ requiredLead: string;
32
+ list: string;
33
+ yearfulList: string;
34
+ listScans: readonly [RegExp, RegExp];
35
+ licensedListScan: RegExp;
36
+ leadPrefix: RegExp;
37
+ leadListAnchored: RegExp;
38
+ listAnchored: RegExp;
39
+ yearfulListAnchored: RegExp;
40
+ leads: ReadonlyArray<{
41
+ group: string;
42
+ relation: MedicationDateRelation;
43
+ }>;
44
+ }
45
+ /** Compile the existing date grammar's lexical slots once per registered pack. */
46
+ export declare function compileMedicationDateLexicon(configured: MedicationDateLexicon): MedicationDateLexicalFeatures;
13
47
  /** Register or replace a calendar resolver used by medication date interpretation. */
14
48
  export declare function registerMedicationDateResolver(resolver: MedicationDateResolver): void;
15
49
  /** Return the currently registered calendar resolver ids. */
16
50
  export declare function listMedicationDateResolvers(): string[];
17
51
  /** Scan structurally date-shaped numeric date lists, whether resolved or ambiguous. */
18
- export declare function findMedicationDateListSpans(input: string, options?: ParseOptions): MedicationDateListMatch[];
52
+ export declare function findMedicationDateListSpans(input: string, options?: ParseOptions, licensedDateContext?: boolean): MedicationDateListMatch[];
19
53
  /** Resolve a date list beginning exactly at the supplied source offset. */
20
- export declare function parseMedicationDateListAt(input: string, start: number, options?: ParseOptions): MedicationDateListMatch | undefined;
54
+ export declare function parseMedicationDateListAt(input: string, start: number, options?: ParseOptions, licensedDateContext?: boolean): MedicationDateListMatch | undefined;
21
55
  /** True when a source range overlaps a recognized date-shaped list span. */
22
56
  export declare function sourceRangeOverlapsMedicationDate(input: string, start: number, end: number, options?: ParseOptions): boolean;
@@ -1,11 +1,22 @@
1
- import { FhirDayOfWeek, FhirDosage, FhirR6Dosage, FhirR6DosageDetails, MedicationCondition, EzDosage, EzCourseMetadata } from "./types";
1
+ import type { CanonicalTrackCycle } from "./canonical/course";
2
+ export { retainField, readRetainedField } from "./fhir-quantity-operator";
3
+ import { FhirDayOfWeek, FhirDosage, FhirExtension, FhirR6Extension, FhirQuantity, FhirR6Dosage, FhirR6DosageCondition, FhirR6DosageInstruction, FhirR6DosageStep, FhirR6DosageInstructionInput, FhirR6DosageSafety, FhirR6TimingRepeat, MedicationCondition, EzDosage, EzCourseMetadata, EzCourseStep } from "./types";
4
+ /** R5 and R6 tim-8 requires the lower-count Element beside countMax, not a numeric
5
+ * minimum. Preserve authored companions; an absent minimum remains unknown. */
6
+ export declare function withTimingCountMinimum<T extends Pick<FhirR6TimingRepeat, "count" | "countMax" | "_count">>(repeat: T): T;
7
+ /** R5 and R6 tim-7 requires a lower-duration Element, without inventing a numeric bound. */
8
+ export declare function withTimingDurationMinimum<T extends Pick<FhirR6TimingRepeat, "duration" | "durationMax" | "_duration">>(repeat: T): T;
9
+ /** R5 and R6 tim-6 requires a lower-period Element, without inventing a numeric cadence. */
10
+ export declare function withTimingPeriodMinimum<T extends Pick<FhirR6TimingRepeat, "period" | "periodMax" | "_period">>(repeat: T): T;
2
11
  /** Modifier extensions: ignoring either can change whether a dose may be given. */
3
12
  export declare const DOSAGE_CONDITION_R5_URL = "urn:ezmedicationinput:StructureDefinition:medication-conditional-dose";
4
13
  /** Separate R6 DosageCondition-level extension: the R5 Dosage modifier has
5
14
  * a different context and nested child contract, so it cannot be reused. */
6
15
  export declare const DOSAGE_CONDITION_R6_LOGIC_URL = "urn:ezmedicationinput:StructureDefinition:medication-r6-condition-logic";
7
16
  export declare const DOSAGE_EXCLUDED_DATES_R5_URL = "urn:ezmedicationinput:StructureDefinition:medication-excluded-calendar-dates";
8
- export declare const DOSAGE_DETAILS_R5_URL = "urn:ezmedicationinput:StructureDefinition:medication-r6-course-details";
17
+ export { DOSAGE_DETAILS_R5_URL } from "./fhir-quantity-operator";
18
+ /** Keeps an expression-only R5 backbone element valid without inventing a dose. */
19
+ export declare const R5_EXPRESSION_SLOT_SOURCE_URL = "urn:ezmedicationinput:StructureDefinition:r5-expression-slot-source";
9
20
  /** Non-modifier metadata: preserves the author's entire literal instruction
10
21
  * without forcing ordinary R5 consumers to implement R6 safety semantics. */
11
22
  export declare const DOSAGE_RENDERED_INSTRUCTION_R5_URL = "urn:ezmedicationinput:StructureDefinition:medication-rendered-instruction";
@@ -13,6 +24,54 @@ export declare const DOSAGE_EXCLUDED_WEEKDAYS_R5_URL = "urn:ezmedicationinput:St
13
24
  /** Non-modifier provenance emitted when an editable R5 projection and its
14
25
  * retained R6 source cannot be merged one-to-one. */
15
26
  export declare const DOSAGE_RECONCILIATION_WARNING_URL = "urn:ezmedicationinput:StructureDefinition:medication-course-reconciliation-warning";
27
+ export { DOSAGE_RECONCILIATION_SOURCE_URL } from "./fhir-quantity-operator";
28
+ export declare const DOSAGE_RETAINED_R5_SEQUENCE_URL = "urn:ezmedicationinput:StructureDefinition:medication-retained-r5-sequence";
29
+ /** R6 doseAndRate is Element. Preserve any older R5-local metadata in the
30
+ * Element.extension slot without emitting illegal modifierExtension keys. */
31
+ export declare const R5_RATE_MODIFIERS_R6_URL = "urn:ezmedicationinput:StructureDefinition:r5-dose-and-rate-modifier-extensions";
32
+ /** The finite repetition count belongs to the complete treatment course.
33
+ * R6 step.count repeats one step; neither R5 nor R6 has a core course-count
34
+ * slot, so both boundary adapters share this narrow modifier extension. */
35
+ export declare const COURSE_CYCLE_COUNT_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-course-cycle-count";
36
+ type CourseCountField = Pick<FhirExtension, "url" | "valueInteger"> & {
37
+ _valueInteger?: unknown;
38
+ };
39
+ type CourseCountOwner = {
40
+ modifierExtension?: readonly CourseCountField[];
41
+ };
42
+ /** Null retains an authored primitive whose finite count is not known. */
43
+ export declare function getCourseCycleCount(owner: CourseCountOwner): number | null | undefined;
44
+ /** Write the current typed count while preserving unrelated modifiers and
45
+ * metadata on an existing recognized count annotation. Output owns writes. */
46
+ export declare function setCourseCycleCount(owner: {
47
+ modifierExtension?: FhirExtension[];
48
+ }, count: number | undefined): FhirExtension[] | undefined;
49
+ export declare function setCourseCycleCount(owner: {
50
+ modifierExtension?: FhirR6Extension[];
51
+ }, count: number | undefined): FhirR6Extension[] | undefined;
52
+ /** An independent track repeats only its named source members. Ignoring this
53
+ * modifier would change which administrations recur; it is not a root repeatCycle. */
54
+ export declare const COURSE_TRACK_CYCLE_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-track-cycle";
55
+ export declare function getCourseTrackCycles(owner: {
56
+ modifierExtension?: readonly FhirR6Extension[];
57
+ }): CanonicalTrackCycle[] | undefined;
58
+ /** Both external course writers use the same scoped modifier contract. */
59
+ export declare function setCourseTrackCycles(owner: {
60
+ modifierExtension?: FhirExtension[];
61
+ }, cycles: readonly CanonicalTrackCycle[] | undefined): void;
62
+ export declare function setCourseTrackCycles(owner: {
63
+ modifierExtension?: FhirR6Extension[];
64
+ }, cycles: readonly CanonicalTrackCycle[] | undefined): void;
65
+ type ModifierWrapperOwner = {
66
+ extension?: FhirR6Extension[];
67
+ modifierExtension?: FhirR6Extension[];
68
+ };
69
+ /** Project the editable modifier owner on an already-owned output fragment.
70
+ * Step and doseAndRate share this Element boundary, including wrapper metadata. */
71
+ export declare function projectR6ModifierWrapper(output: ModifierWrapperOwner, url: string): void;
72
+ export declare function projectR5ModifierWrapper(output: ModifierWrapperOwner, url: string): void;
73
+ export declare function r6StepMetadata(step: Partial<EzCourseStep>): Omit<FhirR6DosageStep, "component">;
74
+ export declare function r5StepMetadata(step: Omit<FhirR6DosageStep, "component">): Omit<EzCourseStep, "sequence">;
16
75
  /** Treatment-relative phase origin for an independent parallel component. */
17
76
  export declare const PARALLEL_COMPONENT_PHASE_ORIGIN_URL = "urn:ezmedicationinput:StructureDefinition:medication-parallel-component-phase-origin";
18
77
  /** Local must-understand profile for exclusive administration choices.
@@ -30,13 +89,13 @@ export interface DosageAlternativeChoice {
30
89
  * @param dosage An R5 or R6 dosage carrying the same modifier-extension shape.
31
90
  * @returns Recognized membership, or undefined while unfamiliar data stays attached.
32
91
  */
33
- export declare function getDosageAlternativeChoice(dosage: Pick<FhirDosage, "modifierExtension">): DosageAlternativeChoice | undefined;
92
+ export declare function getDosageAlternativeChoice(dosage: Pick<FhirR6Dosage, "modifierExtension">): DosageAlternativeChoice | undefined;
34
93
  /** Assign membership already established by the typed regimen graph.
35
94
  * This does not choose a branch, deduce a group from wording, or add conditions.
36
95
  * @param dosage The editable R5 or R6 component to update.
37
96
  * @param choice Proven membership; undefined explicitly clears this modifier.
38
97
  */
39
- export declare function setDosageAlternativeChoice(dosage: Pick<FhirDosage, "modifierExtension">, choice: DosageAlternativeChoice | undefined): void;
98
+ export declare function setDosageAlternativeChoice(dosage: Pick<FhirR6Dosage, "modifierExtension" | "extension">, choice: DosageAlternativeChoice | undefined): void;
40
99
  /** Machine-readable declaration of the local alternative-choice modifier.
41
100
  * It is generated beside its only codec, avoiding a second copied schema or
42
101
  * an undocumented native FHIR field. Callers can publish/validate the returned
@@ -119,70 +178,285 @@ export declare function buildDosageAlternativeChoiceStructureDefinition(): {
119
178
  })[];
120
179
  };
121
180
  };
181
+ /** Generated copies may be consumed only when their typed predicate agrees. */
182
+ export declare function exactConditionBridgePredicate(extension: FhirExtension): MedicationCondition | undefined;
183
+ export declare function isExactConditionBridge(extension: FhirExtension): boolean;
122
184
  export declare function assertUnderstoodDosageModifiers(_dosage: FhirDosage | EzDosage): void;
123
- export declare function getDosageCondition(dosage: FhirDosage | EzDosage): MedicationCondition | undefined;
185
+ declare function parseDosageCondition(dosage: Pick<FhirR6Dosage, "modifierExtension"> & {
186
+ condition?: FhirR6DosageCondition[];
187
+ }): MedicationCondition | undefined;
188
+ export declare function getDosageCondition(dosage: Pick<FhirR6Dosage, "modifierExtension"> & {
189
+ condition?: FhirR6DosageCondition[];
190
+ }): MedicationCondition | undefined;
124
191
  /** A whole-day evaluation is licensed only for the same live predicate that
125
192
  * the source grammar identified as calendar membership. An edited native
126
193
  * condition or a mixed measurement/day predicate cannot inherit that claim.
127
194
  * @param dosage Native or R5 dosage with optional source-owned day-domain metadata.
128
195
  */
129
- export declare function getDosageCalendarDayCondition(dosage: FhirDosage | EzDosage): MedicationCondition | undefined;
196
+ export declare function getDosageCalendarDayCondition(dosage: FhirDosage | EzDosage | FhirR6Dosage): MedicationCondition | undefined;
130
197
  /** Encode the clinical predicate and its independently supplied day-domain type.
131
198
  * @param dosage Editable target dosage; other modifiers remain untouched.
132
199
  * @param condition Live clinical predicate, or undefined to clear it.
133
200
  * @param calendarDayCondition Source-certified whole-day predicate, never inferred from prose.
134
201
  */
135
202
  export declare function setDosageCondition(dosage: FhirDosage, condition: MedicationCondition | undefined, calendarDayCondition?: MedicationCondition): void;
136
- export declare function getDosageExcludedDates(dosage: FhirDosage | EzDosage): string[];
203
+ export declare function getDosageExcludedDates(dosage: FhirDosage | EzDosage | FhirR6Dosage): string[];
137
204
  export declare function setDosageExcludedDates(dosage: FhirDosage, dates: string[]): void;
138
- export declare function getDosageExcludedWeekdays(dosage: FhirDosage): FhirDayOfWeek[];
205
+ export declare function getDosageExcludedWeekdays(dosage: FhirDosage | FhirR6Dosage): FhirDayOfWeek[];
139
206
  export declare function setDosageExcludedWeekdays(dosage: FhirDosage, days: FhirDayOfWeek[]): void;
207
+ /** Project a complete predicate; existing locale/source context selects only
208
+ * its generated wording, never the encoded clinical meaning or authored text. */
209
+ export declare function conditionToR6(condition: MedicationCondition, context?: {
210
+ locale?: string;
211
+ text?: string;
212
+ extension?: readonly (FhirExtension | FhirR6Extension)[];
213
+ }): FhirR6DosageCondition;
214
+ declare function toR6Safety(dosage: FhirDosage, includePartialPeriods?: boolean): FhirR6DosageSafety | undefined;
215
+ /**
216
+ * Apply edits made through R5 maximum-dose fields without discarding safety
217
+ * semantics that R5 cannot carry. Existing backbone metadata stays attached
218
+ * to the corresponding representable scope; expression/integer limits and
219
+ * the safety-level exceeded action remain byte-for-byte authoritative.
220
+ */
221
+ export declare function reconcileR5SafetyEdits(retained: FhirR6DosageSafety, projected: FhirR6DosageSafety | undefined, baseline?: string, dose?: FhirQuantity): FhirR6DosageSafety | undefined;
222
+ /**
223
+ * Reconcile the two editable views of safety against the row's saved source.
224
+ * Explicit safety edits win. An unchanged lifted safety copy must not hide a
225
+ * changed/deleted R5 maximum; field-local merging retains R6-only limits and
226
+ * authored safety metadata. This runs only for rows with retained safety.
227
+ */
228
+ export declare function reconcileR5SafetySnapshot(row: EzDosage, retained: FhirR6DosageSafety, baseline: string | undefined): FhirR6DosageSafety | undefined;
229
+ export declare function reconcileLiftedR5Safety(row: EzDosage): FhirR6DosageSafety | undefined;
140
230
  /** Lift real R6 concepts once into the familiar flat R5 dosage shape. */
141
231
  export declare function toEzDosages(dosages: readonly (FhirDosage | EzDosage)[]): EzDosage[];
232
+ export declare function isRenderedInstructionMarker(extension: FhirExtension): boolean;
233
+ export declare function hasUnrecognizedEditMetadata(marker: FhirExtension): boolean;
142
234
  /** Project one R6 component without building course-storage metadata. Used by
143
235
  * both strict exports and read-only rendering; source objects are not mutated.
144
236
  * @param dosage Native R6 component.
145
237
  * @param sequence Ordered global course step for its R5 projection.
146
238
  */
147
239
  export declare function fromR6Dosage(dosage: FhirR6Dosage, sequence: number): FhirDosage;
240
+ /** A text-only course's latest full marker may already embed previous
241
+ * reconciliation sources. Keep those sources in their existing flat list,
242
+ * and preserve only the immediate preceding course snapshot as a new item.
243
+ * This strips solely the nested source-history wrapper at the known course
244
+ * top level; it retains unknown fields, safety, warnings and other extensions. */
245
+ export declare function sourceWithoutNestedHistory(marker: FhirExtension): FhirExtension;
246
+ /** Preserve unmatched step metadata in its original typed extension structure.
247
+ * @param step Source step that could not be matched to a live dosage.
248
+ */
249
+ export declare function retainedCourseStepSource(step: NonNullable<EzCourseMetadata["step"]>[number]): FhirExtension;
250
+ /** Compare live projections without sorted copies or serialization. Validator
251
+ * additions are tolerated only on Coding metadata, never on clinical fields.
252
+ * @param original Original typed projection.
253
+ * @param current Current editable projection.
254
+ * @param context Metadata context for Coding-system/version additions.
255
+ */
256
+ export declare function equivalentProjection(original: unknown, current: unknown, context?: "general" | "coding-list" | "coding-item"): boolean;
257
+ /**
258
+ * Inspect the live R5 projection independently of the embedded R6 snapshot.
259
+ * Modifier metadata is deliberately excluded from the comparison: it can
260
+ * describe a course but must never replace subsequently edited dosage values.
261
+ */
262
+ export declare function liveDosageProjection(dosage: FhirDosage | EzDosage, includeText?: boolean): object;
263
+ export declare function compactProjectionFingerprint(value: unknown): string;
264
+ /** Matching keys narrow candidates; exact equivalence is checked before
265
+ * claiming identity. Added Coding.system/version annotations do not force
266
+ * every edited row to rescan every original row. Existing baseline hashes
267
+ * remain byte-for-byte unchanged. */
268
+ export declare function matchingProjectionFingerprint(value: unknown): string;
269
+ /** Hash the current editable clinical view without allocating a stripped
270
+ * dosage tree on every call. Retained edit baselines themselves are excluded;
271
+ * active local row fields and all unrelated source annotations remain hashed.
272
+ * The exact token order is identical to compactProjectionFingerprint so
273
+ * existing persisted edit identities require no migration. */
274
+ export declare function dosageProjectionFingerprint(dosage: FhirDosage | EzDosage | FhirR6Dosage): string;
275
+ /** New agreement excludes narrative annotations; legacy untagged hashes keep
276
+ * their exact saved algorithm. An old hash alone cannot recover prior metadata. */
277
+ export declare function dosageClinicalProjectionFingerprint(dosage: FhirDosage | EzDosage | FhirR6Dosage): string;
278
+ export declare function matchesDosageProjectionFingerprint(dosage: FhirDosage | EzDosage | FhirR6Dosage, expected: string | undefined): boolean;
279
+ /** Source text can be retained without claiming it agrees with current
280
+ * external clinical fields. The compact annotation is local to every row. */
281
+ export declare function getDosageSourceTextFingerprint(dosage: Pick<FhirR6Dosage, "extension">): string | undefined;
282
+ /** The original clinical baseline stays bound to its original narrative across saves. */
283
+ export declare function getDosageSourceProjectionFingerprint(dosage: Pick<FhirR6Dosage, "extension">): string | undefined;
284
+ /** An unchanged source may receive its equivalent target-version baseline.
285
+ * Changed clinical fields retain the old hash so saving cannot certify stale text. */
286
+ export declare function retainedSourceProjectionFingerprint(dosage: FhirDosage | EzDosage | FhirR6Dosage): string | undefined;
287
+ /** Wording coverage and permission to replay clinical text are distinct.
288
+ * A declared coverage bit follows its exact source; legacy agreement keeps
289
+ * its existing requirement for a saved clinical projection. */
290
+ export declare function dosageHasAgreedSourceText(dosage: FhirDosage | EzDosage | FhirR6Dosage): boolean;
291
+ export declare function getDosageSourceTextAgreement(dosage: Pick<FhirR6Dosage, "extension" | "text">, acceptTextEdits?: boolean): boolean | undefined;
292
+ /** Source ownership of an immutable parser row. These flags identify the
293
+ * original HPSG projection; no clinical values are copied or watched. */
294
+ export interface FreshDoseSource {
295
+ defaulted: boolean;
296
+ clocks: boolean;
297
+ events: boolean;
298
+ site: boolean;
299
+ }
300
+ export declare function markFreshDoseSource(dosage: FhirDosage, defaulted: boolean, sourceTextAgreed?: boolean, sourceTextCovered?: boolean): void;
301
+ export declare function getFreshDoseSource(dosage: FhirDosage): FreshDoseSource | undefined;
302
+ export interface DosageSourceOwnership {
303
+ clocks?: boolean;
304
+ events?: boolean;
305
+ site?: boolean;
306
+ }
307
+ export declare function sourceOwnership(marker: FhirR6Extension): DosageSourceOwnership | undefined;
308
+ /** Saved primary-field ownership. Missing evidence never licenses removal
309
+ * of independent clocks, event anchors, or sites supplied only by the graph. */
310
+ export declare function getDosageSourceOwnership(dosage: Pick<FhirR6Dosage, "extension">): DosageSourceOwnership | undefined;
311
+ /** Known agreement remains owned even when its source Element has annotations. */
312
+ export declare function isSourceAgreementMarker(marker: FhirExtension): boolean;
313
+ export declare function isCompactSourceAgreementMarker(marker: FhirExtension | FhirR6Extension): boolean;
314
+ /** Verify each immutable submitted dosage's source clinical authority once.
315
+ * Missing provenance is unknown, not a mismatch. Fresh submissions always
316
+ * compare their current fields with the retained projection fingerprint. */
317
+ export declare function dosageMatchesSavedProjection(dosage: FhirDosage | EzDosage | FhirR6Dosage): boolean | undefined;
318
+ export declare function dosageTextFingerprint(dosage: FhirDosage | EzDosage | FhirR6Dosage): string;
148
319
  /**
149
320
  * Attach source/display provenance using repeated, structured row extensions.
150
321
  * Both primary parser output and strict R5 export use this same representation.
151
322
  * @param dosages Independently editable rows being returned to the caller.
152
- * @param instruction The author's unmodified instruction.
323
+ * @param instruction The author's unmodified instruction, when supplied.
324
+ * @param sourceAgreement Whether the producer established that wording agrees with the clinical fields.
153
325
  */
154
- export declare function withDosageEditProvenance<T extends FhirDosage | EzDosage>(dosages: readonly T[], instruction: string): T[];
155
- /**
156
- * Export the R5-style extended dose array as strict R6 DosageDetails.
157
- * The optional course.step rows use the official R6 step fields, grouped
158
- * by the existing global R5 sequence number.
159
- * @param dosages Authoritative live R5 rows, including retained course metadata.
160
- * @param renderedInstruction Explicit replacement whole-course display.
161
- * @param course Explicit editable course and step metadata, when supplied.
162
- * @param options Confirm corrected phase sequences after editing saved rows.
163
- * Only their persisted conflict flags are cleared; live disagreements still
164
- * block numeric execution and the prior conflict remains source provenance.
165
- * @returns The editable R6 course with any unresolved context retained.
166
- */
167
- export declare function toDosageDetails(dosages: readonly (FhirDosage | EzDosage)[], renderedInstruction?: string, course?: EzCourseMetadata, options?: {
326
+ export interface DosageSourceTextBaseline {
327
+ sourceAgreement: boolean;
328
+ sourceTextAgreed?: boolean;
329
+ projectionFingerprint?: string;
330
+ textFingerprint?: string;
331
+ sourceHasStructuredClocks?: boolean;
332
+ sourceHasStructuredEvents?: boolean;
333
+ sourceHasStructuredSite?: boolean;
334
+ }
335
+ export declare function withDosageEditProvenance<T extends FhirDosage | EzDosage>(dosages: readonly T[], instruction: string | undefined, sourceAgreement?: boolean, rowSources?: readonly (DosageSourceTextBaseline | undefined)[], headerCovered?: boolean): T[];
336
+ /** R6 imports follow the *current* DosageInstruction contract, not historical
337
+ * drafts. This runs only at the R6 import boundary, never on ordinary SIG
338
+ * parsing or R5 editing hot paths. Typed extensions and unknown value[x]
339
+ * payloads remain intact instead of being interpreted as clinical language. */
340
+ /** Compatibility name for the requested R6 export: R5 -> native -> R6.
341
+ * The native importer owns all row/phase reconciliation. */
342
+ export declare function toDosageDetails(rows: readonly (FhirDosage | EzDosage)[], instruction?: string, metadata?: EzCourseMetadata, options?: {
168
343
  resolvedPhaseSequences?: readonly number[];
169
- }): FhirR6DosageDetails;
170
- /** Import a complete R6 course without replacing EZMED's flat dosage layout. */
171
- export declare function fromDosageDetails(details: FhirR6DosageDetails): {
344
+ }): FhirR6DosageInstruction;
345
+ export declare function assertCurrentR6DosageInstruction(value: FhirR6DosageInstructionInput): string[];
346
+ /** A supplied R6 instruction is an input source, not an intermediate.
347
+ * Normalize it once and serialize requested R5 views directly. */
348
+ export declare function projectEditableR5Course(details: FhirR6DosageInstructionInput, strictPreview?: boolean): {
172
349
  dosages: EzDosage[];
173
350
  course: EzCourseMetadata;
351
+ strictDosages?: FhirDosage[];
174
352
  };
175
- /** Flatten R6 steps to R5 Dosage.sequence with explicit modifier extensions. */
176
- export declare function toFhirR5Dosages(input: FhirR6DosageDetails | readonly (FhirDosage | EzDosage)[], course?: EzCourseMetadata): FhirDosage[];
353
+ /** Import the complete native R6 course into the established editable R5
354
+ * interchange contract. New internal course paths do not use this function. */
355
+ export declare function fromDosageDetails(details: FhirR6DosageInstructionInput): {
356
+ dosages: EzDosage[];
357
+ course: EzCourseMetadata;
358
+ };
359
+ /** Requested R5 export: either input version is imported into native
360
+ * clinical facts, then written directly to R5. Neither external format is an
361
+ * intermediate representation for the other. */
362
+ export declare function toFhirR5Dosages(input: FhirR6DosageInstructionInput | readonly (FhirDosage | EzDosage)[], metadata?: EzCourseMetadata): FhirDosage[];
363
+ /** R5-only fields whose original R6 spelling or metadata needs a local delta. */
364
+ export interface ComponentDeltaBaseline {
365
+ condition?: string;
366
+ safety?: string;
367
+ site?: string;
368
+ doseAndRate?: Array<{
369
+ dose?: string;
370
+ rate?: string;
371
+ doseExpression?: string;
372
+ rateExpression?: string;
373
+ expressionSlot?: boolean;
374
+ }>;
375
+ timing?: string;
376
+ }
377
+ /** Each marker belongs to its live row, never to another component's snapshot. */
378
+ export interface CompactCourseRow {
379
+ rowIndex: number;
380
+ sequence: number;
381
+ stepCount: number;
382
+ /** Current saved-row contract: step.count repeats only that step. */
383
+ countScope?: "step";
384
+ step?: Omit<FhirR6DosageStep, "component">;
385
+ component?: Partial<FhirR6Dosage>;
386
+ /** R6 offsets are typed extension children, never R5 Extension.valueTiming. */
387
+ timingOffsets?: Pick<FhirR6TimingRepeat, "startOffset" | "endOffset">;
388
+ baseline?: ComponentDeltaBaseline;
389
+ context?: string;
390
+ contextRequired?: boolean;
391
+ course?: Omit<FhirR6DosageInstruction, "step" | "renderedInstruction">;
392
+ emptyStep?: EzCourseStep[];
393
+ missingContext?: string[];
394
+ }
395
+ /** Period-local offsets are measured within the cadence period. A frequency
396
+ * edit does not change that window while the R6 frequency > 1 constraint holds. */
397
+ export declare function offsetCadenceFingerprint(timing: FhirDosage["timing"] | FhirR6Dosage["timing"]): string;
398
+ export declare function matchesOffsetCadence(timing: FhirDosage["timing"] | FhirR6Dosage["timing"], baseline: string | undefined): boolean;
177
399
  /** Encode local phase metadata and unrepresentable component fields.
178
400
  * Course-wide metadata has one owner, referenced by all participating rows.
179
401
  * All rows are newly created by the caller; no source course is mutated.
180
402
  * @param dosages Fresh flattened output rows in step/component order.
181
403
  * @param details Typed source course, used only to calculate missing metadata.
182
404
  */
183
- export declare function attachCourseDetailsExtensions(dosages: (FhirDosage | EzDosage)[], details: FhirR6DosageDetails): void;
405
+ export declare function attachCourseDetailsExtensions(dosages: (FhirDosage | EzDosage)[], details: FhirR6DosageInstruction): void;
406
+ /** These are R5 extension codecs, not version converters. A native writer
407
+ * supplies only final retained fields which cannot live in an R5 Dosage row.
408
+ * The old extension names remain stable so existing persisted edits reopen. */
409
+ export declare function attachR5RetainedRow(row: FhirDosage | EzDosage, retained: CompactCourseRow): void;
410
+ /** Typed quantity qualifiers and unevaluated safety use the same retained-row
411
+ * modifier and edit baseline as the direct native R5 writer. */
412
+ export declare function attachQualifiedR5Details(row: FhirDosage, safety?: FhirR6DosageSafety): void;
413
+ /** A course with no administration has a source carrier, not a fabricated
414
+ * dosage. Encode the header and empty-stage metadata directly into its R5
415
+ * extension; do not allocate an intermediate external course. */
416
+ export declare function createR5EmptyCourseCarrier(fields: Omit<FhirR6DosageInstruction, "step" | "renderedInstruction">, steps: Omit<FhirR6DosageStep, "component">[], instruction?: string): FhirDosage;
417
+ /** Comparison views used only by the retained-row codec. These project small
418
+ * individual fields, never a whole R6 dosage/course to serve as R5 input. */
419
+ export declare const r5ConditionBaseline: typeof parseDosageCondition;
420
+ export declare const r5SafetyBaseline: typeof toR6Safety;
421
+ /** Decode only retained R5 profile fields, not a synthetic external course. */
422
+ export declare function decodeR5RetainedFields(marker: FhirR6Extension): Partial<CompactCourseRow>;
423
+ export declare function encodeR5RetainedFields(value: Partial<CompactCourseRow>): FhirExtension[];
424
+ /** Detect the row-local contract without decoding ordinary R5 inputs.
425
+ * @param dosage Live row carrying optional course metadata.
426
+ */
427
+ export declare function compactCourseMarker(dosage: FhirDosage | EzDosage): FhirExtension | undefined;
428
+ /** Preserve a superseded local delta without nesting its course owner again.
429
+ * @param marker The row's original structured extension.
430
+ */
431
+ export declare function localReconciliationSource(marker: FhirExtension): FhirExtension;
432
+ /** Align R6-only dose/rate choices with surviving R5 entries by their
433
+ * native Element.id or unique clinical type. Position is meaningful only if
434
+ * the list cardinality is unchanged; without identity, deleting one of two
435
+ * indistinguishable projected entries cannot prove which was removed.
436
+ *
437
+ * Only called for a course row that actually carries R6-only choices.
438
+ * @returns Live index -> retained source index; unmatched sources stay inert.
439
+ */
440
+ export declare function retainedDoseRateMatches(source: readonly NonNullable<FhirR6Dosage["doseAndRate"]>[number][], live: readonly NonNullable<FhirR6Dosage["doseAndRate"]>[number][], baselines?: ComponentDeltaBaseline["doseAndRate"]): Map<number, number>;
441
+ /** Phase fields whose disagreement can change administration or supply.
442
+ * IDs and non-modifier annotations remain editable without blocking execution.
443
+ * @param step Local phase metadata without dosage components.
444
+ */
445
+ export declare function executablePhaseMetadata(step: NonNullable<CompactCourseRow["step"]>): {
446
+ start: import("./types").FhirR6RelativeTime | undefined;
447
+ end: import("./types").FhirR6RelativeTime | undefined;
448
+ count: number | undefined;
449
+ safety: FhirR6DosageSafety | undefined;
450
+ };
184
451
  /** Identify unavailable or contradictory context before numeric execution.
185
452
  * Parsing, formatting and editing continue to preserve all surviving data.
186
453
  * @param course Reconstructed course with typed context markers on its components.
187
454
  */
188
- export declare function getCourseContextIssue(course: FhirR6DosageDetails): "missing-course-context" | "conflicting-course-phase" | undefined;
455
+ export declare function getCourseContextIssue(course: FhirR6DosageInstruction): "missing-course-context" | "conflicting-course-phase" | undefined;
456
+ export declare function encodeR6SourceMetadata(url: string, value: object, kind: "drafts" | "safety" | "step"): FhirExtension;
457
+ export declare function decodeR6SourceMetadata(marker: FhirR6Extension, kind: "drafts" | "safety" | "step"): Record<string, unknown> | undefined;
458
+ /** Recover a course from a structured extension, leaving malformed originals
459
+ * with the caller for preservation. No string payload is interpreted here.
460
+ * @param node The dosageDetails extension child.
461
+ */
462
+ export declare function decodeCourseDetails(node: FhirExtension): FhirR6DosageInstruction | undefined;
@@ -1,4 +1,5 @@
1
- import { EventTiming } from "./types";
1
+ import { type LexToken } from "./lexer/token-types";
2
+ import { EventTiming, type ParseOptions } from "./types";
2
3
  export interface EventTimingExpression {
3
4
  timing: EventTiming;
4
5
  length: number;
@@ -6,3 +7,27 @@ export interface EventTimingExpression {
6
7
  export declare const MAX_EVENT_TIMING_EXPRESSION_PARTS: number;
7
8
  /** Resolve the most specific canonical event expression at `start`. */
8
9
  export declare function resolveEventTimingExpression(parts: readonly string[], start?: number, endExclusive?: number): EventTimingExpression | undefined;
10
+ /** A dose head owns its complete registered event modifiers. Return the
11
+ * selected nominal end so an adjacent calendar daughter can keep its own role.
12
+ * Withholding valence can also select the whole-medication noun without an event. */
13
+ export declare function medicationDoseSlotNominalEnd(words: readonly string[], options?: ParseOptions, requireEvent?: boolean): number | undefined;
14
+ /** Complete source coverage prevents an unrelated food or opaque noun from
15
+ * borrowing a contained event as proof of a medication target. */
16
+ export declare function isMedicationDoseSlotNominal(words: readonly string[], options?: ParseOptions): boolean;
17
+ export declare function eventTimingExpressionAt(tokens: readonly LexToken[], start: number, consumed?: ReadonlySet<number>): EventTimingExpression | undefined;
18
+ /** The complete registered nominal has the same owner at a relation lead and
19
+ * at a contained event token. Caller meanings retain their exact precedence. */
20
+ export declare function qualifiedMealStateNominalEnd(tokens: readonly LexToken[], start: number, options?: ParseOptions, input?: string): number | undefined;
21
+ /** Declared PRN leads are independent clauses. A bare FOR reason lead is
22
+ * ambiguous inside an unknown nominal and needs its ordinary PRN owner. */
23
+ export declare function isExplicitPrnClauseLead(tokens: readonly LexToken[], index: number, consumed?: ReadonlySet<number>): boolean;
24
+ /** Registered independent clauses end an accompaniment nominal. Reuse this
25
+ * boundary in the nominal reader and the free-advice body owner. */
26
+ export declare function isAccompanimentClauseBoundary(tokens: readonly LexToken[], index: number, consumed?: ReadonlySet<number>): boolean;
27
+ /** A negative accompaniment owns its event noun as advice, not a positive
28
+ * administration anchor. The chart and instruction boundary reader share this
29
+ * constituent ownership so list punctuation cannot split off an event daughter. */
30
+ export declare function isNegatedEventComplement(tokens: readonly LexToken[], index: number, consumed?: ReadonlySet<number>, options?: ParseOptions, input?: string): boolean;
31
+ /** Punctuation inside the same negative event list is a nominal boundary,
32
+ * not a new instruction. Every extraction path uses this selected scope. */
33
+ export declare function isNegatedEventListSeparator(tokens: readonly LexToken[], index: number, consumed?: ReadonlySet<number>, options?: ParseOptions, input?: string): boolean;