ezmedicationinput 0.1.67 → 0.2.0
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 +25 -22
- package/dist/advice.d.ts +20 -0
- package/dist/body-site-grammar.d.ts +34 -1
- package/dist/date-interpretation.d.ts +2 -0
- package/dist/dosage-course.d.ts +188 -0
- package/dist/fhir.d.ts +144 -9
- package/dist/format.d.ts +9 -1
- package/dist/hpsg/constructions.d.ts +105 -0
- package/dist/hpsg/lexical-classes.d.ts +170 -1
- package/dist/hpsg/procedural-context.d.ts +15 -1
- package/dist/hpsg/projection.d.ts +10 -2
- package/dist/hpsg/rule-context.d.ts +13 -0
- package/dist/hpsg/rules/clinical-quantity-rules.d.ts +9 -0
- package/dist/hpsg/rules/condition-rules.d.ts +15 -0
- package/dist/hpsg/rules/core-rules.d.ts +29 -0
- package/dist/hpsg/rules/instruction-rules.d.ts +9 -1
- package/dist/hpsg/rules/timing-rules.d.ts +121 -7
- package/dist/hpsg/signature.d.ts +342 -4
- package/dist/hpsg/type-system.d.ts +16 -1
- package/dist/hpsg/unification.d.ts +1 -0
- package/dist/i18n.d.ts +2 -0
- package/dist/index.cjs +48961 -31422
- package/dist/index.d.ts +21 -5
- package/dist/index.js +48936 -31421
- package/dist/instruction-action-locale-adapter.d.ts +1 -0
- package/dist/instruction-action-terminology.d.ts +16 -1
- package/dist/instruction-concept-terminology.d.ts +1 -1
- package/dist/instruction-graph-fhir.d.ts +1 -1
- package/dist/instruction-graph.d.ts +38 -2
- package/dist/ir.d.ts +12 -1
- package/dist/maps.d.ts +15 -0
- package/dist/medication-condition.d.ts +42 -0
- package/dist/parser-state.d.ts +5 -1
- package/dist/parser.d.ts +5 -2
- package/dist/regimen/coordination-scope.d.ts +53 -0
- package/dist/regimen/grammar.d.ts +68 -0
- package/dist/regimen/parallel-course.d.ts +85 -0
- package/dist/regimen/planner.d.ts +19 -0
- package/dist/regimen/regimen.d.ts +66 -0
- package/dist/schedule.d.ts +9 -6
- package/dist/stable-structure.d.ts +23 -1
- package/dist/types.d.ts +433 -28
- package/dist/utils/strength.d.ts +16 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- Converts shorthand strings (e.g. `1x3 po pc`, `500 mg po q6h prn pain`) into FHIR-compliant dosage JSON.
|
|
8
|
-
- Parses multi-clause sigs into multiple dosage items (e.g. `OD ... , OS ...`)
|
|
8
|
+
- Parses multi-clause sigs into multiple dosage items (e.g. `OD ... , OS ...`), with all dosage rows available in the complete `batch.fhir` array.
|
|
9
9
|
- Emits timing abbreviations (`timing.code`) and repeat structures simultaneously where possible.
|
|
10
10
|
- Maps meal/time blocks to the correct `Timing.repeat.when` **EventTiming** codes and can auto-expand AC/PC/C into specific meals.
|
|
11
11
|
- Outputs SNOMED CT route codings (while providing friendly text) and round-trips known SNOMED routes back into the parser.
|
|
@@ -37,12 +37,13 @@ import { parseSig } from "ezmedicationinput";
|
|
|
37
37
|
|
|
38
38
|
const batch = parseSig("1x3 po pc", { context: { dosageForm: "tab" } });
|
|
39
39
|
|
|
40
|
-
//
|
|
41
|
-
console.log(batch.count);
|
|
42
|
-
console.log(batch.items[0].fhir);
|
|
40
|
+
// Individual clause and one FHIR Dosage
|
|
41
|
+
console.log(batch.count); // 1
|
|
42
|
+
console.log(batch.items[0].fhir); // Single FHIR dosage
|
|
43
43
|
|
|
44
|
-
//
|
|
45
|
-
console.log(batch.fhir);
|
|
44
|
+
// Complete batch for multi-dose or phased instructions
|
|
45
|
+
console.log(batch.fhir); // EzDosage[]: flat R5-compatible rows
|
|
46
|
+
console.log(batch.fhirNext); // R6-like course and phases
|
|
46
47
|
```
|
|
47
48
|
|
|
48
49
|
Example output:
|
|
@@ -68,23 +69,25 @@ Example output:
|
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
],
|
|
71
|
-
"fhir": { "
|
|
72
|
+
"fhir": [{ "doseAndRate": [{ "doseQuantity": { "value": 1, "unit": "tab" } }] }]
|
|
72
73
|
}
|
|
73
74
|
```
|
|
74
75
|
|
|
75
|
-
###
|
|
76
|
+
### Batch dosage output
|
|
76
77
|
|
|
77
|
-
`parseSig`
|
|
78
|
+
`parseSig` and `parseSigAsync` return one batch result containing:
|
|
78
79
|
|
|
79
|
-
- `count`: number of parsed dosage clauses
|
|
80
|
-
- `items`:
|
|
81
|
-
- `
|
|
80
|
+
- `count`: number of parsed dosage clauses.
|
|
81
|
+
- `items[n].fhir`: the dosage for an individual clause.
|
|
82
|
+
- `fhir`: `EzDosage[]` containing all flat R5-compatible dosage rows.
|
|
83
|
+
- `fhirNext`: R6-like course details, including phases and independent dosing schedules.
|
|
84
|
+
- `meta.segments`: source ranges for each clause.
|
|
85
|
+
- `shortText`, `longText`, `warnings`, and `meta`: batch-level display and diagnostics.
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
So existing code that expects one result can continue using first-item compatibility while newer code uses `items[]`.
|
|
87
|
+
Use `items[0].fhir` when displaying or editing a single dosage, and
|
|
88
|
+
`batch.fhir` when processing the complete flat prescription.
|
|
89
|
+
`formatSig` and `fromFhirDosage` accept one dosage; `formatSigBatch`
|
|
90
|
+
accepts an array of dosages.
|
|
88
91
|
|
|
89
92
|
### PRN reasons & additional instructions
|
|
90
93
|
|
|
@@ -94,7 +97,7 @@ codes them with SNOMED CT whenever possible.
|
|
|
94
97
|
```ts
|
|
95
98
|
const result = parseSig("1 tab po q4h prn headache; do not exceed 6 tabs/day");
|
|
96
99
|
|
|
97
|
-
result.fhir.asNeededFor;
|
|
100
|
+
result.items[0].fhir.asNeededFor;
|
|
98
101
|
// → [{
|
|
99
102
|
// text: "headache",
|
|
100
103
|
// coding: [{
|
|
@@ -104,7 +107,7 @@ result.fhir.asNeededFor;
|
|
|
104
107
|
// }]
|
|
105
108
|
// }]
|
|
106
109
|
|
|
107
|
-
result.fhir.additionalInstruction;
|
|
110
|
+
result.items[0].fhir.additionalInstruction;
|
|
108
111
|
// → [{ text: "Do not exceed 6 tablets daily" }]
|
|
109
112
|
```
|
|
110
113
|
|
|
@@ -251,7 +254,7 @@ The HPSG chart uses packed semantic state, an indexed agenda, and a compatible s
|
|
|
251
254
|
|
|
252
255
|
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
256
|
|
|
254
|
-
`
|
|
257
|
+
`urn:ezmedicationinput:StructureDefinition:medication-timing-frequency-min`
|
|
255
258
|
|
|
256
259
|
## Procedural instruction semantics and opaque-span enrichment
|
|
257
260
|
|
|
@@ -343,7 +346,7 @@ import { parseSig } from "ezmedicationinput";
|
|
|
343
346
|
|
|
344
347
|
const result = parseSig("apply cream to left arm twice daily");
|
|
345
348
|
|
|
346
|
-
result.fhir.site?.coding?.[0];
|
|
349
|
+
result.items[0].fhir.site?.coding?.[0];
|
|
347
350
|
// → { system: "http://snomed.info/sct", code: "368208006", display: "Left upper arm structure" }
|
|
348
351
|
```
|
|
349
352
|
|
|
@@ -353,7 +356,7 @@ and in `ParseResult.meta.normalized.site.spatialRelation`.
|
|
|
353
356
|
```ts
|
|
354
357
|
const result = parseSig("apply to area between fingers");
|
|
355
358
|
|
|
356
|
-
result.fhir.site?.text;
|
|
359
|
+
result.items[0].fhir.site?.text;
|
|
357
360
|
// → "area between fingers"
|
|
358
361
|
|
|
359
362
|
result.meta.normalized.site?.spatialRelation;
|
package/dist/advice.d.ts
CHANGED
|
@@ -11,6 +11,26 @@ export interface AdviceParseContext {
|
|
|
11
11
|
defaultForce?: AdviceForce;
|
|
12
12
|
allowFreeTextFallback?: boolean;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolve semantic qualifier codings from the COMPLETE composed action program.
|
|
16
|
+
* This is the existing structural matcher, with no string-based reparsing of
|
|
17
|
+
* clinical instructions after FHIR projection.
|
|
18
|
+
*/
|
|
19
|
+
export declare function matchComposedAdviceCodings(frames: readonly AdviceFrame[]): AdditionalInstructionDefinition[];
|
|
20
|
+
/** Determine whether a rule's coding must be rechecked against scoped HPSG frames. */
|
|
21
|
+
export declare function adviceCodingNeedsComposedScope(system: string, code: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Standardized coded warnings retain their clinical wording when precisely
|
|
24
|
+
* one composed action entails that warning. Return its original action source
|
|
25
|
+
* for exclusion from a DUPLICATE realization; neither action nor code is lost.
|
|
26
|
+
*/
|
|
27
|
+
export declare function composedCodedWarningActionSources(frames: readonly AdviceFrame[], coding: Pick<FhirCoding, "system" | "code"> | undefined): string[];
|
|
28
|
+
/** Existing advice terminology supplies manner modifiers to the main action
|
|
29
|
+
* grammar. It is lexical evidence, not a second clause parser. */
|
|
30
|
+
export declare function resolveAdviceMannerModifier(surface: string): {
|
|
31
|
+
lemma: string;
|
|
32
|
+
i18n?: Record<string, string>;
|
|
33
|
+
} | undefined;
|
|
14
34
|
export declare function realizeAdviceFramesText(frames: AdviceFrame[], locale?: string): string | undefined;
|
|
15
35
|
export declare function parseAdditionalInstructions(sourceText: string, span: TextRange, context?: AdviceParseContext): ParsedAdditionalInstruction[];
|
|
16
36
|
export declare function findAdditionalInstructionDefinitionByCoding(system: string, code: string): AdditionalInstructionDefinition | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BodySiteDefinition, BodySiteSpatialRelation, FhirCoding } from "./types";
|
|
1
|
+
import { BodySiteDefinition, BodySiteSpatialRelation, FhirCoding, type BodySiteRestriction, type BodySiteRestrictionPredicate, type TextRange } from "./types";
|
|
2
2
|
import type { BodySiteLocativeRelation } from "./relation-terminology";
|
|
3
3
|
export type BodySiteGrammarKind = "nominal" | "partitive" | "locative";
|
|
4
4
|
export type { BodySiteLocativeRelation };
|
|
@@ -49,6 +49,11 @@ export interface ResolvedBodySitePhrase {
|
|
|
49
49
|
definition?: BodySiteDefinition;
|
|
50
50
|
features: BodySiteFeatureStructure;
|
|
51
51
|
englishObjectText: string;
|
|
52
|
+
/** Composed localization of clinical qualifier + known nominal head.
|
|
53
|
+
* It deliberately grants no code to a qualified site merely because its
|
|
54
|
+
* unqualified anatomy is coded. */
|
|
55
|
+
siteI18n?: Record<string, string>;
|
|
56
|
+
restrictions?: BodySiteRestriction[];
|
|
52
57
|
preferredPreposition?: "to" | "at" | "in" | "into";
|
|
53
58
|
}
|
|
54
59
|
export interface BodySitePhraseContext {
|
|
@@ -56,4 +61,32 @@ export interface BodySitePhraseContext {
|
|
|
56
61
|
allowTerminalModifierInheritance?: boolean;
|
|
57
62
|
}
|
|
58
63
|
export declare function lookupBodySiteDefinition(map: Record<string, BodySiteDefinition> | undefined, canonical: string): BodySiteDefinition | undefined;
|
|
64
|
+
/** One lexical interpretation for standalone and clause-level site predicates.
|
|
65
|
+
* Introducers and terminology are resolved here once, never in FHIR lowering.
|
|
66
|
+
* @param text Predicate surface text, excluding the relation marker.
|
|
67
|
+
* @param range Optional original-source span owned by the lexical sign.
|
|
68
|
+
*/
|
|
69
|
+
export declare function resolveBodySiteRestrictionPredicate(text: string, range: TextRange): BodySiteRestrictionPredicate & {
|
|
70
|
+
range: TextRange;
|
|
71
|
+
};
|
|
72
|
+
export declare function resolveBodySiteRestrictionPredicate(text: string, range?: TextRange): BodySiteRestrictionPredicate;
|
|
73
|
+
/** Construct the same typed relative clause for either entrypoint. Full-SIG
|
|
74
|
+
* attachment remains the HPSG head-adjunct construction's responsibility.
|
|
75
|
+
* @param predicate Already interpreted lexical predicate.
|
|
76
|
+
* @param markerRange Original span of the relative marker.
|
|
77
|
+
* @param sourceText Original complete relative clause, when available.
|
|
78
|
+
*/
|
|
79
|
+
export declare function formBodySiteRestriction(predicate: BodySiteRestrictionPredicate, markerRange?: TextRange, sourceText?: string): BodySiteRestriction;
|
|
80
|
+
/** Realize a typed restriction by lexical identity, never by re-parsing prose.
|
|
81
|
+
* @param restriction Typed site-local relative clause.
|
|
82
|
+
* @param locale English or Thai output locale.
|
|
83
|
+
*/
|
|
84
|
+
export declare function realizeBodySiteRestriction(restriction: BodySiteRestriction, locale: "en" | "th"): string | undefined;
|
|
59
85
|
export declare function resolveBodySitePhrase(text: string, customSiteMap?: Record<string, BodySiteDefinition>, context?: BodySitePhraseContext): ResolvedBodySitePhrase | undefined;
|
|
86
|
+
/** Anatomical vocabulary lookup only. Full-SIG lexical rules use this entrypoint
|
|
87
|
+
* so a lexical site cannot independently absorb a relative clause.
|
|
88
|
+
* @param text Anatomical constituent selected by the caller's grammar.
|
|
89
|
+
* @param customSiteMap Registered anatomy and custom terminology.
|
|
90
|
+
* @param context Contextual anatomy/terminal-modifier lookup options.
|
|
91
|
+
*/
|
|
92
|
+
export declare function resolveBodySiteLexeme(text: string, customSiteMap?: Record<string, BodySiteDefinition>, context?: BodySitePhraseContext): ResolvedBodySitePhrase | undefined;
|
|
@@ -4,6 +4,8 @@ export interface MedicationDateListMatch {
|
|
|
4
4
|
start: number;
|
|
5
5
|
end: number;
|
|
6
6
|
sourceText: string;
|
|
7
|
+
/** True when medication syntax explicitly introduced the date relation (for example `until` or `วันที่`). */
|
|
8
|
+
explicitLead?: boolean;
|
|
7
9
|
relation: MedicationDateRelation;
|
|
8
10
|
events: CanonicalCalendarEventExpr[];
|
|
9
11
|
unresolved: boolean;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { FhirDayOfWeek, FhirDosage, FhirR6Dosage, FhirR6DosageDetails, MedicationCondition, EzDosage, EzCourseMetadata } from "./types";
|
|
2
|
+
/** Modifier extensions: ignoring either can change whether a dose may be given. */
|
|
3
|
+
export declare const DOSAGE_CONDITION_R5_URL = "urn:ezmedicationinput:StructureDefinition:medication-conditional-dose";
|
|
4
|
+
/** Separate R6 DosageCondition-level extension: the R5 Dosage modifier has
|
|
5
|
+
* a different context and nested child contract, so it cannot be reused. */
|
|
6
|
+
export declare const DOSAGE_CONDITION_R6_LOGIC_URL = "urn:ezmedicationinput:StructureDefinition:medication-r6-condition-logic";
|
|
7
|
+
export declare const DOSAGE_EXCLUDED_DATES_R5_URL = "urn:ezmedicationinput:StructureDefinition:medication-excluded-calendar-dates";
|
|
8
|
+
export declare const DOSAGE_DETAILS_R5_URL = "urn:ezmedicationinput:StructureDefinition:medication-r6-course-details";
|
|
9
|
+
/** Non-modifier metadata: preserves the author's entire literal instruction
|
|
10
|
+
* without forcing ordinary R5 consumers to implement R6 safety semantics. */
|
|
11
|
+
export declare const DOSAGE_RENDERED_INSTRUCTION_R5_URL = "urn:ezmedicationinput:StructureDefinition:medication-rendered-instruction";
|
|
12
|
+
export declare const DOSAGE_EXCLUDED_WEEKDAYS_R5_URL = "urn:ezmedicationinput:StructureDefinition:medication-excluded-weekdays";
|
|
13
|
+
/** Non-modifier provenance emitted when an editable R5 projection and its
|
|
14
|
+
* retained R6 source cannot be merged one-to-one. */
|
|
15
|
+
export declare const DOSAGE_RECONCILIATION_WARNING_URL = "urn:ezmedicationinput:StructureDefinition:medication-course-reconciliation-warning";
|
|
16
|
+
/** Treatment-relative phase origin for an independent parallel component. */
|
|
17
|
+
export declare const PARALLEL_COMPONENT_PHASE_ORIGIN_URL = "urn:ezmedicationinput:StructureDefinition:medication-parallel-component-phase-origin";
|
|
18
|
+
/** Local must-understand profile for exclusive administration choices.
|
|
19
|
+
* Equal R5 sequences and R6 step components alone represent concurrency,
|
|
20
|
+
* so grammar-proven alternatives need explicit membership in both formats.
|
|
21
|
+
*/
|
|
22
|
+
export declare const DOSAGE_ALTERNATIVE_CHOICE_URL = "urn:ezmedicationinput:StructureDefinition:medication-alternative-choice";
|
|
23
|
+
/** Group identity is course-local; a branch may contain multiple dosages. */
|
|
24
|
+
export interface DosageAlternativeChoice {
|
|
25
|
+
groupId: string;
|
|
26
|
+
branchId: string;
|
|
27
|
+
selectionBehavior: "exactly-one";
|
|
28
|
+
}
|
|
29
|
+
/** Read typed membership without interpreting clinical text or changing source.
|
|
30
|
+
* @param dosage An R5 or R6 dosage carrying the same modifier-extension shape.
|
|
31
|
+
* @returns Recognized membership, or undefined while unfamiliar data stays attached.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getDosageAlternativeChoice(dosage: Pick<FhirDosage, "modifierExtension">): DosageAlternativeChoice | undefined;
|
|
34
|
+
/** Assign membership already established by the typed regimen graph.
|
|
35
|
+
* This does not choose a branch, deduce a group from wording, or add conditions.
|
|
36
|
+
* @param dosage The editable R5 or R6 component to update.
|
|
37
|
+
* @param choice Proven membership; undefined explicitly clears this modifier.
|
|
38
|
+
*/
|
|
39
|
+
export declare function setDosageAlternativeChoice(dosage: Pick<FhirDosage, "modifierExtension">, choice: DosageAlternativeChoice | undefined): void;
|
|
40
|
+
/** Machine-readable declaration of the local alternative-choice modifier.
|
|
41
|
+
* It is generated beside its only codec, avoiding a second copied schema or
|
|
42
|
+
* an undocumented native FHIR field. Callers can publish/validate the returned
|
|
43
|
+
* StructureDefinition independently of the parser's permissive read path.
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildDosageAlternativeChoiceStructureDefinition(): {
|
|
46
|
+
resourceType: "StructureDefinition";
|
|
47
|
+
id: string;
|
|
48
|
+
url: string;
|
|
49
|
+
name: string;
|
|
50
|
+
title: string;
|
|
51
|
+
status: "draft";
|
|
52
|
+
description: string;
|
|
53
|
+
kind: "complex-type";
|
|
54
|
+
abstract: boolean;
|
|
55
|
+
type: string;
|
|
56
|
+
baseDefinition: string;
|
|
57
|
+
derivation: "constraint";
|
|
58
|
+
context: {
|
|
59
|
+
type: "element";
|
|
60
|
+
expression: string;
|
|
61
|
+
}[];
|
|
62
|
+
differential: {
|
|
63
|
+
element: ({
|
|
64
|
+
id: string;
|
|
65
|
+
path: string;
|
|
66
|
+
sliceName: string;
|
|
67
|
+
min: number;
|
|
68
|
+
max: string;
|
|
69
|
+
type: {
|
|
70
|
+
code: string;
|
|
71
|
+
}[];
|
|
72
|
+
fixedUri?: undefined;
|
|
73
|
+
} | {
|
|
74
|
+
id: string;
|
|
75
|
+
path: string;
|
|
76
|
+
max: string;
|
|
77
|
+
sliceName?: undefined;
|
|
78
|
+
min?: undefined;
|
|
79
|
+
type?: undefined;
|
|
80
|
+
fixedUri?: undefined;
|
|
81
|
+
} | {
|
|
82
|
+
id: string;
|
|
83
|
+
path: string;
|
|
84
|
+
fixedUri: string;
|
|
85
|
+
sliceName?: undefined;
|
|
86
|
+
min?: undefined;
|
|
87
|
+
max?: undefined;
|
|
88
|
+
type?: undefined;
|
|
89
|
+
} | {
|
|
90
|
+
fixedCode?: string | undefined;
|
|
91
|
+
id: string;
|
|
92
|
+
path: string;
|
|
93
|
+
min: number;
|
|
94
|
+
max: string;
|
|
95
|
+
type: {
|
|
96
|
+
code: "string" | "code";
|
|
97
|
+
}[];
|
|
98
|
+
sliceName?: undefined;
|
|
99
|
+
fixedUri?: undefined;
|
|
100
|
+
} | {
|
|
101
|
+
id: string;
|
|
102
|
+
path: string;
|
|
103
|
+
isModifier: boolean;
|
|
104
|
+
isModifierReason: string;
|
|
105
|
+
slicing?: undefined;
|
|
106
|
+
} | {
|
|
107
|
+
id: string;
|
|
108
|
+
path: string;
|
|
109
|
+
slicing: {
|
|
110
|
+
discriminator: {
|
|
111
|
+
type: string;
|
|
112
|
+
path: string;
|
|
113
|
+
}[];
|
|
114
|
+
ordered: boolean;
|
|
115
|
+
rules: string;
|
|
116
|
+
};
|
|
117
|
+
isModifier?: undefined;
|
|
118
|
+
isModifierReason?: undefined;
|
|
119
|
+
})[];
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
export declare function assertUnderstoodDosageModifiers(_dosage: FhirDosage | EzDosage): void;
|
|
123
|
+
export declare function getDosageCondition(dosage: FhirDosage | EzDosage): MedicationCondition | undefined;
|
|
124
|
+
/** A whole-day evaluation is licensed only for the same live predicate that
|
|
125
|
+
* the source grammar identified as calendar membership. An edited native
|
|
126
|
+
* condition or a mixed measurement/day predicate cannot inherit that claim.
|
|
127
|
+
* @param dosage Native or R5 dosage with optional source-owned day-domain metadata.
|
|
128
|
+
*/
|
|
129
|
+
export declare function getDosageCalendarDayCondition(dosage: FhirDosage | EzDosage): MedicationCondition | undefined;
|
|
130
|
+
/** Encode the clinical predicate and its independently supplied day-domain type.
|
|
131
|
+
* @param dosage Editable target dosage; other modifiers remain untouched.
|
|
132
|
+
* @param condition Live clinical predicate, or undefined to clear it.
|
|
133
|
+
* @param calendarDayCondition Source-certified whole-day predicate, never inferred from prose.
|
|
134
|
+
*/
|
|
135
|
+
export declare function setDosageCondition(dosage: FhirDosage, condition: MedicationCondition | undefined, calendarDayCondition?: MedicationCondition): void;
|
|
136
|
+
export declare function getDosageExcludedDates(dosage: FhirDosage | EzDosage): string[];
|
|
137
|
+
export declare function setDosageExcludedDates(dosage: FhirDosage, dates: string[]): void;
|
|
138
|
+
export declare function getDosageExcludedWeekdays(dosage: FhirDosage): FhirDayOfWeek[];
|
|
139
|
+
export declare function setDosageExcludedWeekdays(dosage: FhirDosage, days: FhirDayOfWeek[]): void;
|
|
140
|
+
/** Lift real R6 concepts once into the familiar flat R5 dosage shape. */
|
|
141
|
+
export declare function toEzDosages(dosages: readonly (FhirDosage | EzDosage)[]): EzDosage[];
|
|
142
|
+
/** Project one R6 component without building course-storage metadata. Used by
|
|
143
|
+
* both strict exports and read-only rendering; source objects are not mutated.
|
|
144
|
+
* @param dosage Native R6 component.
|
|
145
|
+
* @param sequence Ordered global course step for its R5 projection.
|
|
146
|
+
*/
|
|
147
|
+
export declare function fromR6Dosage(dosage: FhirR6Dosage, sequence: number): FhirDosage;
|
|
148
|
+
/**
|
|
149
|
+
* Attach source/display provenance using repeated, structured row extensions.
|
|
150
|
+
* Both primary parser output and strict R5 export use this same representation.
|
|
151
|
+
* @param dosages Independently editable rows being returned to the caller.
|
|
152
|
+
* @param instruction The author's unmodified instruction.
|
|
153
|
+
*/
|
|
154
|
+
export declare function withDosageEditProvenance<T extends FhirDosage | EzDosage>(dosages: readonly T[], instruction: string): T[];
|
|
155
|
+
/**
|
|
156
|
+
* Export the R5-style extended dose array as strict R6 DosageDetails.
|
|
157
|
+
* The optional course.step rows use the official R6 step fields, grouped
|
|
158
|
+
* by the existing global R5 sequence number.
|
|
159
|
+
* @param dosages Authoritative live R5 rows, including retained course metadata.
|
|
160
|
+
* @param renderedInstruction Explicit replacement whole-course display.
|
|
161
|
+
* @param course Explicit editable course and step metadata, when supplied.
|
|
162
|
+
* @param options Confirm corrected phase sequences after editing saved rows.
|
|
163
|
+
* Only their persisted conflict flags are cleared; live disagreements still
|
|
164
|
+
* block numeric execution and the prior conflict remains source provenance.
|
|
165
|
+
* @returns The editable R6 course with any unresolved context retained.
|
|
166
|
+
*/
|
|
167
|
+
export declare function toDosageDetails(dosages: readonly (FhirDosage | EzDosage)[], renderedInstruction?: string, course?: EzCourseMetadata, options?: {
|
|
168
|
+
resolvedPhaseSequences?: readonly number[];
|
|
169
|
+
}): FhirR6DosageDetails;
|
|
170
|
+
/** Import a complete R6 course without replacing EZMED's flat dosage layout. */
|
|
171
|
+
export declare function fromDosageDetails(details: FhirR6DosageDetails): {
|
|
172
|
+
dosages: EzDosage[];
|
|
173
|
+
course: EzCourseMetadata;
|
|
174
|
+
};
|
|
175
|
+
/** Flatten R6 steps to R5 Dosage.sequence with explicit modifier extensions. */
|
|
176
|
+
export declare function toFhirR5Dosages(input: FhirR6DosageDetails | readonly (FhirDosage | EzDosage)[], course?: EzCourseMetadata): FhirDosage[];
|
|
177
|
+
/** Encode local phase metadata and unrepresentable component fields.
|
|
178
|
+
* Course-wide metadata has one owner, referenced by all participating rows.
|
|
179
|
+
* All rows are newly created by the caller; no source course is mutated.
|
|
180
|
+
* @param dosages Fresh flattened output rows in step/component order.
|
|
181
|
+
* @param details Typed source course, used only to calculate missing metadata.
|
|
182
|
+
*/
|
|
183
|
+
export declare function attachCourseDetailsExtensions(dosages: (FhirDosage | EzDosage)[], details: FhirR6DosageDetails): void;
|
|
184
|
+
/** Identify unavailable or contradictory context before numeric execution.
|
|
185
|
+
* Parsing, formatting and editing continue to preserve all surviving data.
|
|
186
|
+
* @param course Reconstructed course with typed context markers on its components.
|
|
187
|
+
*/
|
|
188
|
+
export declare function getCourseContextIssue(course: FhirR6DosageDetails): "missing-course-context" | "conflicting-course-phase" | undefined;
|
package/dist/fhir.d.ts
CHANGED
|
@@ -1,16 +1,151 @@
|
|
|
1
1
|
import { ParserState } from "./parser-state";
|
|
2
|
-
import { CanonicalOccurrenceCapExpr, CanonicalSigClause, FhirDosage, FhirTimingRepeat } from "./types";
|
|
3
|
-
|
|
4
|
-
export declare const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare
|
|
9
|
-
export declare const
|
|
10
|
-
|
|
2
|
+
import { CanonicalActivityTimingExpr, CanonicalCycleDayConstraint, CanonicalOccurrenceCapExpr, CanonicalSigClause, EventTiming, FhirDosage, FhirExtension, FhirTimingRepeat } from "./types";
|
|
3
|
+
/** Known modifier: an independent cadence is restricted by unresolved cycle days. */
|
|
4
|
+
export declare const CYCLE_DAY_ELIGIBILITY_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-cycle-day-eligibility";
|
|
5
|
+
/** Read the recognized cycle constraint without interpreting narrative text.
|
|
6
|
+
* @param dosage Editable R5/R6-compatible dosage with a retained known modifier.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getCycleDayConstraint(dosage: FhirDosage): CanonicalCycleDayConstraint | undefined;
|
|
9
|
+
export declare const TIMING_FREQUENCY_MIN_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-frequency-min";
|
|
10
|
+
/** Modifier: each retained base-schedule opportunity occurs this many minutes later. */
|
|
11
|
+
export declare const ADMINISTRATION_OFFSET_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-administration-offset";
|
|
12
|
+
export declare function getAdministrationOffsetMinutes(dosage: FhirDosage): number | undefined;
|
|
13
|
+
/** Modifier retaining a course duration alongside its absolute calendar bounds. */
|
|
14
|
+
export declare const ANCHORED_COURSE_DURATION_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-anchored-course-duration";
|
|
15
|
+
/** Read the authored temporal quantity without reconstructing it from dates or text.
|
|
16
|
+
* @param dosage R5/R6-compatible dosage containing the known duration modifier.
|
|
17
|
+
* @returns The retained duration quantity or range, when supplied.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getAnchoredCourseDuration(dosage: Pick<FhirDosage, "modifierExtension">): Pick<FhirExtension, "valueQuantity" | "valueRange"> | undefined;
|
|
20
|
+
export declare const TIMING_OFFSET_MIN_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-offset-min";
|
|
21
|
+
export declare const TIMING_OFFSET_MAX_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-offset-max";
|
|
22
|
+
export declare const TIMING_OFFSET_EXACT_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-offset-exact";
|
|
23
|
+
export declare const TIMING_ACTIVITY_WINDOW_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-activity-window";
|
|
24
|
+
/** Recurring administration opportunity window; distinct from a punctual
|
|
25
|
+
* FHIR Timing.repeat.when WAKE or HS administration. */
|
|
26
|
+
export declare const TIMING_EVENT_WINDOW_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-event-window";
|
|
27
|
+
export declare const TIMING_CLOCK_WINDOW_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-clock-window";
|
|
28
|
+
/** Read a local-clock recurrence window from structural timing metadata.
|
|
29
|
+
* @param repeat FHIR Timing.repeat containing a typed window extension.
|
|
30
|
+
* @returns Source clock endpoints and explicit endpoint inclusivity.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getTimingClockWindow(repeat: FhirTimingRepeat | undefined): {
|
|
33
|
+
start: string;
|
|
34
|
+
end: string;
|
|
35
|
+
endInclusive: boolean;
|
|
36
|
+
} | undefined;
|
|
37
|
+
/** Standard HL7 extension for day-of-month timing (repeatable positive integer). */
|
|
38
|
+
export declare const TIMING_DAY_OF_MONTH_EXTENSION_URL = "http://hl7.org/fhir/StructureDefinition/timing-dayOfMonth";
|
|
39
|
+
/** Retrieve bounded executable month-day selection without interpreting prose.
|
|
40
|
+
* Unknown and malformed extensions remain in the original FHIR object.
|
|
41
|
+
* @param repeat Original FHIR R5 Timing.repeat with optional standard extensions.
|
|
42
|
+
* @returns Sorted unique calendar days, or undefined when none are recognized.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getTimingMonthDays(repeat: FhirTimingRepeat | undefined): number[] | undefined;
|
|
45
|
+
export declare const TIMING_WEEKDAY_ORDINAL_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-weekday-ordinal";
|
|
46
|
+
/** Read the explicitly encoded ordinal, independent of prose and scheduling anchors.
|
|
47
|
+
* @param repeat Typed FHIR timing repeat containing an optional ordinal extension.
|
|
48
|
+
* @returns The source weekday occurrence, including -1 for last, when valid.
|
|
49
|
+
*/
|
|
50
|
+
export declare function getTimingWeekdayOrdinal(repeat: FhirTimingRepeat | undefined): -1 | 1 | 2 | 3 | 4 | 5 | undefined;
|
|
51
|
+
/** Read an explicitly encoded daily event window without examining SIG text. */
|
|
52
|
+
export declare function getTimingEventWindow(repeat: FhirTimingRepeat | undefined): {
|
|
53
|
+
start: EventTiming;
|
|
54
|
+
end: EventTiming;
|
|
55
|
+
} | undefined;
|
|
56
|
+
export declare const TIMING_OCCURRENCE_CAP_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-occurrence-cap";
|
|
57
|
+
export declare const TIMING_EVENT_CALENDAR_SOURCE_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-event-calendar-source";
|
|
58
|
+
export declare const PRN_TRIGGER_PHASE_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-prn-trigger-phase";
|
|
59
|
+
export declare const BODY_SITE_RESTRICTION_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-body-site-restriction";
|
|
60
|
+
export declare const INFUSION_CARRIER_MATERIAL_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-infusion-carrier-material";
|
|
61
|
+
/** Draft FHIR R5 extension definition, produced from the same typed child
|
|
62
|
+
* contract as the live encoder. Carrier material is a descriptive vehicle
|
|
63
|
+
* role, not a verified drug code or a modified administration choice.
|
|
64
|
+
* External HL7 conformance validation remains a separate release check.
|
|
65
|
+
*/
|
|
66
|
+
export declare function buildInfusionCarrierMaterialStructureDefinition(): {
|
|
67
|
+
resourceType: "StructureDefinition";
|
|
68
|
+
id: string;
|
|
69
|
+
url: string;
|
|
70
|
+
name: string;
|
|
71
|
+
title: string;
|
|
72
|
+
status: "draft";
|
|
73
|
+
description: string;
|
|
74
|
+
kind: "complex-type";
|
|
75
|
+
abstract: boolean;
|
|
76
|
+
type: string;
|
|
77
|
+
baseDefinition: string;
|
|
78
|
+
derivation: "constraint";
|
|
79
|
+
context: {
|
|
80
|
+
type: "element";
|
|
81
|
+
expression: string;
|
|
82
|
+
}[];
|
|
83
|
+
differential: {
|
|
84
|
+
element: ({
|
|
85
|
+
id: string;
|
|
86
|
+
path: string;
|
|
87
|
+
sliceName: string;
|
|
88
|
+
min: number;
|
|
89
|
+
max: string;
|
|
90
|
+
type: {
|
|
91
|
+
code: string;
|
|
92
|
+
}[];
|
|
93
|
+
fixedUri?: undefined;
|
|
94
|
+
} | {
|
|
95
|
+
id: string;
|
|
96
|
+
path: string;
|
|
97
|
+
max: string;
|
|
98
|
+
sliceName?: undefined;
|
|
99
|
+
min?: undefined;
|
|
100
|
+
type?: undefined;
|
|
101
|
+
fixedUri?: undefined;
|
|
102
|
+
} | {
|
|
103
|
+
id: string;
|
|
104
|
+
path: string;
|
|
105
|
+
fixedUri: string;
|
|
106
|
+
sliceName?: undefined;
|
|
107
|
+
min?: undefined;
|
|
108
|
+
max?: undefined;
|
|
109
|
+
type?: undefined;
|
|
110
|
+
} | {
|
|
111
|
+
id: string;
|
|
112
|
+
path: string;
|
|
113
|
+
min: number;
|
|
114
|
+
max: string;
|
|
115
|
+
type: {
|
|
116
|
+
code: "string" | "integer";
|
|
117
|
+
}[];
|
|
118
|
+
sliceName?: undefined;
|
|
119
|
+
fixedUri?: undefined;
|
|
120
|
+
} | {
|
|
121
|
+
id: string;
|
|
122
|
+
path: string;
|
|
123
|
+
isModifier: boolean;
|
|
124
|
+
slicing?: undefined;
|
|
125
|
+
} | {
|
|
126
|
+
id: string;
|
|
127
|
+
path: string;
|
|
128
|
+
slicing: {
|
|
129
|
+
discriminator: {
|
|
130
|
+
type: string;
|
|
131
|
+
path: string;
|
|
132
|
+
}[];
|
|
133
|
+
ordered: boolean;
|
|
134
|
+
rules: string;
|
|
135
|
+
};
|
|
136
|
+
isModifier?: undefined;
|
|
137
|
+
})[];
|
|
138
|
+
};
|
|
139
|
+
};
|
|
11
140
|
export declare function getExactTimingOffsetMinutes(repeat: FhirTimingRepeat | undefined): number | undefined;
|
|
12
141
|
export declare function getTimingOccurrenceCap(repeat: FhirTimingRepeat | undefined): CanonicalOccurrenceCapExpr | undefined;
|
|
142
|
+
/** Read typed activity-event relations from Timing extensions without parsing
|
|
143
|
+
* narrative instructions or inferring an activity's calendar instant.
|
|
144
|
+
*/
|
|
145
|
+
export declare function parseActivityTimingExtensions(repeat: FhirTimingRepeat | undefined): CanonicalActivityTimingExpr[] | undefined;
|
|
13
146
|
export interface FhirProjectionOptions {
|
|
147
|
+
/** Typed regimen-graph sequence; serialized without inferring phase meaning. */
|
|
148
|
+
sequence?: number;
|
|
14
149
|
/**
|
|
15
150
|
* Defaults to true. When true, structured spatial body-site phrases such as
|
|
16
151
|
* "top of head" can emit a SNOMED topographical modifier expression in
|
package/dist/format.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { ParserState } from "./parser-state";
|
|
2
2
|
import type { SigLocalization } from "./i18n";
|
|
3
|
-
import { CanonicalSigClause } from "./types";
|
|
3
|
+
import { CanonicalScheduleExpr, CanonicalSigClause } from "./types";
|
|
4
4
|
import { type TimingSummaryOptions } from "./timing-summary";
|
|
5
|
+
export declare const DAY_NAMES: Record<string, string>;
|
|
6
|
+
/** Daily recurrence applies to every explicit clock, not one occurrence in total.
|
|
7
|
+
* Presentation may say "daily at ..." without rewriting the stored frequency.
|
|
8
|
+
* Explicit ranges and counts other than one retain their authored summary.
|
|
9
|
+
* @param schedule Typed timing to realize; source text is never inspected.
|
|
10
|
+
*/
|
|
11
|
+
export declare function hasDailyRecurrenceAcrossClocks(schedule: CanonicalScheduleExpr | undefined): boolean;
|
|
12
|
+
export declare function joinWithAnd(parts: string[]): string;
|
|
5
13
|
export declare function formatCanonicalClause(clause: CanonicalSigClause, style: "short" | "long", localization?: SigLocalization, options?: TimingSummaryOptions): string;
|
|
6
14
|
export declare function formatInternal(internal: ParserState, style: "short" | "long", localization?: SigLocalization, options?: TimingSummaryOptions): string;
|