ezmedicationinput 0.1.53 → 0.1.55

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 (37) hide show
  1. package/README.md +111 -25
  2. package/dist/body-site-grammar.d.ts +1 -0
  3. package/dist/event-timing-expression.d.ts +8 -0
  4. package/dist/fhir.d.ts +6 -1
  5. package/dist/hpsg/constructions.d.ts +6 -0
  6. package/dist/hpsg/defaults.d.ts +1 -0
  7. package/dist/hpsg/feature-structure.d.ts +5 -0
  8. package/dist/hpsg/lexical-classes.d.ts +41 -1
  9. package/dist/hpsg/method-lexicon.d.ts +14 -14
  10. package/dist/hpsg/procedural-context.d.ts +10 -0
  11. package/dist/hpsg/rules/condition-rules.d.ts +4 -0
  12. package/dist/hpsg/rules/core-rules.d.ts +1 -0
  13. package/dist/hpsg/rules/instruction-rules.d.ts +1 -0
  14. package/dist/hpsg/rules/prn-rules.d.ts +8 -0
  15. package/dist/hpsg/rules/timing-rules.d.ts +19 -0
  16. package/dist/hpsg/segmenter.d.ts +2 -1
  17. package/dist/hpsg/signature.d.ts +49 -2
  18. package/dist/hpsg/type-system.d.ts +48 -0
  19. package/dist/i18n.d.ts +2 -0
  20. package/dist/index.cjs +21887 -9720
  21. package/dist/index.d.ts +9 -0
  22. package/dist/index.js +21861 -9717
  23. package/dist/instruction-action-terminology.d.ts +29 -0
  24. package/dist/instruction-concept-terminology.d.ts +26 -0
  25. package/dist/instruction-graph-fhir.d.ts +4 -0
  26. package/dist/instruction-graph.d.ts +21 -0
  27. package/dist/instruction-semantic-resolver.d.ts +4 -0
  28. package/dist/ir.d.ts +1 -0
  29. package/dist/lexer/locale.d.ts +8 -0
  30. package/dist/lexer/token-types.d.ts +2 -0
  31. package/dist/localized-timing.d.ts +1 -0
  32. package/dist/maps.d.ts +2 -8
  33. package/dist/parser-state.d.ts +8 -0
  34. package/dist/symptom-terminology.d.ts +12 -0
  35. package/dist/timing-summary.d.ts +2 -0
  36. package/dist/types.d.ts +249 -4
  37. package/package.json +6 -2
