@medplum/core 0.5.2 → 0.9.0

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 (50) hide show
  1. package/dist/cjs/index.js +819 -60
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/index.min.js +1 -1
  4. package/dist/cjs/index.min.js.map +1 -1
  5. package/dist/esm/index.js +817 -61
  6. package/dist/esm/index.js.map +1 -1
  7. package/dist/esm/index.min.js +1 -1
  8. package/dist/esm/index.min.js.map +1 -1
  9. package/dist/types/client.d.ts +427 -13
  10. package/dist/types/fix-ro-iddentifiers.d.ts +0 -0
  11. package/dist/types/index.d.ts +1 -0
  12. package/dist/types/repo.d.ts +116 -0
  13. package/dist/types/search.d.ts +9 -12
  14. package/dist/types/utils.d.ts +21 -0
  15. package/docs/.nojekyll +1 -0
  16. package/docs/assets/highlight.css +92 -0
  17. package/docs/assets/icons.css +1043 -0
  18. package/docs/assets/icons.png +0 -0
  19. package/docs/assets/icons@2x.png +0 -0
  20. package/docs/assets/main.js +52 -0
  21. package/docs/assets/search.js +1 -0
  22. package/docs/assets/style.css +1414 -0
  23. package/docs/assets/widgets.png +0 -0
  24. package/docs/assets/widgets@2x.png +0 -0
  25. package/docs/classes/LegacyRepositoryClient.html +71 -0
  26. package/docs/classes/MedplumClient.html +324 -0
  27. package/docs/classes/OperationOutcomeError.html +6 -0
  28. package/docs/enums/Operator.html +5 -0
  29. package/docs/enums/PropertyType.html +5 -0
  30. package/docs/enums/SearchParameterType.html +1 -0
  31. package/docs/index.html +89 -0
  32. package/docs/interfaces/AddressFormatOptions.html +1 -0
  33. package/docs/interfaces/FetchLike.html +1 -0
  34. package/docs/interfaces/Filter.html +1 -0
  35. package/docs/interfaces/GoogleCredentialResponse.html +1 -0
  36. package/docs/interfaces/HumanNameFormatOptions.html +1 -0
  37. package/docs/interfaces/IndexedStructureDefinition.html +19 -0
  38. package/docs/interfaces/LoginAuthenticationResponse.html +1 -0
  39. package/docs/interfaces/LoginProfileResponse.html +1 -0
  40. package/docs/interfaces/LoginScopeResponse.html +1 -0
  41. package/docs/interfaces/LoginState.html +1 -0
  42. package/docs/interfaces/MedplumClientOptions.html +33 -0
  43. package/docs/interfaces/RegisterRequest.html +1 -0
  44. package/docs/interfaces/SearchParameterDetails.html +1 -0
  45. package/docs/interfaces/SearchRequest.html +1 -0
  46. package/docs/interfaces/SortRule.html +1 -0
  47. package/docs/interfaces/TokenResponse.html +1 -0
  48. package/docs/interfaces/TypeSchema.html +10 -0
  49. package/docs/modules.html +138 -0
  50. package/package.json +3 -2
package/dist/cjs/index.js CHANGED
@@ -173,6 +173,7 @@
173
173
  * @return Human friendly display string.
174
174
  */
