@medplum/core 2.0.24 → 2.0.25

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 (81) hide show
  1. package/dist/cjs/index.cjs +28 -14114
  2. package/dist/cjs/index.cjs.map +7 -1
  3. package/dist/esm/index.mjs +31 -29
  4. package/dist/esm/index.mjs.map +7 -1
  5. package/dist/types/utils.d.ts +14 -0
  6. package/package.json +2 -2
  7. package/dist/cjs/index.min.cjs +0 -1
  8. package/dist/esm/access.mjs +0 -142
  9. package/dist/esm/access.mjs.map +0 -1
  10. package/dist/esm/base-schema.json.mjs +0 -4408
  11. package/dist/esm/base-schema.json.mjs.map +0 -1
  12. package/dist/esm/base64.mjs +0 -33
  13. package/dist/esm/base64.mjs.map +0 -1
  14. package/dist/esm/bundle.mjs +0 -36
  15. package/dist/esm/bundle.mjs.map +0 -1
  16. package/dist/esm/cache.mjs +0 -64
  17. package/dist/esm/cache.mjs.map +0 -1
  18. package/dist/esm/client.mjs +0 -2168
  19. package/dist/esm/client.mjs.map +0 -1
  20. package/dist/esm/crypto.mjs +0 -22
  21. package/dist/esm/crypto.mjs.map +0 -1
  22. package/dist/esm/eventtarget.mjs +0 -36
  23. package/dist/esm/eventtarget.mjs.map +0 -1
  24. package/dist/esm/fhirlexer/parse.mjs +0 -122
  25. package/dist/esm/fhirlexer/parse.mjs.map +0 -1
  26. package/dist/esm/fhirlexer/tokenize.mjs +0 -231
  27. package/dist/esm/fhirlexer/tokenize.mjs.map +0 -1
  28. package/dist/esm/fhirmapper/parse.mjs +0 -329
  29. package/dist/esm/fhirmapper/parse.mjs.map +0 -1
  30. package/dist/esm/fhirmapper/tokenize.mjs +0 -13
  31. package/dist/esm/fhirmapper/tokenize.mjs.map +0 -1
  32. package/dist/esm/fhirpath/atoms.mjs +0 -347
  33. package/dist/esm/fhirpath/atoms.mjs.map +0 -1
  34. package/dist/esm/fhirpath/date.mjs +0 -24
  35. package/dist/esm/fhirpath/date.mjs.map +0 -1
  36. package/dist/esm/fhirpath/functions.mjs +0 -1626
  37. package/dist/esm/fhirpath/functions.mjs.map +0 -1
  38. package/dist/esm/fhirpath/parse.mjs +0 -145
  39. package/dist/esm/fhirpath/parse.mjs.map +0 -1
  40. package/dist/esm/fhirpath/tokenize.mjs +0 -10
  41. package/dist/esm/fhirpath/tokenize.mjs.map +0 -1
  42. package/dist/esm/fhirpath/utils.mjs +0 -377
  43. package/dist/esm/fhirpath/utils.mjs.map +0 -1
  44. package/dist/esm/filter/parse.mjs +0 -101
  45. package/dist/esm/filter/parse.mjs.map +0 -1
  46. package/dist/esm/filter/tokenize.mjs +0 -16
  47. package/dist/esm/filter/tokenize.mjs.map +0 -1
  48. package/dist/esm/filter/types.mjs +0 -34
  49. package/dist/esm/filter/types.mjs.map +0 -1
  50. package/dist/esm/format.mjs +0 -390
  51. package/dist/esm/format.mjs.map +0 -1
  52. package/dist/esm/hl7.mjs +0 -242
  53. package/dist/esm/hl7.mjs.map +0 -1
  54. package/dist/esm/index.min.mjs +0 -1
  55. package/dist/esm/jwt.mjs +0 -30
  56. package/dist/esm/jwt.mjs.map +0 -1
  57. package/dist/esm/node_modules/tslib/package.json +0 -1
  58. package/dist/esm/outcomes.mjs +0 -295
  59. package/dist/esm/outcomes.mjs.map +0 -1
  60. package/dist/esm/readablepromise.mjs +0 -82
  61. package/dist/esm/readablepromise.mjs.map +0 -1
  62. package/dist/esm/schema.mjs +0 -417
  63. package/dist/esm/schema.mjs.map +0 -1
  64. package/dist/esm/search/details.mjs +0 -162
  65. package/dist/esm/search/details.mjs.map +0 -1
  66. package/dist/esm/search/match.mjs +0 -166
  67. package/dist/esm/search/match.mjs.map +0 -1
  68. package/dist/esm/search/search.mjs +0 -378
  69. package/dist/esm/search/search.mjs.map +0 -1
  70. package/dist/esm/sftp.mjs +0 -24
  71. package/dist/esm/sftp.mjs.map +0 -1
  72. package/dist/esm/storage.mjs +0 -95
  73. package/dist/esm/storage.mjs.map +0 -1
  74. package/dist/esm/types.mjs +0 -370
  75. package/dist/esm/types.mjs.map +0 -1
  76. package/dist/esm/typeschema/types.mjs +0 -278
  77. package/dist/esm/typeschema/types.mjs.map +0 -1
  78. package/dist/esm/typeschema/validation.mjs +0 -262
  79. package/dist/esm/typeschema/validation.mjs.map +0 -1
  80. package/dist/esm/utils.mjs +0 -632
  81. package/dist/esm/utils.mjs.map +0 -1
