@medplum/core 0.9.1 → 0.9.4
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/README.md +158 -29
- package/dist/cjs/index.js +254 -262
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -1
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/esm/index.js +251 -262
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/types/cache.d.ts +1 -0
- package/dist/types/client.d.ts +76 -7
- package/dist/types/index.d.ts +2 -1
- package/dist/types/readablepromise.d.ts +43 -0
- package/dist/types/search.d.ts +2 -1
- package/dist/types/utils.d.ts +8 -3
- package/package.json +2 -2
- package/dist/types/repo.d.ts +0 -116
package/dist/types/cache.d.ts
CHANGED
package/dist/types/client.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Binary, Bundle, Project, ProjectMembership, Reference, Resource, UserConfiguration, ValueSet } from '@medplum/fhirtypes';
|
|
2
2
|
import type { Operation } from 'fast-json-patch';
|
|
3
3
|
import { EventTarget } from './eventtarget';
|
|
4
|
+
import { Hl7Message } from './hl7';
|
|
5
|
+
import { ReadablePromise } from './readablepromise';
|
|
4
6
|
import { SearchRequest } from './search';
|
|
5
7
|
import { IndexedStructureDefinition } from './types';
|
|
6
8
|
import { ProfileResource } from './utils';
|
|
@@ -98,6 +100,10 @@ export interface TokenResponse {
|
|
|
98
100
|
readonly project: Reference<Project>;
|
|
99
101
|
readonly profile: Reference<ProfileResource>;
|
|
100
102
|
}
|
|
103
|
+
export interface BotEvent {
|
|
104
|
+
readonly contentType: string;
|
|
105
|
+
readonly input: Resource | Hl7Message | string;
|
|
106
|
+
}
|
|
101
107
|
/**
|
|
102
108
|
* The MedplumClient class provides a client for the Medplum FHIR server.
|
|
103
109
|
*
|
|
@@ -164,7 +170,7 @@ export declare class MedplumClient extends EventTarget {
|
|
|
164
170
|
* @param options Optional fetch options.
|
|
165
171
|
* @returns Promise to the response content.
|
|
166
172
|
*/
|
|
167
|
-
get(url: string, options?: RequestInit):
|
|
173
|
+
get<T = any>(url: string, options?: RequestInit): ReadablePromise<T>;
|
|
168
174
|
/**
|
|
169
175
|
* Makes an HTTP POST request to the specified URL.
|
|
170
176
|
*
|
|
@@ -396,7 +402,7 @@ export declare class MedplumClient extends EventTarget {
|
|
|
396
402
|
* @param id The resource ID.
|
|
397
403
|
* @returns The resource if available; undefined otherwise.
|
|
398
404
|
*/
|
|
399
|
-
readResource<T extends Resource>(resourceType: string, id: string):
|
|
405
|
+
readResource<T extends Resource>(resourceType: string, id: string): ReadablePromise<T>;
|
|
400
406
|
/**
|
|
401
407
|
* Reads a resource by resource type and ID using the in-memory resource cache.
|
|
402
408
|
*
|
|
@@ -415,7 +421,7 @@ export declare class MedplumClient extends EventTarget {
|
|
|
415
421
|
* @param id The resource ID.
|
|
416
422
|
* @returns The resource if available; undefined otherwise.
|
|
417
423
|
*/
|
|
418
|
-
readCached<T extends Resource>(resourceType: string, id: string):
|
|
424
|
+
readCached<T extends Resource>(resourceType: string, id: string): ReadablePromise<T>;
|
|
419
425
|
/**
|
|
420
426
|
* Reads a resource by `Reference`.
|
|
421
427
|
*
|
|
@@ -434,7 +440,7 @@ export declare class MedplumClient extends EventTarget {
|
|
|
434
440
|
* @param reference The FHIR reference object.
|
|
435
441
|
* @returns The resource if available; undefined otherwise.
|
|
436
442
|
*/
|
|
437
|
-
readReference<T extends Resource>(reference: Reference<T>):
|
|
443
|
+
readReference<T extends Resource>(reference: Reference<T>): ReadablePromise<T>;
|
|
438
444
|
/**
|
|
439
445
|
* Reads a resource by `Reference` using the in-memory resource cache.
|
|
440
446
|
*
|
|
@@ -455,7 +461,7 @@ export declare class MedplumClient extends EventTarget {
|
|
|
455
461
|
* @param reference The FHIR reference object.
|
|
456
462
|
* @returns The resource if available; undefined otherwise.
|
|
457
463
|
*/
|
|
458
|
-
readCachedReference<T extends Resource>(reference: Reference<T>):
|
|
464
|
+
readCachedReference<T extends Resource>(reference: Reference<T>): ReadablePromise<T>;
|
|
459
465
|
/**
|
|
460
466
|
* Returns a cached schema for a resource type.
|
|
461
467
|
* If the schema is not cached, returns undefined.
|
|
@@ -532,6 +538,45 @@ export declare class MedplumClient extends EventTarget {
|
|
|
532
538
|
* @returns The result of the create operation.
|
|
533
539
|
*/
|
|
534
540
|
createResource<T extends Resource>(resource: T): Promise<T>;
|
|
541
|
+
/**
|
|
542
|
+
* Conditionally create a new FHIR resource only if some equivalent resource does not already exist on the server.
|
|
543
|
+
*
|
|
544
|
+
* The return value is the existing resource or the newly created resource, including the ID and meta.
|
|
545
|
+
*
|
|
546
|
+
* Example:
|
|
547
|
+
*
|
|
548
|
+
* ```typescript
|
|
549
|
+
* const result = await medplum.createResourceIfNoneExist(
|
|
550
|
+
* 'Patient?identifier=123',
|
|
551
|
+
* {
|
|
552
|
+
* resourceType: 'Patient',
|
|
553
|
+
* identifier: [{
|
|
554
|
+
* system: 'http://example.com/mrn',
|
|
555
|
+
* value: '123'
|
|
556
|
+
* }]
|
|
557
|
+
* name: [{
|
|
558
|
+
* family: 'Smith',
|
|
559
|
+
* given: ['John']
|
|
560
|
+
* }]
|
|
561
|
+
* });
|
|
562
|
+
* console.log(result.id);
|
|
563
|
+
* ```
|
|
564
|
+
*
|
|
565
|
+
* This method is syntactic sugar for:
|
|
566
|
+
*
|
|
567
|
+
* ```typescript
|
|
568
|
+
* return searchOne(query) ?? createResource(resource);
|
|
569
|
+
* ```
|
|
570
|
+
*
|
|
571
|
+
* The query parameter only contains the search parameters (what would be in the URL following the "?").
|
|
572
|
+
*
|
|
573
|
+
* See the FHIR "conditional create" operation for full details: https://www.hl7.org/fhir/http.html#ccreate
|
|
574
|
+
*
|
|
575
|
+
* @param resource The FHIR resource to create.
|
|
576
|
+
* @param query The search query for an equivalent resource.
|
|
577
|
+
* @returns The result of the create operation.
|
|
578
|
+
*/
|
|
579
|
+
createResourceIfNoneExist<T extends Resource>(resource: T, query: string): Promise<T>;
|
|
535
580
|
/**
|
|
536
581
|
* Creates a FHIR `Binary` resource with the provided data content.
|
|
537
582
|
*
|
|
@@ -550,10 +595,34 @@ export declare class MedplumClient extends EventTarget {
|
|
|
550
595
|
*
|
|
551
596
|
* See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
|
|
552
597
|
*
|
|
553
|
-
* @param
|
|
598
|
+
* @param data The binary data to upload.
|
|
599
|
+
* @param filename Optional filename for the binary.
|
|
600
|
+
* @param contentType Content type for the binary.
|
|
601
|
+
* @returns The result of the create operation.
|
|
602
|
+
*/
|
|
603
|
+
createBinary(data: string | File, filename: string | undefined, contentType: string): Promise<Binary>;
|
|
604
|
+
/**
|
|
605
|
+
* Creates a PDF as a FHIR `Binary` resource based on pdfmake document definition.
|
|
606
|
+
*
|
|
607
|
+
* The return value is the newly created resource, including the ID and meta.
|
|
608
|
+
*
|
|
609
|
+
* The `docDefinition` parameter is a pdfmake document definition.
|
|
610
|
+
*
|
|
611
|
+
* Example:
|
|
612
|
+
*
|
|
613
|
+
* ```typescript
|
|
614
|
+
* const result = await medplum.createPdf({
|
|
615
|
+
* content: ['Hello world']
|
|
616
|
+
* });
|
|
617
|
+
* console.log(result.id);
|
|
618
|
+
* ```
|
|
619
|
+
*
|
|
620
|
+
* See the pdfmake document definition for full details: https://pdfmake.github.io/docs/0.1/document-definition-object/
|
|
621
|
+
*
|
|
622
|
+
* @param docDefinition The FHIR resource to create.
|
|
554
623
|
* @returns The result of the create operation.
|
|
555
624
|
*/
|
|
556
|
-
|
|
625
|
+
createPdf(docDefinition: Record<string, unknown>, filename?: string): Promise<Binary>;
|
|
557
626
|
/**
|
|
558
627
|
* Updates a FHIR resource.
|
|
559
628
|
*
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
export * from './cache';
|
|
1
2
|
export * from './client';
|
|
2
3
|
export * from './format';
|
|
3
4
|
export * from './hl7';
|
|
4
5
|
export * from './outcomes';
|
|
5
|
-
export * from './
|
|
6
|
+
export * from './readablepromise';
|
|
6
7
|
export * from './search';
|
|
7
8
|
export * from './searchparams';
|
|
8
9
|
export * from './types';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ReadablePromise class wraps a request promise suitable for React Suspense.
|
|
3
|
+
* See: https://blog.logrocket.com/react-suspense-data-fetching/#wrappromise-js
|
|
4
|
+
* See: https://github.com/ovieokeh/suspense-data-fetching/blob/master/lib/api/wrapPromise.js
|
|
5
|
+
*/
|
|
6
|
+
export declare class ReadablePromise<T> implements Promise<T> {
|
|
7
|
+
#private;
|
|
8
|
+
readonly [Symbol.toStringTag]: string;
|
|
9
|
+
constructor(requestPromise: Promise<T>);
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if the promise is pending.
|
|
12
|
+
* @returns True if the Promise is pending.
|
|
13
|
+
*/
|
|
14
|
+
isPending(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Attempts to read the value of the promise.
|
|
17
|
+
* If the promise is pending, this method will throw a promise.
|
|
18
|
+
* If the promise rejected, this method will throw the rejection reason.
|
|
19
|
+
* If the promise resolved, this method will return the resolved value.
|
|
20
|
+
* @returns The resolved value of the Promise.
|
|
21
|
+
*/
|
|
22
|
+
read(): T;
|
|
23
|
+
/**
|
|
24
|
+
* Attaches callbacks for the resolution and/or rejection of the Promise.
|
|
25
|
+
* @param onfulfilled The callback to execute when the Promise is resolved.
|
|
26
|
+
* @param onrejected The callback to execute when the Promise is rejected.
|
|
27
|
+
* @returns A Promise for the completion of which ever callback is executed.
|
|
28
|
+
*/
|
|
29
|
+
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
|
|
30
|
+
/**
|
|
31
|
+
* Attaches a callback for only the rejection of the Promise.
|
|
32
|
+
* @param onrejected The callback to execute when the Promise is rejected.
|
|
33
|
+
* @returns A Promise for the completion of the callback.
|
|
34
|
+
*/
|
|
35
|
+
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
|
|
38
|
+
* resolved value cannot be modified from the callback.
|
|
39
|
+
* @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
|
|
40
|
+
* @returns A Promise for the completion of the callback.
|
|
41
|
+
*/
|
|
42
|
+
finally(onfinally?: (() => void) | undefined | null): Promise<T>;
|
|
43
|
+
}
|
package/dist/types/search.d.ts
CHANGED
package/dist/types/utils.d.ts
CHANGED
|
@@ -91,18 +91,23 @@ export declare function stringify(value: any, pretty?: boolean): string;
|
|
|
91
91
|
/**
|
|
92
92
|
* Resource equality.
|
|
93
93
|
* Ignores meta.versionId and meta.lastUpdated.
|
|
94
|
-
* See: https://dmitripavlutin.com/how-to-compare-objects-in-javascript/#4-deep-equality
|
|
95
94
|
* @param object1 The first object.
|
|
96
95
|
* @param object2 The second object.
|
|
97
96
|
* @returns True if the objects are equal.
|
|
98
97
|
*/
|
|
99
|
-
export declare function deepEquals(object1:
|
|
98
|
+
export declare function deepEquals(object1: unknown, object2: unknown, path?: string): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Returns true if the input string is a UUID.
|
|
101
|
+
* @param input The input string.
|
|
102
|
+
* @returns True if the input string matches the UUID format.
|
|
103
|
+
*/
|
|
104
|
+
export declare function isUUID(input: string): boolean;
|
|
100
105
|
/**
|
|
101
106
|
* Returns true if the input is an object.
|
|
102
107
|
* @param object The candidate object.
|
|
103
108
|
* @returns True if the input is a non-null non-undefined object.
|
|
104
109
|
*/
|
|
105
|
-
export declare function isObject(obj: unknown): obj is
|
|
110
|
+
export declare function isObject(obj: unknown): obj is Record<string, unknown>;
|
|
106
111
|
/**
|
|
107
112
|
* Returns true if the input array is an array of strings.
|
|
108
113
|
* @param arr Input array.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medplum/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"description": "Medplum TS/JS Library",
|
|
5
5
|
"author": "Medplum <hello@medplum.com>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"test": "jest"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@medplum/fhirtypes": "0.9.
|
|
20
|
+
"@medplum/fhirtypes": "0.9.4",
|
|
21
21
|
"fast-json-patch": "3.1.1"
|
|
22
22
|
},
|
|
23
23
|
"main": "dist/cjs/index.js",
|
package/dist/types/repo.d.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { Bundle, OperationOutcome, Reference, Resource } from '@medplum/fhirtypes';
|
|
2
|
-
import { Operation } from 'fast-json-patch';
|
|
3
|
-
import { MedplumClient } from './client';
|
|
4
|
-
import { SearchRequest } from './search';
|
|
5
|
-
/**
|
|
6
|
-
* The LegacyRepositoryResult type is a tuple of operation outcome and optional resource.
|
|
7
|
-
* @deprecated
|
|
8
|
-
*/
|
|
9
|
-
export declare type LegacyRepositoryResult<T extends Resource | undefined> = Promise<[OperationOutcome, T | undefined]>;
|
|
10
|
-
/**
|
|
11
|
-
* The LegacyRepositoryClient is a supplementary API client that matches the legacy "Repository" API.
|
|
12
|
-
* The "Repository" API is deprecated and will be removed in a future release.
|
|
13
|
-
* This LegacyRepositoryClient is also deprecated and will be removed in a future release.
|
|
14
|
-
* @deprecated
|
|
15
|
-
*/
|
|
16
|
-
export declare class LegacyRepositoryClient {
|
|
17
|
-
#private;
|
|
18
|
-
constructor(client: MedplumClient);
|
|
19
|
-
/**
|
|
20
|
-
* Creates a resource.
|
|
21
|
-
*
|
|
22
|
-
* See: https://www.hl7.org/fhir/http.html#create
|
|
23
|
-
*
|
|
24
|
-
* @param resource The resource to create.
|
|
25
|
-
* @returns Operation outcome and the new resource.
|
|
26
|
-
* @deprecated
|
|
27
|
-
*/
|
|
28
|
-
createResource<T extends Resource>(resource: T): LegacyRepositoryResult<T>;
|
|
29
|
-
/**
|
|
30
|
-
* Returns a resource.
|
|
31
|
-
*
|
|
32
|
-
* See: https://www.hl7.org/fhir/http.html#read
|
|
33
|
-
*
|
|
34
|
-
* @param resourceType The FHIR resource type.
|
|
35
|
-
* @param id The FHIR resource ID.
|
|
36
|
-
* @returns Operation outcome and a resource.
|
|
37
|
-
* @deprecated
|
|
38
|
-
*/
|
|
39
|
-
readResource<T extends Resource>(resourceType: string, id: string): LegacyRepositoryResult<T>;
|
|
40
|
-
/**
|
|
41
|
-
* Returns a resource by FHIR reference.
|
|
42
|
-
*
|
|
43
|
-
* See: https://www.hl7.org/fhir/http.html#read
|
|
44
|
-
*
|
|
45
|
-
* @param reference The FHIR reference.
|
|
46
|
-
* @returns Operation outcome and a resource.
|
|
47
|
-
* @deprecated
|
|
48
|
-
*/
|
|
49
|
-
readReference<T extends Resource>(reference: Reference<T>): LegacyRepositoryResult<T>;
|
|
50
|
-
/**
|
|
51
|
-
* Returns resource history.
|
|
52
|
-
*
|
|
53
|
-
* See: https://www.hl7.org/fhir/http.html#history
|
|
54
|
-
*
|
|
55
|
-
* @param resourceType The FHIR resource type.
|
|
56
|
-
* @param id The FHIR resource ID.
|
|
57
|
-
* @returns Operation outcome and a history bundle.
|
|
58
|
-
* @deprecated
|
|
59
|
-
*/
|
|
60
|
-
readHistory<T extends Resource>(resourceType: string, id: string): LegacyRepositoryResult<Bundle<T>>;
|
|
61
|
-
/**
|
|
62
|
-
* Returns a resource version.
|
|
63
|
-
*
|
|
64
|
-
* See: https://www.hl7.org/fhir/http.html#vread
|
|
65
|
-
*
|
|
66
|
-
* @param resourceType The FHIR resource type.
|
|
67
|
-
* @param id The FHIR resource ID.
|
|
68
|
-
* @param vid The version ID.
|
|
69
|
-
* @returns Operation outcome and a resource.
|
|
70
|
-
* @deprecated
|
|
71
|
-
*/
|
|
72
|
-
readVersion<T extends Resource>(resourceType: string, id: string, vid: string): LegacyRepositoryResult<T>;
|
|
73
|
-
/**
|
|
74
|
-
* Updates a resource.
|
|
75
|
-
*
|
|
76
|
-
* See: https://www.hl7.org/fhir/http.html#update
|
|
77
|
-
*
|
|
78
|
-
* @param resource The resource to update.
|
|
79
|
-
* @returns Operation outcome and the updated resource.
|
|
80
|
-
* @deprecated
|
|
81
|
-
*/
|
|
82
|
-
updateResource<T extends Resource>(resource: T): LegacyRepositoryResult<T>;
|
|
83
|
-
/**
|
|
84
|
-
* Deletes a resource.
|
|
85
|
-
*
|
|
86
|
-
* See: https://www.hl7.org/fhir/http.html#delete
|
|
87
|
-
*
|
|
88
|
-
* @param resourceType The FHIR resource type.
|
|
89
|
-
* @param id The resource ID.
|
|
90
|
-
* @returns Operation outcome.
|
|
91
|
-
* @deprecated
|
|
92
|
-
*/
|
|
93
|
-
deleteResource(resourceType: string, id: string): LegacyRepositoryResult<undefined>;
|
|
94
|
-
/**
|
|
95
|
-
* Patches a resource.
|
|
96
|
-
*
|
|
97
|
-
* See: https://www.hl7.org/fhir/http.html#patch
|
|
98
|
-
*
|
|
99
|
-
* @param resourceType The FHIR resource type.
|
|
100
|
-
* @param id The resource ID.
|
|
101
|
-
* @param patch Array of JSONPatch operations.
|
|
102
|
-
* @returns Operation outcome and the resource.
|
|
103
|
-
* @deprecated
|
|
104
|
-
*/
|
|
105
|
-
patchResource(resourceType: string, id: string, patch: Operation[]): LegacyRepositoryResult<Resource>;
|
|
106
|
-
/**
|
|
107
|
-
* Searches for resources.
|
|
108
|
-
*
|
|
109
|
-
* See: https://www.hl7.org/fhir/http.html#search
|
|
110
|
-
*
|
|
111
|
-
* @param searchRequest The search request.
|
|
112
|
-
* @returns The search result bundle.
|
|
113
|
-
* @deprecated
|
|
114
|
-
*/
|
|
115
|
-
search<T extends Resource>(query: SearchRequest | string): LegacyRepositoryResult<Bundle<T>>;
|
|
116
|
-
}
|