ezmedicationinput 0.3.0-beta.1 → 0.3.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.
Files changed (75) hide show
  1. package/README.md +17 -10
  2. package/dist/adapters/canonical-course.d.ts +7 -4
  3. package/dist/adapters/r5-course.d.ts +5 -2
  4. package/dist/advice-locale-adapter.d.ts +24 -0
  5. package/dist/advice.d.ts +39 -3
  6. package/dist/body-site-grammar.d.ts +21 -2
  7. package/dist/body-site-lookup.d.ts +6 -1
  8. package/dist/body-site-spatial.d.ts +7 -1
  9. package/dist/body-site-target.d.ts +32 -3
  10. package/dist/canonical/compile.d.ts +22 -3
  11. package/dist/canonical/course.d.ts +43 -7
  12. package/dist/canonical/format-course.d.ts +4 -2
  13. package/dist/clause-tail-grammar.d.ts +2 -0
  14. package/dist/date-interpretation.d.ts +36 -2
  15. package/dist/dosage-course.d.ts +26 -17
  16. package/dist/event-timing-expression.d.ts +26 -1
  17. package/dist/fhir-quantity-operator.d.ts +37 -1
  18. package/dist/fhir-translations.d.ts +1 -1
  19. package/dist/fhir.d.ts +24 -4
  20. package/dist/format.d.ts +23 -24
  21. package/dist/hpsg/constructions.d.ts +24 -5
  22. package/dist/hpsg/lexical-classes.d.ts +94 -33
  23. package/dist/hpsg/method-lexicon.d.ts +3 -0
  24. package/dist/hpsg/procedural-context.d.ts +46 -3
  25. package/dist/hpsg/projection.d.ts +7 -3
  26. package/dist/hpsg/quantity-lexicon.d.ts +51 -0
  27. package/dist/hpsg/rule-context.d.ts +101 -33
  28. package/dist/hpsg/rules/clinical-quantity-rules.d.ts +1 -1
  29. package/dist/hpsg/rules/condition-rules.d.ts +13 -2
  30. package/dist/hpsg/rules/core-rules.d.ts +5 -2
  31. package/dist/hpsg/rules/prn-rules.d.ts +10 -1
  32. package/dist/hpsg/rules/site-rules.d.ts +10 -1
  33. package/dist/hpsg/rules/timing-rules.d.ts +102 -24
  34. package/dist/hpsg/segmenter.d.ts +2 -2
  35. package/dist/hpsg/signature.d.ts +41 -4
  36. package/dist/hpsg/timing-lexicon.d.ts +18 -2
  37. package/dist/i18n.d.ts +7 -7
  38. package/dist/index.cjs +75606 -61766
  39. package/dist/index.d.ts +7 -2
  40. package/dist/index.js +75606 -61766
  41. package/dist/instruction-action-locale-adapter.d.ts +63 -4
  42. package/dist/instruction-action-parser.d.ts +43 -0
  43. package/dist/instruction-action-terminology.d.ts +22 -1
  44. package/dist/instruction-concept-terminology.d.ts +13 -1
  45. package/dist/instruction-graph-fhir.d.ts +4 -2
  46. package/dist/instruction-graph-ownership.d.ts +96 -0
  47. package/dist/instruction-graph.d.ts +19 -42
  48. package/dist/lexer/lex.d.ts +5 -1
  49. package/dist/lexer/locale.d.ts +14 -0
  50. package/dist/lexer/locales/en.d.ts +11 -0
  51. package/dist/lexer/surface.d.ts +3 -1
  52. package/dist/lexer/token-types.d.ts +6 -0
  53. package/dist/locale-detection.d.ts +4 -2
  54. package/dist/locales/clause/en.d.ts +14 -0
  55. package/dist/locales/course/en.d.ts +5 -0
  56. package/dist/localization.d.ts +3 -0
  57. package/dist/localized-timing.d.ts +1 -1
  58. package/dist/maps.d.ts +38 -12
  59. package/dist/medication-condition.d.ts +72 -11
  60. package/dist/parser-state.d.ts +10 -0
  61. package/dist/parser.d.ts +5 -3
  62. package/dist/prn.d.ts +13 -2
  63. package/dist/regimen/coordination-scope.d.ts +13 -1
  64. package/dist/regimen/grammar.d.ts +7 -1
  65. package/dist/regimen/parallel-course.d.ts +6 -2
  66. package/dist/regimen/planner.d.ts +2 -3
  67. package/dist/regimen/regimen.d.ts +2 -0
  68. package/dist/snomed.d.ts +3 -0
  69. package/dist/suggest-locale-adapter.d.ts +15 -0
  70. package/dist/symptom-terminology.d.ts +5 -1
  71. package/dist/timing-summary.d.ts +41 -9
  72. package/dist/types.d.ts +127 -15
  73. package/dist/unit-lexicon.d.ts +2 -6
  74. package/dist/utils/units.d.ts +3 -0
  75. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { TEMPORAL_DATE_RELATION_SOURCES } from "./hpsg/lexical-classes";
1
2
  import { CanonicalCalendarEventExpr, MedicationDateResolver, ParseOptions } from "./types";
2
3
  export type MedicationDateRelation = "event" | "start-inclusive" | "start-exclusive" | "end-inclusive" | "end-exclusive";
