@medplum/core 1.0.1 → 1.0.2

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.
@@ -207,7 +207,7 @@ export interface TokenResponse {
207
207
  readonly project: Reference<Project>;
208
208
  readonly profile: Reference<ProfileResource>;
209
209
  }
210
- export interface BotEvent<T = Resource | Hl7Message | string> {
210
+ export interface BotEvent<T = Resource | Hl7Message | string | Record<string, any>> {
211
211
  readonly contentType: string;
212
212
  readonly input: T;
213
213
  readonly secrets: Record<string, ProjectSecret>;
@@ -2,7 +2,7 @@ interface Event {
2
2
  readonly type: string;
3
3
  readonly defaultPrevented?: boolean;
4
4
  }
5
- declare type EventListener = (e: Event) => void;
5
+ type EventListener = (e: Event) => void;
6
6
  export declare class EventTarget {
7
7
  #private;
8
8
  constructor();
@@ -22,9 +22,10 @@ export declare function formatTiming(timing: Timing | undefined): string;
22
22
  /**
23
23
  * Returns a human-readable string for a FHIR Range datatype, taking into account comparators and one-sided ranges
24
24
  * @param range A FHIR Range element
25
+ * @param exclusive If true, one-sided ranges will be rendered with the '>' or '<' bounds rather than '>=' or '<='
25
26
  * @returns A human-readable string representation of the Range
26
27
  */
27
- export declare function formatRange(range: Range | undefined): string;
28
+ export declare function formatRange(range: Range | undefined, precision?: number, exclusive?: boolean): string;
28
29
  /**
29
30
  * Returns a human-readable string for a FHIR Quantity datatype, taking into account units and comparators
30
31
  * @param quantity A FHIR Quantity element
package/dist/cjs/index.js CHANGED
@@ -264,20 +264,37 @@
264
264
  /**
265
265
  * Returns a human-readable string for a FHIR Range datatype, taking into account comparators and one-sided ranges
266
266
  * @param range A FHIR Range element
267
+ * @param exclusive If true, one-sided ranges will be rendered with the '>' or '<' bounds rather than '>=' or '<='
267
268
  * @returns A human-readable string representation of the Range
268
269
  */
269
- function formatRange(range) {
270
- var _a, _b, _c, _d, _e, _f;
271
- if (!range || (((_a = range.low) === null || _a === void 0 ? void 0 : _a.value) === undefined && ((_b = range.high) === null || _b === void 0 ? void 0 : _b.value) === undefined)) {
270
+ function formatRange(range, precision, exclusive = false) {
271
+ var _a, _b, _c, _d;
272
+ if (exclusive && precision === undefined) {
273
+ throw new Error('Precision must be specified for exclusive ranges');
274
+ }
275
+ const low = (range === null || range === void 0 ? void 0 : range.low) && Object.assign({}, range.low);
276
+ const high = (range === null || range === void 0 ? void 0 : range.high) && Object.assign({}, range.high);
277
+ if (!range || ((low === null || low === void 0 ? void 0 : low.value) === undefined && (high === null || high === void 0 ? void 0 : high.value) === undefined)) {
272
278
  return '';
273
279
  }
274
- if (((_c = range.low) === null || _c === void 0 ? void 0 : _c.value) !== undefined && ((_d = range.high) === null || _d === void 0 ? void 0 : _d.value) === undefined) {
275
- return `>= ${formatQuantity(range.low)}`;
280
+ if (((_a = range.low) === null || _a === void 0 ? void 0 : _a.value) !== undefined && ((_b = range.high) === null || _b === void 0 ? void 0 : _b.value) === undefined) {
281
+ if (exclusive && precision !== undefined) {
282
+ range.low.value = preciseDecrement(range.low.value, precision);
283
+ return `> ${formatQuantity(range.low, precision)}`;
284
+ }
285
+ return `>= ${formatQuantity(range.low, precision)}`;
276
286
  }
277
- if (((_e = range.low) === null || _e === void 0 ? void 0 : _e.value) === undefined && ((_f = range.high) === null || _f === void 0 ? void 0 : _f.value) !== undefined) {
278
- return `<= ${formatQuantity(range.high)}`;
287
+ if (((_c = range.low) === null || _c === void 0 ? void 0 : _c.value) === undefined && ((_d = range.high) === null || _d === void 0 ? void 0 : _d.value) !== undefined) {
288
+ if (exclusive && precision !== undefined) {
289
+ range.high.value = preciseIncrement(range.high.value, precision);
290
+ return `< ${formatQuantity(range.high, precision)}`;
291
+ }
292
+ return `<= ${formatQuantity(range.high, precision)}`;
279
293
  }
280
- return `${formatQuantity(range.low)} - ${formatQuantity(range.high)}`;
294
+ if ((low === null || low === void 0 ? void 0 : low.unit) === (high === null || high === void 0 ? void 0 : high.unit)) {
295
+ low === null || low === void 0 ? true : delete low.unit;
296
+ }
297
+ return `${formatQuantity(low, precision)} - ${formatQuantity(high, precision)}`;
281
298
  }
282
299
  /**
283
300
  * Returns a human-readable string for a FHIR Quantity datatype, taking into account units and comparators
@@ -309,6 +326,37 @@
309
326
  }
310
327
  return result.join('').trim();
311
328
  }
329
+ /**
330
+ * Returns the input number increased by the `n` units of the specified precision
331
+ * @param a The input number
332
+ * @param precision The precision in number of digits.
333
+ * @param n (default 1) The number of units to add
334
+ */
335
+ function preciseIncrement(a, precision, n = 1) {
336
+ return (toPreciseInteger$1(a, precision) + n) * Math.pow(10, -precision);
337
+ }
338
+ /**
339
+ * Returns the input number decreased by the `n` units of the specified precision
340
+ * @param a The input number
341
+ * @param precision The precision in number of digits.
342
+ * @param n (default 1) The number of units to subtract
343
+ */
344
+ function preciseDecrement(a, precision, n = 1) {
345
+ return (toPreciseInteger$1(a, precision) - n) * Math.pow(10, -precision);
346
+ }
347
+ /**
348
+ * Returns an integer representation of the number with the given precision.
349
+ * For example, if precision is 2, then 1.2345 will be returned as 123.
350
+ * @param a The number.
351
+ * @param precision Optional precision in number of digits.
352
+ * @returns The integer with the given precision.
353
+ */
354
+ function toPreciseInteger$1(a, precision) {
355
+ if (precision === undefined) {
356
+ return a;
357
+ }
358
+ return Math.round(a * Math.pow(10, precision));
359
+ }
312
360
 
313
361
  /**
314
362
  * Creates a reference resource.
@@ -6322,7 +6370,7 @@
6322
6370
  // PKCE auth based on:
6323
6371
  // https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
6324
6372
  var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _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_getCacheEntry, _MedplumClient_setCacheEntry, _MedplumClient_request, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
6325
- const MEDPLUM_VERSION = "1.0.1-69d972ca";
6373
+ const MEDPLUM_VERSION = "1.0.2-0ed0f55a";
6326
6374
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
6327
6375
  const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
6328
6376
  const DEFAULT_CACHE_TIME = 60000; // 60 seconds