@medplum/core 1.0.1 → 1.0.3

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();
@@ -1,7 +1,8 @@
1
- import { Address, HumanName, Period, Timing, Range, Quantity } from '@medplum/fhirtypes';
1
+ import { Address, CodeableConcept, Coding, HumanName, Observation, ObservationComponent, Period, Quantity, Range, Timing } from '@medplum/fhirtypes';
2
2
  export interface AddressFormatOptions {
3
3
  all?: boolean;
4
4
  use?: boolean;
5
+ lineSeparator?: string;
5
6
  }
6
7
  export interface HumanNameFormatOptions {
7
8
  all?: boolean;
@@ -9,25 +10,108 @@ export interface HumanNameFormatOptions {
9
10
  suffix?: boolean;
10
11
  use?: boolean;
11
12
  }
13
+ /**
14
+ * Formats a FHIR Address as a string.
15
+ * @param address The address to format.
16
+ * @param options Optional address format options.
17
+ * @returns The formatted address string.
18
+ */
12
19
  export declare function formatAddress(address: Address, options?: AddressFormatOptions): string;
20
+ /**
21
+ * Formats a FHIR HumanName as a string.
22
+ * @param name The name to format.
23
+ * @param options Optional name format options.
24
+ * @returns The formatted name string.
25
+ */
13
26
  export declare function formatHumanName(name: HumanName, options?: HumanNameFormatOptions): string;
27
+ /**
28
+ * Formats the given name portion of a FHIR HumanName element.
29
+ * @param name The name to format.
30
+ * @returns The formatted given name string.
31
+ */
14
32
  export declare function formatGivenName(name: HumanName): string;
33
+ /**
34
+ * Formats the family name portion of a FHIR HumanName element.
35
+ * @param name The name to format.
36
+ * @returns The formatted family name string.
37
+ */
15
38
  export declare function formatFamilyName(name: HumanName): string;
39
+ /**
40
+ * Returns true if the given date object is a valid date.
41
+ * Dates can be invalid if created by parsing an invalid string.
42
+ * @param date A date object.
43
+ * @returns Returns true if the date is a valid date.
44
+ */
16
45
  export declare function isValidDate(date: Date): boolean;
17
- export declare function formatDate(date: string | undefined, options?: Intl.DateTimeFormatOptions): string;
18
- export declare function formatTime(time: string | undefined, options?: Intl.DateTimeFormatOptions): string;
19
- export declare function formatDateTime(dateTime: string | undefined, options?: Intl.DateTimeFormatOptions): string;
20
- export declare function formatPeriod(period: Period | undefined): string;
46
+ /**
47
+ * Formats a FHIR date string as a human readable string.
48
+ * Handles missing values and invalid dates.
49
+ * @param date The date to format.
50
+ * @param locales Optional locales.
51
+ * @param options Optional date format options.
52
+ * @returns The formatted date string.
53
+ */
54
+ export declare function formatDate(date: string | undefined, locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions | undefined): string;
55
+ /**
56
+ * Formats a FHIR time string as a human readable string.
57
+ * Handles missing values and invalid dates.
58
+ * @param time The date to format.
59
+ * @param locales Optional locales.
60
+ * @param options Optional time format options.
61
+ * @returns The formatted time string.
62
+ */
63
+ export declare function formatTime(time: string | undefined, locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions | undefined): string;
64
+ /**
65
+ * Formats a FHIR dateTime string as a human readable string.
66
+ * Handles missing values and invalid dates.
67
+ * @param dateTime The dateTime to format.
68
+ * @param locales Optional locales.
69
+ * @param options Optional dateTime format options.
70
+ * @returns The formatted dateTime string.
71
+ */
72
+ export declare function formatDateTime(dateTime: string | undefined, locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions | undefined): string;
73
+ /**
74
+ * Formats a FHIR Period as a human readable string.
75
+ * @param period The period to format.
76
+ * @param locales Optional locales.
77
+ * @param options Optional period format options.
78
+ * @returns The formatted period string.
79
+ */
80
+ export declare function formatPeriod(period: Period | undefined, locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions | undefined): string;
81
+ /**
82
+ * Formats a FHIR Timing as a human readable string.
83
+ * @param timing The timing to format.
84
+ * @returns The formatted timing string.
85
+ */
21
86
  export declare function formatTiming(timing: Timing | undefined): string;
22
87
  /**
23
88
  * Returns a human-readable string for a FHIR Range datatype, taking into account comparators and one-sided ranges
24
89
  * @param range A FHIR Range element
90
+ * @param exclusive If true, one-sided ranges will be rendered with the '>' or '<' bounds rather than '>=' or '<='
25
91
  * @returns A human-readable string representation of the Range
26
92
  */
27
- export declare function formatRange(range: Range | undefined): string;
93
+ export declare function formatRange(range: Range | undefined, precision?: number, exclusive?: boolean): string;
28
94
  /**
29
95
  * Returns a human-readable string for a FHIR Quantity datatype, taking into account units and comparators
30
96
  * @param quantity A FHIR Quantity element
31
97
  * @returns A human-readable string representation of the Quantity
32
98
  */
33
99
  export declare function formatQuantity(quantity: Quantity | undefined, precision?: number): string;
100
+ /**
101
+ * Formats a CodeableConcept element as a string.
102
+ * @param codeableConcept A FHIR CodeableConcept element
103
+ * @returns The codeable concept as a string.
104
+ */
105
+ export declare function formatCodeableConcept(codeableConcept: CodeableConcept | undefined): string;
106
+ /**
107
+ * Formats a Coding element as a string.
108
+ * @param coding A FHIR Coding element
109
+ * @returns The coding as a string.
110
+ */
111
+ export declare function formatCoding(coding: Coding | undefined): string;
112
+ /**
113
+ * Formats a FHIR Observation resource value as a string.
114
+ * @param obs A FHIR Observation resource.
115
+ * @returns A human-readable string representation of the Observation.
116
+ */
117
+ export declare function formatObservationValue(obs: Observation | ObservationComponent | undefined): string;
package/dist/cjs/index.js CHANGED
@@ -108,25 +108,41 @@
108
108
  return __classPrivateFieldGet(this, _LRUCache_cache, "f").keys().next().value;
109
109
  };