175
175
  function getDisplayString(resource) {
176
+ var _a, _b;
176
177
  if (isProfileResource(resource)) {
177
178
  const profileName = getProfileResourceDisplayString(resource);
178
179
  if (profileName) {
@@ -185,6 +186,11 @@
185
186
  return deviceName;
186
187
  }
187
188
  }
189
+ if (resource.resourceType === 'Observation') {
190
+ if ('code' in resource && ((_a = resource.code) === null || _a === void 0 ? void 0 : _a.text)) {
191
+ return (_b = resource.code) === null || _b === void 0 ? void 0 : _b.text;
192
+ }
193
+ }
188
194
  if (resource.resourceType === 'User') {
189
195
  if (resource.email) {
190
196
  return resource.email;
@@ -229,12 +235,25 @@
229
235
  const photos = resource.photo;
230
236
  if (photos) {
231
237
  for (const photo of photos) {
232
- if (photo.url && photo.contentType && photo.contentType.startsWith('image/')) {
233
- return photo.url;
238
+ const url = getPhotoImageSrc(photo);
239
+ if (url) {
240
+ return url;
234
241
  }
235
242
  }
236
243
  }
237
244
  }
245
+ if (resource.resourceType === 'Bot' && resource.photo) {
246
+ const url = getPhotoImageSrc(resource.photo);
247
+ if (url) {
248
+ return url;
249
+ }
250
+ }
251
+ return undefined;
252
+ }
253
+ function getPhotoImageSrc(photo) {
254
+ if (photo.url && photo.contentType && photo.contentType.startsWith('image/')) {
255
+ return photo.url;
256
+ }
238
257
  return undefined;
239
258
  }
240
259
  /**
@@ -247,6 +266,55 @@
247
266
  function getDateProperty(date) {
248
267
  return date ? new Date(date) : undefined;
249
268
  }
269
+ /**
270
+ * Calculates the age in years from the birth date.
271
+ * @param birthDateStr The birth date or start date in ISO-8601 format YYYY-MM-DD.
272
+ * @param endDateStr Optional end date in ISO-8601 format YYYY-MM-DD. Default value is today.
273
+ * @returns The age in years, months, and days.
274
+ */
275
+ function calculateAge(birthDateStr, endDateStr) {
276
+ const startDate = new Date(birthDateStr);
277
+ startDate.setUTCHours(0, 0, 0, 0);
278
+ const endDate = endDateStr ? new Date(endDateStr) : new Date();
279
+ endDate.setUTCHours(0, 0, 0, 0);
280
+ const startYear = startDate.getUTCFullYear();
281
+ const startMonth = startDate.getUTCMonth();
282
+ const startDay = startDate.getUTCDate();
283
+ const endYear = endDate.getUTCFullYear();
284
+ const endMonth = endDate.getUTCMonth();
285
+ const endDay = endDate.getUTCDate();
286
+ let years = endYear - startYear;
287
+ if (endMonth < startMonth || (endMonth === startMonth && endDay < startDay)) {
288
+ years--;
289
+ }
290
+ let months = endYear * 12 + endMonth - (startYear * 12 + startMonth);
291
+ if (endDay < startDay) {
292
+ months--;
293
+ }
294
+ const days = Math.floor((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24));
295
+ return { years, months, days };
296
+ }
297
+ /**
298
+ * Calculates the age string for display using the age appropriate units.
299
+ * If the age is greater than or equal to 2 years, then the age is displayed in years.
300
+ * If the age is greater than or equal to 1 month, then the age is displayed in months.
301
+ * Otherwise, the age is displayed in days.
302
+ * @param birthDateStr The birth date or start date in ISO-8601 format YYYY-MM-DD.
303
+ * @param endDateStr Optional end date in ISO-8601 format YYYY-MM-DD. Default value is today.
304
+ * @returns The age string.
305
+ */
306
+ function calculateAgeString(birthDateStr, endDateStr) {
307
+ const { years, months, days } = calculateAge(birthDateStr, endDateStr);
308
+ if (years >= 2) {
309
+ return years.toString().padStart(3, '0') + 'Y';
310
+ }
311
+ else if (months >= 1) {
312
+ return months.toString().padStart(3, '0') + 'M';
313
+ }
314
+ else {
315
+ return days.toString().padStart(3, '0') + 'D';
316
+ }
317
+ }
250
318
  /**
251
319
  * FHIR JSON stringify.
252
320
  * Removes properties with empty string values.
@@ -267,7 +335,15 @@
267
335
  * @param {*} v Property value.
268
336
  */
269
337
  function stringifyReplacer(k, v) {
270
- return isEmpty(v) ? undefined : v;
338
+ return !isArrayKey(k) && isEmpty(v) ? undefined : v;
339
+ }
340
+ /**
341
+ * Returns true if the key is an array key.
342
+ * @param k The property key.
343
+ * @returns True if the key is an array key.
344
+ */
345
+ function isArrayKey(k) {
346
+ return !!k.match(/\d+$/);
271
347
  }
272
348
  /**
273
349
  * Returns true if the value is empty (null, undefined, empty string, or empty object).
@@ -420,7 +496,7 @@
420
496
  */
421
497
  function decodePayload(payload) {
422
498
  const cleanedPayload = payload.replace(/-/g, '+').replace(/_/g, '/');
423
- const decodedPayload = window.atob(cleanedPayload);
499
+ const decodedPayload = decodeBase64(cleanedPayload);
424
500
  const uriEncodedPayload = Array.from(decodedPayload).reduce((acc, char) => {
425
501
  const uriEncodedChar = ('00' + char.charCodeAt(0).toString(16)).slice(-2);
426
502
  return `${acc}%${uriEncodedChar}`;
@@ -428,6 +504,15 @@
428
504
  const jsonPayload = decodeURIComponent(uriEncodedPayload);
429
505
  return JSON.parse(jsonPayload);
430
506
  }
507
+ function decodeBase64(data) {
508
+ if (typeof window !== 'undefined') {
509
+ return window.atob(data);
510
+ }
511
+ if (typeof Buffer !== 'undefined') {
512
+ return Buffer.from(data, 'base64').toString('binary');
513
+ }
514
+ throw new Error('Unable to decode base64');
515
+ }
431
516
  /**
432
517
  * Parses the JWT payload.
433
518
  * @param token JWT token
@@ -640,10 +725,11 @@
640
725
  *
641
726
  * See the FHIR search spec: http://hl7.org/fhir/r4/search.html
642
727
  *
643
- * @param location The URL to parse.
728
+ * @param url The URL to parse.
644
729
  * @returns Parsed search definition.
645
730
  */
646
- function parseSearchDefinition(location) {
731
+ function parseSearchDefinition(url) {
732
+ const location = new URL(url, 'https://example.com/');
647
733
  const resourceType = location.pathname
648
734
  .replace(/(^\/)|(\/$)/g, '') // Remove leading and trailing slashes
649
735
  .split('/')
@@ -1072,13 +1158,61 @@
1072
1158
 
1073
1159
  // PKCE auth ased on:
1074
1160
  // https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
1075
- var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_storage, _MedplumClient_schema, _MedplumClient_resourceCache, _MedplumClient_baseUrl, _MedplumClient_clientId, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_request, _MedplumClient_buildFetchOptions, _MedplumClient_handleUnauthenticated, _MedplumClient_startPkce, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
1161
+ var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_storage, _MedplumClient_schema, _MedplumClient_resourceCache, _MedplumClient_baseUrl, _MedplumClient_clientId, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_request, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_startPkce, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
1076
1162
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
1077
1163
  const DEFAULT_SCOPE = 'launch/patient openid fhirUser offline_access user/*.*';
1078
1164
  const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
1079
1165
  const JSON_CONTENT_TYPE = 'application/json';
1080
1166
  const FHIR_CONTENT_TYPE = 'application/fhir+json';
1081
1167
  const PATCH_CONTENT_TYPE = 'application/json-patch+json';
1168
+ /**
1169
+ * The MedplumClient class provides a client for the Medplum FHIR server.
1170
+ *
1171
+ * The client can be used in the browser, in a NodeJS application, or in a Medplum Bot.
1172
+ *
1173
+ * The client provides helpful methods for common operations such as:
1174
+ * 1) Authenticating
1175
+ * 2) Creating resources
1176
+ * 2) Reading resources
1177
+ * 3) Updating resources
1178
+ * 5) Deleting resources
1179
+ * 6) Searching
1180
+ * 7) Making GraphQL queries
1181
+ *
1182
+ * Here is a quick example of how to use the client:
1183
+ *
1184
+ * ```typescript
1185
+ * import { MedplumClient } from '@medplum/core';
1186
+ * const medplum = new MedplumClient();
1187
+ * ```
1188
+ *
1189
+ * Create a `Patient`:
1190
+ *
1191
+ * ```typescript
1192
+ * const patient = await medplum.createResource({
1193
+ * resourceType: 'Patient',
1194
+ * name: [{
1195
+ * given: ['Alice'],
1196
+ * family: 'Smith'
1197
+ * }]
1198
+ * });
1199
+ * ```
1200
+ *
1201
+ * Read a `Patient` by ID:
1202
+ *
1203
+ * ```typescript
1204
+ * const patient = await medplum.readResource('Patient', '123');
1205
+ * console.log(patient.name[0].given[0]);
1206
+ * ```
1207
+ *
1208
+ * Search for a `Patient` by name:
1209
+ *
1210
+ * ```typescript
1211
+ * const bundle = await medplum.search('Patient?name=Alice');
1212
+ * console.log(bundle.total);
1213
+ * ```
1214
+ *
1215
+ */
1082
1216
  class MedplumClient extends EventTarget {
1083
1217
  constructor(options) {
1084
1218
  var _a;
@@ -1138,17 +1272,94 @@
1138
1272
  __classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
1139
1273
  this.dispatchEvent({ type: 'change' });
1140
1274
  }
1141
- get(url) {
1142
- return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'GET', url);
1275
+ /**
1276
+ * Makes an HTTP GET request to the specified URL.
1277
+ *
1278
+ * This is a lower level method for custom requests.
1279
+ * For common operations, we recommend using higher level methods
1280
+ * such as `readResource()`, `search()`, etc.
1281
+ *
1282
+ * @param url The target URL.
1283
+ * @param options Optional fetch options.
1284
+ * @returns Promise to the response content.
1285
+ */
1286
+ get(url, options = {}) {
1287
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'GET', url, options);
1288
+ }
1289
+ /**
1290
+ * Makes an HTTP POST request to the specified URL.
1291
+ *
1292
+ * This is a lower level method for custom requests.
1293
+ * For common operations, we recommend using higher level methods
1294
+ * such as `createResource()`.
1295
+ *
1296
+ * @param url The target URL.
1297
+ * @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
1298
+ * @param contentType The content type to be included in the "Content-Type" header.
1299
+ * @param options Optional fetch options.
1300
+ * @returns Promise to the response content.
1301
+ */
1302
+ post(url, body, contentType, options = {}) {
1303
+ if (body) {
1304
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestBody).call(this, options, body);
1305
+ }
1306
+ if (contentType) {
1307
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestContentType).call(this, options, contentType);
1308
+ }
1309
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'POST', url, options);
1143
1310
  }
1144
- post(url, body, contentType) {
1145
- return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'POST', url, contentType, body);
1311
+ /**
1312
+ * Makes an HTTP PUT request to the specified URL.
1313
+ *
1314
+ * This is a lower level method for custom requests.
1315
+ * For common operations, we recommend using higher level methods
1316
+ * such as `updateResource()`.
1317
+ *
1318
+ * @param url The target URL.
1319
+ * @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
1320
+ * @param contentType The content type to be included in the "Content-Type" header.
1321
+ * @param options Optional fetch options.
1322
+ * @returns Promise to the response content.
1323
+ */
1324
+ put(url, body, contentType, options = {}) {
1325
+ if (body) {
1326
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestBody).call(this, options, body);
1327
+ }
1328
+ if (contentType) {
1329
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestContentType).call(this, options, contentType);
1330
+ }
1331
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'PUT', url, options);
1146
1332
  }
