@medplum/core 0.9.20 → 0.9.23

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.
@@ -6332,18 +6342,53 @@
6332
6342
  return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'DELETE', url, options);
6333
6343
  }
6334
6344
  /**
6335
- * Tries to register a new user.
6336
- * @param request The registration request.
6345
+ * Initiates a new user flow.
6346
+ *
6347
+ * This method is part of the two different user registration flows:
6348
+ * 1) New Practitioner and new Project
6349
+ * 2) New Patient registration
6350
+ *
6351
+ * @category Authentication
6352
+ * @param registerRequest Register request including email and password.
6337
6353
  * @returns Promise to the authentication response.
6338
6354
  */
6339
- register(request) {
6355
+ startNewUser(registerRequest) {
6340
6356
  return __awaiter(this, void 0, void 0, function* () {
6341
- const response = yield this.post('auth/register', request);
6342
- yield this.setActiveLogin(response);
6357
+ yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
6358
+ return this.post('auth/newuser', Object.assign(Object.assign({}, registerRequest), { codeChallengeMethod: 'S256', codeChallenge: __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge') }));
6359
+ });
6360
+ }
6361
+ /**
6362
+ * Initiates a new project flow.
6363
+ *
6364
+ * This requires a partial login from `startNewUser` or `startNewGoogleUser`.
6365
+ *
6366
+ * @param registerRequest Register request including email and password.
6367
+ * @param login The partial login to complete. This should come from the `startNewUser` method.
6368
+ * @returns Promise to the authentication response.
6369
+ */
6370
+ startNewProject(registerRequest, login) {
6371
+ return __awaiter(this, void 0, void 0, function* () {
6372
+ return this.post('auth/newproject', Object.assign(Object.assign({}, registerRequest), login));
6373
+ });
6374
+ }
6375
+ /**
6376
+ * Initiates a new patient flow.
6377
+ *
6378
+ * This requires a partial login from `startNewUser` or `startNewGoogleUser`.
6379
+ *
6380
+ * @param registerRequest Register request including email and password.
6381
+ * @param login The partial login to complete. This should come from the `startNewUser` method.
6382
+ * @returns Promise to the authentication response.
6383
+ */
6384
+ startNewPatient(registerRequest, login) {
6385
+ return __awaiter(this, void 0, void 0, function* () {
6386
+ return this.post('auth/newpatient', Object.assign(Object.assign({}, registerRequest), login));
6343
6387
  });
6344
6388
  }
6345
6389
  /**
6346
6390
  * Initiates a user login flow.
6391
+ * @category Authentication
6347
6392
  * @param loginRequest Login request including email and password.
6348
6393
  * @returns Promise to the authentication response.
6349
6394
  */
@@ -6358,6 +6403,7 @@
6358
6403
  * Tries to sign in with Google authentication.
6359
6404
  * The response parameter is the result of a Google authentication.
6360
6405
  * See: https://developers.google.com/identity/gsi/web/guides/handle-credential-responses-js-functions
6406
+ * @category Authentication
6361
6407
  * @param loginRequest Login request including Google credential response.
6362
6408
  * @returns Promise to the authentication response.
6363
6409
  */
@@ -6371,6 +6417,7 @@
6371
6417
  /**
6372
6418
  * Signs out locally.
6373
6419
  * Does not invalidate tokens with the server.
6420
+ * @category Authentication
6374
6421
  */
6375
6422
  signOut() {
6376
6423
  this.clear();
@@ -6380,6 +6427,7 @@
6380
6427
  * Tries to sign in the user.
6381
6428
  * Returns true if the user is signed in.
6382
6429
  * This may result in navigating away to the sign in page.
6430
+ * @category Authentication
6383
6431
  */
6384
6432
  signInWithRedirect() {
6385
6433
  const urlParams = new URLSearchParams(window.location.search);
@@ -6395,6 +6443,7 @@
6395
6443
  /**
6396
6444
  * Tries to sign out the user.
6397
6445
  * See: https://docs.aws.amazon.com/cognito/latest/developerguide/logout-endpoint.html
6446
+ * @category Authentication
6398
6447
  */
6399
6448
  signOutWithRedirect() {
6400
6449
  window.location.assign(__classPrivateFieldGet(this, _MedplumClient_logoutUrl, "f"));
@@ -6402,6 +6451,7 @@
6402
6451
  /**
6403
6452
  * Builds a FHIR URL from a collection of URL path components.
6404
6453
  * For example, `buildUrl('/Patient', '123')` returns `fhir/R4/Patient/123`.
6454
+ * @category HTTP
6405
6455
  * @param path The path component of the URL.
6406
6456
  * @returns The well-formed FHIR URL.
6407
6457
  */
@@ -6410,6 +6460,8 @@
6410
6460
  }
6411
6461
  /**
6412
6462
  * Builds a FHIR search URL from a search query or structured query object.
6463
+ * @category HTTP
6464
+ * @category Search
6413
6465
  * @param query The FHIR search query or structured query object.
6414
6466
  * @returns The well-formed FHIR URL.
6415
6467
  */
@@ -6457,6 +6509,7 @@
6457
6509
  *
6458
6510
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
6459
6511
  *
6512
+ * @category Search
6460
6513
  * @param query The search query as either a string or a structured search object.
6461
6514
  * @returns Promise to the search result bundle.
6462
6515
  */
@@ -6479,6 +6532,7 @@
6479
6532
  *
6480
6533
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
6481
6534
  *
6535
+ * @category Search
6482
6536
  * @param query The search query as either a string or a structured search object.
6483
6537
  * @returns Promise to the search result bundle.
6484
6538
  */
@@ -6511,6 +6565,7 @@
6511
6565
  *
6512
6566
  * See FHIR search for full details: https://www.hl7.org/fhir/search.html
6513
6567
  *
6568
+ * @category Search
6514
6569
  * @param query The search query as either a string or a structured search object.
6515
6570
  * @returns Promise to the search result bundle.
6516
6571
  */
@@ -6528,6 +6583,8 @@
6528
6583
  /**
6529
6584
  * Searches a ValueSet resource using the "expand" operation.
6530
6585
  * See: https://www.hl7.org/fhir/operation-valueset-expand.html
6586
+ *
6587
+ * @category Search
6531
6588
  * @param system The ValueSet system url.
6532
6589
  * @param filter The search string.
6533
6590
  * @returns Promise to expanded ValueSet.
@@ -6540,6 +6597,7 @@
6540
6597
  }
6541
6598
  /**
6542
6599
  * Returns a cached resource if it is available.
6600
+ * @category Caching
6543
6601
  * @param resourceType The FHIR resource type.
6544
6602
  * @param id The FHIR resource ID.
6545
6603
  * @returns The resource if it is available in the cache; undefined otherwise.
@@ -6551,6 +6609,7 @@
6551
6609
  }
6552
6610
  /**
6553
6611
  * Returns a cached resource if it is available.
6612
+ * @category Caching
6554
6613
  * @param resourceType The FHIR resource type.
6555
6614
  * @param id The FHIR resource ID.
6556
6615
  * @returns The resource if it is available in the cache; undefined otherwise.
@@ -6578,6 +6637,7 @@
6578
6637
  *
6579
6638
  * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
6580
6639
  *
6640
+ * @category Caching
6581
6641
  * @param resourceType The FHIR resource type.
6582
6642
  * @param id The resource ID.
6583
6643
  * @returns The resource if available; undefined otherwise.
@@ -6600,6 +6660,7 @@
6600
6660
  *
6601
6661
  * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
6602
6662
  *
6663
+ * @category Read
6603
6664
  * @param reference The FHIR reference object.
6604
6665
  * @returns The resource if available; undefined otherwise.
6605
6666
  */
@@ -6618,6 +6679,7 @@
6618
6679
  * Returns a cached schema for a resource type.
6619
6680
  * If the schema is not cached, returns undefined.
6620
6681
  * It is assumed that a client will call requestSchema before using this method.
6682
+ * @category Schema
6621
6683
  * @param resourceType The FHIR resource type.
6622
6684
  * @returns The schema if immediately available, undefined otherwise.
6623
6685
  * @deprecated Use globalSchema instead.
@@ -6628,6 +6690,7 @@
6628
6690
  /**
6629
6691
  * Requests the schema for a resource type.
6630
6692
  * If the schema is already cached, the promise is resolved immediately.
6693
+ * @category Schema
6631
6694
  * @param resourceType The FHIR resource type.
6632
6695
  * @returns Promise to a schema with the requested resource type.
6633
6696
  */
@@ -6689,6 +6752,7 @@
6689
6752
  *
6690
6753
  * See the FHIR "history" operation for full details: https://www.hl7.org/fhir/http.html#history
6691
6754
  *
6755
+ * @category Read
6692
6756
  * @param resourceType The FHIR resource type.
6693
6757
  * @param id The resource ID.
6694
6758
  * @returns Promise to the resource history.
@@ -6708,6 +6772,7 @@
6708
6772
  *
6709
6773
  * See the FHIR "vread" operation for full details: https://www.hl7.org/fhir/http.html#vread
6710
6774
  *
6775
+ * @category Read
6711
6776
  * @param resourceType The FHIR resource type.
6712
6777
  * @param id The resource ID.
6713
6778
  * @returns The resource if available; undefined otherwise.
@@ -6715,6 +6780,12 @@
6715
6780
  readVersion(resourceType, id, vid) {
6716
6781
  return this.get(this.fhirUrl(resourceType, id, '_history', vid));
6717
6782
  }
6783
+ /**
6784
+ *
6785
+ * @category Read
6786
+ * @param id The Patient Id
6787
+ * @returns A Bundle of all Resources related to the Patient
6788
+ */
6718
6789
  readPatientEverything(id) {
6719
6790
  return this.get(this.fhirUrl('Patient', id, '$everything'));
6720
6791
  }
@@ -6738,6 +6809,7 @@
6738
6809
  *
6739
6810
  * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
6740
6811
  *
6812
+ * @category Create
6741
6813
  * @param resource The FHIR resource to create.
6742
6814
  * @returns The result of the create operation.
6743
6815
  */
@@ -6782,6 +6854,7 @@
6782
6854
  *
6783
6855
  * See the FHIR "conditional create" operation for full details: https://www.hl7.org/fhir/http.html#ccreate
6784
6856
  *
6857
+ * @category Create
6785
6858
  * @param resource The FHIR resource to create.
6786
6859
  * @param query The search query for an equivalent resource.
6787
6860
  * @returns The result of the create operation.
@@ -6810,6 +6883,7 @@
6810
6883
  *
6811
6884
  * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
6812
6885
  *
6886
+ * @category Create
6813
6887
  * @param data The binary data to upload.
6814
6888
  * @param filename Optional filename for the binary.
6815
6889
  * @param contentType Content type for the binary.
@@ -6840,6 +6914,7 @@
6840
6914
  *
6841
6915
  * See the pdfmake document definition for full details: https://pdfmake.github.io/docs/0.1/document-definition-object/
6842
6916
  *
6917
+ * @category Media
6843
6918
  * @param docDefinition The PDF document definition.
6844
6919
  * @returns The result of the create operation.
6845
6920
  */
@@ -6857,6 +6932,7 @@
6857
6932
  *
6858
6933
  * This is a convenience method to handle commmon cases where a `Communication` resource is created with a `payload`.
6859
6934
  *
6935
+ * @category Create
6860
6936
  * @param resource The FHIR resource to comment on.
6861
6937
  * @param text The text of the comment.
6862
6938
  * @returns The result of the create operation.
@@ -6907,6 +6983,7 @@
6907
6983
  *
6908
6984
  * See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#update
6909
6985
  *
6986
+ * @category Write
6910
6987
  * @param resource The FHIR resource to update.
6911
6988
  * @returns The result of the update operation.
6912
6989
  */
@@ -6938,6 +7015,7 @@
6938
7015
  *
6939
7016
  * See the JSONPatch specification for full details: https://tools.ietf.org/html/rfc6902
6940
7017
  *
7018
+ * @category Write
6941
7019
  * @param resourceType The FHIR resource type.
6942
7020
  * @param id The resource ID.
6943
7021
  * @param operations The JSONPatch operations.
@@ -6958,6 +7036,7 @@
6958
7036
  *
6959
7037
  * See the FHIR "delete" operation for full details: https://www.hl7.org/fhir/http.html#delete
6960
7038
  *
7039
+ * @category Delete
6961
7040
  * @param resourceType The FHIR resource type.
6962
7041
  * @param id The resource ID.
6963
7042
  * @returns The result of the delete operation.
@@ -6966,6 +7045,56 @@
6966
7045
  this.invalidateSearches(resourceType);
6967
7046
  return this.delete(this.fhirUrl(resourceType, id));
6968
7047
  }
7048
+ /**
7049
+ * Executes a batch or transaction of FHIR operations.
7050
+ *
7051
+ * Example:
7052
+ *
7053
+ * ```typescript
7054
+ * await medplum.executeBatch({
7055
+ * "resourceType": "Bundle",
7056
+ * "type": "transaction",
7057
+ * "entry": [
7058
+ * {
7059
+ * "fullUrl": "urn:uuid:61ebe359-bfdc-4613-8bf2-c5e300945f0a",
7060
+ * "resource": {
7061
+ * "resourceType": "Patient",
7062
+ * "name": [{ "use": "official", "given": ["Alice"], "family": "Smith" }],
7063
+ * "gender": "female",
7064
+ * "birthDate": "1974-12-25"
7065
+ * },
7066
+ * "request": {
7067
+ * "method": "POST",
7068
+ * "url": "Patient"
7069
+ * }
7070
+ * },
7071
+ * {
7072
+ * "fullUrl": "urn:uuid:88f151c0-a954-468a-88bd-5ae15c08e059",
7073
+ * "resource": {
7074
+ * "resourceType": "Patient",
7075
+ * "identifier": [{ "system": "http:/example.org/fhir/ids", "value": "234234" }],
7076
+ * "name": [{ "use": "official", "given": ["Bob"], "family": "Jones" }],
7077
+ * "gender": "male",
7078
+ * "birthDate": "1974-12-25"
7079
+ * },
7080
+ * "request": {
7081
+ * "method": "POST",
7082
+ * "url": "Patient",
7083
+ * "ifNoneExist": "identifier=http:/example.org/fhir/ids|234234"
7084
+ * }
7085
+ * }
7086
+ * ]
7087
+ * });
7088
+ * ```
7089
+ *
7090
+ * See The FHIR "batch/transaction" section for full details: https://hl7.org/fhir/http.html#transaction
7091
+ * @category Batch
7092
+ * @param bundle The FHIR batch/transaction bundle.
7093
+ * @returns The FHIR batch/transaction response bundle.
7094
+ */
7095
+ executeBatch(bundle) {
7096
+ return this.post('fhir/R4', bundle);
7097
+ }
6969
7098
  /**
6970
7099
  * Sends an email using the Medplum Email API.
6971
7100
  *
@@ -6999,7 +7128,7 @@
6999
7128
  * ```
7000
7129
  *
7001
7130
  * See options here: https://nodemailer.com/extras/mailcomposer/
7002
- *
7131
+ * @category Media
7003
7132
  * @param options The MailComposer options.
7004
7133
  * @returns Promise to the operation outcome.
7005
7134
  */
@@ -7047,6 +7176,7 @@
7047
7176
  *
7048
7177
  * See the FHIR GraphQL documentation for FHIR specific details: https://www.hl7.org/fhir/graphql.html
7049
7178
  *
7179
+ * @category Read
7050
7180
  * @param query The GraphQL query.
7051
7181
  * @param operationName Optional GraphQL operation name.
7052
7182
  * @param variables Optional GraphQL variables.
@@ -7056,9 +7186,16 @@
7056
7186
  graphql(query, operationName, variables, options) {
7057
7187
  return this.post(this.fhirUrl('$graphql'), { query, operationName, variables }, JSON_CONTENT_TYPE, options);
7058
7188
  }
7189
+ /**
7190
+ * @category Authentication
7191
+ * @returns The Login State
7192
+ */
7059
7193
  getActiveLogin() {
7060
7194
  return __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('activeLogin');
7061
7195
  }
7196
+ /**
7197
+ * @category Authentication
7198
+ */
7062
7199
  setActiveLogin(login) {
7063
7200
  return __awaiter(this, void 0, void 0, function* () {
7064
7201
  __classPrivateFieldSet(this, _MedplumClient_accessToken, login.accessToken, "f");
@@ -7072,25 +7209,43 @@
7072
7209
  yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this);
7073
7210
  });
7074
7211
  }
7212
+ /**
7213
+ * @category Authentication
7214
+ */
7075
7215
  getAccessToken() {
7076
7216
  return __classPrivateFieldGet(this, _MedplumClient_accessToken, "f");
7077
7217
  }
7218
+ /**
7219
+ * @category Authentication
7220
+ */
7078
7221
  setAccessToken(accessToken) {
7079
7222
  __classPrivateFieldSet(this, _MedplumClient_accessToken, accessToken, "f");
7080
7223
  __classPrivateFieldSet(this, _MedplumClient_refreshToken, undefined, "f");
7081
7224
  __classPrivateFieldSet(this, _MedplumClient_profile, undefined, "f");
7082
7225
  __classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
7083
7226
  }
7227
+ /**
7228
+ * @category Authentication
7229
+ */
7084
7230
  getLogins() {
7085
7231
  var _a;
7086
7232
  return (_a = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins')) !== null && _a !== void 0 ? _a : [];
7087
7233
  }
7234
+ /**
7235
+ * @category Authentication
7236
+ */
7088
7237
  isLoading() {
7089
7238
  return !!__classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
7090
7239
  }
7240
+ /**
7241
+ * @category User Profile
7242
+ */
7091
7243
  getProfile() {
7092
7244
  return __classPrivateFieldGet(this, _MedplumClient_profile, "f");
7093
7245
  }
7246
+ /**
7247
+ * @category User Profile
7248
+ */
7094
7249
  getProfileAsync() {
7095
7250
  return __awaiter(this, void 0, void 0, function* () {
7096
7251
  if (__classPrivateFieldGet(this, _MedplumClient_profilePromise, "f")) {
@@ -7099,11 +7254,16 @@
7099
7254
  return this.getProfile();
7100
7255
  });
7101
7256
  }
7257
+ /**
7258
+ * @category User Profile
7259
+ */
7102
7260
  getUserConfiguration() {
7103
7261
  return __classPrivateFieldGet(this, _MedplumClient_config, "f");
7104
7262
  }
7105
7263
  /**
7106
7264
  * Downloads the URL as a blob.
7265
+ *
7266
+ * @category Read
7107
7267
  * @param url The URL to request.
7108
7268
  * @returns Promise to the response body as a blob.
7109
7269
  */
@@ -7144,6 +7304,7 @@
7144
7304
  /**
7145
7305
  * Starts a new OAuth2 client credentials flow.
7146
7306
  * See: https://datatracker.ietf.org/doc/html/rfc6749#section-4.4
7307
+ * @category Authentication
7147
7308
  * @param clientId The client ID.
7148
7309
  * @param clientSecret The client secret.
7149
7310
  * @returns Promise that resolves to the client profile.
@@ -7351,6 +7512,7 @@
7351
7512
  };
7352
7513
  /**
7353
7514
  * Returns the base URL for the current page.
7515
+ * @category HTTP
7354
7516
  */
7355
7517
  function getBaseUrl() {
7356
7518
  return window.location.protocol + '//' + window.location.host + '/';
@@ -10689,6 +10851,7 @@
10689
10851
  exports.notFound = notFound;
10690
10852
  exports.notModified = notModified;
10691
10853
  exports.parseFhirPath = parseFhirPath;
10854
+ exports.parseJWTPayload = parseJWTPayload;
10692
10855
  exports.parseSearchDefinition = parseSearchDefinition;
10693
10856
  exports.preciseEquals = preciseEquals;
10694
10857
  exports.preciseGreaterThan = preciseGreaterThan;