fhir-runtime 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/CHANGELOG.md +211 -0
- package/LICENSE +21 -0
- package/README.md +261 -0
- package/dist/cjs/index.cjs +7368 -0
- package/dist/cjs/index.cjs.map +7 -0
- package/dist/cjs/index.d.ts +4224 -0
- package/dist/cjs/package.json +5 -0
- package/dist/esm/index.d.ts +4224 -0
- package/dist/esm/index.mjs +7250 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/index.d.ts +4224 -0
- package/dist/lib/context/bundle-loader.d.ts +124 -0
- package/dist/lib/context/bundle-loader.d.ts.map +1 -0
- package/dist/lib/context/core-definitions/index.d.ts +72 -0
- package/dist/lib/context/core-definitions/index.d.ts.map +1 -0
- package/dist/lib/context/errors.d.ts +114 -0
- package/dist/lib/context/errors.d.ts.map +1 -0
- package/dist/lib/context/fhir-context.d.ts +72 -0
- package/dist/lib/context/fhir-context.d.ts.map +1 -0
- package/dist/lib/context/index.d.ts +21 -0
- package/dist/lib/context/index.d.ts.map +1 -0
- package/dist/lib/context/inheritance-resolver.d.ts +98 -0
- package/dist/lib/context/inheritance-resolver.d.ts.map +1 -0
- package/dist/lib/context/inner-type-extractor.d.ts +80 -0
- package/dist/lib/context/inner-type-extractor.d.ts.map +1 -0
- package/dist/lib/context/loaders/composite-loader.d.ts +47 -0
- package/dist/lib/context/loaders/composite-loader.d.ts.map +1 -0
- package/dist/lib/context/loaders/file-loader.d.ts +47 -0
- package/dist/lib/context/loaders/file-loader.d.ts.map +1 -0
- package/dist/lib/context/loaders/index.d.ts +11 -0
- package/dist/lib/context/loaders/index.d.ts.map +1 -0
- package/dist/lib/context/loaders/memory-loader.d.ts +42 -0
- package/dist/lib/context/loaders/memory-loader.d.ts.map +1 -0
- package/dist/lib/context/registry.d.ts +116 -0
- package/dist/lib/context/registry.d.ts.map +1 -0
- package/dist/lib/context/types.d.ts +266 -0
- package/dist/lib/context/types.d.ts.map +1 -0
- package/dist/lib/fhirpath/atoms.d.ts +228 -0
- package/dist/lib/fhirpath/atoms.d.ts.map +1 -0
- package/dist/lib/fhirpath/cache.d.ts +79 -0
- package/dist/lib/fhirpath/cache.d.ts.map +1 -0
- package/dist/lib/fhirpath/date.d.ts +17 -0
- package/dist/lib/fhirpath/date.d.ts.map +1 -0
- package/dist/lib/fhirpath/functions.d.ts +28 -0
- package/dist/lib/fhirpath/functions.d.ts.map +1 -0
- package/dist/lib/fhirpath/index.d.ts +20 -0
- package/dist/lib/fhirpath/index.d.ts.map +1 -0
- package/dist/lib/fhirpath/lexer/parse.d.ts +100 -0
- package/dist/lib/fhirpath/lexer/parse.d.ts.map +1 -0
- package/dist/lib/fhirpath/lexer/tokenize.d.ts +80 -0
- package/dist/lib/fhirpath/lexer/tokenize.d.ts.map +1 -0
- package/dist/lib/fhirpath/parse.d.ts +101 -0
- package/dist/lib/fhirpath/parse.d.ts.map +1 -0
- package/dist/lib/fhirpath/tokenize.d.ts +20 -0
- package/dist/lib/fhirpath/tokenize.d.ts.map +1 -0
- package/dist/lib/fhirpath/types.d.ts +111 -0
- package/dist/lib/fhirpath/types.d.ts.map +1 -0
- package/dist/lib/fhirpath/utils.d.ts +81 -0
- package/dist/lib/fhirpath/utils.d.ts.map +1 -0
- package/dist/lib/index.d.ts +24 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/model/canonical-profile.d.ts +381 -0
- package/dist/lib/model/canonical-profile.d.ts.map +1 -0
- package/dist/lib/model/element-definition.d.ts +503 -0
- package/dist/lib/model/element-definition.d.ts.map +1 -0
- package/dist/lib/model/index.d.ts +14 -0
- package/dist/lib/model/index.d.ts.map +1 -0
- package/dist/lib/model/primitives.d.ts +464 -0
- package/dist/lib/model/primitives.d.ts.map +1 -0
- package/dist/lib/model/structure-definition.d.ts +263 -0
- package/dist/lib/model/structure-definition.d.ts.map +1 -0
- package/dist/lib/parser/choice-type-parser.d.ts +182 -0
- package/dist/lib/parser/choice-type-parser.d.ts.map +1 -0
- package/dist/lib/parser/index.d.ts +16 -0
- package/dist/lib/parser/index.d.ts.map +1 -0
- package/dist/lib/parser/json-parser.d.ts +171 -0
- package/dist/lib/parser/json-parser.d.ts.map +1 -0
- package/dist/lib/parser/parse-error.d.ts +146 -0
- package/dist/lib/parser/parse-error.d.ts.map +1 -0
- package/dist/lib/parser/primitive-parser.d.ts +136 -0
- package/dist/lib/parser/primitive-parser.d.ts.map +1 -0
- package/dist/lib/parser/serializer.d.ts +64 -0
- package/dist/lib/parser/serializer.d.ts.map +1 -0
- package/dist/lib/parser/structure-definition-parser.d.ts +63 -0
- package/dist/lib/parser/structure-definition-parser.d.ts.map +1 -0
- package/dist/lib/profile/canonical-builder.d.ts +87 -0
- package/dist/lib/profile/canonical-builder.d.ts.map +1 -0
- package/dist/lib/profile/constraint-merger.d.ts +100 -0
- package/dist/lib/profile/constraint-merger.d.ts.map +1 -0
- package/dist/lib/profile/element-merger.d.ts +80 -0
- package/dist/lib/profile/element-merger.d.ts.map +1 -0
- package/dist/lib/profile/element-sorter.d.ts +81 -0
- package/dist/lib/profile/element-sorter.d.ts.map +1 -0
- package/dist/lib/profile/errors.d.ts +150 -0
- package/dist/lib/profile/errors.d.ts.map +1 -0
- package/dist/lib/profile/index.d.ts +27 -0
- package/dist/lib/profile/index.d.ts.map +1 -0
- package/dist/lib/profile/path-utils.d.ts +180 -0
- package/dist/lib/profile/path-utils.d.ts.map +1 -0
- package/dist/lib/profile/slicing-handler.d.ts +121 -0
- package/dist/lib/profile/slicing-handler.d.ts.map +1 -0
- package/dist/lib/profile/snapshot-generator.d.ts +73 -0
- package/dist/lib/profile/snapshot-generator.d.ts.map +1 -0
- package/dist/lib/profile/types.d.ts +220 -0
- package/dist/lib/profile/types.d.ts.map +1 -0
- package/dist/lib/validator/errors.d.ts +83 -0
- package/dist/lib/validator/errors.d.ts.map +1 -0
- package/dist/lib/validator/index.d.ts +23 -0
- package/dist/lib/validator/index.d.ts.map +1 -0
- package/dist/lib/validator/invariant-validator.d.ts +62 -0
- package/dist/lib/validator/invariant-validator.d.ts.map +1 -0
- package/dist/lib/validator/path-extractor.d.ts +123 -0
- package/dist/lib/validator/path-extractor.d.ts.map +1 -0
- package/dist/lib/validator/slicing-validator.d.ts +119 -0
- package/dist/lib/validator/slicing-validator.d.ts.map +1 -0
- package/dist/lib/validator/structure-validator.d.ts +74 -0
- package/dist/lib/validator/structure-validator.d.ts.map +1 -0
- package/dist/lib/validator/types.d.ts +288 -0
- package/dist/lib/validator/types.d.ts.map +1 -0
- package/dist/lib/validator/validation-rules.d.ts +198 -0
- package/dist/lib/validator/validation-rules.d.ts.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +76 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slicing-handler.d.ts","sourceRoot":"","sources":["../../../src/profile/slicing-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,wBAAwB,EACxB,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAuBxD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,IAAI,wBAAwB,CAW/D;AAMD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,SAAS,iBAAiB,EAAE,EACtC,gBAAgB,EAAE,MAAM,GACvB,iBAAiB,EAAE,CAsBrB;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,wBAAwB,EACrC,WAAW,EAAE,wBAAwB,EACrC,MAAM,EAAE,aAAa,EAAE,EACvB,IAAI,EAAE,MAAM,GACX,OAAO,CAoET;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,SAAS,kBAAkB,EAAE,EAC1C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,SAAS,qBAAqB,EAAE,GAAG,SAAS,GACtD,OAAO,CAwBT;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,iBAAiB,EAAE,EAC3B,WAAW,EAAE,iBAAiB,EAC9B,SAAS,EAAE,cAAc,EACzB,WAAW,EAAE,kBAAkB,EAAE,EACjC,YAAY,EAAE,SAAS,kBAAkB,EAAE,EAC3C,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,MAAM,GACZ,IAAI,CAkEN;AAMD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,iBAAiB,EAAE,EAC3B,WAAW,EAAE,iBAAiB,EAC9B,SAAS,EAAE,cAAc,EACzB,WAAW,EAAE,kBAAkB,EAAE,EACjC,YAAY,EAAE,SAAS,kBAAkB,EAAE,EAC3C,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,MAAM,GACZ,IAAI,CA8HN"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fhir-profile — Snapshot Generator (Orchestrator)
|
|
3
|
+
*
|
|
4
|
+
* Implements the top-level snapshot generation workflow, corresponding to
|
|
5
|
+
* HAPI FHIR R4's `ProfileUtilities.generateSnapshot()`.
|
|
6
|
+
*
|
|
7
|
+
* This is the **orchestrator** that coordinates:
|
|
8
|
+
* 1. Input validation
|
|
9
|
+
* 2. Circular dependency detection (generation stack)
|
|
10
|
+
* 3. Base SD loading (recursive snapshot generation if needed)
|
|
11
|
+
* 4. Datatype cache population
|
|
12
|
+
* 5. Merge loop delegation to {@link processPaths}
|
|
13
|
+
* 6. Post-processing (unconsumed diff, element IDs)
|
|
14
|
+
* 7. Result caching
|
|
15
|
+
*
|
|
16
|
+
* @module fhir-profile
|
|
17
|
+
*/
|
|
18
|
+
import type { StructureDefinition } from '../model/index.js';
|
|
19
|
+
import type { FhirContext } from '../context/types.js';
|
|
20
|
+
import type { SnapshotGeneratorOptions, SnapshotResult } from './types.js';
|
|
21
|
+
/**
|
|
22
|
+
* Snapshot Generator — top-level orchestrator for snapshot generation.
|
|
23
|
+
*
|
|
24
|
+
* Corresponds to HAPI's `ProfileUtilities.generateSnapshot()`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const generator = new SnapshotGenerator(fhirContext, { throwOnError: false });
|
|
29
|
+
* const result = await generator.generate(myProfile);
|
|
30
|
+
* if (result.success) {
|
|
31
|
+
* console.log('Snapshot generated with', result.structureDefinition.snapshot?.element.length, 'elements');
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class SnapshotGenerator {
|
|
36
|
+
private readonly context;
|
|
37
|
+
private readonly options;
|
|
38
|
+
/** URLs currently being generated — for circular dependency detection. */
|
|
39
|
+
private readonly generationStack;
|
|
40
|
+
constructor(context: FhirContext, options?: SnapshotGeneratorOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Generate a snapshot for a StructureDefinition.
|
|
43
|
+
*
|
|
44
|
+
* @param sd - StructureDefinition with a differential to expand.
|
|
45
|
+
* @returns SnapshotResult with the populated snapshot and any issues.
|
|
46
|
+
* @throws {SnapshotCircularDependencyError} if circular reference detected
|
|
47
|
+
* @throws {BaseNotFoundError} if base SD cannot be loaded
|
|
48
|
+
* @throws {UnconsumedDifferentialError} if throwOnError and unconsumed diffs
|
|
49
|
+
*/
|
|
50
|
+
generate(sd: StructureDefinition): Promise<SnapshotResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Validate input StructureDefinition.
|
|
53
|
+
* Returns true if there's a fatal validation error.
|
|
54
|
+
*/
|
|
55
|
+
private validateInput;
|
|
56
|
+
/**
|
|
57
|
+
* Load the base StructureDefinition.
|
|
58
|
+
*/
|
|
59
|
+
private loadBase;
|
|
60
|
+
/**
|
|
61
|
+
* Populate the datatype cache with snapshots of types referenced by
|
|
62
|
+
* the differential's child paths.
|
|
63
|
+
*
|
|
64
|
+
* Scans both base elements and diff elements for type codes, then
|
|
65
|
+
* pre-loads their StructureDefinitions into the merge context cache.
|
|
66
|
+
*/
|
|
67
|
+
private populateDatatypeCache;
|
|
68
|
+
/**
|
|
69
|
+
* Build a SnapshotResult from the current state.
|
|
70
|
+
*/
|
|
71
|
+
private buildResult;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=snapshot-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-generator.d.ts","sourceRoot":"","sources":["../../../src/profile/snapshot-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAqB,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,wBAAwB,EAAE,cAAc,EAAiB,MAAM,YAAY,CAAC;AAc1F;;;;;;;;;;;;;GAaG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IAEnD,0EAA0E;IAC1E,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA0B;gBAE9C,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,wBAA6B;IASxE;;;;;;;;OAQG;IACG,QAAQ,CAAC,EAAE,EAAE,mBAAmB,GAAG,OAAO,CAAC,cAAc,CAAC;IAmJhE;;;OAGG;IACH,OAAO,CAAC,aAAa;IAgCrB;;OAEG;YACW,QAAQ;IA0BtB;;;;;;OAMG;YACW,qBAAqB;IA+CnC;;OAEG;IACH,OAAO,CAAC,WAAW;CAQpB"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fhir-profile — Public Interfaces & Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the core abstractions for the FHIR profile module:
|
|
5
|
+
* - {@link SnapshotGeneratorOptions} — generation configuration
|
|
6
|
+
* - {@link SnapshotResult} — generation output
|
|
7
|
+
* - {@link SnapshotIssue} — issue reporting
|
|
8
|
+
* - {@link DiffElementTracker} — internal differential consumption tracking
|
|
9
|
+
* - {@link TraversalScope} — cursor-based scope for base-driven traversal
|
|
10
|
+
*
|
|
11
|
+
* This module implements the snapshot generation algorithm conceptually
|
|
12
|
+
* equivalent to HAPI FHIR's `ProfileUtilities.generateSnapshot()`.
|
|
13
|
+
*
|
|
14
|
+
* @module fhir-profile
|
|
15
|
+
*/
|
|
16
|
+
import type { CanonicalProfile, ElementDefinition, StructureDefinition } from '../model/index.js';
|
|
17
|
+
/**
|
|
18
|
+
* Configuration options for snapshot generation.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const options: SnapshotGeneratorOptions = {
|
|
23
|
+
* throwOnError: false,
|
|
24
|
+
* maxRecursionDepth: 50,
|
|
25
|
+
* generateCanonical: true,
|
|
26
|
+
* };
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export interface SnapshotGeneratorOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Whether to throw on the first error or collect all errors.
|
|
32
|
+
*
|
|
33
|
+
* When `true`, the generator throws immediately on the first error
|
|
34
|
+
* (matching HAPI's "exception mode"). When `false` (default), errors
|
|
35
|
+
* are collected in {@link SnapshotResult.issues} and generation
|
|
36
|
+
* continues as far as possible.
|
|
37
|
+
*
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
readonly throwOnError?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Maximum recursion depth for nested snapshot generation.
|
|
43
|
+
*
|
|
44
|
+
* Snapshot generation can recursively trigger generation of other
|
|
45
|
+
* profiles (e.g., when a base profile lacks a snapshot, or when
|
|
46
|
+
* expanding into datatype definitions). This limit prevents runaway
|
|
47
|
+
* recursion in pathological or circular profiles.
|
|
48
|
+
*
|
|
49
|
+
* @default 50
|
|
50
|
+
*/
|
|
51
|
+
readonly maxRecursionDepth?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Whether to generate a {@link CanonicalProfile} alongside the snapshot.
|
|
54
|
+
*
|
|
55
|
+
* When `true`, the result includes a `canonical` field containing
|
|
56
|
+
* the MedXAI internal semantic model derived from the generated snapshot.
|
|
57
|
+
*
|
|
58
|
+
* @default false
|
|
59
|
+
*/
|
|
60
|
+
readonly generateCanonical?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Result of snapshot generation.
|
|
64
|
+
*
|
|
65
|
+
* Contains the StructureDefinition with its populated snapshot, any issues
|
|
66
|
+
* encountered during generation, and optionally a {@link CanonicalProfile}.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const result = await generator.generate(sd);
|
|
71
|
+
* if (result.success) {
|
|
72
|
+
* console.log(`Generated ${result.structureDefinition.snapshot?.element.length} elements`);
|
|
73
|
+
* } else {
|
|
74
|
+
* console.error('Errors:', result.issues.filter(i => i.severity === 'error'));
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export interface SnapshotResult {
|
|
79
|
+
/** The StructureDefinition with populated snapshot. */
|
|
80
|
+
readonly structureDefinition: StructureDefinition;
|
|
81
|
+
/**
|
|
82
|
+
* Optional {@link CanonicalProfile} if
|
|
83
|
+
* {@link SnapshotGeneratorOptions.generateCanonical} was `true`.
|
|
84
|
+
*/
|
|
85
|
+
readonly canonical?: CanonicalProfile;
|
|
86
|
+
/** Issues encountered during generation (warnings + errors). */
|
|
87
|
+
readonly issues: readonly SnapshotIssue[];
|
|
88
|
+
/**
|
|
89
|
+
* Whether generation completed successfully.
|
|
90
|
+
*
|
|
91
|
+
* `true` when no error-severity issues were recorded.
|
|
92
|
+
* Warnings and informational issues do not affect this flag.
|
|
93
|
+
*/
|
|
94
|
+
readonly success: boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* An issue encountered during snapshot generation.
|
|
98
|
+
*
|
|
99
|
+
* Mirrors the concept of HAPI's `ValidationMessage` but scoped to
|
|
100
|
+
* snapshot generation. Issues are collected during generation and
|
|
101
|
+
* returned in {@link SnapshotResult.issues}.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const issue: SnapshotIssue = {
|
|
106
|
+
* severity: 'error',
|
|
107
|
+
* code: 'CARDINALITY_VIOLATION',
|
|
108
|
+
* message: 'Derived min (0) is less than base min (1)',
|
|
109
|
+
* path: 'Patient.identifier',
|
|
110
|
+
* };
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export interface SnapshotIssue {
|
|
114
|
+
/** Severity level of the issue. */
|
|
115
|
+
readonly severity: 'error' | 'warning' | 'information';
|
|
116
|
+
/** Machine-readable issue code. */
|
|
117
|
+
readonly code: SnapshotIssueCode;
|
|
118
|
+
/** Human-readable description of the issue. */
|
|
119
|
+
readonly message: string;
|
|
120
|
+
/** Element path where the issue occurred (e.g., `'Patient.identifier'`). */
|
|
121
|
+
readonly path?: string;
|
|
122
|
+
/** Additional details for debugging. */
|
|
123
|
+
readonly details?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Machine-readable issue codes for snapshot generation.
|
|
127
|
+
*
|
|
128
|
+
* Each code corresponds to a specific category of problem that can
|
|
129
|
+
* occur during the snapshot generation process.
|
|
130
|
+
*/
|
|
131
|
+
export type SnapshotIssueCode =
|
|
132
|
+
/** Circular dependency detected in profile chain. */
|
|
133
|
+
'CIRCULAR_DEPENDENCY'
|
|
134
|
+
/** Base StructureDefinition could not be loaded. */
|
|
135
|
+
| 'BASE_NOT_FOUND'
|
|
136
|
+
/** Base StructureDefinition exists but has no snapshot. */
|
|
137
|
+
| 'BASE_MISSING_SNAPSHOT'
|
|
138
|
+
/** Differential element was not consumed during generation. */
|
|
139
|
+
| 'DIFFERENTIAL_NOT_CONSUMED'
|
|
140
|
+
/** Cardinality constraint violation (min/max tightening rules). */
|
|
141
|
+
| 'CARDINALITY_VIOLATION'
|
|
142
|
+
/** Type constraint is incompatible with base types. */
|
|
143
|
+
| 'TYPE_INCOMPATIBLE'
|
|
144
|
+
/** Binding constraint violation (e.g., relaxing REQUIRED binding). */
|
|
145
|
+
| 'BINDING_VIOLATION'
|
|
146
|
+
/** Slicing-related error (compatibility, closed slicing, etc.). */
|
|
147
|
+
| 'SLICING_ERROR'
|
|
148
|
+
/** Differential path not found in base snapshot. */
|
|
149
|
+
| 'PATH_NOT_FOUND'
|
|
150
|
+
/** Generic invalid constraint (catch-all for other violations). */
|
|
151
|
+
| 'INVALID_CONSTRAINT'
|
|
152
|
+
/** Internal error in the generator (should not happen). */
|
|
153
|
+
| 'INTERNAL_ERROR';
|
|
154
|
+
/**
|
|
155
|
+
* Tracks a differential element during snapshot generation.
|
|
156
|
+
*
|
|
157
|
+
* Implements the HAPI marker pattern where each differential element
|
|
158
|
+
* is tagged with `userData(GENERATED_IN_SNAPSHOT)` after being consumed
|
|
159
|
+
* by the merge algorithm. At the end of generation, any tracker with
|
|
160
|
+
* `consumed === false` indicates an unmatched differential element.
|
|
161
|
+
*
|
|
162
|
+
* @internal Used by {@link ElementMerger} and {@link SnapshotGenerator}.
|
|
163
|
+
*/
|
|
164
|
+
export interface DiffElementTracker {
|
|
165
|
+
/** The original differential ElementDefinition. */
|
|
166
|
+
readonly element: ElementDefinition;
|
|
167
|
+
/**
|
|
168
|
+
* Whether this element has been consumed (matched and merged)
|
|
169
|
+
* during snapshot generation.
|
|
170
|
+
*
|
|
171
|
+
* Set to `true` by the merge algorithm when the element is
|
|
172
|
+
* successfully applied to the snapshot. Checked post-generation
|
|
173
|
+
* to detect unmatched differential elements.
|
|
174
|
+
*/
|
|
175
|
+
consumed: boolean;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Cursor-based scope for base-driven traversal.
|
|
179
|
+
*
|
|
180
|
+
* Used by the element merger (`processPaths` equivalent) to define
|
|
181
|
+
* the current working range within a list of ElementDefinitions.
|
|
182
|
+
* Both `start` and `end` are inclusive indices.
|
|
183
|
+
*
|
|
184
|
+
* This mirrors HAPI's `baseCursor/baseLimit` and `diffCursor/diffLimit`
|
|
185
|
+
* parameter pairs in `processPaths()`.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* // Scope covering elements[2] through elements[5]
|
|
190
|
+
* const scope: TraversalScope = {
|
|
191
|
+
* elements: baseSnapshot.element,
|
|
192
|
+
* start: 2,
|
|
193
|
+
* end: 5,
|
|
194
|
+
* };
|
|
195
|
+
* ```
|
|
196
|
+
*
|
|
197
|
+
* @internal Used by {@link ElementMerger}.
|
|
198
|
+
*/
|
|
199
|
+
export interface TraversalScope {
|
|
200
|
+
/** The element list being traversed. */
|
|
201
|
+
readonly elements: readonly ElementDefinition[];
|
|
202
|
+
/** Start index (inclusive). */
|
|
203
|
+
readonly start: number;
|
|
204
|
+
/** End index (inclusive). */
|
|
205
|
+
readonly end: number;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Create a {@link SnapshotIssue} with the given parameters.
|
|
209
|
+
*
|
|
210
|
+
* Convenience factory to reduce boilerplate when recording issues.
|
|
211
|
+
*/
|
|
212
|
+
export declare function createSnapshotIssue(severity: SnapshotIssue['severity'], code: SnapshotIssueCode, message: string, path?: string, details?: string): SnapshotIssue;
|
|
213
|
+
/**
|
|
214
|
+
* Create a {@link DiffElementTracker} for a differential element.
|
|
215
|
+
*
|
|
216
|
+
* @param element - The differential ElementDefinition to track.
|
|
217
|
+
* @returns A tracker with `consumed` set to `false`.
|
|
218
|
+
*/
|
|
219
|
+
export declare function createDiffTracker(element: ElementDefinition): DiffElementTracker;
|
|
220
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/profile/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAM3B;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;;;;;;;OASG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;;;;;;OASG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAEpC;;;;;;;OAOG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CACtC;AAMD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,cAAc;IAC7B,uDAAuD;IACvD,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC;IAElD;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAEtC,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,CAAC;IAE1C;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,aAAa;IAC5B,mCAAmC;IACnC,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,aAAa,CAAC;IAEvD,mCAAmC;IACnC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAEjC,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB,wCAAwC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAMD;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB;AAC3B,qDAAqD;AACnD,qBAAqB;AACvB,oDAAoD;GAClD,gBAAgB;AAClB,2DAA2D;GACzD,uBAAuB;AACzB,+DAA+D;GAC7D,2BAA2B;AAC7B,mEAAmE;GACjE,uBAAuB;AACzB,uDAAuD;GACrD,mBAAmB;AACrB,sEAAsE;GACpE,mBAAmB;AACrB,mEAAmE;GACjE,eAAe;AACjB,oDAAoD;GAClD,gBAAgB;AAClB,mEAAmE;GACjE,oBAAoB;AACtB,2DAA2D;GACzD,gBAAgB,CAAC;AAMrB;;;;;;;;;GASG;AACH,MAAM,WAAW,kBAAkB;IACjC,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IAEpC;;;;;;;OAOG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB;AAMD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,QAAQ,CAAC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAEhD,+BAA+B;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,6BAA6B;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAMD;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,EACnC,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,MAAM,GACf,aAAa,CASf;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,GAAG,kBAAkB,CAEhF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fhir-validator — Error Types
|
|
3
|
+
*
|
|
4
|
+
* Structured error hierarchy for the FHIR validator module.
|
|
5
|
+
* All errors extend {@link ValidatorError} so consumers can catch
|
|
6
|
+
* validator-related failures with a single `catch` clause.
|
|
7
|
+
*
|
|
8
|
+
* Error hierarchy:
|
|
9
|
+
* ```
|
|
10
|
+
* ValidatorError (base)
|
|
11
|
+
* ├── ProfileNotFoundError
|
|
12
|
+
* └── ValidationFailedError
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @module fhir-validator
|
|
16
|
+
*/
|
|
17
|
+
import type { ValidationIssue } from './types.js';
|
|
18
|
+
/**
|
|
19
|
+
* Base error class for all fhir-validator failures.
|
|
20
|
+
*
|
|
21
|
+
* Provides a stable `name` property and preserves the original `cause`
|
|
22
|
+
* when wrapping lower-level errors.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* try {
|
|
27
|
+
* await validator.validate(resource);
|
|
28
|
+
* } catch (err) {
|
|
29
|
+
* if (err instanceof ValidatorError) {
|
|
30
|
+
* // Handle any validator-related error
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class ValidatorError extends Error {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
constructor(message: string, options?: ErrorOptions);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Thrown when the profile required for validation cannot be found or loaded.
|
|
41
|
+
*
|
|
42
|
+
* This occurs when:
|
|
43
|
+
* - The specified `profileUrl` does not exist in the FhirContext
|
|
44
|
+
* - The profile exists but has no snapshot
|
|
45
|
+
* - No profile URL is specified and none can be inferred from the resource
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* throw new ProfileNotFoundError(
|
|
50
|
+
* 'http://example.org/StructureDefinition/UnknownProfile',
|
|
51
|
+
* );
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare class ProfileNotFoundError extends ValidatorError {
|
|
55
|
+
readonly name = "ProfileNotFoundError";
|
|
56
|
+
/** The canonical URL of the profile that could not be found. */
|
|
57
|
+
readonly profileUrl: string;
|
|
58
|
+
constructor(profileUrl: string, cause?: Error);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Thrown when validation fails and {@link ValidationOptions.failFast} is enabled.
|
|
62
|
+
*
|
|
63
|
+
* Contains the issues accumulated up to the point of failure. This allows
|
|
64
|
+
* callers to inspect the first error(s) that triggered the failure.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* try {
|
|
69
|
+
* await validator.validate(resource, { failFast: true });
|
|
70
|
+
* } catch (err) {
|
|
71
|
+
* if (err instanceof ValidationFailedError) {
|
|
72
|
+
* console.error('First error:', err.issues[0].message);
|
|
73
|
+
* }
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare class ValidationFailedError extends ValidatorError {
|
|
78
|
+
readonly name = "ValidationFailedError";
|
|
79
|
+
/** The validation issues accumulated before failure. */
|
|
80
|
+
readonly issues: readonly ValidationIssue[];
|
|
81
|
+
constructor(message: string, issues: readonly ValidationIssue[], cause?: Error);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/validator/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAMlD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAkB,IAAI,EAAE,MAAM,CAAoB;gBAEtC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAKpD;AAMD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,oBAAqB,SAAQ,cAAc;IACtD,SAAkB,IAAI,0BAA0B;IAEhD,gEAAgE;IAChE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAO9C;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,qBAAsB,SAAQ,cAAc;IACvD,SAAkB,IAAI,2BAA2B;IAEjD,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;gBAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,eAAe,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK;CAO/E"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fhir-validator — Barrel Exports
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all public types, interfaces, error classes, and helper
|
|
5
|
+
* functions from the FHIR validator module.
|
|
6
|
+
*
|
|
7
|
+
* Public surface:
|
|
8
|
+
* - Types: ValidationOptions, ValidationResult, ValidationIssue, etc.
|
|
9
|
+
* - Errors: ValidatorError hierarchy
|
|
10
|
+
* - Helpers: createValidationIssue, hasValidationErrors, etc.
|
|
11
|
+
*
|
|
12
|
+
* @module fhir-validator
|
|
13
|
+
*/
|
|
14
|
+
export type { ValidationOptions, ValidationResult, ValidationIssue, ValidationIssueCode, ValidationContext, } from './types.js';
|
|
15
|
+
export { createValidationIssue, createValidationContext, resolveValidationOptions, hasValidationErrors, filterIssuesBySeverity, filterIssuesByCode, } from './types.js';
|
|
16
|
+
export { extractValues, pathExists, findChoiceTypeField, normalizeChoicePath, extractChoiceTypeSuffix, } from './path-extractor.js';
|
|
17
|
+
export { validateCardinality, validateRequired, validateType, validateChoiceType, inferFhirType, deepEqual, validateFixed, matchesPattern, validatePattern, extractReferenceType, validateReference, } from './validation-rules.js';
|
|
18
|
+
export { validateSlicing, findMatchingSlice, matchesDiscriminator, isSliceOrderValid, extractValueAtPath, getSliceDiscriminatorValue, getSliceTypes, } from './slicing-validator.js';
|
|
19
|
+
export { StructureValidator } from './structure-validator.js';
|
|
20
|
+
export type { InvariantValidationOptions } from './invariant-validator.js';
|
|
21
|
+
export { validateInvariants, validateSingleInvariant, validateAllInvariants, } from './invariant-validator.js';
|
|
22
|
+
export { ValidatorError, ProfileNotFoundError, ValidationFailedError, } from './errors.js';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,aAAa,EACb,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,SAAS,EACT,aAAa,EACb,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,0BAA0B,EAC1B,aAAa,GACd,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D,YAAY,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FHIRPath Invariant Validator
|
|
3
|
+
*
|
|
4
|
+
* Evaluates FHIRPath constraint expressions from StructureDefinition
|
|
5
|
+
* elements and reports violations as ValidationIssues.
|
|
6
|
+
*
|
|
7
|
+
* @module validator
|
|
8
|
+
*/
|
|
9
|
+
import type { Invariant, CanonicalElement } from '../model/canonical-profile.js';
|
|
10
|
+
import type { ValidationIssue } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Options for invariant validation.
|
|
13
|
+
*/
|
|
14
|
+
export interface InvariantValidationOptions {
|
|
15
|
+
/** Skip all invariant evaluation. */
|
|
16
|
+
skipInvariants?: boolean;
|
|
17
|
+
/** Skip invariants from inherited profiles (only evaluate local constraints). */
|
|
18
|
+
skipInheritedInvariants?: boolean;
|
|
19
|
+
/** Profile URL of the current profile (used to filter inherited constraints). */
|
|
20
|
+
currentProfileUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Validate FHIRPath invariants (constraint.expression) on a single element value.
|
|
24
|
+
*
|
|
25
|
+
* For each constraint on the element that has an expression, the expression
|
|
26
|
+
* is evaluated against the value. If it evaluates to `false`, a validation
|
|
27
|
+
* issue is recorded.
|
|
28
|
+
*
|
|
29
|
+
* @param element - The canonical element with constraints.
|
|
30
|
+
* @param value - The value at the element path (raw JS value).
|
|
31
|
+
* @param resource - The root resource being validated (for %resource context).
|
|
32
|
+
* @param issues - Mutable array to push validation issues into.
|
|
33
|
+
* @param options - Validation options.
|
|
34
|
+
*/
|
|
35
|
+
export declare function validateInvariants(element: CanonicalElement, value: unknown, resource: unknown, issues: ValidationIssue[], options?: InvariantValidationOptions): void;
|
|
36
|
+
/**
|
|
37
|
+
* Validate a single FHIRPath invariant constraint.
|
|
38
|
+
*
|
|
39
|
+
* @param constraint - The invariant to validate.
|
|
40
|
+
* @param path - The element path for error reporting.
|
|
41
|
+
* @param value - The value to validate.
|
|
42
|
+
* @param resource - The root resource.
|
|
43
|
+
* @param issues - Mutable array to push issues into.
|
|
44
|
+
* @param options - Validation options.
|
|
45
|
+
*/
|
|
46
|
+
export declare function validateSingleInvariant(constraint: Invariant, path: string, value: unknown, resource: unknown, issues: ValidationIssue[], options?: InvariantValidationOptions): void;
|
|
47
|
+
/**
|
|
48
|
+
* Validate all invariants for multiple element-value pairs.
|
|
49
|
+
*
|
|
50
|
+
* Convenience function for batch validation of all constraints
|
|
51
|
+
* across a resource's elements.
|
|
52
|
+
*
|
|
53
|
+
* @param elements - Array of [element, values] pairs.
|
|
54
|
+
* @param resource - The root resource.
|
|
55
|
+
* @param options - Validation options.
|
|
56
|
+
* @returns Array of validation issues.
|
|
57
|
+
*/
|
|
58
|
+
export declare function validateAllInvariants(elements: Array<{
|
|
59
|
+
element: CanonicalElement;
|
|
60
|
+
values: unknown[];
|
|
61
|
+
}>, resource: unknown, options?: InvariantValidationOptions): ValidationIssue[];
|
|
62
|
+
//# sourceMappingURL=invariant-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invariant-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/invariant-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAUlD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,qCAAqC;IACrC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iFAAiF;IACjF,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,iFAAiF;IACjF,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,OAAO,EACjB,MAAM,EAAE,eAAe,EAAE,EACzB,OAAO,GAAE,0BAA+B,GACvC,IAAI,CAYN;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,SAAS,EACrB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,OAAO,EACjB,MAAM,EAAE,eAAe,EAAE,EACzB,OAAO,GAAE,0BAA+B,GACvC,IAAI,CAyDN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,KAAK,CAAC;IAAE,OAAO,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC,EACjE,QAAQ,EAAE,OAAO,EACjB,OAAO,GAAE,0BAA+B,GACvC,eAAe,EAAE,CAcnB"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fhir-validator — Path Extractor
|
|
3
|
+
*
|
|
4
|
+
* Extracts values from FHIR resource instances using element paths.
|
|
5
|
+
* Handles nested objects, arrays, and choice type (`[x]`) paths.
|
|
6
|
+
*
|
|
7
|
+
* This is the core utility that bridges CanonicalProfile element paths
|
|
8
|
+
* (e.g., `Patient.name.family`) to actual values in a resource JSON object.
|
|
9
|
+
*
|
|
10
|
+
* @module fhir-validator
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Extract values from a resource instance using an element path.
|
|
14
|
+
*
|
|
15
|
+
* Navigates the resource object following the dot-separated path segments.
|
|
16
|
+
* Arrays are automatically expanded — if an intermediate node is an array,
|
|
17
|
+
* extraction continues into each element.
|
|
18
|
+
*
|
|
19
|
+
* @param resource - The resource object to extract from.
|
|
20
|
+
* @param path - Element path (e.g., `'Patient.name.family'`).
|
|
21
|
+
* @returns Array of extracted values (empty if path not found).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const patient = {
|
|
26
|
+
* resourceType: 'Patient',
|
|
27
|
+
* name: [
|
|
28
|
+
* { family: 'Smith', given: ['John', 'James'] },
|
|
29
|
+
* { family: 'Doe' },
|
|
30
|
+
* ],
|
|
31
|
+
* };
|
|
32
|
+
*
|
|
33
|
+
* extractValues(patient, 'Patient.name')
|
|
34
|
+
* // → [{ family: 'Smith', given: ['John', 'James'] }, { family: 'Doe' }]
|
|
35
|
+
*
|
|
36
|
+
* extractValues(patient, 'Patient.name.family')
|
|
37
|
+
* // → ['Smith', 'Doe']
|
|
38
|
+
*
|
|
39
|
+
* extractValues(patient, 'Patient.name.given')
|
|
40
|
+
* // → ['John', 'James']
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function extractValues(resource: Record<string, unknown>, path: string): unknown[];
|
|
44
|
+
/**
|
|
45
|
+
* Check if a path exists in the resource (even if value is null/undefined).
|
|
46
|
+
*
|
|
47
|
+
* Unlike `extractValues`, this checks for property existence rather than
|
|
48
|
+
* value presence. A property set to `null` or `undefined` still "exists".
|
|
49
|
+
*
|
|
50
|
+
* @param resource - The resource object to check.
|
|
51
|
+
* @param path - Element path (e.g., `'Patient.name'`).
|
|
52
|
+
* @returns `true` if the path exists in the resource.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* pathExists({ resourceType: 'Patient', name: [] }, 'Patient.name')
|
|
57
|
+
* // → true
|
|
58
|
+
*
|
|
59
|
+
* pathExists({ resourceType: 'Patient' }, 'Patient.name')
|
|
60
|
+
* // → false
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function pathExists(resource: Record<string, unknown>, path: string): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Find the concrete choice type property name in an object.
|
|
66
|
+
*
|
|
67
|
+
* Given a choice base name (e.g., `'value'`), searches the object for
|
|
68
|
+
* a property like `valueString`, `valueQuantity`, etc.
|
|
69
|
+
*
|
|
70
|
+
* @param obj - The object to search.
|
|
71
|
+
* @param baseName - The choice type base name (without `[x]`).
|
|
72
|
+
* @returns The concrete property name, or `undefined` if not found.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* findChoiceTypeField({ valueQuantity: { value: 120 } }, 'value')
|
|
77
|
+
* // → 'valueQuantity'
|
|
78
|
+
*
|
|
79
|
+
* findChoiceTypeField({ code: '12345' }, 'value')
|
|
80
|
+
* // → undefined
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function findChoiceTypeField(obj: Record<string, unknown>, baseName: string): string | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Normalize a choice type path to a concrete path.
|
|
86
|
+
*
|
|
87
|
+
* Replaces the `[x]` suffix with the actual type suffix found in the object.
|
|
88
|
+
*
|
|
89
|
+
* @param basePath - The choice type path (e.g., `'Observation.value[x]'`).
|
|
90
|
+
* @param concreteField - The concrete field name (e.g., `'valueQuantity'`).
|
|
91
|
+
* @returns The normalized path (e.g., `'Observation.valueQuantity'`).
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* normalizeChoicePath('Observation.value[x]', 'valueQuantity')
|
|
96
|
+
* // → 'Observation.valueQuantity'
|
|
97
|
+
*
|
|
98
|
+
* normalizeChoicePath('Extension.value[x]', 'valueString')
|
|
99
|
+
* // → 'Extension.valueString'
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function normalizeChoicePath(basePath: string, concreteField: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* Extract the type suffix from a concrete choice type property name.
|
|
105
|
+
*
|
|
106
|
+
* @param concreteField - The concrete field name (e.g., `'valueQuantity'`).
|
|
107
|
+
* @param baseName - The choice type base name (e.g., `'value'`).
|
|
108
|
+
* @returns The type suffix (e.g., `'Quantity'`), or `undefined` if not a match.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* extractChoiceTypeSuffix('valueQuantity', 'value')
|
|
113
|
+
* // → 'Quantity'
|
|
114
|
+
*
|
|
115
|
+
* extractChoiceTypeSuffix('valueString', 'value')
|
|
116
|
+
* // → 'String'
|
|
117
|
+
*
|
|
118
|
+
* extractChoiceTypeSuffix('code', 'value')
|
|
119
|
+
* // → undefined
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function extractChoiceTypeSuffix(concreteField: string, baseName: string): string | undefined;
|
|
123
|
+
//# sourceMappingURL=path-extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-extractor.d.ts","sourceRoot":"","sources":["../../../src/validator/path-extractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAwEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,IAAI,EAAE,MAAM,GACX,OAAO,EAAE,CAwBX;AAmHD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,IAAI,EAAE,MAAM,GACX,OAAO,CAaT;AAsED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,SAAS,CAsBpB;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,GACpB,MAAM,CAYR;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,SAAS,CAepB"}
|