@medplum/core 0.9.19 → 0.9.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -6190,6 +6190,7 @@
6190
6190
  * Returns the current base URL for all API requests.
6191
6191
  * By default, this is set to `https://api.medplum.com/`.
6192
6192
  * This can be overridden by setting the `baseUrl` option when creating the client.
6193
+ * @category HTTP
6193
6194
  * @returns The current base URL for all API requests.
6194
6195
  */
6195
6196
  getBaseUrl() {
@@ -6197,6 +6198,7 @@
6197
6198
  }
6198
6199
  /**
6199
6200
  * Clears all auth state including local storage and session storage.
6201
+ * @category Authentication
6200
6202
  */
6201
6203
  clear() {
6202
6204
  __classPrivateFieldGet(this, _MedplumClient_storage, "f").clear();
@@ -6209,6 +6211,7 @@
6209
6211
  }
6210
6212
  /**
6211
6213
  * Invalidates any cached values or cached requests for the given URL.
6214
+ * @category Caching
6212
6215
  * @param url The URL to invalidate.
6213
6216
  */
6214
6217
  invalidateUrl(url) {
@@ -6217,6 +6220,7 @@
6217
6220
  }
6218
6221
  /**
6219
6222
  * Invalidates all cached search results or cached requests for the given resourceType.
6223
+ * @category Caching
6220
6224
  * @param resourceType The resource type to invalidate.
6221
6225
  */
6222
6226
  invalidateSearches(resourceType) {
@@ -6234,6 +6238,7 @@
6234
6238
  * For common operations, we recommend using higher level methods
6235
6239
  * such as `readResource()`, `search()`, etc.
6236
6240
  *
6241
+ * @category HTTP
6237
6242
  * @param url The target URL.
6238
6243
  * @param options Optional fetch options.
6239
6244
  * @returns Promise to the response content.
@@ -6255,6 +6260,7 @@
6255
6260
  * For common operations, we recommend using higher level methods
6256
6261
  * such as `createResource()`.
6257
6262
  *
6263
+ * @category HTTP
6258
6264
  * @param url The target URL.
6259
6265
  * @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
6260
6266
  * @param contentType The content type to be included in the "Content-Type" header.
@@ -6279,6 +6285,7 @@
6279
6285
  * For common operations, we recommend using higher level methods
6280
6286
  * such as `updateResource()`.
6281
6287
  *
6288
+ * @category HTTP
6282
6289
  * @param url The target URL.
6283
6290
  * @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
6284
6291
  * @param contentType The content type to be included in the "Content-Type" header.
@@ -6303,6 +6310,7 @@
6303
6310
  * For common operations, we recommend using higher level methods
6304
6311
  * such as `patchResource()`.
6305
6312
  *
6313
+ * @category HTTP
6306
6314
  * @param url The target URL.
6307
6315
  * @param operations Array of JSONPatch operations.
6308
6316
  * @param options Optional fetch options.
@@ -6318,10 +6326,12 @@
6318
6326
  /**
6319
6327
  * Makes an HTTP DELETE request to the specified URL.
6320
6328
  *
6329
+ *
6321
6330
  * This is a lower level method for custom requests.
6322
6331
  * For common operations, we recommend using higher level methods
6323
6332
  * such as `deleteResource()`.
6324
6333
  *
6334
+ * @category HTTP
6325
6335
  * @param url The target URL.
6326
6336
  * @param options Optional fetch options.
6327
6337
  * @returns Promise to the response content.
@@ -6333,6 +6343,7 @@
6333
6343
  }
6334
6344
  /**
6335
6345
  * Tries to register a new user.
6346
+ * @category Authentication
6336
6347
  * @param request The registration request.
6337
6348
  * @returns Promise to the authentication response.
6338
6349
  */
@@ -6344,31 +6355,36 @@
6344
6355
  }
6345
6356
  /**
6346
6357
  * Initiates a user login flow.
6358
+ * @category Authentication
6347
6359
  * @param loginRequest Login request including email and password.
6348
6360
  * @returns Promise to the authentication response.
6349
6361
  */
