ezmedicationinput 0.1.67 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +25 -22
  2. package/dist/advice.d.ts +20 -0
  3. package/dist/body-site-grammar.d.ts +34 -1
  4. package/dist/date-interpretation.d.ts +2 -0
  5. package/dist/dosage-course.d.ts +188 -0
  6. package/dist/fhir.d.ts +144 -9
  7. package/dist/format.d.ts +9 -1
  8. package/dist/hpsg/constructions.d.ts +105 -0
  9. package/dist/hpsg/lexical-classes.d.ts +170 -1
  10. package/dist/hpsg/procedural-context.d.ts +15 -1
  11. package/dist/hpsg/projection.d.ts +10 -2
  12. package/dist/hpsg/rule-context.d.ts +13 -0
  13. package/dist/hpsg/rules/clinical-quantity-rules.d.ts +9 -0
  14. package/dist/hpsg/rules/condition-rules.d.ts +15 -0
  15. package/dist/hpsg/rules/core-rules.d.ts +29 -0
  16. package/dist/hpsg/rules/instruction-rules.d.ts +9 -1
  17. package/dist/hpsg/rules/timing-rules.d.ts +121 -7
  18. package/dist/hpsg/signature.d.ts +342 -4
  19. package/dist/hpsg/type-system.d.ts +16 -1
  20. package/dist/hpsg/unification.d.ts +1 -0
  21. package/dist/i18n.d.ts +2 -0
  22. package/dist/index.cjs +48961 -31422
  23. package/dist/index.d.ts +21 -5
  24. package/dist/index.js +48936 -31421
  25. package/dist/instruction-action-locale-adapter.d.ts +1 -0
  26. package/dist/instruction-action-terminology.d.ts +16 -1
  27. package/dist/instruction-concept-terminology.d.ts +1 -1
  28. package/dist/instruction-graph-fhir.d.ts +1 -1
  29. package/dist/instruction-graph.d.ts +38 -2
  30. package/dist/ir.d.ts +12 -1
  31. package/dist/maps.d.ts +15 -0
  32. package/dist/medication-condition.d.ts +42 -0
  33. package/dist/parser-state.d.ts +5 -1
  34. package/dist/parser.d.ts +5 -2
  35. package/dist/regimen/coordination-scope.d.ts +53 -0
  36. package/dist/regimen/grammar.d.ts +68 -0
  37. package/dist/regimen/parallel-course.d.ts +85 -0
  38. package/dist/regimen/planner.d.ts +19 -0
  39. package/dist/regimen/regimen.d.ts +66 -0
  40. package/dist/schedule.d.ts +9 -6
  41. package/dist/stable-structure.d.ts +23 -1
  42. package/dist/types.d.ts +433 -28
  43. package/dist/utils/strength.d.ts +16 -0
  44. package/package.json +3 -2
@@ -22,6 +22,7 @@ export interface InstructionActionRealizationInput {
22
22
  }
23
23
  export interface InstructionActionLocaleAdapter {
24
24
  locale: string;
25
+ selectLexicalRealization?(input: InstructionActionRealizationInput): InstructionActionRealizationInput;
25
26
  render(realizer: MedicationInstructionActionRealizer, input: InstructionActionRealizationInput): string | undefined;
26
27
  renderNegated(input: InstructionActionRealizationInput): string;
27
28
  applyPositiveModality(text: string, frame: AdviceFrame): string;
@@ -1,4 +1,4 @@
1
- import { FhirCoding, MedicationInstructionActionDefinition, ParseOptions } from "./types";
1
+ import { AdviceArgument, FhirCoding, MedicationInstructionActionDefinition, ParseOptions } from "./types";
2
2
  export declare const MEDICATION_INSTRUCTION_ACTION_SYSTEM: string;
3
3
  export interface MedicationInstructionActionCodeSystem {
4
4
  resourceType: "CodeSystem";
@@ -18,9 +18,24 @@ export interface MedicationInstructionActionCodeSystem {
18
18
  }>;
19
19
  }>;
20
20
  }
21
+ /** Bound phrase matching by the declared lexicon without widening unrelated scans.
22
+ * @param lead Normalized first token of a possible instruction action.
23
+ */
24
+ export declare function medicationInstructionActionSpanLimit(lead: string, options?: ParseOptions): number;
21
25
  export declare function normalizeActionSurface(value: string): string;
