@medplum/core 0.9.3 → 0.9.6

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,669 +1,756 @@
1
- import { Binary, Bundle, Project, ProjectMembership, Reference, Resource, UserConfiguration, ValueSet } from '@medplum/fhirtypes';
2
- import type { Operation } from 'fast-json-patch';
3
- import { EventTarget } from './eventtarget';
4
- import { ReadablePromise } from './readablepromise';
5
- import { SearchRequest } from './search';
6
- import { IndexedStructureDefinition } from './types';
7
- import { ProfileResource } from './utils';
8
- export interface MedplumClientOptions {
9
- /**
10
- * The client ID.
11
- * Optional. Default is to defer to the server to use the default client.
12
- * Use this to use a specific client for SMART-on-FHIR.
13
- */
14
- clientId?: string;
15
- /**
16
- * Base server URL.
17
- * Optional. Default value is "https://api.medplum.com/".
18
- * Use this to point to a custom Medplum deployment.
19
- */
20
- baseUrl?: string;
21
- /**
22
- * OAuth2 authorize URL.
23
- * Optional. Default value is baseUrl + "/oauth2/authorize".
24
- * Use this if you want to use a separate OAuth server.
25
- */
26
- authorizeUrl?: string;
27
- /**
28
- * OAuth2 token URL.
29
- * Optional. Default value is baseUrl + "/oauth2/token".
30
- * Use this if you want to use a separate OAuth server.
31
- */
32
- tokenUrl?: string;
33
- /**
34
- * OAuth2 logout URL.
35
- * Optional. Default value is baseUrl + "/oauth2/logout".
36
- * Use this if you want to use a separate OAuth server.
37
- */
38
- logoutUrl?: string;
39
- /**
40
- * Number of resources to store in the cache.
41
- * Optional. Default value is 1000.
42
- * Consider using this for performance of displaying Patient or Practitioner resources.
43
- */
44
- resourceCacheSize?: number;
45
- /**
46
- * Optional fetch implementation.
47
- * Optional. Default is window.fetch.
48
- * For nodejs applications, consider the 'node-fetch' package.
49
- */
50
- fetch?: FetchLike;
51
- /**
52
- * Optional callback for when the client is unauthenticated.
53
- * Default is do nothing.
54
- * For client side applications, consider redirecting to a sign in page.
55
- */
56
- onUnauthenticated?: () => void;
57
- }
58
- export interface FetchLike {
59
- (url: string, options?: any): Promise<any>;
60
- }
61
- export interface RegisterRequest {
62
- readonly firstName: string;
63
- readonly lastName: string;
64
- readonly projectName: string;
65
- readonly email: string;
66
- readonly password: string;
67
- readonly remember?: boolean;
68
- readonly recaptchaToken: string;
69
- }
70
- export interface GoogleCredentialResponse {
71
- readonly clientId: string;
72
- readonly credential: string;
73
- }
74
- export interface LoginAuthenticationResponse {
75
- readonly login: string;
76
- readonly code?: string;
77
- readonly memberships?: ProjectMembership[];
78
- }
79
- export interface LoginProfileResponse {
80
- readonly login: string;
81
- readonly scope: string;
82
- }
83
- export interface LoginScopeResponse {
84
- readonly login: string;
85
- readonly code: string;
86
- }
87
- export interface LoginState {
88
- readonly project: Reference<Project>;
89
- readonly profile: Reference<ProfileResource>;
90
- readonly accessToken: string;
91
- readonly refreshToken: string;
92
- }
93
- export interface TokenResponse {
94
- readonly token_type: string;
95
- readonly id_token: string;
96
- readonly access_token: string;
97
- readonly refresh_token: string;
98
- readonly expires_in: number;
99
- readonly project: Reference<Project>;
100
- readonly profile: Reference<ProfileResource>;
101
- }
102
- /**
103
- * The MedplumClient class provides a client for the Medplum FHIR server.
104
- *
105
- * The client can be used in the browser, in a NodeJS application, or in a Medplum Bot.
106
- *
107
- * The client provides helpful methods for common operations such as:
108
- * 1) Authenticating
109
- * 2) Creating resources
110
- * 2) Reading resources
111
- * 3) Updating resources
112
- * 5) Deleting resources
113
- * 6) Searching
114
- * 7) Making GraphQL queries
115
- *
116
- * Here is a quick example of how to use the client:
117
- *
118
- * ```typescript
119
- * import { MedplumClient } from '@medplum/core';
120
- * const medplum = new MedplumClient();
121
- * ```
122
- *
123
- * Create a `Patient`:
124
- *
125
- * ```typescript
126
- * const patient = await medplum.createResource({
127
- * resourceType: 'Patient',
128
- * name: [{
129
- * given: ['Alice'],
130
- * family: 'Smith'
131
- * }]
132
- * });
133
- * ```
134
- *
135
- * Read a `Patient` by ID:
136
- *
137
- * ```typescript
138
- * const patient = await medplum.readResource('Patient', '123');
139
- * console.log(patient.name[0].given[0]);
140
- * ```
141
- *
142
- * Search for a `Patient` by name:
143
- *
144
- * ```typescript
145
- * const bundle = await medplum.search('Patient?name=Alice');
146
- * console.log(bundle.total);
147
- * ```
148
- *
149
- */
150
- export declare class MedplumClient extends EventTarget {
151
- #private;
152
- constructor(options?: MedplumClientOptions);
153
- /**
154
- * Clears all auth state including local storage and session storage.
155
- */
156
- clear(): void;
157
- /**
158
- * Makes an HTTP GET request to the specified URL.
159
- *
160
- * This is a lower level method for custom requests.
161
- * For common operations, we recommend using higher level methods
162
- * such as `readResource()`, `search()`, etc.
163
- *
164
- * @param url The target URL.
165
- * @param options Optional fetch options.
166
- * @returns Promise to the response content.
167
- */
168
- get<T = any>(url: string, options?: RequestInit): ReadablePromise<T>;
169
- /**
170
- * Makes an HTTP POST request to the specified URL.
171
- *
172
- * This is a lower level method for custom requests.
173
- * For common operations, we recommend using higher level methods
174
- * such as `createResource()`.
175
- *
176
- * @param url The target URL.
177
- * @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
178
- * @param contentType The content type to be included in the "Content-Type" header.
179
- * @param options Optional fetch options.
180
- * @returns Promise to the response content.
181
- */
182
- post(url: string, body: any, contentType?: string, options?: RequestInit): Promise<any>;
183
- /**
184
- * Makes an HTTP PUT request to the specified URL.
185
- *
186
- * This is a lower level method for custom requests.
187
- * For common operations, we recommend using higher level methods
188
- * such as `updateResource()`.
189
- *
190
- * @param url The target URL.
191
- * @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
192
- * @param contentType The content type to be included in the "Content-Type" header.
193
- * @param options Optional fetch options.
194
- * @returns Promise to the response content.
195
- */
196
- put(url: string, body: any, contentType?: string, options?: RequestInit): Promise<any>;
197
- /**
198
- * Makes an HTTP PATCH request to the specified URL.
199
- *
200
- * This is a lower level method for custom requests.
201
- * For common operations, we recommend using higher level methods
202
- * such as `patchResource()`.
203
- *
204
- * @param url The target URL.
205
- * @param operations Array of JSONPatch operations.
206
- * @param options Optional fetch options.
207
- * @returns Promise to the response content.
208
- */
209
- patch(url: string, operations: Operation[], options?: RequestInit): Promise<any>;
210
- /**
211
- * Makes an HTTP DELETE request to the specified URL.
212
- *
213
- * This is a lower level method for custom requests.
214
- * For common operations, we recommend using higher level methods
215
- * such as `deleteResource()`.
216
- *
217
- * @param url The target URL.
218
- * @param options Optional fetch options.
219
- * @returns Promise to the response content.
220
- */
221
- delete(url: string, options?: RequestInit): Promise<any>;
222
- /**
223
- * Tries to register a new user.
224
- * @param request The registration request.
225
- * @returns Promise to the authentication response.
226
- */
227
- register(request: RegisterRequest): Promise<void>;
228
- /**
229
- * Initiates a user login flow.
230
- * @param email The email address of the user.
231
- * @param password The password of the user.
232
- * @param remember Optional flag to remember the user.
233
- * @returns Promise to the authentication response.
234
- */
235
- startLogin(email: string, password: string, remember?: boolean): Promise<LoginAuthenticationResponse>;
236
- /**
237
- * Tries to sign in with Google authentication.
238
- * The response parameter is the result of a Google authentication.
239
- * See: https://developers.google.com/identity/gsi/web/guides/handle-credential-responses-js-functions
240
- * @param googleResponse The Google credential response.
241
- * @returns Promise to the authentication response.
242
- */
243
- startGoogleLogin(googleResponse: GoogleCredentialResponse): Promise<LoginAuthenticationResponse>;
244
- /**
245
- * Signs out locally.
246
- * Does not invalidate tokens with the server.
247
- */
248
- signOut(): Promise<void>;
249
- /**
250
- * Tries to sign in the user.
251
- * Returns true if the user is signed in.
252
- * This may result in navigating away to the sign in page.
253
- */
254
- signInWithRedirect(): Promise<ProfileResource | void> | undefined;
255
- /**
256
- * Tries to sign out the user.
257
- * See: https://docs.aws.amazon.com/cognito/latest/developerguide/logout-endpoint.html
258
- */
259
- signOutWithRedirect(): void;
260
- /**
261
- * Builds a FHIR URL from a collection of URL path components.
262
- * For example, `buildUrl('/Patient', '123')` returns `fhir/R4/Patient/123`.
263
- * @param path The path component of the URL.
264
- * @returns The well-formed FHIR URL.
265
- */
266
- fhirUrl(...path: string[]): string;
267
- /**
268
- * Sends a FHIR search request.
269
- *
270
- * Example using a FHIR search string:
271
- *
272
- * ```typescript
273
- * const bundle = await client.search('Patient?name=Alice');
274
- * console.log(bundle);
275
- * ```
276
- *
277
- * Example using a structured search:
278
- *
279
- * ```typescript
280
- * const bundle = await client.search({
281
- * resourceType: 'Patient',
282
- * filters: [{
283
- * code: 'name',
284
- * operator: 'eq',
285
- * value: 'Alice',
286
- * }]
287
- * });
288
- * console.log(bundle);
289
- * ```
290
- *
291
- * The return value is a FHIR bundle:
292
- *
293
- * ```json
294
- * {
295
- * "resourceType": "Bundle",
296
- * "type": "searchest",
297
- * "total": 1,
298
- * "entry": [
299
- * {
300
- * "resource": {
301
- * "resourceType": "Patient",
302
- * "name": [
303
- * {
304
- * "given": [
305
- * "George"
306
- * ],
307
- * "family": "Washington"
308
- * }
309
- * ],
310
- * }
311
- * }
312
- * ]
313
- * }
314
- * ```
315
- *
316
- * See FHIR search for full details: https://www.hl7.org/fhir/search.html
317
- *
318
- * @param query The search query as either a string or a structured search object.
319
- * @returns Promise to the search result bundle.
320
- */
321
- search<T extends Resource>(query: string | SearchRequest, options?: RequestInit): Promise<Bundle<T>>;
322
- /**
323
- * Sends a FHIR search request for a single resource.
324
- *
325
- * This is a convenience method for `search()` that returns the first resource rather than a `Bundle`.
326
- *
327
- * Example using a FHIR search string:
328
- *
329
- * ```typescript
330
- * const patient = await client.searchOne('Patient?identifier=123');
331
- * console.log(patient);
332
- * ```
333
- *
334
- * The return value is the resource, if available; otherwise, undefined.
335
- *
336
- * See FHIR search for full details: https://www.hl7.org/fhir/search.html
337
- *
338
- * @param query The search query as either a string or a structured search object.
339
- * @returns Promise to the search result bundle.
340
- */
341
- searchOne<T extends Resource>(query: string | SearchRequest, options?: RequestInit): Promise<T | undefined>;
342
- /**
343
- * Sends a FHIR search request for an array of resources.
344
- *
345
- * This is a convenience method for `search()` that returns the resources as an array rather than a `Bundle`.
346
- *
347
- * Example using a FHIR search string:
348
- *
349
- * ```typescript
350
- * const patients = await client.searchResources('Patient?name=Alice');
351
- * console.log(patients);
352
- * ```
353
- *
354
- * The return value is an array of resources.
355
- *
356
- * See FHIR search for full details: https://www.hl7.org/fhir/search.html
357
- *
358
- * @param query The search query as either a string or a structured search object.
359
- * @returns Promise to the search result bundle.
360
- */
361
- searchResources<T extends Resource>(query: string | SearchRequest, options?: RequestInit): Promise<T[]>;
362
- /**
363
- * Searches a ValueSet resource using the "expand" operation.
364
- * See: https://www.hl7.org/fhir/operation-valueset-expand.html
365
- * @param system The ValueSet system url.
366
- * @param filter The search string.
367
- * @returns Promise to expanded ValueSet.
368
- */
369
- searchValueSet(system: string, filter: string, options?: RequestInit): Promise<ValueSet>;
370
- /**
371
- * Returns a cached resource if it is available.
372
- * @param resourceType The FHIR resource type.
373
- * @param id The FHIR resource ID.
374
- * @returns The resource if it is available in the cache; undefined otherwise.
375
- */
376
- getCached<T extends Resource>(resourceType: string, id: string): T | undefined;
377
- /**
378
- * Returns a cached resource if it is available.
379
- * @param resourceType The FHIR resource type.
380
- * @param id The FHIR resource ID.
381
- * @returns The resource if it is available in the cache; undefined otherwise.
382
- */
383
- getCachedReference<T extends Resource>(reference: Reference<T>): T | undefined;
384
- /**
385
- * Reads a resource by resource type and ID.
386
- *
387
- * Example:
388
- *
389
- * ```typescript
390
- * const patient = await medplum.readResource('Patient', '123');
391
- * console.log(patient);
392
- * ```
393
- *
394
- * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
395
- *
396
- * @param resourceType The FHIR resource type.
397
- * @param id The resource ID.
398
- * @returns The resource if available; undefined otherwise.
399
- */
400
- readResource<T extends Resource>(resourceType: string, id: string): ReadablePromise<T>;
401
- /**
402
- * Reads a resource by resource type and ID using the in-memory resource cache.
403
- *
404
- * If the resource is not available in the cache, it will be read from the server.
405
- *
406
- * Example:
407
- *
408
- * ```typescript
409
- * const patient = await medplum.readCached('Patient', '123');
410
- * console.log(patient);
411
- * ```
412
- *
413
- * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
414
- *
415
- * @param resourceType The FHIR resource type.
416
- * @param id The resource ID.
417
- * @returns The resource if available; undefined otherwise.
418
- */
419
- readCached<T extends Resource>(resourceType: string, id: string): ReadablePromise<T>;
420
- /**
421
- * Reads a resource by `Reference`.
422
- *
423
- * This is a convenience method for `readResource()` that accepts a `Reference` object.
424
- *
425
- * Example:
426
- *
427
- * ```typescript
428
- * const serviceRequest = await medplum.readResource('ServiceRequest', '123');
429
- * const patient = await medplum.readReference(serviceRequest.subject);
430
- * console.log(patient);
431
- * ```
432
- *
433
- * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
434
- *
435
- * @param reference The FHIR reference object.
436
- * @returns The resource if available; undefined otherwise.
437
- */
438
- readReference<T extends Resource>(reference: Reference<T>): ReadablePromise<T>;
439
- /**
440
- * Reads a resource by `Reference` using the in-memory resource cache.
441
- *
442
- * This is a convenience method for `readResource()` that accepts a `Reference` object.
443
- *
444
- * If the resource is not available in the cache, it will be read from the server.
445
- *
446
- * Example:
447
- *
448
- * ```typescript
449
- * const serviceRequest = await medplum.readResource('ServiceRequest', '123');
450
- * const patient = await medplum.readCachedReference(serviceRequest.subject);
451
- * console.log(patient);
452
- * ```
453
- *
454
- * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
455
- *
456
- * @param reference The FHIR reference object.
457
- * @returns The resource if available; undefined otherwise.
458
- */
459
- readCachedReference<T extends Resource>(reference: Reference<T>): ReadablePromise<T>;
460
- /**
461
- * Returns a cached schema for a resource type.
462
- * If the schema is not cached, returns undefined.
463
- * It is assumed that a client will call requestSchema before using this method.
464
- * @param resourceType The FHIR resource type.
465
- * @returns The schema if immediately available, undefined otherwise.
466
- */
467
- getSchema(): IndexedStructureDefinition;
468
- /**
469
- * Requests the schema for a resource type.
470
- * If the schema is already cached, the promise is resolved immediately.
471
- * @param resourceType The FHIR resource type.
472
- * @returns Promise to a schema with the requested resource type.
473
- */
474
- requestSchema(resourceType: string): Promise<IndexedStructureDefinition>;
475
- /**
476
- * Reads resource history by resource type and ID.
477
- *
478
- * The return value is a bundle of all versions of the resource.
479
- *
480
- * Example:
481
- *
482
- * ```typescript
483
- * const history = await medplum.readHistory('Patient', '123');
484
- * console.log(history);
485
- * ```
486
- *
487
- * See the FHIR "history" operation for full details: https://www.hl7.org/fhir/http.html#history
488
- *
489
- * @param resourceType The FHIR resource type.
490
- * @param id The resource ID.
491
- * @returns The resource if available; undefined otherwise.
492
- */
493
- readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>;
494
- /**
495
- * Reads a specific version of a resource by resource type, ID, and version ID.
496
- *
497
- * Example:
498
- *
499
- * ```typescript
500
- * const version = await medplum.readVersion('Patient', '123', '456');
501
- * console.log(version);
502
- * ```
503
- *
504
- * See the FHIR "vread" operation for full details: https://www.hl7.org/fhir/http.html#vread
505
- *
506
- * @param resourceType The FHIR resource type.
507
- * @param id The resource ID.
508
- * @returns The resource if available; undefined otherwise.
509
- */
510
- readVersion<T extends Resource>(resourceType: string, id: string, vid: string): Promise<T>;
511
- readPatientEverything(id: string): Promise<Bundle>;
512
- /**
513
- * Creates a new FHIR resource.
514
- *
515
- * The return value is the newly created resource, including the ID and meta.
516
- *
517
- * Example:
518
- *
519
- * ```typescript
520
- * const result = await medplum.createResource({
521
- * resourceType: 'Patient',
522
- * name: [{
523
- * family: 'Smith',
524
- * given: ['John']
525
- * }]
526
- * });
527
- * console.log(result.id);
528
- * ```
529
- *
530
- * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
531
- *
532
- * @param resource The FHIR resource to create.
533
- * @returns The result of the create operation.
534
- */
535
- createResource<T extends Resource>(resource: T): Promise<T>;
536
- /**
537
- * Creates a FHIR `Binary` resource with the provided data content.
538
- *
539
- * The return value is the newly created resource, including the ID and meta.
540
- *
541
- * The `data` parameter can be a string or a `File` object.
542
- *
543
- * A `File` object often comes from a `<input type="file">` element.
544
- *
545
- * Example:
546
- *
547
- * ```typescript
548
- * const result = await medplum.createBinary(myFile, 'test.jpg', 'image/jpeg');
549
- * console.log(result.id);
550
- * ```
551
- *
552
- * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
553
- *
554
- * @param data The binary data to upload.
555
- * @param filename Optional filename for the binary.
556
- * @param contentType Content type for the binary.
557
- * @returns The result of the create operation.
558
- */
559
- createBinary(data: string | File, filename: string | undefined, contentType: string): Promise<Binary>;
560
- /**
561
- * Creates a PDF as a FHIR `Binary` resource based on pdfmake document definition.
562
- *
563
- * The return value is the newly created resource, including the ID and meta.
564
- *
565
- * The `docDefinition` parameter is a pdfmake document definition.
566
- *
567
- * Example:
568
- *
569
- * ```typescript
570
- * const result = await medplum.createPdf({
571
- * content: ['Hello world']
572
- * });
573
- * console.log(result.id);
574
- * ```
575
- *
576
- * See the pdfmake document definition for full details: https://pdfmake.github.io/docs/0.1/document-definition-object/
577
- *
578
- * @param docDefinition The FHIR resource to create.
579
- * @returns The result of the create operation.
580
- */
581
- createPdf(docDefinition: Record<string, unknown>, filename?: string): Promise<Binary>;
582
- /**
583
- * Updates a FHIR resource.
584
- *
585
- * The return value is the updated resource, including the ID and meta.
586
- *
587
- * Example:
588
- *
589
- * ```typescript
590
- * const result = await medplum.updateResource({
591
- * resourceType: 'Patient',
592
- * id: '123',
593
- * name: [{
594
- * family: 'Smith',
595
- * given: ['John']
596
- * }]
597
- * });
598
- * console.log(result.meta.versionId);
599
- * ```
600
- *
601
- * See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#update
602
- *
603
- * @param resource The FHIR resource to update.
604
- * @returns The result of the update operation.
605
- */
606
- updateResource<T extends Resource>(resource: T): Promise<T>;
607
- /**
608
- * Updates a FHIR resource using JSONPatch operations.
609
- *
610
- * The return value is the updated resource, including the ID and meta.
611
- *
612
- * Example:
613
- *
614
- * ```typescript
615
- * const result = await medplum.patchResource('Patient', '123', [
616
- * {op: 'replace', path: '/name/0/family', value: 'Smith'},
617
- * ]);
618
- * console.log(result.meta.versionId);
619
- * ```
620
- *
621
- * See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#patch
622
- *
623
- * See the JSONPatch specification for full details: https://tools.ietf.org/html/rfc6902
624
- *
625
- * @param resourceType The FHIR resource type.
626
- * @param id The resource ID.
627
- * @param operations The JSONPatch operations.
628
- * @returns The result of the patch operations.
629
- */
630
- patchResource<T extends Resource>(resourceType: string, id: string, operations: Operation[]): Promise<T>;
631
- /**
632
- * Deletes a FHIR resource by resource type and ID.
633
- *
634
- * Example:
635
- *
636
- * ```typescript
637
- * await medplum.deleteResource('Patient', '123');
638
- * ```
639
- *
640
- * See the FHIR "delete" operation for full details: https://www.hl7.org/fhir/http.html#delete
641
- *
642
- * @param resourceType The FHIR resource type.
643
- * @param id The resource ID.
644
- * @returns The result of the delete operation.
645
- */
646
- deleteResource(resourceType: string, id: string): Promise<any>;
647
- graphql(query: string, options?: RequestInit): Promise<any>;
648
- getActiveLogin(): LoginState | undefined;
649
- setActiveLogin(login: LoginState): Promise<void>;
650
- setAccessToken(accessToken: string): void;
651
- getLogins(): LoginState[];
652
- isLoading(): boolean;
653
- getProfile(): ProfileResource | undefined;
654
- getProfileAsync(): Promise<ProfileResource | undefined>;
655
- getUserConfiguration(): UserConfiguration | undefined;
656
- /**
657
- * Downloads the URL as a blob.
658
- * @param url The URL to request.
659
- * @returns Promise to the response body as a blob.
660
- */
661
- download(url: string, options?: RequestInit): Promise<Blob>;
662
- /**
663
- * Processes an OAuth authorization code.
664
- * See: https://openid.net/specs/openid-connect-core-1_0.html#TokenRequest
665
- * @param code The authorization code received by URL parameter.
666
- */
667
- processCode(code: string): Promise<ProfileResource>;
668
- clientCredentials(clientId: string, clientSecret: string): Promise<ProfileResource>;
669
- }
1
+ import { Binary, Bundle, OperationOutcome, Project, ProjectMembership, Reference, Resource, UserConfiguration, ValueSet } from '@medplum/fhirtypes';
2
+ import type { Operation } from 'fast-json-patch';
3
+ import type Mail from 'nodemailer/lib/mailer';
4
+ import { EventTarget } from './eventtarget';
5
+ import { Hl7Message } from './hl7';
6
+ import { ReadablePromise } from './readablepromise';
7
+ import { SearchRequest } from './search';
8
+ import { IndexedStructureDefinition } from './types';
9
+ import { ProfileResource } from './utils';
10
+ export interface MedplumClientOptions {
11
+ /**
12
+ * The client ID.
13
+ * Optional. Default is to defer to the server to use the default client.
14
+ * Use this to use a specific client for SMART-on-FHIR.
15
+ */
16
+ clientId?: string;
17
+ /**
18
+ * Base server URL.
19
+ * Optional. Default value is "https://api.medplum.com/".
20
+ * Use this to point to a custom Medplum deployment.
21
+ */
22
+ baseUrl?: string;
23
+ /**
24
+ * OAuth2 authorize URL.
25
+ * Optional. Default value is baseUrl + "/oauth2/authorize".
26
+ * Use this if you want to use a separate OAuth server.
27
+ */
28
+ authorizeUrl?: string;
29
+ /**
30
+ * OAuth2 token URL.
31
+ * Optional. Default value is baseUrl + "/oauth2/token".
32
+ * Use this if you want to use a separate OAuth server.
33
+ */
34
+ tokenUrl?: string;
35
+ /**
36
+ * OAuth2 logout URL.
37
+ * Optional. Default value is baseUrl + "/oauth2/logout".
38
+ * Use this if you want to use a separate OAuth server.
39
+ */
40
+ logoutUrl?: string;
41
+ /**
42
+ * Number of resources to store in the cache.
43
+ * Optional. Default value is 1000.
44
+ * Consider using this for performance of displaying Patient or Practitioner resources.
45
+ */
46
+ resourceCacheSize?: number;
47
+ /**
48
+ * Optional fetch implementation.
49
+ * Optional. Default is window.fetch.
50
+ * For nodejs applications, consider the 'node-fetch' package.
51
+ */
52
+ fetch?: FetchLike;
53
+ /**
54
+ * Optional callback for when the client is unauthenticated.
55
+ * Default is do nothing.
56
+ * For client side applications, consider redirecting to a sign in page.
57
+ */
58
+ onUnauthenticated?: () => void;
59
+ }
60
+ export interface FetchLike {
61
+ (url: string, options?: any): Promise<any>;
62
+ }
63
+ export interface LoginRequest {
64
+ readonly email: string;
65
+ readonly password: string;
66
+ readonly remember?: boolean;
67
+ readonly projectId?: string;
68
+ }
69
+ export interface RegisterRequest {
70
+ readonly firstName: string;
71
+ readonly lastName: string;
72
+ readonly projectName: string;
73
+ readonly email: string;
74
+ readonly password: string;
75
+ readonly remember?: boolean;
76
+ readonly recaptchaToken: string;
77
+ }
78
+ export interface GoogleCredentialResponse {
79
+ readonly clientId: string;
80
+ readonly credential: string;
81
+ }
82
+ export interface LoginAuthenticationResponse {
83
+ readonly login: string;
84
+ readonly code?: string;
85
+ readonly memberships?: ProjectMembership[];
86
+ }
87
+ export interface LoginProfileResponse {
88
+ readonly login: string;
89
+ readonly scope: string;
90
+ }
91
+ export interface LoginScopeResponse {
92
+ readonly login: string;
93
+ readonly code: string;
94
+ }
95
+ export interface LoginState {
96
+ readonly project: Reference<Project>;
97
+ readonly profile: Reference<ProfileResource>;
98
+ readonly accessToken: string;
99
+ readonly refreshToken: string;
100
+ }
101
+ export interface TokenResponse {
102
+ readonly token_type: string;
103
+ readonly id_token: string;
104
+ readonly access_token: string;
105
+ readonly refresh_token: string;
106
+ readonly expires_in: number;
107
+ readonly project: Reference<Project>;
108
+ readonly profile: Reference<ProfileResource>;
109
+ }
110
+ export interface BotEvent {
111
+ readonly contentType: string;
112
+ readonly input: Resource | Hl7Message | string;
113
+ }
114
+ /**
115
+ * The MedplumClient class provides a client for the Medplum FHIR server.
116
+ *
117
+ * The client can be used in the browser, in a NodeJS application, or in a Medplum Bot.
118
+ *
119
+ * The client provides helpful methods for common operations such as:
120
+ * 1) Authenticating
121
+ * 2) Creating resources
122
+ * 2) Reading resources
123
+ * 3) Updating resources
124
+ * 5) Deleting resources
125
+ * 6) Searching
126
+ * 7) Making GraphQL queries
127
+ *
128
+ * Here is a quick example of how to use the client:
129
+ *
130
+ * ```typescript
131
+ * import { MedplumClient } from '@medplum/core';
132
+ * const medplum = new MedplumClient();
133
+ * ```
134
+ *
135
+ * Create a `Patient`:
136
+ *
137
+ * ```typescript
138
+ * const patient = await medplum.createResource({
139
+ * resourceType: 'Patient',
140
+ * name: [{
141
+ * given: ['Alice'],
142
+ * family: 'Smith'
143
+ * }]
144
+ * });
145
+ * ```
146
+ *
147
+ * Read a `Patient` by ID:
148
+ *
149
+ * ```typescript
150
+ * const patient = await medplum.readResource('Patient', '123');
151
+ * console.log(patient.name[0].given[0]);
152
+ * ```
153
+ *
154
+ * Search for a `Patient` by name:
155
+ *
156
+ * ```typescript
157
+ * const bundle = await medplum.search('Patient?name=Alice');
158
+ * console.log(bundle.total);
159
+ * ```
160
+ *
161
+ */
162
+ export declare class MedplumClient extends EventTarget {
163
+ #private;
164
+ constructor(options?: MedplumClientOptions);
165
+ /**
166
+ * Clears all auth state including local storage and session storage.
167
+ */
168
+ clear(): void;
169
+ /**
170
+ * Makes an HTTP GET request to the specified URL.
171
+ *
172
+ * This is a lower level method for custom requests.
173
+ * For common operations, we recommend using higher level methods
174
+ * such as `readResource()`, `search()`, etc.
175
+ *
176
+ * @param url The target URL.
177
+ * @param options Optional fetch options.
178
+ * @returns Promise to the response content.
179
+ */
180
+ get<T = any>(url: string, options?: RequestInit): ReadablePromise<T>;
181
+ /**
182
+ * Makes an HTTP POST request to the specified URL.
183
+ *
184
+ * This is a lower level method for custom requests.
185
+ * For common operations, we recommend using higher level methods
186
+ * such as `createResource()`.
187
+ *
188
+ * @param url The target URL.
189
+ * @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
190
+ * @param contentType The content type to be included in the "Content-Type" header.
191
+ * @param options Optional fetch options.
192
+ * @returns Promise to the response content.
193
+ */
194
+ post(url: string, body: any, contentType?: string, options?: RequestInit): Promise<any>;
195
+ /**
196
+ * Makes an HTTP PUT request to the specified URL.
197
+ *
198
+ * This is a lower level method for custom requests.
199
+ * For common operations, we recommend using higher level methods
200
+ * such as `updateResource()`.
201
+ *
202
+ * @param url The target URL.
203
+ * @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
204
+ * @param contentType The content type to be included in the "Content-Type" header.
205
+ * @param options Optional fetch options.
206
+ * @returns Promise to the response content.
207
+ */
208
+ put(url: string, body: any, contentType?: string, options?: RequestInit): Promise<any>;
209
+ /**
210
+ * Makes an HTTP PATCH request to the specified URL.
211
+ *
212
+ * This is a lower level method for custom requests.
213
+ * For common operations, we recommend using higher level methods
214
+ * such as `patchResource()`.
215
+ *
216
+ * @param url The target URL.
217
+ * @param operations Array of JSONPatch operations.
218
+ * @param options Optional fetch options.
219
+ * @returns Promise to the response content.
220
+ */
221
+ patch(url: string, operations: Operation[], options?: RequestInit): Promise<any>;
222
+ /**
223
+ * Makes an HTTP DELETE request to the specified URL.
224
+ *
225
+ * This is a lower level method for custom requests.
226
+ * For common operations, we recommend using higher level methods
227
+ * such as `deleteResource()`.
228
+ *
229
+ * @param url The target URL.
230
+ * @param options Optional fetch options.
231
+ * @returns Promise to the response content.
232
+ */
233
+ delete(url: string, options?: RequestInit): Promise<any>;
234
+ /**
235
+ * Tries to register a new user.
236
+ * @param request The registration request.
237
+ * @returns Promise to the authentication response.
238
+ */
239
+ register(request: RegisterRequest): Promise<void>;
240
+ /**
241
+ * Initiates a user login flow.
242
+ * @param loginRequest Login request including email and password.
243
+ * @returns Promise to the authentication response.
244
+ */
245
+ startLogin(loginRequest: LoginRequest): Promise<LoginAuthenticationResponse>;
246
+ /**
247
+ * Tries to sign in with Google authentication.
248
+ * The response parameter is the result of a Google authentication.
249
+ * See: https://developers.google.com/identity/gsi/web/guides/handle-credential-responses-js-functions
250
+ * @param googleResponse The Google credential response.
251
+ * @returns Promise to the authentication response.
252
+ */
253
+ startGoogleLogin(googleResponse: GoogleCredentialResponse): Promise<LoginAuthenticationResponse>;
254
+ /**
255
+ * Signs out locally.
256
+ * Does not invalidate tokens with the server.
257
+ */
258
+ signOut(): Promise<void>;
259
+ /**
260
+ * Tries to sign in the user.
261
+ * Returns true if the user is signed in.
262
+ * This may result in navigating away to the sign in page.
263
+ */
264
+ signInWithRedirect(): Promise<ProfileResource | void> | undefined;
265
+ /**
266
+ * Tries to sign out the user.
267
+ * See: https://docs.aws.amazon.com/cognito/latest/developerguide/logout-endpoint.html
268
+ */
269
+ signOutWithRedirect(): void;
270
+ /**
271
+ * Builds a FHIR URL from a collection of URL path components.
272
+ * For example, `buildUrl('/Patient', '123')` returns `fhir/R4/Patient/123`.
273
+ * @param path The path component of the URL.
274
+ * @returns The well-formed FHIR URL.
275
+ */
276
+ fhirUrl(...path: string[]): string;
277
+ /**
278
+ * Sends a FHIR search request.
279
+ *
280
+ * Example using a FHIR search string:
281
+ *
282
+ * ```typescript
283
+ * const bundle = await client.search('Patient?name=Alice');
284
+ * console.log(bundle);
285
+ * ```
286
+ *
287
+ * Example using a structured search:
288
+ *
289
+ * ```typescript
290
+ * const bundle = await client.search({
291
+ * resourceType: 'Patient',
292
+ * filters: [{
293
+ * code: 'name',
294
+ * operator: 'eq',
295
+ * value: 'Alice',
296
+ * }]
297
+ * });
298
+ * console.log(bundle);
299
+ * ```
300
+ *
301
+ * The return value is a FHIR bundle:
302
+ *
303
+ * ```json
304
+ * {
305
+ * "resourceType": "Bundle",
306
+ * "type": "searchest",
307
+ * "total": 1,
308
+ * "entry": [
309
+ * {
310
+ * "resource": {
311
+ * "resourceType": "Patient",
312
+ * "name": [
313
+ * {
314
+ * "given": [
315
+ * "George"
316
+ * ],
317
+ * "family": "Washington"
318
+ * }
319
+ * ],
320
+ * }
321
+ * }
322
+ * ]
323
+ * }
324
+ * ```
325
+ *
326
+ * See FHIR search for full details: https://www.hl7.org/fhir/search.html
327
+ *
328
+ * @param query The search query as either a string or a structured search object.
329
+ * @returns Promise to the search result bundle.
330
+ */
331
+ search<T extends Resource>(query: string | SearchRequest, options?: RequestInit): Promise<Bundle<T>>;
332
+ /**
333
+ * Sends a FHIR search request for a single resource.
334
+ *
335
+ * This is a convenience method for `search()` that returns the first resource rather than a `Bundle`.
336
+ *
337
+ * Example using a FHIR search string:
338
+ *
339
+ * ```typescript
340
+ * const patient = await client.searchOne('Patient?identifier=123');
341
+ * console.log(patient);
342
+ * ```
343
+ *
344
+ * The return value is the resource, if available; otherwise, undefined.
345
+ *
346
+ * See FHIR search for full details: https://www.hl7.org/fhir/search.html
347
+ *
348
+ * @param query The search query as either a string or a structured search object.
349
+ * @returns Promise to the search result bundle.
350
+ */
351
+ searchOne<T extends Resource>(query: string | SearchRequest, options?: RequestInit): Promise<T | undefined>;
352
+ /**
353
+ * Sends a FHIR search request for an array of resources.
354
+ *
355
+ * This is a convenience method for `search()` that returns the resources as an array rather than a `Bundle`.
356
+ *
357
+ * Example using a FHIR search string:
358
+ *
359
+ * ```typescript
360
+ * const patients = await client.searchResources('Patient?name=Alice');
361
+ * console.log(patients);
362
+ * ```
363
+ *
364
+ * The return value is an array of resources.
365
+ *
366
+ * See FHIR search for full details: https://www.hl7.org/fhir/search.html
367
+ *
368
+ * @param query The search query as either a string or a structured search object.
369
+ * @returns Promise to the search result bundle.
370
+ */
371
+ searchResources<T extends Resource>(query: string | SearchRequest, options?: RequestInit): Promise<T[]>;
372
+ /**
373
+ * Searches a ValueSet resource using the "expand" operation.
374
+ * See: https://www.hl7.org/fhir/operation-valueset-expand.html
375
+ * @param system The ValueSet system url.
376
+ * @param filter The search string.
377
+ * @returns Promise to expanded ValueSet.
378
+ */
379
+ searchValueSet(system: string, filter: string, options?: RequestInit): Promise<ValueSet>;
380
+ /**
381
+ * Returns a cached resource if it is available.
382
+ * @param resourceType The FHIR resource type.
383
+ * @param id The FHIR resource ID.
384
+ * @returns The resource if it is available in the cache; undefined otherwise.
385
+ */
386
+ getCached<T extends Resource>(resourceType: string, id: string): T | undefined;
387
+ /**
388
+ * Returns a cached resource if it is available.
389
+ * @param resourceType The FHIR resource type.
390
+ * @param id The FHIR resource ID.
391
+ * @returns The resource if it is available in the cache; undefined otherwise.
392
+ */
393
+ getCachedReference<T extends Resource>(reference: Reference<T>): T | undefined;
394
+ /**
395
+ * Reads a resource by resource type and ID.
396
+ *
397
+ * Example:
398
+ *
399
+ * ```typescript
400
+ * const patient = await medplum.readResource('Patient', '123');
401
+ * console.log(patient);
402
+ * ```
403
+ *
404
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
405
+ *
406
+ * @param resourceType The FHIR resource type.
407
+ * @param id The resource ID.
408
+ * @returns The resource if available; undefined otherwise.
409
+ */
410
+ readResource<T extends Resource>(resourceType: string, id: string): ReadablePromise<T>;
411
+ /**
412
+ * Reads a resource by resource type and ID using the in-memory resource cache.
413
+ *
414
+ * If the resource is not available in the cache, it will be read from the server.
415
+ *
416
+ * Example:
417
+ *
418
+ * ```typescript
419
+ * const patient = await medplum.readCached('Patient', '123');
420
+ * console.log(patient);
421
+ * ```
422
+ *
423
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
424
+ *
425
+ * @param resourceType The FHIR resource type.
426
+ * @param id The resource ID.
427
+ * @returns The resource if available; undefined otherwise.
428
+ */
429
+ readCached<T extends Resource>(resourceType: string, id: string): ReadablePromise<T>;
430
+ /**
431
+ * Reads a resource by `Reference`.
432
+ *
433
+ * This is a convenience method for `readResource()` that accepts a `Reference` object.
434
+ *
435
+ * Example:
436
+ *
437
+ * ```typescript
438
+ * const serviceRequest = await medplum.readResource('ServiceRequest', '123');
439
+ * const patient = await medplum.readReference(serviceRequest.subject);
440
+ * console.log(patient);
441
+ * ```
442
+ *
443
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
444
+ *
445
+ * @param reference The FHIR reference object.
446
+ * @returns The resource if available; undefined otherwise.
447
+ */
448
+ readReference<T extends Resource>(reference: Reference<T>): ReadablePromise<T>;
449
+ /**
450
+ * Reads a resource by `Reference` using the in-memory resource cache.
451
+ *
452
+ * This is a convenience method for `readResource()` that accepts a `Reference` object.
453
+ *
454
+ * If the resource is not available in the cache, it will be read from the server.
455
+ *
456
+ * Example:
457
+ *
458
+ * ```typescript
459
+ * const serviceRequest = await medplum.readResource('ServiceRequest', '123');
460
+ * const patient = await medplum.readCachedReference(serviceRequest.subject);
461
+ * console.log(patient);
462
+ * ```
463
+ *
464
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
465
+ *
466
+ * @param reference The FHIR reference object.
467
+ * @returns The resource if available; undefined otherwise.
468
+ */
469
+ readCachedReference<T extends Resource>(reference: Reference<T>): ReadablePromise<T>;
470
+ /**
471
+ * Returns a cached schema for a resource type.
472
+ * If the schema is not cached, returns undefined.
473
+ * It is assumed that a client will call requestSchema before using this method.
474
+ * @param resourceType The FHIR resource type.
475
+ * @returns The schema if immediately available, undefined otherwise.
476
+ */
477
+ getSchema(): IndexedStructureDefinition;
478
+ /**
479
+ * Requests the schema for a resource type.
480
+ * If the schema is already cached, the promise is resolved immediately.
481
+ * @param resourceType The FHIR resource type.
482
+ * @returns Promise to a schema with the requested resource type.
483
+ */
484
+ requestSchema(resourceType: string): Promise<IndexedStructureDefinition>;
485
+ /**
486
+ * Reads resource history by resource type and ID.
487
+ *
488
+ * The return value is a bundle of all versions of the resource.
489
+ *
490
+ * Example:
491
+ *
492
+ * ```typescript
493
+ * const history = await medplum.readHistory('Patient', '123');
494
+ * console.log(history);
495
+ * ```
496
+ *
497
+ * See the FHIR "history" operation for full details: https://www.hl7.org/fhir/http.html#history
498
+ *
499
+ * @param resourceType The FHIR resource type.
500
+ * @param id The resource ID.
501
+ * @returns The resource if available; undefined otherwise.
502
+ */
503
+ readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>;
504
+ /**
505
+ * Reads a specific version of a resource by resource type, ID, and version ID.
506
+ *
507
+ * Example:
508
+ *
509
+ * ```typescript
510
+ * const version = await medplum.readVersion('Patient', '123', '456');
511
+ * console.log(version);
512
+ * ```
513
+ *
514
+ * See the FHIR "vread" operation for full details: https://www.hl7.org/fhir/http.html#vread
515
+ *
516
+ * @param resourceType The FHIR resource type.
517
+ * @param id The resource ID.
518
+ * @returns The resource if available; undefined otherwise.
519
+ */
520
+ readVersion<T extends Resource>(resourceType: string, id: string, vid: string): Promise<T>;
521
+ readPatientEverything(id: string): Promise<Bundle>;
522
+ /**
523
+ * Creates a new FHIR resource.
524
+ *
525
+ * The return value is the newly created resource, including the ID and meta.
526
+ *
527
+ * Example:
528
+ *
529
+ * ```typescript
530
+ * const result = await medplum.createResource({
531
+ * resourceType: 'Patient',
532
+ * name: [{
533
+ * family: 'Smith',
534
+ * given: ['John']
535
+ * }]
536
+ * });
537
+ * console.log(result.id);
538
+ * ```
539
+ *
540
+ * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
541
+ *
542
+ * @param resource The FHIR resource to create.
543
+ * @returns The result of the create operation.
544
+ */
545
+ createResource<T extends Resource>(resource: T): Promise<T>;
546
+ /**
547
+ * Conditionally create a new FHIR resource only if some equivalent resource does not already exist on the server.
548
+ *
549
+ * The return value is the existing resource or the newly created resource, including the ID and meta.
550
+ *
551
+ * Example:
552
+ *
553
+ * ```typescript
554
+ * const result = await medplum.createResourceIfNoneExist(
555
+ * 'Patient?identifier=123',
556
+ * {
557
+ * resourceType: 'Patient',
558
+ * identifier: [{
559
+ * system: 'http://example.com/mrn',
560
+ * value: '123'
561
+ * }]
562
+ * name: [{
563
+ * family: 'Smith',
564
+ * given: ['John']
565
+ * }]
566
+ * });
567
+ * console.log(result.id);
568
+ * ```
569
+ *
570
+ * This method is syntactic sugar for:
571
+ *
572
+ * ```typescript
573
+ * return searchOne(query) ?? createResource(resource);
574
+ * ```
575
+ *
576
+ * The query parameter only contains the search parameters (what would be in the URL following the "?").
577
+ *
578
+ * See the FHIR "conditional create" operation for full details: https://www.hl7.org/fhir/http.html#ccreate
579
+ *
580
+ * @param resource The FHIR resource to create.
581
+ * @param query The search query for an equivalent resource.
582
+ * @returns The result of the create operation.
583
+ */
584
+ createResourceIfNoneExist<T extends Resource>(resource: T, query: string): Promise<T>;
585
+ /**
586
+ * Creates a FHIR `Binary` resource with the provided data content.
587
+ *
588
+ * The return value is the newly created resource, including the ID and meta.
589
+ *
590
+ * The `data` parameter can be a string or a `File` object.
591
+ *
592
+ * A `File` object often comes from a `<input type="file">` element.
593
+ *
594
+ * Example:
595
+ *
596
+ * ```typescript
597
+ * const result = await medplum.createBinary(myFile, 'test.jpg', 'image/jpeg');
598
+ * console.log(result.id);
599
+ * ```
600
+ *
601
+ * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
602
+ *
603
+ * @param data The binary data to upload.
604
+ * @param filename Optional filename for the binary.
605
+ * @param contentType Content type for the binary.
606
+ * @returns The result of the create operation.
607
+ */
608
+ createBinary(data: string | File, filename: string | undefined, contentType: string): Promise<Binary>;
609
+ /**
610
+ * Creates a PDF as a FHIR `Binary` resource based on pdfmake document definition.
611
+ *
612
+ * The return value is the newly created resource, including the ID and meta.
613
+ *
614
+ * The `docDefinition` parameter is a pdfmake document definition.
615
+ *
616
+ * Example:
617
+ *
618
+ * ```typescript
619
+ * const result = await medplum.createPdf({
620
+ * content: ['Hello world']
621
+ * });
622
+ * console.log(result.id);
623
+ * ```
624
+ *
625
+ * See the pdfmake document definition for full details: https://pdfmake.github.io/docs/0.1/document-definition-object/
626
+ *
627
+ * @param docDefinition The FHIR resource to create.
628
+ * @returns The result of the create operation.
629
+ */
630
+ createPdf(docDefinition: Record<string, unknown>, filename?: string): Promise<Binary>;
631
+ /**
632
+ * Updates a FHIR resource.
633
+ *
634
+ * The return value is the updated resource, including the ID and meta.
635
+ *
636
+ * Example:
637
+ *
638
+ * ```typescript
639
+ * const result = await medplum.updateResource({
640
+ * resourceType: 'Patient',
641
+ * id: '123',
642
+ * name: [{
643
+ * family: 'Smith',
644
+ * given: ['John']
645
+ * }]
646
+ * });
647
+ * console.log(result.meta.versionId);
648
+ * ```
649
+ *
650
+ * See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#update
651
+ *
652
+ * @param resource The FHIR resource to update.
653
+ * @returns The result of the update operation.
654
+ */
655
+ updateResource<T extends Resource>(resource: T): Promise<T>;
656
+ /**
657
+ * Updates a FHIR resource using JSONPatch operations.
658
+ *
659
+ * The return value is the updated resource, including the ID and meta.
660
+ *
661
+ * Example:
662
+ *
663
+ * ```typescript
664
+ * const result = await medplum.patchResource('Patient', '123', [
665
+ * {op: 'replace', path: '/name/0/family', value: 'Smith'},
666
+ * ]);
667
+ * console.log(result.meta.versionId);
668
+ * ```
669
+ *
670
+ * See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#patch
671
+ *
672
+ * See the JSONPatch specification for full details: https://tools.ietf.org/html/rfc6902
673
+ *
674
+ * @param resourceType The FHIR resource type.
675
+ * @param id The resource ID.
676
+ * @param operations The JSONPatch operations.
677
+ * @returns The result of the patch operations.
678
+ */
679
+ patchResource<T extends Resource>(resourceType: string, id: string, operations: Operation[]): Promise<T>;
680
+ /**
681
+ * Deletes a FHIR resource by resource type and ID.
682
+ *
683
+ * Example:
684
+ *
685
+ * ```typescript
686
+ * await medplum.deleteResource('Patient', '123');
687
+ * ```
688
+ *
689
+ * See the FHIR "delete" operation for full details: https://www.hl7.org/fhir/http.html#delete
690
+ *
691
+ * @param resourceType The FHIR resource type.
692
+ * @param id The resource ID.
693
+ * @returns The result of the delete operation.
694
+ */
695
+ deleteResource(resourceType: string, id: string): Promise<any>;
696
+ /**
697
+ * Sends an email using the Medplum Email API.
698
+ *
699
+ * Builds the email using nodemailer MailComposer.
700
+ *
701
+ * Examples:
702
+ *
703
+ * Send a simple text email:
704
+ *
705
+ * ```typescript
706
+ * await medplum.sendEmail({
707
+ * to: 'alice@example.com',
708
+ * cc: 'bob@example.com',
709
+ * subject: 'Hello',
710
+ * text: 'Hello Alice',
711
+ * });
712
+ * ```
713
+ *
714
+ * Send an email with a `Binary` attachment:
715
+ *
716
+ * ```typescript
717
+ * await medplum.sendEmail({
718
+ * to: 'alice@example.com',
719
+ * subject: 'Email with attachment',
720
+ * text: 'See the attached report',
721
+ * attachments: [{
722
+ * filename: 'report.pdf',
723
+ * path: "Binary/" + binary.id
724
+ * }]
725
+ * });
726
+ * ```
727
+ *
728
+ * See options here: https://nodemailer.com/extras/mailcomposer/
729
+ *
730
+ * @param options The MailComposer options.
731
+ * @returns Promise to the operation outcome.
732
+ */
733
+ sendEmail(email: Mail.Options): Promise<OperationOutcome>;
734
+ graphql(query: string, options?: RequestInit): Promise<any>;
735
+ getActiveLogin(): LoginState | undefined;
736
+ setActiveLogin(login: LoginState): Promise<void>;
737
+ setAccessToken(accessToken: string): void;
738
+ getLogins(): LoginState[];
739
+ isLoading(): boolean;
740
+ getProfile(): ProfileResource | undefined;
741
+ getProfileAsync(): Promise<ProfileResource | undefined>;
742
+ getUserConfiguration(): UserConfiguration | undefined;
743
+ /**
744
+ * Downloads the URL as a blob.
745
+ * @param url The URL to request.
746
+ * @returns Promise to the response body as a blob.
747
+ */
748
+ download(url: string, options?: RequestInit): Promise<Blob>;
749
+ /**
750
+ * Processes an OAuth authorization code.
751
+ * See: https://openid.net/specs/openid-connect-core-1_0.html#TokenRequest
752
+ * @param code The authorization code received by URL parameter.
753
+ */
754
+ processCode(code: string): Promise<ProfileResource>;
755
+ clientCredentials(clientId: string, clientSecret: string): Promise<ProfileResource>;
756
+ }