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.
Files changed (44) hide show
  1. package/README.md +25 -22
  2. package/dist/advice.d.ts +20 -0
  3. package/dist/body-site-grammar.d.ts +34 -1
  4. package/dist/date-interpretation.d.ts +2 -0
  5. package/dist/dosage-course.d.ts +188 -0
  6. package/dist/fhir.d.ts +144 -9
  7. package/dist/format.d.ts +9 -1
  8. package/dist/hpsg/constructions.d.ts +105 -0
  9. package/dist/hpsg/lexical-classes.d.ts +170 -1
  10. package/dist/hpsg/procedural-context.d.ts +15 -1
  11. package/dist/hpsg/projection.d.ts +10 -2
  12. package/dist/hpsg/rule-context.d.ts +13 -0
  13. package/dist/hpsg/rules/clinical-quantity-rules.d.ts +9 -0
  14. package/dist/hpsg/rules/condition-rules.d.ts +15 -0
  15. package/dist/hpsg/rules/core-rules.d.ts +29 -0
  16. package/dist/hpsg/rules/instruction-rules.d.ts +9 -1
  17. package/dist/hpsg/rules/timing-rules.d.ts +121 -7
  18. package/dist/hpsg/signature.d.ts +342 -4
  19. package/dist/hpsg/type-system.d.ts +16 -1
  20. package/dist/hpsg/unification.d.ts +1 -0
  21. package/dist/i18n.d.ts +2 -0
  22. package/dist/index.cjs +48961 -31422
  23. package/dist/index.d.ts +21 -5
  24. package/dist/index.js +48936 -31421
  25. package/dist/instruction-action-locale-adapter.d.ts +1 -0
  26. package/dist/instruction-action-terminology.d.ts +16 -1
  27. package/dist/instruction-concept-terminology.d.ts +1 -1
  28. package/dist/instruction-graph-fhir.d.ts +1 -1
  29. package/dist/instruction-graph.d.ts +38 -2
  30. package/dist/ir.d.ts +12 -1
  31. package/dist/maps.d.ts +15 -0
  32. package/dist/medication-condition.d.ts +42 -0
  33. package/dist/parser-state.d.ts +5 -1
  34. package/dist/parser.d.ts +5 -2
  35. package/dist/regimen/coordination-scope.d.ts +53 -0
  36. package/dist/regimen/grammar.d.ts +68 -0
  37. package/dist/regimen/parallel-course.d.ts +85 -0
  38. package/dist/regimen/planner.d.ts +19 -0
  39. package/dist/regimen/regimen.d.ts +66 -0
  40. package/dist/schedule.d.ts +9 -6
  41. package/dist/stable-structure.d.ts +23 -1
  42. package/dist/types.d.ts +433 -28
  43. package/dist/utils/strength.d.ts +16 -0
  44. package/package.json +3 -2
