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
@@ -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,19 +37,25 @@ 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
43
47
  * wire layer never has to choose between boundsPeriod and boundsDuration.
44
48
  */
45
49
  export declare function anchoredScheduleDurationEnd(schedule: CanonicalSigClause['schedule']): string | undefined;
50
+ /** Inherit a source administration before selective target/clock partitioning. */
51
+ export declare function scopeDelayedTargetAdministrations(states: readonly ParserState[], segments: readonly HpsgSigSegment[], graph: RegimenGraph): void;
46
52
  /**
47
53
  * License sequential schedule inheritance on the typed regimen graph before
48
54
  * canonical clauses are lowered to FHIR. A complete predecessor phase owns
49
55
  * the derived start, and only anchors shared by every predecessor daughter
50
56
  * may fill an otherwise unanchored successor.
51
57
  */
52
- export declare function scopeSequentialPhaseSemantics(states: readonly ParserState[], segments: readonly HpsgSigSegment[], graph: RegimenGraph, source: string): InheritanceEvidence[];
58
+ export declare function scopeSequentialPhaseSemantics(states: readonly ParserState[], segments: readonly HpsgSigSegment[], graph: RegimenGraph, source: string, options?: ParseOptions): InheritanceEvidence[];
53
59
  /** Sequence belongs to the typed graph, before FHIR projection. */
54
60
  export declare function regimenMemberSequences(graph: RegimenGraph): number[];
55
61
  /** Materialize an explicit ADD phase over its preceding typed regimen.
@@ -74,6 +74,7 @@ export declare function resolveActionRelationSurfaceCandidates(surface: string):
74
74
  export declare function resolveActionRelationSurface(surface: string, preferredSemanticClasses?: readonly string[]): AdviceRelation | undefined;
75
75
  export declare function resolveActionRelationSurfaceByGrammarFeature(surface: string, feature: keyof AdviceRelationGrammarFeatures): AdviceRelation | undefined;
76
76
  export declare function resolveAdviceRelationSurface(surface: string): AdviceRelation | undefined;
77
+ /** Vocabulary definitions are borrowed under the immutable-output contract. */
77
78
  export declare function getAdviceRelationDefinition(relation: AdviceRelation): AdviceRelationDefinition | undefined;
78
79
  export declare function relationHasGrammarFeature(relation: AdviceRelation | undefined, feature: keyof AdviceRelationGrammarFeatures): boolean;
79
80
  export declare function getUniqueAdviceRelationByGrammarFeature(feature: keyof AdviceRelationGrammarFeatures): AdviceRelation | undefined;
@@ -1,10 +1,14 @@
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
- }
10
- export declare function calculateTotalUnits(options: TotalUnitsOptions): TotalUnitsResult;
1
+ /**
2
+ * Public medication execution boundary.
3
+ *
4
+ * Accept the established R5/R6/batch inputs and normalize them ONCE to the
5
+ * canonical course. All calendar, phase, occurrence and supply semantics are
6
+ * implemented in execution/engine, which has no import/export dependency.
7
+ * Canonical callers bypass interchange completely.
8
+ */
9
+ import type { FhirDosage, FhirR6DosageInstructionInput, ParseBatchResult, NextDueDoseOptions, TotalUnitsOptions, TotalUnitsResult } from "./types";
10
+ import type { CanonicalScheduleInput, CanonicalSupplyOptions } from "./canonical/course";
11
+ import { MedicationQuantityCalculationError } from "./execution/engine";
12
+ export { MedicationQuantityCalculationError };
13
+ export declare function nextDueDoses(input: FhirDosage | readonly FhirDosage[] | FhirR6DosageInstructionInput | ParseBatchResult | CanonicalScheduleInput, options: NextDueDoseOptions): string[];
14
+ export declare function calculateTotalUnits(options: TotalUnitsOptions | CanonicalSupplyOptions): TotalUnitsResult;
package/dist/snomed.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { FhirCoding, FhirR6Coding } from "./types";
1
2
  export declare const SNOMED_SYSTEM = "http://snomed.info/sct";
2
3
  export declare const SNOMED_CT_FINDING_SITE_ATTRIBUTE_CODE = "363698007";