26
+ /** Preserve coded constituents separately from equivalent whole-action codings. */
27
+ export declare function cloneMedicationInstructionActionSemanticComponents(components: MedicationInstructionActionDefinition["semanticComponents"]): MedicationInstructionActionDefinition["semanticComponents"];
22
28
  export declare function cloneMedicationInstructionActionRealizerConfig(config: MedicationInstructionActionDefinition["realizerConfig"]): MedicationInstructionActionDefinition["realizerConfig"];
23
29
  export declare function medicationInstructionActionLocaleRealizerConfig(config: MedicationInstructionActionDefinition["realizerConfig"], locale: string): import("./types").MedicationInstructionActionLocaleRealizerConfig | undefined;
30
+ /** Shared typed-argument matcher for both equivalent context codings and
31
+ * independent standards-coded constituents. No new language interpretation. */
32
+ export declare function matchesMedicationInstructionActionContextArgument(expected: NonNullable<MedicationInstructionActionDefinition["contextualCodings"]>[number]["whenArgument"], args: readonly AdviceArgument[]): boolean;
33
+ /** Resolve exact whole-action mappings licensed by typed argument semantics.
34
+ * Shared by the primary HPSG graph and optional semantic-resolver graph. */
35
+ export declare function medicationInstructionActionContextualCodings(definition: MedicationInstructionActionDefinition, args: readonly AdviceArgument[]): FhirCoding[];
36
+ /** Combine only constituents justified by this action's actual typed arguments.
37
+ * Do not place fragment/finding/qualifier codes in whole-predicate Codings. */
38
+ export declare function medicationInstructionActionSemanticComponentsForArgs(definition: MedicationInstructionActionDefinition, args: readonly AdviceArgument[]): MedicationInstructionActionDefinition["semanticComponents"];
24
39
  export declare function resolveMedicationInstructionSequenceAction(surface: string, options?: ParseOptions): MedicationInstructionActionDefinition | undefined;
25
40
  export declare function resolveMedicationInstructionSeparableAction(lead: string, particle: string, options?: ParseOptions): MedicationInstructionActionDefinition | undefined;
26
41
  export declare function medicationInstructionActionIsSafetyScopeTarget(surface: string, options?: ParseOptions): boolean;
@@ -20,7 +20,7 @@ export interface MedicationInstructionConceptCodeSystem {
20
20
  }
21
21
  export declare function normalizeConceptSurface(value: string): string;
22
22
  export declare function resolveMedicationInstructionConcept(surface: string, options?: ParseOptions): MedicationInstructionConceptDefinition | undefined;
23
- export declare function getMedicationInstructionConcept(code: string): MedicationInstructionConceptDefinition | undefined;
23
+ export declare function getMedicationInstructionConcept(code: string, system?: string): MedicationInstructionConceptDefinition | undefined;
24
24
  export declare function listMedicationInstructionConcepts(): MedicationInstructionConceptDefinition[];
25
25
  export declare function buildMedicationInstructionConceptCodeSystem(): MedicationInstructionConceptCodeSystem;
26
26
  export declare function medicationInstructionConceptCodings(definition: MedicationInstructionConceptDefinition): FhirCoding[];
@@ -1,4 +1,4 @@
1
1
  import { CanonicalInstructionGraph, FhirExtension } from "./types";
2
- export declare const MEDICATION_INSTRUCTION_GRAPH_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-instruction-graph";
2
+ export declare const MEDICATION_INSTRUCTION_GRAPH_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-instruction-graph";
3
3
  export declare function buildInstructionGraphExtension(graph: CanonicalInstructionGraph | undefined): FhirExtension | undefined;
4
4
  export declare function parseInstructionGraphExtension(extensions: FhirExtension[] | undefined): CanonicalInstructionGraph | undefined;
@@ -1,11 +1,47 @@
1
- import { AdviceFrame, AdviceModality, AdviceRelation, CanonicalInstructionGraph, CanonicalSigClause, ParseOptions } from "./types";
1
+ import { AdviceFrame, AdviceModality, AdviceRelation, CanonicalInstructionGraph, CanonicalSigClause, CanonicalAdditionalInstructionExpr, CanonicalSourceSpan, FhirCoding, ParseOptions, TextRange } from "./types";
2
2
  export declare function parseInstructionActions(sourceText: string, baseOffset?: number, options?: ParseOptions): AdviceFrame[];
