@medplum/core 2.0.5 → 2.0.7

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 (48) hide show
  1. package/dist/cjs/index.cjs +872 -27
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.min.cjs +1 -1
  4. package/dist/esm/client.mjs +7 -6
  5. package/dist/esm/client.mjs.map +1 -1
  6. package/dist/esm/fhirlexer/tokenize.mjs +13 -4
  7. package/dist/esm/fhirlexer/tokenize.mjs.map +1 -1
  8. package/dist/esm/fhirmapper/parse.mjs +317 -0
  9. package/dist/esm/fhirmapper/parse.mjs.map +1 -0
  10. package/dist/esm/fhirmapper/tokenize.mjs +15 -0
  11. package/dist/esm/fhirmapper/tokenize.mjs.map +1 -0
  12. package/dist/esm/fhirpath/atoms.mjs +2 -2
  13. package/dist/esm/fhirpath/atoms.mjs.map +1 -1
  14. package/dist/esm/fhirpath/functions.mjs +2 -2
  15. package/dist/esm/fhirpath/functions.mjs.map +1 -1
  16. package/dist/esm/fhirpath/utils.mjs +4 -4
  17. package/dist/esm/fhirpath/utils.mjs.map +1 -1
  18. package/dist/esm/filter/parse.mjs +51 -0
  19. package/dist/esm/filter/parse.mjs.map +1 -0
  20. package/dist/esm/filter/tokenize.mjs +18 -0
  21. package/dist/esm/filter/tokenize.mjs.map +1 -0
  22. package/dist/esm/filter/types.mjs +34 -0
  23. package/dist/esm/filter/types.mjs.map +1 -0
  24. package/dist/esm/index.min.mjs +1 -1
  25. package/dist/esm/index.mjs +8 -2
  26. package/dist/esm/index.mjs.map +1 -1
  27. package/dist/esm/node_modules/tslib/tslib.es6.mjs.map +1 -1
  28. package/dist/esm/outcomes.mjs +15 -1
  29. package/dist/esm/outcomes.mjs.map +1 -1
  30. package/dist/esm/schema.mjs +397 -0
  31. package/dist/esm/schema.mjs.map +1 -0
  32. package/dist/esm/search/details.mjs +1 -1
  33. package/dist/esm/search/details.mjs.map +1 -1
  34. package/dist/esm/types.mjs +34 -8
  35. package/dist/esm/types.mjs.map +1 -1
  36. package/dist/types/client.d.ts +20 -8
  37. package/dist/types/fhirlexer/tokenize.d.ts +5 -1
  38. package/dist/types/fhirmapper/index.d.ts +1 -0
  39. package/dist/types/filter/index.d.ts +2 -0
  40. package/dist/types/filter/parse.d.ts +7 -0
  41. package/dist/types/filter/tokenize.d.ts +2 -0
  42. package/dist/types/filter/types.d.ts +31 -0
  43. package/dist/types/index.d.ts +4 -0
  44. package/dist/types/outcomes.d.ts +1 -0
  45. package/dist/types/schema.d.ts +120 -0
  46. package/dist/types/types.d.ts +19 -5
  47. package/package.json +1 -1
  48. package/tsconfig.build.json +0 -9
