ezmedicationinput 0.2.0 → 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 (61) hide show
  1. package/README.md +201 -10
  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 +36 -5
  5. package/dist/body-site-lookup.d.ts +3 -0
  6. package/dist/body-site-spatial.d.ts +6 -2
  7. package/dist/body-site-target.d.ts +9 -3
  8. package/dist/canonical/compile.d.ts +79 -0
  9. package/dist/canonical/course.d.ts +352 -0
  10. package/dist/canonical/format-course.d.ts +36 -0
  11. package/dist/dosage-course.d.ts +294 -29
  12. package/dist/execution/calendar.d.ts +107 -0
  13. package/dist/execution/engine.d.ts +11 -0
  14. package/dist/fhir-quantity-operator.d.ts +53 -0
  15. package/dist/fhir-translations.d.ts +5 -6
  16. package/dist/fhir.d.ts +99 -14
  17. package/dist/format.d.ts +105 -3
  18. package/dist/hpsg/constructions.d.ts +11 -3
  19. package/dist/hpsg/defaults.d.ts +2 -0
  20. package/dist/hpsg/lexical-classes.d.ts +115 -4
  21. package/dist/hpsg/procedural-context.d.ts +3 -3
  22. package/dist/hpsg/projection.d.ts +28 -1
  23. package/dist/hpsg/rule-context.d.ts +104 -7
  24. package/dist/hpsg/rules/clinical-quantity-rules.d.ts +16 -7
  25. package/dist/hpsg/rules/condition-rules.d.ts +0 -1
  26. package/dist/hpsg/rules/core-rules.d.ts +3 -0
  27. package/dist/hpsg/rules/instruction-rules.d.ts +2 -0
  28. package/dist/hpsg/rules/prn-rules.d.ts +3 -1
  29. package/dist/hpsg/rules/timing-rules.d.ts +17 -1
  30. package/dist/hpsg/signature.d.ts +13 -3
  31. package/dist/hpsg/unification.d.ts +3 -1
  32. package/dist/i18n.d.ts +37 -1
  33. package/dist/index.cjs +63500 -46393
  34. package/dist/index.d.ts +21 -9
  35. package/dist/index.js +63491 -46393
  36. package/dist/instruction-action-locale-adapter.d.ts +31 -3
  37. package/dist/instruction-action-terminology.d.ts +23 -3
  38. package/dist/instruction-concept-terminology.d.ts +7 -0
  39. package/dist/instruction-graph-fhir.d.ts +8 -2
  40. package/dist/instruction-graph.d.ts +80 -38
  41. package/dist/ir.d.ts +1 -1
  42. package/dist/lexer/surface-segmenter.d.ts +1 -1
  43. package/dist/lexer/surface.d.ts +1 -0
  44. package/dist/locale-detection.d.ts +3 -0
  45. package/dist/locales/course/en.d.ts +15 -0
  46. package/dist/locales/course/th.d.ts +12 -0
  47. package/dist/localization.d.ts +73 -0
  48. package/dist/maps.d.ts +10 -2
  49. package/dist/medication-condition.d.ts +1 -1
  50. package/dist/parser-state.d.ts +2 -2
  51. package/dist/regimen/grammar.d.ts +11 -0
  52. package/dist/regimen/parallel-course.d.ts +8 -41
  53. package/dist/regimen/regimen.d.ts +6 -2
  54. package/dist/relation-terminology.d.ts +1 -0
  55. package/dist/schedule.d.ts +14 -10
  56. package/dist/timing-summary.d.ts +82 -1
  57. package/dist/types.d.ts +510 -56
  58. package/dist/unit-lexicon.d.ts +7 -0
  59. package/dist/utils/text.d.ts +3 -0
  60. package/dist/utils/units.d.ts +19 -0
  61. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { AdviceArgument, AdviceFrame, MedicationInstructionActionDefinition, MedicationInstructionActionRealizer } from "./types";