3
4
  export interface MedicationDateListMatch {
@@ -10,13 +11,46 @@ export interface MedicationDateListMatch {
10
11
  events: CanonicalCalendarEventExpr[];
11
12
  unresolved: boolean;
12
13
  }
14
+ export interface MedicationDateLexicon {
15
+ months?: ReadonlyArray<{
16
+ month: number;
17
+ forms: readonly string[];
18
+ }>;
19
+ listSeparator?: string;
20
+ eventLead?: string;
21
+ endInclusiveExtra?: string;
22
+ monthBoundary?: string;
23
+ relations?: Partial<typeof TEMPORAL_DATE_RELATION_SOURCES>;
24
+ }
25
+ export interface MedicationDateLexicalFeatures {
26
+ namedMonths: ReadonlyMap<string, number>;
27
+ monthToken: RegExp;
28
+ textualDmy: RegExp;
29
+ textualMdy: RegExp;
30
+ components: RegExp;
31
+ requiredLead: string;
32
+ list: string;
33
+ yearfulList: string;
34
+ listScans: readonly [RegExp, RegExp];
35
+ licensedListScan: RegExp;
36
+ leadPrefix: RegExp;
37
+ leadListAnchored: RegExp;
38
+ listAnchored: RegExp;
39
+ yearfulListAnchored: RegExp;
40
+ leads: ReadonlyArray<{
41
+ group: string;
42
+ relation: MedicationDateRelation;
43
+ }>;
44
+ }
45
+ /** Compile the existing date grammar's lexical slots once per registered pack. */
46
+ export declare function compileMedicationDateLexicon(configured: MedicationDateLexicon): MedicationDateLexicalFeatures;
13
47
  /** Register or replace a calendar resolver used by medication date interpretation. */
14
48
  export declare function registerMedicationDateResolver(resolver: MedicationDateResolver): void;
15
49
  /** Return the currently registered calendar resolver ids. */
16
50
  export declare function listMedicationDateResolvers(): string[];
17
51
  /** Scan structurally date-shaped numeric date lists, whether resolved or ambiguous. */
18
- export declare function findMedicationDateListSpans(input: string, options?: ParseOptions): MedicationDateListMatch[];
52
+ export declare function findMedicationDateListSpans(input: string, options?: ParseOptions, licensedDateContext?: boolean): MedicationDateListMatch[];
19
53
  /** Resolve a date list beginning exactly at the supplied source offset. */
20
- export declare function parseMedicationDateListAt(input: string, start: number, options?: ParseOptions): MedicationDateListMatch | undefined;
54
+ export declare function parseMedicationDateListAt(input: string, start: number, options?: ParseOptions, licensedDateContext?: boolean): MedicationDateListMatch | undefined;
21
55
  /** True when a source range overlaps a recognized date-shaped list span. */
22
56
  export declare function sourceRangeOverlapsMedicationDate(input: string, start: number, end: number, options?: ParseOptions): boolean;
@@ -1,3 +1,5 @@
1
+ import type { CanonicalTrackCycle } from "./canonical/course";
2
+ export { retainField, readRetainedField } from "./fhir-quantity-operator";
1
3
  import { FhirDayOfWeek, FhirDosage, FhirExtension, FhirR6Extension, FhirQuantity, FhirR6Dosage, FhirR6DosageCondition, FhirR6DosageInstruction, FhirR6DosageStep, FhirR6DosageInstructionInput, FhirR6DosageSafety, FhirR6TimingRepeat, MedicationCondition, EzDosage, EzCourseMetadata, EzCourseStep } from "./types";
2
4
  /** R5 and R6 tim-8 requires the lower-count Element beside countMax, not a numeric
3
5
  * minimum. Preserve authored companions; an absent minimum remains unknown. */
@@ -12,7 +14,7 @@ export declare const DOSAGE_CONDITION_R5_URL = "urn:ezmedicationinput:StructureD
12
14
  * a different context and nested child contract, so it cannot be reused. */
13
15
  export declare const DOSAGE_CONDITION_R6_LOGIC_URL = "urn:ezmedicationinput:StructureDefinition:medication-r6-condition-logic";
14
16
  export declare const DOSAGE_EXCLUDED_DATES_R5_URL = "urn:ezmedicationinput:StructureDefinition:medication-excluded-calendar-dates";
15
- export declare const DOSAGE_DETAILS_R5_URL = "urn:ezmedicationinput:StructureDefinition:medication-r6-course-details";
17
+ export { DOSAGE_DETAILS_R5_URL } from "./fhir-quantity-operator";
16
18
  /** Keeps an expression-only R5 backbone element valid without inventing a dose. */
17
19
  export declare const R5_EXPRESSION_SLOT_SOURCE_URL = "urn:ezmedicationinput:StructureDefinition:r5-expression-slot-source";
18
20
  /** Non-modifier metadata: preserves the author's entire literal instruction
@@ -47,6 +49,19 @@ export declare function setCourseCycleCount(owner: {
47
49
  export declare function setCourseCycleCount(owner: {
48
50
  modifierExtension?: FhirR6Extension[];
49
51
  }, count: number | undefined): FhirR6Extension[] | undefined;
52
+ /** An independent track repeats only its named source members. Ignoring this
53
+ * modifier would change which administrations recur; it is not a root repeatCycle. */
54
+ export declare const COURSE_TRACK_CYCLE_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-track-cycle";
55
+ export declare function getCourseTrackCycles(owner: {
56
+ modifierExtension?: readonly FhirR6Extension[];
57
+ }): CanonicalTrackCycle[] | undefined;
58
+ /** Both external course writers use the same scoped modifier contract. */
59
+ export declare function setCourseTrackCycles(owner: {
60
+ modifierExtension?: FhirExtension[];
61
+ }, cycles: readonly CanonicalTrackCycle[] | undefined): void;
62
+ export declare function setCourseTrackCycles(owner: {
63
+ modifierExtension?: FhirR6Extension[];
64
+ }, cycles: readonly CanonicalTrackCycle[] | undefined): void;
50
65
  type ModifierWrapperOwner = {
51
66
  extension?: FhirR6Extension[];
52
67
  modifierExtension?: FhirR6Extension[];
@@ -189,7 +204,13 @@ export declare function getDosageExcludedDates(dosage: FhirDosage | EzDosage | F
189
204
  export declare function setDosageExcludedDates(dosage: FhirDosage, dates: string[]): void;
190
205
  export declare function getDosageExcludedWeekdays(dosage: FhirDosage | FhirR6Dosage): FhirDayOfWeek[];
191
206
  export declare function setDosageExcludedWeekdays(dosage: FhirDosage, days: FhirDayOfWeek[]): void;
192
- export declare function conditionToR6(condition: MedicationCondition): FhirR6DosageCondition;
207
+ /** Project a complete predicate; existing locale/source context selects only
208
+ * its generated wording, never the encoded clinical meaning or authored text. */
209
+ export declare function conditionToR6(condition: MedicationCondition, context?: {
210
+ locale?: string;
211
+ text?: string;
212
+ extension?: readonly (FhirExtension | FhirR6Extension)[];
213
+ }): FhirR6DosageCondition;
193
214
  declare function toR6Safety(dosage: FhirDosage, includePartialPeriods?: boolean): FhirR6DosageSafety | undefined;
194
215
  /**
195
216
  * Apply edits made through R5 maximum-dose fields without discarding safety
@@ -386,10 +407,9 @@ export declare function attachCourseDetailsExtensions(dosages: (FhirDosage | EzD
386
407
  * supplies only final retained fields which cannot live in an R5 Dosage row.
387
408
  * The old extension names remain stable so existing persisted edits reopen. */
388
409
  export declare function attachR5RetainedRow(row: FhirDosage | EzDosage, retained: CompactCourseRow): void;
389
- /** Qualifiers in SimpleQuantity cannot be ignored as exact numeric doses.
390
- * The clause writer calls this only after finding a typed qualifier, using the
391
- * same modifier and edit baseline as the direct native R5 writer. */
392
- export declare function attachQualifiedR5AmountDetails(row: FhirDosage): void;
410
+ /** Typed quantity qualifiers and unevaluated safety use the same retained-row
411
+ * modifier and edit baseline as the direct native R5 writer. */
412
+ export declare function attachQualifiedR5Details(row: FhirDosage, safety?: FhirR6DosageSafety): void;
393
413
  /** A course with no administration has a source carrier, not a fabricated
394
414
  * dosage. Encode the header and empty-stage metadata directly into its R5
395
415
  * extension; do not allocate an intermediate external course. */
@@ -435,17 +455,6 @@ export declare function executablePhaseMetadata(step: NonNullable<CompactCourseR
435
455
  export declare function getCourseContextIssue(course: FhirR6DosageInstruction): "missing-course-context" | "conflicting-course-phase" | undefined;
436
456
  export declare function encodeR6SourceMetadata(url: string, value: object, kind: "drafts" | "safety" | "step"): FhirExtension;
437
457
  export declare function decodeR6SourceMetadata(marker: FhirR6Extension, kind: "drafts" | "safety" | "step"): Record<string, unknown> | undefined;
438
- /** Preserve an unfamiliar field as explicit typed extension content, never an
439
- * opaque JSON string. Known FHIR fields use the named datatype schemas above;
440
- * this escape hatch only retains future/unrecognized native fields verbatim.
441
- * @param url The enclosing field name.
442
- * @param value The actual source value; no clinical interpretation is inferred.
443
- */
444
- export declare function retainField(url: string, value: unknown): FhirExtension;
445
- /** Read retained fields without evaluating them or reparsing serialized text.
446
- * @param node One preserved field extension.
447
- */
448
- export declare function readRetainedField(node: FhirR6Extension): unknown;
449
458
  /** Recover a course from a structured extension, leaving malformed originals
450
459
  * with the caller for preservation. No string payload is interpreted here.
451
460
  * @param node The dosageDetails extension child.
@@ -1,4 +1,5 @@
1
- import { EventTiming } from "./types";
1
+ import { type LexToken } from "./lexer/token-types";
2
+ import { EventTiming, type ParseOptions } from "./types";
2
3
  export interface EventTimingExpression {
3
4
  timing: EventTiming;
4
5
  length: number;
@@ -6,3 +7,27 @@ export interface EventTimingExpression {
6
7
  export declare const MAX_EVENT_TIMING_EXPRESSION_PARTS: number;
7
8
  /** Resolve the most specific canonical event expression at `start`. */
8
9
  export declare function resolveEventTimingExpression(parts: readonly string[], start?: number, endExclusive?: number): EventTimingExpression | undefined;
10
+ /** A dose head owns its complete registered event modifiers. Return the
11
+ * selected nominal end so an adjacent calendar daughter can keep its own role.
12
+ * Withholding valence can also select the whole-medication noun without an event. */
13
+ export declare function medicationDoseSlotNominalEnd(words: readonly string[], options?: ParseOptions, requireEvent?: boolean): number | undefined;
14
+ /** Complete source coverage prevents an unrelated food or opaque noun from
15
+ * borrowing a contained event as proof of a medication target. */
16
+ export declare function isMedicationDoseSlotNominal(words: readonly string[], options?: ParseOptions): boolean;
17
+ export declare function eventTimingExpressionAt(tokens: readonly LexToken[], start: number, consumed?: ReadonlySet<number>): EventTimingExpression | undefined;
18
+ /** The complete registered nominal has the same owner at a relation lead and
19
+ * at a contained event token. Caller meanings retain their exact precedence. */
20
+ export declare function qualifiedMealStateNominalEnd(tokens: readonly LexToken[], start: number, options?: ParseOptions, input?: string): number | undefined;
21
+ /** Declared PRN leads are independent clauses. A bare FOR reason lead is
22
+ * ambiguous inside an unknown nominal and needs its ordinary PRN owner. */
23
+ export declare function isExplicitPrnClauseLead(tokens: readonly LexToken[], index: number, consumed?: ReadonlySet<number>): boolean;
24
+ /** Registered independent clauses end an accompaniment nominal. Reuse this
25
+ * boundary in the nominal reader and the free-advice body owner. */
26
+ export declare function isAccompanimentClauseBoundary(tokens: readonly LexToken[], index: number, consumed?: ReadonlySet<number>): boolean;
27
+ /** A negative accompaniment owns its event noun as advice, not a positive
28
+ * administration anchor. The chart and instruction boundary reader share this
29
+ * constituent ownership so list punctuation cannot split off an event daughter. */
30
+ export declare function isNegatedEventComplement(tokens: readonly LexToken[], index: number, consumed?: ReadonlySet<number>, options?: ParseOptions, input?: string): boolean;
31
+ /** Punctuation inside the same negative event list is a nominal boundary,
32
+ * not a new instruction. Every extraction path uses this selected scope. */
33
+ export declare function isNegatedEventListSeparator(tokens: readonly LexToken[], index: number, consumed?: ReadonlySet<number>, options?: ParseOptions, input?: string): boolean;
@@ -15,7 +15,17 @@
15
15
  * Keep this identifier in the leaf codec so annotation conversion does not
16
16
  * initialize the course importer or clinical grammar. */
17
17
  export declare const DOSAGE_RECONCILIATION_SOURCE_URL = "urn:ezmedicationinput:StructureDefinition:medication-course-reconciliation-source";
18
- import type { FhirQuantity, FhirR6Quantity, FhirSimpleQuantity, FhirR6SimpleQuantity, FhirR6Coding, FhirR6Extension, FhirPrimitiveElement, FhirR6PrimitiveElement } from "./types";
18
+ /** The same local R6-field carrier is valid on Dosage and nested Timing. */
19
+ export declare const DOSAGE_DETAILS_R5_URL = "urn:ezmedicationinput:StructureDefinition:medication-r6-course-details";
20
+ export declare const TIMING_OFFSETS_BRIDGE_SHAPE: {
21
+ readonly startOffset: {
22
+ readonly value: "valueQuantity";
23
+ };
24
+ readonly endOffset: {
25
+ readonly value: "valueQuantity";
26
+ };
27
+ };
28
+ import type { FhirExtension, FhirQuantity, FhirR6Quantity, FhirSimpleQuantity, FhirR6SimpleQuantity, FhirR6Timing, FhirR6TimingRepeat, FhirR6Coding, FhirR6CodeableConcept, FhirR6Expression, FhirR6Extension, FhirPrimitiveElement, FhirR6PrimitiveElement } from "./types";
19
29
  export declare const EMA_QUANTITY_COMPARATOR_EXTENSION_URL = "http://ema.europa.eu/fhir/extension/comparator";
20
30
  export declare const EMA_QUANTITY_OPERATOR_SYSTEM = "http://spor.ema.europa.eu/v1/lists/100000000008";
21
31
  export declare const FHIR_QUANTITY_COMPARATOR_SYSTEM = "http://hl7.org/fhir/quantity-comparator";
@@ -29,8 +39,34 @@ export declare function getQuantityComparator(quantity: Pick<FhirR6Quantity, "co
29
39
  /** Translations describe a particular code, not an operator slot. Preserve
30
40
  * superseded labels under their original Coding, outside the active operator. */
31
41
  export declare const QUANTITY_OPERATOR_SOURCE_URL = "urn:ezmedicationinput:StructureDefinition:quantity-operator-source";
42
+ /** Preserve an unfamiliar field as explicit typed extension content, never an
43
+ * opaque JSON string. Known FHIR fields use their declared datatype schemas;
44
+ * this escape hatch only retains future/unrecognized native fields verbatim.
45
+ * @param url The enclosing field name.
46
+ * @param value The actual source value; no clinical interpretation is inferred.
47
+ */
48
+ export declare function retainField(url: string, value: unknown): FhirExtension;
49
+ /** Restore one retained name/value pair as a literal enumerable field. */
50
+ export declare function restoreRetainedField(result: Record<string, unknown>, child: FhirR6Extension): void;
51
+ /** Read retained fields without evaluating them or reparsing serialized text.
52
+ * @param node One preserved field extension.
53
+ */
54
+ export declare function readRetainedField(node: FhirR6Extension): unknown;
55
+ export declare function quantityAnnotationExtensions(source: FhirR6Extension[], target: "r5"): FhirExtension[];
32
56
  export declare function quantityAnnotationExtensions(source: FhirR6Extension[], target: "r5" | "r6"): FhirR6Extension[];
57
+ /** Read the two declared carrier values without requiring a wire cadence.
58
+ * Native import consumes these facts even when R6 core promotion is ineligible. */
59
+ export declare function readRetainedTimingOffsets(timing: FhirR6Timing): Pick<FhirR6TimingRepeat, "startOffset" | "endOffset"> | undefined;
60
+ /** The supported R6 Timing contract permits offsets on a repeated cadence. */
61
+ export declare function canUseCoreTimingOffsets(repeat: Pick<FhirR6TimingRepeat, "frequency" | "period"> | undefined): boolean;
62
+ export declare function withRetainedTimingOffsets(modifiers: FhirR6Extension[] | undefined, repeat: Pick<FhirR6TimingRepeat, "startOffset" | "endOffset">): FhirR6Extension[];
63
+ /** Follow declared Timing annotation carriers, without interpreting its schedule
64
+ * or walking opaque application payloads. Unchanged branches retain identity. */
65
+ export declare function quantityTimingForWire(timing: FhirR6Timing | undefined, target: "r5" | "r6"): FhirR6Timing | undefined;
66
+ export declare function quantityExpressionForWire(expression: FhirR6Expression, target: "r5" | "r6"): FhirR6Expression;
67
+ export declare function quantityConceptForWire(concept: FhirR6CodeableConcept | undefined, target: "r5" | "r6"): FhirR6CodeableConcept | undefined;
33
68
  export declare function quantityCodingForWire(coding: FhirR6Coding | undefined, target: "r5" | "r6"): FhirR6Coding | undefined;
69
+ export declare function quantityPrimitiveForWire(primitive: FhirR6PrimitiveElement | undefined, target: "r5" | "r6"): FhirR6PrimitiveElement | undefined;
34
70
  /** The known Quantity choice is projected; all unrelated opaque annotations
35
71
  * retain their original datatype and fields at this version boundary. */
36
72
  export declare function quantityPrimitiveForR5(primitive: FhirR6PrimitiveElement | undefined): FhirPrimitiveElement | undefined;
@@ -7,4 +7,4 @@ export declare function clonePrimitiveElement(element: FhirR6PrimitiveElement |
7
7
  export declare function buildTranslationPrimitiveElement(translations: Record<string, string> | undefined, base?: FhirPrimitiveElement): FhirPrimitiveElement | undefined;
8
8
  export declare function mergeTranslationPrimitiveElement(base: FhirPrimitiveElement | undefined, translations: Record<string, string> | undefined): FhirPrimitiveElement | undefined;
9
9
  export declare function getPrimitiveTranslation(element: FhirR6PrimitiveElement | undefined, locale: string | undefined): string | undefined;
10
- export declare function getPrimitiveTranslations(element: FhirR6PrimitiveElement | undefined): Record<string, string> | undefined;
10
+ export declare function getPrimitiveTranslations(element: FhirR6PrimitiveElement | undefined, fallback?: Record<string, string>): Record<string, string> | undefined;
package/dist/fhir.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { ParseOptions } from "./types";
2
2
  import type { HpsgClinicalQuantityFeature } from "./hpsg/signature";
3
3
  import { ParserState } from "./parser-state";
4
- import { CanonicalAdditionalInstructionExpr, CanonicalInstructionGraph, CanonicalActivityTimingExpr, CanonicalCycleDayConstraint, CanonicalOccurrenceCapExpr, CanonicalDoseRange, CanonicalSigClause, CanonicalScheduleExpr, EventTiming, FhirCodeableConcept, FhirR6CodeableConcept, FhirDosage, FhirExtension, FhirR6Extension, FhirR6Dosage, FhirR6Quantity, FhirRange, FhirR6Range, FhirTiming, FhirTimingRepeat, FhirR6TimingRepeat } from "./types";
4
+ import { CanonicalAdditionalInstructionExpr, CanonicalClinicalAdjuncts, CanonicalInstructionGraph, CanonicalActivityTimingExpr, CanonicalCycleDayConstraint, CanonicalOccurrenceCapExpr, CanonicalDoseRange, CanonicalDoseExpr, CanonicalSigClause, CanonicalScheduleExpr, EventTiming, FhirCodeableConcept, FhirR6CodeableConcept, FhirDosage, FhirExtension, FhirR6Extension, FhirR6Dosage, FhirR6Quantity, FhirRange, FhirR6Range, FhirTiming, FhirTimingRepeat, FhirR6TimingRepeat } from "./types";
5
5
  /** Known modifier: an independent cadence is restricted by unresolved cycle days. */
6
6
  export declare const CYCLE_DAY_ELIGIBILITY_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-cycle-day-eligibility";
7
7
  /** Read the recognized cycle constraint without interpreting narrative text.
@@ -13,14 +13,21 @@ export declare function getCycleDayConstraint(dosage: FhirDosage | FhirR6Dosage)
13
13
  */
14
14
  export declare function cycleDayConstraintExtension(constraint: CanonicalCycleDayConstraint, previous?: FhirExtension): FhirExtension;
15
15
  export declare const TIMING_FREQUENCY_MIN_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-frequency-min";
16
+ /** Divided administrations share the active treatment day of a civil-day interval. */
17
+ export declare const TIMING_FREQUENCY_WITHIN_DAY_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-frequency-within-day";
16
18
  /** Qualified per-administration duration, independent of a scalar rate denominator. */
17
19
  export declare const TIMING_ADMINISTRATION_DURATION_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:timing-administration-duration";
18
20
  /** Decode one classified marker without flattening independent endpoints. */
19
- export declare function parseTimingAdministrationDuration(extension: FhirR6Extension | undefined, current?: Pick<FhirTimingRepeat, "duration" | "durationMax" | "durationUnit">): (Partial<NonNullable<HpsgClinicalQuantityFeature["administrationDuration"]>> & {
21
+ export declare function parseTimingAdministrationDuration(extension: FhirR6Extension | undefined, current?: Pick<FhirR6TimingRepeat, "duration" | "durationMax" | "durationUnit">): (Partial<NonNullable<HpsgClinicalQuantityFeature["administrationDuration"]>> & {
20
22
  range?: import("./canonical/course").CanonicalRange;
21
23
  }) | undefined;
22
24
  /** Modifier: each retained base-schedule opportunity occurs this many minutes later. */
23
25
  export declare const ADMINISTRATION_OFFSET_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-administration-offset";
26
+ /** Modifier: a selective condition cannot allocate the authored shared amount. */
27
+ export declare const CONDITION_ALLOCATION_UNRESOLVED_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-condition-allocation-unresolved";
28
+ /** Keep the selective site's allowance in its own modifier, never on the whole dose. */
29
+ export declare function buildConditionAllocationUnresolvedExtension(target?: CanonicalClinicalAdjuncts["conditionTarget"]): FhirExtension;
30
+ export declare function conditionAllocationTargetFromExtension(marker: FhirR6Extension): CanonicalClinicalAdjuncts["conditionTarget"];
24
31
  export declare function getAdministrationOffsetMinutes(dosage: FhirDosage | FhirR6Dosage): number | undefined;
25
32
  /** Modifier retaining a course duration alongside its absolute calendar bounds. */
26
33
  export declare const ANCHORED_COURSE_DURATION_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-anchored-course-duration";
@@ -101,7 +108,14 @@ export declare const TIMING_OCCURRENCE_CAP_EXTENSION_URL = "urn:ezmedicationinpu
101
108
  export declare const TIMING_SHARED_COUNT_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-shared-count";
102
109
  export declare const TIMING_EVENT_CALENDAR_SOURCE_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-timing-event-calendar-source";
103
110
  export declare const PRN_TRIGGER_PHASE_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-prn-trigger-phase";
111
+ /** Explicit counted per-target allocation; anatomical cardinality alone is not this fact. */
112
+ export declare const DOSAGE_DOSE_ALLOCATION_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-dose-allocation";
113
+ export declare function getDosageDoseAllocation(dosage: {
114
+ modifierExtension?: FhirR6Extension[];
115
+ }): CanonicalDoseExpr["allocation"];
104
116
  export declare const BODY_SITE_RESTRICTION_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-body-site-restriction";
117
+ /** An explicitly authored vehicle volume, independent of active dose or rate. */
118
+ export declare const INFUSION_CARRIER_VOLUME_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-infusion-carrier-volume";
105
119
  export declare const INFUSION_CARRIER_MATERIAL_EXTENSION_URL = "urn:ezmedicationinput:StructureDefinition:medication-infusion-carrier-material";
106
120
  /** Draft FHIR R5 extension definition, produced from the same typed child
107
121
  * contract as the live encoder. Carrier material is a descriptive vehicle
@@ -187,6 +201,10 @@ export declare function buildInfusionCarrierMaterialStructureDefinition(): {
187
201
  * changes dose/rate scheduling or converts a vehicle into the active drug.
188
202
  */
189
203
  export declare function infusionCarrierMaterialExtension(material: NonNullable<HpsgClinicalQuantityFeature["carrierMaterial"]>): FhirExtension;
204
+ /** Typed FHIR extraction: retain only supplied extension children, never
205
+ * guess a vehicle from original SIG text or volume/mass alone.
206
+ */
207
+ export declare function infusionCarrierMaterialFromFhir(dosage: FhirDosage): HpsgClinicalQuantityFeature["carrierMaterial"];
190
208
  /** Reconstitute dimensional R5 meaning only where the role and amount were
191
209
  * explicitly supplied. Other external rateRatio dosages remain untouched.
192
210
  */
@@ -226,8 +244,10 @@ export declare function extractCanonicalDoseRange(range: FhirRange): {
226
244
  * are read back from this interchange object. R5/R6 adapters own their own
227
245
  * quantity and timing choices around the same exact clinical code payload. */
228
246
  export declare function serializeCanonicalContext(clause: CanonicalSigClause, options?: FhirProjectionOptions): Pick<FhirDosage, "extension" | "route" | "site" | "method" | "additionalInstruction" | "asNeeded" | "asNeededFor" | "patientInstruction">;
229
- /** Core Timing offsets require a nonnegative integer and a qualified event anchor. */
230
- export declare function canUseCoreTimingOffset(when: readonly (string | null)[] | undefined, offset: number | undefined): boolean;
247
+ /** Core Timing offsets require a nonnegative integer and a supplied when
248
+ * element without a neutral meal code. An extension-only primitive is still
249
+ * a supplied element; its annotation does not invent an event identity. */
250
+ export declare function canUseCoreTimingOffset(when: readonly (string | null)[] | undefined, offset: number | undefined, suppliedWhenElement?: boolean): boolean;
231
251
  /** Shared wire Timing/source metadata serializer. This projects the already
232
252
  * scoped canonical schedule; it never parses or interprets external dosage.
233
253
  * R5 and current-R6 adapters independently choose their Quantity encodings. */
package/dist/format.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import type { CourseLanguage } from "./localization";
2
2
  import { ParserState } from "./parser-state";
3
- import { type SigLocalization, type SigLongContext, type SigDoseScope } from "./i18n";
3
+ import { resolveNativeClauseRendering, type SigLocalization, type SigLongContext } from "./i18n";
4
4
  import { type InstructionGraphPrimaryCondition } from "./instruction-graph";
5
- import { type AdviceFrame, type CanonicalAdditionalInstructionExpr, CanonicalDoseExpr, CanonicalScheduleExpr, CanonicalSigClause, EventTiming, FhirPeriodUnit, type MedicationCondition, type FhirDayOfWeek } from "./types";
5
+ import { type AdviceFrame, type CanonicalAdditionalInstructionExpr, CanonicalScheduleExpr, CanonicalSigClause, EventTiming, FhirPeriodUnit, type MedicationCondition, type FhirDayOfWeek } from "./types";
6
6
  import { type TimingSummaryOptions } from "./timing-summary";
7
- export declare const DAY_NAMES: Record<string, string>;
7
+ export declare function scheduleOf(clause: CanonicalSigClause): CanonicalScheduleExpr;
8
8
  /** A method can name a registered manner rather than an action head. */
9
9
  export declare function registeredMethodManner(method: CanonicalSigClause["method"], resolvedMethod?: SigLongContext["resolvedMethod"]): import("./types").AdditionalInstructionDefinition | undefined;
10
10
  export declare function alternateDayEvent(schedule: CanonicalScheduleExpr | undefined): EventTiming | undefined;
@@ -14,7 +14,7 @@ export declare function alternateDayEvent(schedule: CanonicalScheduleExpr | unde
14
14
  * @param schedule Typed timing to realize; source text is never inspected.
15
15
  */
16
16
  export declare function hasDailyRecurrenceAcrossClocks(schedule: CanonicalScheduleExpr | undefined): boolean;
17
- type FrequencyDisplayMode = "daily" | "daily-count" | "daily-range" | "daily-maximum" | "period" | "period-maximum" | "alternate-days" | "calendar-count" | "calendar-range" | "calendar-maximum" | "code" | "code-period" | "count" | "count-bounds";
17
+ type FrequencyDisplayMode = "daily" | "daily-count" | "daily-range" | "daily-maximum" | "period" | "period-maximum" | "alternate-days" | "treatment-day-count" | "calendar-count" | "calendar-range" | "calendar-maximum" | "code" | "code-period" | "count" | "count-bounds";
18
18
  interface FrequencyDisplay {
19
19
  mode: FrequencyDisplayMode;
20
20
  countPrefix: "none" | "count" | "range" | "maximum";
@@ -30,15 +30,12 @@ interface FrequencyDisplay {
30
30
  periodUnit: FhirPeriodUnit;
31
31
  };
32
32
  }
33
+ /** Select the independent cadence label; a selected event owns its own identity. */
34
+ export declare function timingPreviewCadenceCode(code: string, schedule: CanonicalScheduleExpr): string | undefined;
33
35
  /** Select clinical display meaning once; each locale retains its wording. */
34
36
  export declare function frequencyDisplay(schedule: CanonicalScheduleExpr | undefined, uppercaseTimingCode?: boolean): FrequencyDisplay | undefined;
35
37
  export declare function standaloneOccurrenceCount(schedule: CanonicalScheduleExpr | undefined): number | undefined;
36
- /** A typed scalar/range, or an already complete native rich amount, can be
37
- * labelled without selecting it as the administration's prescribed dose. */
38
- export declare function formatDoseEnglish(dose: CanonicalDoseExpr | string, style: "short" | "long", scope?: SigDoseScope): string | undefined;
39
- export declare function joinWithAnd(parts: string[]): string;
40
- /** Discrete doses distribute across paired targets; metric amounts are totals. */
41
- export declare function doseUnitUsesTargetScope(unit: string | undefined): boolean;
38
+ export { doseUnitUsesTargetScope } from "./body-site-target";
42
39
  /** Whether the recurrence supports describing selected days as occurring each month. */
43
40
  export declare function dayOfMonthUsesSingleMonth(schedule: CanonicalScheduleExpr | undefined): boolean;
44
41
  export declare function formatDurationShort(schedule: CanonicalScheduleExpr): string | undefined;
@@ -52,14 +49,18 @@ export interface DurationWording {
52
49
  readonly lower: string;
53
50
  administrationUnit(unit: FhirPeriodUnit, value: number | undefined, maximum: number | undefined, short: boolean, words: CourseLanguage): string;
54
51
  }
55
- export declare function describeDuration(schedule: CanonicalScheduleExpr | undefined, words: CourseLanguage, text?: DurationWording): string | undefined;
56
- export declare function describeAdministrationDuration(schedule: CanonicalScheduleExpr | undefined, short?: boolean, words?: CourseLanguage, text?: DurationWording, prefix?: string): string | undefined;
57
- /** Preserve free labels; recognized cadence prose yields to a typed recurrence. */
58
- export declare function independentTimingText(code: string | undefined, recurrence?: Pick<CanonicalScheduleExpr, "frequency" | "frequencyMax" | "period" | "periodMax" | "periodUnit">): string | undefined;
59
- export declare function timingCodeMatchesRecurrence(schedule: Pick<CanonicalScheduleExpr, "timingCode" | "frequency" | "frequencyMax" | "period" | "periodMax" | "periodUnit" | "when" | "timeOfDay">, code?: string | undefined): boolean;
52
+ export declare function describeDuration(schedule: CanonicalScheduleExpr | undefined, words: CourseLanguage, text: DurationWording): string | undefined;
53
+ export declare function describeAdministrationDuration(schedule: CanonicalScheduleExpr | undefined, short: boolean, words: CourseLanguage, text: DurationWording, prefix?: string): string | undefined;
54
+ type TimingPreviewRecurrence = Pick<CanonicalScheduleExpr, "frequency" | "frequencyMax" | "period" | "periodMax" | "periodUnit"> & {
55
+ when?: readonly (string | null)[];
56
+ timeOfDay?: readonly (string | null)[];
57
+ };
58
+ /** Preserve free labels and independently selected cadence beside a range. */
59
+ export declare function independentTimingText(code: string | undefined, recurrence?: TimingPreviewRecurrence): string | undefined;
60
+ export declare function timingCodeMatchesRecurrence(schedule: TimingPreviewRecurrence & Pick<CanonicalScheduleExpr, "timingCode">, code?: string | undefined): boolean;
60
61
  /** A code-only event supplies display meaning without changing authored timing. */
61
62
  export declare function timingEventPreviewSchedule(schedule: CanonicalScheduleExpr | undefined): CanonicalScheduleExpr | undefined;
62
- interface LongAdministrationTimingParts {
63
+ export interface LongAdministrationTimingParts {
63
64
  frequency?: string;
64
65
  event?: string;
65
66
  eventWindow?: string;
@@ -73,6 +74,7 @@ interface LongAdministrationTimingParts {
73
74
  administrationDuration?: string;
74
75
  duration?: string;
75
76
  occurrenceCap?: string;
77
+ administrationNote?: string;
76
78
  }
77
79
  interface RichAdministrationParts {
78
80
  route?: string;
@@ -84,12 +86,7 @@ interface RichAdministrationParts {
84
86
  coversSingleEvent: boolean;
85
87
  }
86
88
  /** Locale realizers supply words; their clinical timing order is shared. */
87
- export declare function describeClockWindow(schedule: CanonicalScheduleExpr | undefined, timing?: {
88
- sharedAdministration: (body: string, total?: string) => string;
89
- clockWindow: (start: string, end: string, inclusive: boolean) => string;
90
- offset: (minutes: number) => string;
91
- dayShift: (days: number) => string;
92
- }): string | undefined;
89
+ export declare function describeClockWindow(schedule: CanonicalScheduleExpr | undefined, timing: ReturnType<typeof resolveNativeClauseRendering>["timing"]): string | undefined;
93
90
  export declare function appendLongAdministrationTiming(parts: string[], timing: LongAdministrationTimingParts, richTiming?: RichAdministrationParts): void;
94
91
  export declare function richGraphAdministrationTail(clause: CanonicalSigClause, action: AdviceFrame, timing: LongAdministrationTimingParts, parts: RichAdministrationParts): string[];
95
92
  export declare function instructionGraphMatchesDose(clause: CanonicalSigClause): boolean;
@@ -106,11 +103,13 @@ export declare function composeNativePrimaryDirections(rendered: string, authore
106
103
  current?: string;
107
104
  }, clause?: CanonicalSigClause): string;
108
105
  export declare function isEmptyStomachInstruction(instruction: CanonicalAdditionalInstructionExpr): boolean;
106
+ /** One locale-owned allowance label for a selected shared administration group. */
107
+ export declare function formatSharedAdministration(body: string, shared: Pick<NonNullable<CanonicalScheduleExpr["sharedCount"]>, "count" | "countMax">, localization?: SigLocalization): string;
109
108
  export declare function formatNativeCanonicalClause(clause: CanonicalSigClause, style: "short" | "long", localization?: SigLocalization, options?: TimingSummaryOptions, authoredPrimary?: string, deferredDirections?: {
110
109
  text?: string;
111
110
  current?: string;
112
- }, sharedCountAlreadyDisplayed?: boolean): string;
111
+ }, sharedCountAlreadyDisplayed?: boolean, administrationTimingNote?: string): string;
113
112
  export declare function formatCanonicalClause(clause: CanonicalSigClause, style: "short" | "long", localization?: SigLocalization, options?: TimingSummaryOptions, nativeDefault?: (target: "short" | "long") => string): string;
114
113
  export declare function formatInternal(internal: ParserState, style: "short" | "long", localization?: SigLocalization, options?: TimingSummaryOptions): string;
115
114
  export declare function stripTrailingZero(value: number): string;
116
- export {};
115
+ export { DAY_NAMES, formatDoseEnglish, joinWithAnd } from "./locales/clause/en";
@@ -1,3 +1,4 @@
1
+ import { type MedicationConditionLexicalFeatures } from "../medication-condition";
1
2
  import type { Token } from "../parser-state";
2
3
  import type { MedicationCondition, ParseOptions } from "../types";
3
4
  import { AdviceArgumentRole, AdviceRelation, type AdviceArgument, type AdviceFrame } from "../types";
@@ -64,12 +65,18 @@ export declare function selectHpsgCalendarClockEllipsisConstruction(facts: HpsgC
64
65
  timeOfDay: string[];
65
66
  }) | undefined;
66
67
  /**
67
- * A shared directive scopes over coordinated action daughters. An explicit
68
- * directive on the right starts its own scope; sequencing is not coordination.
69
- * A trailing duration is an adjunct of the coordinated prohibition, not a
70
- * medication-course bound. This construction consumes typed action meaning.
68
+ * A selected shared-polarity link joins the immediately preceding negative
69
+ * daughter. Explicit directives and positive administrations start new groups.
70
+ * Consumers must use the original selected frame order, not a filtered subset.
71
71
  */
72
- export declare function composeCoordinatedActionDirective(left: AdviceFrame, right: AdviceFrame, coordination: "conjunction" | "disjunction" | "unknown", explicitRightDirective: boolean): readonly [AdviceFrame, AdviceFrame];
72
+ export declare function sharedNegativeActionGroupStart(frames: readonly AdviceFrame[], endIndex?: number): number | undefined;
73
+ /**
74
+ * The existing typed coordination owns one directive's polarity and modality.
75
+ * A trailing temporal qualification applies to every daughter of that selected
76
+ * group. Explicit local temporal scope remains local; material
77
+ * and Amount arguments never become shared temporal qualifications.
78
+ */
79
+ export declare function composeCoordinatedActionDirective(frames: AdviceFrame[], right: AdviceFrame, coordination: "conjunction" | "disjunction" | "unknown", explicitRightDirective: boolean): AdviceFrame;
73
80
  /** A contact clause licenses a preposed physical theme, as in a directive
74
81
  * preventing a bottle tip from touching the eye. A nominal and contact head
75
82
  * are required; the causative marker cannot turn an ordinary GIVE into this
@@ -83,6 +90,10 @@ export interface ParsedMedicationGuard {
83
90
  start: number;
84
91
  markerEnd: number;
85
92
  end: number;
93
+ /** Administration head already selected by the guard's consequent construction. */
94
+ administrationStart?: number;
95
+ /** Selected registered withholding consequent; it does not administer a choice dose. */
96
+ withholdingConsequent?: true;
86
97
  text: string;
87
98
  otherwiseHold: boolean;
88
99
  otherwise?: {
@@ -93,6 +104,8 @@ export interface ParsedMedicationGuard {
93
104
  start: number;
94
105
  end: number;
95
106
  };
107
+ /** Selected positive alternative dose, with an explicit or omitted administration head. */
108
+ alternativeDoseStart?: number;
96
109
  /** Authoritative typed derivation reused by the main clause chart. */
97
110
  sign: HpsgSign;
98
111
  }
@@ -103,6 +116,9 @@ export declare function guardHasMeasurement(value: MedicationCondition): boolean
103
116
  * @param scope Existing clinical scope sign (including otherwise-hold ownership).
104
117
  */
105
118
  export declare function scopeMedicationGuardSign(guard: ParsedMedicationGuard, scope: HpsgSign): HpsgSign;
119
+ /** An opaque consequent can select a closed predicate without exporting a
120
+ * medication guard or inventing a typed action inside that consequent. */
121
+ export declare function hasFrontedInstructionCondition(source: string, tokens: Token[], head: Token, end: number, lexicon: MedicationConditionLexicalFeatures): boolean;
106
122
  /** Single source of medication-guard meaning: lexical daughters compose via
107
123
  * HPSG predicate/coordination/head constructions, reused by planner and chart.
108
124
  * @param source Exact clinician text.
@@ -117,3 +133,6 @@ export declare function parseMedicationGuard(source: string, existingTokens?: To
117
133
  markerEnd: number;
118
134
  end?: number;
119
135
  }): ParsedMedicationGuard | undefined;
136
+ /** Continue through each selected guard and branch in the same typed grammar
137
+ * so every independent administration retains its own condition scope. */
138
+ export declare function parseMedicationGuards(source: string, tokens: Token[], options?: ParseOptions): ParsedMedicationGuard[];