@@ -1,278 +0,0 @@
1
- import '../types.mjs';
2
- import { capitalize, isEmpty } from '../utils.mjs';
3
- import { getTypedPropertyValue } from '../fhirpath/utils.mjs';
4
- import '../fhirpath/parse.mjs';
5
- import { OperationOutcomeError, serverError } from '../outcomes.mjs';
6
-
7
- /**
8
- * Parses a StructureDefinition resource into an internal schema better suited for
9
- * programmatic validation and usage in internal systems
10
- * @param sd The StructureDefinition resource to parse
11
- * @returns The parsed schema for the given resource type
12
- * @experimental
13
- */
14
- function parseStructureDefinition(sd) {
15
- return new StructureDefinitionParser(sd).parse();
16
- }
17
- const DATA_TYPES = Object.create(null);
18
- function loadDataTypes(bundle) {
19
- for (const { resource: sd } of bundle.entry ?? []) {
20
- if (!sd?.name) {
21
- throw new Error(`Failed loading StructureDefinition from bundle`);
22
- }
23
- if (sd.resourceType !== 'StructureDefinition') {
24
- continue;
25
- }
26
- const schema = parseStructureDefinition(sd);
27
- DATA_TYPES[sd.name] = schema;
28
- for (const inner of schema.innerTypes) {
29
- DATA_TYPES[inner.name] = inner;
30
- }
31
- }
32
- }
33
- function getDataType(type) {
34
- const schema = DATA_TYPES[type];
35
- if (!schema) {
36
- throw new OperationOutcomeError(serverError(Error('Unknown data type: ' + type)));
37
- }
38
- return schema;
39
- }
40
- /**
41
- * @experimental
42
- */
43
- class StructureDefinitionParser {
44
- /**
45
- * @param sd The StructureDefinition to parse
46
- * @throws Throws when the StructureDefinition does not have a populated `snapshot` field
47
- */
48
- constructor(sd) {
49
- if (!sd.snapshot?.element || sd.snapshot.element.length === 0) {
50
- throw new Error(`No snapshot defined for StructureDefinition '${sd.name}'`);
51
- }
52
- const root = sd.snapshot.element[0];
53
- this.elements = sd.snapshot.element.slice(1);
54
- this.elementIndex = Object.create(null);
55
- this.index = 0;
56
- this.resourceSchema = {
57
- name: sd.type,
58
- fields: {},
59
- constraints: this.parseFieldDefinition(root).constraints,
60
- innerTypes: [],
61
- };
62
- this.innerTypes = [];
63
- }
64
- parse() {
65
- let element = this.next();
66
- while (element) {
67
- if (element.sliceName) {
68
- // Start of slice: this ElementDefinition defines the top-level element of a slice value
69
- this.parseSliceStart(element);
70
- }
71
- else if (element.id?.includes(':')) {
72
- // Slice element, part of some slice definition
73
- if (this.slicingContext?.current) {
74
- const path = elementPath(element, this.slicingContext.path);
75
- this.slicingContext.current.fields[path] = this.parseFieldDefinition(element);
76
- }
77
- }
78
- else {
79
- // Normal field definition
80
- const field = this.parseFieldDefinition(element);
81
- this.checkFieldEnter(element, field);
82
- // Record field in schema
83
- if (this.backboneContext && element.path?.startsWith(this.backboneContext.path + '.')) {
84
- this.backboneContext.type.fields[elementPath(element, this.backboneContext.path)] = field;
85
- }
86
- else if (this.backboneContext?.parent && element.path?.startsWith(this.backboneContext.parent.path + '.')) {
87
- this.backboneContext.parent.type.fields[elementPath(element, this.backboneContext.parent.path)] = field;
88
- }
89
- else {
90
- this.resourceSchema.fields[elementPath(element, this.resourceSchema.name)] = field;
91
- }
92
- // Clean up contextual book-keeping
93
- this.checkFieldExit(element);
94
- }
95
- element = this.next();
96
- }
97
- // Wrap up if the StructureDefinition ends on a slice or backbone element
98
- this.checkFieldExit();
99
- if (this.innerTypes.length > 0) {
100
- this.resourceSchema.innerTypes = this.innerTypes;
101
- }
102
- return this.resourceSchema;
103
- }
104
- checkFieldEnter(element, field) {
105
- if (this.isInnerType(element)) {
106
- while (this.backboneContext && !pathsCompatible(this.backboneContext?.path, element.path)) {
107
- // Starting new inner type, unwind type stack to this property's parent
108
- this.innerTypes.push(this.backboneContext.type);
109
- this.backboneContext = this.backboneContext.parent;
110
- }
111
- this.backboneContext = {
112
- type: {
113
- name: buildTypeName(element.path?.split('.') ?? []),
114
- fields: {},
115
- constraints: this.parseFieldDefinition(element).constraints,
116
- innerTypes: [],
117
- },
118
- path: element.path ?? '',
119
- parent: pathsCompatible(this.backboneContext?.path, element.path)
120
- ? this.backboneContext
121
- : this.backboneContext?.parent,
122
- };
123
- }
124
- if (element.slicing && !this.slicingContext) {
125
- field.slicing = {
126
- discriminator: (element.slicing?.discriminator ?? []).map((d) => ({
127
- path: d.path,
128
- type: d.type,
129
- })),
130
- slices: [],
131
- ordered: element.slicing?.ordered ?? false,
132
- rule: element.slicing?.rules,
133
- };
134
- this.slicingContext = { field: field.slicing, path: element.path ?? '' };
135
- }
136
- }
137
- checkFieldExit(element = undefined) {
138
- if (this.backboneContext && !pathsCompatible(this.backboneContext.path, element?.path)) {
139
- // Leaving BackboneElement child fields
140
- if (this.backboneContext.parent) {
141
- do {
142
- this.innerTypes.push(this.backboneContext.type);
143
- this.backboneContext = this.backboneContext.parent;
144
- } while (this.backboneContext && !pathsCompatible(this.backboneContext.path, element?.path));
145
- }
146
- else {
147
- this.innerTypes.push(this.backboneContext.type);
148
- delete this.backboneContext;
149
- }
150
- }
151
- if (this.slicingContext && !pathsCompatible(this.slicingContext.path, element?.path)) {
152
- // Path must be compatible with the sliced field path (i.e. have it as a prefix) to be a part of the
153
- // same slice group; otherwise, that group is finished and this is the start of a new field
154
- if (this.slicingContext?.current) {
155
- this.slicingContext.field.slices.push(this.slicingContext.current);
156
- }
157
- delete this.slicingContext;
158
- }
159
- }
160
- next() {
161
- const element = this.peek();
162
- if (element) {
163
- this.index++;
164
- return element;
165
- }
166
- return undefined;
167
- }
168
- peek() {
169
- const element = this.elements[this.index];
170
- if (element) {
171
- this.elementIndex[element.path ?? ''] = element;
172
- if (element.contentReference) {
173
- const ref = this.elementIndex[element.contentReference.slice(element.contentReference.indexOf('#') + 1)];
174
- if (!ref) {
175
- return undefined;
176
- }
177
- return {
178
- ...ref,
179
- id: element.id,
180
- path: element.path,
181
- };
182
- }
183
- return element;
184
- }
185
- return undefined;
186
- }
187
- isInnerType(current) {
188
- const next = this.peek();
189
- return !!(pathsCompatible(current?.path, next?.path) &&
190
- current.type?.some((t) => ['BackboneElement', 'Element'].includes(t.code)));
191
- }
192
- parseSliceStart(element) {
193
- if (!this.slicingContext) {
194
- throw new Error('Invalid slice start before discriminator');
195
- }
196
- if (this.slicingContext.current) {
197
- this.slicingContext.field.slices.push(this.slicingContext.current);
198
- }
199
- this.slicingContext.current = {
200
- name: element.sliceName ?? '',
201
- fields: {},
202
- min: element.min ?? 0,
203
- max: element.max === '*' ? Number.POSITIVE_INFINITY : Number.parseInt(element.max, 10),
204
- };
205
- }
206
- parseFieldDefinition(ed) {
207
- const max = parseCardinality(ed.max);
208
- const baseMax = ed.base?.max ? parseCardinality(ed.base.max) : max;
209
- const typedElementDef = { type: 'ElementDefinition', value: ed };
210
- return {
211
- min: ed.min ?? 0,
212
- max: max,
213
- isArray: baseMax > 1,
214
- constraints: (ed.constraint ?? []).map((c) => ({
215
- key: c.key ?? '',
216
- severity: c.severity ?? 'error',
217
- expression: c.expression ?? '',
218
- description: c.human ?? '',
219
- })),
220
- type: (ed.type ?? []).map((t) => ({
221
- code: ['BackboneElement', 'Element'].includes(t.code)
222
- ? buildTypeName(ed.base?.path?.split('.') ?? [])
223
- : t.code ?? '',
224
- targetProfile: t.targetProfile ?? [],
225
- })),
226
- fixed: firstValue(getTypedPropertyValue(typedElementDef, 'fixed')),
227
- pattern: firstValue(getTypedPropertyValue(typedElementDef, 'pattern')),
228
- binding: ed.binding?.strength === 'required' ? ed.binding.valueSet : undefined,
229
- };
230
- }
231
- }
232
- function parseCardinality(c) {
233
- return c === '*' ? Number.POSITIVE_INFINITY : Number.parseInt(c, 10);
234
- }
235
- function elementPath(element, prefix = '') {
236
- return trimPrefix(element.path, prefix);
237
- }
238
- function trimPrefix(str, prefix) {
239
- if (!str) {
240
- return '';
241
- }
242
- if (prefix && str.startsWith(prefix)) {
243
- return str.substring(prefix.length + 1);
244
- }
245
- return str;
246
- }
247
- /**
248
- * Tests whether two element paths are compatible, i.e. whether the child path is nested under the parent.
249
- * @param parent The expected parent path, which should be a prefix of the child path.
250
- * @param child The child path to test for compatibility with the parent path.
251
- * @returns True if the given path is a child of the parent.
252
- */
253
- function pathsCompatible(parent, child) {
254
- if (!parent || !child) {
255
- return false;
256
- }
257
- return child.startsWith(parent + '.') || child === parent;
258
- }
259
- function buildTypeName(components) {
260
- if (components.length === 1) {
261
- return components[0];
262
- }
263
- return components.map(capitalize).join('');
264
- }
265
- function firstValue(obj) {
266
- if (Array.isArray(obj) && obj.length > 0) {
267
- return obj[0];
268
- }
269
- else if (!isEmpty(obj)) {
270
- return obj;
271
- }
272
- else {
273
- return undefined;
274
- }
275
- }
276
-
277
- export { getDataType, loadDataTypes, parseStructureDefinition };
278
- //# sourceMappingURL=types.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.mjs","sources":["../../../src/typeschema/types.ts"],"sourcesContent":["import { Bundle, ElementDefinition, ResourceType, StructureDefinition } from '@medplum/fhirtypes';\nimport { getTypedPropertyValue } from '../fhirpath';\nimport { OperationOutcomeError, serverError } from '../outcomes';\nimport { TypedValue } from '../types';\nimport { capitalize, isEmpty } from '../utils';\n\n/**\n * Internal representation of a non-primitive FHIR type, suitable for use in resource validation\n */\nexport interface InternalTypeSchema {\n name: string;\n fields: Record<string, ElementValidator>;\n constraints: Constraint[];\n innerTypes: InternalTypeSchema[];\n}\n\nexport interface ElementValidator {\n min: number;\n max: number;\n isArray: boolean;\n constraints: Constraint[];\n type: ElementType[];\n slicing?: SlicingRules;\n fixed?: TypedValue;\n pattern?: TypedValue;\n binding?: string;\n}\n\nexport interface ElementType {\n code: string;\n targetProfile: string[];\n}\n\nexport interface Constraint {\n key: string;\n severity: 'error' | 'warning';\n expression: string;\n description: string;\n}\n\nexport interface SlicingRules {\n discriminator: SliceDiscriminator[];\n ordered: boolean;\n rule?: 'open' | 'closed' | 'openAtEnd';\n slices: SliceDefinition[];\n}\n\nexport interface SliceDefinition {\n name: string;\n fields: Record<string, ElementValidator>;\n min: number;\n max: number;\n}\n\nexport interface SliceDiscriminator {\n path: string;\n type: string;\n}\n\n/**\n * Parses a StructureDefinition resource into an internal schema better suited for\n * programmatic validation and usage in internal systems\n * @param sd The StructureDefinition resource to parse\n * @returns The parsed schema for the given resource type\n * @experimental\n */\nexport function parseStructureDefinition(sd: StructureDefinition): InternalTypeSchema {\n return new StructureDefinitionParser(sd).parse();\n}\n\nconst DATA_TYPES: Record<string, InternalTypeSchema> = Object.create(null);\n\nexport function loadDataTypes(bundle: Bundle<StructureDefinition>): void {\n for (const { resource: sd } of bundle.entry ?? []) {\n if (!sd?.name) {\n throw new Error(`Failed loading StructureDefinition from bundle`);\n }\n if (sd.resourceType !== 'StructureDefinition') {\n continue;\n }\n const schema = parseStructureDefinition(sd);\n DATA_TYPES[sd.name] = schema;\n for (const inner of schema.innerTypes) {\n DATA_TYPES[inner.name] = inner;\n }\n }\n}\n\nexport function getDataType(type: string): InternalTypeSchema {\n const schema = DATA_TYPES[type];\n if (!schema) {\n throw new OperationOutcomeError(serverError(Error('Unknown data type: ' + type)));\n }\n return schema;\n}\n\ninterface BackboneContext {\n type: InternalTypeSchema;\n path: string;\n parent?: BackboneContext;\n}\n\n/**\n * @experimental\n */\nclass StructureDefinitionParser {\n private readonly elements: ElementDefinition[];\n private readonly elementIndex: Record<string, ElementDefinition>;\n private index: number;\n private readonly resourceSchema: InternalTypeSchema;\n private slicingContext: { field: SlicingRules; current?: SliceDefinition; path: string } | undefined;\n private innerTypes: InternalTypeSchema[];\n private backboneContext: BackboneContext | undefined;\n\n /**\n * @param sd The StructureDefinition to parse\n * @throws Throws when the StructureDefinition does not have a populated `snapshot` field\n */\n constructor(sd: StructureDefinition) {\n if (!sd.snapshot?.element || sd.snapshot.element.length === 0) {\n throw new Error(`No snapshot defined for StructureDefinition '${sd.name}'`);\n }\n const root = sd.snapshot.element[0];\n\n this.elements = sd.snapshot.element.slice(1);\n this.elementIndex = Object.create(null);\n this.index = 0;\n this.resourceSchema = {\n name: sd.type as ResourceType,\n fields: {},\n constraints: this.parseFieldDefinition(root).constraints,\n innerTypes: [],\n };\n this.innerTypes = [];\n }\n\n parse(): InternalTypeSchema {\n let element = this.next();\n while (element) {\n if (element.sliceName) {\n // Start of slice: this ElementDefinition defines the top-level element of a slice value\n this.parseSliceStart(element);\n } else if (element.id?.includes(':')) {\n // Slice element, part of some slice definition\n if (this.slicingContext?.current) {\n const path = elementPath(element, this.slicingContext.path);\n this.slicingContext.current.fields[path] = this.parseFieldDefinition(element);\n }\n } else {\n // Normal field definition\n const field = this.parseFieldDefinition(element);\n this.checkFieldEnter(element, field);\n\n // Record field in schema\n if (this.backboneContext && element.path?.startsWith(this.backboneContext.path + '.')) {\n this.backboneContext.type.fields[elementPath(element, this.backboneContext.path)] = field;\n } else if (this.backboneContext?.parent && element.path?.startsWith(this.backboneContext.parent.path + '.')) {\n this.backboneContext.parent.type.fields[elementPath(element, this.backboneContext.parent.path)] = field;\n } else {\n this.resourceSchema.fields[elementPath(element, this.resourceSchema.name)] = field;\n }\n\n // Clean up contextual book-keeping\n this.checkFieldExit(element);\n }\n\n element = this.next();\n }\n\n // Wrap up if the StructureDefinition ends on a slice or backbone element\n this.checkFieldExit();\n if (this.innerTypes.length > 0) {\n this.resourceSchema.innerTypes = this.innerTypes;\n }\n\n return this.resourceSchema;\n }\n\n private checkFieldEnter(element: ElementDefinition, field: ElementValidator): void {\n if (this.isInnerType(element)) {\n while (this.backboneContext && !pathsCompatible(this.backboneContext?.path, element.path)) {\n // Starting new inner type, unwind type stack to this property's parent\n this.innerTypes.push(this.backboneContext.type);\n this.backboneContext = this.backboneContext.parent;\n }\n this.backboneContext = {\n type: {\n name: buildTypeName(element.path?.split('.') ?? []) as ResourceType,\n fields: {},\n constraints: this.parseFieldDefinition(element).constraints,\n innerTypes: [],\n },\n path: element.path ?? '',\n parent: pathsCompatible(this.backboneContext?.path, element.path)\n ? this.backboneContext\n : this.backboneContext?.parent,\n };\n }\n if (element.slicing && !this.slicingContext) {\n field.slicing = {\n discriminator: (element.slicing?.discriminator ?? []).map((d) => ({\n path: d.path as string,\n type: d.type as string,\n })),\n slices: [],\n ordered: element.slicing?.ordered ?? false,\n rule: element.slicing?.rules,\n };\n this.slicingContext = { field: field.slicing, path: element.path ?? '' };\n }\n }\n\n private checkFieldExit(element: ElementDefinition | undefined = undefined): void {\n if (this.backboneContext && !pathsCompatible(this.backboneContext.path, element?.path)) {\n // Leaving BackboneElement child fields\n if (this.backboneContext.parent) {\n do {\n this.innerTypes.push(this.backboneContext.type);\n this.backboneContext = this.backboneContext.parent;\n } while (this.backboneContext && !pathsCompatible(this.backboneContext.path, element?.path));\n } else {\n this.innerTypes.push(this.backboneContext.type);\n delete this.backboneContext;\n }\n }\n if (this.slicingContext && !pathsCompatible(this.slicingContext.path, element?.path as string)) {\n // Path must be compatible with the sliced field path (i.e. have it as a prefix) to be a part of the\n // same slice group; otherwise, that group is finished and this is the start of a new field\n if (this.slicingContext?.current) {\n this.slicingContext.field.slices.push(this.slicingContext.current);\n }\n delete this.slicingContext;\n }\n }\n\n private next(): ElementDefinition | undefined {\n const element = this.peek();\n if (element) {\n this.index++;\n return element;\n }\n return undefined;\n }\n\n private peek(): ElementDefinition | undefined {\n const element = this.elements[this.index];\n if (element) {\n this.elementIndex[element.path ?? ''] = element;\n if (element.contentReference) {\n const ref = this.elementIndex[element.contentReference.slice(element.contentReference.indexOf('#') + 1)];\n if (!ref) {\n return undefined;\n }\n return {\n ...ref,\n id: element.id,\n path: element.path,\n };\n }\n return element;\n }\n return undefined;\n }\n\n private isInnerType(current: ElementDefinition): boolean {\n const next = this.peek();\n return !!(\n pathsCompatible(current?.path, next?.path) &&\n current.type?.some((t) => ['BackboneElement', 'Element'].includes(t.code as string))\n );\n }\n\n private parseSliceStart(element: ElementDefinition): void {\n if (!this.slicingContext) {\n throw new Error('Invalid slice start before discriminator');\n }\n if (this.slicingContext.current) {\n this.slicingContext.field.slices.push(this.slicingContext.current);\n }\n this.slicingContext.current = {\n name: element.sliceName ?? '',\n fields: {},\n min: element.min ?? 0,\n max: element.max === '*' ? Number.POSITIVE_INFINITY : Number.parseInt(element.max as string, 10),\n };\n }\n\n private parseFieldDefinition(ed: ElementDefinition): ElementValidator {\n const max = parseCardinality(ed.max as string);\n const baseMax = ed.base?.max ? parseCardinality(ed.base.max) : max;\n const typedElementDef = { type: 'ElementDefinition', value: ed };\n return {\n min: ed.min ?? 0,\n max: max,\n isArray: baseMax > 1,\n constraints: (ed.constraint ?? []).map((c) => ({\n key: c.key ?? '',\n severity: c.severity ?? 'error',\n expression: c.expression ?? '',\n description: c.human ?? '',\n })),\n type: (ed.type ?? []).map((t) => ({\n code: ['BackboneElement', 'Element'].includes(t.code as string)\n ? buildTypeName(ed.base?.path?.split('.') ?? [])\n : t.code ?? '',\n targetProfile: t.targetProfile ?? [],\n })),\n fixed: firstValue(getTypedPropertyValue(typedElementDef, 'fixed')),\n pattern: firstValue(getTypedPropertyValue(typedElementDef, 'pattern')),\n binding: ed.binding?.strength === 'required' ? ed.binding.valueSet : undefined,\n };\n }\n}\n\nfunction parseCardinality(c: string): number {\n return c === '*' ? Number.POSITIVE_INFINITY : Number.parseInt(c, 10);\n}\n\nfunction elementPath(element: ElementDefinition, prefix = ''): string {\n return trimPrefix(element.path, prefix);\n}\n\nfunction trimPrefix(str: string | undefined, prefix: string): string {\n if (!str) {\n return '';\n }\n if (prefix && str.startsWith(prefix)) {\n return str.substring(prefix.length + 1);\n }\n return str;\n}\n\n/**\n * Tests whether two element paths are compatible, i.e. whether the child path is nested under the parent.\n * @param parent The expected parent path, which should be a prefix of the child path.\n * @param child The child path to test for compatibility with the parent path.\n * @returns True if the given path is a child of the parent.\n */\nfunction pathsCompatible(parent: string | undefined, child: string | undefined): boolean {\n if (!parent || !child) {\n return false;\n }\n return child.startsWith(parent + '.') || child === parent;\n}\n\nfunction buildTypeName(components: string[]): string {\n if (components.length === 1) {\n return components[0];\n }\n return components.map(capitalize).join('');\n}\n\nfunction firstValue(obj: TypedValue | TypedValue[] | undefined): TypedValue | undefined {\n if (Array.isArray(obj) && obj.length > 0) {\n return obj[0];\n } else if (!isEmpty(obj)) {\n return obj as TypedValue;\n } else {\n return undefined;\n }\n}\n"],"names":[],"mappings":";;;;;;AA2DA;;;;;;AAMG;AACG,SAAU,wBAAwB,CAAC,EAAuB,EAAA;IAC9D,OAAO,IAAI,yBAAyB,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,GAAuC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAErE,SAAU,aAAa,CAAC,MAAmC,EAAA;AAC/D,IAAA,KAAK,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE;AACjD,QAAA,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE;AACb,YAAA,MAAM,IAAI,KAAK,CAAC,CAAA,8CAAA,CAAgD,CAAC,CAAC;AACnE,SAAA;AACD,QAAA,IAAI,EAAE,CAAC,YAAY,KAAK,qBAAqB,EAAE;YAC7C,SAAS;AACV,SAAA;AACD,QAAA,MAAM,MAAM,GAAG,wBAAwB,CAAC,EAAE,CAAC,CAAC;AAC5C,QAAA,UAAU,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAC7B,QAAA,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,UAAU,EAAE;AACrC,YAAA,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;AAChC,SAAA;AACF,KAAA;AACH,CAAC;AAEK,SAAU,WAAW,CAAC,IAAY,EAAA;AACtC,IAAA,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,MAAM,IAAI,qBA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CAAC;AAC5D,CAAC;AAED,SAAS,aAAa,CAAC,UAAoB,EAAA;AACzC,IAAA,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;AAC3B,QAAA,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;AACtB,KAAA;IACD,OAAO,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,UAAU,CAAC,GAA0C,EAAA;AAC5D,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;AACxC,QAAA,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;AACf,KAAA;AAAM,SAAA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;AACxB,QAAA,OAAO,GAAiB,CAAC;AAC1B,KAAA;AAAM,SAAA;AACL,QAAA,OAAO,SAAS,CAAC;AAClB,KAAA;AACH;;;;"}
@@ -1,262 +0,0 @@
1
- import { getDataType, parseStructureDefinition } from './types.mjs';
2
- import { OperationOutcomeError, validationError } from '../outcomes.mjs';
3
- import { PropertyType } from '../types.mjs';
4
- import { isEmpty, isLowerCase } from '../utils.mjs';
5
- import { getTypedPropertyValue } from '../fhirpath/utils.mjs';
6
- import '../fhirpath/parse.mjs';
7
- import { createStructureIssue } from '../schema.mjs';
8
-
9
- /*
10
- * This file provides schema validation utilities for FHIR JSON objects.
11
- *
12
- * See: [JSON Representation of Resources](https://hl7.org/fhir/json.html)
13
- * See: [FHIR Data Types](https://www.hl7.org/fhir/datatypes.html)
14
- */
15
- const fhirTypeToJsType = {
16
- base64Binary: 'string',
17
- boolean: 'boolean',
18
- canonical: 'string',
19
- code: 'string',
20
- date: 'string',
21
- dateTime: 'string',
22
- decimal: 'number',
23
- id: 'string',
24
- instant: 'string',
25
- integer: 'number',
26
- markdown: 'string',
27
- oid: 'string',
28
- positiveInt: 'number',
29
- string: 'string',
30
- time: 'string',
31
- unsignedInt: 'number',
32
- uri: 'string',
33
- url: 'string',
34
- uuid: 'string',
35
- xhtml: 'string',
36
- 'http://hl7.org/fhirpath/System.String': 'string', // Not actually a FHIR type, but included in some StructureDefinition resources
37
- };
38
- /*
39
- * This file provides schema validation utilities for FHIR JSON objects.
40
- *
41
- * See: [JSON Representation of Resources](https://hl7.org/fhir/json.html)
42
- * See: [FHIR Data Types](https://www.hl7.org/fhir/datatypes.html)
43
- */
44
- const validationRegexes = {
45
- base64Binary: /^([A-Za-z\d+/]{4})*([A-Za-z\d+/]{2}==|[A-Za-z\d+/]{3}=)?$/,
46
- canonical: /^\S*$/,
47
- code: /^[^\s]+( [^\s]+)*$/,
48
- date: /^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1]))?)?$/,
49
- dateTime: /^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1])(T([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?)?)?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00)?)?)?$/,
50
- id: /^[A-Za-z0-9\-.]{1,64}$/,
51
- instant: /^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])T([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00))$/,
52
- markdown: /^[\s\S]+$/,
53
- oid: /^urn:oid:[0-2](\.(0|[1-9]\d*))+$/,
54
- string: /^[\s\S]+$/,
55
- time: /^([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?$/,
56
- uri: /^\S*$/,
57
- url: /^\S*$/,
58
- uuid: /^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,
59
- xhtml: /.*/,
60
- };
61
- function validateResource(resource, profile) {
62
- return new ResourceValidator(resource.resourceType, profile).validate(resource);
63
- }
64
- class ResourceValidator {
65
- constructor(resourceType, profile) {
66
- this.issues = [];
67
- if (!profile) {
68
- this.schema = getDataType(resourceType);
69
- }
70
- else {
71
- this.schema = parseStructureDefinition(profile);
72
- }
73
- }
74
- validate(resource) {
75
- if (!resource) {
76
- throw new OperationOutcomeError(validationError('Resource is null'));
77
- }
78
- const resourceType = resource.resourceType;
79
- if (!resourceType) {
80
- throw new OperationOutcomeError(validationError('Missing resource type'));
81
- }
82
- this.validateObject({ type: resourceType, value: resource }, this.schema, resourceType);
83
- const issues = this.issues;
84
- this.issues = []; // Reset issues to allow re-using the validator for other resources
85
- if (issues.length > 0) {
86
- throw new OperationOutcomeError({
87
- resourceType: 'OperationOutcome',
88
- issue: issues,
89
- });
90
- }
91
- }
92
- validateObject(value, schema, path) {
93
- for (const [key, _propSchema] of Object.entries(schema.fields)) {
94
- this.checkProperty(value, key, schema, path + '.' + key);
95
- }
96
- //@TODO(mattwiller 2023-06-05): Detect extraneous properties in a single pass by keeping track of all keys that
97
- // were correctly matched to resource properties as elements are validated above
98
- this.checkAdditionalProperties(value, schema.fields, path);
99
- }
100
- checkProperty(value, key, schema, path) {
101
- const propertyValues = getNestedProperty(value, key);
102
- const element = schema.fields[key];
103
- if (!element) {
104
- throw new Error(`Missing element validation schema for ${key}`);
105
- }
106
- for (const property of propertyValues) {
107
- if (isEmpty(property)) {
108
- if (element.min > 0) {
109
- this.issues.push(createStructureIssue(path, 'Missing required property'));
110
- }
111
- return;
112
- }
113
- let values;
114
- if (element.isArray) {
115
- if (!Array.isArray(property)) {
116
- this.issues.push(createStructureIssue(path, 'Expected array of values'));
117
- return;
118
- }
119
- values = property;
120
- }
121
- else {
122
- if (Array.isArray(property)) {
123
- this.issues.push(createStructureIssue(path, 'Expected single value'));
124
- return;
125
- }
126
- values = [property];
127
- }
128
- for (const value of values) {
129
- this.checkPropertyValue(value, path);
130
- }
131
- }
132
- }
133
- checkPropertyValue(value, path) {
134
- if (isLowerCase(value.type.charAt(0))) {
135
- this.validatePrimitiveType(value, path);
136
- }
137
- else {
138
- // Recursively validate as the expected data type
139
- const type = getDataType(value.type);
140
- this.validateObject(value, type, path);
141
- }
142
- }
143
- checkAdditionalProperties(typedValue, properties, path) {
144
- const object = typedValue.value;
145
- for (const key of Object.keys(object)) {
146
- if (key === 'resourceType') {
147
- continue; // Skip special resource type discriminator property in JSON
148
- }
149
- if (!(key in properties) &&
150
- !isChoiceOfType(typedValue, key, properties) &&
151
- !this.isPrimitiveExtension(typedValue, key, path)) {
152
- this.issues.push(createStructureIssue(`${path}.${key}`, `Invalid additional property "${key}"`));
153
- }
154
- }
155
- }
156
- /**
157
- * Checks the element for a primitive extension.
158
- *
159
- * FHIR elements with primitive data types are represented in two parts:
160
- * 1) A JSON property with the name of the element, which has a JSON type of number, boolean, or string
161
- * 2) a JSON property with _ prepended to the name of the element, which, if present, contains the value's id and/or extensions
162
- *
163
- * See: https://hl7.org/fhir/json.html#primitive
164
- * @param typedValue The parent value
165
- * @param key The property key to check
166
- * @param path The path to the property
167
- * @returns Whether the element is a primitive extension
168
- */
169
- isPrimitiveExtension(typedValue, key, path) {
170
- // Primitive element starts with underscore
171
- if (!key.startsWith('_')) {
172
- return false;
173
- }
174
- // Then validate the element
175
- //@TODO(mattwiller 2023-06-05): Move this to occur along with the rest of validation
176
- this.validateObject({ type: 'Element', value: typedValue.value[key] }, getDataType('Element'), path);
177
- return true;
178
- }
179
- validatePrimitiveType(typedValue, path) {
180
- const { type, value } = typedValue;
181
- // First, make sure the value is the correct JS type
182
- const expectedType = fhirTypeToJsType[type];
183
- if (typeof value !== expectedType) {
184
- this.issues.push(createStructureIssue(path, `Invalid JSON type at ${path}: expected ${expectedType}, but got ${typeof value}`));
185
- return;
186
- }
187
- // Then, perform additional checks for specialty types
188
- if (expectedType === 'string') {
189
- this.validateString(value, type, path);
190
- }
191
- else if (expectedType === 'number') {
192
- this.validateNumber(value, type, path);
193
- }
194
- }
195
- validateString(str, type, path) {
196
- if (!str.trim()) {
197
- this.issues.push(createStructureIssue(path, 'String must contain non-whitespace content'));
198
- return;
199
- }
200
- const regex = validationRegexes[type];
201
- if (regex && !regex.exec(str)) {
202
- this.issues.push(createStructureIssue(path, 'Invalid ' + type + ' format'));
203
- }
204
- }
205
- validateNumber(n, type, path) {
206
- if (isNaN(n) || !isFinite(n)) {
207
- this.issues.push(createStructureIssue(path, 'Invalid numeric value'));
208
- }
209
- else if (isIntegerType(type) && !Number.isInteger(n)) {
210
- this.issues.push(createStructureIssue(path, 'Expected number to be an integer'));
211
- }
212
- else if (type === PropertyType.positiveInt && n <= 0) {
213
- this.issues.push(createStructureIssue(path, 'Expected number to be positive'));
214
- }
215
- else if (type === PropertyType.unsignedInt && n < 0) {
216
- this.issues.push(createStructureIssue(path, 'Expected number to be non-negative'));
217
- }
218
- }
219
- }
220
- function isIntegerType(propertyType) {
221
- return (propertyType === PropertyType.integer ||
222
- propertyType === PropertyType.positiveInt ||
223
- propertyType === PropertyType.unsignedInt);
224
- }
225
- function isChoiceOfType(typedValue, key, propertyDefinitions) {
226
- const parts = key.split(/(?=[A-Z])/g); // Split before capital letters
227
- let testProperty = '';
228
- for (const part of parts) {
229
- testProperty += part;
230
- if (!propertyDefinitions[testProperty + '[x]']) {
231
- continue;
232
- }
233
- const typedPropertyValue = getTypedPropertyValue(typedValue, testProperty);
234
- return !!typedPropertyValue;
235
- }
236
- return false;
237
- }
238
- function getNestedProperty(value, key) {
239
- const [firstProp, ...nestedProps] = key.split('.');
240
- let propertyValues = [getTypedPropertyValue(value, firstProp)];
241
- for (const prop of nestedProps) {
242
- const next = [];
243
- for (const current of propertyValues) {
244
- if (current === undefined) {
245
- continue;
246
- }
247
- else if (Array.isArray(current)) {
248
- for (const element of current) {
249
- next.push(getTypedPropertyValue(element, prop));
250
- }
251
- }
252
- else {
253
- next.push(getTypedPropertyValue(current, prop));
254
- }
255
- }
256
- propertyValues = next;
257
- }
258
- return propertyValues;
259
- }
260
-
261
- export { validateResource };
262
- //# sourceMappingURL=validation.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.mjs","sources":["../../../src/typeschema/validation.ts"],"sourcesContent":["import { OperationOutcomeIssue, Resource, StructureDefinition } from '@medplum/fhirtypes';\nimport { ElementValidator, getDataType, parseStructureDefinition, InternalTypeSchema } from './types';\nimport { OperationOutcomeError, validationError } from '../outcomes';\nimport { PropertyType, TypedValue } from '../types';\nimport { getTypedPropertyValue } from '../fhirpath';\nimport { createStructureIssue } from '../schema';\nimport { isEmpty, isLowerCase } from '../utils';\n\n/*\n * This file provides schema validation utilities for FHIR JSON objects.\n *\n * See: [JSON Representation of Resources](https://hl7.org/fhir/json.html)\n * See: [FHIR Data Types](https://www.hl7.org/fhir/datatypes.html)\n */\nconst fhirTypeToJsType: Record<string, string> = {\n base64Binary: 'string',\n boolean: 'boolean',\n canonical: 'string',\n code: 'string',\n date: 'string',\n dateTime: 'string',\n decimal: 'number',\n id: 'string',\n instant: 'string',\n integer: 'number',\n markdown: 'string',\n oid: 'string',\n positiveInt: 'number',\n string: 'string',\n time: 'string',\n unsignedInt: 'number',\n uri: 'string',\n url: 'string',\n uuid: 'string',\n xhtml: 'string',\n 'http://hl7.org/fhirpath/System.String': 'string', // Not actually a FHIR type, but included in some StructureDefinition resources\n};\n\n/*\n * This file provides schema validation utilities for FHIR JSON objects.\n *\n * See: [JSON Representation of Resources](https://hl7.org/fhir/json.html)\n * See: [FHIR Data Types](https://www.hl7.org/fhir/datatypes.html)\n */\nconst validationRegexes: Record<string, RegExp> = {\n base64Binary: /^([A-Za-z\\d+/]{4})*([A-Za-z\\d+/]{2}==|[A-Za-z\\d+/]{3}=)?$/,\n canonical: /^\\S*$/,\n code: /^[^\\s]+( [^\\s]+)*$/,\n date: /^(\\d(\\d(\\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\\d|3[0-1]))?)?$/,\n dateTime:\n /^(\\d(\\d(\\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\\d|3[0-1])(T([01]\\d|2[0-3]):[0-5]\\d:([0-5]\\d|60)(\\.\\d{1,9})?)?)?(Z|[+-]((0\\d|1[0-3]):[0-5]\\d|14:00)?)?)?$/,\n id: /^[A-Za-z0-9\\-.]{1,64}$/,\n instant:\n /^(\\d(\\d(\\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\\d|3[0-1])T([01]\\d|2[0-3]):[0-5]\\d:([0-5]\\d|60)(\\.\\d{1,9})?(Z|[+-]((0\\d|1[0-3]):[0-5]\\d|14:00))$/,\n markdown: /^[\\s\\S]+$/,\n oid: /^urn:oid:[0-2](\\.(0|[1-9]\\d*))+$/,\n string: /^[\\s\\S]+$/,\n time: /^([01]\\d|2[0-3]):[0-5]\\d:([0-5]\\d|60)(\\.\\d{1,9})?$/,\n uri: /^\\S*$/,\n url: /^\\S*$/,\n uuid: /^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,\n xhtml: /.*/,\n};\n\nexport function validateResource(resource: Resource, profile?: StructureDefinition): void {\n return new ResourceValidator(resource.resourceType, profile).validate(resource);\n}\n\nclass ResourceValidator {\n private issues: OperationOutcomeIssue[];\n private readonly schema: InternalTypeSchema;\n\n constructor(resourceType: string, profile?: StructureDefinition) {\n this.issues = [];\n if (!profile) {\n this.schema = getDataType(resourceType);\n } else {\n this.schema = parseStructureDefinition(profile);\n }\n }\n\n validate(resource: Resource): void {\n if (!resource) {\n throw new OperationOutcomeError(validationError('Resource is null'));\n }\n const resourceType = resource.resourceType;\n if (!resourceType) {\n throw new OperationOutcomeError(validationError('Missing resource type'));\n }\n\n this.validateObject({ type: resourceType, value: resource }, this.schema, resourceType);\n\n const issues = this.issues;\n this.issues = []; // Reset issues to allow re-using the validator for other resources\n if (issues.length > 0) {\n throw new OperationOutcomeError({\n resourceType: 'OperationOutcome',\n issue: issues,\n });\n }\n }\n\n private validateObject(value: TypedValue, schema: InternalTypeSchema, path: string): void {\n for (const [key, _propSchema] of Object.entries(schema.fields)) {\n this.checkProperty(value, key, schema, path + '.' + key);\n }\n\n //@TODO(mattwiller 2023-06-05): Detect extraneous properties in a single pass by keeping track of all keys that\n // were correctly matched to resource properties as elements are validated above\n this.checkAdditionalProperties(value, schema.fields, path);\n }\n\n private checkProperty(value: TypedValue, key: string, schema: InternalTypeSchema, path: string): void {\n const propertyValues = getNestedProperty(value, key);\n const element = schema.fields[key];\n if (!element) {\n throw new Error(`Missing element validation schema for ${key}`);\n }\n for (const property of propertyValues) {\n if (isEmpty(property)) {\n if (element.min > 0) {\n this.issues.push(createStructureIssue(path, 'Missing required property'));\n }\n return;\n }\n\n let values: TypedValue[];\n if (element.isArray) {\n if (!Array.isArray(property)) {\n this.issues.push(createStructureIssue(path, 'Expected array of values'));\n return;\n }\n values = property;\n } else {\n if (Array.isArray(property)) {\n this.issues.push(createStructureIssue(path, 'Expected single value'));\n return;\n }\n values = [property as TypedValue];\n }\n for (const value of values) {\n this.checkPropertyValue(value, path);\n }\n }\n }\n\n private checkPropertyValue(value: TypedValue, path: string): void {\n if (isLowerCase(value.type.charAt(0))) {\n this.validatePrimitiveType(value, path);\n } else {\n // Recursively validate as the expected data type\n const type = getDataType(value.type);\n this.validateObject(value, type, path);\n }\n }\n\n private checkAdditionalProperties(\n typedValue: TypedValue,\n properties: Record<string, ElementValidator>,\n path: string\n ): void {\n const object = typedValue.value as Record<string, unknown>;\n for (const key of Object.keys(object)) {\n if (key === 'resourceType') {\n continue; // Skip special resource type discriminator property in JSON\n }\n if (\n !(key in properties) &&\n !isChoiceOfType(typedValue, key, properties) &&\n !this.isPrimitiveExtension(typedValue, key, path)\n ) {\n this.issues.push(createStructureIssue(`${path}.${key}`, `Invalid additional property \"${key}\"`));\n }\n }\n }\n\n /**\n * Checks the element for a primitive extension.\n *\n * FHIR elements with primitive data types are represented in two parts:\n * 1) A JSON property with the name of the element, which has a JSON type of number, boolean, or string\n * 2) a JSON property with _ prepended to the name of the element, which, if present, contains the value's id and/or extensions\n *\n * See: https://hl7.org/fhir/json.html#primitive\n * @param typedValue The parent value\n * @param key The property key to check\n * @param path The path to the property\n * @returns Whether the element is a primitive extension\n */\n private isPrimitiveExtension(typedValue: TypedValue, key: string, path: string): boolean {\n // Primitive element starts with underscore\n if (!key.startsWith('_')) {\n return false;\n }\n\n // Then validate the element\n //@TODO(mattwiller 2023-06-05): Move this to occur along with the rest of validation\n this.validateObject({ type: 'Element', value: typedValue.value[key] }, getDataType('Element'), path);\n return true;\n }\n\n private validatePrimitiveType(typedValue: TypedValue, path: string): void {\n const { type, value } = typedValue;\n\n // First, make sure the value is the correct JS type\n const expectedType = fhirTypeToJsType[type];\n if (typeof value !== expectedType) {\n this.issues.push(\n createStructureIssue(path, `Invalid JSON type at ${path}: expected ${expectedType}, but got ${typeof value}`)\n );\n return;\n }\n\n // Then, perform additional checks for specialty types\n if (expectedType === 'string') {\n this.validateString(value as string, type as PropertyType, path);\n } else if (expectedType === 'number') {\n this.validateNumber(value as number, type as PropertyType, path);\n }\n }\n\n private validateString(str: string, type: PropertyType, path: string): void {\n if (!str.trim()) {\n this.issues.push(createStructureIssue(path, 'String must contain non-whitespace content'));\n return;\n }\n\n const regex = validationRegexes[type];\n if (regex && !regex.exec(str)) {\n this.issues.push(createStructureIssue(path, 'Invalid ' + type + ' format'));\n }\n }\n\n private validateNumber(n: number, type: PropertyType, path: string): void {\n if (isNaN(n) || !isFinite(n)) {\n this.issues.push(createStructureIssue(path, 'Invalid numeric value'));\n } else if (isIntegerType(type) && !Number.isInteger(n)) {\n this.issues.push(createStructureIssue(path, 'Expected number to be an integer'));\n } else if (type === PropertyType.positiveInt && n <= 0) {\n this.issues.push(createStructureIssue(path, 'Expected number to be positive'));\n } else if (type === PropertyType.unsignedInt && n < 0) {\n this.issues.push(createStructureIssue(path, 'Expected number to be non-negative'));\n }\n }\n}\n\nfunction isIntegerType(propertyType: PropertyType): boolean {\n return (\n propertyType === PropertyType.integer ||\n propertyType === PropertyType.positiveInt ||\n propertyType === PropertyType.unsignedInt\n );\n}\n\nfunction isChoiceOfType(\n typedValue: TypedValue,\n key: string,\n propertyDefinitions: Record<string, ElementValidator>\n): boolean {\n const parts = key.split(/(?=[A-Z])/g); // Split before capital letters\n let testProperty = '';\n for (const part of parts) {\n testProperty += part;\n if (!propertyDefinitions[testProperty + '[x]']) {\n continue;\n }\n const typedPropertyValue = getTypedPropertyValue(typedValue, testProperty);\n return !!typedPropertyValue;\n }\n return false;\n}\n\nfunction getNestedProperty(value: TypedValue, key: string): (TypedValue | TypedValue[] | undefined)[] {\n const [firstProp, ...nestedProps] = key.split('.');\n let propertyValues = [getTypedPropertyValue(value, firstProp)];\n for (const prop of nestedProps) {\n const next = [];\n for (const current of propertyValues) {\n if (current === undefined) {\n continue;\n } else if (Array.isArray(current)) {\n for (const element of current) {\n next.push(getTypedPropertyValue(element, prop));\n }\n } else {\n next.push(getTypedPropertyValue(current, prop));\n }\n }\n propertyValues = next;\n }\n return propertyValues;\n}\n"],"names":[],"mappings":";;;;;;;;AAQA;;;;;AAKG;AACH,MAAM,gBAAgB,GAA2B;AAC/C,IAAA,YAAY,EAAE,QAAQ;AACtB,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,SAAS,EAAE,QAAQ;AACnB,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,QAAQ,EAAE,QAAQ;AAClB,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,EAAE,EAAE,QAAQ;AACZ,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,OAAO,EAAE,QAAQ;AACjB,I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