3
+ export declare function isSupplementalHydrationInstruction(frame: AdviceFrame): boolean;
3
4
  export declare function refreshInstructionGraphDerivedState(graph: CanonicalInstructionGraph): void;
4
- export declare function buildInstructionGraph(input: string, clause: CanonicalSigClause, options?: ParseOptions): CanonicalInstructionGraph | undefined;
5
+ export declare function buildInstructionGraph(input: string, clause: CanonicalSigClause, options?: ParseOptions, semanticOwnershipRanges?: readonly TextRange[]): CanonicalInstructionGraph | undefined;
5
6
  export declare function realizeInstructionAction(frame: AdviceFrame, locale?: string): string;
6
7
  export declare function instructionGraphRepresentsText(graph: CanonicalInstructionGraph, text: string): boolean;
7
8
  export declare function instructionGraphTextParticipatesInRelation(graph: CanonicalInstructionGraph, text: string): boolean;
8
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;
32
+ /** Exact source-backed discourse connector that introduces the first action
33
+ * after the canonical administration. This lets realization preserve contrast
34
+ * without pretending that it is the temporal THEN relation. */
35
+ 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;
9
45
  export declare function instructionGraphRichPrimaryAction(clause: CanonicalSigClause): AdviceFrame | undefined;
10
46
  export declare function instructionGraphRoundTripPrimaryAction(clause: CanonicalSigClause): AdviceFrame | undefined;
11
47
  export declare function instructionGraphPrimarySiteRelation(clause: CanonicalSigClause): AdviceRelation | undefined;
package/dist/ir.d.ts CHANGED
@@ -2,4 +2,15 @@ import { ParserState } from "./parser-state";
2
2
  import { CanonicalSigClause } from "./types";
3
3
  export declare function canonicalClauseHasAdministrationSemantics(clause: CanonicalSigClause): boolean;
4
4
  export declare function buildCanonicalSigClauses(internal: ParserState): CanonicalSigClause[];
5
- export declare function shiftCanonicalSigClauses(clauses: CanonicalSigClause[], offset: number): void;
5
+ /**
6
+ * Convert one segment's relative canonical source ranges into full-SIG ranges.
7
+ *
8
+ * Flattened dosage rows may share nested evidence, target, and instruction
9
+ * frames. Keep the same seen-set across their projections so an aliased source
10
+ * span moves once for the segment, not once for every projected dosage.
11
+ *
12
+ * @param clauses Canonical clauses to rebase.
13
+ * @param offset Absolute start of the source segment in the full SIG.
14
+ * @param shiftedSpans Identity set shared by all projections of one segment.
15
+ */
16
+ export declare function shiftCanonicalSigClauses(clauses: CanonicalSigClause[], offset: number, shiftedSpans?: WeakSet<object>): void;
package/dist/maps.d.ts CHANGED
@@ -35,6 +35,21 @@ export declare const DEFAULT_BODY_SITE_SNOMED: Record<string, BodySiteDefinition
35
35
  export declare const DEFAULT_BODY_SITE_HINTS: Set<string>;
36
36
  export declare const HOUSEHOLD_VOLUME_UNITS: readonly ["tsp", "tbsp"];
37
37
  export declare const DEFAULT_UNIT_SYNONYMS: Record<string, string>;
38
+ /** Resolve standard codes and plain unit labels to the same calculation unit.
39
+ * @param quantity A dose or limit quantity; its original display remains untouched.
40
+ */
41
+ export declare function getDoseQuantityUnit(quantity: {
42
+ system?: string;
43
+ code?: string;
44
+ unit?: string;
45
+ } | undefined): string;
46
+ /** Resolve a known dosage unit without changing its display or numerical value.
47
+ * @param unit Canonical unit or supported synonym, including dimensional rates.
48
+ */
49
+ export declare function getStandardDoseUnitCoding(unit: string | undefined): {
50
+ system: string;
51
+ code: string;
52
+ } | undefined;
38
53
  export interface ProductFormHint {
39
54
  routeHint?: RouteCode;
40
55
  }
