@medplum/core 0.9.6 → 0.9.7

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.
@@ -0,0 +1 @@
1
+ {"type": "module"}
@@ -1,58 +1,75 @@
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';
1
+ import { Binary, Bundle, Communication, OperationOutcome, Project, ProjectMembership, Reference, Resource, UserConfiguration, ValueSet } from '@medplum/fhirtypes';
4
2
  import { EventTarget } from './eventtarget';
5
3
  import { Hl7Message } from './hl7';
6
4
  import { ReadablePromise } from './readablepromise';
7
5
  import { SearchRequest } from './search';
8
6
  import { IndexedStructureDefinition } from './types';
9
7
  import { ProfileResource } from './utils';
8
+ /**
9
+ * The MedplumClientOptions interface defines configuration options for MedplumClient.
10
+ *
11
+ * All configuration settings are optional.
12
+ */
10
13
  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
14
  /**
18
15
  * Base server URL.
19
- * Optional. Default value is "https://api.medplum.com/".
16
+ *
17
+ * Default value is "https://api.medplum.com/".
18
+ *
20
19
  * Use this to point to a custom Medplum deployment.
21
20
  */
22
21
  baseUrl?: string;
23
22
  /**
24
23
  * OAuth2 authorize URL.
25
- * Optional. Default value is baseUrl + "/oauth2/authorize".
24
+ *
25
+ * Default value is baseUrl + "/oauth2/authorize".
26
+ *
26
27
  * Use this if you want to use a separate OAuth server.
27
28
  */
28
29
  authorizeUrl?: string;
29
30
  /**
30
31
  * OAuth2 token URL.
31
- * Optional. Default value is baseUrl + "/oauth2/token".
32
+ *
33
+ * Default value is baseUrl + "/oauth2/token".
34
+ *
32
35
  * Use this if you want to use a separate OAuth server.
33
36
  */
34
37
  tokenUrl?: string;
35
38
  /**
36
39
  * OAuth2 logout URL.
37
- * Optional. Default value is baseUrl + "/oauth2/logout".
40
+ *
41
+ * Default value is baseUrl + "/oauth2/logout".
42
+ *
38
43
  * Use this if you want to use a separate OAuth server.
39
44
  */
40
45
  logoutUrl?: string;
46
+ /**
47
+ * The client ID.
48
+ *
49
+ * Client ID can be used for SMART-on-FHIR customization.
50
+ */
51
+ clientId?: string;
41
52
  /**
42
53
  * Number of resources to store in the cache.
43
- * Optional. Default value is 1000.
54
+ *
55
+ * Default value is 1000.
56
+ *
44
57
  * Consider using this for performance of displaying Patient or Practitioner resources.
45
58
  */
46
59
  resourceCacheSize?: number;
47
60
  /**
48
- * Optional fetch implementation.
49
- * Optional. Default is window.fetch.
61
+ * Fetch implementation.
62
+ *
63
+ * Default is window.fetch (if available).
64
+ *
50
65
  * For nodejs applications, consider the 'node-fetch' package.
51
66
  */
52
67
  fetch?: FetchLike;
53
68
  /**
54
- * Optional callback for when the client is unauthenticated.
69
+ * Callback for when the client is unauthenticated.
70
+ *
55
71
  * Default is do nothing.
72
+ *
56
73
  * For client side applications, consider redirecting to a sign in page.
57
74
  */
58
75
  onUnauthenticated?: () => void;
@@ -111,6 +128,63 @@ export interface BotEvent {
111
128
  readonly contentType: string;
112
129
  readonly input: Resource | Hl7Message | string;
113
130
  }