@@ -0,0 +1,29 @@
1
+ import { FhirCoding, MedicationInstructionActionDefinition, ParseOptions } from "./types";
2
+ export declare const MEDICATION_INSTRUCTION_ACTION_SYSTEM: string;
3
+ export interface MedicationInstructionActionCodeSystem {
4
+ resourceType: "CodeSystem";
5
+ url: string;
6
+ name: string;
7
+ title: string;
8
+ status: "active";
9
+ experimental: boolean;
10
+ caseSensitive: boolean;
11
+ content: "complete";
12
+ concept: Array<{
13
+ code: string;
14
+ display: string;
15
+ designation?: Array<{
16
+ language: string;
17
+ value: string;
18
+ }>;
19
+ }>;
20
+ }
21
+ export declare function normalizeActionSurface(value: string): string;
22
+ export declare function resolveMedicationInstructionSeparableAction(lead: string, particle: string, options?: ParseOptions): MedicationInstructionActionDefinition | undefined;
23
+ export declare function medicationInstructionActionIsSafetyScopeTarget(surface: string, options?: ParseOptions): boolean;
24
+ export declare function resolveMedicationInstructionAction(surface: string, options?: ParseOptions): MedicationInstructionActionDefinition | undefined;
25
+ export declare function getMedicationInstructionAction(code: string): MedicationInstructionActionDefinition | undefined;
26
+ export declare function listMedicationInstructionActions(): MedicationInstructionActionDefinition[];
27
+ export declare function buildMedicationInstructionActionCodeSystem(): MedicationInstructionActionCodeSystem;
28
+ export declare function medicationInstructionActionCoding(definition: MedicationInstructionActionDefinition): FhirCoding;
29
+ export declare function medicationInstructionActionCodings(definition: MedicationInstructionActionDefinition): FhirCoding[];
@@ -0,0 +1,26 @@
1
+ import { FhirCoding, MedicationInstructionConceptDefinition, ParseOptions } from "./types";
2
+ export declare const MEDICATION_INSTRUCTION_CONCEPT_SYSTEM: string;
3
+ export interface MedicationInstructionConceptCodeSystem {
4
+ resourceType: "CodeSystem";
5
+ url: string;
6
+ name: string;
7
+ title: string;
8
+ status: "active";
9
+ experimental: boolean;
10
+ caseSensitive: boolean;
11
+ content: "complete";
12
+ concept: Array<{
13
+ code: string;
14
+ display: string;
15
+ designation?: Array<{
16
+ language: string;
17
+ value: string;
18
+ }>;
19
+ }>;
20
+ }
21
+ export declare function normalizeConceptSurface(value: string): string;
22
+ export declare function resolveMedicationInstructionConcept(surface: string, options?: ParseOptions): MedicationInstructionConceptDefinition | undefined;
23
+ export declare function getMedicationInstructionConcept(code: string): MedicationInstructionConceptDefinition | undefined;
24
+ export declare function listMedicationInstructionConcepts(): MedicationInstructionConceptDefinition[];
25
+ export declare function buildMedicationInstructionConceptCodeSystem(): MedicationInstructionConceptCodeSystem;
26
+ export declare function medicationInstructionConceptCodings(definition: MedicationInstructionConceptDefinition): FhirCoding[];
@@ -0,0 +1,4 @@
1
+ import { CanonicalInstructionGraph, FhirExtension } from "./types";
2
+ export declare const MEDICATION_INSTRUCTION_GRAPH_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-instruction-graph";
3
+ export declare function buildInstructionGraphExtension(graph: CanonicalInstructionGraph | undefined): FhirExtension | undefined;
4
+ export declare function parseInstructionGraphExtension(extensions: FhirExtension[] | undefined): CanonicalInstructionGraph | undefined;
@@ -0,0 +1,21 @@
1
+ import { AdviceFrame, AdviceModality, CanonicalInstructionGraph, CanonicalSigClause, ParseOptions } from "./types";
2
+ export declare function parseInstructionActions(sourceText: string, baseOffset?: number, options?: ParseOptions): AdviceFrame[];
3
+ export declare function refreshInstructionGraphDerivedState(graph: CanonicalInstructionGraph): void;
4
+ export declare function buildInstructionGraph(input: string, clause: CanonicalSigClause, options?: ParseOptions): CanonicalInstructionGraph | undefined;
5
+ export declare function instructionGraphRepresentsText(graph: CanonicalInstructionGraph, text: string): boolean;
6
+ export declare function instructionGraphSingleActionRepresentsText(graph: CanonicalInstructionGraph, text: string): boolean;
7
+ export declare function instructionGraphPrimaryAdministrationModality(clause: CanonicalSigClause): AdviceModality | undefined;
8
+ export declare function instructionGraphHasNovelNonWarningContent(graph: CanonicalInstructionGraph, representedTexts: readonly string[]): boolean;
9
+ export declare function realizeInstructionGraph(graph: CanonicalInstructionGraph, locale?: string, options?: {
10
+ includeWarnings?: boolean;
11
+ onlyWarnings?: boolean;
12
+ omitCanonicalAdministration?: CanonicalSigClause;
13
+ /** Prefer each understood action's exact source wording when source and target locales match. */
14
+ preferSourceText?: boolean;
15
+ /** Source phrases already rendered through another semantic channel. */
16
+ omitSourceTexts?: readonly string[];
17
+ /** Restrict realization around the canonical primary administration source span. */
18
+ position?: "all" | "pre" | "post";
19
+ /** Prefer deliberately unambiguous lexical labels when generating parse-safe text. */
20
+ roundtripSafe?: boolean;
21
+ }): string | undefined;
@@ -0,0 +1,4 @@
1
+ import { ParserState } from "./parser-state";
2
+ import { ParseOptions } from "./types";
3
+ export declare function applyInstructionSemanticResolvers(internal: ParserState, options?: ParseOptions): void;
4
+ export declare function applyInstructionSemanticResolversAsync(internal: ParserState, options?: ParseOptions): Promise<void>;
package/dist/ir.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ParserState } from "./parser-state";
2
2
  import { CanonicalSigClause } from "./types";
