@medplum/core 0.9.28 → 0.9.29

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 (40) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/cache.d.ts +34 -0
  3. package/dist/cjs/client.d.ts +1094 -0
  4. package/dist/cjs/crypto.d.ts +9 -0
  5. package/dist/cjs/eventtarget.d.ts +13 -0
  6. package/dist/cjs/fhirpath/atoms.d.ts +150 -0
  7. package/dist/cjs/fhirpath/date.d.ts +1 -0
  8. package/dist/cjs/fhirpath/functions.d.ts +5 -0
  9. package/dist/cjs/fhirpath/index.d.ts +4 -0
  10. package/dist/cjs/fhirpath/parse.d.ts +24 -0
  11. package/dist/cjs/fhirpath/tokenize.d.ts +5 -0
  12. package/dist/cjs/fhirpath/utils.d.ts +95 -0
  13. package/dist/cjs/format.d.ts +21 -0
  14. package/dist/cjs/hl7.d.ts +43 -0
  15. package/dist/cjs/index.d.ts +12 -0
  16. package/dist/cjs/index.js +82 -39
  17. package/dist/cjs/index.js.map +1 -1
  18. package/dist/cjs/index.min.js +1 -1
  19. package/dist/cjs/index.min.js.map +1 -1
  20. package/dist/cjs/jwt.d.ts +5 -0
  21. package/dist/cjs/outcomes.d.ts +30 -0
  22. package/dist/cjs/readablepromise.d.ts +48 -0
  23. package/dist/cjs/search.d.ts +64 -0
  24. package/dist/cjs/searchparams.d.ts +35 -0
  25. package/dist/cjs/storage.d.ts +47 -0
  26. package/dist/cjs/types.d.ts +148 -0
  27. package/dist/cjs/utils.d.ts +239 -0
  28. package/dist/esm/client.d.ts +8 -7
  29. package/dist/esm/client.js +36 -29
  30. package/dist/esm/client.js.map +1 -1
  31. package/dist/esm/index.js +2 -2
  32. package/dist/esm/index.min.js +1 -1
  33. package/dist/esm/index.min.js.map +1 -1
  34. package/dist/esm/outcomes.d.ts +2 -1
  35. package/dist/esm/outcomes.js +27 -10
  36. package/dist/esm/outcomes.js.map +1 -1
  37. package/dist/esm/utils.d.ts +15 -0
  38. package/dist/esm/utils.js +18 -1
  39. package/dist/esm/utils.js.map +1 -1
  40. package/package.json +3 -3