3
4
  export declare const SNOMED_CT_FINDING_SITE_ATTRIBUTE_DISPLAY = "Finding site";
@@ -11,3 +12,5 @@ export declare const SNOMED_CT_RIGHT_QUALIFIER_CODE = "24028007";
11
12
  export declare const SNOMED_CT_RIGHT_QUALIFIER_DISPLAY = "Right";
12
13
  export declare const SNOMED_CT_BILATERAL_QUALIFIER_CODE = "51440002";
13
14
  export declare const SNOMED_CT_BILATERAL_QUALIFIER_DISPLAY = "Right and left";
15
+ /** Legacy shorthand defaults to SNOMED; a primitive companion alone does not establish identity. */
16
+ export declare function codingSystemWithSnomedDefault(coding: Pick<FhirCoding | FhirR6Coding, "system" | "_system"> | undefined): string | undefined;
@@ -7,6 +7,11 @@ export interface SuggestLocaleUnitRoutePair {
7
7
  export interface SuggestLocaleAdapter {
8
8
  locale: string;
9
9
  acceptsSurface(surface: string): boolean;
10
+ directTimeSuggestions?(input: string, limit: number): string[] | undefined;
11
+ directRelationSuggestions?(input: string, events: string[], acceptsEvent: (relation: string, event: string) => boolean, limit: number): string[] | undefined;
12
+ actionDisplay?(display: string, custom: boolean): string | undefined;
13
+ allowsAdjacentArgument?(action: string, suffix: string): boolean;
14
+ prnReasonLocale?(input: string): string | undefined;
10
15
  unitSuggestionUsesLocaleLexemes: boolean;
11
16
  includeEyeAbbreviations: boolean;
12
17
  preferRawSiteMapSurfaces: boolean;
@@ -18,6 +23,9 @@ export interface SuggestLocaleAdapter {
18
23
  partial: string;
19
24
  } | undefined;
20
25
  joinBodySite(lead: string, surface: string): string;
26
+ /** Own PRN recognition and vocabulary selection together. The vocabulary
27
+ * callback is lazy; legacy completion hooks remain the fallback. */
28
+ completePrn?(input: string, reasons: (locale?: string) => string[], limit: number): string[] | undefined;
21
29
  directPrnCompletion(input: string, reasons: string[], limit: number): string[] | undefined;
22
30
  buildUnitCandidate(prefix: string, dose: string, surface: string, route: string): string;
23
31
  unitSurface(unit: string, lexeme: SuggestLocaleLexemeResolver): string;
@@ -29,3 +37,10 @@ export interface SuggestLocaleAdapter {
29
37
  }
30
38
  export declare function registerSuggestLocaleAdapter(adapter: SuggestLocaleAdapter): void;
31
39
  export declare function getSuggestLocaleAdapter(locale: string): SuggestLocaleAdapter;
40
+ /** An unregistered locale shares the English clock fallback. A registered
41
+ * provider owns its absent or declining capability without augmentation. */
42
+ export declare function directLocaleTimeSuggestions(locale: string, input: string, limit: number): string[] | undefined;
43
+ /** Dispatch provider completion without constructing stock vocabulary for an
44
+ * unrelated input. Stock combined hooks already include their unchanged legacy
45
+ * matcher; a provider's independent legacy override remains a real fallback. */
46
+ export declare function completeLocalePrnSuggestions(adapter: SuggestLocaleAdapter, locale: string, input: string, reasons: (locale?: string) => string[], limit: number): string[] | undefined;
@@ -1,4 +1,4 @@
1
- import { SymptomDefinition } from "./types";
1
+ import { SymptomDefinition, PrnReasonLookupRequest, PrnReasonSelection } from "./types";
2
2
  export interface SymptomDictionaryEntry {
3
3
  canonical: string;
4
4
  definition: SymptomDefinition;
@@ -10,3 +10,7 @@ export declare const DEFAULT_SYMPTOM_DEFINITIONS: Record<string, SymptomDefiniti
10
10
  export declare function resolveSymptomDefinition(surface: string, ...customMaps: Array<Record<string, SymptomDefinition> | undefined>): SymptomDefinition | undefined;
11
11
  export declare function findSymptomDefinitionByCoding(system: string, code: string): SymptomDefinition | undefined;
12
12
  export declare function listSymptomDefinitions(): SymptomDefinition[];
13
+ /** Shared exact selection keys for grammar ownership and later coding. */
14
+ export declare function buildCombinedPrnReasonCanonical(request: PrnReasonLookupRequest): string | undefined;
15
+ export declare function collectPrnReasonLookupCanonicals(request: PrnReasonLookupRequest): string[];
16
+ export declare function matchPrnReasonSelection(selections: PrnReasonSelection | PrnReasonSelection[] | undefined, request: PrnReasonLookupRequest): PrnReasonSelection | undefined;
@@ -1,5 +1,114 @@
1
- import { EventTiming, FhirDayOfWeek, FhirPeriodUnit } from "./types";
1
+ import type { CanonicalScheduleExpr } from "./types";
2
+ import { EventTiming, FhirDayOfWeek, FhirPeriodUnit, type ParseOptions } from "./types";
3
+ /** Resolve authored event-relative offsets without changing their stored sign. */
4
+ export declare function signedTimingEventOffset(code: string, offset: number): number;
5
+ /** Standard event meanings that already supply a before/after relation. */
6
+ export declare function timingEventHasDirectionalRelation(code: string): boolean;
7
+ /** Exact standard timing identities shared by native compilation and wire
8
+ * projection. Local codes remain text unless this vocabulary recognizes them. */
9
+ /** Lexical shorthand selects clinic clock defaults; the typed repeat owns its cadence. */
10
+ export declare const SIG_TIMING_SHORTHAND_SYSTEM = "urn:ezmedicationinput:CodeSystem:timing-shorthand";
11
+ export declare const FHIR_GTS_TIMING_SYSTEM = "http://terminology.hl7.org/CodeSystem/v3-GTSAbbreviation";
12
+ export declare const FHIR_GTS_TIMING_CODES: Set<string>;
13
+ type TimingCodingIdentity = {
14
+ system?: string;
15
+ _system?: unknown;
16
+ code?: string;
17
+ };
18
+ /** An absent namespace allows shorthand; an explicitly unknown namespace does not. */
19
+ export declare function hasStandardTimingSystem(coding: TimingCodingIdentity | undefined): boolean;
20
+ /** Supported standard identity for coding selection and wire projection. */
21
+ export declare function isStandardTimingCoding(coding: TimingCodingIdentity | undefined): boolean;
22
+ /** Existing compact interval vocabulary applies to text and systemless codes. */
23
+ export declare function isCompactIntervalTimingCode(code: string): boolean;
24
+ /** Existing clinical preview abbreviations include shorthand such as QHS
25
+ * that is not emitted as a standard FHIR code. Foreign systems stay opaque. */
26
+ export declare function isPreviewTimingCoding(coding: TimingCodingIdentity | undefined): boolean;
27
+ /** Prefer an understood cadence over a local translation without changing
28
+ * either coding or its authored order. Local-only concepts keep their first code. */
29
+ export declare function preferredTimingCoding<T extends {
30
+ system?: string;
31
+ code?: string;
32
+ }>(timing: {
33
+ code?: {
34
+ coding?: readonly T[];
35
+ };
36
+ }, includePreview?: boolean): T | undefined;
37
+ /** Display-only coding is authored text, never an executable cadence. */
38
+ export declare function codeLessTimingDisplay(timing: {
39
+ code?: {
40
+ coding?: readonly {
41
+ code?: string;
42
+ display?: string;
43
+ }[];
44
+ };
45
+ } | undefined): string | undefined;
46
+ /** Preview shorthand does not change execution's standard-code preference. */
47
+ export declare function preferredPreviewTimingCoding<T extends {
48
+ system?: string;
49
+ code?: string;
50
+ }>(timing: {
51
+ code?: {
52
+ coding?: readonly T[];
53
+ };
54
+ }): T | undefined;
55
+ /** Recognized daily cadence, independent of configured clock realization. */
56
+ export declare const TIMING_CODE_DAILY_FREQUENCIES: Readonly<Record<string, number>>;
57
+ /** Exact standard elapsed intervals, separate from daily clock codes and
58
+ * language-specific SIG abbreviation recognition. */
59
+ export declare const TIMING_CODE_HOURLY_PERIODS: Readonly<Record<string, number>>;
60
+ /** Exact elapsed scales used to compare a numeric cadence, without assigning
61
+ * calendar-month lengths or choosing clinic clocks. */
62
+ export declare const FIXED_TIMING_PERIOD_SECONDS: Readonly<Record<string, number>>;
63
+ /** Exact grouping on treatment days within a whole civil-day interval.
64
+ * Preview and execution retain their own behavior outside this shared scope. */
65
+ export declare function isExactTreatmentDayCadence(repeat: {
66
+ frequency?: number;
67
+ frequencyMax?: number;
68
+ period?: number;
69
+ periodMax?: number;
70
+ periodUnit?: string;
71
+ }): boolean;
72
+ /** One exact cadence comparison for execution and clinical preview. */
73
+ export declare function matchesDailyCodeCadence(daily: number, repeat: {
74
+ frequency?: number;
75
+ period?: number;
76
+ periodUnit?: string;
77
+ }): boolean;
78
+ /** Whether a known daily cadence fits an authored frequency/period range.
79
+ * Execution retains validation and clock selection; preview uses this same
80
+ * intersection without resolving or replacing either authored endpoint. */
81
+ export declare function dailyCodeFitsRecurrenceRange(daily: number, repeat: {
82
+ frequency?: number;
83
+ frequencyMax?: number;
84
+ period?: number;
85
+ periodMax?: number;
86
+ periodUnit?: string;
87
+ }): boolean;
88
+ /** Standard coding has its own clinical meaning; free SIG shorthand stays lexical. */
89
+ export declare function timingCodeMeaning(coding: {
90
+ system?: string;
91
+ code?: string;
92
+ } | undefined): string | undefined;
93
+ /** Emit a standard identity only when its complete meaning matches the parsed
94
+ * shorthand. Restricted recurrence retains the established local-code map key. */
95
+ export declare function timingCodingFromSig(code: string | undefined, schedule?: CanonicalScheduleExpr): {
96
+ system: string;
97
+ code: string;
98
+ } | undefined;
99
+ /** Standard BED supplies an event anchor independently of the repeat cadence. */
100
+ export declare function timingPreviewDescriptor(code: string): import("./maps").FrequencyDescriptor;
101
+ /** Human previews also recognize existing SIG shorthand without treating it
102
+ * as a standard FHIR timing identity or changing its structured projection. */
103
+ export declare function intervalTimingPreviewDescriptor(code: string): {
104
+ period: number;
105
+ periodMax?: number;
106
+ periodUnit: FhirPeriodUnit;
107
+ } | undefined;
2
108
  export interface TimingSummaryOptions {
109
+ /** Scoped vocabulary in the original parse/format request. Do not build
110
+ * any second registry or retain it on the canonical clinical course. */
111
+ instructionActionMap?: ParseOptions["instructionActionMap"];
3
112
  realizationMode?: "normalized" | "roundtrip";
4
113
  groupMealTimingsByRelation?: boolean;
5
114
  includeTimesPerDaySummary?: boolean;
@@ -20,8 +129,12 @@ export interface TimingSummaryInput {
20
129
  periodUnit?: FhirPeriodUnit;
21
130
  timingCode?: string;
22
131
  dayOfWeek?: FhirDayOfWeek[];
132
+ dayOfMonth?: number[];
23
133
  when?: EventTiming[];
24
134
  timeOfDay?: string[];
25
135
  }
136
+ /** A named meal is an event anchor, distinct from a coarse morning/evening daypart. */
137
+ export declare function isSpecificMealTimingEvent(code: EventTiming): boolean;
26
138
  export declare function getMealTimingGroup(when: EventTiming[], options?: TimingSummaryOptions): MealTimingGroup | undefined;
27
139
  export declare function inferDailyOccurrenceCount(input: TimingSummaryInput, options?: TimingSummaryOptions): number | undefined;
140
+ export {};