3
+ export declare function canonicalClauseHasAdministrationSemantics(clause: CanonicalSigClause): boolean;
3
4
  export declare function buildCanonicalSigClauses(internal: ParserState): CanonicalSigClause[];
4
5
  export declare function shiftCanonicalSigClauses(clauses: CanonicalSigClause[], offset: number): void;
@@ -0,0 +1,8 @@
1
+ import { LexToken } from "./token-types";
2
+ export interface MedicationLocaleLexeme {
3
+ surface: string;
4
+ canonical: string;
5
+ }
6
+ /** Parser-owned locale lexemes for bounded autocomplete/discovery surfaces. */
7
+ export declare function listMedicationLocaleLexemes(locale: string): MedicationLocaleLexeme[];
8
+ export declare function applyLocaleLexicon(tokens: readonly LexToken[], input: string): LexToken[];
@@ -23,6 +23,8 @@ export interface SurfaceToken {
23
23
  export interface LexToken {
24
24
  original: string;
25
25
  lower: string;
26
+ /** Canonical grammar lexeme when locale-aware normalization has one. */
27
+ canonical?: string;
26
28
  index: number;
27
29
  kind: LexKind;
28
30
  value?: number;
@@ -5,6 +5,7 @@ export interface LocalizedTimingGrammar {
5
5
  readonly whenText: Partial<Record<EventTiming, string>>;
6
6
  joinList(parts: string[]): string;
7
7
  summarizeMealTimingGroup(group: MealTimingGroup): string;
8
+ formatEventOffset?(eventText: string, schedule: CanonicalScheduleExpr): string;
8
9
  bedtimeJoinStyle?(dailyCount: number | undefined): BedtimeJoinStyle;
9
10
  }
10
11
  export declare function filterLocalizedWhenEvents(schedule: CanonicalScheduleExpr | undefined): EventTiming[];
package/dist/maps.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BodySiteDefinition, EventTiming, FhirDayOfWeek, FhirPeriodUnit, PrnReasonDefinition, RouteCode, SNOMEDCTRouteCodes } from "./types";
2
+ import { type SymptomDictionaryEntry } from "./symptom-terminology";
2
3
  /**
3
4
  * SNOMED CT codings aligned with every known RouteCode. Keeping the structure
4
5
  * data-driven ensures any additions to the enumeration are surfaced
@@ -70,15 +71,8 @@ export declare const DEFAULT_UNIT_BY_NORMALIZED_FORM: Record<string, string>;
70
71
  export declare const DEFAULT_UNIT_BY_ROUTE: Partial<Record<RouteCode, string>>;
71
72
  export declare function normalizePrnReasonKey(value: string): string;
72
73
  export declare function normalizeAdditionalInstructionKey(value: string): string;
73
- export interface PrnReasonDictionaryEntry {
74
- canonical: string;
75
- definition: PrnReasonDefinition;
76
- terms: string[];
77
- }
74
+ export type PrnReasonDictionaryEntry = SymptomDictionaryEntry;
78
75
  export declare const DEFAULT_PRN_REASON_ENTRIES: PrnReasonDictionaryEntry[];
79
76
  export declare const DEFAULT_PRN_REASON_DEFINITIONS: Record<string, PrnReasonDefinition>;
80
- /**
81
- * Finds a default PRN reason definition by its SNOMED coding.
82
- */
83
77
  export declare function findPrnReasonDefinitionByCoding(system: string, code: string): PrnReasonDefinition | undefined;
84
78
  export {};
@@ -65,6 +65,12 @@ export declare class ParserState {
65
65
  set periodMax(value: number | undefined);
66
66
  get periodUnit(): FhirPeriodUnit | undefined;
67
67
  set periodUnit(value: FhirPeriodUnit | undefined);
68
+ get offset(): number | undefined;
69
+ set offset(value: number | undefined);
70
+ get offsetMin(): number | undefined;
71
+ set offsetMin(value: number | undefined);
72
+ get offsetMax(): number | undefined;
73
+ set offsetMax(value: number | undefined);
68
74
  get dayOfWeek(): FhirDayOfWeek[];
69
75
  get when(): EventTiming[];
70
76
  get timeOfDay(): string[] | undefined;
@@ -81,6 +87,8 @@ export declare class ParserState {
81
87
  set asNeededReasonCoding(value: LocalizedCoding | undefined);
82
88
  get siteText(): string | undefined;
83
89
  set siteText(value: string | undefined);
90
+ get siteI18n(): Record<string, string> | undefined;
91
+ set siteI18n(value: Record<string, string> | undefined);
84
92
  get siteSource(): "abbreviation" | "text" | "selection" | "resolver" | undefined;
85
93
  set siteSource(value: "abbreviation" | "text" | "selection" | "resolver" | undefined);
86
94
  get siteCoding(): LocalizedCoding | undefined;
@@ -0,0 +1,12 @@
1
+ import { SymptomDefinition } from "./types";
2
+ export interface SymptomDictionaryEntry {
3
+ canonical: string;
4
+ definition: SymptomDefinition;
5
+ terms: string[];
6
+ }
7
+ export declare function normalizeSymptomKey(value: string): string;
8
+ export declare const DEFAULT_SYMPTOM_ENTRIES: SymptomDictionaryEntry[];
9
+ export declare const DEFAULT_SYMPTOM_DEFINITIONS: Record<string, SymptomDefinition>;
10
+ export declare function resolveSymptomDefinition(surface: string, ...customMaps: Array<Record<string, SymptomDefinition> | undefined>): SymptomDefinition | undefined;
11
+ export declare function findSymptomDefinitionByCoding(system: string, code: string): SymptomDefinition | undefined;
12
+ export declare function listSymptomDefinitions(): SymptomDefinition[];
@@ -1,7 +1,9 @@
1
1
  import { EventTiming, FhirDayOfWeek, FhirPeriodUnit } from "./types";
2
2
  export interface TimingSummaryOptions {
3
+ realizationMode?: "normalized" | "roundtrip";
3
4
  groupMealTimingsByRelation?: boolean;
4
5
  includeTimesPerDaySummary?: boolean;
6
+ sitePlacement?: "natural" | "trailing";
5
7
  }
6
8
  export type MealRelation = "before" | "after" | "with";
7
9
  export type MealName = "breakfast" | "lunch" | "dinner";
package/dist/types.d.ts CHANGED
@@ -301,9 +301,14 @@ export declare enum FhirDayOfWeek {
301
301
  Saturday = "sat",
302
302
  Sunday = "sun"
303
303
  }
304
- export interface FhirTimingRepeat {
304
+ export interface FhirPeriod {
305
+ start?: string;
306
+ end?: string;
307
+ }
308
+ export interface FhirTimingRepeat extends FhirElement {
305
309
  count?: number;
306
310
  boundsDuration?: FhirQuantity;
311
+ boundsPeriod?: FhirPeriod;
307
312
  boundsRange?: FhirRange;
308
313
  frequency?: number;
309
314
  frequencyMax?: number;
@@ -313,6 +318,7 @@ export interface FhirTimingRepeat {
313
318
  dayOfWeek?: FhirDayOfWeek[];
314
319
  timeOfDay?: string[];
315
320
  when?: EventTiming[];
321
+ /** Exact event offset in minutes. */
316
322
  offset?: number;
317
323
  }
318
324
  export interface FhirTiming {
@@ -378,6 +384,12 @@ export interface MedicationContext {
378
384
  }
379
385
  export interface FormatOptions {
380
386
  locale?: "en" | "th" | string;
387
+ /**
388
+ * `normalized` favors compact natural wording. `roundtrip` stays human-readable
389
+ * but emits explicit attachment/route cues so parse -> realize -> parse can
390
+ * preserve canonical semantics. Defaults to `normalized`.
391
+ */
392
+ realizationMode?: "normalized" | "roundtrip";
381
393
  i18n?: SigTranslationConfig;
382
394
  /**
383
395
  * Collapses repeated meal relation phrases into a grouped phrase when all
@@ -390,6 +402,8 @@ export interface FormatOptions {
390
402
  * schedule (for example, "three times daily" or "วันละ 3 ครั้ง").
391
403
  */
392
404
  includeTimesPerDaySummary?: boolean;
405
+ /** Thai long-text site placement. `natural` uses route-sensitive Thai word order; `trailing` preserves the legacy trailing site phrase. */
406
+ sitePlacement?: "natural" | "trailing";
393
407
  }
394
408
  export interface FormatBatchOptions extends FormatOptions {
395
409
  /**
@@ -433,9 +447,16 @@ export interface CodeableConceptDefinition {
433
447
  /** Optional translations for different locales (e.g., { "th": "ปวด" }) */
434
448
  i18n?: Record<string, string>;
435
449
  }
436
- export interface PrnReasonDefinition extends CodeableConceptDefinition {
450
+ export interface SymptomDefinition extends CodeableConceptDefinition {
451
+ /** Locale-specific surface proposition used after a conditional such as Thai `เมื่อ`. */
452
+ conditionI18n?: Record<string, string>;
453
+ }
454
+ /** Backward-compatible PRN view of the shared symptom terminology. */
455
+ export interface PrnReasonDefinition extends SymptomDefinition {
437
456
  }
438
457
  export interface AdditionalInstructionDefinition extends CodeableConceptDefinition {
458
+ /** Locale-specific suffix appended directly to the administration verb. */
459
+ verbSuffixI18n?: Record<string, string>;
439
460
  }
440
461
  export declare enum AdvicePolarity {
441
462
  Affirm = "affirm",
@@ -465,7 +486,13 @@ export declare enum AdviceRelation {
465
486
  Until = "until",
466
487
  For = "for",
467
488
  In = "in",
468
- On = "on"
489
+ Into = "into",
490
+ On = "on",
491
+ To = "to",
492
+ If = "if",
493
+ Unless = "unless",
494
+ When = "when",
495
+ While = "while"
469
496
  }
470
497
  export declare enum AdviceArgumentRole {
471
498
  Theme = "theme",
@@ -475,6 +502,10 @@ export declare enum AdviceArgumentRole {
475
502
  Activity = "activity",
476
503
  Material = "material",
477
504
  Site = "site",
505
+ Destination = "destination",
506
+ Result = "result",
507
+ Container = "container",
508
+ Manner = "manner",
478
509
  Amount = "amount",
479
510
  Duration = "duration",
480
511
  Time = "time",
@@ -485,6 +516,14 @@ export interface AdviceArgument {
485
516
  text: string;
486
517
  normalized?: string;
487
518
  conceptId?: string;
519
+ coding?: FhirCoding;
520
+ codings?: FhirCoding[];
521
+ i18n?: Record<string, string>;
522
+ quantity?: {
523
+ value?: number;
524
+ range?: CanonicalDoseRange;
525
+ unit?: string;
526
+ };
488
527
  span?: TextRange;
489
528
  }
490
529
  export interface AdviceFrame {
@@ -494,12 +533,24 @@ export interface AdviceFrame {
494
533
  predicate: {
495
534
  lemma: string;
496
535
  semanticClass?: string;
536
+ display?: string;
537
+ i18n?: Record<string, string>;
538
+ /** Persisted realization profile so caller-owned actions remain deterministic after parse/FHIR round-trip. */
539
+ realizer?: MedicationInstructionActionRealizer;
540
+ realizerConfig?: {
541
+ thaiFallbackObject?: string;
542
+ thaiSuppressActivityConcepts?: string[];
543
+ };
544
+ /** Internal/custom action coding followed by any trustworthy external mappings. */
545
+ codings?: FhirCoding[];
497
546
  };
498
547
  relation?: AdviceRelation;
499
548
  args: AdviceArgument[];
500
549
  span: TextRange;
501
550
  sourceText: string;
502
551
  sequenceIndex?: number;
552
+ origin?: "grammar" | "semantic-resolver";
553
+ confidence?: number;
503
554
  coding?: FhirCoding;
504
555
  }
505
556
  export interface TextRange {
@@ -635,6 +686,140 @@ export interface SmartMealExpansionScope {
635
686
  */
636
687
  excludeDosageForms?: string[];
637
688
  }
689
+ export type MedicationInstructionActionArgumentParser = "default" | "container-activity" | "theme-destination-amount" | "object-amount-material" | "amount-duration" | "object-duration" | "object-time" | "mix-substance" | "result" | "site" | "site-relation" | "duration" | "bare-duration" | "activity";
690
+ export type MedicationInstructionActionRealizer = "default" | "source-faithful" | "container-activity" | "theme-destination-amount" | "mix-substance" | "result" | "site-relation" | "object-amount-material" | "prime" | "amount-duration" | "object-duration" | "object-time" | "separable-object-relation" | "relation-duration" | "leave-duration" | "duration" | "activity";
691
+ export interface MedicationInstructionActionContextualCodingRule {
692
+ whenArgument: {
693
+ role?: AdviceArgumentRole;
694
+ conceptId?: string;
695
+ codingCode?: string;
696
+ normalized?: string;
697
+ };
698
+ coding: FhirCoding;
699
+ }
700
+ export interface MedicationInstructionActionDefinition {
701
+ /** Stable semantic action code. */
702
+ code: string;
703
+ semanticClass: string;
704
+ display: string;
705
+ /** Alternate human-readable labels keyed by BCP-47-ish language tag. */
706
+ i18n?: Record<string, string>;
707
+ /** Unambiguous parser-safe labels used only for semantic round-trip realization. */
708
+ roundtripI18n?: Record<string, string>;
709
+ /** Surface forms that should resolve to this action. */
710
+ aliases?: string[];
711
+ /** Discontinuous surface forms such as Thai `เอา X ออก` (remove X). */
712
+ separableAliases?: Array<{
713
+ lead: string;
714
+ particle: string;
715
+ }>;
716
+ /** Whether this is a procedural action rather than ordinary administration advice. */
717
+ procedural?: boolean;
718
+ /** Declarative argument grammar family used by the instruction graph. */
719
+ argumentParser?: MedicationInstructionActionArgumentParser;
720
+ /** Declarative realization family used by English/Thai graph generation. */
721
+ realizer?: MedicationInstructionActionRealizer;
722
+ argumentParserConfig?: {
723
+ primaryConcepts?: string[];
724
+ secondaryConcepts?: string[];
725
+ implicitMatchedConcept?: string;
726
+ implicitMatchedRole?: AdviceArgumentRole;
727
+ };
728
+ realizerConfig?: {
729
+ thaiFallbackObject?: string;
730
+ thaiSuppressActivityConcepts?: string[];
731
+ /** Thai can omit an otherwise generic medication object for this action (e.g. รับประทานหลังอาหาร). */
732
+ thaiImplicitMedicationObject?: boolean;
733
+ /** English realizes the anatomical site as the verb's direct object instead of `to/at <site>`. */
734
+ englishDirectSiteObject?: boolean;
735
+ };
736
+ continuationLicenses?: Array<{
737
+ candidateAction: string;
738
+ previousConcepts?: string[];
739
+ previousKinds?: Array<"NUMBER" | "NUMBER_RANGE">;
740
+ nextConcepts?: string[];
741
+ }>;
742
+ continuationAfterRelations?: string[];
743
+ /** Exact coding for FHIR Dosage.method when this action can head administration. */
744
+ administrationMethod?: FhirCoding;
745
+ /** Route candidate licensed by the action surface itself (e.g. take -> oral). */
746
+ verbRouteHint?: RouteCode;
747
+ /** Exact route that overrides the ordinary verb route candidate for the method head. */
748
+ methodRouteOverride?: RouteCode;
749
+ /** Do not project the action's verb route hint from the method head. */
750
+ suppressMethodRouteHint?: boolean;
751
+ /** Marks surfaces that establish topical/application context for site grammar. */
752
+ applicationVerb?: boolean;
753
+ /** Extra exact codings licensed by a typed semantic argument. */
754
+ contextualCodings?: MedicationInstructionActionContextualCodingRule[];
755
+ /** A method-capable procedural action that may serve as the primary administration head. */
756
+ primaryAdministrationHead?: boolean;
757
+ /** Semantically light verb that yields to an immediately following stronger administration head. */
758
+ supportVerb?: boolean;
759
+ /** Positive action whose condition belongs to safety/instruction scope, not PRN administration scope. */
760
+ safetyScopeTarget?: boolean;
761
+ acceptsAmount?: boolean;
762
+ /** Whether an amount argument on this action defines the medication dose. */
763
+ definesDose?: boolean;
764
+ /** Optional primary coding when an institution owns the action terminology. */
765
+ coding?: FhirCoding;
766
+ /** Exact external terminology mappings; never fuzzy/approximate mappings. */
767
+ externalCodings?: FhirCoding[];
768
+ }
769
+ export interface MedicationInstructionActionInput extends Partial<MedicationInstructionActionDefinition> {
770
+ semanticClass?: string;
771
+ }
772
+ export interface MedicationInstructionConceptDefinition {
773
+ code: string;
774
+ role: AdviceArgumentRole;
775
+ display: string;
776
+ i18n?: Record<string, string>;
777
+ aliases?: string[];
778
+ coding?: FhirCoding;
779
+ externalCodings?: FhirCoding[];
780
+ }
781
+ export interface MedicationInstructionConceptInput extends Partial<MedicationInstructionConceptDefinition> {
782
+ role?: AdviceArgumentRole;
783
+ }
784
+ export interface InstructionSemanticArgumentProposal {
785
+ /** Typed argument role the resolver believes this phrase fills. */
786
+ role: AdviceArgumentRole;
787
+ /** Range relative to the opaque source span supplied in the resolver request. */
788
+ range: TextRange;
789
+ /** Registered instruction concept or body-site surface/code. */
790
+ concept?: string;
791
+ /** Explicit quantity, still validated against the parser's unit terminology. */
792
+ quantity?: {
793
+ value?: number;
794
+ low?: number;
795
+ high?: number;
796
+ unit?: string;
797
+ };
798
+ }
799
+ export interface InstructionSemanticActionProposal {
800
+ /** Registered instruction action surface/code. */
801
+ action: string;
802
+ /** Range relative to the opaque source span supplied in the resolver request. */
803
+ range: TextRange;
804
+ polarity?: AdvicePolarity;
805
+ /** Resolver confidence only; it never bypasses deterministic validation. */
806
+ confidence?: number;
807
+ args?: InstructionSemanticArgumentProposal[];
808
+ }
809
+ export interface InstructionSemanticResolution {
810
+ actions: InstructionSemanticActionProposal[];
811
+ }
812
+ export interface InstructionSemanticResolverRequest {
813
+ inputText: string;
814
+ sourceText: string;
815
+ /** Absolute range of sourceText within inputText. */
816
+ range: TextRange;
817
+ locale?: string;
818
+ context?: MedicationContext | null;
819
+ /** Read-only semantic context produced before learned enrichment. */
820
+ existingGraph: CanonicalInstructionGraph;
821
+ }
822
+ export type InstructionSemanticResolver = (request: InstructionSemanticResolverRequest) => InstructionSemanticResolution | null | undefined | Promise<InstructionSemanticResolution | null | undefined>;
638
823
  export interface ParseOptions extends FormatOptions {
639
824
  /**
640
825
  * Optional medication context that assists with default unit inference.
@@ -643,6 +828,24 @@ export interface ParseOptions extends FormatOptions {
643
828
  context?: MedicationContext | null;
644
829
  routeMap?: Record<string, RouteCode>;
645
830
  unitMap?: Record<string, string>;
831
+ /**
832
+ * Institution/application procedural vocabulary. Map keys are accepted
833
+ * surface forms; definitions may use any coding system and may add aliases.
834
+ * Unknown text still remains opaque rather than being guessed.
835
+ */
836
+ instructionActionMap?: Record<string, MedicationInstructionActionInput>;
837
+ /**
838
+ * Institution/application argument vocabulary for substances, containers,
839
+ * results, activities, etc. Body sites still use the richer siteCodeMap.
840
+ */
841
+ instructionConceptMap?: Record<string, MedicationInstructionConceptInput>;
842
+ /**
843
+ * Optional learned/remote semantic proposal providers. They are used only by
844
+ * parseSigAsync(), and only against spans the deterministic parser left opaque.
845
+ * Proposals are validated against registered action/concept/site/unit vocabularies
846
+ * before they can enter the canonical graph.
847
+ */
848
+ instructionSemanticResolvers?: InstructionSemanticResolver | InstructionSemanticResolver[];
646
849
  freqMap?: Record<string, {
647
850
  timesPerDay?: number;
648
851
  intervalHours?: number;
@@ -724,7 +927,13 @@ export interface ParseOptions extends FormatOptions {
724
927
  */
725
928
  siteCodeSuggestionResolvers?: SiteCodeSuggestionResolver | SiteCodeSuggestionResolver[];
726
929
  /**
727
- * Optional dictionary for translating PRN reason phrases into coded concepts.
930
+ * Optional application/institution symptom vocabulary shared by conditions,
931
+ * PRN indications, HPSG symptom recognition, and suggestion surfaces.
932
+ */
933
+ symptomMap?: Record<string, SymptomDefinition>;
934
+ /**
935
+ * Backward-compatible PRN-specific symptom overrides. When both maps define
936
+ * the same surface, this narrower PRN map takes precedence.
728
937
  */
729
938
  prnReasonMap?: Record<string, PrnReasonDefinition>;
730
939
  /**
@@ -784,6 +993,12 @@ export interface CanonicalScheduleExpr {
784
993
  period?: number;
785
994
  periodMax?: number;
786
995
  periodUnit?: FhirPeriodUnit;
996
+ /** Exact event offset in minutes, matching FHIR Timing.repeat.offset. */
997
+ offset?: number;
998
+ /** Minimum event offset in minutes when the source says “at least”. */
999
+ offsetMin?: number;
1000
+ /** Maximum event offset in minutes when the source says “at most”. */
1001
+ offsetMax?: number;
787
1002
  dayOfWeek?: FhirDayOfWeek[];
788
1003
  when?: EventTiming[];
789
1004
  timeOfDay?: string[];
@@ -807,6 +1022,34 @@ export interface CanonicalAdditionalInstructionExpr {
807
1022
  frames?: AdviceFrame[];
808
1023
  evidence?: CanonicalEvidence[];
809
1024
  }
1025
+ export interface CanonicalInstructionRelation {
1026
+ kind: AdviceRelation;
1027
+ fromActionIndex?: number;
1028
+ toActionIndex: number;
1029
+ text?: string;
1030
+ span?: TextRange;
1031
+ }
1032
+ export interface CanonicalInstructionCoverage {
1033
+ understoodCharacters: number;
1034
+ opaqueCharacters: number;
1035
+ ratio: number;
1036
+ complete: boolean;
1037
+ }
1038
+ export interface CanonicalInstructionGraph {
1039
+ /** Ordered, language-neutral procedural/administration actions. */
1040
+ actions: AdviceFrame[];
1041
+ /** Explicit temporal/conditional relationships between actions or source clauses. */
1042
+ relations?: CanonicalInstructionRelation[];
1043
+ /** Source span of the canonical primary administration head, when known. */
1044
+ primaryAdministrationSpan?: TextRange;
1045
+ /** Source fragments the parser deliberately did not assign semantics to. */
1046
+ opaqueSpans?: CanonicalSourceSpan[];
1047
+ coverage?: CanonicalInstructionCoverage;
1048
+ /** Exact original source represented by this graph. */
1049
+ sourceText: string;
1050
+ /** Source language when it can be determined without guessing. */
1051
+ sourceLocale?: string;
1052
+ }
810
1053
  export interface CanonicalSourceSpan extends TextRange {
811
1054
  text: string;
812
1055
  tokenIndices?: number[];
@@ -829,6 +1072,7 @@ export interface CanonicalSigClause {
829
1072
  schedule?: CanonicalScheduleExpr;
830
1073
  prn?: CanonicalPrnExpr;
831
1074
  patientInstruction?: string;
1075
+ instructionGraph?: CanonicalInstructionGraph;
832
1076
  additionalInstructions?: CanonicalAdditionalInstructionExpr[];
833
1077
  leftovers: CanonicalSourceSpan[];
834
1078
  evidence: CanonicalEvidence[];
@@ -868,6 +1112,7 @@ export interface ParseNormalizedMeta {
868
1112
  coding?: FhirCoding;
869
1113
  };
870
1114
  patientInstruction?: string;
1115
+ instructionGraph?: CanonicalInstructionGraph;
871
1116
  prnReason?: ConceptSiteDetail;
872
1117
  prnReasons?: ConceptSiteDetail[];
873
1118
  additionalInstructions?: Array<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ezmedicationinput",
3
- "version": "0.1.53",
3
+ "version": "0.1.55",
4
4
  "description": "Parse concise medication sigs into FHIR R5 Dosage JSON",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -17,7 +17,11 @@
17
17
  "scripts": {
18
18
  "test:dist": "npm run build && vitest run test-dist",
19
19
  "build": "tsup && tsc -p tsconfig.types.json",
20
- "test": "vitest run --dir test"
20
+ "test": "vitest run --dir test",
21
+ "bench:torture": "npm run build && node bench/real-world-torture.mjs",
22
+ "bench:adversarial": "npm run build && node bench/adversarial.mjs",
23
+ "bench:roundtrip": "npm run build && node bench/roundtrip.mjs",
24
+ "bench:suggest": "npm run build && node --expose-gc bench/suggest.mjs"
21
25
  },
22
26
  "files": [
23
27
  "dist"