1
+ import { AdviceArgument, AdviceFrame, AdviceModality, AdviceRelation, MedicationInstructionActionDefinition, MedicationInstructionActionRealizer } from "./types";
2
2
  export interface InstructionActionRealizationInput {
3
3
  frame: AdviceFrame;
4
4
  locale: string;
@@ -12,6 +12,11 @@ export interface InstructionActionRealizationInput {
12
12
  result?: string;
13
13
  activity?: string;
14
14
  time?: string;
15
+ /** Selected Time's explicit or licensed inherited relation. */
16
+ timeRelation?: AdviceRelation;
17
+ /** Optional output evidence requested by action composition. Set only
18
+ * at the branch that actually includes the selected Time in its wording. */
19
+ timeWasRendered?: boolean;
15
20
  duration?: string;
16
21
  material?: string;
17
22
  manner?: string;
@@ -24,7 +29,7 @@ export interface InstructionActionLocaleAdapter {
24
29
  locale: string;
25
30
  selectLexicalRealization?(input: InstructionActionRealizationInput): InstructionActionRealizationInput;
26
31
  render(realizer: MedicationInstructionActionRealizer, input: InstructionActionRealizationInput): string | undefined;
27
- renderNegated(input: InstructionActionRealizationInput): string;
32
+ renderNegated(input: InstructionActionRealizationInput, completeAction?: string): string;
28
33
  applyPositiveModality(text: string, frame: AdviceFrame): string;
29
34
  parseConditionPersistence(body: string): {
30
35
  body: string;
@@ -33,9 +38,32 @@ export interface InstructionActionLocaleAdapter {
33
38
  renderConditionBody(base: string, conditionForm: string | undefined, persists: boolean): string;
34
39
  joinConditionLead(lead: string, body: string): string;
35
40
  conditionalContinuation(text: string, imperative: boolean): string;
36
- postposedCondition(text: string): string;
41
+ postposedCondition(text: string, precedingText?: string): string;
37
42
  sequenceSeparator(): string;
38
43
  continuationText(text: string, understood: boolean): string;
44
+ withAuthoredDirections?(current: string, source: string): string;
45
+ directTime?(time: string): string;
39
46
  }
40
47
  export declare function registerInstructionActionLocaleAdapter(adapter: InstructionActionLocaleAdapter): void;
41
48
  export declare function getInstructionActionLocaleAdapter(locale: string): InstructionActionLocaleAdapter;
49
+ export declare function instructionActionDefinitionForRealization(frame: AdviceFrame): MedicationInstructionActionDefinition | undefined;
50
+ /** The selected valence determines which daughter owns the frame relation. */
51
+ export declare function instructionFrameRelationOwnsTemporalArgument(frame: AdviceFrame, arg: AdviceArgument): boolean;
52
+ /** Resolve Site attachment before locale realization or Time consumption. */
53
+ export declare function instructionFrameSiteRelation(frame: AdviceFrame, site?: AdviceArgument): AdviceRelation | undefined;
54
+ export declare function instructionSiteRelation(input: InstructionActionRealizationInput, site?: AdviceArgument): string | undefined;
55
+ export declare const EN_POSITIVE_MODALITY_PREFIX: Partial<Record<AdviceModality, string>>;
56
+ /** Internal selection metadata; public locale inputs and callbacks stay unchanged. */
57
+ type SelectedTimeInput = Pick<InstructionActionRealizationInput, "locale" | "time" | "timeRelation" | "timeWasRendered"> & {
58
+ selectedTime?: AdviceArgument;
59
+ frame?: AdviceFrame;
60
+ };
61
+ /** Consume the selected typed Time once; locale adapters own direct wording. */
62
+ export declare function realizeTimeArgument(c: SelectedTimeInput): string | undefined;
63
+ export declare function quantityOnlyInstructionArgument(arg: AdviceArgument | undefined): boolean;
64
+ /** A typed measured nominal without its own noun label retains the opaque
65
+ * argument separately; its source text cannot override the current quantity. */
66
+ export declare function instructionArgumentNeedsAuthoredDirections(arg: AdviceArgument, locale: string): boolean;
67
+ export declare const TH_POSITIVE_MODALITY_PREFIX: Partial<Record<AdviceModality, string>>;
68
+ export declare function selectThaiApplyLabel(actionCode: string | undefined, label: string, unit?: string, args?: readonly AdviceArgument[]): string | undefined;
69
+ export {};
@@ -1,4 +1,4 @@
1
- import { AdviceArgument, FhirCoding, MedicationInstructionActionDefinition, ParseOptions } from "./types";
1
+ import { AdviceArgument, CanonicalMethodExpr, FhirCoding, FhirR6Coding, MedicationInstructionActionDefinition, ParseOptions } from "./types";
2
2
  export declare const MEDICATION_INSTRUCTION_ACTION_SYSTEM: string;
3
3
  export interface MedicationInstructionActionCodeSystem {
4
4
  resourceType: "CodeSystem";
@@ -39,9 +39,29 @@ export declare function medicationInstructionActionSemanticComponentsForArgs(def
39
39
  export declare function resolveMedicationInstructionSequenceAction(surface: string, options?: ParseOptions): MedicationInstructionActionDefinition | undefined;
40
40
  export declare function resolveMedicationInstructionSeparableAction(lead: string, particle: string, options?: ParseOptions): MedicationInstructionActionDefinition | undefined;
41
41
  export declare function medicationInstructionActionIsSafetyScopeTarget(surface: string, options?: ParseOptions): boolean;
42
- export declare function resolveMedicationInstructionAction(surface: string, options?: ParseOptions): MedicationInstructionActionDefinition | undefined;
43
- export declare function getMedicationInstructionAction(code: string): MedicationInstructionActionDefinition | undefined;
42
+ export declare function resolveMedicationInstructionAction(surface: string, options?: ParseOptions, includeCode?: boolean): MedicationInstructionActionDefinition | undefined;
43
+ /** The package lookup accepts saved codes as well as registered surfaces.
44
+ * Internal lexical callers retain the surface-only default above. */
45
+ export declare function resolveMedicationInstructionActionWithCodeFallback(surface: string, options?: ParseOptions, includeCode?: boolean): MedicationInstructionActionDefinition | undefined;
46
+ /** Resolve a declared administration method by exact code identity. Known
47
+ * codings own the verb even when an external edit leaves stale display text.
48
+ * Unknown identities return undefined for the caller's existing text fallback. */
49
+ export declare function resolveMedicationInstructionActionByMethod(coding: FhirR6Coding | undefined, options?: ParseOptions): MedicationInstructionActionDefinition | undefined;
50
+ /** A translated coding can precede the known method in a CodeableConcept.
51
+ * Select its recognized identity in one pass and retain the first code as
52
+ * the fallback for wholly unfamiliar concepts. A display-only Coding remains
53
+ * a text fallback when no identity is supplied. The source array is untouched. */
54
+ export declare function selectMedicationInstructionMethodCoding<TCoding extends FhirR6Coding>(codings: readonly TCoding[] | undefined, options?: ParseOptions): TCoding | undefined;
55
+ /** Keep compatible authored verbs (Drink and Swallow share a method), while
56
+ * a recognized edited code replaces an incompatible retained verb. */
57
+ export declare function resolveMedicationInstructionActionForMethod(method: (Omit<CanonicalMethodExpr, "coding"> & {
58
+ coding?: FhirR6Coding;
59
+ }) | undefined, options?: ParseOptions, includeQualifiedHead?: boolean): MedicationInstructionActionDefinition | undefined;
60
+ export declare function getMedicationInstructionAction(code: string, options?: ParseOptions): MedicationInstructionActionDefinition | undefined;
44
61
  export declare function listMedicationInstructionActions(): MedicationInstructionActionDefinition[];
62
+ /** A CodeSystem snapshot is a public value, not mutable global schema.
63
+ * Build it with one definition walk and one language-key walk per published
64
+ * action; avoid filter→map and map→filter pipelines on every public call. */
45
65
  export declare function buildMedicationInstructionActionCodeSystem(): MedicationInstructionActionCodeSystem;
46
66
  export declare function medicationInstructionActionCoding(definition: MedicationInstructionActionDefinition): FhirCoding;
47
67
  export declare function medicationInstructionActionCodings(definition: MedicationInstructionActionDefinition): FhirCoding[];
@@ -19,8 +19,15 @@ export interface MedicationInstructionConceptCodeSystem {
19
19
  }>;
20
20
  }
21
21
  export declare function normalizeConceptSurface(value: string): string;
22
+ export declare function cloneMedicationInstructionConceptComponents(components: MedicationInstructionConceptDefinition["components"]): MedicationInstructionConceptDefinition["components"];
23
+ /** Dictionary definitions are immutable by caller contract. Repeated
24
+ * lexical resolution must not recursively clone the same vocabulary tree.
25
+ * Explicit frame construction still copies only the fields it later edits. */
22
26
  export declare function resolveMedicationInstructionConcept(surface: string, options?: ParseOptions): MedicationInstructionConceptDefinition | undefined;
23
27
  export declare function getMedicationInstructionConcept(code: string, system?: string): MedicationInstructionConceptDefinition | undefined;
24
28
  export declare function listMedicationInstructionConcepts(): MedicationInstructionConceptDefinition[];
29
+ /** The public CodeSystem is freshly returned, but its published concepts
30
+ * require only one source-definition walk and one designation walk each.
31
+ * This avoids filter->map and map->filter intermediary arrays per call. */
25
32
  export declare function buildMedicationInstructionConceptCodeSystem(): MedicationInstructionConceptCodeSystem;
26
33
  export declare function medicationInstructionConceptCodings(definition: MedicationInstructionConceptDefinition): FhirCoding[];
@@ -1,4 +1,10 @@
1
- import { CanonicalInstructionGraph, FhirExtension } from "./types";
1
+ import { AdviceFrame, CanonicalInstructionCoverage, CanonicalInstructionGraph, FhirExtension } from "./types";
2
2
  export declare const MEDICATION_INSTRUCTION_GRAPH_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-instruction-graph";
3
+ export declare function buildActionExtension(frame: AdviceFrame): FhirExtension;
4
+ export declare function buildInstructionCoverageExtension(coverage: CanonicalInstructionCoverage): FhirExtension;
3
5
  export declare function buildInstructionGraphExtension(graph: CanonicalInstructionGraph | undefined): FhirExtension | undefined;
4
- export declare function parseInstructionGraphExtension(extensions: FhirExtension[] | undefined): CanonicalInstructionGraph | undefined;
6
+ /** One traversal per known graph/action/argument node. Repeated children retain
7
+ * order, first scalar fields retain ownership, and unknown metadata remains
8
+ * outside interpreted clinical meaning. No indexed heap copies or cached
9
+ * input identities are needed to read the same mutable external input again. */
10
+ export declare function parseInstructionGraphExtension<T extends Pick<FhirExtension, "url">>(extensions: readonly T[] | undefined): CanonicalInstructionGraph | undefined;
@@ -1,56 +1,96 @@
1
- import { AdviceFrame, AdviceModality, AdviceRelation, CanonicalInstructionGraph, CanonicalSigClause, CanonicalAdditionalInstructionExpr, CanonicalSourceSpan, FhirCoding, ParseOptions, TextRange } from "./types";
1
+ import { lexInput } from "./lexer/lex";
2
+ import { AdviceFrame, AdviceModality, AdviceRelation, CanonicalInstructionCoverage, CanonicalInstructionGraph, CanonicalInstructionRelation, CanonicalSigClause, CanonicalAdditionalInstructionExpr, CanonicalSourceSpan, FhirCodeableConcept, MedicationInstructionActionDefinition, ParseOptions, TextRange } from "./types";
3
+ type ActionDefinition = MedicationInstructionActionDefinition;
4
+ type Lexeme = ReturnType<typeof lexInput>[number];
5
+ interface ActionMatch {
6
+ definition: ActionDefinition;
7
+ length: number;
8
+ separableParticleIndex?: number;
9
+ }
10
+ export declare function actionMatchAt(parts: Lexeme[], index: number, options?: ParseOptions): ActionMatch | undefined;
2
11
  export declare function parseInstructionActions(sourceText: string, baseOffset?: number, options?: ParseOptions): AdviceFrame[];
12
+ export declare function frameActionDefinition(frame: AdviceFrame, options?: ParseOptions): ActionDefinition | undefined;
3
13
  export declare function isSupplementalHydrationInstruction(frame: AdviceFrame): boolean;
14
+ export declare function relationFromSourceText(text: string): AdviceRelation | undefined;
15
+ export declare function buildInstructionCoverage(actions: AdviceFrame[], relations: CanonicalInstructionRelation[], opaqueSpans: CanonicalSourceSpan[]): CanonicalInstructionCoverage;
4
16
  export declare function refreshInstructionGraphDerivedState(graph: CanonicalInstructionGraph): void;
5
- export declare function buildInstructionGraph(input: string, clause: CanonicalSigClause, options?: ParseOptions, semanticOwnershipRanges?: readonly TextRange[]): CanonicalInstructionGraph | undefined;
6
- export declare function realizeInstructionAction(frame: AdviceFrame, locale?: string): string;
7
- export declare function instructionGraphRepresentsText(graph: CanonicalInstructionGraph, text: string): boolean;
8
- export declare function instructionGraphTextParticipatesInRelation(graph: CanonicalInstructionGraph, text: string): boolean;
9
- export declare function instructionGraphSingleActionRepresentsText(graph: CanonicalInstructionGraph, text: string): boolean;
10
- /**
11
- * Non-coded advice is redundant only when the grammar already owns every
12
- * negative predicate in the same source interval. Free text alone cannot
13
- * justify deleting a distinct clinical prohibition.
14
- */
15
- export declare function instructionGraphCoversTypedWarnings(graph: CanonicalInstructionGraph, frames: readonly AdviceFrame[] | undefined): boolean;
16
- /** A coded qualifier already entailed by the displayed action graph needs no
17
- * second patient-visible sentence, but keeps its exact FHIR coding. */
18
- export declare function instructionGraphEntailsAdviceCoding(graph: CanonicalInstructionGraph, coding: FhirCoding | undefined): boolean;
19
- /**
20
- * Give a complete source-preserved free-text instruction ownership of the
21
- * graph actions whose exact source ranges it contains. This prevents duplicate
22
- * rendering without reinterpreting the instruction or dropping its remaining
23
- * unparsed clinical content.
24
- */
25
- export declare function instructionGraphSourceOwnedByAdvice(graph: CanonicalInstructionGraph, instruction: CanonicalAdditionalInstructionExpr): string[];
26
- /**
27
- * A source-backed additional fragment is fully represented when every
28
- * lexical constituent belongs to a composed action or its licensed
29
- * coordination connector. A partial match cannot delete unresolved advice.
30
- */
31
- export declare function instructionGraphFullyOwnsAdvice(graph: CanonicalInstructionGraph, instruction: CanonicalAdditionalInstructionExpr): boolean;
17
+ export declare function buildInstructionGraph(input: string, clause: CanonicalSigClause, options?: ParseOptions, semanticOwnershipRanges?: readonly TextRange[], proceduralFrames?: readonly AdviceFrame[]): CanonicalInstructionGraph | undefined;
18
+ /** Select complete administration techniques from the already-composed clause
19
+ * and action program. Interchange only projects these selected codings. */
20
+ export declare function instructionGraphAdministrationTechnique(clause: CanonicalSigClause): {
21
+ route?: FhirCodeableConcept;
22
+ method?: FhirCodeableConcept;
23
+ } | undefined;
24
+ /** Realize one selected action with its existing external graph scope, when supplied. */
25
+ export declare function realizeInstructionAction(frame: AdviceFrame, locale?: string, graph?: CanonicalInstructionGraph): string;
26
+ /** A rich source action can carry its own Manner/Time but no Amount because a
27
+ * preceding preparatory verb supplied the original quantity. When the
28
+ * clinician edits the canonical dose, never let that amountless rich action
29
+ * replace the numeric administration text without the CURRENT dose.
30
+ * This is a display-only frame copy, not an edit of source graph/provenance. */
31
+ export declare function realizeRichPrimaryWithCanonicalDose(frame: AdviceFrame, clause: CanonicalSigClause, locale: string, options?: Pick<ParseOptions, "instructionActionMap" | "realizationMode">, coverage?: {
32
+ singleScheduledEvent: boolean;
33
+ }): string;
34
+ /** Typed warning equivalence retains complete qualifiers and the established negative-force tolerance. */
35
+ export declare function sameTypedWarning(left: AdviceFrame, right: AdviceFrame): boolean;
36
+ /** Locate an authored fragment; this is correspondence, not action identity. */
37
+ export declare function instructionSourceRange(graph: CanonicalInstructionGraph, text: string | undefined, source?: string): TextRange | undefined;
38
+ /** Selected instruction evidence covers exactly its complete typed frames. */
39
+ export declare function instructionHasCompleteFrameEvidence(instruction: CanonicalAdditionalInstructionExpr): boolean;
32
40
  /** Exact source-backed discourse connector that introduces the first action
33
41
  * after the canonical administration. This lets realization preserve contrast
34
42
  * without pretending that it is the temporal THEN relation. */
35
43
  export declare function instructionGraphPostAdministrationDiscourseConnector(graph: CanonicalInstructionGraph): CanonicalSourceSpan | undefined;
36
- /** Use complete realized negative actions to recognize otherwise untyped FHIR text. */
37
- export declare function instructionGraphRealizesWarningText(graph: CanonicalInstructionGraph, text: string): boolean;
38
- /**
39
- * A rich administration frame and its canonical HPSG schedule can refer to
40
- * the same meal event using different typed relations: CM + before = ACM.
41
- * Both localizers share this compositional check instead of reparsing the
42
- * displayed text independently.
43
- */
44
- export declare function instructionGraphActionCoversSingleScheduledEvent(frame: AdviceFrame, clause: CanonicalSigClause): boolean;
44
+ /** Counted or qualified sites use the canonical site's complete dose scope. */
45
+ export declare function canonicalSiteOwnsPrimaryPhrase(clause: CanonicalSigClause): boolean;
46
+ /** A sole typed preparation owns the amount before a later administration.
47
+ * Ordinary primary-only graphs return before the ownership walk. */
48
+ export declare function instructionGraphPreparationOwnsDose(clause: CanonicalSigClause, options?: Pick<ParseOptions, "instructionActionMap">): boolean;
49
+ /** Whole-source replay and action realization have the same amount owner.
50
+ * Unrelated later-stage Amounts are not evidence the canonical dose changed. */
51
+ export declare function instructionGraphSourceConflictsWithDose(clause: CanonicalSigClause, options?: Pick<ParseOptions, "instructionActionMap">): boolean;
45
52
  export declare function instructionGraphRichPrimaryAction(clause: CanonicalSigClause): AdviceFrame | undefined;
46
53
  export declare function instructionGraphRoundTripPrimaryAction(clause: CanonicalSigClause): AdviceFrame | undefined;
47
54
  export declare function instructionGraphPrimarySiteRelation(clause: CanonicalSigClause): AdviceRelation | undefined;
48
55
  export declare function instructionGraphPrimaryAdministrationModality(clause: CanonicalSigClause): AdviceModality | undefined;
49
- export declare function instructionGraphHasNovelNonWarningContent(graph: CanonicalInstructionGraph, representedTexts: readonly string[]): boolean;
56
+ /** Presentation classification only; action licensing and scope use their own typed facts. */
57
+ export declare function isInstructionGraphDisplayWarning(frame: AdviceFrame): boolean;
58
+ /** A graph condition whose primary action is rendered by the clause formatter. */
59
+ export interface InstructionGraphPrimaryCondition {
60
+ text: string;
61
+ position: "pre" | "post";
62
+ start: number;
63
+ imperative: boolean;
64
+ }
65
+ /** Attach only conditions owned by that primary, before independent graph
66
+ * actions/advice are composed. Ordinary clauses do not allocate this report. */
67
+ export declare function attachInstructionGraphPrimaryConditions(text: string, conditions: InstructionGraphPrimaryCondition[] | undefined, locale: string, guardedPrimary?: boolean): string;
68
+ /** Associate selected advice with current typed action occurrences; no display coverage is inferred. */
69
+ export declare function instructionGraphAdviceAssociation(graph: CanonicalInstructionGraph, instruction: CanonicalAdditionalInstructionExpr, includeRepresentation?: boolean): {
70
+ actionIndices: number[];
71
+ representedActionIndices: number[];
72
+ codingProved: boolean;
73
+ };
74
+ interface ClauseInstructionRealization {
75
+ pre?: string;
76
+ post?: string;
77
+ whole?: string;
78
+ patient?: string;
79
+ preFlowsIntoAdministration?: boolean;
80
+ postFlowsFromAdministration?: boolean;
81
+ }
82
+ /** Internal clause preview uses the same selected node walk as the public graph
83
+ * realizer. No receipt or source ownership is stored on the clinical values. */
84
+ export declare function realizeClauseInstructions(clause: CanonicalSigClause, locale: string, options: Parameters<typeof realizeInstructionGraph>[2], render: (instruction: CanonicalAdditionalInstructionExpr) => string | undefined, alreadyRendered?: readonly CanonicalAdditionalInstructionExpr[], presentGraphAction?: (text: string) => string | undefined): ClauseInstructionRealization;
50
85
  export declare function realizeInstructionGraph(graph: CanonicalInstructionGraph, locale?: string, options?: {
51
86
  includeWarnings?: boolean;
52
87
  onlyWarnings?: boolean;
53
88
  omitCanonicalAdministration?: CanonicalSigClause;
89
+ /** The selected primary action already realized with its full arguments.
90
+ * Identity remains valid even when imported source wording is absent. */
91
+ omitRenderedAction?: AdviceFrame;
92
+ /** Report conditions attached to the covered primary during this walk. */
93
+ primaryConditions?: InstructionGraphPrimaryCondition[];
54
94
  /** Prefer each understood action's exact source wording when source and target locales match. */
55
95
  preferSourceText?: boolean;
56
96
  /** Source phrases already rendered through another semantic channel. */
@@ -59,4 +99,6 @@ export declare function realizeInstructionGraph(graph: CanonicalInstructionGraph
59
99
  position?: "all" | "pre" | "post";
60
100
  /** Prefer deliberately unambiguous lexical labels when generating parse-safe text. */
61
101
  roundtripSafe?: boolean;
102
+ instructionActionMap?: ParseOptions["instructionActionMap"];
62
103
  }): string | undefined;
104
+ export {};
package/dist/ir.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ParserState } from "./parser-state";
2
2
  import { CanonicalSigClause } from "./types";
3
- export declare function canonicalClauseHasAdministrationSemantics(clause: CanonicalSigClause): boolean;
3
+ export declare function canonicalClauseHasAdministrationSemantics(clause: CanonicalSigClause, includeConstraints?: boolean): boolean;
4
4
  export declare function buildCanonicalSigClauses(internal: ParserState): CanonicalSigClause[];
5
5
  /**
6
6
  * Convert one segment's relative canonical source ranges into full-SIG ranges.
@@ -8,7 +8,7 @@ export interface MedicationSurfaceSegmenter {
8
8
  segment(input: string): Iterable<MedicationSurfaceSegment>;
9
9
  }
10
10
  export declare function registerMedicationSurfaceSegmenter(segmenter: MedicationSurfaceSegmenter): void;
11
- export declare function listMedicationSurfaceSegmenters(): MedicationSurfaceSegmenter[];
11
+ export declare function listMedicationSurfaceSegmenters(): Readonly<MedicationSurfaceSegmenter>[];
12
12
  export declare function registerIntlMedicationSurfaceSegmenter(locale: string, script: RegExp): void;
13
13
  export declare function splitMedicationScriptRuns(value: string): Array<{
14
14
  text: string;
@@ -1,2 +1,3 @@
1
1
  import { SurfaceToken } from "./token-types";
2
+ export declare function isSentenceBoundaryChar(input: string, index: number): boolean;
2
3
  export declare function scanSurfaceTokens(input: string): SurfaceToken[];
@@ -7,3 +7,6 @@ export interface MedicationLocaleDetector {
7
7
  export declare function registerMedicationLocaleDetector(detector: MedicationLocaleDetector): void;
8
8
  export declare function shouldJoinAdjacentSourceTokens(left: string, right: string): boolean;
9
9
  export declare function inferMedicationLocale(text: string, fallback?: string): string;
10
+ /** Registered source languages keep their authored wording; English uses the
11
+ * lexical definition's wording rather than overriding it with a surface form. */
12
+ export declare function withMedicationSourceI18n(sourceText: string, i18n: Record<string, string> | undefined): Record<string, string> | undefined;
@@ -0,0 +1,15 @@
1
+ /** English course wording. Clinical scope and date arithmetic are supplied
2
+ * by the canonical formatter; this module owns words and English inflection. */
3
+ import { RouteCode } from "../../types";
4
+ import type { CourseLanguage } from "../../localization";
5
+ export declare const ENGLISH_DAY_NAMES: Record<string, string>;
6
+ export declare const ENGLISH_COURSE: CourseLanguage;
7
+ /** Native clause timing wording; shared formatting supplies resolved clock shifts. */
8
+ export declare const ENGLISH_CLAUSE_TIMING: {
9
+ sharedAdministration: (body: string, total?: string) => string;
10
+ clockWindow: (start: string, end: string, inclusive: boolean) => string;
11
+ offset: (minutes: number) => string;
12
+ dayShift: (days: number) => string;
13
+ };
14
+ /** English route labels retain their existing lexical specificity in every locale. */
15
+ export declare function routeCodeFromDisplayText(text: string | undefined, includeOtic: boolean): RouteCode | undefined;
@@ -0,0 +1,12 @@
1
+ /** Thai course wording. Keep locale realization separate from shared
2
+ * interval/count/condition semantics; this is a facet of SigLocalization. */
3
+ import type { CourseLanguage } from "../../localization";
4
+ export declare const THAI_DAY_NAMES: Record<string, string>;
5
+ export declare const THAI_COURSE: CourseLanguage;
6
+ /** Native clause timing wording; shared formatting supplies resolved clock shifts. */
7
+ export declare const THAI_CLAUSE_TIMING: {
8
+ sharedAdministration: (body: string, total?: string) => string;
9
+ clockWindow: (start: string, end: string, inclusive: boolean) => string;
10
+ offset: (minutes: number) => string;
11
+ dayShift: (days: number) => string;
12
+ };
@@ -1,4 +1,7 @@
1
+ import type { FhirR6Quantity } from "./types";
1
2
  export type I18nRecord = Record<string, string>;
3
+ export declare function cloneLocaleAliases(aliases: Record<string, string[]> | undefined): Record<string, string[]> | undefined;
4
+ export declare function flattenLocaleAliases(aliases: Record<string, string[]> | undefined): string[];
2
5
  export declare function normalizeLocaleTag(locale: string | undefined): string | undefined;
3
6
  export declare function baseLanguageTag(locale: string | undefined): string | undefined;
4
7
  export declare function localeFallbackChain(locale: string | undefined): string[];
@@ -6,3 +9,73 @@ export declare function localizedValue(i18n: Record<string, string | undefined>
6
9
  export declare function localizedConfig<T>(configs: Record<string, T> | undefined, locale: string | undefined, fallbackLocale?: string): T | undefined;
7
10
  export declare function localeKeys(...records: Array<Record<string, unknown> | undefined>): string[];
8
11
  export declare function composeLocalizedRecords(records: Array<I18nRecord | undefined>, compose: (values: string[], locale: string) => string | undefined): I18nRecord | undefined;
12
+ /** Spoken quantity operator shared by medication and action-graph renderers.
13
+ * No qualifier means no prefix; amounts must not become exact when the
14
+ * instruction graph supplies a richer sentence than the ordinary dose body. */
15
+ export declare function quantityComparatorText(comparator: FhirR6Quantity["comparator"], locale: string): string;
16
+ /** Locale-owned realization of already-resolved course semantics.
17
+ * The canonical formatter chooses clinical facts and scope; this contract
18
+ * supplies wording only. A language pack can provide it through the existing
19
+ * SigLocalization registry alongside its clause grammar. No second parser,
20
+ * external serialization, or locale checks belong in the canonical course.
21
+ */
22
+ export interface CourseLanguage {
23
+ readonly notPrefix: string;
24
+ readonly allSeparator: string;
25
+ readonly anySeparator: string;
26
+ readonly onlyIf: string;
27
+ readonly unless: string;
28
+ readonly exceptDates: string;
29
+ readonly exceptWeekdays: string;
30
+ readonly choicePrefix: string;
31
+ readonly stageSeparator: string;
32
+ readonly doseLabel: string;
33
+ amountRoleLabel(kind: "dose" | "rate" | "rateRange", role: "ordered" | "calculated" | undefined, sourceRole: string): string;
34
+ applicationSites(count: number): string;
35
+ readonly rateLabel: string;
36
+ readonly rateRangeLabel: string;
37
+ readonly unspecified: string;
38
+ withAuthoredDirections(current: string, source: string): string;
39
+ readonly treatmentStart: string;
40
+ readonly cycleStart: string;
41
+ readonly treatmentDayStart: string;
42
+ readonly afterPreviousPhase: string;
43
+ readonly nextDayAfterPreviousPhase: string;
44
+ readonly previousPhaseEnd?: string;
45
+ readonly incompleteInterpretation: string;
46
+ readonly retainedStructure: string;
47
+ readonly maxAdministrationLabel: string;
48
+ readonly maxLifetimeLabel: string;
49
+ readonly maxPeriodLabel: string;
50
+ readonly maxDosageLabel: string;
51
+ readonly courseLimitsLabel: string;
52
+ readonly stageLimitsLabel: string;
53
+ ifLimitExceeded(action: string): string;
54
+ eventWindow(start: string, end: string): string;
55
+ unresolvedCycleTiming(days: string, periodDays?: number, cycles?: number, anchor?: string): string;
56
+ weekdayName(day: string): string;
57
+ measurementName(name: string): string;
58
+ joinList(items: readonly string[]): string;
59
+ timeUnit(unit: string, value: number | undefined): string | undefined;
60
+ expression(kind: "dose" | "rate", detail: string | undefined): string;
61
+ upTo(value: string): string;
62
+ administrations(frequency: string, period?: string): string;
63
+ dosingPeriod(period: string): string;
64
+ periodContext(period: string): string;
65
+ startsWithinPeriod(offset: string, context: string): string;
66
+ endsWithinPeriod(offset: string, context: string): string;
67
+ afterTreatmentStart(offset: string): string;
68
+ relativeEvent(offset: string, event: string | undefined, before: boolean): string;
69
+ calendarWindow(start?: string, end?: string): string;
70
+ calendarEvents(events: readonly string[]): string;
71
+ reviewTiming(source?: string, boundary?: "end"): string;
72
+ dayRange(first: number, last: number): string;
73
+ fromDay(first: number): string;
74
+ throughDay(last: number): string;
75
+ noDoseDays(first: number, last: number): string;
76
+ noDoseWindow(start: string, end: string): string;
77
+ phaseCount(count: number): string;
78
+ unresolvedPhaseCount: string;
79
+ repeatCount(count: number): string;
80
+ repeatCycle(interval: string, exact: boolean, count?: number): string;
81
+ }
package/dist/maps.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BodySiteDefinition, EventTiming, FhirDayOfWeek, FhirPeriodUnit, PrnReasonDefinition, RouteCode, SNOMEDCTRouteCodes } from "./types";
1
+ import { BodySiteDefinition, EventTiming, FhirDayOfWeek, type FhirCoding, FhirPeriodUnit, PrnReasonDefinition, RouteCode, SNOMEDCTRouteCodes } from "./types";
2
2
  import { type SymptomDictionaryEntry } from "./symptom-terminology";
3
3
  /**
4
4
  * SNOMED CT codings aligned with every known RouteCode. Keeping the structure
@@ -15,6 +15,8 @@ export declare const ROUTE_TEXT: Record<RouteCode, string>;
15
15
  * into our internal RouteCode abstraction during round-tripping.
16
16
  */
17
17
  export declare const ROUTE_BY_SNOMED: Record<SNOMEDCTRouteCodes, RouteCode>;
18
+ /** Prefer the first explicitly identified route; keep a systemless legacy fallback. */
19
+ export declare function routeCodeFromCodings(codings: readonly Pick<FhirCoding, "system" | "code">[] | undefined): RouteCode | undefined;
18
20
  export interface RouteSynonym {
19
21
  code: RouteCode;
20
22
  text: string;
@@ -35,14 +37,20 @@ export declare const DEFAULT_BODY_SITE_SNOMED: Record<string, BodySiteDefinition
35
37
  export declare const DEFAULT_BODY_SITE_HINTS: Set<string>;
36
38
  export declare const HOUSEHOLD_VOLUME_UNITS: readonly ["tsp", "tbsp"];
37
39
  export declare const DEFAULT_UNIT_SYNONYMS: Record<string, string>;
40
+ /** Remove non-dimensional UCUM annotations for comparison only.
41
+ * Callers retain their own terminology, supported-unit and case rules. */
42
+ export declare function stripUcumAnnotations(code: string): string;
38
43
  /** Resolve standard codes and plain unit labels to the same calculation unit.
39
44
  * @param quantity A dose or limit quantity; its original display remains untouched.
45
+ * @param includeOpaqueCode Retain an unknown code as a display/counting label.
46
+ * Dimensional calculations disable that fallback, while still accepting authored
47
+ * unit labels and explicit UCUM expressions outside the simple-unit lexicon.
40
48
  */
41
49
  export declare function getDoseQuantityUnit(quantity: {
42
50
  system?: string;
43
51
  code?: string;
44
52
  unit?: string;
45
- } | undefined): string;
53
+ } | undefined, includeOpaqueCode?: boolean): string;
46
54
  /** Resolve a known dosage unit without changing its display or numerical value.
47
55
  * @param unit Canonical unit or supported synonym, including dimensional rates.
48
56
  */
@@ -15,9 +15,9 @@ export declare function medicationGuardLeadLexeme(source: string, licensedConseq
15
15
  /** Lexical boundary spellings shared with the typed guard phrase. No result
16
16
  * from these recognizers is itself a medication condition or administration. */
17
17
  export declare const MEDICATION_GUARD_BOUNDARIES: {
18
+ frontedLead: RegExp;
18
19
  alternative: RegExp;
19
20
  noDoseConsequent: RegExp;
20
- administrationHead: RegExp;
21
21
  };
22
22
  /** Recognize one predicate atom. Incomplete comparisons remain unsatisfied
23
23
  * head requirements, not measurements with a guessed variable name. */
@@ -1,5 +1,5 @@
1
1
  import { AnnotatedLexToken } from "./lexer/meaning";
2
- import { CanonicalAdditionalInstructionExpr, CanonicalAdministrationTargetGroup, BodySiteSpatialRelation, CanonicalDoseRange, CanonicalPrnReasonExpr, CanonicalSigClause, EventTiming, FhirCoding, FhirDayOfWeek, FhirPrimitiveElement, FhirPeriodUnit, PrnReasonLookupRequest, PrnReasonSuggestion, RouteCode, SiteCodeLookupRequest, SiteCodeSuggestion } from "./types";
2
+ import { CanonicalAdditionalInstructionExpr, CanonicalAdministrationTargetGroup, BodySiteSpatialRelation, CanonicalDoseRange, CanonicalPrnReasonExpr, CanonicalSigClause, EventTiming, FhirCoding, FhirDayOfWeek, FhirPrimitiveElement, FhirR6PrimitiveElement, FhirPeriodUnit, PrnReasonLookupRequest, PrnReasonSuggestion, RouteCode, SiteCodeLookupRequest, SiteCodeSuggestion } from "./types";
3
3
  export interface SiteLookupDetail {
4
4
  request: SiteCodeLookupRequest;
5
5
  suggestions: SiteCodeSuggestion[];
@@ -43,7 +43,7 @@ export declare class ParserState {
43
43
  set routeText(value: string | undefined);
44
44
  get methodText(): string | undefined;
45
45
  set methodText(value: string | undefined);
46
- get methodTextElement(): FhirPrimitiveElement | undefined;
46
+ get methodTextElement(): FhirR6PrimitiveElement | undefined;
47
47
  set methodTextElement(value: FhirPrimitiveElement | undefined);
48
48
  get methodCoding(): LocalizedCoding | undefined;
49
49
  set methodCoding(value: LocalizedCoding | undefined);
@@ -41,6 +41,17 @@ interface SemanticConstraint {
41
41
  interface SemanticConstruction extends RegimenSemanticConstruction {
42
42
  constraints: readonly SemanticConstraint[];
43
43
  }
44
+ /** A source-unowned single count is an execution default, not a written
45
+ * schedule or phase bound. Both boundary planning and cadence inheritance use
46
+ * this same distinction before a later adjunct completes the administration. */
47
+ export declare function hasImplicitSingleCount(clause: CanonicalSigClause): boolean;
48
+ /** A postposed onset completes a dose whose only timing is local runtime
49
+ * or delay. Independent recurrence, anchored positions and authored bounds
50
+ * remain capable of establishing a separate treatment phase. */
51
+ export declare function canReceivePostposedOnset(probe: ProbeSummary): boolean;
52
+ /** A single clock without independent recurrence or phase boundaries can
53
+ * locate the initial administration in an explicitly ordered clock sequence. */
54
+ export declare function singleClockWithoutRecurrence(schedule: CanonicalSigClause['schedule']): string | undefined;
44
55
  /**
45
56
  * Distributive cadence is licensed only for a coordinated dose continuation.
46
57
  * The right daughter is the scoped cadence donor; an independently headed,
@@ -1,13 +1,9 @@
1
- import { type FhirProjectionOptions } from '../fhir';
1
+ import { type CanonicalBoundary, type RegimenPosition } from '../canonical/course';
2
2
  import type { HpsgSigSegment } from '../hpsg/segmenter';
3
3
  import type { BoundaryPlan } from '../hpsg/signature';
4
4
  import { type RegimenGraph } from './regimen';
5
- import type { CanonicalSigClause, EzCourseMetadata, EzDosage, FhirR6DosageDetails } from '../types';
6
- /** Treatment-relative positions retain calendar months as a distinct unit. */
7
- export interface RegimenPosition {
8
- unit: 'd' | 'mo';
9
- value: number;
10
- }
5
+ import type { CanonicalSigClause } from '../types';
6
+ export type { RegimenPosition } from '../canonical/course';
11
7
  export interface CanonicalParallelComponent {
12
8
  member: number;
13
9
  clause: CanonicalSigClause;
@@ -21,7 +17,11 @@ export interface CanonicalParallelPhase {
21
17
  kind: 'relative' | 'calendar';
22
18
  members: CanonicalParallelComponent[];
23
19
  start?: RegimenPosition;
20
+ /** Origin of the known relative start; absent retains elapsed semantics. */
21
+ startReference?: "treatment-day-start";
24
22
  end?: RegimenPosition;
23
+ /** A known same-track successor caps this phase without replacing its own end. */
24
+ phaseEnd?: CanonicalBoundary;
25
25
  }
26
26
  export interface CanonicalParallelTrack {
27
27
  phases: CanonicalParallelPhase[];
@@ -37,22 +37,12 @@ export type CanonicalParallelRegimen = {
37
37
  } | {
38
38
  kind: 'unresolved';
39
39
  reason: string;
40
+ tracks?: CanonicalParallelTrack[];
40
41
  } | {
41
42
  kind: 'resolved';
42
43
  tracks: CanonicalParallelTrack[];
43
44
  stages: CanonicalParallelStage[];
44
45
  };
45
- type ParallelProjection = {
46
- kind: 'not-parallel';
47
- } | {
48
- kind: 'unresolved';
49
- reason: string;
50
- } | {
51
- kind: 'resolved';
52
- dosages: EzDosage[];
53
- course: EzCourseMetadata;
54
- details: FhirR6DosageDetails;
55
- };
56
46
  /**
57
47
  * Build independent track windows and canonical global stages from typed HPSG
58
48
  * clauses and licensed regimen relations. No FHIR object or source text is
@@ -60,26 +50,3 @@ type ParallelProjection = {
60
50
  * per-clause results while this richer course projection stays unresolved.
61
51
  */
62
52
  export declare function buildCanonicalParallelRegimen(clauses: readonly CanonicalSigClause[], segments: readonly HpsgSigSegment[], plan: BoundaryPlan, graph: RegimenGraph): CanonicalParallelRegimen;
63
- export declare const TREATMENT_START_SYSTEM = "http://hl7.org/fhir/evidence-variable-event";
64
- /** Shared pure lowering of an already-typed treatment-relative position. */
65
- export declare function relativeTime(position: RegimenPosition | {
66
- unit: "s" | "min" | "h" | "wk" | "a";
67
- value: number;
68
- }): {
69
- contextCode: {
70
- coding: {
71
- system: string;
72
- code: string;
73
- display: string;
74
- }[];
75
- };
76
- offsetDuration: {
77
- value: number;
78
- unit: "s" | "min" | "h" | "d" | "wk" | "mo" | "a";
79
- system: string;
80
- code: "s" | "min" | "h" | "d" | "wk" | "mo" | "a";
81
- };
82
- };
83
- /** Pure one-way serialization of an already composed canonical course. */
84
- export declare function projectParallelRegimen(regimen: CanonicalParallelRegimen, clauseTexts: readonly (string | undefined)[], renderedInstruction: string, options?: FhirProjectionOptions): ParallelProjection;
85
- export {};
@@ -1,7 +1,7 @@
1
1
  import type { BoundaryPlan, BoundaryRelation } from '../hpsg/signature';
2
2
  import type { HpsgSigSegment } from '../hpsg/segmenter';
3
3
  import { ParserState } from '../parser-state';
4
- import type { CanonicalSigClause, FhirQuantity } from '../types';
4
+ import type { CanonicalSigClause, FhirQuantity, ParseOptions } from '../types';
5
5
  export interface RegimenPhase {
6
6
  id: number;
7
7
  members: number[];
@@ -37,6 +37,10 @@ export interface InheritanceEvidence {
37
37
  }
38
38
  /** Retain coordination as a group; sequence and independent delimiters start new groups. */
39
39
  export declare function buildRegimenGraph(plan: BoundaryPlan, segments: readonly HpsgSigSegment[], states?: readonly ParserState[]): RegimenGraph;
40
+ /** Whether the authored endpoints identify one exact course duration. */
41
+ export declare function hasExactScheduleDuration(schedule: CanonicalSigClause["schedule"]): schedule is NonNullable<CanonicalSigClause["schedule"]> & {
42
+ duration: number;
43
+ };
40
44
  /**
41
45
  * A date-anchored whole-day or calendar-month duration has one inclusive window.
42
46
  * Materialize that window on the typed schedule before FHIR projection so the
@@ -49,7 +53,7 @@ export declare function anchoredScheduleDurationEnd(schedule: CanonicalSigClause
49
53
  * the derived start, and only anchors shared by every predecessor daughter
50
54
  * may fill an otherwise unanchored successor.
51
55
  */
52
- export declare function scopeSequentialPhaseSemantics(states: readonly ParserState[], segments: readonly HpsgSigSegment[], graph: RegimenGraph, source: string): InheritanceEvidence[];
56
+ export declare function scopeSequentialPhaseSemantics(states: readonly ParserState[], segments: readonly HpsgSigSegment[], graph: RegimenGraph, source: string, options?: ParseOptions): InheritanceEvidence[];
53
57
  /** Sequence belongs to the typed graph, before FHIR projection. */
54
58
  export declare function regimenMemberSequences(graph: RegimenGraph): number[];
55
59
  /** Materialize an explicit ADD phase over its preceding typed regimen.