ezmedicationinput 0.1.54 → 0.1.56
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/advice.d.ts +1 -0
- package/dist/body-site-grammar.d.ts +3 -1
- package/dist/event-timing-expression.d.ts +8 -0
- package/dist/fhir.d.ts +10 -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 +70 -7
- 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 +2 -0
- package/dist/hpsg/rules/instruction-rules.d.ts +1 -0
- package/dist/hpsg/rules/prn-rules.d.ts +11 -0
- package/dist/hpsg/rules/timing-rules.d.ts +28 -0
- package/dist/hpsg/segmenter.d.ts +2 -1
- package/dist/hpsg/signature.d.ts +54 -2
- package/dist/hpsg/type-system.d.ts +48 -0
- package/dist/i18n.d.ts +2 -0
- package/dist/index.cjs +25759 -9747
- package/dist/index.d.ts +11 -0
- package/dist/index.js +25720 -9744
- 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 +23 -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 +16 -0
- package/dist/prn.d.ts +1 -0
- package/dist/relation-terminology.d.ts +101 -0
- package/dist/stable-structure.d.ts +1 -0
- package/dist/symptom-terminology.d.ts +12 -0
- package/dist/timing-summary.d.ts +2 -0
- package/dist/types.d.ts +284 -4
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -108,11 +108,15 @@ result.fhir.additionalInstruction;
|
|
|
108
108
|
// → [{ text: "Do not exceed 6 tablets daily" }]
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
Default symptom vocabulary is vendored declaratively in `symptom-terminology.json`.
|
|
112
|
+
It currently contains 100 exact coded symptom concepts with Thai/English surfaces;
|
|
113
|
+
HPSG PRN/condition recognition, coding, localization, and `suggestSig` consume the
|
|
114
|
+
same derived terminology index. Applications can add shared symptom vocabulary at
|
|
115
|
+
runtime through `symptomMap`:
|
|
112
116
|
|
|
113
117
|
```ts
|
|
114
118
|
parseSig(input, {
|
|
115
|
-
|
|
119
|
+
symptomMap: {
|
|
116
120
|
migraine: {
|
|
117
121
|
text: "Migraine",
|
|
118
122
|
coding: {
|
|
@@ -127,6 +131,12 @@ parseSig(input, {
|
|
|
127
131
|
});
|
|
128
132
|
```
|
|
129
133
|
|
|
134
|
+
`prnReasonMap` remains supported as a backward-compatible PRN-only override and
|
|
135
|
+
takes precedence over `symptomMap` for the same surface. Public helpers
|
|
136
|
+
`listSymptomDefinitions`, `resolveSymptomDefinition`, and
|
|
137
|
+
`findSymptomDefinitionByCoding` expose the default terminology without coupling
|
|
138
|
+
callers to PRN internals.
|
|
139
|
+
|
|
130
140
|
Use `{reason}` in the sig string (e.g. `prn {migraine}`) to force a lookup even
|
|
131
141
|
when a direct match exists. Additional instructions are sourced from a built-in
|
|
132
142
|
set of SNOMED CT concepts under *419492006 – Additional dosage instructions* and
|
|
@@ -163,6 +173,10 @@ const shortFromFhir = formatSigBatch(batch.items.map((item) => item.fhir), "shor
|
|
|
163
173
|
Formatting options:
|
|
164
174
|
|
|
165
175
|
- `locale`: selects the registered localization, such as `"en"` or `"th"`.
|
|
176
|
+
- `realizationMode`: defaults to `"normalized"`. Use `"roundtrip"` when the
|
|
177
|
+
generated text is expected to be parsed again: it chooses attachment-safe
|
|
178
|
+
wording, preserves source-faithful clinician text when the semantic graph has
|
|
179
|
+
same-locale provenance, and realizes typed graph semantics across locales.
|
|
166
180
|
- `i18n`: overrides or augments the registered localization callbacks.
|
|
167
181
|
- `groupMealTimingsByRelation`: compacts repeated meal relation phrases when all
|
|
168
182
|
meal anchors share the same relation.
|
|
@@ -187,38 +201,110 @@ Notes:
|
|
|
187
201
|
|
|
188
202
|
### Sig (directions) suggestions
|
|
189
203
|
|
|
190
|
-
Use `suggestSig` to drive autocomplete
|
|
191
|
-
|
|
192
|
-
of
|
|
193
|
-
a `limit` and custom PRN
|
|
204
|
+
Use `suggestSig` to drive autocomplete while the clinician is typing medication
|
|
205
|
+
directions. Completion is bounded and shares the parser's terminology and locale
|
|
206
|
+
lexicons instead of generating a Cartesian product of canned sig strings. It
|
|
207
|
+
accepts the same `ParseOptions` context plus a `limit` and optional custom PRN
|
|
208
|
+
reasons.
|
|
194
209
|
|
|
195
210
|
```ts
|
|
196
211
|
import { suggestSig } from "ezmedicationinput";
|
|
197
212
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
context: { dosageForm: "ophthalmic solution" },
|
|
201
|
-
});
|
|
213
|
+
suggestSig("1 tab po q", { limit: 5 });
|
|
214
|
+
// → ["1 tab po qd", "1 tab po qid", "1 tab po q1h", ...]
|
|
202
215
|
|
|
203
|
-
|
|
216
|
+
suggestSig("ทา", { locale: "th", limit: 5 });
|
|
217
|
+
// → ["ทา", "ทา วันละครั้ง"]
|
|
204
218
|
```
|
|
205
219
|
|
|
206
220
|
Highlights:
|
|
207
221
|
|
|
208
|
-
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
-
|
|
219
|
-
|
|
220
|
-
-
|
|
221
|
-
|
|
222
|
+
- Complete semantic prefixes are recognized through the live parser/HPSG path
|
|
223
|
+
and short-circuit instead of searching an unrelated suggestion universe.
|
|
224
|
+
- Action, route, unit, body-site, PRN, frequency, and timing extensions supplied
|
|
225
|
+
through `ParseOptions` participate in autocomplete where applicable; parser
|
|
226
|
+
terminology remains the source of truth.
|
|
227
|
+
- Thai suggestions use the parser-owned Thai lexicon, including Thai defaults,
|
|
228
|
+
action prefixes, grammar words, and PRN symptom tails rather than falling back
|
|
229
|
+
to English shorthand.
|
|
230
|
+
- Unit, route, timing, clock, PRN, and meal-dash partials use bounded specialized
|
|
231
|
+
completion paths; unknown prefixes cheaply return no suggestions.
|
|
232
|
+
- Suggested representative EN/TH completions are regression-tested by reparsing
|
|
233
|
+
them through the real parser with no leftover text.
|
|
234
|
+
- `npm run bench:suggest` reports latency, throughput, and retained/peak memory
|
|
235
|
+
without imposing timing-sensitive test thresholds.
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
## Formal HPSG substrate
|
|
239
|
+
|
|
240
|
+
The HPSG core now uses an actual typed-feature-structure runtime on the live parse path. Signs participate in a subtype hierarchy, feature appropriateness is validated, general feature unification preserves reentrancy/structure sharing, and phrase mothers unify daughter `SYNSEM` structures rather than relying only on flat TypeScript object merging. Structural AVMs are immutable and memoized because the medication grammar reuses a small number of SYNSEM shapes heavily.
|
|
241
|
+
|
|
242
|
+
This is intentionally an incremental formalization rather than a claim that the entire grammar is already equivalent to a DELPH-IN grammar: domain leaf-value compatibility (for example route refinement and medication-specific schedule semantics) is still partly implemented in specialized constraint functions, and the semantic representation is the package medication instruction graph rather than MRS. The typed substrate allows those remaining constraints to migrate into declarative feature logic without rewriting the working parser.
|
|
243
|
+
|
|
244
|
+
## Adversarial real-world parsing and HPSG performance
|
|
245
|
+
|
|
246
|
+
The repository includes a 50-case TH/EN real-world torture corpus covering oral liquids, mouth rinses, topical workflows, vaginal/rectal applicators, inhalers, nasal sprays, eye/ear drops, patches, insulin/device steps, conditional instructions, and colloquial Thai sequences. A second 28-case weird-clinician corpus stresses eye-drop event sets, safety-condition scope, 0–2/day symptom-adjusted use, ranged leave-on/rinse workflows, patch application, abbreviations, punctuation variants, and TH/EN code-switching. Together they provide 78 adversarial directions plus dedicated FHIR round-trip invariants. The tests assert semantic contracts (dose/range, route, site, method, timing, procedural actions, and selected forbidden false interpretations), not merely that parsing succeeds.
|
|
247
|
+
|
|
248
|
+
`npm run bench:torture` preserves the original 50-case apples-to-apples performance workload. `npm run bench:adversarial` runs the combined 78-case parser corpus. `npm run bench:roundtrip` measures the 87-case EN/TH/cross-language parse -> human realization -> reparse workload. The parse benchmarks report mean/p50/p95/p99 latency, throughput, and the slowest cases; they are intentionally benchmarks rather than timing-sensitive unit tests.
|
|
249
|
+
|
|
250
|
+
The HPSG chart uses packed semantic state, an indexed agenda, and a compatible semantic cover across opaque gaps. Procedural constructions use typed local arguments so local instructions such as `wash hands`, `wait 30 minutes`, or inhaler priming do not overwrite the medication's global site, schedule, route, or dose. Additional typed constructions now distinguish safety-condition advice from PRN, symptom-adjusted use from fixed schedules, and the first workflow action (the possible administration head) from later dependent procedure actions. Separated and compact frequency ranges are grammatical schedule constituents, so `0 to 2 times per day` cannot be stolen by the dose grammar.
|
|
251
|
+
|
|
252
|
+
FHIR cannot represent zero as `Timing.repeat.frequency` because the primitive is positive; a package-owned extension preserves an explicit lower bound of zero while `frequencyMax`, `period`, and `periodUnit` remain standard fields:
|
|
253
|
+
|
|
254
|
+
`https://solublelabs.com/fhir/StructureDefinition/medication-timing-frequency-min`
|
|
255
|
+
|
|
256
|
+
## Procedural instruction semantics and opaque-span enrichment
|
|
257
|
+
|
|
258
|
+
Complex directions may contain preparation/application workflow that does not fit
|
|
259
|
+
FHIR `Dosage` fields cleanly. `ParseResult.meta.normalized.instructionGraph`
|
|
260
|
+
retains that meaning as ordered actions, typed arguments, relations, source
|
|
261
|
+
spans, provenance, and semantic coverage. The same graph is carried through a
|
|
262
|
+
FHIR extension while standard `Dosage.text`, `patientInstruction`, and
|
|
263
|
+
`additionalInstruction` remain interoperable fallbacks.
|
|
264
|
+
|
|
265
|
+
The built-in procedural action and argument vocabularies are declarative and can
|
|
266
|
+
be extended with `instructionActionMap` / `instructionConceptMap`, including
|
|
267
|
+
institution-owned coding systems. Exact external mappings (such as SNOMED CT)
|
|
268
|
+
are additive rather than approximate.
|
|
269
|
+
|
|
270
|
+
For opaque text that deterministic parsing deliberately leaves uninterpreted,
|
|
271
|
+
applications may optionally register `instructionSemanticResolvers`. Resolver
|
|
272
|
+
output is a proposal, not trusted parser state: ezmedicationinput revalidates
|
|
273
|
+
source ranges, procedural action terminology, argument concepts/body sites, and
|
|
274
|
+
units before accepting an action. Invalid proposals leave the source opaque.
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
const result = await parseSigAsync("shake bottle, then croon a song", {
|
|
278
|
+
instructionActionMap: {
|
|
279
|
+
sing: {
|
|
280
|
+
code: "sing",
|
|
281
|
+
semanticClass: "activity",
|
|
282
|
+
display: "Sing",
|
|
283
|
+
i18n: { th: "ร้องเพลง" },
|
|
284
|
+
procedural: true
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
instructionSemanticResolvers: async ({ sourceText }) => {
|
|
288
|
+
if (sourceText !== "croon a song") return undefined;
|
|
289
|
+
return {
|
|
290
|
+
actions: [
|
|
291
|
+
{
|
|
292
|
+
action: "sing",
|
|
293
|
+
range: { start: 0, end: sourceText.length },
|
|
294
|
+
confidence: 0.91
|
|
295
|
+
}
|
|
296
|
+
]
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Resolver ranges are relative to the supplied opaque `sourceText`. Accepted
|
|
303
|
+
actions are marked `origin: "semantic-resolver"`; optional resolver confidence
|
|
304
|
+
is preserved separately from graph `coverage`, so learned semantics are never
|
|
305
|
+
indistinguishable from grammar-derived semantics. A resolver failure preserves
|
|
306
|
+
the original text and adds a warning. Synchronous resolvers may be used with
|
|
307
|
+
`parseSig`; Promise-returning resolvers require `parseSigAsync`.
|
|
222
308
|
|
|
223
309
|
## Dictionaries
|
|
224
310
|
|
package/dist/advice.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface AdviceParseContext {
|
|
|
11
11
|
defaultForce?: AdviceForce;
|
|
12
12
|
allowFreeTextFallback?: boolean;
|
|
13
13
|
}
|
|
14
|
+
export declare function realizeAdviceFramesText(frames: AdviceFrame[], locale?: string): string | undefined;
|
|
14
15
|
export declare function parseAdditionalInstructions(sourceText: string, span: TextRange, context?: AdviceParseContext): ParsedAdditionalInstruction[];
|
|
15
16
|
export declare function findAdditionalInstructionDefinitionByCoding(system: string, code: string): AdditionalInstructionDefinition | undefined;
|
|
16
17
|
export declare const __test__: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BodySiteDefinition, BodySiteSpatialRelation, FhirCoding } from "./types";
|
|
2
|
+
import type { BodySiteLocativeRelation } from "./relation-terminology";
|
|
2
3
|
export type BodySiteGrammarKind = "nominal" | "partitive" | "locative";
|
|
3
|
-
export type BodySiteLocativeRelation
|
|
4
|
+
export type { BodySiteLocativeRelation };
|
|
4
5
|
export interface BodySiteNominalFeatures {
|
|
5
6
|
kind: "nominal";
|
|
6
7
|
text: string;
|
|
@@ -34,6 +35,7 @@ export interface ResolvedBodySitePhrase {
|
|
|
34
35
|
}
|
|
35
36
|
export interface BodySitePhraseContext {
|
|
36
37
|
bodySiteContext?: string;
|
|
38
|
+
allowTerminalModifierInheritance?: boolean;
|
|
37
39
|
}
|
|
38
40
|
export declare function lookupBodySiteDefinition(map: Record<string, BodySiteDefinition> | undefined, canonical: string): BodySiteDefinition | undefined;
|
|
39
41
|
export declare function resolveBodySitePhrase(text: string, customSiteMap?: Record<string, BodySiteDefinition>, context?: BodySitePhraseContext): ResolvedBodySitePhrase | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EventTiming } from "./types";
|
|
2
|
+
export interface EventTimingExpression {
|
|
3
|
+
timing: EventTiming;
|
|
4
|
+
length: number;
|
|
5
|
+
}
|
|
6
|
+
export declare const MAX_EVENT_TIMING_EXPRESSION_PARTS: number;
|
|
7
|
+
/** Resolve the most specific canonical event expression at `start`. */
|
|
8
|
+
export declare function resolveEventTimingExpression(parts: readonly string[], start?: number, endExclusive?: number): EventTimingExpression | undefined;
|
package/dist/fhir.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { ParserState } from "./parser-state";
|
|
2
|
-
import { CanonicalSigClause, FhirDosage } from "./types";
|
|
2
|
+
import { CanonicalOccurrenceCapExpr, CanonicalSigClause, FhirDosage, FhirTimingRepeat } from "./types";
|
|
3
|
+
export declare const TIMING_FREQUENCY_MIN_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-frequency-min";
|
|
4
|
+
export declare const TIMING_OFFSET_MIN_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-offset-min";
|
|
5
|
+
export declare const TIMING_OFFSET_MAX_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-offset-max";
|
|
6
|
+
export declare const TIMING_OFFSET_EXACT_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-offset-exact";
|
|
7
|
+
export declare const TIMING_ACTIVITY_WINDOW_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-activity-window";
|
|
8
|
+
export declare const TIMING_OCCURRENCE_CAP_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-timing-occurrence-cap";
|
|
9
|
+
export declare const PRN_TRIGGER_PHASE_EXTENSION_URL = "https://solublelabs.com/fhir/StructureDefinition/medication-prn-trigger-phase";
|
|
10
|
+
export declare function getExactTimingOffsetMinutes(repeat: FhirTimingRepeat | undefined): number | undefined;
|
|
11
|
+
export declare function getTimingOccurrenceCap(repeat: FhirTimingRepeat | undefined): CanonicalOccurrenceCapExpr | undefined;
|
|
3
12
|
export interface FhirProjectionOptions {
|
|
4
13
|
/**
|
|
5
14
|
* Defaults to true. When true, structured spatial body-site phrases such as
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HpsgConstruction, HpsgSign, HpsgType } from "./signature";
|
|
2
|
+
export interface HpsgConstructionSelection {
|
|
3
|
+
motherType: HpsgType;
|
|
4
|
+
construction: HpsgConstruction;
|
|
5
|
+
}
|
|
6
|
+
export declare function selectHpsgConstruction(left: HpsgSign, right: HpsgSign): HpsgConstructionSelection | undefined;
|
package/dist/hpsg/defaults.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export interface HpsgDefaultConstraintDeps {
|
|
|
5
5
|
}
|
|
6
6
|
export declare function applyHpsgDefaultConstraints(state: ParserState, tokens: readonly {
|
|
7
7
|
lower: string;
|
|
8
|
+
canonical?: string;
|
|
8
9
|
index: number;
|
|
9
10
|
}[], options: ParseOptions | undefined, deps: HpsgDefaultConstraintDeps): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { HpsgSynsem, HpsgType } from "./signature";
|
|
2
|
+
import { type HpsgFeatureNode } from "./type-system";
|
|
3
|
+
export declare function synsemFeatureStructure(synsem: HpsgSynsem): HpsgFeatureNode;
|
|
4
|
+
export declare function signFeatureStructure(type: HpsgType, synsem: HpsgSynsem): HpsgFeatureNode;
|
|
5
|
+
export declare function combineSignFeatureStructures(left: HpsgFeatureNode, right: HpsgFeatureNode, motherType: HpsgType, headSide?: "left" | "right", synsemOverride?: HpsgSynsem): HpsgFeatureNode | undefined;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AdviceModality, AdvicePolarity, EventTiming } from "../types";
|
|
2
|
+
export { ACTION_SEQUENCE_MARKERS } from "../relation-terminology";
|
|
2
3
|
type MealRelation = "before" | "after" | "with";
|
|
3
4
|
type MealTimingByRelation = Map<MealRelation, Map<EventTiming, EventTiming>>;
|
|
4
5
|
type BodySiteFeatureKind = "nominal" | "partitive" | "locative";
|
|
6
|
+
type ContextualPrnReasonLead = {
|
|
7
|
+
parts: string[];
|
|
8
|
+
canonical: string;
|
|
9
|
+
requiresKnownReason?: boolean;
|
|
10
|
+
};
|
|
5
11
|
type CompoundDoseUnit = {
|
|
6
12
|
head: string;
|
|
7
13
|
tails: string[];
|
|
@@ -9,16 +15,19 @@ type CompoundDoseUnit = {
|
|
|
9
15
|
requiresSiteContext?: boolean;
|
|
10
16
|
unit: string;
|
|
11
17
|
};
|
|
18
|
+
type InstructionQuantityUnitLabel = {
|
|
19
|
+
th: string;
|
|
20
|
+
enOne: string;
|
|
21
|
+
enOther: string;
|
|
22
|
+
};
|
|
12
23
|
export declare const SITE_ANCHORS: Set<string>;
|
|
13
24
|
export declare const SITE_SELF_DISPLAY_ANCHORS: Set<string>;
|
|
14
25
|
export declare const SITE_FILLERS: Set<string>;
|
|
15
|
-
export declare const BODY_SITE_LOCATIVE_RELATIONS: Set<string>;
|
|
16
|
-
export declare const BODY_SITE_LOCATIVE_RENDER_PREPOSITIONS: Map<string, string>;
|
|
17
|
-
export declare const BODY_SITE_SPATIAL_RELATION_CODINGS: Map<string, FhirCoding>;
|
|
18
26
|
export declare const BODY_SITE_PARTITIVE_HEADS: Set<string>;
|
|
19
27
|
export declare const BODY_SITE_PARTITIVE_MODIFIERS: Set<string>;
|
|
20
28
|
export declare const BODY_SITE_PARTITIVE_CONNECTORS: Set<string>;
|
|
21
29
|
export declare const BODY_SITE_BARE_NOMINAL_PREFIXES: Set<string>;
|
|
30
|
+
export declare const BODY_SITE_ATTRIBUTIVE_MODIFIERS: Set<string>;
|
|
22
31
|
export declare const OTIC_SITE_WORDS: Set<string>;
|
|
23
32
|
export declare const OPHTHALMIC_SITE_WORDS: Set<string>;
|
|
24
33
|
export declare const NASAL_SITE_WORDS: Set<string>;
|
|
@@ -26,15 +35,25 @@ export declare const BODY_SITE_ADJECTIVE_SUFFIXES: readonly string[];
|
|
|
26
35
|
export declare const BODY_SITE_DISPLAY_PENALTY_WORDS: Set<string>;
|
|
27
36
|
export declare const BODY_SITE_FEATURE_SCORE_BONUS: Map<BodySiteFeatureKind, number>;
|
|
28
37
|
export declare const CONNECTORS: Set<string>;
|
|
38
|
+
export declare const THAI_METHOD_AUXILIARY_VERBS: Set<string>;
|
|
39
|
+
export declare const COORDINATED_NOUN_METHOD_VERBS: Set<string>;
|
|
40
|
+
export declare const METHOD_NOUN_LEFT_CONTEXT: Map<string, Set<string>>;
|
|
41
|
+
export declare const PRODUCT_EXTERNAL_MODIFIERS: Set<string>;
|
|
29
42
|
export declare const ROUTE_SITE_PREPOSITIONS: Set<string>;
|
|
30
43
|
export declare const SITE_DISPLAY_FILLERS: Set<string>;
|
|
31
44
|
export declare const SITE_MULTIPLICITY_WORDS: Set<string>;
|
|
32
45
|
export declare const NON_SITE_ANCHORED_PHRASES: Set<string>;
|
|
33
|
-
export declare const EXTERNAL_SITE_LOCATIVE_PREFIXES:
|
|
46
|
+
export declare const EXTERNAL_SITE_LOCATIVE_PREFIXES: ReadonlySet<string>;
|
|
34
47
|
export declare const ROUTE_BLOCKED_BY_FOLLOWING_PARTITIVE_HEADS: Set<string>;
|
|
35
48
|
export declare const PRN_LEADS: Set<string>;
|
|
49
|
+
export declare const SYMPTOM_ONSET_PREFIX_PATTERNS: string[][];
|
|
50
|
+
export declare const SYMPTOM_ONSET_SUFFIX_PATTERNS: {
|
|
51
|
+
lead: string[];
|
|
52
|
+
suffix: string[];
|
|
53
|
+
}[];
|
|
36
54
|
export declare const PRN_REASON_LEAD_INS: Set<string>;
|
|
37
55
|
export declare const PRN_STANDALONE_REASON_LEADS: Set<string>;
|
|
56
|
+
export declare const PRN_CONTEXTUAL_REASON_LEADS: ContextualPrnReasonLead[];
|
|
38
57
|
export declare const PRN_REASON_MULTIWORD_LEAD_INS: Set<string>;
|
|
39
58
|
export declare const PRN_REASON_SITE_CONNECTORS: Set<string>;
|
|
40
59
|
export declare const PRN_REASON_COORDINATORS: Set<string>;
|
|
@@ -46,6 +65,7 @@ export declare const PRN_COMPACT_REASON_SEPARATORS: Set<string>;
|
|
|
46
65
|
export declare const SITE_ROUTE_HINTS_ALLOWED_IN_GRAMMAR: Set<import("../types").SNOMEDCTRouteCodes>;
|
|
47
66
|
export declare const PRODUCT_METHOD_TEXT: Record<string, Partial<Record<string, string>>>;
|
|
48
67
|
export declare const PRODUCT_METHOD_THAI: Record<string, string>;
|
|
68
|
+
export declare const PRODUCT_FORM_MODIFIERS: Set<string>;
|
|
49
69
|
export declare const COMPOUND_DOSE_UNITS: CompoundDoseUnit[];
|
|
50
70
|
export declare const IMPLICIT_SINGLE_DOSE_UNITS: Set<string>;
|
|
51
71
|
export declare const PERCENT_BODY_AREA_UNITS: Map<string, string>;
|
|
@@ -59,6 +79,14 @@ export declare const COMPACT_LIST_SEPARATORS: Set<string>;
|
|
|
59
79
|
export declare const EVERY_INTERVAL_TOKENS_DATA: Set<string>;
|
|
60
80
|
export declare const COUNT_MARKER_TOKENS_DATA: Set<string>;
|
|
61
81
|
export declare const COUNT_CONNECTOR_WORDS_DATA: Set<string>;
|
|
82
|
+
export declare const MAXIMUM_COUNT_LEAD_TOKENS: Set<string>;
|
|
83
|
+
export declare const MAXIMUM_COUNT_LEAD_SEQUENCES: string[][];
|
|
84
|
+
export declare const OCCURRENCE_COUNT_WORDS: Set<string>;
|
|
85
|
+
export declare const OCCURRENCE_CAP_PERIOD_PHRASES: {
|
|
86
|
+
parts: string[];
|
|
87
|
+
period: number;
|
|
88
|
+
periodUnit: string;
|
|
89
|
+
}[];
|
|
62
90
|
export declare const FREQUENCY_SIMPLE_WORDS_DATA: Record<string, number>;
|
|
63
91
|
export declare const FREQUENCY_NUMBER_WORDS_DATA: Record<string, number>;
|
|
64
92
|
export declare const FREQUENCY_TIMES_WORDS_DATA: Set<string>;
|
|
@@ -83,17 +111,52 @@ export declare const WAKE_EVENT_ALIASES: Set<string>;
|
|
|
83
111
|
export declare const FOOD_EVENT_ALIASES: Set<string>;
|
|
84
112
|
export declare const DAY_RANGE_CONNECTORS: Set<string>;
|
|
85
113
|
export declare const RANGE_CONNECTORS: Set<string>;
|
|
86
|
-
export declare const DURATION_LEAD_TOKENS:
|
|
114
|
+
export declare const DURATION_LEAD_TOKENS: ReadonlySet<string>;
|
|
115
|
+
export declare const EVENT_OFFSET_MINIMUM_LEAD_SEQUENCES: string[][];
|
|
116
|
+
export declare const EVENT_OFFSET_MAXIMUM_LEAD_SEQUENCES: string[][];
|
|
117
|
+
export declare const EVENT_OFFSET_FRACTIONS: Map<string, number>;
|
|
118
|
+
export declare const EVENT_OFFSET_ARTICLES: Set<string>;
|
|
87
119
|
export declare const INSTRUCTION_LEADING_SEPARATORS: Set<string>;
|
|
88
120
|
export declare const INSTRUCTION_START_WORDS: Set<string>;
|
|
121
|
+
export declare const POSITIVE_DIRECTIVE_MARKERS: Set<string>;
|
|
122
|
+
export declare const ACTION_DIRECTIVE_PREFIXES: {
|
|
123
|
+
parts: readonly string[];
|
|
124
|
+
polarity: AdvicePolarity | undefined;
|
|
125
|
+
modality: AdviceModality | undefined;
|
|
126
|
+
}[];
|
|
127
|
+
export declare const ACTION_COORDINATION_CONNECTORS: Set<string>;
|
|
128
|
+
export declare const ACTION_SEQUENCE_RELATION_TOKENS: ReadonlySet<string>;
|
|
129
|
+
export declare const INSTRUCTION_DURATION_UNITS: Map<string, string>;
|
|
130
|
+
export declare const INSTRUCTION_DURATION_APPROXIMATION_LEADS: Set<string>;
|
|
131
|
+
export declare const INSTRUCTION_QUANTITY_UNIT_LABELS: Map<string, InstructionQuantityUnitLabel>;
|
|
132
|
+
export declare const FREE_TEXT_DIRECTIVE_STARTS: Set<string>;
|
|
133
|
+
export declare const CONDITIONAL_INSTRUCTION_EXCLUSIVE_LEADS: ReadonlySet<string>;
|
|
134
|
+
export declare const ALTERNATE_EVENT_CADENCES: {
|
|
135
|
+
parts: string[];
|
|
136
|
+
when: EventTiming;
|
|
137
|
+
period: number;
|
|
138
|
+
periodUnit: string;
|
|
139
|
+
}[];
|
|
140
|
+
export declare const ADMINISTRATION_WINDOW_INSTRUCTIONS: {
|
|
141
|
+
parts: string[];
|
|
142
|
+
text: string;
|
|
143
|
+
i18n: {
|
|
144
|
+
th: string;
|
|
145
|
+
} | undefined;
|
|
146
|
+
relation: "before" | "after" | undefined;
|
|
147
|
+
activity: string | undefined;
|
|
148
|
+
}[];
|
|
89
149
|
export declare const SITE_TRAILING_INSTRUCTION_WORDS: Set<string>;
|
|
90
150
|
export declare const WORKFLOW_CONTINUATION_LICENSES: Set<string>;
|
|
151
|
+
export declare const WORKFLOW_ACTION_RELATION_LEADS: ReadonlySet<string>;
|
|
91
152
|
export declare const AS_NEEDED_LEAD_PHRASES: Set<string>;
|
|
92
153
|
export declare const PRN_BREAKING_COORDINATORS: Set<string>;
|
|
154
|
+
export declare const SYMPTOM_ADJUSTMENT_LEADS: Set<string>;
|
|
155
|
+
export declare const SYMPTOM_ADJUSTMENT_CONNECTORS: Set<string>;
|
|
156
|
+
export declare const SYMPTOM_ADJUSTMENT_PATIENT_INSTRUCTION_LEADS: Set<string>;
|
|
93
157
|
export declare const EYE_SITE_ABBREVIATIONS: Set<string>;
|
|
94
158
|
export declare const NON_OCULAR_DOSE_UNITS: Set<string>;
|
|
95
159
|
export declare const OCULAR_ROUTE_CODES: Set<import("../types").SNOMEDCTRouteCodes>;
|
|
96
160
|
export declare const HARD_SEGMENT_BOUNDARY_TOKENS: Set<string>;
|
|
97
161
|
export declare const CLAUSE_LEAD_WORDS: Set<string>;
|
|
98
162
|
export declare const LATERAL_MODIFIER_WORDS: Set<string>;
|
|
99
|
-
export {};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { FhirCoding } from "../types";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Instill = "instill",
|
|
9
|
-
Spray = "spray",
|
|
10
|
-
Swallow = "swallow",
|
|
11
|
-
Wash = "wash"
|
|
12
|
-
}
|
|
1
|
+
import { FhirCoding, MedicationInstructionActionDefinition, ParseOptions, RouteCode } from "../types";
|
|
2
|
+
export type MethodAction = string;
|
|
3
|
+
declare function cloneMethodCoding(coding: FhirCoding | undefined): FhirCoding | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Compatibility indexes derived from the single declarative action terminology.
|
|
6
|
+
* New methods must be added to instruction-action-terminology, not here.
|
|
7
|
+
*/
|
|
13
8
|
export declare const METHOD_ACTION_BY_VERB: Record<string, MethodAction>;
|
|
14
|
-
export declare const METHOD_CODING_BY_ACTION: Record<
|
|
15
|
-
export declare
|
|
9
|
+
export declare const METHOD_CODING_BY_ACTION: Record<string, FhirCoding>;
|
|
10
|
+
export declare const METHOD_ACTIONS_WITHOUT_IMPLICIT_ROUTE: Set<string>;
|
|
11
|
+
export declare const METHOD_ROUTE_OVERRIDE_BY_VERB: Partial<Record<string, RouteCode>>;
|
|
12
|
+
export declare function resolveMedicationAdministrationMethod(surface: string, options?: ParseOptions): MedicationInstructionActionDefinition | undefined;
|
|
13
|
+
export declare function isMedicationAdministrationMethod(surface: string, options?: ParseOptions): boolean;
|
|
14
|
+
export declare function medicationAdministrationMethodCoding(surface: string, options?: ParseOptions): FhirCoding | undefined;
|
|
15
|
+
export { cloneMethodCoding };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type AdviceFrame } from "../types";
|
|
2
|
+
import type { HpsgClauseContext } from "./rule-context";
|
|
3
|
+
/**
|
|
4
|
+
* Parse procedural semantics once per ParserState and share the result across
|
|
5
|
+
* HPSG lexical constructions. Keeping this cache at the HPSG context layer
|
|
6
|
+
* avoids each rule family independently running the instruction parser.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getProceduralFrames(context: HpsgClauseContext): AdviceFrame[];
|
|
9
|
+
export type HpsgAttachmentClass = "administration" | "procedure";
|
|
10
|
+
export declare function sourceRangeAttachmentClass(context: HpsgClauseContext, start: number, end: number): HpsgAttachmentClass;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { HpsgClauseContext } from "../rule-context";
|
|
2
|
+
import { HpsgConditionFeature, HpsgLexicalRule } from "../signature";
|
|
3
|
+
export declare function conditionLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
4
|
+
export declare function getConditionFeatures(context: HpsgClauseContext): HpsgConditionFeature[];
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { HpsgClauseContext } from "../rule-context";
|
|
2
2
|
import { HpsgLexicalRule } from "../signature";
|
|
3
|
+
export declare function directiveMarkerLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
3
4
|
export declare function methodLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
4
5
|
export declare function routeLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
5
6
|
export declare function fillerLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
6
7
|
export declare function productLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
8
|
+
export declare function perTargetCountDoseRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
7
9
|
export declare function doseLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
8
10
|
export declare function connectorLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HpsgClauseContext } from "../rule-context";
|
|
2
2
|
import { HpsgLexicalRule } from "../signature";
|
|
3
|
+
export declare function proceduralActionLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
3
4
|
export declare function workflowLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
4
5
|
export declare function instructionLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import { Token } from "../../parser-state";
|
|
1
2
|
import { HpsgClauseContext } from "../rule-context";
|
|
2
3
|
import { HpsgLexicalRule } from "../signature";
|
|
4
|
+
export declare function startsMaximumCountLead(context: HpsgClauseContext, start: number): boolean;
|
|
5
|
+
export declare function symptomAdjustmentLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
6
|
+
export declare function matchContextualPrnReasonLead(context: HpsgClauseContext, start: number): {
|
|
7
|
+
tokens: Token[];
|
|
8
|
+
canonical: string;
|
|
9
|
+
next: number;
|
|
10
|
+
} | undefined;
|
|
11
|
+
export declare function tokenBelongsToContextualPrnReasonLead(context: HpsgClauseContext, tokenIndex: number): boolean;
|
|
12
|
+
export declare function hasSymptomOnsetPrnAt(context: HpsgClauseContext, start: number): boolean;
|
|
13
|
+
export declare function symptomOnsetPrnRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
3
14
|
export declare function prnLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
@@ -3,8 +3,36 @@ import { HpsgLexicalRule } from "../signature";
|
|
|
3
3
|
export declare function multiplicativeDoseFrequencyRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
4
4
|
export declare function compactIntervalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
5
5
|
export declare function separatedIntervalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
6
|
+
export declare function separatedFrequencyRangeRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
7
|
+
/**
|
|
8
|
+
* A distributive cadence followed directly by a discrete unit licenses an
|
|
9
|
+
* elided cardinal one: Thai `วันละเม็ด` => one tablet daily. This is narrower
|
|
10
|
+
* than globally treating every bare unit as one dose.
|
|
11
|
+
*/
|
|
12
|
+
export declare function cadenceFirstImplicitSingleDoseRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
13
|
+
/**
|
|
14
|
+
* Parses languages and clinical shorthand that place the cadence adverb before
|
|
15
|
+
* the count, e.g. `daily 2 times`. Thai `วันละ 2 ครั้ง` is normalized by the
|
|
16
|
+
* locale lexer to exactly this feature sequence, without pretending Thai has
|
|
17
|
+
* English word order.
|
|
18
|
+
*/
|
|
19
|
+
export declare function cadenceFirstFrequencyRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
6
20
|
export declare function countFrequencyRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
21
|
+
export declare function alternateEventCadenceRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
7
22
|
export declare function timingLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
23
|
+
export declare function quantityFirstActivityTimingRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
24
|
+
/**
|
|
25
|
+
* Quantity-first event offsets are the ordinary English inverse of
|
|
26
|
+
* relation-first forms: `30 min before breakfast`, `half an hour after food`.
|
|
27
|
+
* They project to the same canonical event-offset feature as `before meals
|
|
28
|
+
* 30 minutes`, so ordering is grammar rather than a separate semantic model.
|
|
29
|
+
*/
|
|
30
|
+
export declare function quantityFirstEventOffsetRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
31
|
+
/**
|
|
32
|
+
* Relative event offsets are timing semantics, not treatment duration.
|
|
33
|
+
* `ก่อนอาหารอย่างน้อยครึ่งชั่วโมง` becomes Before Meal + offsetMin 30 min.
|
|
34
|
+
*/
|
|
35
|
+
export declare function eventOffsetRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
8
36
|
export declare function eventTimingPhraseRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
9
37
|
export declare function dayRangeLexicalRule(): HpsgLexicalRule<HpsgClauseContext>;
|
|
10
38
|
export declare function countAndDurationRule(): HpsgLexicalRule<HpsgClauseContext>;
|
package/dist/hpsg/segmenter.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { ParseOptions } from "../types";
|
|
1
2
|
export interface HpsgSigSegment {
|
|
2
3
|
text: string;
|
|
3
4
|
start: number;
|
|
4
5
|
end: number;
|
|
5
6
|
}
|
|
6
|
-
export declare function parseSigSegments(input: string): HpsgSigSegment[];
|
|
7
|
+
export declare function parseSigSegments(input: string, options?: ParseOptions): HpsgSigSegment[];
|