@@ -0,0 +1,120 @@
1
+ import { OperationOutcomeIssue, Resource } from '@medplum/fhirtypes';
2
+ /**
3
+ * Returns true if the given string is a valid FHIR resource type.
4
+ *
5
+ * ```ts
6
+ * isResourceType('Patient'); // true
7
+ * isResourceType('XYZ'); // false
8
+ * ```
9
+ *
10
+ * Note that this depends on globalSchema, which is populated by the StructureDefinition loader.
11
+ *
12
+ * In a server context, you can load all schema definitions:
13
+ *
14
+ * ```ts
15
+ * import { indexStructureDefinitionBundle } from '@medplum/core';
16
+ * import { readJson } from '@medplum/definitions';
17
+ * import { Bundle } from '@medplum/fhirtypes';
18
+ *
19
+ * indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);
20
+ * ```
21
+ *
22
+ * In a client context, you can load the schema definitions using MedplumClient:
23
+ *
24
+ * ```ts
25
+ * import { MedplumClient } from '@medplum/core';
26
+ *
27
+ * const medplum = new MedplumClient();
28
+ * await medplum.requestSchema('Patient');
29
+ * ```
30
+ *
31
+ * @param resourceType The candidate resource type string.
32
+ * @returns True if the resource type is a valid FHIR resource type.
33
+ */
34
+ export declare function isResourceType(resourceType: string): boolean;
35
+ /**
36
+ * Validates that the given string is a valid FHIR resource type.
37
+ * On success, silently returns void.
38
+ * On failure, throws an OperationOutcomeError.
39
+ *
40
+ * ```ts
41
+ * validateResourceType('Patient'); // nothing
42
+ * validateResourceType('XYZ'); // throws OperationOutcomeError
43
+ * ```
44
+ *
45
+ * Note that this depends on globalSchema, which is populated by the StructureDefinition loader.
46
+ *
47
+ * In a server context, you can load all schema definitions:
48
+ *
49
+ * ```ts
50
+ * import { indexStructureDefinitionBundle } from '@medplum/core';
51
+ * import { readJson } from '@medplum/definitions';
52
+ * import { Bundle } from '@medplum/fhirtypes';
53
+ *
54
+ * indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);
55
+ * ```
56
+ *
57
+ * In a client context, you can load the schema definitions using MedplumClient:
58
+ *
59
+ * ```ts
60
+ * import { MedplumClient } from '@medplum/core';
61
+ *
62
+ * const medplum = new MedplumClient();
63
+ * await medplum.requestSchema('Patient');
64
+ * ```
65
+ *
66
+ * @param resourceType The candidate resource type string.
67
+ * @returns True if the resource type is a valid FHIR resource type.
68
+ */
69
+ export declare function validateResourceType(resourceType: string): void;
70
+ /**
71
+ * Validates a candidate FHIR resource object.
72
+ * On success, silently returns void.
73
+ * On failure, throws an OperationOutcomeError with issues for each violation.
74
+ *
75
+ * ```ts
76
+ * validateResource({ resourceType: 'Patient' }); // nothing
77
+ * validateResource({ resourceType: 'XYZ' }); // throws OperationOutcomeError
78
+ * ```
79
+ *
80
+ * Note that this depends on globalSchema, which is populated by the StructureDefinition loader.
81
+ *
82
+ * In a server context, you can load all schema definitions:
83
+ *
84
+ * ```ts
85
+ * import { indexStructureDefinitionBundle } from '@medplum/core';
86
+ * import { readJson } from '@medplum/definitions';
87
+ * import { Bundle } from '@medplum/fhirtypes';
88
+ *
89
+ * indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);
90
+ * ```
91
+ *
92
+ * In a client context, you can load the schema definitions using MedplumClient:
93
+ *
94
+ * ```ts
95
+ * import { MedplumClient } from '@medplum/core';
96
+ *
97
+ * const medplum = new MedplumClient();
98
+ * await medplum.requestSchema('Patient');
99
+ * ```
100
+ *
101
+ * @param resourceType The candidate resource type string.
102
+ * @returns True if the resource type is a valid FHIR resource type.
103
+ */
104
+ export declare function validateResource<T extends Resource>(resource: T): void;
105
+ export declare class FhirSchemaValidator<T extends Resource> {
106
+ #private;
107
+ constructor(root: T);
108
+ validate(): void;
109
+ }
110
+ /**
111
+ * Recursively checks for null values in an object.
112
+ *
113
+ * Note that "null" is a special value in JSON that is not allowed in FHIR.
114
+ *
115
+ * @param value Input value of any type.
116
+ * @param path Path string to the value for OperationOutcome.
117
+ * @param issues Output list of issues.
118
+ */
119
+ export declare function checkForNull(value: unknown, path: string, issues: OperationOutcomeIssue[]): void;
120
+ export declare function createStructureIssue(expression: string, details: string): OperationOutcomeIssue;
@@ -1,4 +1,4 @@
1
- import { Bundle, ElementDefinition, SearchParameter, StructureDefinition } from '@medplum/fhirtypes';
1
+ import { Bundle, ElementDefinition, Reference, Resource, ResourceType, SearchParameter, StructureDefinition } from '@medplum/fhirtypes';
2
2
  import { SearchParameterDetails } from './search/details';
3
3
  export interface TypedValue {
4
4
  readonly type: string;
@@ -157,17 +157,17 @@ export declare function indexSearchParameter(searchParam: SearchParameter): void
157
157
  export declare function getElementDefinitionTypeName(elementDefinition: ElementDefinition): string;
158
158
  export declare function buildTypeName(components: string[]): string;
159
159
  /**
160
- * Returns true if the type schema is a DomainResource.
160
+ * Returns true if the type schema is a non-abstract FHIR resource.
161
161
  * @param typeSchema The type schema to check.
162
- * @returns True if the type schema is a DomainResource.
162
+ * @returns True if the type schema is a non-abstract FHIR resource.
163
163
  */
164
- export declare function isResourceType(typeSchema: TypeSchema): boolean;
164
+ export declare function isResourceTypeSchema(typeSchema: TypeSchema): boolean;
165
165
  /**
166
166
  * Returns an array of all resource types.
167
167
  * Note that this is based on globalSchema, and will only return resource types that are currently in memory.
168
168
  * @returns An array of all resource types.
169
169
  */
170
- export declare function getResourceTypes(): string[];
170
+ export declare function getResourceTypes(): ResourceType[];
171
171
  /**
172
172
  * Returns the type schema for the resource type.
173
173
  * @param resourceType The resource type.
@@ -194,6 +194,20 @@ export declare function getPropertyDisplayName(path: string): string;
194
194
  * @returns The element definition if found.
195
195
  */
196
196
  export declare function getElementDefinition(typeName: string, propertyName: string): ElementDefinition | undefined;
197
+ /**
198
+ * Typeguard to validate that an object is a FHIR resource
199
+ * @param value The object to check
200
+ * @returns True if the input is of type 'object' and contains property 'resourceType'
201
+ */
202
+ export declare function isResource<T extends Resource = Resource>(value: T | Reference<T> | string | undefined | null): value is T;
203
+ /**
204
+ * Typeguard to validate that an object is a FHIR resource
205
+ * @param value The object to check
206
+ * @returns True if the input is of type 'object' and contains property 'reference'
207
+ */
208
+ export declare function isReference<T extends Resource>(value: T | Reference<T> | string | undefined | null): value is Reference<T> & {
209
+ reference: string;
210
+ };
197
211
  /**
198
212
  * Global schema singleton.
199
213
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/core",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "Medplum TS/JS Library",
5
5
  "author": "Medplum <hello@medplum.com>",
6
6
  "license": "Apache-2.0",
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "dist/types",
5
- "noEmit": false,
6
- "emitDeclarationOnly": true
7
- },
8
- "exclude": ["**/*.test.ts"]
9
- }