ezmedicationinput 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,10 +59,15 @@ export interface InstructionActionLocaleAdapter {
59
59
  persists: boolean;
60
60
  };
61
61
  renderConditionBody(base: string, conditionForm: string | undefined, persists: boolean): string;
62
+ parseConditionWorsening?(body: string): string | undefined;
63
+ renderConditionWorsening?(body: string): string;
64
+ renderCountedAdviceSituation?(condition: AdviceArgument): string | undefined;
65
+ joinConditionOperands?(operator: "all" | "any" | "not", operands: string[]): string;
62
66
  joinConditionLead(lead: string, body: string): string;
63
67
  conditionalContinuation(text: string, imperative: boolean, precedingText?: string): string;
64
68
  postposedCondition(text: string, precedingText?: string): string;
65
- sequenceSeparator(): string;
69
+ sequenceSeparator(sharedGuard?: boolean): string;
70
+ coordinatedAdviceSeparator?(moreSiblings?: boolean): string;
66
71
  continuationText(text: string, understood: boolean): string;
67
72
  withAuthoredDirections?(current: string, source: string): string;
68
73
  /** Return undefined to retain an explicit relation for an unrecognized Time. */
@@ -109,7 +114,7 @@ export declare function realizeTimeArgument(c: SelectedTimeInput): string | unde
109
114
  /** A Duration keeps its own governor in every registered action valence.
110
115
  * A supplied elapsed prefix retains the valence's existing For wording;
111
116
  * other explicit governors always use their registered duration wording. */
112
- export declare function realizeDurationArgument(input: Pick<InstructionActionRealizationInput, "frame" | "locale" | "duration">, elapsedPrefix?: string): string | undefined;
117
+ export declare function realizeDurationArgument(input: Pick<InstructionActionRealizationInput, "frame" | "locale" | "duration" | "realizerConfig">, elapsedPrefix?: string): string | undefined;
113
118
  export declare function quantityOnlyInstructionArgument(arg: AdviceArgument | undefined): boolean;
114
119
  /** A typed measured nominal without its own noun label retains the opaque
115
120
  * argument separately; its source text cannot override the current quantity. */
