ezmedicationinput 0.1.54 → 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.
- package/README.md +111 -25
- package/dist/body-site-grammar.d.ts +1 -0
- package/dist/event-timing-expression.d.ts +8 -0
- package/dist/fhir.d.ts +6 -1
- package/dist/hpsg/constructions.d.ts +6 -0
- package/dist/hpsg/defaults.d.ts +1 -0
- package/dist/hpsg/feature-structure.d.ts +5 -0
- package/dist/hpsg/lexical-classes.d.ts +41 -1
- package/dist/hpsg/method-lexicon.d.ts +14 -14
- package/dist/hpsg/procedural-context.d.ts +10 -0
- package/dist/hpsg/rules/condition-rules.d.ts +4 -0
- package/dist/hpsg/rules/core-rules.d.ts +1 -0
- package/dist/hpsg/rules/instruction-rules.d.ts +1 -0
- package/dist/hpsg/rules/prn-rules.d.ts +8 -0
- package/dist/hpsg/rules/timing-rules.d.ts +19 -0
- package/dist/hpsg/segmenter.d.ts +2 -1
- package/dist/hpsg/signature.d.ts +49 -2
- package/dist/hpsg/type-system.d.ts +48 -0
- package/dist/i18n.d.ts +2 -0
- package/dist/index.cjs +21887 -9720
- package/dist/index.d.ts +9 -0
- package/dist/index.js +21861 -9717
- package/dist/instruction-action-terminology.d.ts +29 -0
- package/dist/instruction-concept-terminology.d.ts +26 -0
- package/dist/instruction-graph-fhir.d.ts +4 -0
- package/dist/instruction-graph.d.ts +21 -0
- package/dist/instruction-semantic-resolver.d.ts +4 -0
- package/dist/ir.d.ts +1 -0
- package/dist/lexer/locale.d.ts +8 -0
- package/dist/lexer/token-types.d.ts +2 -0
- package/dist/localized-timing.d.ts +1 -0
- package/dist/maps.d.ts +2 -8
- package/dist/parser-state.d.ts +8 -0
- package/dist/symptom-terminology.d.ts +12 -0
- package/dist/timing-summary.d.ts +2 -0
- package/dist/types.d.ts +244 -4
- 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[];
|
|
@@ -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
|
|
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 {};
|
package/dist/parser-state.d.ts
CHANGED
|
@@ -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[];
|
package/dist/timing-summary.d.ts
CHANGED
|
@@ -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
|
@@ -305,7 +305,7 @@ export interface FhirPeriod {
|
|
|
305
305
|
start?: string;
|
|
306
306
|
end?: string;
|
|
307
307
|
}
|
|
308
|
-
export interface FhirTimingRepeat {
|
|
308
|
+
export interface FhirTimingRepeat extends FhirElement {
|
|
309
309
|
count?: number;
|
|
310
310
|
boundsDuration?: FhirQuantity;
|
|
311
311
|
boundsPeriod?: FhirPeriod;
|
|
@@ -318,6 +318,7 @@ export interface FhirTimingRepeat {
|
|
|
318
318
|
dayOfWeek?: FhirDayOfWeek[];
|
|
319
319
|
timeOfDay?: string[];
|
|
320
320
|
when?: EventTiming[];
|
|
321
|
+
/** Exact event offset in minutes. */
|
|
321
322
|
offset?: number;
|
|
322
323
|
}
|
|
323
324
|
export interface FhirTiming {
|
|
@@ -383,6 +384,12 @@ export interface MedicationContext {
|
|
|
383
384
|
}
|
|
384
385
|
export interface FormatOptions {
|
|
385
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";
|
|
386
393
|
i18n?: SigTranslationConfig;
|
|
387
394
|
/**
|
|
388
395
|
* Collapses repeated meal relation phrases into a grouped phrase when all
|
|
@@ -395,6 +402,8 @@ export interface FormatOptions {
|
|
|
395
402
|
* schedule (for example, "three times daily" or "วันละ 3 ครั้ง").
|
|
396
403
|
*/
|
|
397
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";
|
|
398
407
|
}
|
|
399
408
|
export interface FormatBatchOptions extends FormatOptions {
|
|
400
409
|
/**
|
|
@@ -438,9 +447,16 @@ export interface CodeableConceptDefinition {
|
|
|
438
447
|
/** Optional translations for different locales (e.g., { "th": "ปวด" }) */
|
|
439
448
|
i18n?: Record<string, string>;
|
|
440
449
|
}
|
|
441
|
-
export interface
|
|
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 {
|
|
442
456
|
}
|
|
443
457
|
export interface AdditionalInstructionDefinition extends CodeableConceptDefinition {
|
|
458
|
+
/** Locale-specific suffix appended directly to the administration verb. */
|
|
459
|
+
verbSuffixI18n?: Record<string, string>;
|
|
444
460
|
}
|
|
445
461
|
export declare enum AdvicePolarity {
|
|
446
462
|
Affirm = "affirm",
|
|
@@ -470,7 +486,13 @@ export declare enum AdviceRelation {
|
|
|
470
486
|
Until = "until",
|
|
471
487
|
For = "for",
|
|
472
488
|
In = "in",
|
|
473
|
-
|
|
489
|
+
Into = "into",
|
|
490
|
+
On = "on",
|
|
491
|
+
To = "to",
|
|
492
|
+
If = "if",
|
|
493
|
+
Unless = "unless",
|
|
494
|
+
When = "when",
|
|
495
|
+
While = "while"
|
|
474
496
|
}
|
|
475
497
|
export declare enum AdviceArgumentRole {
|
|
476
498
|
Theme = "theme",
|
|
@@ -480,6 +502,10 @@ export declare enum AdviceArgumentRole {
|
|
|
480
502
|
Activity = "activity",
|
|
481
503
|
Material = "material",
|
|
482
504
|
Site = "site",
|
|
505
|
+
Destination = "destination",
|
|
506
|
+
Result = "result",
|
|
507
|
+
Container = "container",
|
|
508
|
+
Manner = "manner",
|
|
483
509
|
Amount = "amount",
|
|
484
510
|
Duration = "duration",
|
|
485
511
|
Time = "time",
|
|
@@ -490,6 +516,14 @@ export interface AdviceArgument {
|
|
|
490
516
|
text: string;
|
|
491
517
|
normalized?: string;
|
|
492
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
|
+
};
|
|
493
527
|
span?: TextRange;
|
|
494
528
|
}
|
|
495
529
|
export interface AdviceFrame {
|
|
@@ -499,12 +533,24 @@ export interface AdviceFrame {
|
|
|
499
533
|
predicate: {
|
|
500
534
|
lemma: string;
|
|
501
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[];
|
|
502
546
|
};
|
|
503
547
|
relation?: AdviceRelation;
|
|
504
548
|
args: AdviceArgument[];
|
|
505
549
|
span: TextRange;
|
|
506
550
|
sourceText: string;
|
|
507
551
|
sequenceIndex?: number;
|
|
552
|
+
origin?: "grammar" | "semantic-resolver";
|
|
553
|
+
confidence?: number;
|
|
508
554
|
coding?: FhirCoding;
|
|
509
555
|
}
|
|
510
556
|
export interface TextRange {
|
|
@@ -640,6 +686,140 @@ export interface SmartMealExpansionScope {
|
|
|
640
686
|
*/
|
|
641
687
|
excludeDosageForms?: string[];
|
|
642
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>;
|
|
643
823
|
export interface ParseOptions extends FormatOptions {
|
|
644
824
|
/**
|
|
645
825
|
* Optional medication context that assists with default unit inference.
|
|
@@ -648,6 +828,24 @@ export interface ParseOptions extends FormatOptions {
|
|
|
648
828
|
context?: MedicationContext | null;
|
|
649
829
|
routeMap?: Record<string, RouteCode>;
|
|
650
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[];
|
|
651
849
|
freqMap?: Record<string, {
|
|
652
850
|
timesPerDay?: number;
|
|
653
851
|
intervalHours?: number;
|
|
@@ -729,7 +927,13 @@ export interface ParseOptions extends FormatOptions {
|
|
|
729
927
|
*/
|
|
730
928
|
siteCodeSuggestionResolvers?: SiteCodeSuggestionResolver | SiteCodeSuggestionResolver[];
|
|
731
929
|
/**
|
|
732
|
-
* Optional
|
|
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.
|
|
733
937
|
*/
|
|
734
938
|
prnReasonMap?: Record<string, PrnReasonDefinition>;
|
|
735
939
|
/**
|
|
@@ -789,6 +993,12 @@ export interface CanonicalScheduleExpr {
|
|
|
789
993
|
period?: number;
|
|
790
994
|
periodMax?: number;
|
|
791
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;
|
|
792
1002
|
dayOfWeek?: FhirDayOfWeek[];
|
|
793
1003
|
when?: EventTiming[];
|
|
794
1004
|
timeOfDay?: string[];
|
|
@@ -812,6 +1022,34 @@ export interface CanonicalAdditionalInstructionExpr {
|
|
|
812
1022
|
frames?: AdviceFrame[];
|
|
813
1023
|
evidence?: CanonicalEvidence[];
|
|
814
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
|
+
}
|
|
815
1053
|
export interface CanonicalSourceSpan extends TextRange {
|
|
816
1054
|
text: string;
|
|
817
1055
|
tokenIndices?: number[];
|
|
@@ -834,6 +1072,7 @@ export interface CanonicalSigClause {
|
|
|
834
1072
|
schedule?: CanonicalScheduleExpr;
|
|
835
1073
|
prn?: CanonicalPrnExpr;
|
|
836
1074
|
patientInstruction?: string;
|
|
1075
|
+
instructionGraph?: CanonicalInstructionGraph;
|
|
837
1076
|
additionalInstructions?: CanonicalAdditionalInstructionExpr[];
|
|
838
1077
|
leftovers: CanonicalSourceSpan[];
|
|
839
1078
|
evidence: CanonicalEvidence[];
|
|
@@ -873,6 +1112,7 @@ export interface ParseNormalizedMeta {
|
|
|
873
1112
|
coding?: FhirCoding;
|
|
874
1113
|
};
|
|
875
1114
|
patientInstruction?: string;
|
|
1115
|
+
instructionGraph?: CanonicalInstructionGraph;
|
|
876
1116
|
prnReason?: ConceptSiteDetail;
|
|
877
1117
|
prnReasons?: ConceptSiteDetail[];
|
|
878
1118
|
additionalInstructions?: Array<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ezmedicationinput",
|
|
3
|
-
"version": "0.1.
|
|
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"
|