package/dist/types.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { SigTranslationConfig } from "./i18n";
2
2
  export interface FhirCoding {
3
3
  system?: string;
4
+ /** Terminology edition used to define this code. */
5
+ version?: string;
4
6
  code?: string;
5
7
  display?: string;
6
8
  extension?: FhirExtension[];
@@ -14,16 +16,30 @@ export interface FhirCodeableConcept {
14
16
  _text?: FhirPrimitiveElement;
15
17
  }
16
18
  export interface FhirExtension {
19
+ id?: string;
17
20
  url: string;
18
21
  extension?: FhirExtension[];
19
22
  valueCode?: string;
20
23
  valueString?: string;
24
+ valueDate?: string;
21
25
  valueBoolean?: boolean;
22
26
  valueInteger?: number;
23
27
  valueDecimal?: number;
24
28
  valueQuantity?: FhirQuantity;
25
29
  valueCoding?: FhirCoding;
26
30
  valueCodeableConcept?: FhirCodeableConcept;
31
+ valueUri?: string;
32
+ valueCanonical?: string;
33
+ valueDateTime?: string;
34
+ valueTime?: string;
35
+ valuePositiveInt?: number;
36
+ valueUnsignedInt?: number;
37
+ valueRange?: FhirRange;
38
+ valueRatio?: FhirRatio;
39
+ valueExpression?: FhirExpression;
40
+ valueReference?: NonNullable<FhirCodeableReference["reference"]>;
41
+ valueCodeableReference?: FhirCodeableReference;
42
+ valueTiming?: FhirTiming;
27
43
  }
28
44
  export interface FhirElement {
29
45
  id?: string;
@@ -32,14 +48,20 @@ export interface FhirElement {
32
48
  export interface FhirBackboneElement extends FhirElement {
33
49
  modifierExtension?: FhirExtension[];
34
50
  }
35
- export interface FhirPrimitiveElement {
36
- extension?: FhirExtension[];
37
- }
38
- export interface FhirQuantity {
51
+ /** FHIR primitive metadata can carry both Element.id and extensions. */
52
+ export type FhirPrimitiveElement = FhirElement;
53
+ export interface FhirQuantity extends FhirElement {
39
54
  value?: number;
55
+ /** FHIR R5 Quantity comparator. 'ad' was added in R5. */
56
+ comparator?: "<" | "<=" | ">=" | ">" | "ad";
40
57
  unit?: string;
41
58
  system?: string;
42
59
  code?: string;
60
+ /** Primitive Element metadata is valid on every FHIR Quantity specialization. */
61
+ _value?: FhirPrimitiveElement;
62
+ _unit?: FhirPrimitiveElement;
63
+ _system?: FhirPrimitiveElement;
64
+ _code?: FhirPrimitiveElement;
43
65
  }
44
66
  export type DoseUnitKind = "metric" | "biologic_unit" | "counted_presentation" | "device_actuation" | "infusion_rate" | "product_specific_amount" | "length_of_product" | "body_area_proxy" | "qualitative_amount";
45
67
  export type DoseUnitApproximationConfidence = "exact" | "approximate" | "product_specific";
@@ -73,13 +95,21 @@ export interface EstimatedQuantity extends FhirQuantity {
73
95
  basis?: string;
74
96
  source?: string;
75
97
  }
76
- export interface FhirRange {
77
- low?: FhirQuantity;
78
- high?: FhirQuantity;
79
- }
80
- export interface FhirRatio {
98
+ /** FHIR SimpleQuantity: Quantity with the comparator constrained to absent. */
99
+ export type FhirSimpleQuantity = Omit<FhirQuantity, "comparator"> & {
100
+ comparator?: never;
101
+ };
102
+ /** FHIR R6 also supports the approximate (~) comparator in general Quantity. */
103
+ export type FhirR6Quantity = Omit<FhirQuantity, "comparator"> & {
104
+ comparator?: FhirQuantity["comparator"] | "~";
105
+ };
106
+ export interface FhirRange extends FhirElement {
107
+ low?: FhirSimpleQuantity;
108
+ high?: FhirSimpleQuantity;
109
+ }
110
+ export interface FhirRatio extends FhirElement {
81
111
  numerator?: FhirQuantity;
82
- denominator?: FhirQuantity;
112
+ denominator?: FhirSimpleQuantity;
83
113
  }
84
114
  /**
85
115
  * Follows https://build.fhir.org/valueset-event-timing.html
@@ -333,15 +363,131 @@ export interface FhirTiming extends FhirElement {
333
363
  repeat?: FhirTimingRepeat;
334
364
  code?: FhirCodeableConcept;
335
365
  }
366
+ /** FHIR Expression: enough structure to preserve external R6 dose/rate expressions. */
367
+ export interface FhirExpression extends FhirElement {
368
+ description?: string;
369
+ name?: string;
370
+ /** FHIR R5/R6 Expression.language is optional (0..1). */
371
+ language?: string;
372
+ expression?: string;
373
+ reference?: string;
374
+ }
336
375
  export interface FhirDoseAndRate extends FhirBackboneElement {
337
376
  type?: FhirCodeableConcept;
338
377
  doseRange?: FhirRange;
339
- doseQuantity?: FhirQuantity;
378
+ doseQuantity?: FhirSimpleQuantity;
340
379
  rateRatio?: FhirRatio;
341
380
  rateRange?: FhirRange;
342
- rateQuantity?: FhirQuantity;
381
+ rateQuantity?: FhirSimpleQuantity;
382
+ }
383
+ /** R6 additions to the R5 DoseAndRate child object. */
384
+ export interface EzDoseAndRate extends FhirDoseAndRate {
385
+ doseExpression?: FhirExpression;
386
+ rateExpression?: FhirExpression;
387
+ }
388
+ /**
389
+ * The meaning of a condition is independent of its wording.
390
+ * all/any/not are explicit: FHIR R6 condition[] alone is OR, not AND.
391
+ * Free-text predicates remain representable but need a caller evaluator.
392
+ */
393
+ export type MedicationCondition = {
394
+ kind: "measurement";
395
+ name: string;
396
+ operation: "gt" | "ge" | "lt" | "le" | "eq" | "ne";
397
+ value: number;
398
+ unit?: string;
399
+ text: string;
400
+ } | {
401
+ kind: "state";
402
+ name: string;
403
+ text: string;
404
+ expected: boolean;
405
+ } | {
406
+ kind: "text";
407
+ text: string;
408
+ } | {
409
+ kind: "not";
410
+ condition: MedicationCondition;
411
+ } | {
412
+ kind: "all" | "any";
413
+ conditions: MedicationCondition[];
414
+ };
415
+ /** FHIR R6 draft DosageCondition compatible subset. */
416
+ export interface FhirR6DosageCondition extends FhirBackboneElement {
417
+ code: FhirCodeableConcept;
418
+ details?: FhirCodeableConcept;
419
+ operation?: "eq" | "ne" | "in" | "nin" | "gt" | "lt" | "ge" | "le" | "sa" | "eb" | "ap";
420
+ valueBoolean?: boolean;
421
+ valueQuantity?: FhirR6Quantity;
422
+ valueString?: string;
423
+ text?: string;
424
+ }
425
+ /** FHIR R6 DosageSafety.doseLimit.value[x] is a required choice. */
426
+ export type FhirR6DoseLimit = FhirBackboneElement & {
427
+ scope: "dosage" | "period" | "administration" | "lifetime";
428
+ period?: FhirQuantity;
429
+ text?: string;
430
+ } & ({
431
+ valueQuantity: FhirR6Quantity;
432
+ valueInteger?: never;
433
+ valueExpression?: never;
434
+ } | {
435
+ valueInteger: number;
436
+ valueQuantity?: never;
437
+ valueExpression?: never;
438
+ } | {
439
+ valueExpression: FhirExpression;
440
+ valueQuantity?: never;
441
+ valueInteger?: never;
442
+ });
443
+ export interface FhirR6DosageSafety extends FhirBackboneElement {
444
+ doseLimit?: FhirR6DoseLimit[];
445
+ ifExceeded?: string;
446
+ }
447
+ /** FHIR R6 CodeableReference allows either a concept or resource reference. */
448
+ export interface FhirCodeableReference {
449
+ concept?: FhirCodeableConcept;
450
+ reference?: {
451
+ reference?: string;
452
+ type?: string;
453
+ display?: string;
454
+ };
455
+ }
456
+ /** FHIR R6 draft Dosage: no R5 sequence/legacy maxima/PRN alias. */
457
+ export interface FhirR6Dosage extends Omit<FhirDosage, "sequence" | "site" | "maxDosePerPeriod" | "maxDosePerAdministration" | "maxDosePerLifetime" | "doseAndRate"> {
458
+ condition?: FhirR6DosageCondition[];
459
+ site?: FhirCodeableReference;
460
+ doseAndRate?: EzDoseAndRate[];
461
+ safety?: FhirR6DosageSafety;
462
+ }
463
+ export interface FhirR6RelativeTime extends FhirBackboneElement {
464
+ contextReference?: {
465
+ reference?: string;
466
+ };
467
+ contextDefinition?: string;
468
+ contextPath?: string;
469
+ contextCode?: FhirCodeableConcept;
470
+ offsetDuration?: FhirQuantity;
471
+ offsetRange?: FhirRange;
472
+ text?: string;
473
+ }
474
+ export interface FhirR6DosageStep extends FhirBackboneElement {
475
+ start?: FhirR6RelativeTime;
476
+ end?: FhirR6RelativeTime;
477
+ count?: number;
478
+ component: FhirR6Dosage[];
479
+ safety?: FhirR6DosageSafety;
480
+ }
481
+ /** R6's step/component course representation. */
482
+ export interface FhirR6DosageDetails extends FhirBackboneElement {
483
+ renderedInstruction?: string;
484
+ repeatCycle?: FhirQuantity;
485
+ step: FhirR6DosageStep[];
486
+ safety?: FhirR6DosageSafety;
343
487
  }
344
488
  export interface FhirDosage extends FhirBackboneElement {
489
+ /** FHIR R5 ordering: equal sequences are concurrent, increasing sequences are sequential. */
490
+ sequence?: number;
345
491
  text?: string;
346
492
  patientInstruction?: string;
347
493
  timing?: FhirTiming;
@@ -349,9 +495,48 @@ export interface FhirDosage extends FhirBackboneElement {
349
495
  site?: FhirCodeableConcept;
350
496
  method?: FhirCodeableConcept;
351
497
  additionalInstruction?: FhirCodeableConcept[];
352
- asNeededBoolean?: boolean;
498
+ /** FHIR R5 spelling. */
499
+ asNeeded?: boolean;
353
500
  asNeededFor?: FhirCodeableConcept[];
354
501
  doseAndRate?: FhirDoseAndRate[];
502
+ maxDosePerPeriod?: FhirRatio[];
503
+ maxDosePerAdministration?: FhirSimpleQuantity;
504
+ maxDosePerLifetime?: FhirSimpleQuantity;
505
+ }
506
+ /**
507
+ * EZMED's primary dose object. Retains the useful FHIR R5 Dosage shape and
508
+ * lifts a small number of actual R6 features into optional typed fields.
509
+ * This is NOT strict FHIR R5 JSON: call toFhirR5Dosages() for wire export.
510
+ */
511
+ export interface EzDosage extends Omit<FhirDosage, "doseAndRate"> {
512
+ doseAndRate?: EzDoseAndRate[];
513
+ /** FHIR R6 Dosage.condition, including compound conditions when needed. */
514
+ condition?: FhirR6DosageCondition[];
515
+ /** FHIR R6 Dosage.safety, alongside the R5 maximum fields. */
516
+ safety?: FhirR6DosageSafety;
517
+ /** FHIR R6 Dosage.site.reference, while site remains R5 CodeableConcept. */
518
+ siteReference?: FhirCodeableReference["reference"];
519
+ /** EZMED-specific dates omitted from a repeating schedule; not an HL7 core field. */
520
+ excludedDates?: string[];
521
+ }
522
+ /**
523
+ * Small amount of course-level metadata that does not logically belong to an
524
+ * individual dosage. Each step row addresses the usual R5 Dosage.sequence.
525
+ * The fields under step come directly from FHIR R6 DosageDetails.step.
526
+ */
527
+ export interface EzCourseStep extends FhirBackboneElement {
528
+ /** R5 global sequence corresponding to this R6 step. */
529
+ sequence: number;
530
+ start?: FhirR6RelativeTime;
531
+ end?: FhirR6RelativeTime;
532
+ count?: number;
533
+ safety?: FhirR6DosageSafety;
534
+ }
535
+ export interface EzCourseMetadata extends FhirBackboneElement {
536
+ renderedInstruction?: string;
537
+ repeatCycle?: FhirQuantity;
538
+ safety?: FhirR6DosageSafety;
539
+ step?: EzCourseStep[];
355
540
  }
356
541
  export type RouteCode = SNOMEDCTRouteCodes;
357
542
  export declare const RouteCode: typeof SNOMEDCTRouteCodes;
@@ -366,7 +551,8 @@ export interface MedicationContext {
366
551
  /** "Simple" strength string; might be the only way strength is provided
367
552
  * for discrete units this is the amount of medication for unit e.g. "500 mg" (1 tablet), or for mixed tablets might be like "400 mg + 80 mg"
368
553
  * for things like creams or fluids or syrupsit might be "2%", 5 g/100g, 100mg/ 100 g, 262 mg/15 mL, 200 mg/2 mL, 1 mg/dL, or "400 mg/5mL + 80 mg/5mL"
369
- * In the "x + y" case, the strengthQuantity/strengthRatio will be the sum of the two ingredients.
554
+ * For combination products, individual ingredient strengths must remain
555
+ * separate; never sum the parts into one strengthQuantity/strengthRatio.
370
556
  */
371
557
  strength?: string;
372
558
  strengthQuantity?: FhirQuantity;
@@ -432,11 +618,35 @@ export interface BodySiteSpatialRelation {
432
618
  targetCoding?: BodySiteCode;
433
619
  sourceText?: string;
434
620
  }
621
+ export type BodySiteRestrictionPredicateForm = "state" | "existential" | "raw";
622
+ /**
623
+ * A source-backed predicate that narrows an administration site. It is not a
624
+ * diagnosis or a regimen-wide execution condition.
625
+ */
626
+ export interface BodySiteRestrictionPredicate {
627
+ text: string;
628
+ lemma?: string;
629
+ form: BodySiteRestrictionPredicateForm;
630
+ /** Predicate payload after a declarative introducer such as "there is". */
631
+ focusText?: string;
632
+ range?: TextRange;
633
+ }
634
+ /** A restrictive relative clause attached locally to a body-site sign. */
635
+ export interface BodySiteRestriction {
636
+ relation: "where";
637
+ sourceText: string;
638
+ range?: TextRange;
639
+ markerRange?: TextRange;
640
+ predicate: BodySiteRestrictionPredicate;
641
+ }
435
642
  export interface BodySiteDefinition {
436
643
  coding?: BodySiteCode;
437
644
  text?: string;
438
645
  spatialRelation?: BodySiteSpatialRelation;
439
646
  routeHint?: RouteCode;
647
+ /** Only applies when a typed locative places medication INSIDE this site;
648
+ * external skin administration retains the product/administration route. */
649
+ internalRouteHint?: RouteCode;
440
650
  administrationTargetCount?: number;
441
651
  /** Optional surface used when the dose applies independently to each target. */
442
652
  perTargetText?: string;
@@ -523,13 +733,29 @@ export declare enum AdviceArgumentRole {
523
733
  Time = "time",
524
734
  Free = "free"
525
735
  }
736
+ /** A constituent of a compound meaning, not an alternative coding of that whole meaning. */
737
+ export interface InstructionConceptComponent {
738
+ role: "head" | "qualifier" | "amount";
739
+ text: string;
740
+ coding?: FhirCoding;
741
+ }
742
+ /** A standard-coded constituent of an instruction predicate, not an equivalent
743
+ * code for the whole imperative or an unvalidated SNOMED expression. */
744
+ export interface InstructionActionSemanticComponent {
745
+ role: "activity" | "technique" | "target-state" | "target-site" | "target-object" | "operation" | "orientation" | "mechanism" | "situation";
746
+ coding: FhirCoding;
747
+ }
526
748
  export interface AdviceArgument {
527
749
  role: AdviceArgumentRole;
528
750
  text: string;
751
+ /** Independent typed relation from this action to its argument.
752
+ * Permits material WITH and event BEFORE to coexist on one action. */
753
+ relation?: AdviceRelation;
529
754
  normalized?: string;
530
755
  conceptId?: string;
531
756
  coding?: FhirCoding;
532
757
  codings?: FhirCoding[];
758
+ components?: InstructionConceptComponent[];
533
759
  i18n?: Record<string, string>;
534
760
  quantity?: {
535
761
  value?: number;
@@ -541,6 +767,8 @@ export interface AdviceArgument {
541
767
  export interface AdviceFrame {
542
768
  force: AdviceForce;
543
769
  polarity?: AdvicePolarity;
770
+ /** Shared directive scope may differ from this action's own source wording. */
771
+ polaritySource?: "shared";
544
772
  modality?: AdviceModality;
545
773
  predicate: {
546
774
  lemma: string;
@@ -552,6 +780,8 @@ export interface AdviceFrame {
552
780
  realizerConfig?: MedicationInstructionActionRealizerConfig;
553
781
  /** Internal/custom action coding followed by any trustworthy external mappings. */
554
782
  codings?: FhirCoding[];
783
+ /** Independently coded constituents, not alternative predicate Codings. */
784
+ semanticComponents?: InstructionActionSemanticComponent[];
555
785
  };
556
786
  relation?: AdviceRelation;
557
787
  args: AdviceArgument[];
@@ -706,6 +936,12 @@ export interface MedicationInstructionActionContextualCodingRule {
706
936
  };
707
937
  coding: FhirCoding;
708
938
  }
939
+ /** Bind independently coded parts to a typed semantic argument rather than
940
+ * to an ambiguous bare verb. Reuses existing contextual coding match semantics. */
941
+ export interface MedicationInstructionActionContextualSemanticComponentRule {
942
+ whenArgument: MedicationInstructionActionContextualCodingRule["whenArgument"];
943
+ component: InstructionActionSemanticComponent;
944
+ }
709
945
  export interface MedicationInstructionActionLocaleRealizerConfig {
710
946
  fallbackObject?: string;
711
947
  suppressActivityConcepts?: string[];
@@ -734,6 +970,8 @@ export interface MedicationInstructionActionDefinition {
734
970
  roundtripI18n?: Record<string, string>;
735
971
  /** Surface forms that should resolve to this action. */
736
972
  aliases?: string[];
973
+ /** Ambiguous aliases licensed only at a directive boundary or after an explicit directive. */
974
+ directiveOnlyAliases?: string[];
737
975
  /** Surface forms licensed only when immediately sequence-scoped (e.g. `then off`). */
738
976
  sequenceAliases?: string[];
739
977
  /** Locale-specific parser lexemes. Display translation belongs in `i18n`; parsing aliases are explicit. */
@@ -750,6 +988,12 @@ export interface MedicationInstructionActionDefinition {
750
988
  /** Declarative realization family used by English/Thai graph generation. */
751
989
  realizer?: MedicationInstructionActionRealizer;
752
990
  argumentParserConfig?: {
991
+ /** Polarity that licenses this lexical frame as a directive rather than an event predicate. */
992
+ requiredDirectivePolarity?: AdvicePolarity;
993
+ /** Semantic effect of an affirmative conditional action on its medication-dose complement.
994
+ * The selected-dose form requires an explicit medication object or a typed dose-slot target;
995
+ * it never treats a bare avoidance verb, food object, or negation as withholding. */
996
+ medicationConditionEffect?: "withhold" | "withhold-selected-dose";
753
997
  primaryConcepts?: string[];
754
998
  secondaryConcepts?: string[];
755
999
  implicitMatchedConcept?: string;
@@ -779,6 +1023,8 @@ export interface MedicationInstructionActionDefinition {
779
1023
  applicationVerb?: boolean;
780
1024
  /** Extra exact codings licensed by a typed semantic argument. */
781
1025
  contextualCodings?: MedicationInstructionActionContextualCodingRule[];
1026
+ /** Add accurate standard-coded constituents only in the matched argument context. */
1027
+ contextualSemanticComponents?: MedicationInstructionActionContextualSemanticComponentRule[];
782
1028
  /** A method-capable procedural action that may serve as the primary administration head. */
783
1029
  primaryAdministrationHead?: boolean;
784
1030
  /** Semantically light verb that yields to an immediately following stronger administration head. */
@@ -792,6 +1038,8 @@ export interface MedicationInstructionActionDefinition {
792
1038
  coding?: FhirCoding;
793
1039
  /** Exact external terminology mappings; never fuzzy/approximate mappings. */
794
1040
  externalCodings?: FhirCoding[];
1041
+ /** Standard-coded parts of the instruction; preserve its local action coding. */
1042
+ semanticComponents?: InstructionActionSemanticComponent[];
795
1043
  }
796
1044
  export interface MedicationInstructionActionInput extends Partial<MedicationInstructionActionDefinition> {
797
1045
  semanticClass?: string;
@@ -799,6 +1047,14 @@ export interface MedicationInstructionActionInput extends Partial<MedicationInst
799
1047
  export interface MedicationInstructionConceptDefinition {
800
1048
  code: string;
801
1049
  role: AdviceArgumentRole;
1050
+ /** A registered compound noun may entail a second independently typed
1051
+ * argument, e.g. a temporal material "before first use" also supplies
1052
+ * its explicit first-use event. Not a free-form text rewrite. */
1053
+ impliedArgument?: {
1054
+ role: AdviceArgumentRole;
1055
+ conceptId: string;
1056
+ relation: AdviceRelation;
1057
+ };
802
1058
  display: string;
803
1059
  i18n?: Record<string, string>;
804
1060
  aliases?: string[];
@@ -806,6 +1062,8 @@ export interface MedicationInstructionConceptDefinition {
806
1062
  localeAliases?: Record<string, string[]>;
807
1063
  coding?: FhirCoding;
808
1064
  externalCodings?: FhirCoding[];
1065
+ /** Separately coded head and modifiers when there is no equivalent code for the whole phrase. */
1066
+ components?: InstructionConceptComponent[];
809
1067
  }
810
1068
  export interface MedicationInstructionConceptInput extends Partial<MedicationInstructionConceptDefinition> {
811
1069
  role?: AdviceArgumentRole;
@@ -1050,10 +1308,24 @@ export interface CanonicalSiteExpr {
1050
1308
  i18n?: Record<string, string>;
1051
1309
  coding?: BodySiteCode;
1052
1310
  spatialRelation?: BodySiteSpatialRelation;
1311
+ restrictions?: BodySiteRestriction[];
1053
1312
  administrationTargetCount?: number;
1054
1313
  source?: "abbreviation" | "text" | "selection" | "resolver";
1055
1314
  inferred?: boolean;
1056
1315
  evidence?: CanonicalEvidence[];
1316
+ range?: TextRange;
1317
+ }
1318
+ export type AdministrationTargetCoordinationKind = "conjunction" | "disjunction" | "mixed";
1319
+ /**
1320
+ * A grammatical coordination of administration sites. Each target is an
1321
+ * independently typed site atom; the relation is retained before the singular
1322
+ * FHIR Dosage.site projection chooses whether conjunction fan-out is needed.
1323
+ */
1324
+ export interface CanonicalAdministrationTargetGroup {
1325
+ coordination: AdministrationTargetCoordinationKind;
1326
+ sourceText: string;
1327
+ range?: TextRange;
1328
+ targets: CanonicalSiteExpr[];
1057
1329
  }
1058
1330
  export interface CanonicalMethodExpr {
1059
1331
  text?: string;
@@ -1066,6 +1338,13 @@ export interface CanonicalOccurrenceCapExpr {
1066
1338
  period: number;
1067
1339
  periodUnit: FhirPeriodUnit;
1068
1340
  }
1341
+ /** Explicit maximum medication quantity within a recurring period. */
1342
+ export interface CanonicalDosePeriodMaximumExpr {
1343
+ amount: number;
1344
+ unit: string;
1345
+ period: number;
1346
+ periodUnit: FhirPeriodUnit;
1347
+ }
1069
1348
  export interface CanonicalActivityTimingExpr {
1070
1349
  relation: "before" | "after";
1071
1350
  activity: {
@@ -1080,6 +1359,14 @@ export interface CanonicalActivityTimingExpr {
1080
1359
  /** Maximum offset from the activity in minutes. */
1081
1360
  offsetMax?: number;
1082
1361
  }
1362
+ /** Caller-resolved daily administration window. Unlike a WHEN anchor, this
1363
+ * bounds recurring opportunities rather than defining one administration.
1364
+ * Both endpoints are clinical EventTiming codes, never inferred clock times.
1365
+ */
1366
+ export interface CanonicalEventWindowExpr {
1367
+ start: EventTiming;
1368
+ end: EventTiming;
1369
+ }
1083
1370
  export interface CanonicalCalendarEventExpr {
1084
1371
  /** Gregorian ISO calendar date used for date-only FHIR Timing.event values and display. */
1085
1372
  isoDate: string;
@@ -1096,7 +1383,39 @@ export interface CanonicalCalendarEventExpr {
1096
1383
  /** True when a two-digit source year was expanded using the reference date. */
1097
1384
  inferredYear?: boolean;
1098
1385
  }
1386
+ /** A recognized cycle-day restriction whose calendar eligibility is unresolved.
1387
+ * Independent dose/route/clock fields remain useful for clinician editing.
1388
+ */
1389
+ export interface CanonicalCycleDayConstraint {
1390
+ days: number[];
1391
+ periodDays?: number;
1392
+ cycles?: number;
1393
+ anchor?: string;
1394
+ reason: string;
1395
+ sourceText: string;
1396
+ }
1099
1397
  export interface CanonicalScheduleExpr {
1398
+ /** Required cycle-day eligibility; do not execute the independent cadence until resolved. */
1399
+ cycleDayConstraint?: CanonicalCycleDayConstraint;
1400
+ /** Typed whole-course interval for a recurring active/rest construction. */
1401
+ repeatCycle?: FhirQuantity;
1402
+ /** Explicit finite number of whole-course repetitions; absent means unbounded. */
1403
+ repeatCount?: number;
1404
+ /** Explicit local-clock interval window; not a list of endpoint doses. */
1405
+ clockWindow?: {
1406
+ start: string;
1407
+ end: string;
1408
+ endInclusive: boolean;
1409
+ };
1410
+ /** Weekday occurrence in each month; -1 denotes the last occurrence. */
1411
+ weekdayOrdinal?: -1 | 1 | 2 | 3 | 4 | 5;
1412
+ /** Source-anaphoric timing (e.g. "at the same times") awaiting a licensed
1413
+ * previous regimen daughter. Resolved within HPSG/regimen, never by FHIR. */
1414
+ timingReference?: "previous" | "previous-weekday-complement";
1415
+ /** Source-relative phase onset, in elapsed days from treatment start. */
1416
+ treatmentStartOffsetDays?: number;
1417
+ /** Elapsed delay from each opportunity in this explicitly retained base schedule. */
1418
+ administrationOffsetMinutes?: number;
1100
1419
  timingCode?: string;
1101
1420
  count?: number;
1102
1421
  countMax?: number;
@@ -1123,14 +1442,22 @@ export interface CanonicalScheduleExpr {
1123
1442
  /** Maximum event offset in minutes when the source says “at most”. */
1124
1443
  offsetMax?: number;
1125
1444
  dayOfWeek?: FhirDayOfWeek[];
1445
+ /** Source-specified calendar days of each month, not medication dose amounts. */
1446
+ dayOfMonth?: number[];
1126
1447
  when?: EventTiming[];
1127
1448
  timeOfDay?: string[];
1449
+ /** Typed recurring window, distinct from an instantaneous WHEN event. */
1450
+ eventWindow?: CanonicalEventWindowExpr;
1128
1451
  /** Explicit calendar occurrences, projected to FHIR Timing.event. */
1129
1452
  calendarEvents?: CanonicalCalendarEventExpr[];
1130
1453
  activityTiming?: CanonicalActivityTimingExpr[];
1131
1454
  occurrenceCap?: CanonicalOccurrenceCapExpr;
1455
+ /** Quantity cap, distinct from occurrenceCap's maximum administration count. */
1456
+ maxDosePerPeriod?: CanonicalDosePeriodMaximumExpr[];
1132
1457
  evidence?: CanonicalEvidence[];
1133
1458
  }
1459
+ /** Schedule fields explicitly contributed by typed grammar evidence. */
1460
+ export type CanonicalScheduleSemanticField = Exclude<keyof CanonicalScheduleExpr, "evidence">;
1134
1461
  export interface CanonicalPrnReasonExpr {
1135
1462
  text?: string;
1136
1463
  i18n?: Record<string, string>;
@@ -1184,23 +1511,81 @@ export interface CanonicalSourceSpan extends TextRange {
1184
1511
  text: string;
1185
1512
  tokenIndices?: number[];
1186
1513
  }
1514
+ /** Lexical grammatical role carried from the originating typed sign.
1515
+ * Production names remain diagnostic labels, never semantic dispatch keys. */
1516
+ export type CanonicalLexicalCategory = "dose" | "method" | "prn" | "connector" | "instruction" | "workflow";
1187
1517
  export interface CanonicalEvidence {
1188
1518
  rule: string;
1519
+ /** Role of the actual lexical sign, independent of the grammar-rule label. */
1520
+ lexicalCategory?: CanonicalLexicalCategory;
1189
1521
  spans: CanonicalSourceSpan[];
1522
+ /** Exact schedule semantics owned by this evidence, independent of rule names. */
1523
+ scheduleFields?: CanonicalScheduleSemanticField[];
1190
1524
  score?: number;
1191
1525
  note?: string;
1192
1526
  }
1527
+ /**
1528
+ * Clinical adjuncts are grammatical facts on a typed administration clause.
1529
+ * Local surface recognizers produce them; HPSG constructions determine their
1530
+ * scope; FHIR only projects the resulting semantics. Raw/source data is kept.
1531
+ */
1532
+ export interface CanonicalClinicalAdjuncts {
1533
+ /** Finite medication-free interval selected by a typed withholding head. */
1534
+ treatmentPause?: {
1535
+ durationDays: number;
1536
+ range: TextRange;
1537
+ };
1538
+ condition?: MedicationCondition;
1539
+ /** Source-typed calendar membership, distinct from unrelated clinical guards. */
1540
+ calendarDayCondition?: MedicationCondition;
1541
+ /** Typed nominal reference of a conditional administration instruction.
1542
+ * Resolved across related regimen daughters before any FHIR lowering. */
1543
+ conditionTarget?: {
1544
+ when?: EventTiming[];
1545
+ /** Explicit existing clock slots selected by the nominal dose object. */
1546
+ timeOfDay?: string[];
1547
+ /** Lexical daypart membership over already stated clocks; creates no times. */
1548
+ clockRange?: {
1549
+ startHour: number;
1550
+ endHour: number;
1551
+ };
1552
+ quantifier?: "all" | "both";
1553
+ };
1554
+ excludedDates?: string[];
1555
+ excludedWeekdays?: FhirDayOfWeek[];
1556
+ /** Local source spans for lint ownership, not inherited donor spans. */
1557
+ localRanges?: TextRange[];
1558
+ evidence?: CanonicalEvidence[];
1559
+ }
1193
1560
  export interface CanonicalSigClause {
1194
1561
  kind: "administration";
1562
+ /** Source-backed phase operation; resolved by the typed regimen graph. */
1563
+ regimenAdjustment?: "replace" | "add" | "replace-target";
1195
1564
  rawText: string;
1196
1565
  span?: TextRange;
1197
1566
  raw: CanonicalSourceSpan;
1198
1567
  dose?: CanonicalDoseExpr;
1199
1568
  route?: CanonicalRouteExpr;
1200
1569
  site?: CanonicalSiteExpr;
1570
+ administrationTargetGroup?: CanonicalAdministrationTargetGroup;
1201
1571
  method?: CanonicalMethodExpr;
1572
+ /** Only the executable schedule. Undefined when scheduling is unresolved. */
1202
1573
  schedule?: CanonicalScheduleExpr;
1574
+ /**
1575
+ * Recognized but NON-EXECUTABLE schedule features retained for review/UI.
1576
+ * An unresolved medication can still have trustworthy dose, route, site,
1577
+ * clocks and bounds. Never schedule or calculate supply from this field;
1578
+ * execution requires a resolved schedule and the dosage safety checks.
1579
+ */
1580
+ provisionalSchedule?: CanonicalScheduleExpr;
1203
1581
  prn?: CanonicalPrnExpr;
1582
+ clinicalAdjuncts?: CanonicalClinicalAdjuncts;
1583
+ /** Closed HPSG condition ownership, projected into instruction-graph relations. */
1584
+ instructionScopes?: Array<{
1585
+ kind: AdviceRelation;
1586
+ span: TextRange;
1587
+ target: TextRange;
1588
+ }>;
1204
1589
  patientInstruction?: string;
1205
1590
  instructionGraph?: CanonicalInstructionGraph;
1206
1591
  additionalInstructions?: CanonicalAdditionalInstructionExpr[];
@@ -1254,6 +1639,8 @@ export interface BodySiteDetail {
1254
1639
  text?: string;
1255
1640
  coding?: BodySiteCode;
1256
1641
  spatialRelation?: BodySiteSpatialRelation;
1642
+ /** Typed site-local predicates retained for editable normalized suggestions. */
1643
+ restrictions?: BodySiteRestriction[];
1257
1644
  administrationTargetCount?: number;
1258
1645
  }
1259
1646
  export interface ConceptSiteDetail {
@@ -1269,21 +1656,15 @@ export interface ParseBatchSegmentMeta {
1269
1656
  export interface ParseBatchResult {
1270
1657
  input: string;
1271
1658
  count: number;
1659
+ /** Per-clause parser diagnostics and intermediate R5-compatible dosage shapes. */
1272
1660
  items: ParseResult[];
1273
- /**
1274
- * Top-level compatibility field mirroring the first parsed item so existing
1275
- * single-sig integrations can migrate incrementally.
1276
- */
1277
- fhir: FhirDosage;
1278
- /**
1279
- * Top-level compatibility field mirroring the first parsed item so existing
1280
- * single-sig integrations can migrate incrementally.
1281
- */
1661
+ /** Primary output: COMPLETE flat R5-like dosage array with additive R6 fields. */
1662
+ fhir: EzDosage[];
1663
+ /** Strict R6 snapshot projection of the same prescription. */
1664
+ fhirNext: FhirR6DosageDetails;
1665
+ /** Optional R6 step/course metadata not owned by a single dose. */
1666
+ course?: EzCourseMetadata;
1282
1667
  shortText: string;
1283
- /**
1284
- * Top-level compatibility field mirroring the first parsed item so existing
1285
- * single-sig integrations can migrate incrementally.
1286
- */
1287
1668
  longText: string;
1288
1669
  warnings: string[];
1289
1670
  meta: {
@@ -1364,8 +1745,17 @@ export interface NextDueDoseConfig {
1364
1745
  /**
1365
1746
  * Options bag for next-due dose generation.
1366
1747
  */
1748
+ export type MedicationConditionEvaluator = (condition: MedicationCondition, at: string) => boolean | undefined;
1367
1749
  export interface NextDueDoseOptions {
1368
1750
  from: Date | string;
1751
+ /** Explicit course-local selection for exactly-one alternative groups.
1752
+ * Keys are getDosageAlternativeChoice(...).groupId; values are branchId.
1753
+ * Omit only for ordinary courses without mutually exclusive alternatives.
1754
+ * Parsing and editing never require a selection; execution and supply do.
1755
+ */
1756
+ alternativeChoices?: Readonly<Record<string, string>>;
1757
+ /** Evaluate structured conditional instructions at each candidate occurrence. Required for conditional scheduling. */
1758
+ evaluateCondition?: MedicationConditionEvaluator;
1369
1759
  orderedAt?: Date | string;
1370
1760
  limit?: number;
1371
1761
  priorCount?: number;
@@ -1377,15 +1767,30 @@ export interface NextDueDoseOptions {
1377
1767
  frequencyDefaults?: FrequencyFallbackTimes;
1378
1768
  config?: NextDueDoseConfig;
1379
1769
  }
1770
+ /** Due times calculated with each ordered medication-instruction phase respected. */
1771
+ export interface RegimenDueTimes {
1772
+ dosageIndex: number;
1773
+ sequence: number;
1774
+ phaseStart: string;
1775
+ timestamps: string[];
1776
+ }
1380
1777
  export interface TotalUnitsResult {
1381
1778
  totalUnits: number;
1779
+ /** Unit of totalUnits, when known. */
1780
+ unit?: string;
1781
+ /** PRN and unresolved clinical observations yield the maximum planned supply, not actual consumption. */
1782
+ quantityKind?: "scheduled" | "maximum";
1783
+ /** Human-readable basis/assumptions suitable for displaying alongside a calculated quantity. */
1784
+ explanation?: string;
1382
1785
  totalContainers?: number;
1383
1786
  totalContainerQuantity?: FhirQuantity;
1384
1787
  totalApproximateQuantity?: EstimatedQuantity;
1385
1788
  totalApproximateIngredientQuantity?: EstimatedQuantity;
1386
1789
  }
1387
1790
  export interface TotalUnitsOptions extends NextDueDoseOptions {
1388
- dosage: FhirDosage | FhirDosage[];
1791
+ dosage: FhirDosage | readonly EzDosage[] | FhirR6DosageDetails | ParseBatchResult;
1792
+ /** Required to resolve per-kg administered doses into an actual quantity. */
1793
+ patientWeightKg?: number;
1389
1794
  durationValue: number;
1390
1795
  durationUnit: FhirPeriodUnit;
1391
1796
  roundToMultiple?: number;