@@ -17,6 +17,9 @@ export declare function isInstructionConditionActivity(parts: Lexeme[], index: n
17
17
  export declare function actionMatchAt(parts: Lexeme[], index: number, options?: ParseOptions, includeGovernedProcedure?: boolean, directivePrefixEnd?: number, productComplement?: boolean): ActionMatch | undefined;
18
18
  export declare function codingFromSite(text: string, options?: ParseOptions): AdviceArgument | undefined;
19
19
  export declare function trimSemanticText(value: string): string;
20
+ /** A temporal governor can select a complete registered Activity nominal
21
+ * without introducing an executable clock or an opaque connector Time. */
22
+ export declare function knownTemporalActivity(parts: Lexeme[], start: number, end: number, input: string, options?: ParseOptions, measuredOnly?: boolean): AdviceArgument | undefined;
20
23
  export declare function parseQuantityArgument(parts: Lexeme[], start: number, endExclusive: number, input: string, offset: number, options?: ParseOptions, numberEndExclusive?: number): AdviceArgument | undefined;
21
24
  type MeasuredTemporalReference = TextRange & {
22
25
  timing?: TextRange;
@@ -28,6 +31,8 @@ type InterleavedCadence = TextRange & {
28
31
  /** A bounded predicate can describe inability to perform a registered
29
32
  * administration. Reuse the same modal/action valence as directive selection. */
30
33
  export declare function isNegativeAdministrationAbility(parts: Lexeme[], options?: ParseOptions): boolean;
34
+ /** An overt, licensed directive prefix can close a fronted advice condition. */
35
+ export declare function actionFrameHasExplicitDirective(parts: Lexeme[], frame: AdviceFrame, options?: ParseOptions): boolean;
31
36
  /** Preserve the lexical daughter while the conditional owner selects whether
32
37
  * its modal predicate belongs to an antecedent or an independent directive. */
33
38
  export declare function actionFrameHasEmbeddedModal(parts: Lexeme[], frame: AdviceFrame, options?: ParseOptions): boolean;
@@ -30,6 +30,7 @@ export declare function cloneMedicationInstructionConceptComponents(components:
30
30
  * lexical resolution must not recursively clone the same vocabulary tree.
31
31
  * Explicit frame construction still copies only the fields it later edits. */
32
32
  export declare function resolveMedicationInstructionConcept(surface: string, options?: ParseOptions): MedicationInstructionConceptDefinition | undefined;
33
+ export declare function argumentFromConceptDefinition(definition: MedicationInstructionConceptDefinition, sourceText: string): AdviceArgument;
33
34
  export declare function getMedicationInstructionConcept(code: string, system?: string): MedicationInstructionConceptDefinition | undefined;
34
35
  export declare function listMedicationInstructionConcepts(): MedicationInstructionConceptDefinition[];
35
36
  /** The public CodeSystem is freshly returned, but its published concepts
@@ -54,8 +54,11 @@ export interface CourseLanguage {
54
54
  ifLimitExceeded(action: string): string;
55
55
  eventWindow(start: string, end: string): string;
56
56
  unresolvedCycleTiming(days: string, periodDays?: number, cycles?: number, anchor?: string): string;
57
+ namedCycleTiming?(cycle: string, days: string, startDay?: number, maxTreatmentDays?: number): string;
58
+ cycleDayOneDefinition?(event: string): string;
57
59
  weekdayName(day: string): string;
58
60
  measurementName(name: string): string;
61
+ conditionFindingName?(fallback: string, translations?: Readonly<Record<string, string>>, label?: string): string;
59
62
  joinList(items: readonly string[]): string;
60
63
  timeUnit(unit: string, value: number | undefined): string | undefined;
61
64
  expression(kind: "dose" | "rate", detail: string | undefined): string;
@@ -2,7 +2,16 @@ import { MedicationCondition, type FhirDayOfWeek } from "./types";
2
2
  import type { HpsgGuardFeature } from "./hpsg/signature";
3
3
  export { parseMedicationGuard } from "./hpsg/constructions";
4
4
  export type { ParsedMedicationGuard } from "./hpsg/constructions";
5
+ export interface CountedAdviceSituation {
6
+ end: number;
7
+ conceptId: string;
8
+ count: number;
9
+ unit: "tab" | "dose";
10
+ comparator?: ">=";
11
+ consecutive?: true;
12
+ }
5
13
  export interface MedicationConditionLexicalFeatures {
14
+ countedAdviceSituation?(source: string): CountedAdviceSituation | undefined;
6
15
  operators: ReadonlyArray<{
7
16
  operation: "ge" | "le" | "gt" | "lt";
8
17
  pattern: RegExp;
@@ -31,10 +40,25 @@ export interface MedicationConditionLexicalFeatures {
31
40
  sourceCue: RegExp;
32
41
  calendar: {
33
42
  cycle: {
43
+ /** Whole-source admission for day, named-cycle and maximum constituents. */
34
44
  cue: RegExp;
35
45
  frame: string;
36
46
  startLead: RegExp;
37
47
  repeatCount: RegExp;
48
+ dayPart?: string;
49
+ identifyNamedCycle?(surface: string): {
50
+ conceptId: string;
51
+ startsOnDay?: boolean;
52
+ } | undefined;
53
+ treatmentMaximum?: {
54
+ cue: RegExp;
55
+ frame: string;
56
+ };
57
+ dayOneDefinitions?: readonly {
58
+ frame: string;
59
+ cycleConceptId: string;
60
+ eventConceptId: string;
61
+ }[];
38
62
  };
39
63
  cue: RegExp;
40
64
  /** Registration-derived views for whole-source search and token-origin admission. */
@@ -53,6 +77,7 @@ export interface MedicationConditionLexicalFeatures {
53
77
  dayHeads: ReadonlySet<string>;
54
78
  };
55
79
  guardLead: RegExp;
80
+ intervalEligibilityLead?: RegExp;
56
81
  numericGuard: RegExp;
57
82
  contextDayGuard: RegExp;
58
83
  contextDayNominal: RegExp;
@@ -74,10 +99,18 @@ export interface MedicationGuardLeadLexeme {
74
99
  end: number;
75
100
  marker: "if" | "only-if" | "unless";
76
101
  circumstantial?: true;
102
+ intervalEligibility?: true;
77
103
  }
78
104
  /** Recognize a conditional marker's spelling, leaving its predicate licensing
79
105
  * and scope to the HPSG guard-head construction. */
80
106
  export declare function medicationGuardLeadLexeme(source: string, licensedConsequent?: boolean, lexicon?: MedicationConditionLexicalFeatures): MedicationGuardLeadLexeme | undefined;
107
+ /** The cycle schedule and adjacent guards use the same provider-owned cap span. */
108
+ export declare function namedCycleTreatmentMaxima(source: string, cycle: MedicationConditionLexicalFeatures["calendar"]["cycle"], start?: number, end?: number): IterableIterator<{
109
+ start: number;
110
+ end: number;
111
+ days: number;
112
+ conceptId: string;
113
+ }>;
81
114
  /** Lexical boundary spellings shared with the typed guard phrase. No result
82
115
  * from these recognizers is itself a medication condition or administration. */
83
116
  /** Recognize one predicate atom. Incomplete comparisons remain unsatisfied
package/dist/prn.d.ts CHANGED
@@ -3,6 +3,8 @@ import { type ResolvedBodySitePhrase } from "./body-site-grammar";
3
3
  export declare function getCanonicalPrnReasonText(reason: CanonicalPrnReasonExpr | undefined): string | undefined;
4
4
  export declare function joinCanonicalPrnReasonTexts(reasons: CanonicalPrnReasonExpr[] | undefined, conjunction?: string): string | undefined;
5
5
  export declare function getPreferredCanonicalPrnReasonText(reason: CanonicalPrnReasonExpr | undefined, reasons: CanonicalPrnReasonExpr[] | undefined, conjunction?: string): string | undefined;
6
+ /** Match the complete registered symptom, allowing only its existing predicative state lead. */
7
+ export declare function resolveWholePrnSymptom(text: string | undefined): SymptomDefinition | undefined;
6
8
  export declare function getPrnReasonTextFallbackI18n(reason: CanonicalPrnReasonExpr): Record<string, string> | undefined;
7
9
  export declare function getLocalizedCanonicalPrnReasonText(reason: CanonicalPrnReasonExpr | undefined, reasons: CanonicalPrnReasonExpr[] | undefined, locale: string, conjunction?: string, realizeReason?: (reason: CanonicalPrnReasonExpr, localizedText: string | undefined) => string | undefined): string | undefined;
8
10
  export interface LocatedPrnWording {
@@ -6,9 +6,12 @@
6
6
  * implemented in execution/engine, which has no import/export dependency.
7
7
  * Canonical callers bypass interchange completely.
8
8
  */
9
- import type { FhirDosage, FhirR6DosageInstructionInput, ParseBatchResult, NextDueDoseOptions, TotalUnitsOptions, TotalUnitsResult } from "./types";
9
+ import type { FhirDosage, FhirR6DosageInstructionInput, ParseBatchResult, DueDose, NextDueDoseOptions, TotalUnitsOptions, TotalUnitsResult } from "./types";
10
10
  import type { CanonicalScheduleInput, CanonicalSupplyOptions } from "./canonical/course";
11
11
  import { MedicationQuantityCalculationError } from "./execution/engine";
12
12
  export { MedicationQuantityCalculationError };
13
- export declare function nextDueDoses(input: FhirDosage | readonly FhirDosage[] | FhirR6DosageInstructionInput | ParseBatchResult | CanonicalScheduleInput, options: NextDueDoseOptions): string[];
13
+ type ScheduleInput = FhirDosage | readonly FhirDosage[] | FhirR6DosageInstructionInput | ParseBatchResult | CanonicalScheduleInput;
14
+ export declare function nextDueDoses(input: ScheduleInput, options: NextDueDoseOptions): string[];
15
+ /** Schedule the same opportunities with the selected administration and known source facts. */
16
+ export declare function nextDueDosesDetailed(input: ScheduleInput, options: NextDueDoseOptions): DueDose[];
14
17
  export declare function calculateTotalUnits(options: TotalUnitsOptions | CanonicalSupplyOptions): TotalUnitsResult;
@@ -1,4 +1,4 @@
1
- import type { CanonicalScheduleExpr } from "./types";
1
+ import type { CanonicalScheduleExpr, FormatOptions } from "./types";
2
2
  import { EventTiming, FhirDayOfWeek, FhirPeriodUnit, type ParseOptions } from "./types";
3
3
  /** Resolve authored event-relative offsets without changing their stored sign. */
4
4
  export declare function signedTimingEventOffset(code: string, offset: number): number;
@@ -105,7 +105,7 @@ export declare function intervalTimingPreviewDescriptor(code: string): {
105
105
  periodMax?: number;
106
106
  periodUnit: FhirPeriodUnit;
107
107
  } | undefined;
108
- export interface TimingSummaryOptions {
108
+ export interface TimingSummaryOptions extends Pick<ParseOptions, "locale" | "i18n"> {
109
109
  /** Scoped vocabulary in the original parse/format request. Do not build
110
110
  * any second registry or retain it on the canonical clinical course. */
111
111
  instructionActionMap?: ParseOptions["instructionActionMap"];
@@ -113,6 +113,7 @@ export interface TimingSummaryOptions {
113
113
  groupMealTimingsByRelation?: boolean;
114
114
  includeTimesPerDaySummary?: boolean;
115
115
  sitePlacement?: "natural" | "trailing";
116
+ pairedSiteWording?: FormatOptions["pairedSiteWording"];
116
117
  }
117
118
  export type MealRelation = "before" | "after" | "with";
118
119
  export type MealName = "breakfast" | "lunch" | "dinner";
package/dist/types.d.ts CHANGED
@@ -610,6 +610,12 @@ export type MedicationCondition = {
610
610
  name: string;
611
611
  text: string;
612
612
  expected: boolean;
613
+ finding?: {
614
+ system: string;
615
+ code: string;
616
+ version?: string;
617
+ display?: string;
618
+ };
613
619
  } | {
614
620
  kind: "text";
615
621
  text: string;
@@ -962,6 +968,8 @@ export interface FormatOptions {
962
968
  includeTimesPerDaySummary?: boolean;
963
969
  /** Thai long-text site placement. `natural` uses route-sensitive Thai word order; `trailing` preserves the legacy trailing site phrase. */
964
970
  sitePlacement?: "natural" | "trailing";
971
+ /** In normalized long text, name both paired sites while retaining the per-target dose. Defaults to `each`. */
972
+ pairedSiteWording?: "each" | "both";
965
973
  }
966
974
  export interface FormatBatchOptions extends FormatOptions {
967
975
  /**
@@ -1034,6 +1042,8 @@ export interface BodySiteDefinition {
1034
1042
  perTargetText?: string;
1035
1043
  /** Locale-specific per-target surface, e.g. Thai `รูจมูกข้างละ`. */
1036
1044
  perTargetI18n?: Record<string, string>;
1045
+ /** Localized qualifier in the explicit-pair form, e.g. `per eye` or `ทั้งสองข้าง`. */
1046
+ pairedDoseScopeI18n?: Record<string, string>;
1037
1047
  /** Optional translations for different locales (e.g., { "th": "ตา" }) */
1038
1048
  i18n?: Record<string, string>;
1039
1049
  /**
@@ -1077,7 +1087,8 @@ export declare enum AdviceModality {
1077
1087
  Might = "might",
1078
1088
  Could = "could",
1079
1089
  Should = "should",
1080
- Must = "must"
1090
+ Must = "must",
1091
+ Need = "need"
1081
1092
  }
1082
1093
  export declare enum AdviceRelation {
1083
1094
  With = "with",
@@ -1095,6 +1106,7 @@ export declare enum AdviceRelation {
1095
1106
  On = "on",
1096
1107
  To = "to",
1097
1108
  If = "if",
1109
+ EvenIf = "even-if",
1098
1110
  Unless = "unless",
1099
1111
  When = "when",
1100
1112
  While = "while"
@@ -1114,6 +1126,7 @@ export declare enum AdviceArgumentRole {
1114
1126
  Amount = "amount",
1115
1127
  Duration = "duration",
1116
1128
  Time = "time",
1129
+ Condition = "condition",
1117
1130
  Free = "free"
1118
1131
  }
1119
1132
  /** A constituent of a compound meaning, not an alternative coding of that whole meaning. */
@@ -1369,6 +1382,8 @@ export interface MedicationInstructionActionLocaleRealizerConfig {
1369
1382
  routePhrases?: Record<string, string>;
1370
1383
  /** Prefix for the duration of each administration occurrence. */
1371
1384
  administrationDurationPrefix?: string;
1385
+ /** Locale wording for a selected procedural duration. */
1386
+ proceduralDurationPrefix?: string;
1372
1387
  }
1373
1388
  export interface MedicationInstructionActionRealizerConfig {
1374
1389
  /** Locale-specific realization behavior keyed by BCP-47-ish language tag. */
@@ -1417,6 +1432,8 @@ export interface MedicationInstructionActionDefinition {
1417
1432
  * The selected-dose form requires an explicit medication object or a typed dose-slot target;
1418
1433
  * it never treats a bare avoidance verb, food object, or negation as withholding. */
1419
1434
  medicationConditionEffect?: "withhold" | "withhold-selected-dose";
1435
+ /** Registered lexical governors of a local procedural duration. */
1436
+ durationArgumentIntroducers?: string[];
1420
1437
  primaryConcepts?: string[];
1421
1438
  secondaryConcepts?: string[];
1422
1439
  implicitMatchedConcept?: string;
@@ -1475,8 +1492,14 @@ export interface MedicationInstructionActionInput extends Partial<MedicationInst
1475
1492
  semanticClass?: string;
1476
1493
  }
1477
1494
  export interface MedicationInstructionConceptDefinition {
1495
+ /** An instruction-owned Object retains its own temporal complements. */
1496
+ localInstructionObject?: true;
1478
1497
  code: string;
1479
1498
  role: AdviceArgumentRole;
1499
+ /** The registered activity can itself close an instruction predicate. */
1500
+ conditionEvent?: true;
1501
+ /** An authored following duration measures this selected activity. */
1502
+ measuredActivity?: true;
1480
1503
  /** A complete unqualified nominal refers to the administration's selected site. */
1481
1504
  administrationSiteReference?: true;
1482
1505
  /** A registered compound noun may entail a second independently typed
@@ -1843,6 +1866,14 @@ export interface CanonicalCalendarEventExpr {
1843
1866
  */
1844
1867
  export interface CanonicalCycleDayConstraint {
1845
1868
  days: number[];
1869
+ cycleConcept?: FhirR6Coding;
1870
+ /** An authored treatment start ordinal, distinct from a day of eligibility. */
1871
+ startDay?: number;
1872
+ /** Maximum number of treatment days in one cycle. */
1873
+ maxTreatmentDays?: number;
1874
+ /** Authored event defining day one. */
1875
+ dayOneEvent?: FhirR6Coding;
1876
+ dayOneSourceText?: string;
1846
1877
  periodDays?: number;
1847
1878
  cycles?: number;
1848
1879
  anchor?: string;
@@ -1976,6 +2007,17 @@ export interface CanonicalAdditionalInstructionExpr {
1976
2007
  frames?: AdviceFrame[];
1977
2008
  evidence?: CanonicalEvidence[];
1978
2009
  }
2010
+ /** A procedural condition reuses the existing coded argument at its leaves.
2011
+ * Boolean scope is distinct from medication administration eligibility. */
2012
+ export type CanonicalInstructionCondition = (AdviceArgument & {
2013
+ aspect?: "persists" | "worsens";
2014
+ }) | {
2015
+ operator: "all" | "any";
2016
+ operands: CanonicalInstructionCondition[];
2017
+ } | {
2018
+ operator: "not";
2019
+ operands: [CanonicalInstructionCondition];
2020
+ };
1979
2021
  export interface CanonicalInstructionRelation {
1980
2022
  /** Retained wire annotations are source data, never relationship semantics. */
1981
2023
  sourceId?: string;
@@ -1986,6 +2028,10 @@ export interface CanonicalInstructionRelation {
1986
2028
  fromActionIndex?: number;
1987
2029
  toActionIndex: number;
1988
2030
  text?: string;
2031
+ /** A complete registered predicate selected for this instruction scope. */
2032
+ condition?: CanonicalInstructionCondition;
2033
+ /** Temporal adjunct of the complete predicate, separate from its action. */
2034
+ conditionTiming?: AdviceArgument;
1989
2035
  span?: TextRange;
1990
2036
  }
1991
2037
  export interface CanonicalInstructionCoverage {
@@ -2141,8 +2187,12 @@ export interface CanonicalSigClause {
2141
2187
  kind: AdviceRelation;
2142
2188
  span: TextRange;
2143
2189
  target: TextRange;
2190
+ condition?: CanonicalInstructionCondition;
2191
+ conditionTiming?: AdviceArgument;
2144
2192
  }>;
2145
2193
  patientInstruction?: string;
2194
+ /** Explicit wording supplied on the FHIR patientInstruction primitive. */
2195
+ patientInstructionI18n?: Record<string, string>;
2146
2196
  instructionGraph?: CanonicalInstructionGraph;
2147
2197
  additionalInstructions?: CanonicalAdditionalInstructionExpr[];
2148
2198
  leftovers: CanonicalSourceSpan[];
@@ -2332,6 +2382,41 @@ export interface NextDueDoseOptions {
2332
2382
  frequencyDefaults?: FrequencyFallbackTimes;
2333
2383
  config?: NextDueDoseConfig;
2334
2384
  }
2385
+ /** Authored selectors that contributed to this occurrence. An anchor can
2386
+ * resolve to a specific meal when the schedule names a generic meal. */
2387
+ export type DueDoseOrigin = {
2388
+ readonly kind: "anchor";
2389
+ readonly code: string;
2390
+ readonly event?: string;
2391
+ } | {
2392
+ readonly kind: "clock" | "configured-clock";
2393
+ readonly clock: string;
2394
+ } | {
2395
+ readonly kind: "date";
2396
+ readonly value: string;
2397
+ };
2398
+ /** Zero-based positions within the normalized input course, when known.
2399
+ * Source member and authored track identities are retained independently. */
2400
+ export interface DueDoseSource {
2401
+ readonly stageIndex?: number;
2402
+ readonly administrationIndex?: number;
2403
+ readonly sourceMember?: number;
2404
+ readonly trackIndex?: number;
2405
+ }
2406
+ type ReadonlyClinicalFacts<T> = {
2407
+ readonly [Key in keyof T]: ReadonlyClinicalFacts<T[Key]>;
2408
+ };
2409
+ /** One accepted scheduled opportunity. Its authored quantities may be
2410
+ * ranged, rates, or otherwise dependent on clinical information. */
2411
+ export interface DueDose {
2412
+ readonly time: string;
2413
+ readonly administration: ReadonlyClinicalFacts<import("./canonical/course").CanonicalAdministration>;
2414
+ readonly source?: DueDoseSource;
2415
+ readonly origins?: readonly DueDoseOrigin[];
2416
+ readonly asNeeded: boolean;
2417
+ /** Whether a clinical condition was absent, assumed, or admitted by the evaluator. */
2418
+ readonly condition: "none" | "assumed" | "evaluated";
2419
+ }
2335
2420
  /** Due times calculated with each ordered medication-instruction phase respected. */
2336
2421
  export interface RegimenDueTimes {
2337
2422
  dosageIndex: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ezmedicationinput",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Parse clinician SIGs into extended R5-style dosages with strict R5 and R6 projections",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",