@medplum/core 0.9.28 → 0.9.31

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