1147
- put(url, body, contentType) {
1148
- return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'PUT', url, contentType, body);
1333
+ /**
1334
+ * Makes an HTTP PATCH request to the specified URL.
1335
+ *
1336
+ * This is a lower level method for custom requests.
1337
+ * For common operations, we recommend using higher level methods
1338
+ * such as `patchResource()`.
1339
+ *
1340
+ * @param url The target URL.
1341
+ * @param operations Array of JSONPatch operations.
1342
+ * @param options Optional fetch options.
1343
+ * @returns Promise to the response content.
1344
+ */
1345
+ patch(url, operations, options = {}) {
1346
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestBody).call(this, options, operations);
1347
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestContentType).call(this, options, PATCH_CONTENT_TYPE);
1348
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'PATCH', url, options);
1149
1349
  }
1150
- delete(url) {
1151
- return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'DELETE', url);
1350
+ /**
1351
+ * Makes an HTTP DELETE request to the specified URL.
1352
+ *
1353
+ * This is a lower level method for custom requests.
1354
+ * For common operations, we recommend using higher level methods
1355
+ * such as `deleteResource()`.
1356
+ *
1357
+ * @param url The target URL.
1358
+ * @param options Optional fetch options.
1359
+ * @returns Promise to the response content.
1360
+ */
1361
+ delete(url, options = {}) {
1362
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'DELETE', url, options);
1152
1363
  }