131
+ /**
132
+ * JSONPatch patch operation.
133
+ * Compatible with fast-json-patch Operation.
134
+ */
135
+ export interface PatchOperation {
136
+ readonly op: string;
137
+ readonly path: string;
138
+ readonly value?: any;
139
+ }
140
+ /**
141
+ * Email address definition.
142
+ * Compatible with nodemailer Mail.Address.
143
+ */
144
+ export interface MailAddress {
145
+ readonly name: string;
146
+ readonly address: string;
147
+ }
148
+ /**
149
+ * Email attachment definition.
150
+ * Compatible with nodemailer Mail.Options.
151
+ */
152
+ export interface MailAttachment {
153
+ /** String, Buffer or a Stream contents for the attachmentent */
154
+ readonly content?: string;
155
+ /** 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) */
156
+ readonly path?: string;
157
+ /** 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 */
158
+ readonly filename?: string | false;
159
+ /** optional content type for the attachment, if not set will be derived from the filename property */
160
+ readonly contentType?: string;
161
+ }
162
+ /**
163
+ * Email message definition.
164
+ * Compatible with nodemailer Mail.Options.
165
+ */
166
+ export interface MailOptions {
167
+ /** The e-mail address of the sender. All e-mail addresses can be plain 'sender@server.com' or formatted 'Sender Name <sender@server.com>' */
168
+ readonly from?: string | MailAddress;
169
+ /** An e-mail address that will appear on the Sender: field */
170
+ readonly sender?: string | MailAddress;
171
+ /** Comma separated list or an array of recipients e-mail addresses that will appear on the To: field */
172
+ readonly to?: string | MailAddress | string[] | MailAddress[];
173
+ /** Comma separated list or an array of recipients e-mail addresses that will appear on the Cc: field */
174
+ readonly cc?: string | MailAddress | string[] | MailAddress[];
175
+ /** Comma separated list or an array of recipients e-mail addresses that will appear on the Bcc: field */
176
+ readonly bcc?: string | MailAddress | string[] | MailAddress[];
177
+ /** An e-mail address that will appear on the Reply-To: field */
178
+ readonly replyTo?: string | MailAddress;
179
+ /** The subject of the e-mail */
180
+ readonly subject?: string;
181
+ /** The plaintext version of the message */
182
+ readonly text?: string;
183
+ /** The HTML version of the message */
184
+ readonly html?: string;
185
+ /** An array of attachment objects */
186
+ readonly attachments?: MailAttachment[];
187
+ }
114
188
  /**
115
189
  * The MedplumClient class provides a client for the Medplum FHIR server.
116
190
  *
@@ -157,11 +231,17 @@ export interface BotEvent {
157
231
  * const bundle = await medplum.search('Patient?name=Alice');
158
232
  * console.log(bundle.total);
159
233
  * ```
160
- *
161
234
  */
