ezmedicationinput 0.1.67 → 0.3.0-beta.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.
- package/README.md +222 -28
- package/dist/adapters/canonical-course.d.ts +128 -0
- package/dist/adapters/r5-course.d.ts +24 -0
- package/dist/advice.d.ts +52 -1
- package/dist/body-site-grammar.d.ts +34 -1
- package/dist/body-site-lookup.d.ts +3 -0
- package/dist/body-site-spatial.d.ts +6 -2
- package/dist/body-site-target.d.ts +9 -3
- package/dist/canonical/compile.d.ts +79 -0
- package/dist/canonical/course.d.ts +352 -0
- package/dist/canonical/format-course.d.ts +36 -0
- package/dist/date-interpretation.d.ts +2 -0
- package/dist/dosage-course.d.ts +453 -0
- package/dist/execution/calendar.d.ts +107 -0
- package/dist/execution/engine.d.ts +11 -0
- package/dist/fhir-quantity-operator.d.ts +53 -0
- package/dist/fhir-translations.d.ts +5 -6
- package/dist/fhir.d.ts +233 -13
- package/dist/format.d.ts +113 -3
- package/dist/hpsg/constructions.d.ts +113 -0
- package/dist/hpsg/defaults.d.ts +2 -0
- package/dist/hpsg/lexical-classes.d.ts +282 -2
- package/dist/hpsg/procedural-context.d.ts +18 -4
- package/dist/hpsg/projection.d.ts +38 -3
- package/dist/hpsg/rule-context.d.ts +117 -7
- package/dist/hpsg/rules/clinical-quantity-rules.d.ts +18 -0
- package/dist/hpsg/rules/condition-rules.d.ts +14 -0
- package/dist/hpsg/rules/core-rules.d.ts +32 -0
- package/dist/hpsg/rules/instruction-rules.d.ts +11 -1
- package/dist/hpsg/rules/prn-rules.d.ts +3 -1
- package/dist/hpsg/rules/timing-rules.d.ts +138 -8
- package/dist/hpsg/signature.d.ts +353 -5
- package/dist/hpsg/type-system.d.ts +16 -1
- package/dist/hpsg/unification.d.ts +4 -1
- package/dist/i18n.d.ts +39 -1
- package/dist/index.cjs +65539 -30893
- package/dist/index.d.ts +35 -7
- package/dist/index.js +65505 -30892
- package/dist/instruction-action-locale-adapter.d.ts +32 -3
- package/dist/instruction-action-terminology.d.ts +38 -3
- package/dist/instruction-concept-terminology.d.ts +8 -1
- package/dist/instruction-graph-fhir.d.ts +9 -3
- package/dist/instruction-graph.d.ts +85 -7
- package/dist/ir.d.ts +13 -2
- package/dist/lexer/surface-segmenter.d.ts +1 -1
- package/dist/lexer/surface.d.ts +1 -0
- package/dist/locale-detection.d.ts +3 -0
- package/dist/locales/course/en.d.ts +15 -0
- package/dist/locales/course/th.d.ts +12 -0
- package/dist/localization.d.ts +73 -0
- package/dist/maps.d.ts +24 -1
- package/dist/medication-condition.d.ts +42 -0
- package/dist/parser-state.d.ts +6 -2
- package/dist/parser.d.ts +5 -2
- package/dist/regimen/coordination-scope.d.ts +53 -0
- package/dist/regimen/grammar.d.ts +79 -0
- package/dist/regimen/parallel-course.d.ts +52 -0
- package/dist/regimen/planner.d.ts +19 -0
- package/dist/regimen/regimen.d.ts +70 -0
- package/dist/relation-terminology.d.ts +1 -0
- package/dist/schedule.d.ts +12 -5
- package/dist/stable-structure.d.ts +23 -1
- package/dist/timing-summary.d.ts +82 -1
- package/dist/types.d.ts +899 -40
- package/dist/unit-lexicon.d.ts +7 -0
- package/dist/utils/strength.d.ts +16 -0
- package/dist/utils/text.d.ts +3 -0
- package/dist/utils/units.d.ts +19 -0
- package/package.json +3 -2
package/dist/hpsg/signature.d.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { HpsgSigSegment } from "./segmenter";
|
|
2
|
+
import type { CanonicalSigClause, ParseOptions } from "../types";
|
|
3
|
+
import type { MedicationDateListMatch } from "../date-interpretation";
|
|
4
|
+
import { AdviceFrame, AdviceRelation, CanonicalDoseRange, CanonicalClinicalAdjuncts, CanonicalAdditionalInstructionExpr, CanonicalActivityTimingExpr, CanonicalCalendarEventExpr, CanonicalCycleDayConstraint, CanonicalDosePeriodMaximumExpr, CanonicalOccurrenceCapExpr, AdministrationTargetCoordinationKind, CanonicalScheduleSemanticField, CanonicalLexicalCategory, BodySiteRestriction, BodySiteRestrictionPredicate, BodySiteSpatialRelation, EventTiming, FhirCoding, FhirDayOfWeek, FhirPeriodUnit, FhirPrimitiveElement, FhirQuantity, MedicationCondition, RouteCode, PrnReasonLookupRequest, SiteCodeLookupRequest, TextRange } from "../types";
|
|
2
5
|
import { Token } from "../parser-state";
|
|
3
6
|
import type { HpsgFeatureNode } from "./type-system";
|
|
4
|
-
export type HpsgType = "sign" | "word-sign" | "phrase-sign" | "headed-phrase" | "head-complement-phrase" | "head-adjunct-phrase" | "head-marker-phrase" | "procedure-sequence-phrase" | "conditional-instruction-phrase" | "coordination-phrase" | "clause-sign" | "administration-clause" | "method-sign" | "route-sign" | "site-sign" | "dose-sign" | "schedule-sign" | "prn-sign" | "instruction-sign" | "conditional-sign" | "adjustment-sign" | "connector-sign";
|
|
7
|
+
export type HpsgType = "sign" | "word-sign" | "phrase-sign" | "headed-phrase" | "head-complement-phrase" | "head-adjunct-phrase" | "head-marker-phrase" | "procedure-sequence-phrase" | "conditional-instruction-phrase" | "coordination-phrase" | "site-coordination-phrase" | "clause-sign" | "administration-clause" | "method-sign" | "route-sign" | "site-sign" | "site-relative-marker-sign" | "site-predicate-sign" | "site-relative-clause" | "restricted-site-phrase" | "recurring-course-phrase" | "dose-sign" | "schedule-sign" | "prn-sign" | "instruction-sign" | "conditional-sign" | "clinical-adjunct-sign" | "guard-predicate-sign" | "guard-operator-sign" | "guard-marker-sign" | "guard-predicate-phrase" | "guard-coordination-tail" | "guard-negation-phrase" | "medication-guard-phrase" | "adjustment-sign" | "connector-sign";
|
|
5
8
|
export interface HpsgEvidence {
|
|
6
9
|
rule: string;
|
|
10
|
+
/** Canonical provenance comes from the typed lexical sign, not its rule ID. */
|
|
11
|
+
lexicalCategory?: CanonicalLexicalCategory;
|
|
7
12
|
tokenIndices: number[];
|
|
8
13
|
/** Lexical evidence that a schedule field is an inferred, construction-local default. */
|
|
9
|
-
scheduleDefault?: "daily-frequency";
|
|
14
|
+
scheduleDefault?: "daily-frequency" | "weekday-recurrence";
|
|
15
|
+
/** Exact typed schedule fields contributed by this lexical evidence. */
|
|
16
|
+
scheduleFields?: CanonicalScheduleSemanticField[];
|
|
10
17
|
}
|
|
11
18
|
export type HpsgConstructionKind = "head-complement" | "head-adjunct" | "head-marker" | "procedure-sequence" | "conditional-instruction" | "coordination" | "administration-clause" | "generic";
|
|
12
|
-
export type HpsgConstructionOperation = "unify" | "scope";
|
|
19
|
+
export type HpsgConstructionOperation = "unify" | "scope" | "form-site-relative" | "restrict-site" | "repeat-course";
|
|
13
20
|
export interface HpsgConstruction {
|
|
14
21
|
kind: HpsgConstructionKind;
|
|
15
22
|
operation?: HpsgConstructionOperation;
|
|
@@ -29,14 +36,36 @@ export interface HpsgRouteFeature {
|
|
|
29
36
|
attachmentClass?: "administration" | "procedure";
|
|
30
37
|
text?: string;
|
|
31
38
|
}
|
|
32
|
-
export interface
|
|
39
|
+
export interface HpsgAdministrationTargetFeature {
|
|
33
40
|
attachmentClass?: "administration" | "procedure";
|
|
34
41
|
text?: string;
|
|
35
42
|
i18n?: Record<string, string>;
|
|
36
43
|
source?: "abbreviation" | "text" | "selection" | "resolver";
|
|
37
44
|
coding?: FhirCoding;
|
|
38
45
|
spatialRelation?: BodySiteSpatialRelation;
|
|
46
|
+
restrictions?: BodySiteRestriction[];
|
|
39
47
|
lookupRequest?: SiteCodeLookupRequest;
|
|
48
|
+
administrationTargetCount?: number;
|
|
49
|
+
range?: TextRange;
|
|
50
|
+
}
|
|
51
|
+
export interface HpsgSiteCoordinationFeature {
|
|
52
|
+
coordination: AdministrationTargetCoordinationKind;
|
|
53
|
+
sourceText: string;
|
|
54
|
+
range: TextRange;
|
|
55
|
+
targets: HpsgAdministrationTargetFeature[];
|
|
56
|
+
}
|
|
57
|
+
export interface HpsgSiteFeature extends HpsgAdministrationTargetFeature {
|
|
58
|
+
coordination?: HpsgSiteCoordinationFeature;
|
|
59
|
+
}
|
|
60
|
+
export interface HpsgCoordinationMarkerFeature {
|
|
61
|
+
coordination: Exclude<AdministrationTargetCoordinationKind, "mixed">;
|
|
62
|
+
}
|
|
63
|
+
export interface HpsgSiteRelativeMarkerFeature {
|
|
64
|
+
relation: BodySiteRestriction["relation"];
|
|
65
|
+
range: TextRange;
|
|
66
|
+
}
|
|
67
|
+
export interface HpsgSitePredicateFeature extends BodySiteRestrictionPredicate {
|
|
68
|
+
range: TextRange;
|
|
40
69
|
}
|
|
41
70
|
export interface HpsgPrnFeature {
|
|
42
71
|
enabled: true;
|
|
@@ -63,9 +92,61 @@ export interface HpsgConditionFeature {
|
|
|
63
92
|
sourceEnd: number;
|
|
64
93
|
targetStart: number;
|
|
65
94
|
targetEnd: number;
|
|
95
|
+
/** Independently selected targets of one coordinated withholding program. */
|
|
96
|
+
targetRanges?: TextRange[];
|
|
66
97
|
safety: boolean;
|
|
67
98
|
frames: AdviceFrame[];
|
|
68
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* A medication-level guard or calendar omission contributed by a lexical
|
|
102
|
+
* sign. This is distinct from HpsgConditionFeature, which scopes procedural
|
|
103
|
+
* instruction programs such as "if irritation occurs, stop use".
|
|
104
|
+
*/
|
|
105
|
+
/** A predicate daughter can require a measurement head from an adjacent
|
|
106
|
+
* coordinate. Only the HPSG coordination construction may discharge it. */
|
|
107
|
+
export type HpsgGuardExpression = {
|
|
108
|
+
kind: "predicate";
|
|
109
|
+
value: MedicationCondition;
|
|
110
|
+
dayInvariant?: true;
|
|
111
|
+
} | {
|
|
112
|
+
kind: "measurement-complement";
|
|
113
|
+
operation: "gt" | "ge" | "lt" | "le" | "eq";
|
|
114
|
+
value: number;
|
|
115
|
+
unit?: string;
|
|
116
|
+
text: string;
|
|
117
|
+
} | {
|
|
118
|
+
kind: "coordination";
|
|
119
|
+
operator: "all" | "any";
|
|
120
|
+
parts: HpsgGuardExpression[];
|
|
121
|
+
} | {
|
|
122
|
+
kind: "negation";
|
|
123
|
+
operand: HpsgGuardExpression;
|
|
124
|
+
};
|
|
125
|
+
/** Internal conditional constituent features, never a second FHIR schema. */
|
|
126
|
+
export interface HpsgGuardFeature {
|
|
127
|
+
expression?: HpsgGuardExpression;
|
|
128
|
+
operator?: "all" | "any" | "not";
|
|
129
|
+
marker?: "if" | "only-if" | "unless";
|
|
130
|
+
licensesBareIf?: true;
|
|
131
|
+
}
|
|
132
|
+
export interface HpsgClinicalAdjunctFeature {
|
|
133
|
+
treatmentPause?: CanonicalClinicalAdjuncts["treatmentPause"];
|
|
134
|
+
condition?: MedicationCondition;
|
|
135
|
+
/** Day-domain meaning retained separately for typed anaphoric complements. */
|
|
136
|
+
calendarDayCondition?: MedicationCondition;
|
|
137
|
+
conditionTarget?: CanonicalClinicalAdjuncts["conditionTarget"];
|
|
138
|
+
excludedDates?: string[];
|
|
139
|
+
excludedWeekdays?: FhirDayOfWeek[];
|
|
140
|
+
/** Recognized adjunct boundary whose payload remains intentionally editable. */
|
|
141
|
+
unresolved?: true;
|
|
142
|
+
localRanges: TextRange[];
|
|
143
|
+
/** Lexical provenance and typed clinical role are distinct. */
|
|
144
|
+
evidence: Array<{
|
|
145
|
+
rule: string;
|
|
146
|
+
kind: "condition" | "calendar-exclusion" | "treatment-pause" | "unresolved";
|
|
147
|
+
ranges: TextRange[];
|
|
148
|
+
}>;
|
|
149
|
+
}
|
|
69
150
|
export interface HpsgScopedAdministrationFeature {
|
|
70
151
|
condition: HpsgConditionFeature;
|
|
71
152
|
head: HpsgSynsem["head"];
|
|
@@ -79,15 +160,97 @@ export interface HpsgDoseFeature {
|
|
|
79
160
|
value?: number;
|
|
80
161
|
range?: CanonicalDoseRange;
|
|
81
162
|
unit?: string;
|
|
163
|
+
comparator?: FhirQuantity["comparator"] | "~";
|
|
164
|
+
/**
|
|
165
|
+
* Dimensionally typed clinical quantity contributed by the grammar. This
|
|
166
|
+
* remains distinct from `value`/`unit`: an infusion rate must never be
|
|
167
|
+
* projected through the ordinary doseQuantity path.
|
|
168
|
+
*/
|
|
169
|
+
clinicalQuantity?: HpsgClinicalQuantityFeature;
|
|
170
|
+
/** Number of administrations dividing a stated period-total quantity. */
|
|
171
|
+
divisionCount?: number;
|
|
172
|
+
}
|
|
173
|
+
export type HpsgClinicalQuantityDimension = "mass" | "volume" | "biologic-activity" | "administration-unit" | "patient-mass" | "time";
|
|
174
|
+
/** Authored quantity label plus any FHIR unit coding that cannot be regenerated from it. */
|
|
175
|
+
export interface HpsgCodedQuantityTerm {
|
|
176
|
+
value: number;
|
|
177
|
+
unit: string;
|
|
178
|
+
/** Qualifier on this amount only; active drug and carrier can differ. */
|
|
179
|
+
comparator?: FhirQuantity["comparator"] | "~";
|
|
180
|
+
system?: string;
|
|
181
|
+
code?: string;
|
|
182
|
+
}
|
|
183
|
+
export interface HpsgDimensionalQuantityTerm extends HpsgCodedQuantityTerm {
|
|
184
|
+
dimension: HpsgClinicalQuantityDimension;
|
|
185
|
+
}
|
|
186
|
+
export interface HpsgClinicalQuantityFeature {
|
|
187
|
+
representation: "dose" | "rate-quantity" | "dose-with-rate-ratio";
|
|
188
|
+
status: "resolved" | "incomplete" | "unsupported";
|
|
189
|
+
numerator: HpsgDimensionalQuantityTerm | (Omit<HpsgDimensionalQuantityTerm, "value"> & {
|
|
190
|
+
range: CanonicalDoseRange;
|
|
191
|
+
});
|
|
192
|
+
denominators: HpsgDimensionalQuantityTerm[];
|
|
193
|
+
/** Per-administration value after an explicit daily total is divided. */
|
|
194
|
+
projectedDose?: HpsgCodedQuantityTerm;
|
|
195
|
+
/** Carrier amount used for an administration rate when it differs from the active drug dose. */
|
|
196
|
+
rateNumerator?: HpsgCodedQuantityTerm;
|
|
197
|
+
/** Source-backed vehicle NP scoped to the carrier volume, not the active drug.
|
|
198
|
+
* It is descriptive and uncoded unless terminology separately confirms it. */
|
|
199
|
+
carrierMaterial?: {
|
|
200
|
+
text: string;
|
|
201
|
+
range?: TextRange;
|
|
202
|
+
};
|
|
203
|
+
dailyTotal?: boolean;
|
|
204
|
+
dividedDoseCount?: number;
|
|
205
|
+
administrationDuration?: {
|
|
206
|
+
value: number;
|
|
207
|
+
unit: FhirPeriodUnit;
|
|
208
|
+
comparator?: FhirQuantity["comparator"] | "~";
|
|
209
|
+
};
|
|
210
|
+
requiresPatientWeight?: true;
|
|
211
|
+
reviewReason?: "incomplete-weight-based-dose" | "unsupported-weight-based-rate";
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The public canonical schema predates rate parsing. Declaration merging
|
|
215
|
+
* exposes the typed grammar contribution without forcing it into the scalar
|
|
216
|
+
* CanonicalDoseExpr shape. FHIR lowering can therefore distinguish a dose,
|
|
217
|
+
* a rateQuantity, and a dose/rateRatio without reparsing source text.
|
|
218
|
+
*/
|
|
219
|
+
declare module "../types" {
|
|
220
|
+
interface CanonicalSigClause {
|
|
221
|
+
clinicalQuantity?: HpsgClinicalQuantityFeature;
|
|
222
|
+
}
|
|
82
223
|
}
|
|
83
224
|
export interface HpsgScheduleFeature {
|
|
225
|
+
cycleDayConstraint?: CanonicalCycleDayConstraint;
|
|
226
|
+
/** Typed whole-course interval for a recurring active/rest construction. */
|
|
227
|
+
repeatCycle?: FhirQuantity;
|
|
228
|
+
/** Explicit finite number of whole-course repetitions; absent means unbounded. */
|
|
229
|
+
repeatCount?: number;
|
|
230
|
+
/** Explicit local-clock interval window; not a list of endpoint doses. */
|
|
231
|
+
clockWindow?: {
|
|
232
|
+
start: string;
|
|
233
|
+
end: string;
|
|
234
|
+
endInclusive: boolean;
|
|
235
|
+
};
|
|
236
|
+
/** Weekday occurrence in each month; -1 denotes the last occurrence. */
|
|
237
|
+
weekdayOrdinal?: -1 | 1 | 2 | 3 | 4 | 5;
|
|
238
|
+
timingReference?: "previous" | "previous-weekday-complement";
|
|
239
|
+
/** Source-relative phase onset; the reference distinguishes civil days. */
|
|
240
|
+
treatmentStartOffsetDays?: number;
|
|
241
|
+
/** Local civil-day origin or completion of the preceding phase. */
|
|
242
|
+
phaseStartReference?: "treatment-day-start" | "previous-phase-next-day" | "previous-phase-end";
|
|
84
243
|
attachmentClass?: "administration" | "procedure";
|
|
244
|
+
/** Exact source owned by this schedule construction, retained for generic attachment arbitration. */
|
|
245
|
+
sourceRanges?: TextRange[];
|
|
85
246
|
timingCode?: string;
|
|
86
247
|
count?: number;
|
|
87
248
|
countMax?: number;
|
|
88
249
|
duration?: number;
|
|
89
250
|
durationMax?: number;
|
|
90
251
|
durationUnit?: FhirPeriodUnit;
|
|
252
|
+
/** Elapsed delay before one administration, not a course duration. */
|
|
253
|
+
administrationOffsetMinutes?: number;
|
|
91
254
|
boundsStart?: string;
|
|
92
255
|
boundsEnd?: string;
|
|
93
256
|
frequency?: number;
|
|
@@ -100,10 +263,17 @@ export interface HpsgScheduleFeature {
|
|
|
100
263
|
offsetMax?: number;
|
|
101
264
|
when?: EventTiming[];
|
|
102
265
|
dayOfWeek?: FhirDayOfWeek[];
|
|
266
|
+
/** Recurring calendar dates of each month; e.g. days 1–14. */
|
|
267
|
+
dayOfMonth?: number[];
|
|
103
268
|
timeOfDay?: string[];
|
|
104
269
|
calendarEvents?: CanonicalCalendarEventExpr[];
|
|
105
270
|
activityTiming?: CanonicalActivityTimingExpr[];
|
|
271
|
+
eventWindow?: {
|
|
272
|
+
start: EventTiming;
|
|
273
|
+
end: EventTiming;
|
|
274
|
+
};
|
|
106
275
|
occurrenceCap?: CanonicalOccurrenceCapExpr;
|
|
276
|
+
maxDosePerPeriod?: CanonicalDosePeriodMaximumExpr[];
|
|
107
277
|
}
|
|
108
278
|
export interface HpsgSynsem {
|
|
109
279
|
head: {
|
|
@@ -119,10 +289,18 @@ export interface HpsgSynsem {
|
|
|
119
289
|
patientInstruction?: HpsgPatientInstructionFeature;
|
|
120
290
|
};
|
|
121
291
|
cont: {
|
|
292
|
+
/** Source operation on the preceding regimen, resolved before projection. */
|
|
293
|
+
regimenAdjustment?: "replace" | "add" | "replace-target";
|
|
122
294
|
clauseKind?: "administration";
|
|
123
295
|
condition?: HpsgConditionFeature;
|
|
296
|
+
clinicalAdjunct?: HpsgClinicalAdjunctFeature;
|
|
297
|
+
guard?: HpsgGuardFeature;
|
|
124
298
|
scopedAdministrations?: HpsgScopedAdministrationFeature[];
|
|
125
299
|
scopeClosed?: true;
|
|
300
|
+
coordinationMarker?: HpsgCoordinationMarkerFeature;
|
|
301
|
+
siteRelativeMarker?: HpsgSiteRelativeMarkerFeature;
|
|
302
|
+
sitePredicate?: HpsgSitePredicateFeature;
|
|
303
|
+
siteRestriction?: BodySiteRestriction;
|
|
126
304
|
};
|
|
127
305
|
nonlocal?: {
|
|
128
306
|
scopeRequirements?: HpsgConditionFeature[];
|
|
@@ -165,6 +343,7 @@ export declare function emptySynsem(): HpsgSynsem;
|
|
|
165
343
|
export declare function lexicalSign(args: {
|
|
166
344
|
type: HpsgType;
|
|
167
345
|
rule: string;
|
|
346
|
+
lexicalCategory?: CanonicalLexicalCategory;
|
|
168
347
|
tokens: Token[];
|
|
169
348
|
synsem: HpsgSynsem;
|
|
170
349
|
consumedTokenIndices?: number[];
|
|
@@ -172,4 +351,173 @@ export declare function lexicalSign(args: {
|
|
|
172
351
|
warnings?: string[];
|
|
173
352
|
score?: number;
|
|
174
353
|
scheduleDefault?: HpsgEvidence["scheduleDefault"];
|
|
354
|
+
scheduleFields?: CanonicalScheduleSemanticField[];
|
|
175
355
|
}): HpsgSign;
|
|
356
|
+
/** Cross-clause HPSG construction facts and source-boundary plans. */
|
|
357
|
+
export interface Range {
|
|
358
|
+
start: number;
|
|
359
|
+
end: number;
|
|
360
|
+
}
|
|
361
|
+
export type StructureKind = 'cycle-schedule' | 'target-list' | 'calendar-date-list' | 'clock-list' | 'weekday-list' | 'numeric-quantity' | 'parenthesized' | 'calendar-exclusion' | 'fronted-conditional-clause' | 'procedural-argument' | 'clinical-condition' | 'event-timing-list';
|
|
362
|
+
export interface StructuralClaim extends Range {
|
|
363
|
+
id: string;
|
|
364
|
+
kind: StructureKind;
|
|
365
|
+
policy: 'no-external-split';
|
|
366
|
+
producer: string;
|
|
367
|
+
resolved: boolean;
|
|
368
|
+
}
|
|
369
|
+
export type BoundaryKind = 'coordination' | 'alternative' | 'sequence' | 'comma' | 'hard' | 'slash' | 'adjacent-dose' | 'punctuation';
|
|
370
|
+
export type CoordinationConnectorKind = 'conjunction' | 'disjunction' | 'unknown';
|
|
371
|
+
export type RegimenRelation = 'sequence' | 'coordination' | 'alternative' | 'shared-duration' | 'independent';
|
|
372
|
+
export interface BoundarySite extends Range {
|
|
373
|
+
tokenIndex: number;
|
|
374
|
+
lastTokenIndex: number;
|
|
375
|
+
rightIndex: number;
|
|
376
|
+
kind: BoundaryKind;
|
|
377
|
+
surface: string;
|
|
378
|
+
}
|
|
379
|
+
export interface Evidence {
|
|
380
|
+
feature: string;
|
|
381
|
+
value: string | number | boolean | readonly string[];
|
|
382
|
+
range?: Range;
|
|
383
|
+
}
|
|
384
|
+
export interface Proposal {
|
|
385
|
+
action: 'keep' | 'split';
|
|
386
|
+
rule: string;
|
|
387
|
+
priority: number;
|
|
388
|
+
relation?: RegimenRelation;
|
|
389
|
+
/** Typed boundary license to inherit a following sibling's course duration. */
|
|
390
|
+
inheritFollowingDuration?: boolean;
|
|
391
|
+
/** Typed construction license, never inferred from its display rule id. */
|
|
392
|
+
semanticLicense?: "dose-continuation" | "target-transition" | "delayed-target" | "event-timing-ellipsis" | "interval-origin";
|
|
393
|
+
evidence: Evidence[];
|
|
394
|
+
}
|
|
395
|
+
export interface BoundaryDecision {
|
|
396
|
+
site: BoundarySite;
|
|
397
|
+
selected: Proposal;
|
|
398
|
+
alternatives: Proposal[];
|
|
399
|
+
conflict: boolean;
|
|
400
|
+
rejectedRules?: Array<{
|
|
401
|
+
rule: string;
|
|
402
|
+
failedConstraints: string[];
|
|
403
|
+
}>;
|
|
404
|
+
}
|
|
405
|
+
export interface ProbeSummary extends Range {
|
|
406
|
+
complete: boolean;
|
|
407
|
+
hasHead: boolean;
|
|
408
|
+
hasDose: boolean;
|
|
409
|
+
hasSchedule: boolean;
|
|
410
|
+
hasRecurringCadence: boolean;
|
|
411
|
+
hasDates: boolean;
|
|
412
|
+
hasClocks: boolean;
|
|
413
|
+
hasOffset: boolean;
|
|
414
|
+
method: boolean;
|
|
415
|
+
prn: boolean;
|
|
416
|
+
clocks: readonly string[];
|
|
417
|
+
conditionStarts: readonly number[];
|
|
418
|
+
targets: readonly string[];
|
|
419
|
+
hasTargets: boolean;
|
|
420
|
+
siteCoordinations: Array<Range & {
|
|
421
|
+
type: 'site-coordination-phrase';
|
|
422
|
+
coordination: 'conjunction' | 'disjunction' | 'mixed';
|
|
423
|
+
}>;
|
|
424
|
+
clause: CanonicalSigClause;
|
|
425
|
+
}
|
|
426
|
+
export interface PlannerMetrics {
|
|
427
|
+
lexicalPasses: number;
|
|
428
|
+
dateScans: number;
|
|
429
|
+
actionScans: number;
|
|
430
|
+
clauseProbes: number;
|
|
431
|
+
siteCoordinationProbes: number;
|
|
432
|
+
probeCacheHits: number;
|
|
433
|
+
probedTokens: number;
|
|
434
|
+
candidates: number;
|
|
435
|
+
claimedCandidates: number;
|
|
436
|
+
}
|
|
437
|
+
export interface BoundaryPlan {
|
|
438
|
+
experimental: true;
|
|
439
|
+
segments: HpsgSigSegment[];
|
|
440
|
+
claims: StructuralClaim[];
|
|
441
|
+
decisions: BoundaryDecision[];
|
|
442
|
+
relations: BoundaryRelation[];
|
|
443
|
+
metrics: PlannerMetrics;
|
|
444
|
+
}
|
|
445
|
+
export interface PlannerOptions {
|
|
446
|
+
trace?: boolean;
|
|
447
|
+
ownership?: boolean;
|
|
448
|
+
cache?: boolean;
|
|
449
|
+
}
|
|
450
|
+
export interface PlanningInput {
|
|
451
|
+
input: string;
|
|
452
|
+
options?: ParseOptions;
|
|
453
|
+
tokens: Token[];
|
|
454
|
+
dateSpans?: MedicationDateListMatch[];
|
|
455
|
+
}
|
|
456
|
+
/** A licensed relation connects segment identities, never reconstructed from display text. */
|
|
457
|
+
export interface BoundaryRelation {
|
|
458
|
+
from: number;
|
|
459
|
+
to: number;
|
|
460
|
+
kind: RegimenRelation;
|
|
461
|
+
connectorKind: CoordinationConnectorKind;
|
|
462
|
+
rule: string;
|
|
463
|
+
semanticLicense?: Proposal["semanticLicense"];
|
|
464
|
+
range: Range;
|
|
465
|
+
}
|
|
466
|
+
/** Typed facts consumed by cross-clause HPSG coordination constructions. */
|
|
467
|
+
export interface CoordinationScopeFacts {
|
|
468
|
+
relation: BoundaryRelation;
|
|
469
|
+
adjacent: boolean;
|
|
470
|
+
leftComplete: boolean;
|
|
471
|
+
rightComplete: boolean;
|
|
472
|
+
leftExplicitDose: boolean;
|
|
473
|
+
rightExplicitDose: boolean;
|
|
474
|
+
leftExplicitHead: boolean;
|
|
475
|
+
/** An available typed method, whether explicit or inherited from an earlier daughter. */
|
|
476
|
+
leftHasMethod: boolean;
|
|
477
|
+
leftAdministrationContext: boolean;
|
|
478
|
+
rightExplicitHead: boolean;
|
|
479
|
+
leftHasSite: boolean;
|
|
480
|
+
rightHasSite: boolean;
|
|
481
|
+
targetsDistinct: boolean;
|
|
482
|
+
leftHasSchedule: boolean;
|
|
483
|
+
rightHasSchedule: boolean;
|
|
484
|
+
leftHasCadence: boolean;
|
|
485
|
+
rightHasCadence: boolean;
|
|
486
|
+
/** An independently scoped administration modifier without an invented cadence. */
|
|
487
|
+
rightHasAdministrationAdjunct?: boolean;
|
|
488
|
+
leftHasCourseDuration: boolean;
|
|
489
|
+
rightHasCourseDuration: boolean;
|
|
490
|
+
leftHasPrn: boolean;
|
|
491
|
+
rightHasPrn: boolean;
|
|
492
|
+
leftHasFrontedSchedule: boolean;
|
|
493
|
+
leftHasFrontedPrn: boolean;
|
|
494
|
+
rightHasTrailingSchedule: boolean;
|
|
495
|
+
rightHasTrailingCourseDuration: boolean;
|
|
496
|
+
rightHasTrailingPrn: boolean;
|
|
497
|
+
/** A typed, exact trailing clinical predicate/exclusion whose mother scope is unresolved. */
|
|
498
|
+
rightHasTrailingSafetyGuard: boolean;
|
|
499
|
+
}
|
|
500
|
+
/** Typed facts for a terminal negative instruction scoped over one regimen. */
|
|
501
|
+
export interface TrailingInstructionScopeFacts {
|
|
502
|
+
/** HPSG parsed a local negative action after the terminal semicolon. */
|
|
503
|
+
localNegativeAction: boolean;
|
|
504
|
+
/** The terminal action is separated from the administration by grammar evidence. */
|
|
505
|
+
semicolonDelimited: boolean;
|
|
506
|
+
/** Segment relations connect this recipient to the terminal donor. */
|
|
507
|
+
related: boolean;
|
|
508
|
+
/** Route identity is shared with the terminal administration. */
|
|
509
|
+
sameRoute: boolean;
|
|
510
|
+
/** Missing methods are compatible; two explicit methods must agree. */
|
|
511
|
+
compatibleMethod: boolean;
|
|
512
|
+
relationPath: readonly BoundaryRelation[];
|
|
513
|
+
}
|
|
514
|
+
export type RegimenSemanticOperation = 'share-trailing-cadence' | 'share-trailing-adjuncts' | 'share-trailing-course-duration' | 'share-trailing-instruction' | 'share-leading-adjuncts' | 'preserve-disjunctive-dosages' | 'inherit-event-timing-administration' | 'inherit-event-timing-and-share-trailing-course-duration' | 'inherit-administration-head' | 'inherit-administration-head-and-share-trailing-course-duration' | 'preserve-ambiguous-shared-guard';
|
|
515
|
+
export interface RegimenSemanticConstruction {
|
|
516
|
+
id: string;
|
|
517
|
+
priority: number;
|
|
518
|
+
operation: RegimenSemanticOperation;
|
|
519
|
+
}
|
|
520
|
+
export interface RegimenSemanticSelection {
|
|
521
|
+
construction: RegimenSemanticConstruction;
|
|
522
|
+
evidence: Evidence[];
|
|
523
|
+
}
|
|
@@ -44,5 +44,20 @@ export declare function featureAtom(value: unknown, type?: HpsgFeatureAtom["type
|
|
|
44
44
|
export declare function validateFeatureStructureShallow(value: HpsgFeatureNode, typeSystem: HpsgTypeSystem, path?: string): HpsgFeatureValidationIssue[];
|
|
45
45
|
export declare function validateFeatureStructure(value: HpsgFeatureValue, typeSystem: HpsgTypeSystem, path?: string, visited?: Set<HpsgFeatureNode>): HpsgFeatureValidationIssue[];
|
|
46
46
|
export declare function unifyFeatureStructures(left: HpsgFeatureValue, right: HpsgFeatureValue, typeSystem: HpsgTypeSystem): HpsgUnificationResult;
|
|
47
|
-
|
|
47
|
+
/** A structured diagnostic view, with explicit references for reentrant nodes. */
|
|
48
|
+
export type CanonicalFeatureView = {
|
|
49
|
+
atom: string;
|
|
50
|
+
value: unknown;
|
|
51
|
+
} | {
|
|
52
|
+
ref: number;
|
|
53
|
+
} | {
|
|
54
|
+
id: number;
|
|
55
|
+
type: string;
|
|
56
|
+
features: Record<string, CanonicalFeatureView>;
|
|
57
|
+
};
|
|
58
|
+
/** Export an inspectable graph, not a serialized string. Consumers that need a
|
|
59
|
+
* wire/log format can encode it at their own I/O boundary.
|
|
60
|
+
* @param value Feature graph to inspect outside the unifier.
|
|
61
|
+
*/
|
|
62
|
+
export declare function canonicalFeatureStructure(value: HpsgFeatureValue): CanonicalFeatureView;
|
|
48
63
|
export declare const HPSG_TYPE_SYSTEM: HpsgTypeSystem;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { HpsgSign, HpsgSynsem } from "./signature";
|
|
1
|
+
import { HpsgSign, HpsgInstructionFeature, HpsgSynsem } from "./signature";
|
|
2
2
|
import { RouteCode } from "../types";
|
|
3
3
|
export interface HpsgUnificationContext {
|
|
4
4
|
normalizeSiteText(text: string): string;
|
|
5
5
|
isCompatibleRouteRefinement(current: RouteCode | undefined, next: RouteCode): boolean;
|
|
6
|
+
sourceText?(start: number, end: number): string;
|
|
6
7
|
}
|
|
8
|
+
/** Keep separately selected occurrences while retaining unframed instruction deduplication. */
|
|
9
|
+
export declare function sameInstructionSourceOccurrence(left: HpsgInstructionFeature, right: HpsgInstructionFeature): boolean;
|
|
7
10
|
export declare function unifySynsem(left: HpsgSynsem, right: HpsgSynsem, context: HpsgUnificationContext): HpsgSynsem | undefined;
|
|
8
11
|
export declare function combineSigns(left: HpsgSign, right: HpsgSign, context: HpsgUnificationContext, rule: string): HpsgSign | undefined;
|
package/dist/i18n.d.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CourseLanguage } from "./localization";
|
|
2
|
+
import { ENGLISH_CLAUSE_TIMING } from "./locales/course/en";
|
|
3
|
+
export type { CourseLanguage } from "./localization";
|
|
4
|
+
import { BodySiteDefinition, CanonicalDoseExpr, CanonicalSigClause, type MedicationInstructionActionDefinition, type MedicationCondition } from "./types";
|
|
5
|
+
import { type TimingSummaryOptions } from "./timing-summary";
|
|
6
|
+
/** Compose the existing typed guard with its selected administration text. */
|
|
7
|
+
export declare function appendClinicalConditionText(text: string, condition: MedicationCondition, words: CourseLanguage): string;
|
|
2
8
|
export interface SigFormatContext {
|
|
3
9
|
readonly style: "short" | "long";
|
|
4
10
|
readonly clause: CanonicalSigClause;
|
|
5
11
|
readonly defaultText: string;
|
|
12
|
+
readonly course?: CourseLanguage;
|
|
6
13
|
readonly groupMealTimingsByRelation: boolean;
|
|
7
14
|
readonly includeTimesPerDaySummary: boolean;
|
|
8
15
|
readonly realizationMode: "normalized" | "roundtrip";
|
|
9
16
|
readonly sitePlacement: "natural" | "trailing";
|
|
17
|
+
readonly instructionActionMap?: TimingSummaryOptions["instructionActionMap"];
|
|
18
|
+
readonly resolvedMethod?: MedicationInstructionActionDefinition;
|
|
10
19
|
formatDefault(style: "short" | "long"): string;
|
|
11
20
|
}
|
|
12
21
|
export interface SigShortContext extends SigFormatContext {
|
|
@@ -15,21 +24,50 @@ export interface SigShortContext extends SigFormatContext {
|
|
|
15
24
|
export interface SigLongContext extends SigFormatContext {
|
|
16
25
|
readonly style: "long";
|
|
17
26
|
}
|
|
27
|
+
/** Dose amount scope is independent of whether the compact clause has one
|
|
28
|
+
* scalar dose. Native multi/role-bearing amounts retain this target scope. */
|
|
29
|
+
export interface SigDoseScope {
|
|
30
|
+
targetCount: number;
|
|
31
|
+
site?: BodySiteDefinition;
|
|
32
|
+
}
|
|
18
33
|
export interface SigLocalization {
|
|
19
34
|
readonly locale: string;
|
|
35
|
+
/** Optional language-pack facet for whole-course text. Clinical facts stay
|
|
36
|
+
* in canonical code; adding a language never edits the course algorithm. */
|
|
37
|
+
readonly course?: CourseLanguage;
|
|
38
|
+
formatDose?(dose: CanonicalDoseExpr | string, style: "short" | "long", scope?: SigDoseScope): string | undefined;
|
|
20
39
|
formatShort?(context: SigShortContext): string;
|
|
40
|
+
/** Overrides the complete clause; the callback owns its returned wording.
|
|
41
|
+
* Context and default renderings still describe the full clause. */
|
|
21
42
|
formatLong?(context: SigLongContext): string;
|
|
22
43
|
}
|
|
23
44
|
export interface SigLocalizationConfig extends Partial<Omit<SigLocalization, "locale">> {
|
|
24
45
|
locale?: string;
|
|
25
46
|
inherit?: string;
|
|
26
47
|
}
|
|
48
|
+
interface NativeClauseRendering {
|
|
49
|
+
long?: typeof formatLongThai;
|
|
50
|
+
short?: typeof formatShortThai;
|
|
51
|
+
timing: typeof ENGLISH_CLAUSE_TIMING;
|
|
52
|
+
}
|
|
27
53
|
export declare function registerSigLocalization(localization: SigLocalization): void;
|
|
28
54
|
export declare function getRegisteredSigLocalizations(): SigLocalization[];
|
|
55
|
+
export declare function resolveNativeClauseRendering(localization?: SigLocalization): NativeClauseRendering;
|
|
29
56
|
export declare function resolveSigLocalization(locale?: string, config?: SigLocalizationConfig): SigLocalization | undefined;
|
|
57
|
+
export declare function hasClauseFormatOverride(localization: SigLocalization | undefined, style: "short" | "long"): boolean;
|
|
58
|
+
/** Resolve the course facet once at a public formatting boundary. Reuse the
|
|
59
|
+
* existing registry and inheritance contract; no new pack registry or parser. */
|
|
60
|
+
export declare function resolveCourseLanguage(locale?: string, config?: SigLocalizationConfig, resolved?: SigLocalization): CourseLanguage;
|
|
30
61
|
export type SigTranslation = SigLocalization;
|
|
31
62
|
export type SigTranslationConfig = SigLocalizationConfig;
|
|
32
63
|
export declare const registerSigTranslation: typeof registerSigLocalization;
|
|
33
64
|
export declare const getRegisteredSigTranslations: typeof getRegisteredSigLocalizations;
|
|
34
65
|
export declare function resolveSigTranslation(locale?: string, config?: SigTranslationConfig): SigTranslation | undefined;
|
|
66
|
+
export declare const DAY_NAMES_THAI: Record<string, string>;
|
|
35
67
|
export declare const THAI_SITE_TRANSLATIONS: Record<string, string>;
|
|
68
|
+
export declare function joinWithAndThai(parts: string[]): string;
|
|
69
|
+
declare function formatShortThai(clause: CanonicalSigClause, words?: CourseLanguage, resolvedMethod?: MedicationInstructionActionDefinition): string;
|
|
70
|
+
declare function formatLongThai(clause: CanonicalSigClause, options?: TimingSummaryOptions, words?: CourseLanguage, resolvedMethod?: MedicationInstructionActionDefinition, authoredPrimary?: string, deferredDirections?: {
|
|
71
|
+
text?: string;
|
|
72
|
+
current?: string;
|
|
73
|
+
}): string;
|