110
110
 
111
+ /**
112
+ * Formats a FHIR Address as a string.
113
+ * @param address The address to format.
114
+ * @param options Optional address format options.
115
+ * @returns The formatted address string.
116
+ */
111
117
  function formatAddress(address, options) {
112
118
  const builder = [];
113
119
  if (address.line) {
114
120
  builder.push(...address.line);
115
121
  }
116
- if (address.city) {
117
- builder.push(address.city);
118
- }
119
- if (address.state) {
120
- builder.push(address.state);
121
- }
122
- if (address.postalCode) {
123
- builder.push(address.postalCode);
122
+ if (address.city || address.state || address.postalCode) {
123
+ const cityStateZip = [];
124
+ if (address.city) {
125
+ cityStateZip.push(address.city);
126
+ }
127
+ if (address.state) {
128
+ cityStateZip.push(address.state);
129
+ }
130
+ if (address.postalCode) {
131
+ cityStateZip.push(address.postalCode);
132
+ }
133
+ builder.push(cityStateZip.join(', '));
124
134
  }
125
135
  if (address.use && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.use))) {
126
136
  builder.push('[' + address.use + ']');
127
137
  }
128
- return builder.join(', ').trim();
138
+ return builder.join((options === null || options === void 0 ? void 0 : options.lineSeparator) || ', ').trim();
129
139
  }