162
235
  export declare class MedplumClient extends EventTarget {
163
236
  #private;
164
237
  constructor(options?: MedplumClientOptions);
238
+ /**
239
+ * Returns the current base URL for all API requests.
240
+ * By default, this is set to `https://api.medplum.com/`.
241
+ * This can be overridden by setting the `baseUrl` option when creating the client.
242
+ * @returns The current base URL for all API requests.
243
+ */
244
+ getBaseUrl(): string;
165
245
  /**
166
246
  * Clears all auth state including local storage and session storage.
167
247
  */
@@ -177,7 +257,7 @@ export declare class MedplumClient extends EventTarget {
177
257
  * @param options Optional fetch options.
178
258
  * @returns Promise to the response content.
179
259
  */
180
- get<T = any>(url: string, options?: RequestInit): ReadablePromise<T>;
260
+ get<T = any>(url: URL | string, options?: RequestInit): ReadablePromise<T>;
181
261
  /**
182
262
  * Makes an HTTP POST request to the specified URL.
183
263
  *
@@ -191,7 +271,7 @@ export declare class MedplumClient extends EventTarget {
191
271
  * @param options Optional fetch options.
192
272
  * @returns Promise to the response content.
193
273
  */
194
- post(url: string, body: any, contentType?: string, options?: RequestInit): Promise<any>;
274
+ post(url: URL | string, body: any, contentType?: string, options?: RequestInit): Promise<any>;
195
275
  /**
196
276
  * Makes an HTTP PUT request to the specified URL.
197
277
  *
@@ -205,7 +285,7 @@ export declare class MedplumClient extends EventTarget {
205
285
  * @param options Optional fetch options.
206
286
  * @returns Promise to the response content.
207
287
  */
208
- put(url: string, body: any, contentType?: string, options?: RequestInit): Promise<any>;
288
+ put(url: URL | string, body: any, contentType?: string, options?: RequestInit): Promise<any>;
209
289
  /**
210
290
  * Makes an HTTP PATCH request to the specified URL.
211
291
  *
@@ -218,7 +298,7 @@ export declare class MedplumClient extends EventTarget {
218
298
  * @param options Optional fetch options.
219
299
  * @returns Promise to the response content.
220
300
  */
221
- patch(url: string, operations: Operation[], options?: RequestInit): Promise<any>;
301
+ patch(url: URL | string, operations: PatchOperation[], options?: RequestInit): Promise<any>;
222
302
  /**
223
303
  * Makes an HTTP DELETE request to the specified URL.
224
304
  *
@@ -230,7 +310,7 @@ export declare class MedplumClient extends EventTarget {
230
310
  * @param options Optional fetch options.
231
311
  * @returns Promise to the response content.
232
312
  */
233
- delete(url: string, options?: RequestInit): Promise<any>;
313
+ delete(url: URL | string, options?: RequestInit): Promise<any>;
234
314
  /**
235
315
  * Tries to register a new user.
236
316
  * @param request The registration request.
@@ -273,7 +353,7 @@ export declare class MedplumClient extends EventTarget {
273
353
  * @param path The path component of the URL.
274
354
  * @returns The well-formed FHIR URL.
275
355
  */
276
- fhirUrl(...path: string[]): string;
356
+ fhirUrl(...path: string[]): URL;
277
357
  /**
278
358
  * Sends a FHIR search request.
279
359
  *
@@ -328,7 +408,7 @@ export declare class MedplumClient extends EventTarget {
328
408
  * @param query The search query as either a string or a structured search object.
329
409
  * @returns Promise to the search result bundle.
330
410
  */
331
- search<T extends Resource>(query: string | SearchRequest, options?: RequestInit): Promise<Bundle<T>>;
411
+ search<T extends Resource>(query: string | SearchRequest, options?: RequestInit): ReadablePromise<Bundle<T>>;
332
412
  /**
333
413
  * Sends a FHIR search request for a single resource.
334
414
  *
@@ -348,7 +428,7 @@ export declare class MedplumClient extends EventTarget {
348
428
  * @param query The search query as either a string or a structured search object.
349
429
  * @returns Promise to the search result bundle.
350
430
  */
351
- searchOne<T extends Resource>(query: string | SearchRequest, options?: RequestInit): Promise<T | undefined>;
431
+ searchOne<T extends Resource>(query: string | SearchRequest, options?: RequestInit): ReadablePromise<T | undefined>;
352
432
  /**
353
433
  * Sends a FHIR search request for an array of resources.
354
434
  *
@@ -368,7 +448,7 @@ export declare class MedplumClient extends EventTarget {
368
448
  * @param query The search query as either a string or a structured search object.
369
449
  * @returns Promise to the search result bundle.
370
450
  */
371
- searchResources<T extends Resource>(query: string | SearchRequest, options?: RequestInit): Promise<T[]>;
451
+ searchResources<T extends Resource>(query: string | SearchRequest, options?: RequestInit): ReadablePromise<T[]>;
372
452
  /**
373
453
  * Searches a ValueSet resource using the "expand" operation.
374
454
  * See: https://www.hl7.org/fhir/operation-valueset-expand.html
@@ -376,7 +456,7 @@ export declare class MedplumClient extends EventTarget {
376
456
  * @param filter The search string.
377
457
  * @returns Promise to expanded ValueSet.
378
458
  */
379
- searchValueSet(system: string, filter: string, options?: RequestInit): Promise<ValueSet>;
459
+ searchValueSet(system: string, filter: string, options?: RequestInit): ReadablePromise<ValueSet>;
380
460
  /**
381
461
  * Returns a cached resource if it is available.
382
462
  * @param resourceType The FHIR resource type.
@@ -498,9 +578,9 @@ export declare class MedplumClient extends EventTarget {
498
578
  *
499
579
  * @param resourceType The FHIR resource type.
500
580
  * @param id The resource ID.
501
- * @returns The resource if available; undefined otherwise.
581
+ * @returns Promise to the resource history.
502
582
  */
503
- readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>;
583
+ readHistory<T extends Resource>(resourceType: string, id: string): ReadablePromise<Bundle<T>>;
504
584
  /**
505
585
  * Reads a specific version of a resource by resource type, ID, and version ID.
506
586
  *
@@ -517,8 +597,8 @@ export declare class MedplumClient extends EventTarget {
517
597
  * @param id The resource ID.
518
598
  * @returns The resource if available; undefined otherwise.
519
599
  */
520
- readVersion<T extends Resource>(resourceType: string, id: string, vid: string): Promise<T>;
521
- readPatientEverything(id: string): Promise<Bundle>;
600
+ readVersion<T extends Resource>(resourceType: string, id: string, vid: string): ReadablePromise<T>;
601
+ readPatientEverything(id: string): ReadablePromise<Bundle>;
522
602
  /**
523
603
  * Creates a new FHIR resource.
524
604
  *
@@ -628,6 +708,16 @@ export declare class MedplumClient extends EventTarget {
628
708
  * @returns The result of the create operation.
629
709
  */
630
710
  createPdf(docDefinition: Record<string, unknown>, filename?: string): Promise<Binary>;
711
+ /**
712
+ * Creates a FHIR `Communication` resource with the provided data content.
713
+ *
714
+ * This is a convenience method to handle commmon cases where a `Communication` resource is created with a `payload`.
715
+ *
716
+ * @param resource The FHIR resource to comment on.
717
+ * @param text The text of the comment.
718
+ * @returns The result of the create operation.
719
+ */
720
+ createComment(resource: Resource, text: string): Promise<Communication>;
631
721
  /**
632
722
  * Updates a FHIR resource.
633
723
  *
@@ -676,7 +766,7 @@ export declare class MedplumClient extends EventTarget {
676
766
  * @param operations The JSONPatch operations.
677
767
  * @returns The result of the patch operations.
678
768
  */
679
- patchResource<T extends Resource>(resourceType: string, id: string, operations: Operation[]): Promise<T>;
769
+ patchResource<T extends Resource>(resourceType: string, id: string, operations: PatchOperation[]): Promise<T>;
680
770
  /**
681
771
  * Deletes a FHIR resource by resource type and ID.
682
772
  *
@@ -730,10 +820,11 @@ export declare class MedplumClient extends EventTarget {
730
820
  * @param options The MailComposer options.
731
821
  * @returns Promise to the operation outcome.
732
822
  */
733
- sendEmail(email: Mail.Options): Promise<OperationOutcome>;
823
+ sendEmail(email: MailOptions): Promise<OperationOutcome>;
734
824
  graphql(query: string, options?: RequestInit): Promise<any>;
735
825
  getActiveLogin(): LoginState | undefined;
736
826
  setActiveLogin(login: LoginState): Promise<void>;
827
+ getAccessToken(): string | undefined;
737
828
  setAccessToken(accessToken: string): void;
738
829
  getLogins(): LoginState[];
739
830
  isLoading(): boolean;
@@ -745,12 +836,19 @@ export declare class MedplumClient extends EventTarget {
745
836
  * @param url The URL to request.
746
837
  * @returns Promise to the response body as a blob.
747
838
  */
748
- download(url: string, options?: RequestInit): Promise<Blob>;
839
+ download(url: URL | string, options?: RequestInit): Promise<Blob>;
749
840
  /**
750
841
  * Processes an OAuth authorization code.
751
842
  * See: https://openid.net/specs/openid-connect-core-1_0.html#TokenRequest
752
843
  * @param code The authorization code received by URL parameter.
753
844
  */
754
845
  processCode(code: string): Promise<ProfileResource>;
755
- clientCredentials(clientId: string, clientSecret: string): Promise<ProfileResource>;
846
+ /**
847
+ * Starts a new OAuth2 client credentials flow.
848
+ * See: https://datatracker.ietf.org/doc/html/rfc6749#section-4.4
849
+ * @param clientId The client ID.
850
+ * @param clientSecret The client secret.
851
+ * @returns Promise that resolves to the client profile.
852
+ */
853
+ startClientLogin(clientId: string, clientSecret: string): Promise<ProfileResource>;
756
854
  }
@@ -0,0 +1,150 @@
1
+ import { Quantity } from '@medplum/fhirtypes';
2
+ export interface Atom {
3
+ eval(context: unknown): unknown;
4
+ }
5
+ export declare class FhirPathAtom implements Atom {
6
+ readonly original: string;
7
+ readonly child: Atom;
8
+ constructor(original: string, child: Atom);
9
+ eval(context: unknown): unknown[];
10
+ }
11
+ export declare class LiteralAtom implements Atom {
12
+ readonly value: Quantity | boolean | number | string;
13
+ constructor(value: Quantity | boolean | number | string);
14
+ eval(): unknown;
15
+ }
16
+ export declare class SymbolAtom implements Atom {
17
+ readonly name: string;
18
+ constructor(name: string);
19
+ eval(context: unknown): unknown;
20
+ }
21
+ export declare class EmptySetAtom implements Atom {
22
+ eval(): [];
23
+ }
24
+ export declare class UnaryOperatorAtom implements Atom {
25
+ readonly child: Atom;
26
+ readonly impl: (x: unknown) => unknown;
27
+ constructor(child: Atom, impl: (x: unknown) => unknown);
28
+ eval(context: unknown): unknown;
29
+ }
30
+ export declare class AsAtom implements Atom {
31
+ readonly left: Atom;
32
+ readonly right: Atom;
33
+ constructor(left: Atom, right: Atom);
34
+ eval(context: unknown): unknown;
35
+ }
36
+ export declare class ArithemticOperatorAtom implements Atom {
37
+ readonly left: Atom;
38
+ readonly right: Atom;
39
+ readonly impl: (x: number, y: number) => number;
40
+ constructor(left: Atom, right: Atom, impl: (x: number, y: number) => number);
41
+ eval(context: unknown): unknown;
42
+ }
43
+ export declare class ComparisonOperatorAtom implements Atom {
44
+ readonly left: Atom;
45
+ readonly right: Atom;
46
+ readonly impl: (x: number, y: number) => boolean;
47
+ constructor(left: Atom, right: Atom, impl: (x: number, y: number) => boolean);
48
+ eval(context: unknown): unknown;
49
+ }
50
+ export declare class ConcatAtom implements Atom {
51
+ readonly left: Atom;
52
+ readonly right: Atom;
53
+ constructor(left: Atom, right: Atom);
54
+ eval(context: unknown): unknown;
55
+ }
56
+ export declare class ContainsAtom implements Atom {
57
+ readonly left: Atom;
58
+ readonly right: Atom;
59
+ constructor(left: Atom, right: Atom);
60
+ eval(context: unknown): unknown;
61
+ }
62
+ export declare class InAtom implements Atom {
63
+ readonly left: Atom;
64
+ readonly right: Atom;
65
+ constructor(left: Atom, right: Atom);
66
+ eval(context: unknown): unknown;
67
+ }
68
+ export declare class DotAtom implements Atom {
69
+ readonly left: Atom;
70
+ readonly right: Atom;
71
+ constructor(left: Atom, right: Atom);
72
+ eval(context: unknown): unknown;
73
+ }
74
+ export declare class UnionAtom implements Atom {
75
+ readonly left: Atom;
76
+ readonly right: Atom;
77
+ constructor(left: Atom, right: Atom);
78
+ eval(context: unknown): unknown;
79
+ }
80
+ export declare class EqualsAtom implements Atom {
81
+ readonly left: Atom;
82
+ readonly right: Atom;
83
+ constructor(left: Atom, right: Atom);
84
+ eval(context: unknown): unknown;
85
+ }
86
+ export declare class NotEqualsAtom implements Atom {
87
+ readonly left: Atom;
88
+ readonly right: Atom;
89
+ constructor(left: Atom, right: Atom);
90
+ eval(context: unknown): unknown;
91
+ }
92
+ export declare class EquivalentAtom implements Atom {
93
+ readonly left: Atom;
94
+ readonly right: Atom;
95
+ constructor(left: Atom, right: Atom);
96
+ eval(context: unknown): unknown;
97
+ }
98
+ export declare class NotEquivalentAtom implements Atom {
99
+ readonly left: Atom;
100
+ readonly right: Atom;
101
+ constructor(left: Atom, right: Atom);
102
+ eval(context: unknown): unknown;
103
+ }
104
+ export declare class IsAtom implements Atom {
105
+ readonly left: Atom;
106
+ readonly right: Atom;
107
+ constructor(left: Atom, right: Atom);
108
+ eval(context: unknown): unknown;
109
+ }
110
+ /**
111
+ * 6.5.1. and
112
+ * Returns true if both operands evaluate to true, false if either operand evaluates to false, and the empty collection ({ }) otherwise.
113
+ */
114
+ export declare class AndAtom implements Atom {
115
+ readonly left: Atom;
116
+ readonly right: Atom;
117
+ constructor(left: Atom, right: Atom);
118
+ eval(context: unknown): unknown;
119
+ }
120
+ export declare class OrAtom implements Atom {
121
+ readonly left: Atom;
122
+ readonly right: Atom;
123
+ constructor(left: Atom, right: Atom);
124
+ eval(context: unknown): unknown;
125
+ }
126
+ /**
127
+ * 6.5.4. xor
128
+ * Returns true if exactly one of the operands evaluates to true,
129
+ * false if either both operands evaluate to true or both operands evaluate to false,
130
+ * and the empty collection ({ }) otherwise:
131
+ */
132
+ export declare class XorAtom implements Atom {
133
+ readonly left: Atom;
134
+ readonly right: Atom;
135
+ constructor(left: Atom, right: Atom);
136
+ eval(context: unknown): unknown;
137
+ }
138
+ export declare class FunctionAtom implements Atom {
139
+ readonly name: string;
140
+ readonly args: Atom[];
141
+ readonly impl: (context: unknown[], ...a: Atom[]) => unknown[];
142
+ constructor(name: string, args: Atom[], impl: (context: unknown[], ...a: Atom[]) => unknown[]);
143
+ eval(context: unknown): unknown;
144
+ }
145
+ export declare class IndexerAtom implements Atom {
146
+ readonly left: Atom;
147
+ readonly expr: Atom;
148
+ constructor(left: Atom, expr: Atom);
149
+ eval(context: unknown): unknown;
150
+ }
@@ -0,0 +1 @@
1
+ export declare function parseDateString(str: string): string;