1153
1364
  /**
1154
1365
  * Tries to register a new user.
@@ -1239,11 +1450,114 @@
1239
1450
  }
1240
1451
  /**
1241
1452
  * Sends a FHIR search request.
1242
- * @param search The search query.
1453
+ *
1454
+ * Example using a FHIR search string:
1455
+ *
1456
+ * ```typescript
1457
+ * const bundle = await client.search('Patient?name=Alice');
1458
+ * console.log(bundle);
1459
+ * ```
1460
+ *
1461
+ * Example using a structured search:
1462
+ *
1463
+ * ```typescript
1464
+ * const bundle = await client.search({
1465
+ * resourceType: 'Patient',
1466
+ * filters: [{
1467
+ * code: 'name',
1468
+ * operator: 'eq',
1469
+ * value: 'Alice',
1470
+ * }]
1471
+ * });
1472
+ * console.log(bundle);
1473
+ * ```
1474
+ *
1475
+ * The return value is a FHIR bundle:
1476
+ *
1477
+ * ```json
1478
+ * {
1479
+ * "resourceType": "Bundle",
1480
+ * "type": "searchest",
1481
+ * "total": 1,
1482
+ * "entry": [
1483
+ * {
1484
+ * "resource": {
1485
+ * "resourceType": "Patient",
1486
+ * "name": [
1487
+ * {
1488
+ * "given": [
1489
+ * "George"
1490
+ * ],
1491
+ * "family": "Washington"
1492
+ * }
1493
+ * ],
1494
+ * }
1495
+ * }
1496
+ * ]
1497
+ * }
1498
+ * ```
1499
+ *
1500
+ * See FHIR search for full details: https://www.hl7.org/fhir/search.html
1501
+ *
1502
+ * @param query The search query as either a string or a structured search object.
1503
+ * @returns Promise to the search result bundle.
1504
+ */
1505
+ search(query, options = {}) {
1506
+ return this.get(typeof query === 'string' ? 'fhir/R4/' + query : this.fhirUrl(query.resourceType) + formatSearchQuery(query), options);
1507
+ }
1508
+ /**
1509
+ * Sends a FHIR search request for a single resource.
1510
+ *
1511
+ * This is a convenience method for `search()` that returns the first resource rather than a `Bundle`.
1512
+ *
1513
+ * Example using a FHIR search string:
1514
+ *
1515
+ * ```typescript
1516
+ * const patient = await client.searchOne('Patient?identifier=123');
1517
+ * console.log(patient);
1518
+ * ```
1519
+ *
1520
+ * The return value is the resource, if available; otherwise, undefined.
1521
+ *
1522
+ * See FHIR search for full details: https://www.hl7.org/fhir/search.html
1523
+ *
1524
+ * @param query The search query as either a string or a structured search object.
1525
+ * @returns Promise to the search result bundle.
1526
+ */
1527
+ searchOne(query, options = {}) {
1528
+ var _a, _b;
1529
+ return __awaiter(this, void 0, void 0, function* () {
1530
+ const search = typeof query === 'string' ? parseSearchDefinition(query) : query;
1531
+ search.count = 1;
1532
+ const bundle = yield this.search(search, options);
1533
+ return (_b = (_a = bundle.entry) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.resource;
1534
+ });
1535
+ }
1536
+ /**
1537
+ * Sends a FHIR search request for an array of resources.
1538
+ *
1539
+ * This is a convenience method for `search()` that returns the resources as an array rather than a `Bundle`.
1540
+ *
1541
+ * Example using a FHIR search string:
1542
+ *
1543
+ * ```typescript
1544
+ * const patients = await client.searchResources('Patient?name=Alice');
1545
+ * console.log(patients);
1546
+ * ```
1547
+ *
1548
+ * The return value is an array of resources.
1549
+ *
1550
+ * See FHIR search for full details: https://www.hl7.org/fhir/search.html
1551
+ *
1552
+ * @param query The search query as either a string or a structured search object.
1243
1553
  * @returns Promise to the search result bundle.
1244
1554
  */
1245
- search(search) {
1246
- return this.get(this.fhirUrl(search.resourceType) + formatSearchQuery(search));
1555
+ searchResources(query, options = {}) {
1556
+ var _a, _b;
1557
+ return __awaiter(this, void 0, void 0, function* () {
1558
+ const bundle = yield this.search(query, options);
1559
+ return (_b = (_a = bundle.entry) === null || _a === void 0 ? void 0 : _a.map((entry) => entry.resource)) !== null && _b !== void 0 ? _b : [];
1560
+ });
1247
1561
  }
1248
1562
  /**
1249
1563
  * Searches a ValueSet resource using the "expand" operation.
@@ -1252,10 +1566,10 @@
1252
1566
  * @param filter The search string.
1253
1567
  * @returns Promise to expanded ValueSet.
1254
1568
  */
1255
- searchValueSet(system, filter) {
1569
+ searchValueSet(system, filter, options = {}) {
1256
1570
  return this.get(this.fhirUrl('ValueSet', '$expand') +
1257
1571
  `?url=${encodeURIComponent(system)}` +
1258
- `&filter=${encodeURIComponent(filter)}`);
1572
+ `&filter=${encodeURIComponent(filter)}`, options);
1259
1573
  }
1260
1574
  /**
1261
1575
  * Returns a cached resource if it is available.
@@ -1283,7 +1597,23 @@
1283
1597
  }
1284
1598
  return undefined;
1285
1599
  }
1286
- read(resourceType, id) {
1600
+ /**
1601
+ * Reads a resource by resource type and ID.
1602
+ *
1603
+ * Example:
1604
+ *
1605
+ * ```typescript
1606
+ * const patient = await medplum.readResource('Patient', '123');
1607
+ * console.log(patient);
1608
+ * ```
1609
+ *
1610
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
1611
+ *
1612
+ * @param resourceType The FHIR resource type.
1613
+ * @param id The resource ID.
1614
+ * @returns The resource if available; undefined otherwise.
1615
+ */
1616
+ readResource(resourceType, id) {
1287
1617
  const cacheKey = resourceType + '/' + id;
1288
1618
  const promise = this.get(this.fhirUrl(resourceType, id)).then((resource) => {
1289
1619
  __classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").set(cacheKey, resource);
@@ -1292,18 +1622,74 @@
1292
1622
  __classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").set(cacheKey, promise);
1293
1623
  return promise;
1294
1624
  }
1625
+ /**
1626
+ * Reads a resource by resource type and ID using the in-memory resource cache.
1627
+ *
1628
+ * If the resource is not available in the cache, it will be read from the server.
1629
+ *
1630
+ * Example:
1631
+ *
1632
+ * ```typescript
1633
+ * const patient = await medplum.readCached('Patient', '123');
1634
+ * console.log(patient);
1635
+ * ```
1636
+ *
1637
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
1638
+ *
1639
+ * @param resourceType The FHIR resource type.
1640
+ * @param id The resource ID.
1641
+ * @returns The resource if available; undefined otherwise.
1642
+ */
1295
1643
  readCached(resourceType, id) {
1296
1644
  const cached = __classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").get(resourceType + '/' + id);
1297
- return cached ? Promise.resolve(cached) : this.read(resourceType, id);
1645
+ return cached ? Promise.resolve(cached) : this.readResource(resourceType, id);
1298
1646
  }
1647
+ /**
1648
+ * Reads a resource by `Reference`.
1649
+ *
1650
+ * This is a convenience method for `readResource()` that accepts a `Reference` object.
1651
+ *
1652
+ * Example:
1653
+ *
1654
+ * ```typescript
1655
+ * const serviceRequest = await medplum.readResource('ServiceRequest', '123');
1656
+ * const patient = await medplum.readReference(serviceRequest.subject);
1657
+ * console.log(patient);
1658
+ * ```
1659
+ *
1660
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
1661
+ *
1662
+ * @param reference The FHIR reference object.
1663
+ * @returns The resource if available; undefined otherwise.
1664
+ */
1299
1665
  readReference(reference) {
1300
1666
  const refString = reference === null || reference === void 0 ? void 0 : reference.reference;
1301
1667
  if (!refString) {
1302
1668
  return Promise.reject('Missing reference');
1303
1669
  }
1304
1670
  const [resourceType, id] = refString.split('/');
1305
- return this.read(resourceType, id);
1671
+ return this.readResource(resourceType, id);
1306
1672
  }
1673
+ /**
1674
+ * Reads a resource by `Reference` using the in-memory resource cache.
1675
+ *
1676
+ * This is a convenience method for `readResource()` that accepts a `Reference` object.
1677
+ *
1678
+ * If the resource is not available in the cache, it will be read from the server.
1679
+ *
1680
+ * Example:
1681
+ *
1682
+ * ```typescript
1683
+ * const serviceRequest = await medplum.readResource('ServiceRequest', '123');
1684
+ * const patient = await medplum.readCachedReference(serviceRequest.subject);
1685
+ * console.log(patient);
1686
+ * ```
1687
+ *
1688
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
1689
+ *
1690
+ * @param reference The FHIR reference object.
1691
+ * @returns The resource if available; undefined otherwise.
1692
+ */
1307
1693
  readCachedReference(reference) {
1308
1694
  const refString = reference === null || reference === void 0 ? void 0 : reference.reference;
1309
1695
  if (!refString) {
@@ -1372,38 +1758,181 @@
1372
1758
  return __classPrivateFieldGet(this, _MedplumClient_schema, "f");
1373
1759
  });
1374
1760
  }
1761
+ /**
1762
+ * Reads resource history by resource type and ID.
1763
+ *
1764
+ * The return value is a bundle of all versions of the resource.
1765
+ *
1766
+ * Example:
1767
+ *
1768
+ * ```typescript
1769
+ * const history = await medplum.readHistory('Patient', '123');
1770
+ * console.log(history);
1771
+ * ```
1772
+ *
1773
+ * See the FHIR "history" operation for full details: https://www.hl7.org/fhir/http.html#history
1774
+ *
1775
+ * @param resourceType The FHIR resource type.
1776
+ * @param id The resource ID.
1777
+ * @returns The resource if available; undefined otherwise.
1778
+ */
1375
1779
  readHistory(resourceType, id) {
1376
1780
  return this.get(this.fhirUrl(resourceType, id, '_history'));
1377
1781
  }
1782
+ /**
1783
+ * Reads a specific version of a resource by resource type, ID, and version ID.
1784
+ *
1785
+ * Example:
1786
+ *
1787
+ * ```typescript
1788
+ * const version = await medplum.readVersion('Patient', '123', '456');
1789
+ * console.log(version);
1790
+ * ```
1791
+ *
1792
+ * See the FHIR "vread" operation for full details: https://www.hl7.org/fhir/http.html#vread
1793
+ *
1794
+ * @param resourceType The FHIR resource type.
1795
+ * @param id The resource ID.
1796
+ * @returns The resource if available; undefined otherwise.
1797
+ */
1798
+ readVersion(resourceType, id, vid) {
1799
+ return this.get(this.fhirUrl(resourceType, id, '_history', vid));
1800
+ }
1378
1801
  readPatientEverything(id) {
1379
1802
  return this.get(this.fhirUrl('Patient', id, '$everything'));
1380
1803
  }
1381
- create(resource) {
1804
+ /**
1805
+ * Creates a new FHIR resource.
1806
+ *
1807
+ * The return value is the newly created resource, including the ID and meta.
1808
+ *
1809
+ * Example:
1810
+ *
1811
+ * ```typescript
1812
+ * const result = await medplum.createResource({
1813
+ * resourceType: 'Patient',
1814
+ * name: [{
1815
+ * family: 'Smith',
1816
+ * given: ['John']
1817
+ * }]
1818
+ * });
1819
+ * console.log(result.id);
1820
+ * ```
1821
+ *
1822
+ * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
1823
+ *
1824
+ * @param resource The FHIR resource to create.
1825
+ * @returns The result of the create operation.
1826
+ */
1827
+ createResource(resource) {
1382
1828
  if (!resource.resourceType) {
1383
- throw new Error('Missing resourceType');
1829
+ return Promise.reject('Missing resourceType');
1384
1830
  }
1385
1831
  return this.post(this.fhirUrl(resource.resourceType), resource);
1386
1832
  }
1833
+ /**
1834
+ * Creates a FHIR `Binary` resource with the provided data content.
1835
+ *
1836
+ * The return value is the newly created resource, including the ID and meta.
1837
+ *
1838
+ * The `data` parameter can be a string or a `File` object.
1839
+ *
1840
+ * A `File` object often comes from a `<input type="file">` element.
1841
+ *
1842
+ * Example:
1843
+ *
1844
+ * ```typescript
1845
+ * const result = await medplum.createBinary(myFile, 'test.jpg', 'image/jpeg');
1846
+ * console.log(result.id);
1847
+ * ```
1848
+ *
1849
+ * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
1850
+ *
1851
+ * @param resource The FHIR resource to create.
1852
+ * @returns The result of the create operation.
1853
+ */
1387
1854
  createBinary(data, filename, contentType) {
1388
1855
  return this.post(this.fhirUrl('Binary') + '?_filename=' + encodeURIComponent(filename), data, contentType);
1389
1856
  }
1390
- update(resource) {
1857
+ /**
1858
+ * Updates a FHIR resource.
1859
+ *
1860
+ * The return value is the updated resource, including the ID and meta.
1861
+ *
1862
+ * Example:
1863
+ *
1864
+ * ```typescript
1865
+ * const result = await medplum.updateResource({
1866
+ * resourceType: 'Patient',
1867
+ * id: '123',
1868
+ * name: [{
1869
+ * family: 'Smith',
1870
+ * given: ['John']
1871
+ * }]
1872
+ * });
1873
+ * console.log(result.meta.versionId);
1874
+ * ```
1875
+ *
1876
+ * See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#update
1877
+ *
1878
+ * @param resource The FHIR resource to update.
1879
+ * @returns The result of the update operation.
1880
+ */
1881
+ updateResource(resource) {
1391
1882
  if (!resource.resourceType) {
1392
- throw new Error('Missing resourceType');
1883
+ return Promise.reject('Missing resourceType');
1393
1884
  }
1394
1885
  if (!resource.id) {
1395
- throw new Error('Missing id');
1886
+ return Promise.reject('Missing id');
1396
1887
  }
1397
1888
  return this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
1398
1889
  }
1399
- patch(resourceType, id, operations) {
1400
- return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'PATCH', this.fhirUrl(resourceType, id), PATCH_CONTENT_TYPE, operations);
1890
+ /**
1891
+ * Updates a FHIR resource using JSONPatch operations.
1892
+ *
1893
+ * The return value is the updated resource, including the ID and meta.
1894
+ *
1895
+ * Example:
1896
+ *
1897
+ * ```typescript
1898
+ * const result = await medplum.patchResource('Patient', '123', [
1899
+ * {op: 'replace', path: '/name/0/family', value: 'Smith'},
1900
+ * ]);
1901
+ * console.log(result.meta.versionId);
1902
+ * ```
1903
+ *
1904
+ * See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#patch
1905
+ *
1906
+ * See the JSONPatch specification for full details: https://tools.ietf.org/html/rfc6902
1907
+ *
1908
+ * @param resourceType The FHIR resource type.
1909
+ * @param id The resource ID.
1910
+ * @param operations The JSONPatch operations.
1911
+ * @returns The result of the patch operations.
1912
+ */
1913
+ patchResource(resourceType, id, operations) {
1914
+ return this.patch(this.fhirUrl(resourceType, id), operations);
1401
1915
  }
1916
+ /**
1917
+ * Deletes a FHIR resource by resource type and ID.
1918
+ *
1919
+ * Example:
1920
+ *
1921
+ * ```typescript
1922
+ * await medplum.deleteResource('Patient', '123');
1923
+ * ```
1924
+ *
1925
+ * See the FHIR "delete" operation for full details: https://www.hl7.org/fhir/http.html#delete
1926
+ *
1927
+ * @param resourceType The FHIR resource type.
1928
+ * @param id The resource ID.
1929
+ * @returns The result of the delete operation.
1930
+ */
1402
1931
  deleteResource(resourceType, id) {
1403
1932
  return this.delete(this.fhirUrl(resourceType, id));
1404
1933
  }
1405
- graphql(query) {
1406
- return this.post(this.fhirUrl('$graphql'), { query }, JSON_CONTENT_TYPE);
1934
+ graphql(query, options) {
1935
+ return this.post(this.fhirUrl('$graphql'), { query }, JSON_CONTENT_TYPE, options);
1407
1936
  }
1408
1937
  getActiveLogin() {
1409
1938
  return __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('activeLogin');
@@ -1421,6 +1950,12 @@
1421
1950
  yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this);
1422
1951
  });
1423
1952
  }
1953
+ setAccessToken(accessToken) {
1954
+ __classPrivateFieldSet(this, _MedplumClient_accessToken, accessToken, "f");
1955
+ __classPrivateFieldSet(this, _MedplumClient_refreshToken, undefined, "f");
1956
+ __classPrivateFieldSet(this, _MedplumClient_profile, undefined, "f");
1957
+ __classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
1958
+ }
1424
1959
  getLogins() {
1425
1960
  var _a;
1426
1961
  return (_a = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins')) !== null && _a !== void 0 ? _a : [];
@@ -1447,12 +1982,12 @@
1447
1982
  * @param url The URL to request.
1448
1983
  * @returns Promise to the response body as a blob.
1449
1984
  */
1450
- download(url) {
1985
+ download(url, options = {}) {
1451
1986
  return __awaiter(this, void 0, void 0, function* () {
1452
1987
  if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
1453
1988
  yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
1454
1989
  }
1455
- const options = __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_buildFetchOptions).call(this, 'GET');
1990
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
1456
1991
  const response = yield __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options);
1457
1992
  return response.blob();
1458
1993
  });
@@ -1466,12 +2001,12 @@
1466
2001
  const pkceState = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('pkceState');
1467
2002
  if (!pkceState) {
1468
2003
  this.clear();
1469
- throw new Error('Invalid PCKE state');
2004
+ return Promise.reject('Invalid PCKE state');
1470
2005
  }
1471
2006
  const codeVerifier = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeVerifier');
1472
2007
  if (!codeVerifier) {
1473
2008
  this.clear();
1474
- throw new Error('Invalid PCKE code verifier');
2009
+ return Promise.reject('Invalid PCKE code verifier');
1475
2010
  }
1476
2011
  return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, 'grant_type=authorization_code' +
1477
2012
  (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") ? '&client_id=' + encodeURIComponent(__classPrivateFieldGet(this, _MedplumClient_clientId, "f")) : '') +
@@ -1482,6 +2017,15 @@
1482
2017
  '&code=' +
1483
2018
  encodeURIComponent(code));
1484
2019
  }
2020
+ clientCredentials(clientId, clientSecret) {
2021
+ return __awaiter(this, void 0, void 0, function* () {
2022
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, 'grant_type=client_credentials' +
2023
+ '&client_id=' +
2024
+ encodeURIComponent(clientId) +
2025
+ '&client_secret=' +
2026
+ encodeURIComponent(clientSecret));
2027
+ });
2028
+ }
1485
2029
  }
1486
2030
  _MedplumClient_fetch = new WeakMap(), _MedplumClient_storage = new WeakMap(), _MedplumClient_schema = new WeakMap(), _MedplumClient_resourceCache = new WeakMap(), _MedplumClient_baseUrl = new WeakMap(), _MedplumClient_clientId = new WeakMap(), _MedplumClient_authorizeUrl = new WeakMap(), _MedplumClient_tokenUrl = new WeakMap(), _MedplumClient_logoutUrl = new WeakMap(), _MedplumClient_onUnauthenticated = new WeakMap(), _MedplumClient_accessToken = new WeakMap(), _MedplumClient_refreshToken = new WeakMap(), _MedplumClient_refreshPromise = new WeakMap(), _MedplumClient_profilePromise = new WeakMap(), _MedplumClient_profile = new WeakMap(), _MedplumClient_config = new WeakMap(), _MedplumClient_instances = new WeakSet(), _MedplumClient_addLogin = function _MedplumClient_addLogin(newLogin) {
1487
2031
  const logins = this.getLogins().filter((login) => { var _a, _b; return ((_a = login.profile) === null || _a === void 0 ? void 0 : _a.reference) !== ((_b = newLogin.profile) === null || _b === void 0 ? void 0 : _b.reference); });
@@ -1502,7 +2046,7 @@
1502
2046
  }), "f");
