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,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FHIR R4 StructureDefinition Model
|
|
3
|
+
*
|
|
4
|
+
* Defines the complete StructureDefinition resource type as per the FHIR R4
|
|
5
|
+
* specification, including all sub-types (Mapping, Context, Snapshot, Differential).
|
|
6
|
+
*
|
|
7
|
+
* StructureDefinition is the core metadata resource that describes the shape
|
|
8
|
+
* of other FHIR resources, data types, and extensions. It is the primary input
|
|
9
|
+
* for snapshot generation and validation.
|
|
10
|
+
*
|
|
11
|
+
* @see https://hl7.org/fhir/R4/structuredefinition.html
|
|
12
|
+
* @module fhir-model
|
|
13
|
+
*/
|
|
14
|
+
import type { FhirBoolean, FhirCanonical, FhirDateTime, FhirId, FhirMarkdown, FhirString, FhirUri, PublicationStatus, StructureDefinitionKind, TypeDerivationRule, ExtensionContextType, FhirVersionCode, CodeableConcept, Coding, ContactDetail, BackboneElement, DomainResource, Identifier, UsageContext } from './primitives.js';
|
|
15
|
+
import type { ElementDefinition } from './element-definition.js';
|
|
16
|
+
/**
|
|
17
|
+
* A mapping to an external specification that the structure conforms to.
|
|
18
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.mapping
|
|
19
|
+
*/
|
|
20
|
+
export interface StructureDefinitionMapping extends BackboneElement {
|
|
21
|
+
/** Internal id when this mapping is used (1..1) */
|
|
22
|
+
identity: FhirId;
|
|
23
|
+
/** Identifies what this mapping refers to (0..1) */
|
|
24
|
+
uri?: FhirUri;
|
|
25
|
+
/** Names what this mapping refers to (0..1) */
|
|
26
|
+
name?: FhirString;
|
|
27
|
+
/** Versions, issues, scope limitations, etc. (0..1) */
|
|
28
|
+
comment?: FhirString;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Identifies the types of resource or data type elements to which the
|
|
32
|
+
* extension can be applied. Only relevant when kind = 'resource' and
|
|
33
|
+
* type = 'Extension'.
|
|
34
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.context
|
|
35
|
+
*/
|
|
36
|
+
export interface StructureDefinitionContext extends BackboneElement {
|
|
37
|
+
/** fhirpath | element | extension (1..1) */
|
|
38
|
+
type: ExtensionContextType;
|
|
39
|
+
/** Where the extension can be used in instances (1..1) */
|
|
40
|
+
expression: FhirString;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A snapshot view of the structure, containing all element definitions
|
|
44
|
+
* with their complete constraint information resolved from the
|
|
45
|
+
* inheritance chain.
|
|
46
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.snapshot
|
|
47
|
+
*/
|
|
48
|
+
export interface StructureDefinitionSnapshot extends BackboneElement {
|
|
49
|
+
/**
|
|
50
|
+
* Definition of elements in the resource (if no StructureDefinition) (1..*)
|
|
51
|
+
*
|
|
52
|
+
* The snapshot contains the complete, flattened list of all ElementDefinition
|
|
53
|
+
* entries with all constraints from the inheritance chain fully resolved.
|
|
54
|
+
* This is the "semantic truth" used for validation and interpretation.
|
|
55
|
+
*/
|
|
56
|
+
element: ElementDefinition[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A differential view of the structure, containing only the constraints
|
|
60
|
+
* that differ from the base definition. This is the compact authoring
|
|
61
|
+
* format used when creating profiles.
|
|
62
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.differential
|
|
63
|
+
*/
|
|
64
|
+
export interface StructureDefinitionDifferential extends BackboneElement {
|
|
65
|
+
/**
|
|
66
|
+
* Definition of elements in the resource (if no StructureDefinition) (1..*)
|
|
67
|
+
*
|
|
68
|
+
* The differential contains only the constraints that differ from the base
|
|
69
|
+
* profile. It MUST NOT be used directly for semantic interpretation — it
|
|
70
|
+
* must first be expanded into a snapshot via snapshot generation.
|
|
71
|
+
*/
|
|
72
|
+
element: ElementDefinition[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A definition of a FHIR structure — a resource, data type, or extension.
|
|
76
|
+
*
|
|
77
|
+
* StructureDefinition is the central metadata resource in FHIR. It defines:
|
|
78
|
+
* - The shape of resources and data types (via snapshot/differential)
|
|
79
|
+
* - Profile constraints (via derivation = 'constraint')
|
|
80
|
+
* - Extension definitions (via kind = 'resource', type = 'Extension')
|
|
81
|
+
*
|
|
82
|
+
* This interface extends DomainResource and includes all fields defined
|
|
83
|
+
* in the FHIR R4 specification.
|
|
84
|
+
*
|
|
85
|
+
* @see https://hl7.org/fhir/R4/structuredefinition.html
|
|
86
|
+
*/
|
|
87
|
+
export interface StructureDefinition extends DomainResource {
|
|
88
|
+
/** Resource type discriminator (1..1) */
|
|
89
|
+
resourceType: 'StructureDefinition';
|
|
90
|
+
/**
|
|
91
|
+
* Canonical identifier for this structure definition, represented as a URI
|
|
92
|
+
* (globally unique) (1..1)
|
|
93
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.url
|
|
94
|
+
*/
|
|
95
|
+
url: FhirUri;
|
|
96
|
+
/**
|
|
97
|
+
* Additional identifier for the structure definition (0..*)
|
|
98
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.identifier
|
|
99
|
+
*/
|
|
100
|
+
identifier?: Identifier[];
|
|
101
|
+
/**
|
|
102
|
+
* Business version of the structure definition (0..1)
|
|
103
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.version
|
|
104
|
+
*/
|
|
105
|
+
version?: FhirString;
|
|
106
|
+
/**
|
|
107
|
+
* Computer-readable name of the structure definition (1..1)
|
|
108
|
+
*
|
|
109
|
+
* Name should be usable as an identifier for the module by machine
|
|
110
|
+
* processing applications such as code generation.
|
|
111
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.name
|
|
112
|
+
*/
|
|
113
|
+
name: FhirString;
|
|
114
|
+
/**
|
|
115
|
+
* Human-readable name for the structure definition (0..1)
|
|
116
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.title
|
|
117
|
+
*/
|
|
118
|
+
title?: FhirString;
|
|
119
|
+
/**
|
|
120
|
+
* Publication status: draft | active | retired | unknown (1..1)
|
|
121
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.status
|
|
122
|
+
*/
|
|
123
|
+
status: PublicationStatus;
|
|
124
|
+
/**
|
|
125
|
+
* For testing purposes, not real usage (0..1)
|
|
126
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.experimental
|
|
127
|
+
*/
|
|
128
|
+
experimental?: FhirBoolean;
|
|
129
|
+
/**
|
|
130
|
+
* Date last changed (0..1)
|
|
131
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.date
|
|
132
|
+
*/
|
|
133
|
+
date?: FhirDateTime;
|
|
134
|
+
/**
|
|
135
|
+
* Name of the publisher (organization or individual) (0..1)
|
|
136
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.publisher
|
|
137
|
+
*/
|
|
138
|
+
publisher?: FhirString;
|
|
139
|
+
/**
|
|
140
|
+
* Contact details for the publisher (0..*)
|
|
141
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.contact
|
|
142
|
+
*/
|
|
143
|
+
contact?: ContactDetail[];
|
|
144
|
+
/**
|
|
145
|
+
* Natural language description of the structure definition (0..1)
|
|
146
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.description
|
|
147
|
+
*/
|
|
148
|
+
description?: FhirMarkdown;
|
|
149
|
+
/**
|
|
150
|
+
* The context that the content is intended to support (0..*)
|
|
151
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.useContext
|
|
152
|
+
*/
|
|
153
|
+
useContext?: UsageContext[];
|
|
154
|
+
/**
|
|
155
|
+
* Intended jurisdiction for structure definition (0..*)
|
|
156
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.jurisdiction
|
|
157
|
+
*/
|
|
158
|
+
jurisdiction?: CodeableConcept[];
|
|
159
|
+
/**
|
|
160
|
+
* Why this structure definition is defined (0..1)
|
|
161
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.purpose
|
|
162
|
+
*/
|
|
163
|
+
purpose?: FhirMarkdown;
|
|
164
|
+
/**
|
|
165
|
+
* Use and/or publishing restrictions (0..1)
|
|
166
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.copyright
|
|
167
|
+
*/
|
|
168
|
+
copyright?: FhirMarkdown;
|
|
169
|
+
/**
|
|
170
|
+
* Assist with indexing and finding (0..*)
|
|
171
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.keyword
|
|
172
|
+
*/
|
|
173
|
+
keyword?: Coding[];
|
|
174
|
+
/**
|
|
175
|
+
* FHIR Version this StructureDefinition targets (0..1)
|
|
176
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.fhirVersion
|
|
177
|
+
*/
|
|
178
|
+
fhirVersion?: FhirVersionCode;
|
|
179
|
+
/**
|
|
180
|
+
* External specification that the content is mapped to (0..*)
|
|
181
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.mapping
|
|
182
|
+
*/
|
|
183
|
+
mapping?: StructureDefinitionMapping[];
|
|
184
|
+
/**
|
|
185
|
+
* The kind of structure: primitive-type | complex-type | resource | logical (1..1)
|
|
186
|
+
*
|
|
187
|
+
* Determines the fundamental nature of the structure being defined.
|
|
188
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.kind
|
|
189
|
+
*/
|
|
190
|
+
kind: StructureDefinitionKind;
|
|
191
|
+
/**
|
|
192
|
+
* Whether the structure is abstract (1..1)
|
|
193
|
+
*
|
|
194
|
+
* Abstract types cannot be instantiated directly. For example,
|
|
195
|
+
* `DomainResource` is abstract — you cannot create a resource
|
|
196
|
+
* with `resourceType: "DomainResource"`.
|
|
197
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.abstract
|
|
198
|
+
*/
|
|
199
|
+
abstract: FhirBoolean;
|
|
200
|
+
/**
|
|
201
|
+
* If an extension, where it can be used in instances (0..*)
|
|
202
|
+
*
|
|
203
|
+
* Only meaningful when kind = 'resource' and type = 'Extension'.
|
|
204
|
+
* Defines the contexts in which the extension can appear.
|
|
205
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.context
|
|
206
|
+
*/
|
|
207
|
+
context?: StructureDefinitionContext[];
|
|
208
|
+
/**
|
|
209
|
+
* FHIRPath invariants — conditions that must be true for the
|
|
210
|
+
* extension to be valid in a given context (0..*)
|
|
211
|
+
*
|
|
212
|
+
* Only meaningful when kind = 'resource' and type = 'Extension'.
|
|
213
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.contextInvariant
|
|
214
|
+
*/
|
|
215
|
+
contextInvariant?: FhirString[];
|
|
216
|
+
/**
|
|
217
|
+
* Type defined or constrained by this structure (1..1)
|
|
218
|
+
*
|
|
219
|
+
* For base definitions (derivation = 'specialization'), this is the
|
|
220
|
+
* type being defined (e.g., 'Patient', 'Observation').
|
|
221
|
+
* For profiles (derivation = 'constraint'), this is the type being
|
|
222
|
+
* constrained (must match the type of the base definition).
|
|
223
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.type
|
|
224
|
+
*/
|
|
225
|
+
type: FhirUri;
|
|
226
|
+
/**
|
|
227
|
+
* Definition that this type is constrained/specialized from (0..1)
|
|
228
|
+
*
|
|
229
|
+
* The canonical URL of the base StructureDefinition. This forms the
|
|
230
|
+
* inheritance chain used in snapshot generation.
|
|
231
|
+
* - For specializations: points to the parent type
|
|
232
|
+
* - For constraints: points to the profile being constrained
|
|
233
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.baseDefinition
|
|
234
|
+
*/
|
|
235
|
+
baseDefinition?: FhirCanonical;
|
|
236
|
+
/**
|
|
237
|
+
* specialization | constraint (0..1)
|
|
238
|
+
*
|
|
239
|
+
* - `specialization`: defines a new type (e.g., Patient specializes DomainResource)
|
|
240
|
+
* - `constraint`: constrains an existing type (e.g., USCorePatient constrains Patient)
|
|
241
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.derivation
|
|
242
|
+
*/
|
|
243
|
+
derivation?: TypeDerivationRule;
|
|
244
|
+
/**
|
|
245
|
+
* Snapshot view of the structure (0..1)
|
|
246
|
+
*
|
|
247
|
+
* Contains the complete, flattened element tree with all constraints
|
|
248
|
+
* from the inheritance chain resolved. Generated by the snapshot
|
|
249
|
+
* generation algorithm (fhir-profile module).
|
|
250
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.snapshot
|
|
251
|
+
*/
|
|
252
|
+
snapshot?: StructureDefinitionSnapshot;
|
|
253
|
+
/**
|
|
254
|
+
* Differential constraints of the structure (0..1)
|
|
255
|
+
*
|
|
256
|
+
* Contains only the constraints that differ from the base definition.
|
|
257
|
+
* This is the authoring format — profiles are typically written as
|
|
258
|
+
* differentials to avoid repeating base constraints.
|
|
259
|
+
* @see https://hl7.org/fhir/R4/structuredefinition-definitions.html#StructureDefinition.differential
|
|
260
|
+
*/
|
|
261
|
+
differential?: StructureDefinitionDifferential;
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=structure-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structure-definition.d.ts","sourceRoot":"","sources":["../../../src/model/structure-definition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,YAAY,EACZ,MAAM,EACN,YAAY,EACZ,UAAU,EACV,OAAO,EACP,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,MAAM,EACN,aAAa,EACb,eAAe,EACf,cAAc,EACd,UAAU,EACV,YAAY,EACb,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAMjE;;;GAGG;AACH,MAAM,WAAW,0BAA2B,SAAQ,eAAe;IACjE,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,+CAA+C;IAC/C,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,uDAAuD;IACvD,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,WAAW,0BAA2B,SAAQ,eAAe;IACjE,4CAA4C;IAC5C,IAAI,EAAE,oBAAoB,CAAC;IAC3B,0DAA0D;IAC1D,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;;;;GAKG;AACH,MAAM,WAAW,2BAA4B,SAAQ,eAAe;IAClE;;;;;;OAMG;IACH,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AAED;;;;;GAKG;AACH,MAAM,WAAW,+BAAgC,SAAQ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MG;IACH,OAAO,CAAC,EAAE,0BAA0B,EAAE,CAAC;IAEvC;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,UAAU,EAAE,CAAC;IAEhC;;;;;;;;OAQG;IACH,IAAI,EAAE,OAAO,CAAC;IAEd;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,aAAa,CAAC;IAE/B;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAIhC;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,2BAA2B,CAAC;IAEvC;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,+BAA+B,CAAC;CAChD"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FHIR Choice Type [x] Parser
|
|
3
|
+
*
|
|
4
|
+
* Handles FHIR R4 choice type property dispatch. In FHIR JSON, a choice
|
|
5
|
+
* type element like `value[x]` does not appear as a single property.
|
|
6
|
+
* Instead, the property name includes a type suffix:
|
|
7
|
+
*
|
|
8
|
+
* ```json
|
|
9
|
+
* { "valueString": "hello" }
|
|
10
|
+
* { "valueQuantity": { "value": 42, "unit": "kg" } }
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* This module:
|
|
14
|
+
* 1. Defines the `ChoiceTypeField` descriptor and `ChoiceValue` result type
|
|
15
|
+
* 2. Provides `extractChoiceValue()` to scan an object for matching properties
|
|
16
|
+
* 3. Detects multiple-value conflicts (e.g., both `valueString` and `valueBoolean`)
|
|
17
|
+
* 4. Consumes `_element` companions for primitive choice type variants
|
|
18
|
+
* 5. Maintains a registry of all known choice type fields in the model
|
|
19
|
+
*
|
|
20
|
+
* @see https://hl7.org/fhir/R4/formats.html#choice
|
|
21
|
+
* @see ADR-003: FHIR R4 Choice Type [x] Representation Strategy
|
|
22
|
+
* @module fhir-parser
|
|
23
|
+
*/
|
|
24
|
+
import type { ParseIssue } from './parse-error.js';
|
|
25
|
+
/**
|
|
26
|
+
* Definition of a choice type [x] field.
|
|
27
|
+
*
|
|
28
|
+
* Each choice type field has a base name and a set of allowed type suffixes.
|
|
29
|
+
* The actual JSON property name is `baseName` + one of `allowedTypes`.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const field: ChoiceTypeField = {
|
|
34
|
+
* baseName: 'value',
|
|
35
|
+
* allowedTypes: ['String', 'Boolean', 'Integer', 'Quantity', ...],
|
|
36
|
+
* };
|
|
37
|
+
* // Matches: valueString, valueBoolean, valueInteger, valueQuantity, ...
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export interface ChoiceTypeField {
|
|
41
|
+
/** Base property name (e.g., "value", "defaultValue", "fixed") */
|
|
42
|
+
readonly baseName: string;
|
|
43
|
+
/** Allowed type suffixes (e.g., ["String", "Boolean", "Quantity"]) */
|
|
44
|
+
readonly allowedTypes: readonly string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parsed choice type value.
|
|
48
|
+
*
|
|
49
|
+
* Preserves the original JSON property name for round-trip serialization.
|
|
50
|
+
*/
|
|
51
|
+
export interface ChoiceValue {
|
|
52
|
+
/** Type suffix (e.g., "String", "Quantity") */
|
|
53
|
+
readonly typeName: string;
|
|
54
|
+
/** The actual value from JSON */
|
|
55
|
+
readonly value: unknown;
|
|
56
|
+
/** Original JSON property name (e.g., "valueString") — for serialization */
|
|
57
|
+
readonly propertyName: string;
|
|
58
|
+
/** _element companion data, if present */
|
|
59
|
+
readonly elementExtension?: unknown;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Extract a choice type value from a JSON object.
|
|
63
|
+
*
|
|
64
|
+
* Scans all properties of `obj` looking for keys that match
|
|
65
|
+
* `choiceField.baseName` + one of `choiceField.allowedTypes`.
|
|
66
|
+
*
|
|
67
|
+
* Handles:
|
|
68
|
+
* - Single match → returns `ChoiceValue` with type info
|
|
69
|
+
* - No match → returns `null` (field not present)
|
|
70
|
+
* - Multiple matches → returns first match + `MULTIPLE_CHOICE_VALUES` error
|
|
71
|
+
* - Unknown suffix → `INVALID_CHOICE_TYPE` error
|
|
72
|
+
* - `_element` companion → consumed and attached to result
|
|
73
|
+
*
|
|
74
|
+
* @param obj - The raw JSON object to scan
|
|
75
|
+
* @param choiceField - The choice type field definition
|
|
76
|
+
* @param path - JSON path for error reporting
|
|
77
|
+
* @returns Extracted value, issues, and list of consumed keys
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const field = { baseName: 'value', allowedTypes: ['String', 'Boolean'] };
|
|
82
|
+
* const obj = { valueString: 'hello' };
|
|
83
|
+
* const { result, consumedKeys } = extractChoiceValue(obj, field, 'Extension');
|
|
84
|
+
* // result = { typeName: 'String', value: 'hello', propertyName: 'valueString' }
|
|
85
|
+
* // consumedKeys = ['valueString']
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function extractChoiceValue(obj: Record<string, unknown>, choiceField: ChoiceTypeField, path: string): {
|
|
89
|
+
result: ChoiceValue | null;
|
|
90
|
+
issues: ParseIssue[];
|
|
91
|
+
consumedKeys: string[];
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Extract all choice type values from a JSON object for a given set of fields.
|
|
95
|
+
*
|
|
96
|
+
* Convenience function that calls `extractChoiceValue` for each field definition
|
|
97
|
+
* and aggregates results.
|
|
98
|
+
*
|
|
99
|
+
* @param obj - The raw JSON object
|
|
100
|
+
* @param choiceFields - Array of choice type field definitions
|
|
101
|
+
* @param path - JSON path for error reporting
|
|
102
|
+
* @returns Map of baseName → ChoiceValue, all issues, and all consumed keys
|
|
103
|
+
*/
|
|
104
|
+
export declare function extractAllChoiceValues(obj: Record<string, unknown>, choiceFields: readonly ChoiceTypeField[], path: string): {
|
|
105
|
+
results: ReadonlyMap<string, ChoiceValue>;
|
|
106
|
+
issues: ParseIssue[];
|
|
107
|
+
consumedKeys: string[];
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* All FHIR R4 data types that can appear as choice type suffixes.
|
|
111
|
+
*
|
|
112
|
+
* This covers all primitive types (capitalized) and common complex types.
|
|
113
|
+
* Used by choice fields that allow "any FHIR data type" (~50 types).
|
|
114
|
+
*
|
|
115
|
+
* @see https://hl7.org/fhir/R4/datatypes.html
|
|
116
|
+
*/
|
|
117
|
+
export declare const ALL_FHIR_TYPE_SUFFIXES: readonly string[];
|
|
118
|
+
/**
|
|
119
|
+
* Type suffixes for minValue[x] and maxValue[x] fields.
|
|
120
|
+
*
|
|
121
|
+
* These are restricted to orderable types only.
|
|
122
|
+
* @see https://hl7.org/fhir/R4/elementdefinition-definitions.html#ElementDefinition.minValue_x_
|
|
123
|
+
*/
|
|
124
|
+
export declare const MIN_MAX_VALUE_TYPE_SUFFIXES: readonly string[];
|
|
125
|
+
/**
|
|
126
|
+
* Type suffixes for UsageContext.value[x].
|
|
127
|
+
* @see https://hl7.org/fhir/R4/metadatatypes-definitions.html#UsageContext.value_x_
|
|
128
|
+
*/
|
|
129
|
+
export declare const USAGE_CONTEXT_VALUE_TYPE_SUFFIXES: readonly string[];
|
|
130
|
+
/**
|
|
131
|
+
* All known choice type fields in the fhir-model, grouped by host type.
|
|
132
|
+
*
|
|
133
|
+
* This registry is used by the parser to know which choice type fields
|
|
134
|
+
* exist on each type, enabling proper extraction and validation.
|
|
135
|
+
*
|
|
136
|
+
* Coverage: 8 choice type fields across 4 host types.
|
|
137
|
+
*
|
|
138
|
+
* | Host Type | Base Name | Allowed Types |
|
|
139
|
+
* |----------------------------|----------------|---------------|
|
|
140
|
+
* | Extension | value | All (~50) |
|
|
141
|
+
* | UsageContext | value | 4 |
|
|
142
|
+
* | ElementDefinition | defaultValue | All (~50) |
|
|
143
|
+
* | ElementDefinition | fixed | All (~50) |
|
|
144
|
+
* | ElementDefinition | pattern | All (~50) |
|
|
145
|
+
* | ElementDefinition | minValue | 9 |
|
|
146
|
+
* | ElementDefinition | maxValue | 9 |
|
|
147
|
+
* | ElementDefinitionExample | value | All (~50) |
|
|
148
|
+
*/
|
|
149
|
+
export declare const CHOICE_TYPE_FIELDS: ReadonlyMap<string, readonly ChoiceTypeField[]>;
|
|
150
|
+
/**
|
|
151
|
+
* Get the choice type base names for a given host type.
|
|
152
|
+
*
|
|
153
|
+
* Returns an array of base names (e.g., `['value']` for Extension,
|
|
154
|
+
* `['defaultValue', 'fixed', 'pattern', 'minValue', 'maxValue']` for
|
|
155
|
+
* ElementDefinition).
|
|
156
|
+
*
|
|
157
|
+
* This can be used to pass `choiceFieldBases` to `parseComplexObject`
|
|
158
|
+
* for Pass 3 key matching, or for other custom parsing logic.
|
|
159
|
+
*
|
|
160
|
+
* @param hostType - The FHIR type name (e.g., "Extension", "ElementDefinition")
|
|
161
|
+
* @returns Array of base names, or empty array if no choice fields
|
|
162
|
+
*/
|
|
163
|
+
export declare function getChoiceFieldBases(hostType: string): readonly string[];
|
|
164
|
+
/**
|
|
165
|
+
* Get the choice type field definitions for a given host type.
|
|
166
|
+
*
|
|
167
|
+
* @param hostType - The FHIR type name
|
|
168
|
+
* @returns Array of ChoiceTypeField definitions, or empty array
|
|
169
|
+
*/
|
|
170
|
+
export declare function getChoiceFields(hostType: string): readonly ChoiceTypeField[];
|
|
171
|
+
/**
|
|
172
|
+
* Check whether a property name matches any choice type field for a host type.
|
|
173
|
+
*
|
|
174
|
+
* @param key - The JSON property name to check
|
|
175
|
+
* @param hostType - The FHIR type name
|
|
176
|
+
* @returns The matching ChoiceTypeField and extracted suffix, or null
|
|
177
|
+
*/
|
|
178
|
+
export declare function matchChoiceTypeProperty(key: string, hostType: string): {
|
|
179
|
+
field: ChoiceTypeField;
|
|
180
|
+
suffix: string;
|
|
181
|
+
} | null;
|
|
182
|
+
//# sourceMappingURL=choice-type-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choice-type-parser.d.ts","sourceRoot":"","sources":["../../../src/parser/choice-type-parser.ts"],"names":[],"mappings":"AAAA;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,SAAS,MAAM,EAwD1C,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,SAAS,MAAM,EAU/C,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,iCAAiC,EAAE,SAAS,MAAM,EAKrD,CAAC;AAMX;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAgC7E,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAIvE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,eAAe,EAAE,CAE5E;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,GACf;IAAE,KAAK,EAAE,eAAe,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAenD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `fhir-parser` — Public API
|
|
3
|
+
*
|
|
4
|
+
* Unified exports for the FHIR JSON parsing and serialization module.
|
|
5
|
+
* Internal helpers (primitive merging, choice extraction, validation) are
|
|
6
|
+
* intentionally kept private.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export type { ParseSeverity, ParseErrorCode, ParseIssue, ParseResult } from './parse-error.js';
|
|
11
|
+
export { parseSuccess, parseFailure, createIssue, hasErrors } from './parse-error.js';
|
|
12
|
+
export { parseFhirJson, parseFhirObject } from './json-parser.js';
|
|
13
|
+
export { parseStructureDefinition, parseElementDefinition } from './structure-definition-parser.js';
|
|
14
|
+
export { serializeToFhirJson, serializeToFhirObject } from './serializer.js';
|
|
15
|
+
export type { ChoiceValue, ChoiceTypeField } from './choice-type-parser.js';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/parser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGtF,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGlE,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAGpG,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAG7E,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core FHIR JSON Parser Engine
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for parsing FHIR R4 JSON into TypeScript model types.
|
|
5
|
+
* Handles JSON.parse, resourceType dispatch, and provides the generic
|
|
6
|
+
* complex-type parsing infrastructure used by all downstream parsers.
|
|
7
|
+
*
|
|
8
|
+
* Architecture:
|
|
9
|
+
* ```
|
|
10
|
+
* parseFhirJson(string)
|
|
11
|
+
* └─ parseFhirObject(unknown)
|
|
12
|
+
* ├─ validateRootObject()
|
|
13
|
+
* ├─ extractResourceType()
|
|
14
|
+
* └─ dispatch by resourceType:
|
|
15
|
+
* ├─ "StructureDefinition" → parseStructureDefinitionObject() [Task 2.5]
|
|
16
|
+
* └─ other → parseGenericResource()
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* This module also exports lower-level utilities (`parseComplexObject`,
|
|
20
|
+
* `isPlainObject`, path helpers) that Task 2.3–2.5 build upon.
|
|
21
|
+
*
|
|
22
|
+
* @module fhir-parser
|
|
23
|
+
*/
|
|
24
|
+
import type { Resource } from '../model/primitives.js';
|
|
25
|
+
import { type ParseResult, type ParseIssue } from './parse-error.js';
|
|
26
|
+
/**
|
|
27
|
+
* A plain JSON object — `Record<string, unknown>` that is not null and not an array.
|
|
28
|
+
*
|
|
29
|
+
* This is the fundamental input shape for all FHIR complex type parsers.
|
|
30
|
+
*/
|
|
31
|
+
export type JsonObject = Record<string, unknown>;
|
|
32
|
+
/**
|
|
33
|
+
* Check whether a value is a plain JSON object (non-null, non-array, typeof "object").
|
|
34
|
+
*/
|
|
35
|
+
export declare function isPlainObject(value: unknown): value is JsonObject;
|
|
36
|
+
/**
|
|
37
|
+
* Append a property name to a JSON path.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* pathAppend("Patient", "name") // "Patient.name"
|
|
41
|
+
* pathAppend("$", "resourceType") // "$.resourceType"
|
|
42
|
+
*/
|
|
43
|
+
export declare function pathAppend(base: string, property: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Append an array index to a JSON path.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* pathIndex("Patient.name", 0) // "Patient.name[0]"
|
|
49
|
+
*/
|
|
50
|
+
export declare function pathIndex(base: string, index: number): string;
|
|
51
|
+
/**
|
|
52
|
+
* Metadata describing a single property of a FHIR complex type.
|
|
53
|
+
*
|
|
54
|
+
* Used by {@link parseComplexObject} to know how to interpret each JSON key.
|
|
55
|
+
*/
|
|
56
|
+
export interface PropertyDescriptor {
|
|
57
|
+
/** The property name as it appears in the TypeScript interface */
|
|
58
|
+
readonly name: string;
|
|
59
|
+
/**
|
|
60
|
+
* Whether this property holds a primitive FHIR type.
|
|
61
|
+
*
|
|
62
|
+
* When true, the parser will look for a companion `_name` property
|
|
63
|
+
* carrying id/extension metadata (FHIR primitive element split).
|
|
64
|
+
*/
|
|
65
|
+
readonly isPrimitive: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* The FHIR primitive type name (e.g., `'string'`, `'boolean'`, `'id'`).
|
|
68
|
+
*
|
|
69
|
+
* Required when `isPrimitive` is true. Used by `mergePrimitiveElement`
|
|
70
|
+
* to validate the JavaScript type of the value (string, number, or boolean).
|
|
71
|
+
* Defaults to `'string'` when not specified.
|
|
72
|
+
*/
|
|
73
|
+
readonly fhirType?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Whether this property is an array (max cardinality > 1).
|
|
76
|
+
*
|
|
77
|
+
* FHIR JSON always uses arrays for repeating elements, even when
|
|
78
|
+
* only one value is present.
|
|
79
|
+
*/
|
|
80
|
+
readonly isArray: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Parser function for complex-type values.
|
|
83
|
+
*
|
|
84
|
+
* Called for each value (or array element) to recursively parse
|
|
85
|
+
* nested complex types. If `undefined`, the value is passed through
|
|
86
|
+
* as-is (used for primitives and `unknown` choice-type placeholders).
|
|
87
|
+
*/
|
|
88
|
+
readonly parseElement?: (obj: JsonObject, path: string) => {
|
|
89
|
+
result: unknown;
|
|
90
|
+
issues: ParseIssue[];
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A schema describing all known properties of a FHIR complex type.
|
|
95
|
+
*
|
|
96
|
+
* Maps property names to their descriptors. Properties not in this map
|
|
97
|
+
* are reported as `UNEXPECTED_PROPERTY` warnings.
|
|
98
|
+
*
|
|
99
|
+
* Choice type `[x]` fields are NOT included here — they are handled
|
|
100
|
+
* separately by the choice-type-parser (Task 2.4).
|
|
101
|
+
*/
|
|
102
|
+
export type PropertySchema = ReadonlyMap<string, PropertyDescriptor>;
|
|
103
|
+
/**
|
|
104
|
+
* Result of parsing a complex object — the assembled result record
|
|
105
|
+
* plus any issues collected during parsing.
|
|
106
|
+
*/
|
|
107
|
+
export interface ComplexParseResult {
|
|
108
|
+
readonly result: JsonObject;
|
|
109
|
+
readonly issues: ParseIssue[];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Parse a FHIR complex type JSON object using a property schema.
|
|
113
|
+
*
|
|
114
|
+
* This is the workhorse function that all type-specific parsers delegate to.
|
|
115
|
+
* It uses a 4-pass strategy to process the JSON object's keys:
|
|
116
|
+
*
|
|
117
|
+
* 1. **Pass 1: Known properties** — maps non-primitive properties into the result,
|
|
118
|
+
* recursing for complex types. Primitive properties are marked as consumed but
|
|
119
|
+
* their values are deferred to Pass 2 for `_element` merging.
|
|
120
|
+
* 2. **Pass 2: Primitive `_element` merging** — for each primitive property in the
|
|
121
|
+
* schema, calls `mergePrimitiveElement` (or `mergePrimitiveArray`) from
|
|
122
|
+
* primitive-parser to merge the JSON value with its `_name` companion carrying
|
|
123
|
+
* id/extension metadata.
|
|
124
|
+
* 3. **Pass 3: Choice type `[x]`** — identifies choice type properties by matching
|
|
125
|
+
* `choiceFieldBases` prefixes with uppercase type suffixes, stores values as-is
|
|
126
|
+
* (full extraction delegated to choice-type-parser in Task 2.4)
|
|
127
|
+
* 4. **Pass 4: Unexpected properties** — emits `UNEXPECTED_PROPERTY` warnings for
|
|
128
|
+
* any remaining unconsumed keys
|
|
129
|
+
*
|
|
130
|
+
* @param obj - The raw JSON object to parse
|
|
131
|
+
* @param path - Current JSON path (for error reporting)
|
|
132
|
+
* @param schema - Property descriptors for this type
|
|
133
|
+
* @param choiceFieldBases - Base names of choice type `[x]` fields (e.g., `["value", "defaultValue"]`).
|
|
134
|
+
* Any key starting with one of these bases is treated as a potential choice type
|
|
135
|
+
* property and NOT flagged as unexpected. Actual choice type extraction is
|
|
136
|
+
* deferred to Task 2.4.
|
|
137
|
+
*/
|
|
138
|
+
export declare function parseComplexObject(obj: JsonObject, path: string, schema: PropertySchema, choiceFieldBases?: readonly string[]): ComplexParseResult;
|
|
139
|
+
/**
|
|
140
|
+
* Parse a FHIR JSON string into a Resource object.
|
|
141
|
+
*
|
|
142
|
+
* This is the main entry point for the parser. It:
|
|
143
|
+
* 1. Calls `JSON.parse()` with error capture
|
|
144
|
+
* 2. Delegates to {@link parseFhirObject} for structural parsing
|
|
145
|
+
*
|
|
146
|
+
* Stage-1 supports dedicated parsing for `StructureDefinition` (Task 2.5).
|
|
147
|
+
* All other resource types are parsed generically.
|
|
148
|
+
*
|
|
149
|
+
* @param json - A FHIR JSON string
|
|
150
|
+
* @returns A `ParseResult` containing the parsed `Resource` or error details
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const result = parseFhirJson('{"resourceType":"Patient","id":"123"}');
|
|
155
|
+
* if (result.success) {
|
|
156
|
+
* console.log(result.data.resourceType); // "Patient"
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function parseFhirJson(json: string): ParseResult<Resource>;
|
|
161
|
+
/**
|
|
162
|
+
* Parse an already-parsed JSON value into a Resource object.
|
|
163
|
+
*
|
|
164
|
+
* Use this when you already have a JavaScript object (e.g., from a database
|
|
165
|
+
* or from `JSON.parse()` called externally).
|
|
166
|
+
*
|
|
167
|
+
* @param obj - An unknown value (expected to be a plain JSON object with `resourceType`)
|
|
168
|
+
* @returns A `ParseResult` containing the parsed `Resource` or error details
|
|
169
|
+
*/
|
|
170
|
+
export declare function parseFhirObject(obj: unknown): ParseResult<Resource>;
|
|
171
|
+
//# sourceMappingURL=json-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-parser.d.ts","sourceRoot":"","sources":["../../../src/parser/json-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,UAAU,EAKhB,MAAM,kBAAkB,CAAC;AAQ1B;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD;;GAEG;AACH,wBAAgB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