140
+ /**
141
+ * Formats a FHIR HumanName as a string.
142
+ * @param name The name to format.
143
+ * @param options Optional name format options.
144
+ * @returns The formatted name string.
145
+ */
130
146
  function formatHumanName(name, options) {
131
147
  const builder = [];
132
148
  if (name.prefix && (options === null || options === void 0 ? void 0 : options.prefix) !== false) {
@@ -146,6 +162,11 @@
146
162
  }
147
163
  return builder.join(' ').trim();
148
164
  }
165
+ /**
166
+ * Formats the given name portion of a FHIR HumanName element.
167
+ * @param name The name to format.
168
+ * @returns The formatted given name string.
169
+ */
149
170
  function formatGivenName(name) {
150
171
  const builder = [];
151
172
  if (name.given) {
@@ -153,13 +174,32 @@
153
174
  }
154
175
  return builder.join(' ').trim();
155
176
  }
177
+ /**
178
+ * Formats the family name portion of a FHIR HumanName element.
179
+ * @param name The name to format.
180
+ * @returns The formatted family name string.
181
+ */
156
182
  function formatFamilyName(name) {
157
183
  return name.family || '';
158
184
  }
185
+ /**
186
+ * Returns true if the given date object is a valid date.
187
+ * Dates can be invalid if created by parsing an invalid string.
188
+ * @param date A date object.
189
+ * @returns Returns true if the date is a valid date.
190
+ */
159
191
  function isValidDate(date) {
160
192
  return date instanceof Date && !isNaN(date.getTime());
161
193
  }