@@ -0,0 +1,42 @@
1
+ import { MedicationCondition } from "./types";
2
+ import type { HpsgGuardFeature } from "./hpsg/signature";
3
+ export { parseMedicationGuard } from "./hpsg/constructions";
4
+ export type { ParsedMedicationGuard } from "./hpsg/constructions";
5
+ export declare const CIRCUMSTANTIAL_CONDITION_HEADS: Set<string>;
6
+ export interface MedicationGuardLeadLexeme {
7
+ start: number;
8
+ end: number;
9
+ marker: "if" | "only-if" | "unless";
10
+ circumstantial?: true;
11
+ }
12
+ /** Recognize a conditional marker's spelling, leaving its predicate licensing
13
+ * and scope to the HPSG guard-head construction. */
14
+ export declare function medicationGuardLeadLexeme(source: string, licensedConsequent?: boolean): MedicationGuardLeadLexeme | undefined;
15
+ /** Lexical boundary spellings shared with the typed guard phrase. No result
16
+ * from these recognizers is itself a medication condition or administration. */
17
+ export declare const MEDICATION_GUARD_BOUNDARIES: {
18
+ alternative: RegExp;
19
+ noDoseConsequent: RegExp;
20
+ administrationHead: RegExp;
21
+ };
22
+ /** Recognize one predicate atom. Incomplete comparisons remain unsatisfied
23
+ * head requirements, not measurements with a guessed variable name. */
24
+ export declare function medicationConditionAtomLexeme(input: string): HpsgGuardFeature;
25
+ /** Recognize a predicate negator, not the beginning of a comparison idiom.
26
+ * @param source One predicate atom before Boolean coordination.
27
+ */
28
+ export declare function conditionNegationPrefixLength(source: string): number | undefined;
29
+ export interface ConditionSourceLexeme {
30
+ start: number;
31
+ end: number;
32
+ operator?: "all" | "any";
33
+ }
34
+ /** Lexicalize Boolean connective surfaces without assigning a tree or scope. */
35
+ export declare function conditionSourceLexemes(source: string, start: number, end: number): ConditionSourceLexeme[];
36
+ /** Punctuation boundary excluding decimal points inside lexical quantities. */
37
+ export declare function medicationGuardClauseBoundary(text: string): number;
38
+ /**
39
+ * Evaluate a typed Boolean tree if observation values were supplied by the caller.
40
+ * Unknown measurements never evaluate to true and remain unevaluated.
41
+ */
42
+ export declare function evaluateMedicationCondition(condition: MedicationCondition, observed: Record<string, number | boolean>): boolean | undefined;
@@ -1,5 +1,5 @@
1
1
  import { AnnotatedLexToken } from "./lexer/meaning";
