@medplum/core 2.1.3 → 2.1.5

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.
@@ -1,5 +1,6 @@
1
- import { Bundle, ElementDefinition, Reference, Resource, ResourceType, SearchParameter, StructureDefinition } from '@medplum/fhirtypes';
1
+ import { Bundle, ElementDefinition, Reference, Resource, ResourceType, SearchParameter } from '@medplum/fhirtypes';
2
2
  import { SearchParameterDetails } from './search/details';
3
+ import { InternalSchemaElement, InternalTypeSchema } from './typeschema/types';
3
4
  export interface TypedValue {
4
5
  readonly type: string;
5
6
  readonly value: any;
@@ -9,67 +10,67 @@ export interface TypedValue {
9
10
  * http://www.hl7.org/fhir/valueset-defined-types.html
10
11
  * The list here includes additions found from StructureDefinition resources.
11
12
  */
12
- export declare enum PropertyType {
13
- Address = "Address",
14
- Age = "Age",
15
- Annotation = "Annotation",
16
- Attachment = "Attachment",
17
- BackboneElement = "BackboneElement",
18
- CodeableConcept = "CodeableConcept",
19
- Coding = "Coding",
20
- ContactDetail = "ContactDetail",
21
- ContactPoint = "ContactPoint",
22
- Contributor = "Contributor",
23
- Count = "Count",
24
- DataRequirement = "DataRequirement",
25
- Distance = "Distance",
26
- Dosage = "Dosage",
27
- Duration = "Duration",
28
- Expression = "Expression",
29
- Extension = "Extension",
30
- HumanName = "HumanName",
31
- Identifier = "Identifier",
32
- MarketingStatus = "MarketingStatus",
33
- Meta = "Meta",
34
- Money = "Money",
35
- Narrative = "Narrative",
36
- ParameterDefinition = "ParameterDefinition",
37
- Period = "Period",
38
- Population = "Population",
39
- ProdCharacteristic = "ProdCharacteristic",
40
- ProductShelfLife = "ProductShelfLife",
41
- Quantity = "Quantity",
42
- Range = "Range",
43
- Ratio = "Ratio",
44
- Reference = "Reference",
45
- RelatedArtifact = "RelatedArtifact",
46
- SampledData = "SampledData",
47
- Signature = "Signature",
48
- SubstanceAmount = "SubstanceAmount",
49
- SystemString = "http://hl7.org/fhirpath/System.String",
50
- Timing = "Timing",
51
- TriggerDefinition = "TriggerDefinition",
52
- UsageContext = "UsageContext",
53
- base64Binary = "base64Binary",
54
- boolean = "boolean",
55
- canonical = "canonical",
56
- code = "code",
57
- date = "date",
58
- dateTime = "dateTime",
59
- decimal = "decimal",
60
- id = "id",
61
- instant = "instant",
62
- integer = "integer",
63
- markdown = "markdown",
64
- oid = "oid",
65
- positiveInt = "positiveInt",
66
- string = "string",
67
- time = "time",
68
- unsignedInt = "unsignedInt",
69
- uri = "uri",
70
- url = "url",
71
- uuid = "uuid"
72
- }
13
+ export declare const PropertyType: {
14
+ Address: string;
15
+ Age: string;
16
+ Annotation: string;
17
+ Attachment: string;
18
+ BackboneElement: string;
19
+ CodeableConcept: string;
20
+ Coding: string;
21
+ ContactDetail: string;
22
+ ContactPoint: string;
23
+ Contributor: string;
24
+ Count: string;
25
+ DataRequirement: string;
26
+ Distance: string;
27
+ Dosage: string;
28
+ Duration: string;
29
+ Expression: string;
30
+ Extension: string;
31
+ HumanName: string;
32
+ Identifier: string;
33
+ MarketingStatus: string;
34
+ Meta: string;
35
+ Money: string;
36
+ Narrative: string;
37
+ ParameterDefinition: string;
38
+ Period: string;
39
+ Population: string;
40
+ ProdCharacteristic: string;
41
+ ProductShelfLife: string;
42
+ Quantity: string;
43
+ Range: string;
44
+ Ratio: string;
45
+ Reference: string;
46
+ RelatedArtifact: string;
47
+ SampledData: string;
48
+ Signature: string;
49
+ SubstanceAmount: string;
50
+ SystemString: string;
51
+ Timing: string;
52
+ TriggerDefinition: string;
53
+ UsageContext: string;
54
+ base64Binary: string;
55
+ boolean: string;
56
+ canonical: string;
57
+ code: string;
58
+ date: string;
59
+ dateTime: string;
60
+ decimal: string;
61
+ id: string;
62
+ instant: string;
63
+ integer: string;
64
+ markdown: string;
65
+ oid: string;
66
+ positiveInt: string;
67
+ string: string;
68
+ time: string;
69
+ unsignedInt: string;
70
+ uri: string;
71
+ url: string;
72
+ uuid: string;
73
+ };
73
74
  /**
74
75
  * An IndexedStructureDefinition is a lookup-optimized version of a StructureDefinition.
75
76
  *
@@ -96,7 +97,7 @@ export declare enum PropertyType {
96
97
  */
97
98
  export interface IndexedStructureDefinition {
98
99
  types: {
99
- [resourceType: string]: TypeSchema;
100
+ [resourceType: string]: TypeInfo;
100
101
  };
101
102
  }
102
103
  /**
@@ -108,34 +109,14 @@ export interface IndexedStructureDefinition {
108
109
  * 3) Patient_Communication
109
110
  * 4) Patient_Link
110
111
  */
111
- export interface TypeSchema {
112
- structureDefinition: StructureDefinition;
113
- elementDefinition: ElementDefinition;
114
- display: string;
115
- properties: {
116
- [name: string]: ElementDefinition;
117
- };
112
+ export interface TypeInfo {
118
113
  searchParams?: {
119
114
  [code: string]: SearchParameter;
120
115
  };
121
116
  searchParamsDetails?: {
122
117
  [code: string]: SearchParameterDetails;
123
118
  };
124
- description?: string;
125
- parentType?: string;
126
119
  }
127
- /**
128
- * Indexes a bundle of StructureDefinitions for faster lookup.
129
- * @param bundle A FHIR bundle StructureDefinition resources.
130
- * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
131
- */
132
- export declare function indexStructureDefinitionBundle(bundle: Bundle): void;
133
- /**
134
- * Indexes a StructureDefinition for fast lookup.
135
- * @param structureDefinition The original StructureDefinition.
136
- * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
137
- */
138
- export declare function indexStructureDefinition(structureDefinition: StructureDefinition): void;
139
120
  /**
140
121
  * Indexes a bundle of SearchParameter resources for faster lookup.
141
122
  * @param bundle A FHIR bundle SearchParameter resources.
@@ -161,25 +142,26 @@ export declare function buildTypeName(components: string[]): string;
161
142
  * @param typeSchema The type schema to check.
162
143
  * @returns True if the type schema is a non-abstract FHIR resource.
163
144
  */
164
- export declare function isResourceTypeSchema(typeSchema: TypeSchema): boolean;
145
+ export declare function isResourceTypeSchema(typeSchema: InternalTypeSchema): boolean;
165
146
  /**
166
147
  * Returns an array of all resource types.
167
148
  * Note that this is based on globalSchema, and will only return resource types that are currently in memory.
168
149
  * @returns An array of all resource types.
169
150
  */
170
151
  export declare function getResourceTypes(): ResourceType[];
171
- /**
172
- * Returns the type schema for the resource type.
173
- * @param resourceType The resource type.
174
- * @returns The type schema for the resource type.
175
- */
176
- export declare function getResourceTypeSchema(resourceType: string): TypeSchema;
177
152
  /**
178
153
  * Returns the search parameters for the resource type indexed by search code.
179
154
  * @param resourceType The resource type.
180
155
  * @returns The search parameters for the resource type indexed by search code.
181
156
  */
182
157
  export declare function getSearchParameters(resourceType: string): Record<string, SearchParameter> | undefined;
158
+ /**
159
+ * Returns a search parameter for a resource type by search code.
160
+ * @param resourceType The FHIR resource type.
161
+ * @param code The search parameter code.
162
+ * @returns The search parameter if found, otherwise undefined.
163
+ */
164
+ export declare function getSearchParameter(resourceType: string, code: string): SearchParameter | undefined;
183
165
  /**
184
166
  * Returns a human friendly display name for a FHIR element definition path.
185
167
  * @param path The FHIR element definition path.
@@ -193,7 +175,7 @@ export declare function getPropertyDisplayName(path: string): string;
193
175
  * @param propertyName The property name.
194
176
  * @returns The element definition if found.
195
177
  */
196
- export declare function getElementDefinition(typeName: string, propertyName: string): ElementDefinition | undefined;
178
+ export declare function getElementDefinition(typeName: string, propertyName: string): InternalSchemaElement | undefined;
197
179
  /**
198
180
  * Typeguard to validate that an object is a FHIR resource
199
181
  * @param value The object to check
@@ -212,3 +194,9 @@ export declare function isReference(value: unknown): value is Reference & {
212
194
  * Global schema singleton.
213
195
  */
214
196
  export declare const globalSchema: IndexedStructureDefinition;
197
+ /**
198
+ * Output the string representation of a value, suitable for use as part of a search query.
199
+ * @param v The value to format as a string
200
+ * @returns The stringified value
201
+ */
202
+ export declare function stringifyTypedValue(v: TypedValue): string;
@@ -1,30 +1,36 @@
1
- import { Bundle, Resource, StructureDefinition } from '@medplum/fhirtypes';
1
+ import { Bundle, ElementDefinitionBinding, Resource, StructureDefinition } from '@medplum/fhirtypes';
2
2
  import { TypedValue } from '../types';
3
3
  /**
4
4
  * Internal representation of a non-primitive FHIR type, suitable for use in resource validation
5
5
  */
6
6
  export interface InternalTypeSchema {
7
7
  name: string;
8
- fields: Record<string, ElementValidator>;
9
- constraints: Constraint[];
8
+ url?: string;
9
+ kind?: string;
10
+ description?: string;
11
+ elements: Record<string, InternalSchemaElement>;
12
+ constraints?: Constraint[];
13
+ parentType?: InternalTypeSchema;
10
14
  innerTypes: InternalTypeSchema[];
11
15
  summaryProperties?: Set<string>;
12
16
  mandatoryProperties?: Set<string>;
13
17
  }
14
- export interface ElementValidator {
18
+ export interface InternalSchemaElement {
19
+ description: string;
20
+ path: string;
15
21
  min: number;
16
22
  max: number;
17
- isArray: boolean;
18
- constraints: Constraint[];
23
+ isArray?: boolean;
24
+ constraints?: Constraint[];
19
25
  type: ElementType[];
20
26
  slicing?: SlicingRules;
21
27
  fixed?: TypedValue;
22
28
  pattern?: TypedValue;
23
- binding?: string;
29
+ binding?: ElementDefinitionBinding;
24
30
  }
25
31
  export interface ElementType {
26
32
  code: string;
27
- targetProfile: string[];
33
+ targetProfile?: string[];
28
34
  }
29
35
  export interface Constraint {
30
36
  key: string;
@@ -41,7 +47,7 @@ export interface SlicingRules {
41
47
  export interface SliceDefinition {
42
48
  name: string;
43
49
  type?: ElementType[];
44
- fields: Record<string, ElementValidator>;
50
+ elements: Record<string, InternalSchemaElement>;
45
51
  min: number;
46
52
  max: number;
47
53
  }
@@ -57,8 +63,24 @@ export interface SliceDiscriminator {
57
63
  * @experimental
58
64
  */
59
65
  export declare function parseStructureDefinition(sd: StructureDefinition): InternalTypeSchema;
60
- export declare function loadDataTypes(bundle: Bundle<StructureDefinition>): void;
66
+ export declare function indexStructureDefinitionBundle(bundle: StructureDefinition[] | Bundle): void;
67
+ export declare function loadDataType(sd: StructureDefinition): void;
68
+ export declare function getAllDataTypes(): Record<string, InternalTypeSchema>;
69
+ export declare function isDataTypeLoaded(type: string): boolean;
70
+ export declare function tryGetDataType(type: string): InternalTypeSchema | undefined;
61
71
  export declare function getDataType(type: string): InternalTypeSchema;
72
+ /**
73
+ * Returns true if the given string is a valid FHIR resource type.
74
+ *
75
+ * ```ts
76
+ * isResourceType('Patient'); // true
77
+ * isResourceType('XYZ'); // false
78
+ * ```
79
+ *
80
+ * @param resourceType The candidate resource type string.
81
+ * @returns True if the resource type is a valid FHIR resource type.
82
+ */
83
+ export declare function isResourceType(resourceType: string): boolean;
62
84
  /**
63
85
  * Construct the subset of a resource containing a minimum set of fields. The returned resource is not guaranteed
64
86
  * to contain only the provided properties, and may contain others (e.g. `resourceType` and `id`)
@@ -1,4 +1,4 @@
1
- import { CodeableConcept, Extension, ObservationDefinition, ObservationDefinitionQualifiedInterval, Patient, Practitioner, QuestionnaireResponse, QuestionnaireResponseItemAnswer, Range, Reference, RelatedPerson, Resource, ResourceType } from '@medplum/fhirtypes';
1
+ import { CodeableConcept, Extension, Identifier, ObservationDefinition, ObservationDefinitionQualifiedInterval, Patient, Practitioner, QuestionnaireResponse, QuestionnaireResponseItemAnswer, Range, Reference, RelatedPerson, Resource, ResourceType } from '@medplum/fhirtypes';
2
2
  /**
3
3
  * @internal
4
4
  */
@@ -110,6 +110,24 @@ export declare function getAllQuestionnaireAnswers(response: QuestionnaireRespon
110
110
  * @returns The identifier value if found; otherwise undefined.
111
111
  */
112
112
  export declare function getIdentifier(resource: Resource, system: string): string | undefined;
113
+ /**
114
+ * Sets a resource identifier for the given system.
115
+ *
116
+ * Note that this method is only available on resources that have an "identifier" property,
117
+ * and that property must be an array of Identifier objects,
118
+ * which is not true for all FHIR resources.
119
+ *
120
+ * If the identifier already exists, then the value is updated.
121
+ *
122
+ * Otherwise a new identifier is added.
123
+ *
124
+ * @param resource The resource to add the identifier to.
125
+ * @param system The identifier system.
126
+ * @param value The identifier value.
127
+ */
128
+ export declare function setIdentifier(resource: Resource & {
129
+ identifier?: Identifier[];
130
+ }, system: string, value: string): void;
113
131
  /**
114
132
  * Returns an extension value by extension URLs.
115
133
  * @param resource The base resource.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/core",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "Medplum TS/JS Library",
5
5
  "author": "Medplum <hello@medplum.com>",
6
6
  "license": "Apache-2.0",
@@ -20,7 +20,8 @@
20
20
  },
21
21
  "devDependencies": {
22
22
  "@medplum/definitions": "*",
23
- "@medplum/fhirtypes": "*"
23
+ "@medplum/fhirtypes": "*",
24
+ "jest-websocket-mock": "2.5.0"
24
25
  },
25
26
  "peerDependencies": {
26
27
  "pdfmake": "^0.2.5"
@@ -1,2 +0,0 @@
1
- export * from './parse';
2
- export * from './tokenize';
@@ -1 +0,0 @@
1
- export * from './parse';
@@ -1,4 +0,0 @@
1
- export * from './atoms';
2
- export * from './parse';
3
- export * from './tokenize';
4
- export * from './utils';
@@ -1,2 +0,0 @@
1
- export * from './parse';
2
- export * from './types';