@medplum/core 0.5.0 → 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.
- package/dist/cjs/index.js +819 -60
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -1
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/esm/index.js +817 -61
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/types/client.d.ts +427 -13
- package/dist/types/fix-ro-iddentifiers.d.ts +0 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/repo.d.ts +116 -0
- package/dist/types/search.d.ts +9 -12
- package/dist/types/utils.d.ts +21 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +92 -0
- package/docs/assets/icons.css +1043 -0
- package/docs/assets/icons.png +0 -0
- package/docs/assets/icons@2x.png +0 -0
- package/docs/assets/main.js +52 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1414 -0
- package/docs/assets/widgets.png +0 -0
- package/docs/assets/widgets@2x.png +0 -0
- package/docs/classes/LegacyRepositoryClient.html +71 -0
- package/docs/classes/MedplumClient.html +324 -0
- package/docs/classes/OperationOutcomeError.html +6 -0
- package/docs/enums/Operator.html +5 -0
- package/docs/enums/PropertyType.html +5 -0
- package/docs/enums/SearchParameterType.html +1 -0
- package/docs/index.html +89 -0
- package/docs/interfaces/AddressFormatOptions.html +1 -0
- package/docs/interfaces/FetchLike.html +1 -0
- package/docs/interfaces/Filter.html +1 -0
- package/docs/interfaces/GoogleCredentialResponse.html +1 -0
- package/docs/interfaces/HumanNameFormatOptions.html +1 -0
- package/docs/interfaces/IndexedStructureDefinition.html +19 -0
- package/docs/interfaces/LoginAuthenticationResponse.html +1 -0
- package/docs/interfaces/LoginProfileResponse.html +1 -0
- package/docs/interfaces/LoginScopeResponse.html +1 -0
- package/docs/interfaces/LoginState.html +1 -0
- package/docs/interfaces/MedplumClientOptions.html +33 -0
- package/docs/interfaces/RegisterRequest.html +1 -0
- package/docs/interfaces/SearchParameterDetails.html +1 -0
- package/docs/interfaces/SearchRequest.html +1 -0
- package/docs/interfaces/SortRule.html +1 -0
- package/docs/interfaces/TokenResponse.html +1 -0
- package/docs/interfaces/TypeSchema.html +10 -0
- package/docs/modules.html +138 -0
- package/package.json +3 -2
package/dist/esm/index.js
CHANGED
|
@@ -167,6 +167,7 @@ function isProfileResource(resource) {
|
|
|
167
167
|
* @return Human friendly display string.
|
|
168
168
|
*/
|
|
169
169
|
function getDisplayString(resource) {
|
|
170
|
+
var _a, _b;
|
|
170
171
|
if (isProfileResource(resource)) {
|
|
171
172
|
const profileName = getProfileResourceDisplayString(resource);
|
|
172
173
|
if (profileName) {
|
|
@@ -179,6 +180,11 @@ function getDisplayString(resource) {
|
|
|
179
180
|
return deviceName;
|
|
180
181
|
}
|
|
181
182
|
}
|
|
183
|
+
if (resource.resourceType === 'Observation') {
|
|
184
|
+
if ('code' in resource && ((_a = resource.code) === null || _a === void 0 ? void 0 : _a.text)) {
|
|
185
|
+
return (_b = resource.code) === null || _b === void 0 ? void 0 : _b.text;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
182
188
|
if (resource.resourceType === 'User') {
|
|
183
189
|
if (resource.email) {
|
|
184
190
|
return resource.email;
|
|
@@ -223,12 +229,25 @@ function getImageSrc(resource) {
|
|
|
223
229
|
const photos = resource.photo;
|
|
224
230
|
if (photos) {
|
|
225
231
|
for (const photo of photos) {
|
|
226
|
-
|
|
227
|
-
|
|
232
|
+
const url = getPhotoImageSrc(photo);
|
|
233
|
+
if (url) {
|
|
234
|
+
return url;
|
|
228
235
|
}
|
|
229
236
|
}
|
|
230
237
|
}
|
|
231
238
|
}
|
|
239
|
+
if (resource.resourceType === 'Bot' && resource.photo) {
|
|
240
|
+
const url = getPhotoImageSrc(resource.photo);
|
|
241
|
+
if (url) {
|
|
242
|
+
return url;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
function getPhotoImageSrc(photo) {
|
|
248
|
+
if (photo.url && photo.contentType && photo.contentType.startsWith('image/')) {
|
|
249
|
+
return photo.url;
|
|
250
|
+
}
|
|
232
251
|
return undefined;
|
|
233
252
|
}
|
|
234
253
|
/**
|
|
@@ -241,6 +260,55 @@ function getImageSrc(resource) {
|
|
|
241
260
|
function getDateProperty(date) {
|
|
242
261
|
return date ? new Date(date) : undefined;
|
|
243
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Calculates the age in years from the birth date.
|
|
265
|
+
* @param birthDateStr The birth date or start date in ISO-8601 format YYYY-MM-DD.
|
|
266
|
+
* @param endDateStr Optional end date in ISO-8601 format YYYY-MM-DD. Default value is today.
|
|
267
|
+
* @returns The age in years, months, and days.
|
|
268
|
+
*/
|
|
269
|
+
function calculateAge(birthDateStr, endDateStr) {
|
|
270
|
+
const startDate = new Date(birthDateStr);
|
|
271
|
+
startDate.setUTCHours(0, 0, 0, 0);
|
|
272
|
+
const endDate = endDateStr ? new Date(endDateStr) : new Date();
|
|
273
|
+
endDate.setUTCHours(0, 0, 0, 0);
|
|
274
|
+
const startYear = startDate.getUTCFullYear();
|
|
275
|
+
const startMonth = startDate.getUTCMonth();
|
|
276
|
+
const startDay = startDate.getUTCDate();
|
|
277
|
+
const endYear = endDate.getUTCFullYear();
|
|
278
|
+
const endMonth = endDate.getUTCMonth();
|
|
279
|
+
const endDay = endDate.getUTCDate();
|
|
280
|
+
let years = endYear - startYear;
|
|
281
|
+
if (endMonth < startMonth || (endMonth === startMonth && endDay < startDay)) {
|
|
282
|
+
years--;
|
|
283
|
+
}
|
|
284
|
+
let months = endYear * 12 + endMonth - (startYear * 12 + startMonth);
|
|
285
|
+
if (endDay < startDay) {
|
|
286
|
+
months--;
|
|
287
|
+
}
|
|
288
|
+
const days = Math.floor((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24));
|
|
289
|
+
return { years, months, days };
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Calculates the age string for display using the age appropriate units.
|
|
293
|
+
* If the age is greater than or equal to 2 years, then the age is displayed in years.
|
|
294
|
+
* If the age is greater than or equal to 1 month, then the age is displayed in months.
|
|
295
|
+
* Otherwise, the age is displayed in days.
|
|
296
|
+
* @param birthDateStr The birth date or start date in ISO-8601 format YYYY-MM-DD.
|
|
297
|
+
* @param endDateStr Optional end date in ISO-8601 format YYYY-MM-DD. Default value is today.
|
|
298
|
+
* @returns The age string.
|
|
299
|
+
*/
|
|
300
|
+
function calculateAgeString(birthDateStr, endDateStr) {
|
|
301
|
+
const { years, months, days } = calculateAge(birthDateStr, endDateStr);
|
|
302
|
+
if (years >= 2) {
|
|
303
|
+
return years.toString().padStart(3, '0') + 'Y';
|
|
304
|
+
}
|
|
305
|
+
else if (months >= 1) {
|
|
306
|
+
return months.toString().padStart(3, '0') + 'M';
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
return days.toString().padStart(3, '0') + 'D';
|
|
310
|
+
}
|
|
311
|
+
}
|
|
244
312
|
/**
|
|
245
313
|
* FHIR JSON stringify.
|
|
246
314
|
* Removes properties with empty string values.
|
|
@@ -261,7 +329,15 @@ function stringify(value, pretty) {
|
|
|
261
329
|
* @param {*} v Property value.
|
|
262
330
|
*/
|
|
263
331
|
function stringifyReplacer(k, v) {
|
|
264
|
-
return isEmpty(v) ? undefined : v;
|
|
332
|
+
return !isArrayKey(k) && isEmpty(v) ? undefined : v;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Returns true if the key is an array key.
|
|
336
|
+
* @param k The property key.
|
|
337
|
+
* @returns True if the key is an array key.
|
|
338
|
+
*/
|
|
339
|
+
function isArrayKey(k) {
|
|
340
|
+
return !!k.match(/\d+$/);
|
|
265
341
|
}
|
|
266
342
|
/**
|
|
267
343
|
* Returns true if the value is empty (null, undefined, empty string, or empty object).
|
|
@@ -414,7 +490,7 @@ _EventTarget_listeners = new WeakMap();
|
|
|
414
490
|
*/
|
|
415
491
|
function decodePayload(payload) {
|
|
416
492
|
const cleanedPayload = payload.replace(/-/g, '+').replace(/_/g, '/');
|
|
417
|
-
const decodedPayload =
|
|
493
|
+
const decodedPayload = decodeBase64(cleanedPayload);
|
|
418
494
|
const uriEncodedPayload = Array.from(decodedPayload).reduce((acc, char) => {
|
|
419
495
|
const uriEncodedChar = ('00' + char.charCodeAt(0).toString(16)).slice(-2);
|
|
420
496
|
return `${acc}%${uriEncodedChar}`;
|
|
@@ -422,6 +498,15 @@ function decodePayload(payload) {
|
|
|
422
498
|
const jsonPayload = decodeURIComponent(uriEncodedPayload);
|
|
423
499
|
return JSON.parse(jsonPayload);
|
|
424
500
|
}
|
|
501
|
+
function decodeBase64(data) {
|
|
502
|
+
if (typeof window !== 'undefined') {
|
|
503
|
+
return window.atob(data);
|
|
504
|
+
}
|
|
505
|
+
if (typeof Buffer !== 'undefined') {
|
|
506
|
+
return Buffer.from(data, 'base64').toString('binary');
|
|
507
|
+
}
|
|
508
|
+
throw new Error('Unable to decode base64');
|
|
509
|
+
}
|
|
425
510
|
/**
|
|
426
511
|
* Parses the JWT payload.
|
|
427
512
|
* @param token JWT token
|
|
@@ -634,10 +719,11 @@ const PREFIX_OPERATORS = [
|
|
|
634
719
|
*
|
|
635
720
|
* See the FHIR search spec: http://hl7.org/fhir/r4/search.html
|
|
636
721
|
*
|
|
637
|
-
* @param
|
|
722
|
+
* @param url The URL to parse.
|
|
638
723
|
* @returns Parsed search definition.
|
|
639
724
|
*/
|
|
640
|
-
function parseSearchDefinition(
|
|
725
|
+
function parseSearchDefinition(url) {
|
|
726
|
+
const location = new URL(url, 'https://example.com/');
|
|
641
727
|
const resourceType = location.pathname
|
|
642
728
|
.replace(/(^\/)|(\/$)/g, '') // Remove leading and trailing slashes
|
|
643
729
|
.split('/')
|
|
@@ -1066,13 +1152,61 @@ function getPropertyDisplayName(property) {
|
|
|
1066
1152
|
|
|
1067
1153
|
// PKCE auth ased on:
|
|
1068
1154
|
// https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
|
|
1069
|
-
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,
|
|
1155
|
+
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;
|
|
1070
1156
|
const DEFAULT_BASE_URL = 'https://api.medplum.com/';
|
|
1071
1157
|
const DEFAULT_SCOPE = 'launch/patient openid fhirUser offline_access user/*.*';
|
|
1072
1158
|
const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
|
|
1073
1159
|
const JSON_CONTENT_TYPE = 'application/json';
|
|
1074
1160
|
const FHIR_CONTENT_TYPE = 'application/fhir+json';
|
|
1075
1161
|
const PATCH_CONTENT_TYPE = 'application/json-patch+json';
|
|
1162
|
+
/**
|
|
1163
|
+
* The MedplumClient class provides a client for the Medplum FHIR server.
|
|
1164
|
+
*
|
|
1165
|
+
* The client can be used in the browser, in a NodeJS application, or in a Medplum Bot.
|
|
1166
|
+
*
|
|
1167
|
+
* The client provides helpful methods for common operations such as:
|
|
1168
|
+
* 1) Authenticating
|
|
1169
|
+
* 2) Creating resources
|
|
1170
|
+
* 2) Reading resources
|
|
1171
|
+
* 3) Updating resources
|
|
1172
|
+
* 5) Deleting resources
|
|
1173
|
+
* 6) Searching
|
|
1174
|
+
* 7) Making GraphQL queries
|
|
1175
|
+
*
|
|
1176
|
+
* Here is a quick example of how to use the client:
|
|
1177
|
+
*
|
|
1178
|
+
* ```typescript
|
|
1179
|
+
* import { MedplumClient } from '@medplum/core';
|
|
1180
|
+
* const medplum = new MedplumClient();
|
|
1181
|
+
* ```
|
|
1182
|
+
*
|
|
1183
|
+
* Create a `Patient`:
|
|
1184
|
+
*
|
|
1185
|
+
* ```typescript
|
|
1186
|
+
* const patient = await medplum.createResource({
|
|
1187
|
+
* resourceType: 'Patient',
|
|
1188
|
+
* name: [{
|
|
1189
|
+
* given: ['Alice'],
|
|
1190
|
+
* family: 'Smith'
|
|
1191
|
+
* }]
|
|
1192
|
+
* });
|
|
1193
|
+
* ```
|
|
1194
|
+
*
|
|
1195
|
+
* Read a `Patient` by ID:
|
|
1196
|
+
*
|
|
1197
|
+
* ```typescript
|
|
1198
|
+
* const patient = await medplum.readResource('Patient', '123');
|
|
1199
|
+
* console.log(patient.name[0].given[0]);
|
|
1200
|
+
* ```
|
|
1201
|
+
*
|
|
1202
|
+
* Search for a `Patient` by name:
|
|
1203
|
+
*
|
|
1204
|
+
* ```typescript
|
|
1205
|
+
* const bundle = await medplum.search('Patient?name=Alice');
|
|
1206
|
+
* console.log(bundle.total);
|
|
1207
|
+
* ```
|
|
1208
|
+
*
|
|
1209
|
+
*/
|
|
1076
1210
|
class MedplumClient extends EventTarget {
|
|
1077
1211
|
constructor(options) {
|
|
1078
1212
|
var _a;
|
|
@@ -1132,17 +1266,94 @@ class MedplumClient extends EventTarget {
|
|
|
1132
1266
|
__classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
|
|
1133
1267
|
this.dispatchEvent({ type: 'change' });
|
|
1134
1268
|
}
|
|
1135
|
-
|
|
1136
|
-
|
|
1269
|
+
/**
|
|
1270
|
+
* Makes an HTTP GET request to the specified URL.
|
|
1271
|
+
*
|
|
1272
|
+
* This is a lower level method for custom requests.
|
|
1273
|
+
* For common operations, we recommend using higher level methods
|
|
1274
|
+
* such as `readResource()`, `search()`, etc.
|
|
1275
|
+
*
|
|
1276
|
+
* @param url The target URL.
|
|
1277
|
+
* @param options Optional fetch options.
|
|
1278
|
+
* @returns Promise to the response content.
|
|
1279
|
+
*/
|
|
1280
|
+
get(url, options = {}) {
|
|
1281
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'GET', url, options);
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Makes an HTTP POST request to the specified URL.
|
|
1285
|
+
*
|
|
1286
|
+
* This is a lower level method for custom requests.
|
|
1287
|
+
* For common operations, we recommend using higher level methods
|
|
1288
|
+
* such as `createResource()`.
|
|
1289
|
+
*
|
|
1290
|
+
* @param url The target URL.
|
|
1291
|
+
* @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
|
|
1292
|
+
* @param contentType The content type to be included in the "Content-Type" header.
|
|
1293
|
+
* @param options Optional fetch options.
|
|
1294
|
+
* @returns Promise to the response content.
|
|
1295
|
+
*/
|
|
1296
|
+
post(url, body, contentType, options = {}) {
|
|
1297
|
+
if (body) {
|
|
1298
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestBody).call(this, options, body);
|
|
1299
|
+
}
|
|
1300
|
+
if (contentType) {
|
|
1301
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestContentType).call(this, options, contentType);
|
|
1302
|
+
}
|
|
1303
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'POST', url, options);
|
|
1137
1304
|
}
|
|
1138
|
-
|
|
1139
|
-
|
|
1305
|
+
/**
|
|
1306
|
+
* Makes an HTTP PUT request to the specified URL.
|
|
1307
|
+
*
|
|
1308
|
+
* This is a lower level method for custom requests.
|
|
1309
|
+
* For common operations, we recommend using higher level methods
|
|
1310
|
+
* such as `updateResource()`.
|
|
1311
|
+
*
|
|
1312
|
+
* @param url The target URL.
|
|
1313
|
+
* @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
|
|
1314
|
+
* @param contentType The content type to be included in the "Content-Type" header.
|
|
1315
|
+
* @param options Optional fetch options.
|
|
1316
|
+
* @returns Promise to the response content.
|
|
1317
|
+
*/
|
|
1318
|
+
put(url, body, contentType, options = {}) {
|
|
1319
|
+
if (body) {
|
|
1320
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestBody).call(this, options, body);
|
|
1321
|
+
}
|
|
1322
|
+
if (contentType) {
|
|
1323
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestContentType).call(this, options, contentType);
|
|
1324
|
+
}
|
|
1325
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'PUT', url, options);
|
|
1140
1326
|
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1327
|
+
/**
|
|
1328
|
+
* Makes an HTTP PATCH request to the specified URL.
|
|
1329
|
+
*
|
|
1330
|
+
* This is a lower level method for custom requests.
|
|
1331
|
+
* For common operations, we recommend using higher level methods
|
|
1332
|
+
* such as `patchResource()`.
|
|
1333
|
+
*
|
|
1334
|
+
* @param url The target URL.
|
|
1335
|
+
* @param operations Array of JSONPatch operations.
|
|
1336
|
+
* @param options Optional fetch options.
|
|
1337
|
+
* @returns Promise to the response content.
|
|
1338
|
+
*/
|
|
1339
|
+
patch(url, operations, options = {}) {
|
|
1340
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestBody).call(this, options, operations);
|
|
1341
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestContentType).call(this, options, PATCH_CONTENT_TYPE);
|
|
1342
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'PATCH', url, options);
|
|
1143
1343
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1344
|
+
/**
|
|
1345
|
+
* Makes an HTTP DELETE request to the specified URL.
|
|
1346
|
+
*
|
|
1347
|
+
* This is a lower level method for custom requests.
|
|
1348
|
+
* For common operations, we recommend using higher level methods
|
|
1349
|
+
* such as `deleteResource()`.
|
|
1350
|
+
*
|
|
1351
|
+
* @param url The target URL.
|
|
1352
|
+
* @param options Optional fetch options.
|
|
1353
|
+
* @returns Promise to the response content.
|
|
1354
|
+
*/
|
|
1355
|
+
delete(url, options = {}) {
|
|
1356
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'DELETE', url, options);
|
|
1146
1357
|
}
|
|
1147
1358
|
/**
|
|
1148
1359
|
* Tries to register a new user.
|
|
@@ -1233,11 +1444,114 @@ class MedplumClient extends EventTarget {
|
|
|
1233
1444
|
}
|
|
1234
1445
|
/**
|
|
1235
1446
|
* Sends a FHIR search request.
|
|
1236
|
-
*
|
|
1447
|
+
*
|
|
1448
|
+
* Example using a FHIR search string:
|
|
1449
|
+
*
|
|
1450
|
+
* ```typescript
|
|
1451
|
+
* const bundle = await client.search('Patient?name=Alice');
|
|
1452
|
+
* console.log(bundle);
|
|
1453
|
+
* ```
|
|
1454
|
+
*
|
|
1455
|
+
* Example using a structured search:
|
|
1456
|
+
*
|
|
1457
|
+
* ```typescript
|
|
1458
|
+
* const bundle = await client.search({
|
|
1459
|
+
* resourceType: 'Patient',
|
|
1460
|
+
* filters: [{
|
|
1461
|
+
* code: 'name',
|
|
1462
|
+
* operator: 'eq',
|
|
1463
|
+
* value: 'Alice',
|
|
1464
|
+
* }]
|
|
1465
|
+
* });
|
|
1466
|
+
* console.log(bundle);
|
|
1467
|
+
* ```
|
|
1468
|
+
*
|
|
1469
|
+
* The return value is a FHIR bundle:
|
|
1470
|
+
*
|
|
1471
|
+
* ```json
|
|
1472
|
+
* {
|
|
1473
|
+
* "resourceType": "Bundle",
|
|
1474
|
+
* "type": "searchest",
|
|
1475
|
+
* "total": 1,
|
|
1476
|
+
* "entry": [
|
|
1477
|
+
* {
|
|
1478
|
+
* "resource": {
|
|
1479
|
+
* "resourceType": "Patient",
|
|
1480
|
+
* "name": [
|
|
1481
|
+
* {
|
|
1482
|
+
* "given": [
|
|
1483
|
+
* "George"
|
|
1484
|
+
* ],
|
|
1485
|
+
* "family": "Washington"
|
|
1486
|
+
* }
|
|
1487
|
+
* ],
|
|
1488
|
+
* }
|
|
1489
|
+
* }
|
|
1490
|
+
* ]
|
|
1491
|
+
* }
|
|
1492
|
+
* ```
|
|
1493
|
+
*
|
|
1494
|
+
* See FHIR search for full details: https://www.hl7.org/fhir/search.html
|
|
1495
|
+
*
|
|
1496
|
+
* @param query The search query as either a string or a structured search object.
|
|
1497
|
+
* @returns Promise to the search result bundle.
|
|
1498
|
+
*/
|
|
1499
|
+
search(query, options = {}) {
|
|
1500
|
+
return this.get(typeof query === 'string' ? 'fhir/R4/' + query : this.fhirUrl(query.resourceType) + formatSearchQuery(query), options);
|
|
1501
|
+
}
|
|
1502
|
+
/**
|
|
1503
|
+
* Sends a FHIR search request for a single resource.
|
|
1504
|
+
*
|
|
1505
|
+
* This is a convenience method for `search()` that returns the first resource rather than a `Bundle`.
|
|
1506
|
+
*
|
|
1507
|
+
* Example using a FHIR search string:
|
|
1508
|
+
*
|
|
1509
|
+
* ```typescript
|
|
1510
|
+
* const patient = await client.searchOne('Patient?identifier=123');
|
|
1511
|
+
* console.log(patient);
|
|
1512
|
+
* ```
|
|
1513
|
+
*
|
|
1514
|
+
* The return value is the resource, if available; otherwise, undefined.
|
|
1515
|
+
*
|
|
1516
|
+
* See FHIR search for full details: https://www.hl7.org/fhir/search.html
|
|
1517
|
+
*
|
|
1518
|
+
* @param query The search query as either a string or a structured search object.
|
|
1519
|
+
* @returns Promise to the search result bundle.
|
|
1520
|
+
*/
|
|
1521
|
+
searchOne(query, options = {}) {
|
|
1522
|
+
var _a, _b;
|
|
1523
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1524
|
+
const search = typeof query === 'string' ? parseSearchDefinition(query) : query;
|
|
1525
|
+
search.count = 1;
|
|
1526
|
+
const bundle = yield this.search(search, options);
|
|
1527
|
+
return (_b = (_a = bundle.entry) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.resource;
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
/**
|
|
1531
|
+
* Sends a FHIR search request for an array of resources.
|
|
1532
|
+
*
|
|
1533
|
+
* This is a convenience method for `search()` that returns the resources as an array rather than a `Bundle`.
|
|
1534
|
+
*
|
|
1535
|
+
* Example using a FHIR search string:
|
|
1536
|
+
*
|
|
1537
|
+
* ```typescript
|
|
1538
|
+
* const patients = await client.searchResources('Patient?name=Alice');
|
|
1539
|
+
* console.log(patients);
|
|
1540
|
+
* ```
|
|
1541
|
+
*
|
|
1542
|
+
* The return value is an array of resources.
|
|
1543
|
+
*
|
|
1544
|
+
* See FHIR search for full details: https://www.hl7.org/fhir/search.html
|
|
1545
|
+
*
|
|
1546
|
+
* @param query The search query as either a string or a structured search object.
|
|
1237
1547
|
* @returns Promise to the search result bundle.
|
|
1238
1548
|
*/
|
|
1239
|
-
|
|
1240
|
-
|
|
1549
|
+
searchResources(query, options = {}) {
|
|
1550
|
+
var _a, _b;
|
|
1551
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1552
|
+
const bundle = yield this.search(query, options);
|
|
1553
|
+
return (_b = (_a = bundle.entry) === null || _a === void 0 ? void 0 : _a.map((entry) => entry.resource)) !== null && _b !== void 0 ? _b : [];
|
|
1554
|
+
});
|
|
1241
1555
|
}
|
|
1242
1556
|
/**
|
|
1243
1557
|
* Searches a ValueSet resource using the "expand" operation.
|
|
@@ -1246,10 +1560,10 @@ class MedplumClient extends EventTarget {
|
|
|
1246
1560
|
* @param filter The search string.
|
|
1247
1561
|
* @returns Promise to expanded ValueSet.
|
|
1248
1562
|
*/
|
|
1249
|
-
searchValueSet(system, filter) {
|
|
1563
|
+
searchValueSet(system, filter, options = {}) {
|
|
1250
1564
|
return this.get(this.fhirUrl('ValueSet', '$expand') +
|
|
1251
1565
|
`?url=${encodeURIComponent(system)}` +
|
|
1252
|
-
`&filter=${encodeURIComponent(filter)}
|
|
1566
|
+
`&filter=${encodeURIComponent(filter)}`, options);
|
|
1253
1567
|
}
|
|
1254
1568
|
/**
|
|
1255
1569
|
* Returns a cached resource if it is available.
|
|
@@ -1277,7 +1591,23 @@ class MedplumClient extends EventTarget {
|
|
|
1277
1591
|
}
|
|
1278
1592
|
return undefined;
|
|
1279
1593
|
}
|
|
1280
|
-
|
|
1594
|
+
/**
|
|
1595
|
+
* Reads a resource by resource type and ID.
|
|
1596
|
+
*
|
|
1597
|
+
* Example:
|
|
1598
|
+
*
|
|
1599
|
+
* ```typescript
|
|
1600
|
+
* const patient = await medplum.readResource('Patient', '123');
|
|
1601
|
+
* console.log(patient);
|
|
1602
|
+
* ```
|
|
1603
|
+
*
|
|
1604
|
+
* See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
|
|
1605
|
+
*
|
|
1606
|
+
* @param resourceType The FHIR resource type.
|
|
1607
|
+
* @param id The resource ID.
|
|
1608
|
+
* @returns The resource if available; undefined otherwise.
|
|
1609
|
+
*/
|
|
1610
|
+
readResource(resourceType, id) {
|
|
1281
1611
|
const cacheKey = resourceType + '/' + id;
|
|
1282
1612
|
const promise = this.get(this.fhirUrl(resourceType, id)).then((resource) => {
|
|
1283
1613
|
__classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").set(cacheKey, resource);
|
|
@@ -1286,18 +1616,74 @@ class MedplumClient extends EventTarget {
|
|
|
1286
1616
|
__classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").set(cacheKey, promise);
|
|
1287
1617
|
return promise;
|
|
1288
1618
|
}
|
|
1619
|
+
/**
|
|
1620
|
+
* Reads a resource by resource type and ID using the in-memory resource cache.
|
|
1621
|
+
*
|
|
1622
|
+
* If the resource is not available in the cache, it will be read from the server.
|
|
1623
|
+
*
|
|
1624
|
+
* Example:
|
|
1625
|
+
*
|
|
1626
|
+
* ```typescript
|
|
1627
|
+
* const patient = await medplum.readCached('Patient', '123');
|
|
1628
|
+
* console.log(patient);
|
|
1629
|
+
* ```
|
|
1630
|
+
*
|
|
1631
|
+
* See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
|
|
1632
|
+
*
|
|
1633
|
+
* @param resourceType The FHIR resource type.
|
|
1634
|
+
* @param id The resource ID.
|
|
1635
|
+
* @returns The resource if available; undefined otherwise.
|
|
1636
|
+
*/
|
|
1289
1637
|
readCached(resourceType, id) {
|
|
1290
1638
|
const cached = __classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").get(resourceType + '/' + id);
|
|
1291
|
-
return cached ? Promise.resolve(cached) : this.
|
|
1639
|
+
return cached ? Promise.resolve(cached) : this.readResource(resourceType, id);
|
|
1292
1640
|
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Reads a resource by `Reference`.
|
|
1643
|
+
*
|
|
1644
|
+
* This is a convenience method for `readResource()` that accepts a `Reference` object.
|
|
1645
|
+
*
|
|
1646
|
+
* Example:
|
|
1647
|
+
*
|
|
1648
|
+
* ```typescript
|
|
1649
|
+
* const serviceRequest = await medplum.readResource('ServiceRequest', '123');
|
|
1650
|
+
* const patient = await medplum.readReference(serviceRequest.subject);
|
|
1651
|
+
* console.log(patient);
|
|
1652
|
+
* ```
|
|
1653
|
+
*
|
|
1654
|
+
* See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
|
|
1655
|
+
*
|
|
1656
|
+
* @param reference The FHIR reference object.
|
|
1657
|
+
* @returns The resource if available; undefined otherwise.
|
|
1658
|
+
*/
|
|
1293
1659
|
readReference(reference) {
|
|
1294
1660
|
const refString = reference === null || reference === void 0 ? void 0 : reference.reference;
|
|
1295
1661
|
if (!refString) {
|
|
1296
1662
|
return Promise.reject('Missing reference');
|
|
1297
1663
|
}
|
|
1298
1664
|
const [resourceType, id] = refString.split('/');
|
|
1299
|
-
return this.
|
|
1665
|
+
return this.readResource(resourceType, id);
|
|
1300
1666
|
}
|
|
1667
|
+
/**
|
|
1668
|
+
* Reads a resource by `Reference` using the in-memory resource cache.
|
|
1669
|
+
*
|
|
1670
|
+
* This is a convenience method for `readResource()` that accepts a `Reference` object.
|
|
1671
|
+
*
|
|
1672
|
+
* If the resource is not available in the cache, it will be read from the server.
|
|
1673
|
+
*
|
|
1674
|
+
* Example:
|
|
1675
|
+
*
|
|
1676
|
+
* ```typescript
|
|
1677
|
+
* const serviceRequest = await medplum.readResource('ServiceRequest', '123');
|
|
1678
|
+
* const patient = await medplum.readCachedReference(serviceRequest.subject);
|
|
1679
|
+
* console.log(patient);
|
|
1680
|
+
* ```
|
|
1681
|
+
*
|
|
1682
|
+
* See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
|
|
1683
|
+
*
|
|
1684
|
+
* @param reference The FHIR reference object.
|
|
1685
|
+
* @returns The resource if available; undefined otherwise.
|
|
1686
|
+
*/
|
|
1301
1687
|
readCachedReference(reference) {
|
|
1302
1688
|
const refString = reference === null || reference === void 0 ? void 0 : reference.reference;
|
|
1303
1689
|
if (!refString) {
|
|
@@ -1366,38 +1752,181 @@ class MedplumClient extends EventTarget {
|
|
|
1366
1752
|
return __classPrivateFieldGet(this, _MedplumClient_schema, "f");
|
|
1367
1753
|
});
|
|
1368
1754
|
}
|
|
1755
|
+
/**
|
|
1756
|
+
* Reads resource history by resource type and ID.
|
|
1757
|
+
*
|
|
1758
|
+
* The return value is a bundle of all versions of the resource.
|
|
1759
|
+
*
|
|
1760
|
+
* Example:
|
|
1761
|
+
*
|
|
1762
|
+
* ```typescript
|
|
1763
|
+
* const history = await medplum.readHistory('Patient', '123');
|
|
1764
|
+
* console.log(history);
|
|
1765
|
+
* ```
|
|
1766
|
+
*
|
|
1767
|
+
* See the FHIR "history" operation for full details: https://www.hl7.org/fhir/http.html#history
|
|
1768
|
+
*
|
|
1769
|
+
* @param resourceType The FHIR resource type.
|
|
1770
|
+
* @param id The resource ID.
|
|
1771
|
+
* @returns The resource if available; undefined otherwise.
|
|
1772
|
+
*/
|
|
1369
1773
|
readHistory(resourceType, id) {
|
|
1370
1774
|
return this.get(this.fhirUrl(resourceType, id, '_history'));
|
|
1371
1775
|
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Reads a specific version of a resource by resource type, ID, and version ID.
|
|
1778
|
+
*
|
|
1779
|
+
* Example:
|
|
1780
|
+
*
|
|
1781
|
+
* ```typescript
|
|
1782
|
+
* const version = await medplum.readVersion('Patient', '123', '456');
|
|
1783
|
+
* console.log(version);
|
|
1784
|
+
* ```
|
|
1785
|
+
*
|
|
1786
|
+
* See the FHIR "vread" operation for full details: https://www.hl7.org/fhir/http.html#vread
|
|
1787
|
+
*
|
|
1788
|
+
* @param resourceType The FHIR resource type.
|
|
1789
|
+
* @param id The resource ID.
|
|
1790
|
+
* @returns The resource if available; undefined otherwise.
|
|
1791
|
+
*/
|
|
1792
|
+
readVersion(resourceType, id, vid) {
|
|
1793
|
+
return this.get(this.fhirUrl(resourceType, id, '_history', vid));
|
|
1794
|
+
}
|
|
1372
1795
|
readPatientEverything(id) {
|
|
1373
1796
|
return this.get(this.fhirUrl('Patient', id, '$everything'));
|
|
1374
1797
|
}
|
|
1375
|
-
|
|
1798
|
+
/**
|
|
1799
|
+
* Creates a new FHIR resource.
|
|
1800
|
+
*
|
|
1801
|
+
* The return value is the newly created resource, including the ID and meta.
|
|
1802
|
+
*
|
|
1803
|
+
* Example:
|
|
1804
|
+
*
|
|
1805
|
+
* ```typescript
|
|
1806
|
+
* const result = await medplum.createResource({
|
|
1807
|
+
* resourceType: 'Patient',
|
|
1808
|
+
* name: [{
|
|
1809
|
+
* family: 'Smith',
|
|
1810
|
+
* given: ['John']
|
|
1811
|
+
* }]
|
|
1812
|
+
* });
|
|
1813
|
+
* console.log(result.id);
|
|
1814
|
+
* ```
|
|
1815
|
+
*
|
|
1816
|
+
* See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
|
|
1817
|
+
*
|
|
1818
|
+
* @param resource The FHIR resource to create.
|
|
1819
|
+
* @returns The result of the create operation.
|
|
1820
|
+
*/
|
|
1821
|
+
createResource(resource) {
|
|
1376
1822
|
if (!resource.resourceType) {
|
|
1377
|
-
|
|
1823
|
+
return Promise.reject('Missing resourceType');
|
|
1378
1824
|
}
|
|
1379
1825
|
return this.post(this.fhirUrl(resource.resourceType), resource);
|
|
1380
1826
|
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Creates a FHIR `Binary` resource with the provided data content.
|
|
1829
|
+
*
|
|
1830
|
+
* The return value is the newly created resource, including the ID and meta.
|
|
1831
|
+
*
|
|
1832
|
+
* The `data` parameter can be a string or a `File` object.
|
|
1833
|
+
*
|
|
1834
|
+
* A `File` object often comes from a `<input type="file">` element.
|
|
1835
|
+
*
|
|
1836
|
+
* Example:
|
|
1837
|
+
*
|
|
1838
|
+
* ```typescript
|
|
1839
|
+
* const result = await medplum.createBinary(myFile, 'test.jpg', 'image/jpeg');
|
|
1840
|
+
* console.log(result.id);
|
|
1841
|
+
* ```
|
|
1842
|
+
*
|
|
1843
|
+
* See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
|
|
1844
|
+
*
|
|
1845
|
+
* @param resource The FHIR resource to create.
|
|
1846
|
+
* @returns The result of the create operation.
|
|
1847
|
+
*/
|
|
1381
1848
|
createBinary(data, filename, contentType) {
|
|
1382
1849
|
return this.post(this.fhirUrl('Binary') + '?_filename=' + encodeURIComponent(filename), data, contentType);
|
|
1383
1850
|
}
|
|
1384
|
-
|
|
1851
|
+
/**
|
|
1852
|
+
* Updates a FHIR resource.
|
|
1853
|
+
*
|
|
1854
|
+
* The return value is the updated resource, including the ID and meta.
|
|
1855
|
+
*
|
|
1856
|
+
* Example:
|
|
1857
|
+
*
|
|
1858
|
+
* ```typescript
|
|
1859
|
+
* const result = await medplum.updateResource({
|
|
1860
|
+
* resourceType: 'Patient',
|
|
1861
|
+
* id: '123',
|
|
1862
|
+
* name: [{
|
|
1863
|
+
* family: 'Smith',
|
|
1864
|
+
* given: ['John']
|
|
1865
|
+
* }]
|
|
1866
|
+
* });
|
|
1867
|
+
* console.log(result.meta.versionId);
|
|
1868
|
+
* ```
|
|
1869
|
+
*
|
|
1870
|
+
* See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#update
|
|
1871
|
+
*
|
|
1872
|
+
* @param resource The FHIR resource to update.
|
|
1873
|
+
* @returns The result of the update operation.
|
|
1874
|
+
*/
|
|
1875
|
+
updateResource(resource) {
|
|
1385
1876
|
if (!resource.resourceType) {
|
|
1386
|
-
|
|
1877
|
+
return Promise.reject('Missing resourceType');
|
|
1387
1878
|
}
|
|
1388
1879
|
if (!resource.id) {
|
|
1389
|
-
|
|
1880
|
+
return Promise.reject('Missing id');
|
|
1390
1881
|
}
|
|
1391
1882
|
return this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
|
|
1392
1883
|
}
|
|
1393
|
-
|
|
1394
|
-
|
|
1884
|
+
/**
|
|
1885
|
+
* Updates a FHIR resource using JSONPatch operations.
|
|
1886
|
+
*
|
|
1887
|
+
* The return value is the updated resource, including the ID and meta.
|
|
1888
|
+
*
|
|
1889
|
+
* Example:
|
|
1890
|
+
*
|
|
1891
|
+
* ```typescript
|
|
1892
|
+
* const result = await medplum.patchResource('Patient', '123', [
|
|
1893
|
+
* {op: 'replace', path: '/name/0/family', value: 'Smith'},
|
|
1894
|
+
* ]);
|
|
1895
|
+
* console.log(result.meta.versionId);
|
|
1896
|
+
* ```
|
|
1897
|
+
*
|
|
1898
|
+
* See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#patch
|
|
1899
|
+
*
|
|
1900
|
+
* See the JSONPatch specification for full details: https://tools.ietf.org/html/rfc6902
|
|
1901
|
+
*
|
|
1902
|
+
* @param resourceType The FHIR resource type.
|
|
1903
|
+
* @param id The resource ID.
|
|
1904
|
+
* @param operations The JSONPatch operations.
|
|
1905
|
+
* @returns The result of the patch operations.
|
|
1906
|
+
*/
|
|
1907
|
+
patchResource(resourceType, id, operations) {
|
|
1908
|
+
return this.patch(this.fhirUrl(resourceType, id), operations);
|
|
1395
1909
|
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Deletes a FHIR resource by resource type and ID.
|
|
1912
|
+
*
|
|
1913
|
+
* Example:
|
|
1914
|
+
*
|
|
1915
|
+
* ```typescript
|
|
1916
|
+
* await medplum.deleteResource('Patient', '123');
|
|
1917
|
+
* ```
|
|
1918
|
+
*
|
|
1919
|
+
* See the FHIR "delete" operation for full details: https://www.hl7.org/fhir/http.html#delete
|
|
1920
|
+
*
|
|
1921
|
+
* @param resourceType The FHIR resource type.
|
|
1922
|
+
* @param id The resource ID.
|
|
1923
|
+
* @returns The result of the delete operation.
|
|
1924
|
+
*/
|
|
1396
1925
|
deleteResource(resourceType, id) {
|
|
1397
1926
|
return this.delete(this.fhirUrl(resourceType, id));
|
|
1398
1927
|
}
|
|
1399
|
-
graphql(query) {
|
|
1400
|
-
return this.post(this.fhirUrl('$graphql'), { query }, JSON_CONTENT_TYPE);
|
|
1928
|
+
graphql(query, options) {
|
|
1929
|
+
return this.post(this.fhirUrl('$graphql'), { query }, JSON_CONTENT_TYPE, options);
|
|
1401
1930
|
}
|
|
1402
1931
|
getActiveLogin() {
|
|
1403
1932
|
return __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('activeLogin');
|
|
@@ -1415,6 +1944,12 @@ class MedplumClient extends EventTarget {
|
|
|
1415
1944
|
yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this);
|
|
1416
1945
|
});
|
|
1417
1946
|
}
|
|
1947
|
+
setAccessToken(accessToken) {
|
|
1948
|
+
__classPrivateFieldSet(this, _MedplumClient_accessToken, accessToken, "f");
|
|
1949
|
+
__classPrivateFieldSet(this, _MedplumClient_refreshToken, undefined, "f");
|
|
1950
|
+
__classPrivateFieldSet(this, _MedplumClient_profile, undefined, "f");
|
|
1951
|
+
__classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
|
|
1952
|
+
}
|
|
1418
1953
|
getLogins() {
|
|
1419
1954
|
var _a;
|
|
1420
1955
|
return (_a = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins')) !== null && _a !== void 0 ? _a : [];
|
|
@@ -1441,12 +1976,12 @@ class MedplumClient extends EventTarget {
|
|
|
1441
1976
|
* @param url The URL to request.
|
|
1442
1977
|
* @returns Promise to the response body as a blob.
|
|
1443
1978
|
*/
|
|
1444
|
-
download(url) {
|
|
1979
|
+
download(url, options = {}) {
|
|
1445
1980
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1446
1981
|
if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
|
|
1447
1982
|
yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
1448
1983
|
}
|
|
1449
|
-
|
|
1984
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
|
|
1450
1985
|
const response = yield __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options);
|
|
1451
1986
|
return response.blob();
|
|
1452
1987
|
});
|
|
@@ -1460,12 +1995,12 @@ class MedplumClient extends EventTarget {
|
|
|
1460
1995
|
const pkceState = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('pkceState');
|
|
1461
1996
|
if (!pkceState) {
|
|
1462
1997
|
this.clear();
|
|
1463
|
-
|
|
1998
|
+
return Promise.reject('Invalid PCKE state');
|
|
1464
1999
|
}
|
|
1465
2000
|
const codeVerifier = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeVerifier');
|
|
1466
2001
|
if (!codeVerifier) {
|
|
1467
2002
|
this.clear();
|
|
1468
|
-
|
|
2003
|
+
return Promise.reject('Invalid PCKE code verifier');
|
|
1469
2004
|
}
|
|
1470
2005
|
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, 'grant_type=authorization_code' +
|
|
1471
2006
|
(__classPrivateFieldGet(this, _MedplumClient_clientId, "f") ? '&client_id=' + encodeURIComponent(__classPrivateFieldGet(this, _MedplumClient_clientId, "f")) : '') +
|
|
@@ -1476,6 +2011,15 @@ class MedplumClient extends EventTarget {
|
|
|
1476
2011
|
'&code=' +
|
|
1477
2012
|
encodeURIComponent(code));
|
|
1478
2013
|
}
|
|
2014
|
+
clientCredentials(clientId, clientSecret) {
|
|
2015
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2016
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, 'grant_type=client_credentials' +
|
|
2017
|
+
'&client_id=' +
|
|
2018
|
+
encodeURIComponent(clientId) +
|
|
2019
|
+
'&client_secret=' +
|
|
2020
|
+
encodeURIComponent(clientSecret));
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
1479
2023
|
}
|
|
1480
2024
|
_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) {
|
|
1481
2025
|
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); });
|
|
@@ -1496,7 +2040,7 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_storage = new WeakMap(), _M
|
|
|
1496
2040
|
}), "f");
|
|
1497
2041
|
return __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
|
|
1498
2042
|
});
|
|
1499
|
-
}, _MedplumClient_request = function _MedplumClient_request(method, url,
|
|
2043
|
+
}, _MedplumClient_request = function _MedplumClient_request(method, url, options = {}) {
|
|
1500
2044
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1501
2045
|
if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
|
|
1502
2046
|
yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
@@ -1504,11 +2048,12 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_storage = new WeakMap(), _M
|
|
|
1504
2048
|
if (!url.startsWith('http')) {
|
|
1505
2049
|
url = __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + url;
|
|
1506
2050
|
}
|
|
1507
|
-
|
|
2051
|
+
options.method = method;
|
|
2052
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
|
|
1508
2053
|
const response = yield __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options);
|
|
1509
2054
|
if (response.status === 401) {
|
|
1510
2055
|
// Refresh and try again
|
|
1511
|
-
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_handleUnauthenticated).call(this, method, url,
|
|
2056
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_handleUnauthenticated).call(this, method, url, options);
|
|
1512
2057
|
}
|
|
1513
2058
|
if (response.status === 204 || response.status === 304) {
|
|
1514
2059
|
// No content or change
|
|
@@ -1520,32 +2065,40 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_storage = new WeakMap(), _M
|
|
|
1520
2065
|
}
|
|
1521
2066
|
return obj;
|
|
1522
2067
|
});
|
|
1523
|
-
},
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
}
|
|
2068
|
+
}, _MedplumClient_addFetchOptionsDefaults = function _MedplumClient_addFetchOptionsDefaults(options) {
|
|
2069
|
+
if (!options.headers) {
|
|
2070
|
+
options.headers = {};
|
|
2071
|
+
}
|
|
2072
|
+
const headers = options.headers;
|
|
2073
|
+
if (!headers['Content-Type']) {
|
|
2074
|
+
headers['Content-Type'] = FHIR_CONTENT_TYPE;
|
|
2075
|
+
}
|
|
1527
2076
|
if (__classPrivateFieldGet(this, _MedplumClient_accessToken, "f")) {
|
|
1528
2077
|
headers['Authorization'] = 'Bearer ' + __classPrivateFieldGet(this, _MedplumClient_accessToken, "f");
|
|
1529
2078
|
}
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
}
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
}
|
|
1540
|
-
else {
|
|
1541
|
-
options.body = stringify(body);
|
|
1542
|
-
}
|
|
2079
|
+
if (!options.cache) {
|
|
2080
|
+
options.cache = 'no-cache';
|
|
2081
|
+
}
|
|
2082
|
+
if (!options.credentials) {
|
|
2083
|
+
options.credentials = 'include';
|
|
2084
|
+
}
|
|
2085
|
+
}, _MedplumClient_setRequestContentType = function _MedplumClient_setRequestContentType(options, contentType) {
|
|
2086
|
+
if (!options.headers) {
|
|
2087
|
+
options.headers = {};
|
|
1543
2088
|
}
|
|
1544
|
-
|
|
1545
|
-
|
|
2089
|
+
const headers = options.headers;
|
|
2090
|
+
headers['Content-Type'] = contentType;
|
|
2091
|
+
}, _MedplumClient_setRequestBody = function _MedplumClient_setRequestBody(options, data) {
|
|
2092
|
+
if (typeof data === 'string' || (typeof File !== 'undefined' && data instanceof File)) {
|
|
2093
|
+
options.body = data;
|
|
2094
|
+
}
|
|
2095
|
+
else if (data) {
|
|
2096
|
+
options.body = stringify(data);
|
|
2097
|
+
}
|
|
2098
|
+
}, _MedplumClient_handleUnauthenticated = function _MedplumClient_handleUnauthenticated(method, url, options) {
|
|
1546
2099
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1547
2100
|
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refresh).call(this)
|
|
1548
|
-
.then(() => __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, method, url,
|
|
2101
|
+
.then(() => __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, method, url, options))
|
|
1549
2102
|
.catch((error) => {
|
|
1550
2103
|
this.clear();
|
|
1551
2104
|
if (__classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f")) {
|
|
@@ -1567,7 +2120,7 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_storage = new WeakMap(), _M
|
|
|
1567
2120
|
}, _MedplumClient_requestAuthorization = function _MedplumClient_requestAuthorization() {
|
|
1568
2121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1569
2122
|
if (!__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f")) {
|
|
1570
|
-
|
|
2123
|
+
return Promise.reject('Missing authorize URL');
|
|
1571
2124
|
}
|
|
1572
2125
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
|
|
1573
2126
|
window.location.assign(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f") +
|
|
@@ -1662,6 +2215,209 @@ function getBaseUrl() {
|
|
|
1662
2215
|
return window.location.protocol + '//' + window.location.host + '/';
|
|
1663
2216
|
}
|
|
1664
2217
|
|
|
2218
|
+
var _LegacyRepositoryClient_client;
|
|
2219
|
+
/**
|
|
2220
|
+
* The LegacyRepositoryClient is a supplementary API client that matches the legacy "Repository" API.
|
|
2221
|
+
* The "Repository" API is deprecated and will be removed in a future release.
|
|
2222
|
+
* This LegacyRepositoryClient is also deprecated and will be removed in a future release.
|
|
2223
|
+
* @deprecated
|
|
2224
|
+
*/
|
|
2225
|
+
class LegacyRepositoryClient {
|
|
2226
|
+
constructor(client) {
|
|
2227
|
+
_LegacyRepositoryClient_client.set(this, void 0);
|
|
2228
|
+
__classPrivateFieldSet(this, _LegacyRepositoryClient_client, client, "f");
|
|
2229
|
+
}
|
|
2230
|
+
/**
|
|
2231
|
+
* Creates a resource.
|
|
2232
|
+
*
|
|
2233
|
+
* See: https://www.hl7.org/fhir/http.html#create
|
|
2234
|
+
*
|
|
2235
|
+
* @param resource The resource to create.
|
|
2236
|
+
* @returns Operation outcome and the new resource.
|
|
2237
|
+
* @deprecated
|
|
2238
|
+
*/
|
|
2239
|
+
createResource(resource) {
|
|
2240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2241
|
+
try {
|
|
2242
|
+
const result = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").createResource(resource);
|
|
2243
|
+
return [created, result];
|
|
2244
|
+
}
|
|
2245
|
+
catch (error) {
|
|
2246
|
+
return [error, undefined];
|
|
2247
|
+
}
|
|
2248
|
+
});
|
|
2249
|
+
}
|
|
2250
|
+
/**
|
|
2251
|
+
* Returns a resource.
|
|
2252
|
+
*
|
|
2253
|
+
* See: https://www.hl7.org/fhir/http.html#read
|
|
2254
|
+
*
|
|
2255
|
+
* @param resourceType The FHIR resource type.
|
|
2256
|
+
* @param id The FHIR resource ID.
|
|
2257
|
+
* @returns Operation outcome and a resource.
|
|
2258
|
+
* @deprecated
|
|
2259
|
+
*/
|
|
2260
|
+
readResource(resourceType, id) {
|
|
2261
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2262
|
+
try {
|
|
2263
|
+
const resource = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").readResource(resourceType, id);
|
|
2264
|
+
return [allOk, resource];
|
|
2265
|
+
}
|
|
2266
|
+
catch (error) {
|
|
2267
|
+
return [error, undefined];
|
|
2268
|
+
}
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2271
|
+
/**
|
|
2272
|
+
* Returns a resource by FHIR reference.
|
|
2273
|
+
*
|
|
2274
|
+
* See: https://www.hl7.org/fhir/http.html#read
|
|
2275
|
+
*
|
|
2276
|
+
* @param reference The FHIR reference.
|
|
2277
|
+
* @returns Operation outcome and a resource.
|
|
2278
|
+
* @deprecated
|
|
2279
|
+
*/
|
|
2280
|
+
readReference(reference) {
|
|
2281
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2282
|
+
try {
|
|
2283
|
+
const resource = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").readReference(reference);
|
|
2284
|
+
return [allOk, resource];
|
|
2285
|
+
}
|
|
2286
|
+
catch (error) {
|
|
2287
|
+
return [error, undefined];
|
|
2288
|
+
}
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
/**
|
|
2292
|
+
* Returns resource history.
|
|
2293
|
+
*
|
|
2294
|
+
* See: https://www.hl7.org/fhir/http.html#history
|
|
2295
|
+
*
|
|
2296
|
+
* @param resourceType The FHIR resource type.
|
|
2297
|
+
* @param id The FHIR resource ID.
|
|
2298
|
+
* @returns Operation outcome and a history bundle.
|
|
2299
|
+
* @deprecated
|
|
2300
|
+
*/
|
|
2301
|
+
readHistory(resourceType, id) {
|
|
2302
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2303
|
+
try {
|
|
2304
|
+
const resource = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").readHistory(resourceType, id);
|
|
2305
|
+
return [allOk, resource];
|
|
2306
|
+
}
|
|
2307
|
+
catch (error) {
|
|
2308
|
+
return [error, undefined];
|
|
2309
|
+
}
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Returns a resource version.
|
|
2314
|
+
*
|
|
2315
|
+
* See: https://www.hl7.org/fhir/http.html#vread
|
|
2316
|
+
*
|
|
2317
|
+
* @param resourceType The FHIR resource type.
|
|
2318
|
+
* @param id The FHIR resource ID.
|
|
2319
|
+
* @param vid The version ID.
|
|
2320
|
+
* @returns Operation outcome and a resource.
|
|
2321
|
+
* @deprecated
|
|
2322
|
+
*/
|
|
2323
|
+
readVersion(resourceType, id, vid) {
|
|
2324
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2325
|
+
try {
|
|
2326
|
+
const resource = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").readVersion(resourceType, id, vid);
|
|
2327
|
+
return [allOk, resource];
|
|
2328
|
+
}
|
|
2329
|
+
catch (error) {
|
|
2330
|
+
return [error, undefined];
|
|
2331
|
+
}
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
2334
|
+
/**
|
|
2335
|
+
* Updates a resource.
|
|
2336
|
+
*
|
|
2337
|
+
* See: https://www.hl7.org/fhir/http.html#update
|
|
2338
|
+
*
|
|
2339
|
+
* @param resource The resource to update.
|
|
2340
|
+
* @returns Operation outcome and the updated resource.
|
|
2341
|
+
* @deprecated
|
|
2342
|
+
*/
|
|
2343
|
+
updateResource(resource) {
|
|
2344
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2345
|
+
try {
|
|
2346
|
+
const updated = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").updateResource(resource);
|
|
2347
|
+
return [allOk, updated];
|
|
2348
|
+
}
|
|
2349
|
+
catch (error) {
|
|
2350
|
+
return [error, undefined];
|
|
2351
|
+
}
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
/**
|
|
2355
|
+
* Deletes a resource.
|
|
2356
|
+
*
|
|
2357
|
+
* See: https://www.hl7.org/fhir/http.html#delete
|
|
2358
|
+
*
|
|
2359
|
+
* @param resourceType The FHIR resource type.
|
|
2360
|
+
* @param id The resource ID.
|
|
2361
|
+
* @returns Operation outcome.
|
|
2362
|
+
* @deprecated
|
|
2363
|
+
*/
|
|
2364
|
+
deleteResource(resourceType, id) {
|
|
2365
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2366
|
+
try {
|
|
2367
|
+
yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").deleteResource(resourceType, id);
|
|
2368
|
+
return [allOk, undefined];
|
|
2369
|
+
}
|
|
2370
|
+
catch (error) {
|
|
2371
|
+
return [error, undefined];
|
|
2372
|
+
}
|
|
2373
|
+
});
|
|
2374
|
+
}
|
|
2375
|
+
/**
|
|
2376
|
+
* Patches a resource.
|
|
2377
|
+
*
|
|
2378
|
+
* See: https://www.hl7.org/fhir/http.html#patch
|
|
2379
|
+
*
|
|
2380
|
+
* @param resourceType The FHIR resource type.
|
|
2381
|
+
* @param id The resource ID.
|
|
2382
|
+
* @param patch Array of JSONPatch operations.
|
|
2383
|
+
* @returns Operation outcome and the resource.
|
|
2384
|
+
* @deprecated
|
|
2385
|
+
*/
|
|
2386
|
+
patchResource(resourceType, id, patch) {
|
|
2387
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2388
|
+
try {
|
|
2389
|
+
const resource = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").patchResource(resourceType, id, patch);
|
|
2390
|
+
return [allOk, resource];
|
|
2391
|
+
}
|
|
2392
|
+
catch (error) {
|
|
2393
|
+
return [error, undefined];
|
|
2394
|
+
}
|
|
2395
|
+
});
|
|
2396
|
+
}
|
|
2397
|
+
/**
|
|
2398
|
+
* Searches for resources.
|
|
2399
|
+
*
|
|
2400
|
+
* See: https://www.hl7.org/fhir/http.html#search
|
|
2401
|
+
*
|
|
2402
|
+
* @param searchRequest The search request.
|
|
2403
|
+
* @returns The search result bundle.
|
|
2404
|
+
* @deprecated
|
|
2405
|
+
*/
|
|
2406
|
+
search(query) {
|
|
2407
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2408
|
+
const searchRequest = typeof query === 'string' ? parseSearchDefinition(query) : query;
|
|
2409
|
+
try {
|
|
2410
|
+
const bundle = yield __classPrivateFieldGet(this, _LegacyRepositoryClient_client, "f").search(searchRequest);
|
|
2411
|
+
return [allOk, bundle];
|
|
2412
|
+
}
|
|
2413
|
+
catch (error) {
|
|
2414
|
+
return [error, undefined];
|
|
2415
|
+
}
|
|
2416
|
+
});
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
_LegacyRepositoryClient_client = new WeakMap();
|
|
2420
|
+
|
|
1665
2421
|
var SearchParameterType;
|
|
1666
2422
|
(function (SearchParameterType) {
|
|
1667
2423
|
SearchParameterType["BOOLEAN"] = "BOOLEAN";
|
|
@@ -1788,5 +2544,5 @@ function simplifyExpression(input) {
|
|
|
1788
2544
|
return result;
|
|
1789
2545
|
}
|
|
1790
2546
|
|
|
1791
|
-
export { MedplumClient, OperationOutcomeError, Operator, PropertyType, SearchParameterType, accessDenied, allOk, arrayBufferToBase64, arrayBufferToHex, assertOk, badRequest, buildTypeName, capitalize, createReference, createSchema, createTypeSchema, created, deepEquals, formatAddress, formatFamilyName, formatGivenName, formatHumanName, formatSearchQuery, getDateProperty, getDisplayString, getExpressionForResourceType, getImageSrc, getPropertyDisplayName, getReferenceString, getSearchParameterDetails, getStatus, gone, indexSearchParameter, indexStructureDefinition, isGone, isLowerCase, isNotFound, isOk, isProfileResource, notFound, notModified, parseSearchDefinition, resolveId, stringify };
|
|
2547
|
+
export { LegacyRepositoryClient, MedplumClient, OperationOutcomeError, Operator, PropertyType, SearchParameterType, accessDenied, allOk, arrayBufferToBase64, arrayBufferToHex, assertOk, badRequest, buildTypeName, calculateAge, calculateAgeString, capitalize, createReference, createSchema, createTypeSchema, created, deepEquals, formatAddress, formatFamilyName, formatGivenName, formatHumanName, formatSearchQuery, getDateProperty, getDisplayString, getExpressionForResourceType, getImageSrc, getPropertyDisplayName, getReferenceString, getSearchParameterDetails, getStatus, gone, indexSearchParameter, indexStructureDefinition, isGone, isLowerCase, isNotFound, isOk, isProfileResource, notFound, notModified, parseSearchDefinition, resolveId, stringify };
|
|
1792
2548
|
//# sourceMappingURL=index.js.map
|