6350
6362
  startLogin(loginRequest) {
6363
+ var _a, _b;
6351
6364
  return __awaiter(this, void 0, void 0, function* () {
6352
6365
  yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
6353
- return this.post('auth/login', Object.assign(Object.assign({}, loginRequest), { clientId: __classPrivateFieldGet(this, _MedplumClient_clientId, "f"), scope: DEFAULT_SCOPE, codeChallengeMethod: 'S256', codeChallenge: __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge') }));
6366
+ return this.post('auth/login', Object.assign(Object.assign({}, loginRequest), { clientId: (_a = loginRequest.clientId) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _MedplumClient_clientId, "f"), scope: (_b = loginRequest.scope) !== null && _b !== void 0 ? _b : DEFAULT_SCOPE, codeChallengeMethod: 'S256', codeChallenge: __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge') }));
6354
6367
  });
6355
6368
  }
6356
6369
  /**
6357
6370
  * Tries to sign in with Google authentication.
6358
6371
  * The response parameter is the result of a Google authentication.
6359
6372
  * See: https://developers.google.com/identity/gsi/web/guides/handle-credential-responses-js-functions
6360
- * @param googleResponse The Google credential response.
6373
+ * @category Authentication
6374
+ * @param loginRequest Login request including Google credential response.
6361
6375
  * @returns Promise to the authentication response.
6362
6376
  */
6363
- startGoogleLogin(googleResponse) {
6377
+ startGoogleLogin(loginRequest) {
6378
+ var _a, _b;
6364
6379
  return __awaiter(this, void 0, void 0, function* () {
6365
6380
  yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
6366
- return this.post('auth/google', googleResponse);
6381
+ return this.post('auth/google', Object.assign(Object.assign({}, loginRequest), { clientId: (_a = loginRequest.clientId) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _MedplumClient_clientId, "f"), scope: (_b = loginRequest.scope) !== null && _b !== void 0 ? _b : DEFAULT_SCOPE }));
6367
6382
  });
6368
6383
  }
6369
6384
  /**
6370
6385
  * Signs out locally.
6371
6386
  * Does not invalidate tokens with the server.
6387
+ * @category Authentication
6372
6388
  */
6373
6389
  signOut() {
6374
6390
  this.clear();
@@ -6378,6 +6394,7 @@
6378
6394
  * Tries to sign in the user.
6379
6395
  * Returns true if the user is signed in.
6380
6396
  * This may result in navigating away to the sign in page.
6397
+ * @category Authentication
6381
6398
  */
6382
6399
  signInWithRedirect() {
6383
6400
  const urlParams = new URLSearchParams(window.location.search);
@@ -6393,6 +6410,7 @@
6393
6410
  /**
6394
6411
  * Tries to sign out the user.
6395
6412
  * See: https://docs.aws.amazon.com/cognito/latest/developerguide/logout-endpoint.html
6413
+ * @category Authentication
6396
6414
  */
6397
6415
  signOutWithRedirect() {
6398
6416
  window.location.assign(__classPrivateFieldGet(this, _MedplumClient_logoutUrl, "f"));
@@ -6400,6 +6418,7 @@
6400
6418
  /**
6401
6419
  * Builds a FHIR URL from a collection of URL path components.
6402
6420
  * For example, `buildUrl('/Patient', '123')` returns `fhir/R4/Patient/123`.
6421
+ * @category HTTP
6403
6422
  * @param path The path component of the URL.
6404
6423
  * @returns The well-formed FHIR URL.
6405
6424
  */
@@ -6408,6 +6427,8 @@
6408
6427
  }
6409
6428
  /**
6410
6429
  * Builds a FHIR search URL from a search query or structured query object.
6430
+ * @category HTTP
6431
+ * @category Search
6411
6432
  * @param query The FHIR search query or structured query object.
6412
6433
  * @returns The well-formed FHIR URL.
6413
6434
  */
@@ -6455,6 +6476,7 @@
6455
6476
  *
6456
6477
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
6457
6478
  *
6479
+ * @category Search
6458
6480
  * @param query The search query as either a string or a structured search object.
6459
6481
  * @returns Promise to the search result bundle.
6460
6482
  */
@@ -6477,6 +6499,7 @@
6477
6499
  *
6478
6500
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
6479
6501
  *
6502
+ * @category Search
6480
6503
  * @param query The search query as either a string or a structured search object.
6481
6504
  * @returns Promise to the search result bundle.
6482
6505
  */
@@ -6509,6 +6532,7 @@
6509
6532
  *
6510
6533
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
6511
6534
  *
6535
+ * @category Search
6512
6536
  * @param query The search query as either a string or a structured search object.
6513
6537
  * @returns Promise to the search result bundle.
6514
6538
  */
@@ -6526,6 +6550,8 @@
6526
6550
  /**
6527
6551
  * Searches a ValueSet resource using the "expand" operation.
6528
6552
  * See: https://www.hl7.org/fhir/operation-valueset-expand.html
6553
+ *
6554
+ * @category Search
6529
6555
  * @param system The ValueSet system url.
6530
6556
  * @param filter The search string.
6531
6557
  * @returns Promise to expanded ValueSet.
@@ -6538,6 +6564,7 @@
6538
6564
  }
6539
6565
  /**
6540
6566
  * Returns a cached resource if it is available.
6567
+ * @category Caching
6541
6568
  * @param resourceType The FHIR resource type.
6542
6569
  * @param id The FHIR resource ID.
6543
6570
  * @returns The resource if it is available in the cache; undefined otherwise.
@@ -6549,6 +6576,7 @@
6549
6576
  }
6550
6577
  /**
6551
6578
  * Returns a cached resource if it is available.
6579
+ * @category Caching
6552
6580
  * @param resourceType The FHIR resource type.
6553
6581
  * @param id The FHIR resource ID.
6554
6582
  * @returns The resource if it is available in the cache; undefined otherwise.
@@ -6576,6 +6604,7 @@
6576
6604
  *
6577
6605
  * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
6578
6606
  *
6607
+ * @category Caching
6579
6608
  * @param resourceType The FHIR resource type.
6580
6609
  * @param id The resource ID.
6581
6610
  * @returns The resource if available; undefined otherwise.
@@ -6598,6 +6627,7 @@
6598
6627
  *
6599
6628
  * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
6600
6629
  *
6630
+ * @category Read
6601
6631
  * @param reference The FHIR reference object.
6602
6632
  * @returns The resource if available; undefined otherwise.
6603
6633
  */
@@ -6616,6 +6646,7 @@
6616
6646
  * Returns a cached schema for a resource type.
6617
6647
  * If the schema is not cached, returns undefined.
6618
6648
  * It is assumed that a client will call requestSchema before using this method.
6649
+ * @category Schema
6619
6650
  * @param resourceType The FHIR resource type.
6620
6651
  * @returns The schema if immediately available, undefined otherwise.
6621
6652
  * @deprecated Use globalSchema instead.
@@ -6626,6 +6657,7 @@
6626
6657
  /**
6627
6658
  * Requests the schema for a resource type.
6628
6659
  * If the schema is already cached, the promise is resolved immediately.
6660
+ * @category Schema
6629
6661
  * @param resourceType The FHIR resource type.
6630
6662
  * @returns Promise to a schema with the requested resource type.
6631
6663
  */
@@ -6687,6 +6719,7 @@
6687
6719
  *
6688
6720
  * See the FHIR "history" operation for full details: https://www.hl7.org/fhir/http.html#history
6689
6721
  *
6722
+ * @category Read
6690
6723
  * @param resourceType The FHIR resource type.
6691
6724
  * @param id The resource ID.
6692
6725
  * @returns Promise to the resource history.
@@ -6706,6 +6739,7 @@
6706
6739
  *
6707
6740
  * See the FHIR "vread" operation for full details: https://www.hl7.org/fhir/http.html#vread
6708
6741
  *
6742
+ * @category Read
6709
6743
  * @param resourceType The FHIR resource type.
6710
6744
  * @param id The resource ID.
6711
6745
  * @returns The resource if available; undefined otherwise.
@@ -6713,6 +6747,12 @@
6713
6747
  readVersion(resourceType, id, vid) {
6714
6748
  return this.get(this.fhirUrl(resourceType, id, '_history', vid));
6715
6749
  }
6750
+ /**
6751
+ *
6752
+ * @category Read
6753
+ * @param id The Patient Id
6754
+ * @returns A Bundle of all Resources related to the Patient
6755
+ */
6716
6756
  readPatientEverything(id) {
6717
6757
  return this.get(this.fhirUrl('Patient', id, '$everything'));
6718
6758
  }
@@ -6736,6 +6776,7 @@
6736
6776
  *
6737
6777
  * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
6738
6778
  *
6779
+ * @category Create
6739
6780
  * @param resource The FHIR resource to create.
6740
6781
  * @returns The result of the create operation.
6741
6782
  */
@@ -6780,6 +6821,7 @@
6780
6821
  *
6781
6822
  * See the FHIR "conditional create" operation for full details: https://www.hl7.org/fhir/http.html#ccreate
6782
6823
  *
6824
+ * @category Create
6783
6825
  * @param resource The FHIR resource to create.
6784
6826
  * @param query The search query for an equivalent resource.
6785
6827
  * @returns The result of the create operation.
@@ -6808,6 +6850,7 @@
6808
6850
  *
6809
6851
  * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
6810
6852
  *
6853
+ * @category Create
6811
6854
  * @param data The binary data to upload.
6812
6855
  * @param filename Optional filename for the binary.
6813
6856
  * @param contentType Content type for the binary.
@@ -6838,6 +6881,7 @@
6838
6881
  *
6839
6882
  * See the pdfmake document definition for full details: https://pdfmake.github.io/docs/0.1/document-definition-object/
6840
6883
  *
6884
+ * @category Media
6841
6885
  * @param docDefinition The PDF document definition.
6842
6886
  * @returns The result of the create operation.
6843
6887
  */
@@ -6855,6 +6899,7 @@
6855
6899
  *
6856
6900
  * This is a convenience method to handle commmon cases where a `Communication` resource is created with a `payload`.
6857
6901
  *
6902
+ * @category Create
6858
6903
  * @param resource The FHIR resource to comment on.
6859
6904
  * @param text The text of the comment.
6860
6905
  * @returns The result of the create operation.
@@ -6905,6 +6950,7 @@
6905
6950
  *
6906
6951
  * See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#update
6907
6952
  *
6953
+ * @category Write
6908
6954
  * @param resource The FHIR resource to update.
6909
6955
  * @returns The result of the update operation.
6910
6956
  */
@@ -6936,6 +6982,7 @@
6936
6982
  *
6937
6983
  * See the JSONPatch specification for full details: https://tools.ietf.org/html/rfc6902
6938
6984
  *
6985
+ * @category Write
6939
6986
  * @param resourceType The FHIR resource type.
6940
6987
  * @param id The resource ID.
6941
6988
  * @param operations The JSONPatch operations.
@@ -6956,6 +7003,7 @@
6956
7003
  *
6957
7004
  * See the FHIR "delete" operation for full details: https://www.hl7.org/fhir/http.html#delete
6958
7005
  *
7006
+ * @category Delete
6959
7007
  * @param resourceType The FHIR resource type.
6960
7008
  * @param id The resource ID.
6961
7009
  * @returns The result of the delete operation.
@@ -6964,6 +7012,56 @@
6964
7012
  this.invalidateSearches(resourceType);
6965
7013
  return this.delete(this.fhirUrl(resourceType, id));
6966
7014
  }
7015
+ /**
7016
+ * Executes a batch or transaction of FHIR operations.
7017
+ *
7018
+ * Example:
7019
+ *
7020
+ * ```typescript
7021
+ * await medplum.executeBatch({
7022
+ * "resourceType": "Bundle",
7023
+ * "type": "transaction",
7024
+ * "entry": [
7025
+ * {
7026
+ * "fullUrl": "urn:uuid:61ebe359-bfdc-4613-8bf2-c5e300945f0a",
7027
+ * "resource": {
7028
+ * "resourceType": "Patient",
7029
+ * "name": [{ "use": "official", "given": ["Alice"], "family": "Smith" }],
7030
+ * "gender": "female",
7031
+ * "birthDate": "1974-12-25"
7032
+ * },
7033
+ * "request": {
7034
+ * "method": "POST",
7035
+ * "url": "Patient"
7036
+ * }
7037
+ * },
7038
+ * {
7039
+ * "fullUrl": "urn:uuid:88f151c0-a954-468a-88bd-5ae15c08e059",
7040
+ * "resource": {
7041
+ * "resourceType": "Patient",
7042
+ * "identifier": [{ "system": "http:/example.org/fhir/ids", "value": "234234" }],
7043
+ * "name": [{ "use": "official", "given": ["Bob"], "family": "Jones" }],
7044
+ * "gender": "male",
7045
+ * "birthDate": "1974-12-25"
7046
+ * },
7047
+ * "request": {
7048
+ * "method": "POST",
7049
+ * "url": "Patient",
7050
+ * "ifNoneExist": "identifier=http:/example.org/fhir/ids|234234"
7051
+ * }
7052
+ * }
7053
+ * ]
7054
+ * });
7055
+ * ```
7056
+ *
7057
+ * See The FHIR "batch/transaction" section for full details: https://hl7.org/fhir/http.html#transaction
7058
+ * @category Batch
7059
+ * @param bundle The FHIR batch/transaction bundle.
7060
+ * @returns The FHIR batch/transaction response bundle.
7061
+ */
7062
+ executeBatch(bundle) {
7063
+ return this.post('fhir/R4', bundle);
7064
+ }
6967
7065
  /**
6968
7066
  * Sends an email using the Medplum Email API.
6969
7067
  *
@@ -6997,7 +7095,7 @@
6997
7095
  * ```
6998
7096
  *
6999
7097
  * See options here: https://nodemailer.com/extras/mailcomposer/
7000
- *
7098
+ * @category Media
7001
7099
  * @param options The MailComposer options.
7002
7100
  * @returns Promise to the operation outcome.
7003
7101
  */
@@ -7045,6 +7143,7 @@
7045
7143
  *
7046
7144
  * See the FHIR GraphQL documentation for FHIR specific details: https://www.hl7.org/fhir/graphql.html
7047
7145
  *
7146
+ * @category Read
7048
7147
  * @param query The GraphQL query.
7049
7148
  * @param operationName Optional GraphQL operation name.
7050
7149
  * @param variables Optional GraphQL variables.
@@ -7054,9 +7153,16 @@
7054
7153
  graphql(query, operationName, variables, options) {
7055
7154
  return this.post(this.fhirUrl('$graphql'), { query, operationName, variables }, JSON_CONTENT_TYPE, options);
7056
7155
  }
7156
+ /**
7157
+ * @category Authentication
7158
+ * @returns The Login State
7159
+ */
7057
7160
  getActiveLogin() {
7058
7161
  return __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('activeLogin');
7059
7162
  }
7163
+ /**
7164
+ * @category Authentication
7165
+ */
7060
7166
  setActiveLogin(login) {
7061
7167
  return __awaiter(this, void 0, void 0, function* () {
7062
7168
  __classPrivateFieldSet(this, _MedplumClient_accessToken, login.accessToken, "f");
@@ -7070,25 +7176,43 @@
7070
7176
  yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this);
7071
7177
  });
7072
7178
  }
7179
+ /**
7180
+ * @category Authentication
7181
+ */
7073
7182
  getAccessToken() {
7074
7183
  return __classPrivateFieldGet(this, _MedplumClient_accessToken, "f");
7075
7184
  }
7185
+ /**
7186
+ * @category Authentication
7187
+ */
7076
7188
  setAccessToken(accessToken) {
7077
7189
  __classPrivateFieldSet(this, _MedplumClient_accessToken, accessToken, "f");
7078
7190
  __classPrivateFieldSet(this, _MedplumClient_refreshToken, undefined, "f");
7079
7191
  __classPrivateFieldSet(this, _MedplumClient_profile, undefined, "f");
7080
7192
  __classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
7081
7193
  }
7194
+ /**
7195
+ * @category Authentication
7196
+ */
7082
7197
  getLogins() {
7083
7198
  var _a;
7084
7199
  return (_a = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins')) !== null && _a !== void 0 ? _a : [];
7085
7200
  }
7201
+ /**
7202
+ * @category Authentication
7203
+ */
7086
7204
  isLoading() {
7087
7205
  return !!__classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
7088
7206
  }
7207
+ /**
7208
+ * @category User Profile
7209
+ */
7089
7210
  getProfile() {
7090
7211
  return __classPrivateFieldGet(this, _MedplumClient_profile, "f");
7091
7212
  }
7213
+ /**
7214
+ * @category User Profile
7215
+ */
7092
7216
  getProfileAsync() {
7093
7217
  return __awaiter(this, void 0, void 0, function* () {
7094
7218
  if (__classPrivateFieldGet(this, _MedplumClient_profilePromise, "f")) {
@@ -7097,11 +7221,16 @@
7097
7221
  return this.getProfile();
7098
7222
  });
7099
7223
  }
7224
+ /**
7225
+ * @category User Profile
7226
+ */
7100
7227
  getUserConfiguration() {
7101
7228
  return __classPrivateFieldGet(this, _MedplumClient_config, "f");
7102
7229
  }
7103
7230
  /**
7104
7231
  * Downloads the URL as a blob.
7232
+ *
7233
+ * @category Read
7105
7234
  * @param url The URL to request.
7106
7235
  * @returns Promise to the response body as a blob.
7107
7236
  */
@@ -7142,6 +7271,7 @@
7142
7271
  /**
7143
7272
  * Starts a new OAuth2 client credentials flow.
7144
7273
  * See: https://datatracker.ietf.org/doc/html/rfc6749#section-4.4
7274
+ * @category Authentication
7145
7275
  * @param clientId The client ID.
7146
7276
  * @param clientSecret The client secret.
7147
7277
  * @returns Promise that resolves to the client profile.
@@ -7349,6 +7479,7 @@
7349
7479
  };
7350
7480
  /**
7351
7481
  * Returns the base URL for the current page.
7482
+ * @category HTTP
7352
7483
  */
7353
7484
  function getBaseUrl() {
7354
7485
  return window.location.protocol + '//' + window.location.host + '/';