1503
2047
  return __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
1504
2048
  });
1505
- }, _MedplumClient_request = function _MedplumClient_request(method, url, contentType, body) {
2049
+ }, _MedplumClient_request = function _MedplumClient_request(method, url, options = {}) {
1506
2050
  return __awaiter(this, void 0, void 0, function* () {
1507
2051
  if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
1508
2052
  yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
@@ -1510,11 +2054,12 @@
1510
2054
  if (!url.startsWith('http')) {
1511
2055
  url = __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + url;
1512
2056
  }
1513
- const options = __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_buildFetchOptions).call(this, method, contentType, body);
2057
+ options.method = method;
2058
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
1514
2059
  const response = yield __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options);
1515
2060
  if (response.status === 401) {
1516
2061
  // Refresh and try again
1517
- return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_handleUnauthenticated).call(this, method, url, contentType, body);
2062
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_handleUnauthenticated).call(this, method, url, options);
1518
2063
  }
1519
2064
  if (response.status === 204 || response.status === 304) {
1520
2065
  // No content or change
@@ -1526,32 +2071,40 @@
1526
2071
  }
1527
2072
  return obj;
1528
2073
  });
1529
- }, _MedplumClient_buildFetchOptions = function _MedplumClient_buildFetchOptions(method, contentType, body) {
1530
- const headers = {
1531
- 'Content-Type': contentType || FHIR_CONTENT_TYPE,
1532
- };
2074
+ }, _MedplumClient_addFetchOptionsDefaults = function _MedplumClient_addFetchOptionsDefaults(options) {
2075
+ if (!options.headers) {
2076
+ options.headers = {};
2077
+ }
2078
+ const headers = options.headers;
2079
+ if (!headers['Content-Type']) {
2080
+ headers['Content-Type'] = FHIR_CONTENT_TYPE;
2081
+ }
1533
2082
  if (__classPrivateFieldGet(this, _MedplumClient_accessToken, "f")) {
1534
2083
  headers['Authorization'] = 'Bearer ' + __classPrivateFieldGet(this, _MedplumClient_accessToken, "f");
1535
2084
  }
1536
- const options = {
1537
- method: method,
1538
- cache: 'no-cache',
1539
- credentials: 'include',
1540
- headers,
1541
- };
1542
- if (body) {
1543
- if (typeof body === 'string' || (typeof File !== 'undefined' && body instanceof File)) {
1544
- options.body = body;
1545
- }
1546
- else {
1547
- options.body = stringify(body);
1548
- }
2085
+ if (!options.cache) {
2086
+ options.cache = 'no-cache';
2087
+ }
2088
+ if (!options.credentials) {
2089
+ options.credentials = 'include';
2090
+ }
2091
+ }, _MedplumClient_setRequestContentType = function _MedplumClient_setRequestContentType(options, contentType) {
2092
+ if (!options.headers) {
2093
+ options.headers = {};
1549
2094
  }
1550
- return options;
1551
- }, _MedplumClient_handleUnauthenticated = function _MedplumClient_handleUnauthenticated(method, url, contentType, body) {
2095
+ const headers = options.headers;
2096
+ headers['Content-Type'] = contentType;
2097
+ }, _MedplumClient_setRequestBody = function _MedplumClient_setRequestBody(options, data) {
2098
+ if (typeof data === 'string' || (typeof File !== 'undefined' && data instanceof File)) {
2099
+ options.body = data;
2100
+ }
2101
+ else if (data) {
2102
+ options.body = stringify(data);
2103
+ }
2104
+ }, _MedplumClient_handleUnauthenticated = function _MedplumClient_handleUnauthenticated(method, url, options) {
1552
2105
  return __awaiter(this, void 0, void 0, function* () {
1553
2106
  return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refresh).call(this)
1554
- .then(() => __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, method, url, contentType, body))
2107
+ .then(() => __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, method, url, options))
1555
2108
  .catch((error) => {
1556
2109
  this.clear();
1557
2110
  if (__classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f")) {
@@ -1573,7 +2126,7 @@
1573
2126
  }, _MedplumClient_requestAuthorization = function _MedplumClient_requestAuthorization() {
1574
2127
  return __awaiter(this, void 0, void 0, function* () {
1575
2128
  if (!__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f")) {
1576
- throw new Error('Missing authorize URL');
2129
+ return Promise.reject('Missing authorize URL');
1577
2130
  }
1578
2131
  __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
1579
2132
  window.location.assign(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f") +
@@ -1668,6 +2221,209 @@
1668
2221
  return window.location.protocol + '//' + window.location.host + '/';
1669
2222
  }
1670
2223
 
2224
+ var _LegacyRepositoryClient_client;
2225
+ /**
2226
+ * The LegacyRepositoryClient is a supplementary API client that matches the legacy "Repository" API.
2227
+ * The "Repository" API is deprecated and will be removed in a future release.
2228
+ * This LegacyRepositoryClient is also deprecated and will be removed in a future release.
2229
+ * @deprecated
2230
+ */
2231
+ class LegacyRepositoryClient {
2232
+ constructor(client) {
2233
+ _LegacyRepositoryClient_client.set(this, void 0);
2234
+ __classPrivateFieldSet(this, _LegacyRepositoryClient_client, client, "f");
2235
+ }
2236
+ /**
2237
+ * Creates a resource.
2238
+ *
2239
+ * See: https://www.hl7.org/fhir/http.html#create
2240
+ *
2241
+ * @param resource The resource to create.
2242
+ * @returns Operation outcome and the new resource.
2243
+ * @deprecated
2244
+ */
2245
+ createResource(resource) {
2246
+ return __awaiter(this, void 0, void 0, function* () {
2247
+ try {
2248
+ const result = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").createResource(resource);
2249
+ return [created, result];
2250
+ }
2251
+ catch (error) {
2252
+ return [error, undefined];
2253
+ }
2254
+ });
2255
+ }
2256
+ /**
2257
+ * Returns a resource.
2258
+ *
2259
+ * See: https://www.hl7.org/fhir/http.html#read
2260
+ *
2261
+ * @param resourceType The FHIR resource type.
2262
+ * @param id The FHIR resource ID.
2263
+ * @returns Operation outcome and a resource.
2264
+ * @deprecated
2265
+ */
2266
+ readResource(resourceType, id) {
2267
+ return __awaiter(this, void 0, void 0, function* () {
2268
+ try {
2269
+ const resource = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").readResource(resourceType, id);
2270
+ return [allOk, resource];
2271
+ }
2272
+ catch (error) {
2273
+ return [error, undefined];
2274
+ }
2275
+ });
2276
+ }
2277
+ /**
2278
+ * Returns a resource by FHIR reference.
2279
+ *
2280
+ * See: https://www.hl7.org/fhir/http.html#read
2281
+ *
2282
+ * @param reference The FHIR reference.
2283
+ * @returns Operation outcome and a resource.
2284
+ * @deprecated
2285
+ */
2286
+ readReference(reference) {
2287
+ return __awaiter(this, void 0, void 0, function* () {
2288
+ try {
2289
+ const resource = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").readReference(reference);
2290
+ return [allOk, resource];
2291
+ }
2292
+ catch (error) {
2293
+ return [error, undefined];
2294
+ }
2295
+ });
2296
+ }
2297
+ /**
2298
+ * Returns resource history.
2299
+ *
2300
+ * See: https://www.hl7.org/fhir/http.html#history
2301
+ *
2302
+ * @param resourceType The FHIR resource type.
2303
+ * @param id The FHIR resource ID.
2304
+ * @returns Operation outcome and a history bundle.
2305
+ * @deprecated
2306
+ */
2307
+ readHistory(resourceType, id) {
2308
+ return __awaiter(this, void 0, void 0, function* () {
2309
+ try {
2310
+ const resource = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").readHistory(resourceType, id);
2311
+ return [allOk, resource];
2312
+ }
2313
+ catch (error) {
2314
+ return [error, undefined];
2315
+ }
2316
+ });
2317
+ }
2318
+ /**
2319
+ * Returns a resource version.
2320
+ *
2321
+ * See: https://www.hl7.org/fhir/http.html#vread
2322
+ *
2323
+ * @param resourceType The FHIR resource type.
2324
+ * @param id The FHIR resource ID.
2325
+ * @param vid The version ID.
2326
+ * @returns Operation outcome and a resource.
2327
+ * @deprecated
2328
+ */
2329
+ readVersion(resourceType, id, vid) {
2330
+ return __awaiter(this, void 0, void 0, function* () {
2331
+ try {
2332
+ const resource = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").readVersion(resourceType, id, vid);
2333
+ return [allOk, resource];
2334
+ }
2335
+ catch (error) {
2336
+ return [error, undefined];
2337
+ }
2338
+ });
2339
+ }
2340
+ /**
2341
+ * Updates a resource.
2342
+ *
2343
+ * See: https://www.hl7.org/fhir/http.html#update
2344
+ *
2345
+ * @param resource The resource to update.
2346
+ * @returns Operation outcome and the updated resource.
2347
+ * @deprecated
2348
+ */
2349
+ updateResource(resource) {
2350
+ return __awaiter(this, void 0, void 0, function* () {
2351
+ try {
2352
+ const updated = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").updateResource(resource);
2353
+ return [allOk, updated];
2354
+ }
2355
+ catch (error) {
2356
+ return [error, undefined];
2357
+ }
2358
+ });
2359
+ }
2360
+ /**
2361
+ * Deletes a resource.
2362
+ *
2363
+ * See: https://www.hl7.org/fhir/http.html#delete
2364
+ *
2365
+ * @param resourceType The FHIR resource type.
2366
+ * @param id The resource ID.
2367
+ * @returns Operation outcome.
2368
+ * @deprecated
2369
+ */
2370
+ deleteResource(resourceType, id) {
2371
+ return __awaiter(this, void 0, void 0, function* () {
2372
+ try {
2373
+ yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").deleteResource(resourceType, id);
2374
+ return [allOk, undefined];
2375
+ }
2376
+ catch (error) {
2377
+ return [error, undefined];
2378
+ }
2379
+ });
2380
+ }
2381
+ /**
2382
+ * Patches a resource.
2383
+ *
2384
+ * See: https://www.hl7.org/fhir/http.html#patch
2385
+ *
2386
+ * @param resourceType The FHIR resource type.
2387
+ * @param id The resource ID.
2388
+ * @param patch Array of JSONPatch operations.
2389
+ * @returns Operation outcome and the resource.
2390
+ * @deprecated
2391
+ */
2392
+ patchResource(resourceType, id, patch) {
2393
+ return __awaiter(this, void 0, void 0, function* () {
2394
+ try {
2395
+ const resource = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").patchResource(resourceType, id, patch);
2396
+ return [allOk, resource];
2397
+ }
2398
+ catch (error) {
2399
+ return [error, undefined];
2400
+ }
2401
+ });
2402
+ }
2403
+ /**
2404
+ * Searches for resources.
2405
+ *
2406
+ * See: https://www.hl7.org/fhir/http.html#search
2407
+ *
2408
+ * @param searchRequest The search request.
2409
+ * @returns The search result bundle.
2410
+ * @deprecated
2411
+ */
2412
+ search(query) {
2413
+ return __awaiter(this, void 0, void 0, function* () {
2414
+ const searchRequest = typeof query === 'string' ? parseSearchDefinition(query) : query;
2415
+ try {
2416
+ const bundle = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").search(searchRequest);
2417
+ return [allOk, bundle];
2418
+ }
2419
+ catch (error) {
2420
+ return [error, undefined];
2421
+ }
2422
+ });
2423
+ }
2424
+ }
2425
+ _LegacyRepositoryClient_client = new WeakMap();
2426
+
1671
2427
  exports.SearchParameterType = void 0;
1672
2428
  (function (SearchParameterType) {
1673
2429
  SearchParameterType["BOOLEAN"] = "BOOLEAN";
@@ -1794,6 +2550,7 @@
1794
2550
  return result;
1795
2551
  }
1796
2552
 
2553
+ exports.LegacyRepositoryClient = LegacyRepositoryClient;
1797
2554
  exports.MedplumClient = MedplumClient;
1798
2555
  exports.OperationOutcomeError = OperationOutcomeError;
1799
2556
  exports.accessDenied = accessDenied;
@@ -1803,6 +2560,8 @@
1803
2560
  exports.assertOk = assertOk;
1804
2561
  exports.badRequest = badRequest;
1805
2562
  exports.buildTypeName = buildTypeName;
2563
+ exports.calculateAge = calculateAge;
2564
+ exports.calculateAgeString = calculateAgeString;
1806
2565
  exports.capitalize = capitalize;
1807
2566
  exports.createReference = createReference;
1808
2567
  exports.createSchema = createSchema;