@@ -0,0 +1,1094 @@
1
+ import { Binary, Bundle, Communication, ExtractResource, OperationOutcome, Project, ProjectMembership, Reference, Resource, ResourceType, UserConfiguration, ValueSet } from '@medplum/fhirtypes';
2
+ /** @ts-ignore */
3
+ import type { CustomTableLayout, TDocumentDefinitions, TFontDictionary } from 'pdfmake/interfaces';
4
+ import { EventTarget } from './eventtarget';
5
+ import { Hl7Message } from './hl7';
6
+ import { ReadablePromise } from './readablepromise';
7
+ import { IndexedStructureDefinition } from './types';
8
+ import { ProfileResource } from './utils';
9
+ /**
10
+ * The MedplumClientOptions interface defines configuration options for MedplumClient.
11
+ *
12
+ * All configuration settings are optional.
13
+ */
14
+ export interface MedplumClientOptions {
15
+ /**
16
+ * Base server URL.
17
+ *
18
+ * Default value is https://api.medplum.com/
19
+ *
20
+ * Use this to point to a custom Medplum deployment.
21
+ */
22
+ baseUrl?: string;
23
+ /**
24
+ * OAuth2 authorize URL.
25
+ *
26
+ * Default value is baseUrl + "/oauth2/authorize".
27
+ *
28
+ * Use this if you want to use a separate OAuth server.
29
+ */
30
+ authorizeUrl?: string;
31
+ /**
32
+ * OAuth2 token URL.
33
+ *
34
+ * Default value is baseUrl + "/oauth2/token".
35
+ *
36
+ * Use this if you want to use a separate OAuth server.
37
+ */
38
+ tokenUrl?: string;
39
+ /**
40
+ * OAuth2 logout URL.
41
+ *
42
+ * Default value is baseUrl + "/oauth2/logout".
43
+ *
44
+ * Use this if you want to use a separate OAuth server.
45
+ */
46
+ logoutUrl?: string;
47
+ /**
48
+ * The client ID.
49
+ *
50
+ * Client ID can be used for SMART-on-FHIR customization.
51
+ */
52
+ clientId?: string;
53
+ /**
54
+ * Number of resources to store in the cache.
55
+ *
56
+ * Default value is 1000.
57
+ *
58
+ * Consider using this for performance of displaying Patient or Practitioner resources.
59
+ */
60
+ resourceCacheSize?: number;
61
+ /**
62
+ * The length of time in milliseconds to cache resources.
63
+ *
64
+ * Default value is 10000 (10 seconds).
65
+ *
66
+ * Cache time of zero disables all caching.
67
+ *
68
+ * For any individual request, the cache behavior can be overridden by setting the cache property on request options.
69
+ *
70
+ * See: https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
71
+ */
72
+ cacheTime?: number;
73
+ /**
74
+ * Fetch implementation.
75
+ *
76
+ * Default is window.fetch (if available).
77
+ *
78
+ * For nodejs applications, consider the 'node-fetch' package.
79
+ */
80
+ fetch?: FetchLike;
81
+ /**
82
+ * Create PDF implementation.
83
+ *
84
+ * Default is none, and PDF generation is disabled.
85
+ *
86
+ * In browser environments, import the client-side pdfmake library.
87
+ *
88
+ * ```html
89
+ * <script src="pdfmake.min.js"></script>
90
+ * <script>
91
+ * async function createPdf(docDefinition, tableLayouts, fonts) {
92
+ * return new Promise((resolve) => {
93
+ * pdfMake.createPdf(docDefinition, tableLayouts, fonts).getBlob(resolve);
94
+ * });
95
+ * }
96
+ * </script>
97
+ * ```
98
+ *
99
+ * In nodejs applications:
100
+ *
101
+ * ```ts
102
+ * import type { CustomTableLayout, TDocumentDefinitions, TFontDictionary } from 'pdfmake/interfaces';
103
+ * function createPdf(
104
+ * docDefinition: TDocumentDefinitions,
105
+ * tableLayouts?: { [name: string]: CustomTableLayout },
106
+ * fonts?: TFontDictionary
107
+ * ): Promise<Buffer> {
108
+ * return new Promise((resolve, reject) => {
109
+ * const printer = new PdfPrinter(fonts || {});
110
+ * const pdfDoc = printer.createPdfKitDocument(docDefinition, { tableLayouts });
111
+ * const chunks: Uint8Array[] = [];
112
+ * pdfDoc.on('data', (chunk: Uint8Array) => chunks.push(chunk));
113
+ * pdfDoc.on('end', () => resolve(Buffer.concat(chunks)));
114
+ * pdfDoc.on('error', reject);
115
+ * pdfDoc.end();
116
+ * });
117
+ * }
118
+ * ```
119
+ */
120
+ createPdf?: CreatePdfFunction;
121
+ /**
122
+ * Callback for when the client is unauthenticated.
123
+ *
124
+ * Default is do nothing.
125
+ *
126
+ * For client side applications, consider redirecting to a sign in page.
127
+ */
128
+ onUnauthenticated?: () => void;
129
+ }
130
+ export interface FetchLike {
131
+ (url: string, options?: any): Promise<any>;
132
+ }
133
+ export interface CreatePdfFunction {
134
+ (docDefinition: TDocumentDefinitions, tableLayouts?: {
135
+ [name: string]: CustomTableLayout;
136
+ } | undefined, fonts?: TFontDictionary | undefined): Promise<any>;
137
+ }
138
+ export interface LoginRequest {
139
+ readonly email: string;
140
+ readonly password: string;
141
+ readonly remember?: boolean;
142
+ readonly projectId?: string;
143
+ readonly clientId?: string;
144
+ readonly scope?: string;
145
+ readonly nonce?: string;
146
+ }
147
+ export interface NewUserRequest {
148
+ readonly email: string;
149
+ readonly password: string;
150
+ readonly recaptchaToken: string;
151
+ readonly recaptchaSiteKey?: string;
152
+ readonly remember?: boolean;
153
+ }
154
+ export interface NewProjectRequest {
155
+ readonly projectName: string;
156
+ readonly firstName: string;
157
+ readonly lastName: string;
158
+ }
159
+ export interface NewPatientRequest {
160
+ readonly projectId: string;
161
+ readonly firstName: string;
162
+ readonly lastName: string;
163
+ }
164
+ export interface GoogleCredentialResponse {
165
+ readonly clientId: string;
166
+ readonly credential: string;
167
+ }
168
+ export interface GoogleLoginRequest {
169
+ readonly googleClientId: string;
170
+ readonly googleCredential: string;
171
+ readonly clientId?: string;
172
+ readonly scope?: string;
173
+ readonly nonce?: string;
174
+ }
175
+ export interface LoginAuthenticationResponse {
176
+ readonly login: string;
177
+ readonly code?: string;
178
+ readonly memberships?: ProjectMembership[];
179
+ }
180
+ export interface LoginProfileResponse {
181
+ readonly login: string;
182
+ readonly scope: string;
183
+ }
184
+ export interface LoginScopeResponse {
185
+ readonly login: string;
186
+ readonly code: string;
187
+ }
188
+ export interface LoginState {
189
+ readonly project: Reference<Project>;
190
+ readonly profile: Reference<ProfileResource>;
191
+ readonly accessToken: string;
192
+ readonly refreshToken: string;
193
+ }
194
+ export interface TokenResponse {
195
+ readonly token_type: string;
196
+ readonly id_token: string;
197
+ readonly access_token: string;
198
+ readonly refresh_token: string;
199
+ readonly expires_in: number;
200
+ readonly project: Reference<Project>;
201
+ readonly profile: Reference<ProfileResource>;
202
+ }
203
+ export interface BotEvent {
204
+ readonly contentType: string;
205
+ readonly input: Resource | Hl7Message | string;
206
+ }
207
+ /**
208
+ * JSONPatch patch operation.
209
+ * Compatible with fast-json-patch Operation.
210
+ */
211
+ export interface PatchOperation {
212
+ readonly op: 'add' | 'remove' | 'replace' | 'copy' | 'move' | 'test';
213
+ readonly path: string;
214
+ readonly value?: any;
215
+ }
216
+ /**
217
+ * Email address definition.
218
+ * Compatible with nodemailer Mail.Address.
219
+ */
220
+ export interface MailAddress {
221
+ readonly name: string;
222
+ readonly address: string;
223
+ }
224
+ /**
225
+ * Email attachment definition.
226
+ * Compatible with nodemailer Mail.Options.
227
+ */
228
+ export interface MailAttachment {
229
+ /** String, Buffer or a Stream contents for the attachmentent */
230
+ readonly content?: string;
231
+ /** path to a file or an URL (data uris are allowed as well) if you want to stream the file instead of including it (better for larger attachments) */
232
+ readonly path?: string;
233
+ /** filename to be reported as the name of the attached file, use of unicode is allowed. If you do not want to use a filename, set this value as false, otherwise a filename is generated automatically */
234
+ readonly filename?: string | false;
235
+ /** optional content type for the attachment, if not set will be derived from the filename property */
236
+ readonly contentType?: string;
237
+ }
238
+ /**
239
+ * Email message definition.
240
+ * Compatible with nodemailer Mail.Options.
241
+ */
242
+ export interface MailOptions {
243
+ /** The e-mail address of the sender. All e-mail addresses can be plain 'sender@server.com' or formatted 'Sender Name <sender@server.com>' */
244
+ readonly from?: string | MailAddress;
245
+ /** An e-mail address that will appear on the Sender: field */
246
+ readonly sender?: string | MailAddress;
247
+ /** Comma separated list or an array of recipients e-mail addresses that will appear on the To: field */
248
+ readonly to?: string | MailAddress | string[] | MailAddress[];
249
+ /** Comma separated list or an array of recipients e-mail addresses that will appear on the Cc: field */
250
+ readonly cc?: string | MailAddress | string[] | MailAddress[];
251
+ /** Comma separated list or an array of recipients e-mail addresses that will appear on the Bcc: field */
252
+ readonly bcc?: string | MailAddress | string[] | MailAddress[];
253
+ /** An e-mail address that will appear on the Reply-To: field */
254
+ readonly replyTo?: string | MailAddress;
255
+ /** The subject of the e-mail */
256
+ readonly subject?: string;
257
+ /** The plaintext version of the message */
258
+ readonly text?: string;
259
+ /** The HTML version of the message */
260
+ readonly html?: string;
261
+ /** An array of attachment objects */
262
+ readonly attachments?: MailAttachment[];
263
+ }
264
+ /**
265
+ * The MedplumClient class provides a client for the Medplum FHIR server.
266
+ *
267
+ * The client can be used in the browser, in a NodeJS application, or in a Medplum Bot.
268
+ *
269
+ * The client provides helpful methods for common operations such as:
270
+ * 1) Authenticating
271
+ * 2) Creating resources
272
+ * 2) Reading resources
273
+ * 3) Updating resources
274
+ * 5) Deleting resources
275
+ * 6) Searching
276
+ * 7) Making GraphQL queries
277
+ *
278
+ * Here is a quick example of how to use the client:
279
+ *
280
+ * ```typescript
281
+ * import { MedplumClient } from '@medplum/core';
282
+ * const medplum = new MedplumClient();
283
+ * ```
284
+ *
285
+ * Create a `Patient`:
286
+ *
287
+ * ```typescript
288
+ * const patient = await medplum.createResource({
289
+ * resourceType: 'Patient',
290
+ * name: [{
291
+ * given: ['Alice'],
292
+ * family: 'Smith'
293
+ * }]
294
+ * });
295
+ * ```
296
+ *
297
+ * Read a `Patient` by ID:
298
+ *
299
+ * ```typescript
300
+ * const patient = await medplum.readResource('Patient', '123');
301
+ * console.log(patient.name[0].given[0]);
302
+ * ```
303
+ *
304
+ * Search for a `Patient` by name:
305
+ *
306
+ * ```typescript
307
+ * const bundle = await medplum.search('Patient', 'name=Alice');
308
+ * console.log(bundle.total);
309
+ * ```
310
+ */
311
+ export declare class MedplumClient extends EventTarget {
312
+ #private;
313
+ constructor(options?: MedplumClientOptions);
314
+ /**
315
+ * Returns the current base URL for all API requests.
316
+ * By default, this is set to `https://api.medplum.com/`.
317
+ * This can be overridden by setting the `baseUrl` option when creating the client.
318
+ * @category HTTP
319
+ * @returns The current base URL for all API requests.
320
+ */
321
+ getBaseUrl(): string;
322
+ /**
323
+ * Clears all auth state including local storage and session storage.
324
+ * @category Authentication
325
+ */
326
+ clear(): void;
327
+ /**
328
+ * Invalidates any cached values or cached requests for the given URL.
329
+ * @category Caching
330
+ * @param url The URL to invalidate.
331
+ */
332
+ invalidateUrl(url: URL | string): void;
333
+ /**
334
+ * Invalidates all cached search results or cached requests for the given resourceType.
335
+ * @category Caching
336
+ * @param resourceType The resource type to invalidate.
337
+ */
338
+ invalidateSearches<K extends ResourceType>(resourceType: K): void;
339
+ /**
340
+ * Makes an HTTP GET request to the specified URL.
341
+ *
342
+ * This is a lower level method for custom requests.
343
+ * For common operations, we recommend using higher level methods
344
+ * such as `readResource()`, `search()`, etc.
345
+ *
346
+ * @category HTTP
347
+ * @param url The target URL.
348
+ * @param options Optional fetch options.
349
+ * @returns Promise to the response content.
350
+ */
351
+ get<T = any>(url: URL | string, options?: RequestInit): ReadablePromise<T>;
352
+ /**
353
+ * Makes an HTTP POST request to the specified URL.
354
+ *
355
+ * This is a lower level method for custom requests.
356
+ * For common operations, we recommend using higher level methods
357
+ * such as `createResource()`.
358
+ *
359
+ * @category HTTP
360
+ * @param url The target URL.
361
+ * @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
362
+ * @param contentType The content type to be included in the "Content-Type" header.
363
+ * @param options Optional fetch options.
364
+ * @returns Promise to the response content.
365
+ */
366
+ post(url: URL | string, body: any, contentType?: string, options?: RequestInit): Promise<any>;
367
+ /**
368
+ * Makes an HTTP PUT request to the specified URL.
369
+ *
370
+ * This is a lower level method for custom requests.
371
+ * For common operations, we recommend using higher level methods
372
+ * such as `updateResource()`.
373
+ *
374
+ * @category HTTP
375
+ * @param url The target URL.
376
+ * @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
377
+ * @param contentType The content type to be included in the "Content-Type" header.
378
+ * @param options Optional fetch options.
379
+ * @returns Promise to the response content.
380
+ */
381
+ put(url: URL | string, body: any, contentType?: string, options?: RequestInit): Promise<any>;
382
+ /**
383
+ * Makes an HTTP PATCH request to the specified URL.
384
+ *
385
+ * This is a lower level method for custom requests.
386
+ * For common operations, we recommend using higher level methods
387
+ * such as `patchResource()`.
388
+ *
389
+ * @category HTTP
390
+ * @param url The target URL.
391
+ * @param operations Array of JSONPatch operations.
392
+ * @param options Optional fetch options.
393
+ * @returns Promise to the response content.
394
+ */
395
+ patch(url: URL | string, operations: PatchOperation[], options?: RequestInit): Promise<any>;
396
+ /**
397
+ * Makes an HTTP DELETE request to the specified URL.
398
+ *
399
+ *
400
+ * This is a lower level method for custom requests.
401
+ * For common operations, we recommend using higher level methods
402
+ * such as `deleteResource()`.
403
+ *
404
+ * @category HTTP
405
+ * @param url The target URL.
406
+ * @param options Optional fetch options.
407
+ * @returns Promise to the response content.
408
+ */
409
+ delete(url: URL | string, options?: RequestInit): Promise<any>;
410
+ /**
411
+ * Initiates a new user flow.
412
+ *
413
+ * This method is part of the two different user registration flows:
414
+ * 1) New Practitioner and new Project
415
+ * 2) New Patient registration
416
+ *
417
+ * @category Authentication
418
+ * @param newUserRequest Register request including email and password.
419
+ * @returns Promise to the authentication response.
420
+ */
421
+ startNewUser(newUserRequest: NewUserRequest): Promise<LoginAuthenticationResponse>;
422
+ /**
423
+ * Initiates a new project flow.
424
+ *
425
+ * This requires a partial login from `startNewUser` or `startNewGoogleUser`.
426
+ *
427
+ * @param newProjectRequest Register request including email and password.
428
+ * @param login The partial login to complete. This should come from the `startNewUser` method.
429
+ * @returns Promise to the authentication response.
430
+ */
431
+ startNewProject(newProjectRequest: NewProjectRequest, login: LoginAuthenticationResponse): Promise<LoginAuthenticationResponse>;
432
+ /**
433
+ * Initiates a new patient flow.
434
+ *
435
+ * This requires a partial login from `startNewUser` or `startNewGoogleUser`.
436
+ *
437
+ * @param newPatientRequest Register request including email and password.
438
+ * @param login The partial login to complete. This should come from the `startNewUser` method.
439
+ * @returns Promise to the authentication response.
440
+ */
441
+ startNewPatient(newPatientRequest: NewPatientRequest, login: LoginAuthenticationResponse): Promise<LoginAuthenticationResponse>;
442
+ /**
443
+ * Initiates a user login flow.
444
+ * @category Authentication
445
+ * @param loginRequest Login request including email and password.
446
+ * @returns Promise to the authentication response.
447
+ */
448
+ startLogin(loginRequest: LoginRequest): Promise<LoginAuthenticationResponse>;
449
+ /**
450
+ * Tries to sign in with Google authentication.
451
+ * The response parameter is the result of a Google authentication.
452
+ * See: https://developers.google.com/identity/gsi/web/guides/handle-credential-responses-js-functions
453
+ * @category Authentication
454
+ * @param loginRequest Login request including Google credential response.
455
+ * @returns Promise to the authentication response.
456
+ */
457
+ startGoogleLogin(loginRequest: GoogleLoginRequest): Promise<LoginAuthenticationResponse>;
458
+ /**
459
+ * Signs out locally.
460
+ * Does not invalidate tokens with the server.
461
+ * @category Authentication
462
+ */
463
+ signOut(): void;
464
+ /**
465
+ * Tries to sign in the user.
466
+ * Returns true if the user is signed in.
467
+ * This may result in navigating away to the sign in page.
468
+ * @category Authentication
469
+ */
470
+ signInWithRedirect(): Promise<ProfileResource | void>;
471
+ /**
472
+ * Tries to sign out the user.
473
+ * See: https://docs.aws.amazon.com/cognito/latest/developerguide/logout-endpoint.html
474
+ * @category Authentication
475
+ */
476
+ signOutWithRedirect(): void;
477
+ /**
478
+ * Builds a FHIR URL from a collection of URL path components.
479
+ * For example, `buildUrl('/Patient', '123')` returns `fhir/R4/Patient/123`.
480
+ * @category HTTP
481
+ * @param path The path component of the URL.
482
+ * @returns The well-formed FHIR URL.
483
+ */
484
+ fhirUrl(...path: string[]): URL;
485
+ /**
486
+ * Builds a FHIR search URL from a search query or structured query object.
487
+ * @category HTTP
488
+ * @category Search
489
+ * @param query The FHIR search query or structured query object.
490
+ * @returns The well-formed FHIR URL.
491
+ */
492
+ fhirSearchUrl(resourceType: ResourceType, query: URLSearchParams | string | undefined): URL;
493
+ /**
494
+ * Sends a FHIR search request.
495
+ *
496
+ * Example using a FHIR search string:
497
+ *
498
+ * ```typescript
499
+ * const bundle = await client.search('Patient', 'name=Alice');
500
+ * console.log(bundle);
501
+ * ```
502
+ *
503
+ * The return value is a FHIR bundle:
504
+ *
505
+ * ```json
506
+ * {
507
+ * "resourceType": "Bundle",
508
+ * "type": "searchest",
509
+ * "total": 1,
510
+ * "entry": [
511
+ * {
512
+ * "resource": {
513
+ * "resourceType": "Patient",
514
+ * "name": [
515
+ * {
516
+ * "given": [
517
+ * "George"
518
+ * ],
519
+ * "family": "Washington"
520
+ * }
521
+ * ],
522
+ * }
523
+ * }
524
+ * ]
525
+ * }
526
+ * ```
527
+ *
528
+ * See FHIR search for full details: https://www.hl7.org/fhir/search.html
529
+ *
530
+ * @category Search
531
+ * @param query The search query as either a string or a structured search object.
532
+ * @returns Promise to the search result bundle.
533
+ */
534
+ search<K extends ResourceType>(resourceType: K, query?: URLSearchParams | string, options?: RequestInit): ReadablePromise<Bundle<ExtractResource<K>>>;
535
+ /**
536
+ * Sends a FHIR search request for a single resource.
537
+ *
538
+ * This is a convenience method for `search()` that returns the first resource rather than a `Bundle`.
539
+ *
540
+ * Example using a FHIR search string:
541
+ *
542
+ * ```typescript
543
+ * const patient = await client.searchOne('Patient', 'identifier=123');
544
+ * console.log(patient);
545
+ * ```
546
+ *
547
+ * The return value is the resource, if available; otherwise, undefined.
548
+ *
549
+ * See FHIR search for full details: https://www.hl7.org/fhir/search.html
550
+ *
551
+ * @category Search
552
+ * @param query The search query as either a string or a structured search object.
553
+ * @returns Promise to the search result bundle.
554
+ */
555
+ searchOne<K extends ResourceType>(resourceType: K, query?: URLSearchParams | string, options?: RequestInit): ReadablePromise<ExtractResource<K> | undefined>;
556
+ /**
557
+ * Sends a FHIR search request for an array of resources.
558
+ *
559
+ * This is a convenience method for `search()` that returns the resources as an array rather than a `Bundle`.
560
+ *
561
+ * Example using a FHIR search string:
562
+ *
563
+ * ```typescript
564
+ * const patients = await client.searchResources('Patient', 'name=Alice');
565
+ * console.log(patients);
566
+ * ```
567
+ *
568
+ * The return value is an array of resources.
569
+ *
570
+ * See FHIR search for full details: https://www.hl7.org/fhir/search.html
571
+ *
572
+ * @category Search
573
+ * @param query The search query as either a string or a structured search object.
574
+ * @returns Promise to the search result bundle.
575
+ */
576
+ searchResources<K extends ResourceType>(resourceType: K, query?: URLSearchParams | string, options?: RequestInit): ReadablePromise<ExtractResource<K>[]>;
577
+ /**
578
+ * Searches a ValueSet resource using the "expand" operation.
579
+ * See: https://www.hl7.org/fhir/operation-valueset-expand.html
580
+ *
581
+ * @category Search
582
+ * @param system The ValueSet system url.
583
+ * @param filter The search string.
584
+ * @returns Promise to expanded ValueSet.
585
+ */
586
+ searchValueSet(system: string, filter: string, options?: RequestInit): ReadablePromise<ValueSet>;
587
+ /**
588
+ * Returns a cached resource if it is available.
589
+ * @category Caching
590
+ * @param resourceType The FHIR resource type.
591
+ * @param id The FHIR resource ID.
592
+ * @returns The resource if it is available in the cache; undefined otherwise.
593
+ */
594
+ getCached<K extends ResourceType>(resourceType: K, id: string): ExtractResource<K> | undefined;
595
+ /**
596
+ * Returns a cached resource if it is available.
597
+ * @category Caching
598
+ * @param resourceType The FHIR resource type.
599
+ * @param id The FHIR resource ID.
600
+ * @returns The resource if it is available in the cache; undefined otherwise.
601
+ */
602
+ getCachedReference<T extends Resource>(reference: Reference<T>): T | undefined;
603
+ /**
604
+ * Reads a resource by resource type and ID.
605
+ *
606
+ * Example:
607
+ *
608
+ * ```typescript
609
+ * const patient = await medplum.readResource('Patient', '123');
610
+ * console.log(patient);
611
+ * ```
612
+ *
613
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
614
+ *
615
+ * @category Caching
616
+ * @param resourceType The FHIR resource type.
617
+ * @param id The resource ID.
618
+ * @returns The resource if available; undefined otherwise.
619
+ */
620
+ readResource<K extends ResourceType>(resourceType: K, id: string): ReadablePromise<ExtractResource<K>>;
621
+ /**
622
+ * Reads a resource by `Reference`.
623
+ *
624
+ * This is a convenience method for `readResource()` that accepts a `Reference` object.
625
+ *
626
+ * Example:
627
+ *
628
+ * ```typescript
629
+ * const serviceRequest = await medplum.readResource('ServiceRequest', '123');
630
+ * const patient = await medplum.readReference(serviceRequest.subject);
631
+ * console.log(patient);
632
+ * ```
633
+ *
634
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
635
+ *
636
+ * @category Read
637
+ * @param reference The FHIR reference object.
638
+ * @returns The resource if available; undefined otherwise.
639
+ */
640
+ readReference<T extends Resource>(reference: Reference<T>): ReadablePromise<T>;
641
+ /**
642
+ * Returns a cached schema for a resource type.
643
+ * If the schema is not cached, returns undefined.
644
+ * It is assumed that a client will call requestSchema before using this method.
645
+ * @category Schema
646
+ * @param resourceType The FHIR resource type.
647
+ * @returns The schema if immediately available, undefined otherwise.
648
+ * @deprecated Use globalSchema instead.
649
+ */
650
+ getSchema(): IndexedStructureDefinition;
651
+ /**
652
+ * Requests the schema for a resource type.
653
+ * If the schema is already cached, the promise is resolved immediately.
654
+ * @category Schema
655
+ * @param resourceType The FHIR resource type.
656
+ * @returns Promise to a schema with the requested resource type.
657
+ */
658
+ requestSchema(resourceType: string): Promise<IndexedStructureDefinition>;
659
+ /**
660
+ * Reads resource history by resource type and ID.
661
+ *
662
+ * The return value is a bundle of all versions of the resource.
663
+ *
664
+ * Example:
665
+ *
666
+ * ```typescript
667
+ * const history = await medplum.readHistory('Patient', '123');
668
+ * console.log(history);
669
+ * ```
670
+ *
671
+ * See the FHIR "history" operation for full details: https://www.hl7.org/fhir/http.html#history
672
+ *
673
+ * @category Read
674
+ * @param resourceType The FHIR resource type.
675
+ * @param id The resource ID.
676
+ * @returns Promise to the resource history.
677
+ */
678
+ readHistory<K extends ResourceType>(resourceType: K, id: string): ReadablePromise<Bundle<ExtractResource<K>>>;
679
+ /**
680
+ * Reads a specific version of a resource by resource type, ID, and version ID.
681
+ *
682
+ * Example:
683
+ *
684
+ * ```typescript
685
+ * const version = await medplum.readVersion('Patient', '123', '456');
686
+ * console.log(version);
687
+ * ```
688
+ *
689
+ * See the FHIR "vread" operation for full details: https://www.hl7.org/fhir/http.html#vread
690
+ *
691
+ * @category Read
692
+ * @param resourceType The FHIR resource type.
693
+ * @param id The resource ID.
694
+ * @returns The resource if available; undefined otherwise.
695
+ */
696
+ readVersion<K extends ResourceType>(resourceType: K, id: string, vid: string): ReadablePromise<ExtractResource<K>>;
697
+ /**
698
+ *
699
+ * @category Read
700
+ * @param id The Patient Id
701
+ * @returns A Bundle of all Resources related to the Patient
702
+ */
703
+ readPatientEverything(id: string): ReadablePromise<Bundle>;
704
+ /**
705
+ * Creates a new FHIR resource.
706
+ *
707
+ * The return value is the newly created resource, including the ID and meta.
708
+ *
709
+ * Example:
710
+ *
711
+ * ```typescript
712
+ * const result = await medplum.createResource({
713
+ * resourceType: 'Patient',
714
+ * name: [{
715
+ * family: 'Smith',
716
+ * given: ['John']
717
+ * }]
718
+ * });
719
+ * console.log(result.id);
720
+ * ```
721
+ *
722
+ * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
723
+ *
724
+ * @category Create
725
+ * @param resource The FHIR resource to create.
726
+ * @returns The result of the create operation.
727
+ */
728
+ createResource<T extends Resource>(resource: T): Promise<T>;
729
+ /**
730
+ * Conditionally create a new FHIR resource only if some equivalent resource does not already exist on the server.
731
+ *
732
+ * The return value is the existing resource or the newly created resource, including the ID and meta.
733
+ *
734
+ * Example:
735
+ *
736
+ * ```typescript
737
+ * const result = await medplum.createResourceIfNoneExist(
738
+ * {
739
+ * resourceType: 'Patient',
740
+ * identifier: [{
741
+ * system: 'http://example.com/mrn',
742
+ * value: '123'
743
+ * }]
744
+ * name: [{
745
+ * family: 'Smith',
746
+ * given: ['John']
747
+ * }]
748
+ * },
749
+ * 'identifier=123'
750
+ * );
751
+ * console.log(result.id);
752
+ * ```
753
+ *
754
+ * This method is syntactic sugar for:
755
+ *
756
+ * ```typescript
757
+ * return searchOne(resourceType, query) ?? createResource(resource);
758
+ * ```
759
+ *
760
+ * The query parameter only contains the search parameters (what would be in the URL following the "?").
761
+ *
762
+ * See the FHIR "conditional create" operation for full details: https://www.hl7.org/fhir/http.html#ccreate
763
+ *
764
+ * @category Create
765
+ * @param resource The FHIR resource to create.
766
+ * @param query The search query for an equivalent resource (should not include resource type or "?").
767
+ * @returns The result of the create operation.
768
+ */
769
+ createResourceIfNoneExist<T extends Resource>(resource: T, query: string): Promise<T>;
770
+ /**
771
+ * Creates a FHIR `Binary` resource with the provided data content.
772
+ *
773
+ * The return value is the newly created resource, including the ID and meta.
774
+ *
775
+ * The `data` parameter can be a string or a `File` object.
776
+ *
777
+ * A `File` object often comes from a `<input type="file">` element.
778
+ *
779
+ * Example:
780
+ *
781
+ * ```typescript
782
+ * const result = await medplum.createBinary(myFile, 'test.jpg', 'image/jpeg');
783
+ * console.log(result.id);
784
+ * ```
785
+ *
786
+ * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
787
+ *
788
+ * @category Create
789
+ * @param data The binary data to upload.
790
+ * @param filename Optional filename for the binary.
791
+ * @param contentType Content type for the binary.
792
+ * @returns The result of the create operation.
793
+ */
794
+ createBinary(data: string | File | Blob | Uint8Array, filename: string | undefined, contentType: string): Promise<Binary>;
795
+ /**
796
+ * Creates a PDF as a FHIR `Binary` resource based on pdfmake document definition.
797
+ *
798
+ * The return value is the newly created resource, including the ID and meta.
799
+ *
800
+ * The `docDefinition` parameter is a pdfmake document definition.
801
+ *
802
+ * Example:
803
+ *
804
+ * ```typescript
805
+ * const result = await medplum.createPdf({
806
+ * content: ['Hello world']
807
+ * });
808
+ * console.log(result.id);
809
+ * ```
810
+ *
811
+ * See the pdfmake document definition for full details: https://pdfmake.github.io/docs/0.1/document-definition-object/
812
+ *
813
+ * @category Media
814
+ * @param docDefinition The PDF document definition.
815
+ * @returns The result of the create operation.
816
+ */
817
+ createPdf(docDefinition: TDocumentDefinitions, filename?: string, tableLayouts?: {
818
+ [name: string]: CustomTableLayout;
819
+ }, fonts?: TFontDictionary): Promise<Binary>;
820
+ /**
821
+ * Creates a FHIR `Communication` resource with the provided data content.
822
+ *
823
+ * This is a convenience method to handle commmon cases where a `Communication` resource is created with a `payload`.
824
+ *
825
+ * @category Create
826
+ * @param resource The FHIR resource to comment on.
827
+ * @param text The text of the comment.
828
+ * @returns The result of the create operation.
829
+ */
830
+ createComment(resource: Resource, text: string): Promise<Communication>;
831
+ /**
832
+ * Updates a FHIR resource.
833
+ *
834
+ * The return value is the updated resource, including the ID and meta.
835
+ *
836
+ * Example:
837
+ *
838
+ * ```typescript
839
+ * const result = await medplum.updateResource({
840
+ * resourceType: 'Patient',
841
+ * id: '123',
842
+ * name: [{
843
+ * family: 'Smith',
844
+ * given: ['John']
845
+ * }]
846
+ * });
847
+ * console.log(result.meta.versionId);
848
+ * ```
849
+ *
850
+ * See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#update
851
+ *
852
+ * @category Write
853
+ * @param resource The FHIR resource to update.
854
+ * @returns The result of the update operation.
855
+ */
856
+ updateResource<T extends Resource>(resource: T): Promise<T>;
857
+ /**
858
+ * Updates a FHIR resource using JSONPatch operations.
859
+ *
860
+ * The return value is the updated resource, including the ID and meta.
861
+ *
862
+ * Example:
863
+ *
864
+ * ```typescript
865
+ * const result = await medplum.patchResource('Patient', '123', [
866
+ * {op: 'replace', path: '/name/0/family', value: 'Smith'},
867
+ * ]);
868
+ * console.log(result.meta.versionId);
869
+ * ```
870
+ *
871
+ * See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#patch
872
+ *
873
+ * See the JSONPatch specification for full details: https://tools.ietf.org/html/rfc6902
874
+ *
875
+ * @category Write
876
+ * @param resourceType The FHIR resource type.
877
+ * @param id The resource ID.
878
+ * @param operations The JSONPatch operations.
879
+ * @returns The result of the patch operations.
880
+ */
881
+ patchResource<K extends ResourceType>(resourceType: K, id: string, operations: PatchOperation[]): Promise<ExtractResource<K>>;
882
+ /**
883
+ * Deletes a FHIR resource by resource type and ID.
884
+ *
885
+ * Example:
886
+ *
887
+ * ```typescript
888
+ * await medplum.deleteResource('Patient', '123');
889
+ * ```
890
+ *
891
+ * See the FHIR "delete" operation for full details: https://www.hl7.org/fhir/http.html#delete
892
+ *
893
+ * @category Delete
894
+ * @param resourceType The FHIR resource type.
895
+ * @param id The resource ID.
896
+ * @returns The result of the delete operation.
897
+ */
898
+ deleteResource(resourceType: ResourceType, id: string): Promise<any>;
899
+ /**
900
+ * Executes a batch or transaction of FHIR operations.
901
+ *
902
+ * Example:
903
+ *
904
+ * ```typescript
905
+ * await medplum.executeBatch({
906
+ * "resourceType": "Bundle",
907
+ * "type": "transaction",
908
+ * "entry": [
909
+ * {
910
+ * "fullUrl": "urn:uuid:61ebe359-bfdc-4613-8bf2-c5e300945f0a",
911
+ * "resource": {
912
+ * "resourceType": "Patient",
913
+ * "name": [{ "use": "official", "given": ["Alice"], "family": "Smith" }],
914
+ * "gender": "female",
915
+ * "birthDate": "1974-12-25"
916
+ * },
917
+ * "request": {
918
+ * "method": "POST",
919
+ * "url": "Patient"
920
+ * }
921
+ * },
922
+ * {
923
+ * "fullUrl": "urn:uuid:88f151c0-a954-468a-88bd-5ae15c08e059",
924
+ * "resource": {
925
+ * "resourceType": "Patient",
926
+ * "identifier": [{ "system": "http:/example.org/fhir/ids", "value": "234234" }],
927
+ * "name": [{ "use": "official", "given": ["Bob"], "family": "Jones" }],
928
+ * "gender": "male",
929
+ * "birthDate": "1974-12-25"
930
+ * },
931
+ * "request": {
932
+ * "method": "POST",
933
+ * "url": "Patient",
934
+ * "ifNoneExist": "identifier=http:/example.org/fhir/ids|234234"
935
+ * }
936
+ * }
937
+ * ]
938
+ * });
939
+ * ```
940
+ *
941
+ * See The FHIR "batch/transaction" section for full details: https://hl7.org/fhir/http.html#transaction
942
+ * @category Batch
943
+ * @param bundle The FHIR batch/transaction bundle.
944
+ * @returns The FHIR batch/transaction response bundle.
945
+ */
946
+ executeBatch(bundle: Bundle): Promise<Bundle>;
947
+ /**
948
+ * Sends an email using the Medplum Email API.
949
+ *
950
+ * Builds the email using nodemailer MailComposer.
951
+ *
952
+ * Examples:
953
+ *
954
+ * Send a simple text email:
955
+ *
956
+ * ```typescript
957
+ * await medplum.sendEmail({
958
+ * to: 'alice@example.com',
959
+ * cc: 'bob@example.com',
960
+ * subject: 'Hello',
961
+ * text: 'Hello Alice',
962
+ * });
963
+ * ```
964
+ *
965
+ * Send an email with a `Binary` attachment:
966
+ *
967
+ * ```typescript
968
+ * await medplum.sendEmail({
969
+ * to: 'alice@example.com',
970
+ * subject: 'Email with attachment',
971
+ * text: 'See the attached report',
972
+ * attachments: [{
973
+ * filename: 'report.pdf',
974
+ * path: "Binary/" + binary.id
975
+ * }]
976
+ * });
977
+ * ```
978
+ *
979
+ * See options here: https://nodemailer.com/extras/mailcomposer/
980
+ * @category Media
981
+ * @param options The MailComposer options.
982
+ * @returns Promise to the operation outcome.
983
+ */
984
+ sendEmail(email: MailOptions): Promise<OperationOutcome>;
985
+ /**
986
+ * Executes a GraphQL query.
987
+ *
988
+ * Example:
989
+ *
990
+ * ```typescript
991
+ * const result = await medplum.graphql(`{
992
+ * Patient(id: "123") {
993
+ * resourceType
994
+ * id
995
+ * name {
996
+ * given
997
+ * family
998
+ * }
999
+ * }
1000
+ * }`);
1001
+ * ```
1002
+ *
1003
+ * Advanced queries such as named operations and variable substitution are supported:
1004
+ *
1005
+ * ```typescript
1006
+ * const result = await medplum.graphql(
1007
+ * `query GetPatientById($patientId: ID!) {
1008
+ * Patient(id: $patientId) {
1009
+ * resourceType
1010
+ * id
1011
+ * name {
1012
+ * given
1013
+ * family
1014
+ * }
1015
+ * }
1016
+ * }`,
1017
+ * 'GetPatientById',
1018
+ * { patientId: '123' }
1019
+ * );
1020
+ * ```
1021
+ *
1022
+ * See the GraphQL documentation for more details: https://graphql.org/learn/
1023
+ *
1024
+ * See the FHIR GraphQL documentation for FHIR specific details: https://www.hl7.org/fhir/graphql.html
1025
+ *
1026
+ * @category Read
1027
+ * @param query The GraphQL query.
1028
+ * @param operationName Optional GraphQL operation name.
1029
+ * @param variables Optional GraphQL variables.
1030
+ * @param options Optional fetch options.
1031
+ * @returns The GraphQL result.
1032
+ */
1033
+ graphql(query: string, operationName?: string | null, variables?: any, options?: RequestInit): Promise<any>;
1034
+ /**
1035
+ * @category Authentication
1036
+ * @returns The Login State
1037
+ */
1038
+ getActiveLogin(): LoginState | undefined;
1039
+ /**
1040
+ * @category Authentication
1041
+ */
1042
+ setActiveLogin(login: LoginState): Promise<void>;
1043
+ /**
1044
+ * @category Authentication
1045
+ */
1046
+ getAccessToken(): string | undefined;
1047
+ /**
1048
+ * @category Authentication
1049
+ */
1050
+ setAccessToken(accessToken: string): void;
1051
+ /**
1052
+ * @category Authentication
1053
+ */
1054
+ getLogins(): LoginState[];
1055
+ /**
1056
+ * @category Authentication
1057
+ */
1058
+ isLoading(): boolean;
1059
+ /**
1060
+ * @category User Profile
1061
+ */
1062
+ getProfile(): ProfileResource | undefined;
1063
+ /**
1064
+ * @category User Profile
1065
+ */
1066
+ getProfileAsync(): Promise<ProfileResource | undefined>;
1067
+ /**
1068
+ * @category User Profile
1069
+ */
1070
+ getUserConfiguration(): UserConfiguration | undefined;
1071
+ /**
1072
+ * Downloads the URL as a blob.
1073
+ *
1074
+ * @category Read
1075
+ * @param url The URL to request.
1076
+ * @returns Promise to the response body as a blob.
1077
+ */
1078
+ download(url: URL | string, options?: RequestInit): Promise<Blob>;
1079
+ /**
1080
+ * Processes an OAuth authorization code.
1081
+ * See: https://openid.net/specs/openid-connect-core-1_0.html#TokenRequest
1082
+ * @param code The authorization code received by URL parameter.
1083
+ */
1084
+ processCode(code: string): Promise<ProfileResource>;
1085
+ /**
1086
+ * Starts a new OAuth2 client credentials flow.
1087
+ * See: https://datatracker.ietf.org/doc/html/rfc6749#section-4.4
1088
+ * @category Authentication
1089
+ * @param clientId The client ID.
1090
+ * @param clientSecret The client secret.
1091
+ * @returns Promise that resolves to the client profile.
1092
+ */
1093
+ startClientLogin(clientId: string, clientSecret: string): Promise<ProfileResource>;
1094
+ }