2
- import { CanonicalAdditionalInstructionExpr, 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, FhirPeriodUnit, PrnReasonLookupRequest, PrnReasonSuggestion, RouteCode, SiteCodeLookupRequest, SiteCodeSuggestion } from "./types";
3
3
  export interface SiteLookupDetail {
4
4
  request: SiteCodeLookupRequest;
5
5
  suggestions: SiteCodeSuggestion[];
@@ -81,6 +81,8 @@ export declare class ParserState {
81
81
  set activityTiming(value: import("./types").CanonicalActivityTimingExpr[] | undefined);
82
82
  get occurrenceCap(): import("./types").CanonicalOccurrenceCapExpr | undefined;
83
83
  set occurrenceCap(value: import("./types").CanonicalOccurrenceCapExpr | undefined);
84
+ get maxDosePerPeriod(): import("./types").CanonicalDosePeriodMaximumExpr[] | undefined;
85
+ set maxDosePerPeriod(value: import("./types").CanonicalDosePeriodMaximumExpr[] | undefined);
84
86
  get timingCode(): string | undefined;
85
87
  set timingCode(value: string | undefined);
86
88
  get asNeeded(): boolean | undefined;
@@ -104,6 +106,8 @@ export declare class ParserState {
104
106
  get siteSpatialRelation(): BodySiteSpatialRelation | undefined;
105
107
  set siteSpatialRelation(value: BodySiteSpatialRelation | undefined);
106
108
  get siteAdministrationTargetCount(): number | undefined;
109
+ get administrationTargetGroup(): CanonicalAdministrationTargetGroup | undefined;
110
+ set administrationTargetGroup(value: CanonicalAdministrationTargetGroup | undefined);
107
111
  set siteAdministrationTargetCount(value: number | undefined);
108
112
  get additionalInstructions(): CanonicalAdditionalInstructionExpr[];
109
113
  set additionalInstructions(value: CanonicalAdditionalInstructionExpr[]);
package/dist/parser.d.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import { ParserState, Token } from "./parser-state";
2
2
  export { applyPrnReasonCoding, applyPrnReasonCodingAsync } from "./prn-reason-coding";
3
3
  export { applySiteCoding, applySiteCodingAsync } from "./site-coding";
4
- import { ParseOptions, TextRange } from "./types";
4
+ import { BodySiteDefinition, ParseOptions, TextRange } from "./types";
5
5
  export declare function tokenize(input: string): Token[];
6
+ export declare function buildCustomSiteHints(map: Record<string, BodySiteDefinition> | undefined): Set<string> | undefined;
6
7
  export declare function findUnparsedTokenGroups(state: ParserState): Array<{
7
8
  tokens: Token[];
8
9
  range?: TextRange;
9
10
  }>;
10
- export declare function parseClauseState(input: string, options?: ParseOptions): ParserState;
11
+ /** Raw typed analysis for grammar/treebank tests; no canonical or FHIR projection. */
12
+ export declare function parseClauseSign(input: string, options?: ParseOptions): import("./hpsg/signature").HpsgSign | undefined;
13
+ export declare function parseClauseState(input: string, options?: ParseOptions, customSiteHints?: Set<string> | undefined): ParserState;
@@ -0,0 +1,53 @@
1
+ import { ParserState } from '../parser-state';
2
+ import type { CanonicalScheduleSemanticField } from '../types';
3
+ import type { HpsgSigSegment } from '../hpsg/segmenter';
4
+ import type { BoundaryPlan } from '../hpsg/signature';
5
+ export interface CoordinatedClauseState {
6
+ state: ParserState;
7
+ start: number;
8
+ end: number;
9
+ }
10
+ export interface CoordinationScopeApplication {
11
+ rule: string;
12
+ from: number;
13
+ to: number;
14
+ fields: string[];
15
+ }
16
+ type ScheduleSemanticField = CanonicalScheduleSemanticField;
17
+ export interface TimingAnchorCompositionApplication {
18
+ rule: 'hpsg.cx.regimen.coordinated-timing-anchors' | 'hpsg.cx.regimen.interval-origin';
19
+ recipient: number;
20
+ donor: number;
21
+ fields: Array<ScheduleSemanticField | 'method'>;
22
+ }
23
+ export interface TimingAnchorCompositionResult {
24
+ absorbed: Set<number>;
25
+ applications: TimingAnchorCompositionApplication[];
26
+ }
27
+ /**
28
+ * Compose equivalent typed administration daughters before FHIR lowering.
29
+ * Only clock/event anchors may differ; every other schedule and administration
30
+ * feature must already unify, so independent routes, sites and phases survive.
31
+ */
32
+ export declare function composeCoordinatedTimingAnchors(states: readonly ParserState[], plan: BoundaryPlan, segments: readonly HpsgSigSegment[], source: string): TimingAnchorCompositionResult;
33
+ /**
34
+ * Scope a semicolon-terminal negative instruction over compatible dosage
35
+ * daughters before FHIR lowering. The HPSG action licenses the adjunct, and
36
+ * the boundary graph supplies its regimen path; no surface text is reparsed.
37
+ */
38
+ export declare function scopeTrailingSharedNegativeInstructions(states: readonly ParserState[], plan: BoundaryPlan, segments: readonly {
39
+ start: number;
40
+ end: number;
41
+ }[], source: string): void;
42
+ export declare function scopeMedicationConditionTargets(states: ParserState[], plan: BoundaryPlan, segments: HpsgSigSegment[]): void;
43
+ export declare function applyCoordinatedCadenceScopes(states: readonly CoordinatedClauseState[], plan: BoundaryPlan, source: string): CoordinationScopeApplication[];
44
+ /**
45
+ * Apply the segmenter's licensed trailing shared course duration directly to
46
+ * typed HPSG clauses. This intentionally never touches FHIR or rendered text.
47
+ */
48
+ export declare function scopeTrailingSharedDuration(states: readonly ParserState[], segments: readonly {
49
+ start: number;
50
+ text: string;
51
+ inheritTrailingDurationFromNext?: boolean;
52
+ }[]): void;
53
+ export {};
@@ -0,0 +1,68 @@
1
+ import { type CanonicalSigClause } from "../types";
2
+ import type { BoundaryDecision, BoundarySite, CoordinationConnectorKind, CoordinationScopeFacts, Proposal, ProbeSummary, RegimenSemanticConstruction, RegimenSemanticSelection, TrailingInstructionScopeFacts } from '../hpsg/signature';
3
+ /** A recognized modifier of an administration remains meaningful even when
4
+ * it cannot be assigned a clock time (for example an accompanying snack).
5
+ * @param clause Source-typed clause whose explicit dose is being segmented.
6
+ */
7
+ export declare function hasAdministrationAdjunct(clause: CanonicalSigClause): boolean;
8
+ /** Typed boundary facts are a separate signature from the production clause grammar. */
9
+ export interface BoundaryFacts {
10
+ site: BoundarySite;
11
+ left: ProbeSummary;
12
+ right: ProbeSummary;
13
+ inheritedAdministration: boolean;
14
+ connectorKind: CoordinationConnectorKind;
15
+ explicitRightUnit: boolean;
16
+ rightHasProcedure: boolean;
17
+ rightAfterFirstAdministration: boolean;
18
+ leftDateSpan: boolean;
19
+ rightDateSpan: boolean;
20
+ leftTargetCue: boolean;
21
+ rightTargetCue: boolean;
22
+ }
23
+ interface Constraint {
24
+ feature: string;
25
+ satisfied: (facts: BoundaryFacts) => boolean;
26
+ }
27
+ interface Construction {
28
+ id: string;
29
+ priority: number;
30
+ constraints: readonly Constraint[];
31
+ relation: Proposal['relation'];
32
+ acceptsAdjacentDose?: boolean;
33
+ inheritFollowingDuration?: boolean;
34
+ preserveRelationAtSequenceSurface?: boolean;
35
+ semanticLicense?: Proposal['semanticLicense'];
36
+ }
37
+ interface SemanticConstraint {
38
+ feature: string;
39
+ satisfied: (facts: CoordinationScopeFacts) => boolean;
40
+ }
41
+ interface SemanticConstruction extends RegimenSemanticConstruction {
42
+ constraints: readonly SemanticConstraint[];
43
+ }
44
+ /**
45
+ * Distributive cadence is licensed only for a coordinated dose continuation.
46
+ * The right daughter is the scoped cadence donor; an independently headed,
47
+ * incomplete, conflicting, or already-timed daughter cannot participate.
48
+ */
49
+ export declare const COORDINATION_SCOPE_CONSTRUCTIONS: readonly SemanticConstruction[];
50
+ export declare function grammaticalCoordinationScopes(facts: CoordinationScopeFacts): RegimenSemanticSelection[];
51
+ /**
52
+ * License a terminal negative adjunct from typed action and regimen facts.
53
+ * Surface recognition has already happened in HPSG; this rule only decides
54
+ * whether that local adjunct scopes over a related compatible administration.
55
+ */
56
+ export declare function grammaticalTrailingInstructionScope(facts: TrailingInstructionScopeFacts): RegimenSemanticSelection | undefined;
57
+ /** Exact elapsed interval on a terminal wait action, already composed by HPSG. */
58
+ export declare function terminalAdministrationDelay(clause: CanonicalSigClause): number | undefined;
59
+ /** Rules inspect features only. Surface/locale recognition belongs to lexical and span producers. */
60
+ export declare const CONSTRUCTIONS: readonly Construction[];
61
+ export interface RejectedConstruction {
62
+ rule: string;
63
+ failedConstraints: string[];
64
+ }
65
+ export declare function grammaticalProposals(f: BoundaryFacts, rejected?: RejectedConstruction[]): Proposal[];
66
+ /** Hard constraints dominate licensed rules; equal-priority conflicting actions stay unresolved/kept. */
67
+ export declare function arbitrate(site: BoundarySite, proposals: Proposal[]): BoundaryDecision;
68
+ export {};
@@ -0,0 +1,85 @@
1
+ import { type FhirProjectionOptions } from '../fhir';
2
+ import type { HpsgSigSegment } from '../hpsg/segmenter';
3
+ import type { BoundaryPlan } from '../hpsg/signature';
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
+ }
11
+ export interface CanonicalParallelComponent {
12
+ member: number;
13
+ clause: CanonicalSigClause;
14
+ /** Stage-local inclusive end without replacing explicit source semantics. */
15
+ effectiveBoundsEnd?: string;
16
+ boundsEndBasis?: 'next-phase-start' | 'anchored-duration';
17
+ /** Original track-phase origin retained when copied across global steps. */
18
+ phaseOrigin?: RegimenPosition;
19
+ }
20
+ export interface CanonicalParallelPhase {
21
+ kind: 'relative' | 'calendar';
22
+ members: CanonicalParallelComponent[];
23
+ start?: RegimenPosition;
24
+ end?: RegimenPosition;
25
+ }
26
+ export interface CanonicalParallelTrack {
27
+ phases: CanonicalParallelPhase[];
28
+ }
29
+ export interface CanonicalParallelStage {
30
+ sequence: number;
31
+ start: RegimenPosition;
32
+ end?: RegimenPosition;
33
+ components: CanonicalParallelComponent[];
34
+ }
35
+ export type CanonicalParallelRegimen = {
36
+ kind: 'not-parallel';
37
+ } | {
38
+ kind: 'unresolved';
39
+ reason: string;
40
+ } | {
41
+ kind: 'resolved';
42
+ tracks: CanonicalParallelTrack[];
43
+ stages: CanonicalParallelStage[];
44
+ };
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
+ /**
57
+ * Build independent track windows and canonical global stages from typed HPSG
58
+ * clauses and licensed regimen relations. No FHIR object or source text is
59
+ * inspected. Unsupported relationships remain editable through ordinary
60
+ * per-clause results while this richer course projection stays unresolved.
61
+ */
62
+ 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 {};
@@ -0,0 +1,19 @@
1
+ import { type ParseOptions } from '../types';
2
+ import type { ParserState } from '../parser-state';
3
+ import type { HpsgSigSegment } from '../hpsg/segmenter';
4
+ import type { BoundaryPlan, PlannerOptions } from '../hpsg/signature';
5
+ /** Reuse exact completed HPSG probes, but never a partial probe. Carry-forward
6
+ * is applied to the returned state by the same production consumer as a fresh
7
+ * parse, so it does not invalidate an exact segment result. */
8
+ export declare function takeBoundaryParsedState(plan: BoundaryPlan, start: number, end: number, text: string): ParserState | undefined;
9
+ /** Production boundary grammar: lexical candidates are arbitrated using typed
10
+ * constituent ownership before final clause parsing.
11
+ * @param input Original clinician instruction.
12
+ * @param options Terminology and interpretation context.
13
+ * @param experiment Optional diagnostic switches used by the comparison harness.
14
+ */
15
+ export declare function planBoundaries(input: string, options?: ParseOptions, experiment?: PlannerOptions): BoundaryPlan;
16
+ /** Return the segment view of the production boundary plan. */
17
+ export declare function parseSigSegments(input: string, options?: ParseOptions): HpsgSigSegment[];
18
+ /** The public parse pipelines use the production planner directly. */
19
+ export { planBoundaries as createBoundaryPlan };
@@ -0,0 +1,66 @@
1
+ import type { BoundaryPlan, BoundaryRelation } from '../hpsg/signature';
2
+ import type { HpsgSigSegment } from '../hpsg/segmenter';
3
+ import { ParserState } from '../parser-state';
4
+ import type { CanonicalSigClause, FhirQuantity } from '../types';
5
+ export interface RegimenPhase {
6
+ id: number;
7
+ members: number[];
8
+ /** Cycle agreed by every typed administration member in this phase. */
9
+ repeatCycle?: FhirQuantity;
10
+ repeatCount?: number;
11
+ }
12
+ export interface PhaseEdge {
13
+ from: number;
14
+ to: number;
15
+ relation: BoundaryRelation;
16
+ }
17
+ export interface RegimenGraph {
18
+ /** Per-administration dependencies within a repeating phase. */
19
+ administrationDependencies?: Array<{
20
+ from: number;
21
+ to: number;
22
+ delayMinutes: number;
23
+ }>;
24
+ phases: RegimenPhase[];
25
+ sequences: PhaseEdge[];
26
+ /** Whole-course interval contributed by a typed recurring cycle sign. */
27
+ repeatCycle?: FhirQuantity;
28
+ /** Explicit finite number of whole-course repetitions. */
29
+ repeatCount?: number;
30
+ }
31
+ export interface InheritanceEvidence {
32
+ rule: string;
33
+ phase: number;
34
+ sources: number[];
35
+ target: number;
36
+ fields: string[];
37
+ }
38
+ /** Retain coordination as a group; sequence and independent delimiters start new groups. */
39
+ export declare function buildRegimenGraph(plan: BoundaryPlan, segments: readonly HpsgSigSegment[], states?: readonly ParserState[]): RegimenGraph;
40
+ /**
41
+ * A date-anchored whole-day or calendar-month duration has one inclusive window.
42
+ * Materialize that window on the typed schedule before FHIR projection so the
43
+ * wire layer never has to choose between boundsPeriod and boundsDuration.
44
+ */
45
+ export declare function anchoredScheduleDurationEnd(schedule: CanonicalSigClause['schedule']): string | undefined;
46
+ /**
47
+ * License sequential schedule inheritance on the typed regimen graph before
48
+ * canonical clauses are lowered to FHIR. A complete predecessor phase owns
49
+ * the derived start, and only anchors shared by every predecessor daughter
50
+ * may fill an otherwise unanchored successor.
51
+ */
52
+ export declare function scopeSequentialPhaseSemantics(states: readonly ParserState[], segments: readonly HpsgSigSegment[], graph: RegimenGraph, source: string): InheritanceEvidence[];
53
+ /** Sequence belongs to the typed graph, before FHIR projection. */
54
+ export declare function regimenMemberSequences(graph: RegimenGraph): number[];
55
+ /** Materialize an explicit ADD phase over its preceding typed regimen.
56
+ * Source-only operation resolution runs before FHIR; ordinary parses return
57
+ * their original arrays and unrelated parallel tracks are never inspected.
58
+ * @param states Interpreted source clause states.
59
+ * @param segments Source ranges corresponding to those states.
60
+ * @param graph Source-licensed phase relations before wire projection.
61
+ */
62
+ export declare function expandRegimenAdjustmentPhases(states: ParserState[], segments: HpsgSigSegment[], graph: RegimenGraph): {
63
+ states: ParserState[];
64
+ segments: HpsgSigSegment[];
65
+ graph: RegimenGraph;
66
+ };
@@ -1,7 +1,10 @@
1
- import { FhirDosage, NextDueDoseOptions, TotalUnitsOptions, TotalUnitsResult } from "./types";
2
- /**
3
- * Produces the next dose timestamps in ascending order according to the
4
- * provided configuration and dosage metadata.
5
- */
6
- export declare function nextDueDoses(dosage: FhirDosage, options: NextDueDoseOptions): string[];
1
+ import { FhirDosage, NextDueDoseOptions, FhirR6DosageDetails, ParseBatchResult, TotalUnitsOptions, TotalUnitsResult } from "./types";
2
+ export declare function nextDueDoses(dosage: FhirDosage | readonly FhirDosage[] | FhirR6DosageDetails | ParseBatchResult, options: NextDueDoseOptions): string[];
3
+ /** Supply math is deterministic only when the administered amount is known.
4
+ * Clinical conditions/PRN are represented as a maximum permitted supply,
5
+ * not as a claim that every available dose will actually be administered. */
6
+ export declare class MedicationQuantityCalculationError extends Error {
7
+ readonly code: string;
8
+ constructor(code: string, message: string);
9
+ }
7
10
  export declare function calculateTotalUnits(options: TotalUnitsOptions): TotalUnitsResult;
@@ -1 +1,23 @@
1
- export declare function stableStructureKey(value: unknown): string;
1
+ /**
2
+ * Compare acyclic parser/FHIR data directly. Object property order is not
3
+ * meaning; omitted optional fields equal explicit undefined. Array order and
4
+ * primitive types remain significant. No sorting or normalized copy is needed.
5
+ * @param left First structured value.
6
+ * @param right Second structured value.
7
+ */
8
+ export declare function equalStructuredValues(left: unknown, right: unknown): boolean;
9
+ /**
10
+ * Copy acyclic plain data while preserving optional properties and primitive
11
+ * types. Each call owns its nested objects, including unfamiliar FHIR fields.
12
+ * This is not a serializer and never invokes an object's toJSON hook.
13
+ * @param value Plain parser/FHIR data to detach from an editable source.
14
+ */
15
+ export declare function cloneStructuredValue<T>(value: T): T;
16
+ /**
17
+ * Order-independent object / order-sensitive array hash for candidate buckets.
18
+ * A hash is NOT semantic equality: every consumer must compare bucket members
19
+ * with equalStructuredValues before packing or dropping a candidate. Optional
20
+ * undefined fields are omitted consistently with that comparator.
21
+ * @param value Acyclic structured value whose candidate bucket is needed.
22
+ */
23
+ export declare function hashStructuredValue(value: unknown): number;