162
- function formatDate(date, options) {
194
+ /**
195
+ * Formats a FHIR date string as a human readable string.
196
+ * Handles missing values and invalid dates.
197
+ * @param date The date to format.
198
+ * @param locales Optional locales.
199
+ * @param options Optional date format options.
200
+ * @returns The formatted date string.
201
+ */
202
+ function formatDate(date, locales, options) {
163
203
  if (!date) {
164
204
  return '';
165
205
  }
@@ -167,9 +207,18 @@
167
207
  if (!isValidDate(d)) {
168
208
  return '';
169
209
  }
170
- return d.toLocaleDateString(undefined, options);
210
+ d.setUTCHours(0, 0, 0, 0);
211
+ return d.toLocaleDateString(locales, Object.assign({ timeZone: 'UTC' }, options));
171
212
  }
172
- function formatTime(time, options) {
213
+ /**
214
+ * Formats a FHIR time string as a human readable string.
215
+ * Handles missing values and invalid dates.
216
+ * @param time The date to format.
217
+ * @param locales Optional locales.
218
+ * @param options Optional time format options.
219
+ * @returns The formatted time string.
220
+ */
221
+ function formatTime(time, locales, options) {
173
222
  if (!time) {
174
223
  return '';
175
224
  }
@@ -177,9 +226,17 @@
177
226
  if (!isValidDate(d)) {
178
227
  return '';
179
228
  }
180
- return d.toLocaleTimeString(undefined, options);
229
+ return d.toLocaleTimeString(locales, options);
181
230
  }
182
- function formatDateTime(dateTime, options) {
231
+ /**
232
+ * Formats a FHIR dateTime string as a human readable string.
233
+ * Handles missing values and invalid dates.
234
+ * @param dateTime The dateTime to format.
235
+ * @param locales Optional locales.
236
+ * @param options Optional dateTime format options.
237
+ * @returns The formatted dateTime string.
238
+ */
239
+ function formatDateTime(dateTime, locales, options) {
183
240
  if (!dateTime) {
184
241
  return '';
185
242
  }
@@ -187,13 +244,20 @@
187
244
  if (!isValidDate(d)) {
188
245
  return '';
189
246
  }
190
- return d.toLocaleString(undefined, options);
247
+ return d.toLocaleString(locales, options);
191
248
  }
192
- function formatPeriod(period) {
249
+ /**
250
+ * Formats a FHIR Period as a human readable string.
251
+ * @param period The period to format.
252
+ * @param locales Optional locales.
253
+ * @param options Optional period format options.
254
+ * @returns The formatted period string.
255
+ */
256
+ function formatPeriod(period, locales, options) {
193
257
  if (!period || (!period.start && !period.end)) {
194
258
  return '';
195
259
  }
196
- return formatDateTime(period.start) + ' - ' + formatDateTime(period.end);
260
+ return formatDateTime(period.start, locales, options) + ' - ' + formatDateTime(period.end, locales, options);
197
261
  }
198
262
  const unitAdverbForm = {
199
263
  s: 'every second',
@@ -222,6 +286,11 @@
222
286
  mo: 'months',
223
287
  a: 'years',
224
288
  };
289
+ /**
290
+ * Formats a FHIR Timing as a human readable string.
291
+ * @param timing The timing to format.
292
+ * @returns The formatted timing string.
293
+ */
225
294
  function formatTiming(timing) {
226
295
  var _a;
227
296
  if (!timing) {
@@ -264,20 +333,37 @@
264
333
  /**
265
334
  * Returns a human-readable string for a FHIR Range datatype, taking into account comparators and one-sided ranges
266
335
  * @param range A FHIR Range element
336
+ * @param exclusive If true, one-sided ranges will be rendered with the '>' or '<' bounds rather than '>=' or '<='
267
337
  * @returns A human-readable string representation of the Range
268
338
  */
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)) {
339
+ function formatRange(range, precision, exclusive = false) {
340
+ var _a, _b, _c, _d;
341
+ if (exclusive && precision === undefined) {
342
+ throw new Error('Precision must be specified for exclusive ranges');
343
+ }
344
+ const low = (range === null || range === void 0 ? void 0 : range.low) && Object.assign({}, range.low);
345
+ const high = (range === null || range === void 0 ? void 0 : range.high) && Object.assign({}, range.high);
346
+ if (!range || ((low === null || low === void 0 ? void 0 : low.value) === undefined && (high === null || high === void 0 ? void 0 : high.value) === undefined)) {
272
347
  return '';
273
348
  }
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)}`;
349
+ 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) {
350
+ if (exclusive && precision !== undefined) {
351
+ range.low.value = preciseDecrement(range.low.value, precision);
352
+ return `> ${formatQuantity(range.low, precision)}`;
353
+ }
354
+ return `>= ${formatQuantity(range.low, precision)}`;
355
+ }
356
+ 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) {
357
+ if (exclusive && precision !== undefined) {
358
+ range.high.value = preciseIncrement(range.high.value, precision);
359
+ return `< ${formatQuantity(range.high, precision)}`;
360
+ }
361
+ return `<= ${formatQuantity(range.high, precision)}`;
276
362
  }
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)}`;
363
+ if ((low === null || low === void 0 ? void 0 : low.unit) === (high === null || high === void 0 ? void 0 : high.unit)) {
364
+ low === null || low === void 0 ? true : delete low.unit;
279
365
  }
280
- return `${formatQuantity(range.low)} - ${formatQuantity(range.high)}`;
366
+ return `${formatQuantity(low, precision)} - ${formatQuantity(high, precision)}`;
281
367
  }
282
368
  /**
283
369
  * Returns a human-readable string for a FHIR Quantity datatype, taking into account units and comparators
@@ -309,6 +395,85 @@
309
395
  }
310
396
  return result.join('').trim();
311
397
  }
398
+ /**
399
+ * Formats a CodeableConcept element as a string.
400
+ * @param codeableConcept A FHIR CodeableConcept element
401
+ * @returns The codeable concept as a string.
402
+ */
403
+ function formatCodeableConcept(codeableConcept) {
404
+ if (!codeableConcept) {
405
+ return '';
406
+ }
407
+ if (codeableConcept.text) {
408
+ return codeableConcept.text;
409
+ }
410
+ if (codeableConcept.coding) {
411
+ return codeableConcept.coding.map((c) => formatCoding(c)).join(', ');
412
+ }
413
+ return '';
414
+ }
415
+ /**
416
+ * Formats a Coding element as a string.
417
+ * @param coding A FHIR Coding element
418
+ * @returns The coding as a string.
419
+ */
420
+ function formatCoding(coding) {
421
+ return (coding === null || coding === void 0 ? void 0 : coding.display) || (coding === null || coding === void 0 ? void 0 : coding.code) || '';
422
+ }
423
+ /**
424
+ * Formats a FHIR Observation resource value as a string.
425
+ * @param obs A FHIR Observation resource.
426
+ * @returns A human-readable string representation of the Observation.
427
+ */
428
+ function formatObservationValue(obs) {
429
+ if (!obs) {
430
+ return '';
431
+ }
432
+ if ('component' in obs) {
433
+ return obs.component.map((c) => formatObservationValue(c)).join(' / ');
434
+ }
435
+ if (obs === null || obs === void 0 ? void 0 : obs.valueQuantity) {
436
+ return formatQuantity(obs.valueQuantity);
437
+ }
438
+ if (obs.valueCodeableConcept) {
439
+ return formatCodeableConcept(obs.valueCodeableConcept);
440
+ }
441
+ if (obs.valueString) {
442
+ return obs.valueString;
443
+ }
444
+ return '';
445
+ }
446
+ /**
447
+ * Returns the input number increased by the `n` units of the specified precision
448
+ * @param a The input number
449
+ * @param precision The precision in number of digits.
450
+ * @param n (default 1) The number of units to add
451
+ */
452
+ function preciseIncrement(a, precision, n = 1) {
453
+ return (toPreciseInteger$1(a, precision) + n) * Math.pow(10, -precision);
454
+ }
455
+ /**
456
+ * Returns the input number decreased by the `n` units of the specified precision
457
+ * @param a The input number
458
+ * @param precision The precision in number of digits.
459
+ * @param n (default 1) The number of units to subtract
460
+ */
461
+ function preciseDecrement(a, precision, n = 1) {
462
+ return (toPreciseInteger$1(a, precision) - n) * Math.pow(10, -precision);
463
+ }
464
+ /**
465
+ * Returns an integer representation of the number with the given precision.
466
+ * For example, if precision is 2, then 1.2345 will be returned as 123.
467
+ * @param a The number.
468
+ * @param precision Optional precision in number of digits.
469
+ * @returns The integer with the given precision.
470
+ */
471
+ function toPreciseInteger$1(a, precision) {
472
+ if (precision === undefined) {
473
+ return a;
474
+ }
475
+ return Math.round(a * Math.pow(10, precision));
476
+ }
312
477
 
313
478
  /**
314
479
  * Creates a reference resource.
@@ -6322,7 +6487,7 @@
6322
6487
  // PKCE auth based on:
6323
6488
  // https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
6324
6489
  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";
6490
+ const MEDPLUM_VERSION = "1.0.3-3389b2ef";
6326
6491
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
6327
6492
  const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
6328
6493
  const DEFAULT_CACHE_TIME = 60000; // 60 seconds
@@ -11544,11 +11709,14 @@
11544
11709
  exports.findObservationReferenceRange = findObservationReferenceRange;
11545
11710
  exports.forbidden = forbidden;
11546
11711
  exports.formatAddress = formatAddress;
11712
+ exports.formatCodeableConcept = formatCodeableConcept;
11713
+ exports.formatCoding = formatCoding;
11547
11714
  exports.formatDate = formatDate;
11548
11715
  exports.formatDateTime = formatDateTime;
11549
11716
  exports.formatFamilyName = formatFamilyName;
11550
11717
  exports.formatGivenName = formatGivenName;
11551
11718
  exports.formatHumanName = formatHumanName;
11719
+ exports.formatObservationValue = formatObservationValue;
11552
11720
  exports.formatPeriod = formatPeriod;
11553
11721
  exports.formatQuantity = formatQuantity;
11554
11722
  exports.formatRange = formatRange;