@medplum/core 2.0.24 → 2.0.25

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 (81) hide show
  1. package/dist/cjs/index.cjs +28 -14114
  2. package/dist/cjs/index.cjs.map +7 -1
  3. package/dist/esm/index.mjs +31 -29
  4. package/dist/esm/index.mjs.map +7 -1
  5. package/dist/types/utils.d.ts +14 -0
  6. package/package.json +2 -2
  7. package/dist/cjs/index.min.cjs +0 -1
  8. package/dist/esm/access.mjs +0 -142
  9. package/dist/esm/access.mjs.map +0 -1
  10. package/dist/esm/base-schema.json.mjs +0 -4408
  11. package/dist/esm/base-schema.json.mjs.map +0 -1
  12. package/dist/esm/base64.mjs +0 -33
  13. package/dist/esm/base64.mjs.map +0 -1
  14. package/dist/esm/bundle.mjs +0 -36
  15. package/dist/esm/bundle.mjs.map +0 -1
  16. package/dist/esm/cache.mjs +0 -64
  17. package/dist/esm/cache.mjs.map +0 -1
  18. package/dist/esm/client.mjs +0 -2168
  19. package/dist/esm/client.mjs.map +0 -1
  20. package/dist/esm/crypto.mjs +0 -22
  21. package/dist/esm/crypto.mjs.map +0 -1
  22. package/dist/esm/eventtarget.mjs +0 -36
  23. package/dist/esm/eventtarget.mjs.map +0 -1
  24. package/dist/esm/fhirlexer/parse.mjs +0 -122
  25. package/dist/esm/fhirlexer/parse.mjs.map +0 -1
  26. package/dist/esm/fhirlexer/tokenize.mjs +0 -231
  27. package/dist/esm/fhirlexer/tokenize.mjs.map +0 -1
  28. package/dist/esm/fhirmapper/parse.mjs +0 -329
  29. package/dist/esm/fhirmapper/parse.mjs.map +0 -1
  30. package/dist/esm/fhirmapper/tokenize.mjs +0 -13
  31. package/dist/esm/fhirmapper/tokenize.mjs.map +0 -1
  32. package/dist/esm/fhirpath/atoms.mjs +0 -347
  33. package/dist/esm/fhirpath/atoms.mjs.map +0 -1
  34. package/dist/esm/fhirpath/date.mjs +0 -24
  35. package/dist/esm/fhirpath/date.mjs.map +0 -1
  36. package/dist/esm/fhirpath/functions.mjs +0 -1626
  37. package/dist/esm/fhirpath/functions.mjs.map +0 -1
  38. package/dist/esm/fhirpath/parse.mjs +0 -145
  39. package/dist/esm/fhirpath/parse.mjs.map +0 -1
  40. package/dist/esm/fhirpath/tokenize.mjs +0 -10
  41. package/dist/esm/fhirpath/tokenize.mjs.map +0 -1
  42. package/dist/esm/fhirpath/utils.mjs +0 -377
  43. package/dist/esm/fhirpath/utils.mjs.map +0 -1
  44. package/dist/esm/filter/parse.mjs +0 -101
  45. package/dist/esm/filter/parse.mjs.map +0 -1
  46. package/dist/esm/filter/tokenize.mjs +0 -16
  47. package/dist/esm/filter/tokenize.mjs.map +0 -1
  48. package/dist/esm/filter/types.mjs +0 -34
  49. package/dist/esm/filter/types.mjs.map +0 -1
  50. package/dist/esm/format.mjs +0 -390
  51. package/dist/esm/format.mjs.map +0 -1
  52. package/dist/esm/hl7.mjs +0 -242
  53. package/dist/esm/hl7.mjs.map +0 -1
  54. package/dist/esm/index.min.mjs +0 -1
  55. package/dist/esm/jwt.mjs +0 -30
  56. package/dist/esm/jwt.mjs.map +0 -1
  57. package/dist/esm/node_modules/tslib/package.json +0 -1
  58. package/dist/esm/outcomes.mjs +0 -295
  59. package/dist/esm/outcomes.mjs.map +0 -1
  60. package/dist/esm/readablepromise.mjs +0 -82
  61. package/dist/esm/readablepromise.mjs.map +0 -1
  62. package/dist/esm/schema.mjs +0 -417
  63. package/dist/esm/schema.mjs.map +0 -1
  64. package/dist/esm/search/details.mjs +0 -162
  65. package/dist/esm/search/details.mjs.map +0 -1
  66. package/dist/esm/search/match.mjs +0 -166
  67. package/dist/esm/search/match.mjs.map +0 -1
  68. package/dist/esm/search/search.mjs +0 -378
  69. package/dist/esm/search/search.mjs.map +0 -1
  70. package/dist/esm/sftp.mjs +0 -24
  71. package/dist/esm/sftp.mjs.map +0 -1
  72. package/dist/esm/storage.mjs +0 -95
  73. package/dist/esm/storage.mjs.map +0 -1
  74. package/dist/esm/types.mjs +0 -370
  75. package/dist/esm/types.mjs.map +0 -1
  76. package/dist/esm/typeschema/types.mjs +0 -278
  77. package/dist/esm/typeschema/types.mjs.map +0 -1
  78. package/dist/esm/typeschema/validation.mjs +0 -262
  79. package/dist/esm/typeschema/validation.mjs.map +0 -1
  80. package/dist/esm/utils.mjs +0 -632
  81. package/dist/esm/utils.mjs.map +0 -1
@@ -1,390 +0,0 @@
1
- import { capitalize } from './utils.mjs';
2
-
3
- /**
4
- * Formats a FHIR Address as a string.
5
- * @param address The address to format.
6
- * @param options Optional address format options.
7
- * @returns The formatted address string.
8
- */
9
- function formatAddress(address, options) {
10
- const builder = [];
11
- if (address.line) {
12
- builder.push(...address.line);
13
- }
14
- if (address.city || address.state || address.postalCode) {
15
- const cityStateZip = [];
16
- if (address.city) {
17
- cityStateZip.push(address.city);
18
- }
19
- if (address.state) {
20
- cityStateZip.push(address.state);
21
- }
22
- if (address.postalCode) {
23
- cityStateZip.push(address.postalCode);
24
- }
25
- builder.push(cityStateZip.join(', '));
26
- }
27
- if (address.use && (options?.all || options?.use)) {
28
- builder.push('[' + address.use + ']');
29
- }
30
- return builder.join(options?.lineSeparator || ', ').trim();
31
- }
32
- /**
33
- * Formats a FHIR HumanName as a string.
34
- * @param name The name to format.
35
- * @param options Optional name format options.
36
- * @returns The formatted name string.
37
- */
38
- function formatHumanName(name, options) {
39
- const builder = [];
40
- if (name.prefix && options?.prefix !== false) {
41
- builder.push(...name.prefix);
42
- }
43
- if (name.given) {
44
- builder.push(...name.given);
45
- }
46
- if (name.family) {
47
- builder.push(name.family);
48
- }
49
- if (name.suffix && options?.suffix !== false) {
50
- builder.push(...name.suffix);
51
- }
52
- if (name.use && (options?.all || options?.use)) {
53
- builder.push('[' + name.use + ']');
54
- }
55
- return builder.join(' ').trim();
56
- }
57
- /**
58
- * Formats the given name portion of a FHIR HumanName element.
59
- * @param name The name to format.
60
- * @returns The formatted given name string.
61
- */
62
- function formatGivenName(name) {
63
- const builder = [];
64
- if (name.given) {
65
- builder.push(...name.given);
66
- }
67
- return builder.join(' ').trim();
68
- }
69
- /**
70
- * Formats the family name portion of a FHIR HumanName element.
71
- * @param name The name to format.
72
- * @returns The formatted family name string.
73
- */
74
- function formatFamilyName(name) {
75
- return name.family || '';
76
- }
77
- /**
78
- * Returns true if the given date object is a valid date.
79
- * Dates can be invalid if created by parsing an invalid string.
80
- * @param date A date object.
81
- * @returns Returns true if the date is a valid date.
82
- */
83
- function isValidDate(date) {
84
- return date instanceof Date && !isNaN(date.getTime());
85
- }
86
- /**
87
- * Formats a FHIR date string as a human readable string.
88
- * Handles missing values and invalid dates.
89
- * @param date The date to format.
90
- * @param locales Optional locales.
91
- * @param options Optional date format options.
92
- * @returns The formatted date string.
93
- */
94
- function formatDate(date, locales, options) {
95
- if (!date) {
96
- return '';
97
- }
98
- const d = new Date(date);
99
- if (!isValidDate(d)) {
100
- return '';
101
- }
102
- d.setUTCHours(0, 0, 0, 0);
103
- return d.toLocaleDateString(locales, { timeZone: 'UTC', ...options });
104
- }
105
- /**
106
- * Formats a FHIR time string as a human readable string.
107
- * Handles missing values and invalid dates.
108
- * @param time The date to format.
109
- * @param locales Optional locales.
110
- * @param options Optional time format options.
111
- * @returns The formatted time string.
112
- */
113
- function formatTime(time, locales, options) {
114
- if (!time) {
115
- return '';
116
- }
117
- const d = new Date('2000-01-01T' + time + 'Z');
118
- if (!isValidDate(d)) {
119
- return '';
120
- }
121
- return d.toLocaleTimeString(locales, options);
122
- }
123
- /**
124
- * Formats a FHIR dateTime string as a human readable string.
125
- * Handles missing values and invalid dates.
126
- * @param dateTime The dateTime to format.
127
- * @param locales Optional locales.
128
- * @param options Optional dateTime format options.
129
- * @returns The formatted dateTime string.
130
- */
131
- function formatDateTime(dateTime, locales, options) {
132
- if (!dateTime) {
133
- return '';
134
- }
135
- const d = new Date(dateTime);
136
- if (!isValidDate(d)) {
137
- return '';
138
- }
139
- return d.toLocaleString(locales, options);
140
- }
141
- /**
142
- * Formats a FHIR Period as a human readable string.
143
- * @param period The period to format.
144
- * @param locales Optional locales.
145
- * @param options Optional period format options.
146
- * @returns The formatted period string.
147
- */
148
- function formatPeriod(period, locales, options) {
149
- if (!period || (!period.start && !period.end)) {
150
- return '';
151
- }
152
- return formatDateTime(period.start, locales, options) + ' - ' + formatDateTime(period.end, locales, options);
153
- }
154
- const unitAdverbForm = {
155
- s: 'every second',
156
- min: 'every minute',
157
- h: 'hourly',
158
- d: 'daily',
159
- wk: 'weekly',
160
- mo: 'monthly',
161
- a: 'annually',
162
- };
163
- const singularUnits = {
164
- s: 'second',
165
- min: 'minute',
166
- h: 'hour',
167
- d: 'day',
168
- wk: 'week',
169
- mo: 'month',
170
- a: 'year',
171
- };
172
- const pluralUnits = {
173
- s: 'seconds',
174
- min: 'minutes',
175
- h: 'hours',
176
- d: 'days',
177
- wk: 'weeks',
178
- mo: 'months',
179
- a: 'years',
180
- };
181
- /**
182
- * Formats a FHIR Timing as a human readable string.
183
- * @param timing The timing to format.
184
- * @returns The formatted timing string.
185
- */
186
- function formatTiming(timing) {
187
- if (!timing) {
188
- return '';
189
- }
190
- const builder = [];
191
- if (timing.repeat?.periodUnit) {
192
- const frequency = timing.repeat.frequency || 1;
193
- const period = timing.repeat.period || 1;
194
- const periodUnit = timing.repeat.periodUnit;
195
- if (frequency === 1 && period === 1) {
196
- builder.push(unitAdverbForm[periodUnit]);
197
- }
198
- else {
199
- if (frequency === 1) {
200
- builder.push('once');
201
- }
202
- else {
203
- builder.push(frequency + ' times');
204
- }
205
- if (period === 1) {
206
- builder.push('per ' + singularUnits[periodUnit]);
207
- }
208
- else {
209
- builder.push('per ' + period + ' ' + pluralUnits[periodUnit]);
210
- }
211
- }
212
- if (timing.repeat.dayOfWeek) {
213
- builder.push('on ' + timing.repeat.dayOfWeek.map(capitalize).join(', '));
214
- }
215
- if (timing.repeat.timeOfDay) {
216
- builder.push('at ' + timing.repeat.timeOfDay.map((t) => formatTime(t)).join(', '));
217
- }
218
- }
219
- if (timing.event) {
220
- builder.push(timing.event.map((d) => formatDateTime(d)).join(', '));
221
- }
222
- return capitalize(builder.join(' ').trim());
223
- }
224
- /**
225
- * Returns a human-readable string for a FHIR Range datatype, taking into account one-sided ranges
226
- * @param range A FHIR Range element
227
- * @param precision Number of decimal places to display in the rendered quantity values
228
- * @param exclusive If true, one-sided ranges will be rendered with the '>' or '<' bounds rather than '>=' or '<='
229
- * @returns A human-readable string representation of the Range
230
- */
231
- function formatRange(range, precision, exclusive = false) {
232
- if (exclusive && precision === undefined) {
233
- throw new Error('Precision must be specified for exclusive ranges');
234
- }
235
- // Extract high and low range endpoints, explicitly ignoring any comparator
236
- // since Range uses SimpleQuantity variants (see http://www.hl7.org/fhir/datatypes.html#Range)
237
- const low = range?.low && { ...range.low, comparator: undefined };
238
- const high = range?.high && { ...range.high, comparator: undefined };
239
- if (low?.value === undefined && high?.value === undefined) {
240
- return '';
241
- }
242
- if (low?.value !== undefined && high?.value === undefined) {
243
- // Lower bound only
244
- if (exclusive && precision !== undefined) {
245
- low.value = preciseDecrement(low.value, precision);
246
- return `> ${formatQuantity(low, precision)}`;
247
- }
248
- return `>= ${formatQuantity(low, precision)}`;
249
- }
250
- else if (low?.value === undefined && high?.value !== undefined) {
251
- // Upper bound only
252
- if (exclusive && precision !== undefined) {
253
- high.value = preciseIncrement(high.value, precision);
254
- return `< ${formatQuantity(high, precision)}`;
255
- }
256
- return `<= ${formatQuantity(high, precision)}`;
257
- }
258
- else {
259
- // Double-sided range
260
- if (low?.unit === high?.unit) {
261
- delete low?.unit; // Format like "X - Y units" instead of "X units - Y units"
262
- }
263
- return `${formatQuantity(low, precision)} - ${formatQuantity(high, precision)}`;
264
- }
265
- }
266
- /**
267
- * Returns a human-readable string for a FHIR Quantity datatype, taking into account units and comparators
268
- * @param quantity A FHIR Quantity element
269
- * @param precision Number of decimal places to display in the rendered quantity values
270
- * @returns A human-readable string representation of the Quantity
271
- */
272
- function formatQuantity(quantity, precision) {
273
- if (!quantity) {
274
- return '';
275
- }
276
- const result = [];
277
- if (quantity.comparator) {
278
- result.push(quantity.comparator);
279
- result.push(' ');
280
- }
281
- if (quantity.value !== undefined) {
282
- if (precision !== undefined) {
283
- result.push(quantity.value.toFixed(precision));
284
- }
285
- else {
286
- result.push(quantity.value);
287
- }
288
- }
289
- if (quantity.unit) {
290
- if (quantity.unit !== '%' && result[result.length - 1] !== ' ') {
291
- result.push(' ');
292
- }
293
- result.push(quantity.unit);
294
- }
295
- return result.join('').trim();
296
- }
297
- function formatMoney(money) {
298
- if (money?.value === undefined) {
299
- return '';
300
- }
301
- return money.value.toLocaleString(undefined, {
302
- style: 'currency',
303
- currency: money.currency || 'USD',
304
- currencyDisplay: 'narrowSymbol',
305
- });
306
- }
307
- /**
308
- * Formats a CodeableConcept element as a string.
309
- * @param codeableConcept A FHIR CodeableConcept element
310
- * @returns The codeable concept as a string.
311
- */
312
- function formatCodeableConcept(codeableConcept) {
313
- if (!codeableConcept) {
314
- return '';
315
- }
316
- if (codeableConcept.text) {
317
- return codeableConcept.text;
318
- }
319
- if (codeableConcept.coding) {
320
- return codeableConcept.coding.map((c) => formatCoding(c)).join(', ');
321
- }
322
- return '';
323
- }
324
- /**
325
- * Formats a Coding element as a string.
326
- * @param coding A FHIR Coding element
327
- * @returns The coding as a string.
328
- */
329
- function formatCoding(coding) {
330
- return coding?.display || coding?.code || '';
331
- }
332
- /**
333
- * Formats a FHIR Observation resource value as a string.
334
- * @param obs A FHIR Observation resource.
335
- * @returns A human-readable string representation of the Observation.
336
- */
337
- function formatObservationValue(obs) {
338
- if (!obs) {
339
- return '';
340
- }
341
- if ('component' in obs) {
342
- return obs.component.map((c) => formatObservationValue(c)).join(' / ');
343
- }
344
- if (obs.valueQuantity) {
345
- return formatQuantity(obs.valueQuantity);
346
- }
347
- if (obs.valueCodeableConcept) {
348
- return formatCodeableConcept(obs.valueCodeableConcept);
349
- }
350
- if (obs.valueString) {
351
- return obs.valueString;
352
- }
353
- return '';
354
- }
355
- /**
356
- * Returns the input number increased by the `n` units of the specified precision
357
- * @param a The input number.
358
- * @param precision The precision in number of digits.
359
- * @param n (default 1) The number of units to add.
360
- * @returns The result of the increment.
361
- */
362
- function preciseIncrement(a, precision, n = 1) {
363
- return (toPreciseInteger(a, precision) + n) * Math.pow(10, -precision);
364
- }
365
- /**
366
- * Returns the input number decreased by the `n` units of the specified precision
367
- * @param a The input number.
368
- * @param precision The precision in number of digits.
369
- * @param n (default 1) The number of units to subtract.
370
- * @returns The result of the decrement.
371
- */
372
- function preciseDecrement(a, precision, n = 1) {
373
- return (toPreciseInteger(a, precision) - n) * Math.pow(10, -precision);
374
- }
375
- /**
376
- * Returns an integer representation of the number with the given precision.
377
- * For example, if precision is 2, then 1.2345 will be returned as 123.
378
- * @param a The number.
379
- * @param precision Optional precision in number of digits.
380
- * @returns The integer with the given precision.
381
- */
382
- function toPreciseInteger(a, precision) {
383
- if (precision === undefined) {
384
- return a;
385
- }
386
- return Math.round(a * Math.pow(10, precision));
387
- }
388
-
389
- export { formatAddress, formatCodeableConcept, formatCoding, formatDate, formatDateTime, formatFamilyName, formatGivenName, formatHumanName, formatMoney, formatObservationValue, formatPeriod, formatQuantity, formatRange, formatTime, formatTiming, isValidDate };
390
- //# sourceMappingURL=format.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format.mjs","sources":["../../src/format.ts"],"sourcesContent":["import {\n Address,\n CodeableConcept,\n Coding,\n HumanName,\n Money,\n Observation,\n ObservationComponent,\n Period,\n Quantity,\n Range,\n Timing,\n} from '@medplum/fhirtypes';\nimport { capitalize } from './utils';\n\nexport interface AddressFormatOptions {\n all?: boolean;\n use?: boolean;\n lineSeparator?: string;\n}\n\nexport interface HumanNameFormatOptions {\n all?: boolean;\n prefix?: boolean;\n suffix?: boolean;\n use?: boolean;\n}\n\n/**\n * Formats a FHIR Address as a string.\n * @param address The address to format.\n * @param options Optional address format options.\n * @returns The formatted address string.\n */\nexport function formatAddress(address: Address, options?: AddressFormatOptions): string {\n const builder = [];\n\n if (address.line) {\n builder.push(...address.line);\n }\n\n if (address.city || address.state || address.postalCode) {\n const cityStateZip = [];\n if (address.city) {\n cityStateZip.push(address.city);\n }\n if (address.state) {\n cityStateZip.push(address.state);\n }\n if (address.postalCode) {\n cityStateZip.push(address.postalCode);\n }\n builder.push(cityStateZip.join(', '));\n }\n\n if (address.use && (options?.all || options?.use)) {\n builder.push('[' + address.use + ']');\n }\n\n return builder.join(options?.lineSeparator || ', ').trim();\n}\n\n/**\n * Formats a FHIR HumanName as a string.\n * @param name The name to format.\n * @param options Optional name format options.\n * @returns The formatted name string.\n */\nexport function formatHumanName(name: HumanName, options?: HumanNameFormatOptions): string {\n const builder = [];\n\n if (name.prefix && options?.prefix !== false) {\n builder.push(...name.prefix);\n }\n\n if (name.given) {\n builder.push(...name.given);\n }\n\n if (name.family) {\n builder.push(name.family);\n }\n\n if (name.suffix && options?.suffix !== false) {\n builder.push(...name.suffix);\n }\n\n if (name.use && (options?.all || options?.use)) {\n builder.push('[' + name.use + ']');\n }\n\n return builder.join(' ').trim();\n}\n\n/**\n * Formats the given name portion of a FHIR HumanName element.\n * @param name The name to format.\n * @returns The formatted given name string.\n */\nexport function formatGivenName(name: HumanName): string {\n const builder: string[] = [];\n if (name.given) {\n builder.push(...name.given);\n }\n return builder.join(' ').trim();\n}\n\n/**\n * Formats the family name portion of a FHIR HumanName element.\n * @param name The name to format.\n * @returns The formatted family name string.\n */\nexport function formatFamilyName(name: HumanName): string {\n return name.family || '';\n}\n\n/**\n * Returns true if the given date object is a valid date.\n * Dates can be invalid if created by parsing an invalid string.\n * @param date A date object.\n * @returns Returns true if the date is a valid date.\n */\nexport function isValidDate(date: Date): boolean {\n return date instanceof Date && !isNaN(date.getTime());\n}\n\n/**\n * Formats a FHIR date string as a human readable string.\n * Handles missing values and invalid dates.\n * @param date The date to format.\n * @param locales Optional locales.\n * @param options Optional date format options.\n * @returns The formatted date string.\n */\nexport function formatDate(\n date: string | undefined,\n locales?: Intl.LocalesArgument,\n options?: Intl.DateTimeFormatOptions | undefined\n): string {\n if (!date) {\n return '';\n }\n const d = new Date(date);\n if (!isValidDate(d)) {\n return '';\n }\n d.setUTCHours(0, 0, 0, 0);\n return d.toLocaleDateString(locales, { timeZone: 'UTC', ...options });\n}\n\n/**\n * Formats a FHIR time string as a human readable string.\n * Handles missing values and invalid dates.\n * @param time The date to format.\n * @param locales Optional locales.\n * @param options Optional time format options.\n * @returns The formatted time string.\n */\nexport function formatTime(\n time: string | undefined,\n locales?: Intl.LocalesArgument,\n options?: Intl.DateTimeFormatOptions | undefined\n): string {\n if (!time) {\n return '';\n }\n const d = new Date('2000-01-01T' + time + 'Z');\n if (!isValidDate(d)) {\n return '';\n }\n return d.toLocaleTimeString(locales, options);\n}\n\n/**\n * Formats a FHIR dateTime string as a human readable string.\n * Handles missing values and invalid dates.\n * @param dateTime The dateTime to format.\n * @param locales Optional locales.\n * @param options Optional dateTime format options.\n * @returns The formatted dateTime string.\n */\nexport function formatDateTime(\n dateTime: string | undefined,\n locales?: Intl.LocalesArgument,\n options?: Intl.DateTimeFormatOptions | undefined\n): string {\n if (!dateTime) {\n return '';\n }\n const d = new Date(dateTime);\n if (!isValidDate(d)) {\n return '';\n }\n return d.toLocaleString(locales, options);\n}\n\n/**\n * Formats a FHIR Period as a human readable string.\n * @param period The period to format.\n * @param locales Optional locales.\n * @param options Optional period format options.\n * @returns The formatted period string.\n */\nexport function formatPeriod(\n period: Period | undefined,\n locales?: Intl.LocalesArgument,\n options?: Intl.DateTimeFormatOptions | undefined\n): string {\n if (!period || (!period.start && !period.end)) {\n return '';\n }\n return formatDateTime(period.start, locales, options) + ' - ' + formatDateTime(period.end, locales, options);\n}\n\nconst unitAdverbForm: Record<string, string> = {\n s: 'every second',\n min: 'every minute',\n h: 'hourly',\n d: 'daily',\n wk: 'weekly',\n mo: 'monthly',\n a: 'annually',\n};\n\nconst singularUnits: Record<string, string> = {\n s: 'second',\n min: 'minute',\n h: 'hour',\n d: 'day',\n wk: 'week',\n mo: 'month',\n a: 'year',\n};\n\nconst pluralUnits: Record<string, string> = {\n s: 'seconds',\n min: 'minutes',\n h: 'hours',\n d: 'days',\n wk: 'weeks',\n mo: 'months',\n a: 'years',\n};\n\n/**\n * Formats a FHIR Timing as a human readable string.\n * @param timing The timing to format.\n * @returns The formatted timing string.\n */\nexport function formatTiming(timing: Timing | undefined): string {\n if (!timing) {\n return '';\n }\n\n const builder: string[] = [];\n\n if (timing.repeat?.periodUnit) {\n const frequency = timing.repeat.frequency || 1;\n const period = timing.repeat.period || 1;\n const periodUnit = timing.repeat.periodUnit;\n\n if (frequency === 1 && period === 1) {\n builder.push(unitAdverbForm[periodUnit]);\n } else {\n if (frequency === 1) {\n builder.push('once');\n } else {\n builder.push(frequency + ' times');\n }\n\n if (period === 1) {\n builder.push('per ' + singularUnits[periodUnit]);\n } else {\n builder.push('per ' + period + ' ' + pluralUnits[periodUnit]);\n }\n }\n\n if (timing.repeat.dayOfWeek) {\n builder.push('on ' + timing.repeat.dayOfWeek.map(capitalize).join(', '));\n }\n\n if (timing.repeat.timeOfDay) {\n builder.push('at ' + timing.repeat.timeOfDay.map((t) => formatTime(t)).join(', '));\n }\n }\n\n if (timing.event) {\n builder.push(timing.event.map((d) => formatDateTime(d)).join(', '));\n }\n\n return capitalize(builder.join(' ').trim());\n}\n\n/**\n * Returns a human-readable string for a FHIR Range datatype, taking into account one-sided ranges\n * @param range A FHIR Range element\n * @param precision Number of decimal places to display in the rendered quantity values\n * @param exclusive If true, one-sided ranges will be rendered with the '>' or '<' bounds rather than '>=' or '<='\n * @returns A human-readable string representation of the Range\n */\nexport function formatRange(range: Range | undefined, precision?: number, exclusive = false): string {\n if (exclusive && precision === undefined) {\n throw new Error('Precision must be specified for exclusive ranges');\n }\n\n // Extract high and low range endpoints, explicitly ignoring any comparator\n // since Range uses SimpleQuantity variants (see http://www.hl7.org/fhir/datatypes.html#Range)\n const low = range?.low && { ...range.low, comparator: undefined };\n const high = range?.high && { ...range.high, comparator: undefined };\n if (low?.value === undefined && high?.value === undefined) {\n return '';\n }\n\n if (low?.value !== undefined && high?.value === undefined) {\n // Lower bound only\n if (exclusive && precision !== undefined) {\n low.value = preciseDecrement(low.value, precision);\n return `> ${formatQuantity(low, precision)}`;\n }\n return `>= ${formatQuantity(low, precision)}`;\n } else if (low?.value === undefined && high?.value !== undefined) {\n // Upper bound only\n if (exclusive && precision !== undefined) {\n high.value = preciseIncrement(high.value, precision);\n return `< ${formatQuantity(high, precision)}`;\n }\n return `<= ${formatQuantity(high, precision)}`;\n } else {\n // Double-sided range\n if (low?.unit === high?.unit) {\n delete low?.unit; // Format like \"X - Y units\" instead of \"X units - Y units\"\n }\n return `${formatQuantity(low, precision)} - ${formatQuantity(high, precision)}`;\n }\n}\n\n/**\n * Returns a human-readable string for a FHIR Quantity datatype, taking into account units and comparators\n * @param quantity A FHIR Quantity element\n * @param precision Number of decimal places to display in the rendered quantity values\n * @returns A human-readable string representation of the Quantity\n */\nexport function formatQuantity(quantity: Quantity | undefined, precision?: number): string {\n if (!quantity) {\n return '';\n }\n\n const result = [];\n\n if (quantity.comparator) {\n result.push(quantity.comparator);\n result.push(' ');\n }\n\n if (quantity.value !== undefined) {\n if (precision !== undefined) {\n result.push(quantity.value.toFixed(precision));\n } else {\n result.push(quantity.value);\n }\n }\n\n if (quantity.unit) {\n if (quantity.unit !== '%' && result[result.length - 1] !== ' ') {\n result.push(' ');\n }\n result.push(quantity.unit);\n }\n\n return result.join('').trim();\n}\n\nexport function formatMoney(money: Money | undefined): string {\n if (money?.value === undefined) {\n return '';\n }\n\n return money.value.toLocaleString(undefined, {\n style: 'currency',\n currency: money.currency || 'USD',\n currencyDisplay: 'narrowSymbol',\n });\n}\n\n/**\n * Formats a CodeableConcept element as a string.\n * @param codeableConcept A FHIR CodeableConcept element\n * @returns The codeable concept as a string.\n */\nexport function formatCodeableConcept(codeableConcept: CodeableConcept | undefined): string {\n if (!codeableConcept) {\n return '';\n }\n if (codeableConcept.text) {\n return codeableConcept.text;\n }\n if (codeableConcept.coding) {\n return codeableConcept.coding.map((c) => formatCoding(c)).join(', ');\n }\n return '';\n}\n\n/**\n * Formats a Coding element as a string.\n * @param coding A FHIR Coding element\n * @returns The coding as a string.\n */\nexport function formatCoding(coding: Coding | undefined): string {\n return coding?.display || coding?.code || '';\n}\n\n/**\n * Formats a FHIR Observation resource value as a string.\n * @param obs A FHIR Observation resource.\n * @returns A human-readable string representation of the Observation.\n */\nexport function formatObservationValue(obs: Observation | ObservationComponent | undefined): string {\n if (!obs) {\n return '';\n }\n\n if ('component' in obs) {\n return (obs.component as ObservationComponent[]).map((c) => formatObservationValue(c)).join(' / ');\n }\n\n if (obs.valueQuantity) {\n return formatQuantity(obs.valueQuantity);\n }\n\n if (obs.valueCodeableConcept) {\n return formatCodeableConcept(obs.valueCodeableConcept);\n }\n\n if (obs.valueString) {\n return obs.valueString;\n }\n\n return '';\n}\n\n/**\n * Returns the input number increased by the `n` units of the specified precision\n * @param a The input number.\n * @param precision The precision in number of digits.\n * @param n (default 1) The number of units to add.\n * @returns The result of the increment.\n */\nfunction preciseIncrement(a: number, precision: number, n = 1): number {\n return (toPreciseInteger(a, precision) + n) * Math.pow(10, -precision);\n}\n\n/**\n * Returns the input number decreased by the `n` units of the specified precision\n * @param a The input number.\n * @param precision The precision in number of digits.\n * @param n (default 1) The number of units to subtract.\n * @returns The result of the decrement.\n */\nfunction preciseDecrement(a: number, precision: number, n = 1): number {\n return (toPreciseInteger(a, precision) - n) * Math.pow(10, -precision);\n}\n\n/**\n * Returns an integer representation of the number with the given precision.\n * For example, if precision is 2, then 1.2345 will be returned as 123.\n * @param a The number.\n * @param precision Optional precision in number of digits.\n * @returns The integer with the given precision.\n */\nfunction toPreciseInteger(a: number, precision?: number): number {\n if (precision === undefined) {\n return a;\n }\n return Math.round(a * Math.pow(10, precision));\n}\n"],"names":[],"mappings":";;AA4BA;;;;;AAKG;AACa,SAAA,aAAa,CAAC,OAAgB,EAAE,OA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BAAgB,CAAC,CAAS,EAAE,SAAiB,EAAE,CAAC,GAAG,CAAC,EAAA;IAC3D,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;AACzE,CAAC;AAED;;;;;;AAMG;AACH,SAAS,gBAAgB,CAAC,CAAS,EAAE,SAAiB,EAAE,CAAC,GAAG,CAAC,EAAA;IAC3D,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;AACzE,CAAC;AAED;;;;;;AAMG;AACH,SAAS,gBAAgB,CAAC,CAAS,EAAE,SAAkB,EAAA;IACrD,IAAI,SAAS,KAAK,SAAS,EAAE;AAC3B,QAAA,OAAO,CAAC,CAAC;AACV,KAAA;AACD,IAAA,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;AACjD;;;;"}
package/dist/esm/hl7.mjs DELETED
@@ -1,242 +0,0 @@
1
- import { isStringArray } from './utils.mjs';
2
-
3
- /**
4
- * The Hl7Context class represents the parsing context for an HL7 message.
5
- *
6
- * MSH-1:
7
- * https://hl7-definition.caristix.com/v2/HL7v2.6/Fields/MSH.1
8
- *
9
- * MSH-2:
10
- * https://hl7-definition.caristix.com/v2/HL7v2.6/Fields/MSH.2
11
- *
12
- * See this tutorial on MSH, and why it's a bad idea to use anything other than the default values:
13
- * https://www.hl7soup.com/HL7TutorialMSH.html
14
- */
15
- class Hl7Context {
16
- constructor(segmentSeparator = '\r', fieldSeparator = '|', componentSeparator = '^', repetitionSeparator = '~', escapeCharacter = '\\', subcomponentSeparator = '&') {
17
- this.segmentSeparator = segmentSeparator;
18
- this.fieldSeparator = fieldSeparator;
19
- this.componentSeparator = componentSeparator;
20
- this.repetitionSeparator = repetitionSeparator;
21
- this.escapeCharacter = escapeCharacter;
22
- this.subcomponentSeparator = subcomponentSeparator;
23
- }
24
- /**
25
- * Returns the MSH-2 field value based on the configured separators.
26
- * @returns The HL7 MSH-2 field value.
27
- */
28
- getMsh2() {
29
- return (this.fieldSeparator +
30
- this.componentSeparator +
31
- this.repetitionSeparator +
32
- this.escapeCharacter +
33
- this.subcomponentSeparator);
34
- }
35
- }
36
- /**
37
- * The Hl7Message class represents one HL7 message.
38
- * A message is a collection of segments.
39
- */
40
- class Hl7Message {
41
- /**
42
- * Creates a new HL7 message.
43
- * @param segments The HL7 segments.
44
- * @param context Optional HL7 parsing context.
45
- */
46
- constructor(segments, context = new Hl7Context()) {
47
- this.context = context;
48
- this.segments = segments;
49
- }
50
- /**
51
- * Returns an HL7 segment by index or by name.
52
- * @param index The HL7 segment index or name.
53
- * @returns The HL7 segment if found; otherwise, undefined.
54
- */
55
- get(index) {
56
- if (typeof index === 'number') {
57
- return this.segments[index];
58
- }
59
- return this.segments.find((s) => s.name === index);
60
- }
61
- /**
62
- * Returns all HL7 segments of a given name.
63
- * @param name The HL7 segment name.
64
- * @returns An array of HL7 segments with the specified name.
65
- */
66
- getAll(name) {
67
- return this.segments.filter((s) => s.name === name);
68
- }
69
- /**
70
- * Returns the HL7 message as a string.
71
- * @returns The HL7 message as a string.
72
- */
73
- toString() {
74
- return this.segments.map((s) => s.toString()).join(this.context.segmentSeparator);
75
- }
76
- /**
77
- * Returns an HL7 "ACK" (acknowledgement) message for this message.
78
- * @returns The HL7 "ACK" message.
79
- */
80
- buildAck() {
81
- const now = new Date();
82
- const msh = this.get('MSH');
83
- const sendingApp = msh?.get(2)?.toString() || '';
84
- const sendingFacility = msh?.get(3)?.toString() || '';
85
- const receivingApp = msh?.get(4)?.toString() || '';
86
- const receivingFacility = msh?.get(5)?.toString() || '';
87
- const controlId = msh?.get(9)?.toString() || '';
88
- const versionId = msh?.get(12)?.toString() || '2.5.1';
89
- return new Hl7Message([
90
- new Hl7Segment([
91
- 'MSH',
92
- this.context.getMsh2(),
93
- receivingApp,
94
- receivingFacility,
95
- sendingApp,
96
- sendingFacility,
97
- now.toISOString(),
98
- '',
99
- 'ACK',
100
- now.getTime().toString(),
101
- 'P',
102
- versionId,
103
- ], this.context),
104
- new Hl7Segment(['MSA', 'AA', controlId, 'OK'], this.context),
105
- ]);
106
- }
107
- /**
108
- * Parses an HL7 message string into an Hl7Message object.
109
- * @param text The HL7 message text.
110
- * @returns The parsed HL7 message.
111
- */
112
- static parse(text) {
113
- if (!text.startsWith('MSH')) {
114
- const err = new Error('Invalid HL7 message');
115
- err.type = 'entity.parse.failed';
116
- throw err;
117
- }
118
- const context = new Hl7Context('\r', text.charAt(3), // Field separator, recommended "|"
119
- text.charAt(4), // Component separator, recommended "^"
120
- text.charAt(5), // Repetition separator, recommended "~"
121
- text.charAt(6), // Escape character, recommended "\"
122
- text.charAt(7) // Subcomponent separator, recommended "&"
123
- );
124
- return new Hl7Message(text.split(/[\r\n]+/).map((line) => Hl7Segment.parse(line, context)), context);
125
- }
126
- }
127
- /**
128
- * The Hl7Segment class represents one HL7 segment.
129
- * A segment is a collection of fields.
130
- * The name field is the first field.
131
- */
132
- class Hl7Segment {
133
- /**
134
- * Creates a new HL7 segment.
135
- * @param fields The HL7 fields.
136
- * @param context Optional HL7 parsing context.
137
- */
138
- constructor(fields, context = new Hl7Context()) {
139
- this.context = context;
140
- if (isStringArray(fields)) {
141
- this.fields = fields.map((f) => Hl7Field.parse(f));
142
- }
143
- else {
144
- this.fields = fields;
145
- }
146
- this.name = this.fields[0].components[0][0];
147
- }
148
- /**
149
- * Returns an HL7 field by index.
150
- * @param index The HL7 field index.
151
- * @returns The HL7 field.
152
- */
153
- get(index) {
154
- return this.fields[index];
155
- }
156
- /**
157
- * Returns the HL7 segment as a string.
158
- * @returns The HL7 segment as a string.
159
- */
160
- toString() {
161
- return this.fields.map((f) => f.toString()).join(this.context.fieldSeparator);
162
- }
163
- /**
164
- * Parses an HL7 segment string into an Hl7Segment object.
165
- * @param text The HL7 segment text.
166
- * @param context Optional HL7 parsing context.
167
- * @returns The parsed HL7 segment.
168
- */
169
- static parse(text, context = new Hl7Context()) {
170
- return new Hl7Segment(text.split(context.fieldSeparator).map((f) => Hl7Field.parse(f, context)), context);
171
- }
172
- }
173
- /**
174
- * The Hl7Field class represents one HL7 field.
175
- * A field is a collection of components.
176
- */
177
- class Hl7Field {
178
- /**
179
- * Creates a new HL7 field.
180
- * @param components The HL7 components.
181
- * @param context Optional HL7 parsing context.
182
- */
183
- constructor(components, context = new Hl7Context()) {
184
- this.context = context;
185
- this.components = components;
186
- }
187
- /**
188
- * Returns an HL7 component by index.
189
- * @param component The component index.
190
- * @param subcomponent Optional subcomponent index.
191
- * @param repetition Optional repetition index.
192
- * @returns The string value of the specified component.
193
- */
194
- get(component, subcomponent, repetition = 0) {
195
- let value = this.components[repetition][component] || '';
196
- if (subcomponent !== undefined) {
197
- value = value.split(this.context.subcomponentSeparator)[subcomponent] || '';
198
- }
199
- return value;
200
- }
201
- /**
202
- * Returns the HL7 field as a string.
203
- * @returns The HL7 field as a string.
204
- */
205
- toString() {
206
- return this.components.map((r) => r.join(this.context.componentSeparator)).join(this.context.repetitionSeparator);
207
- }
208
- /**
209
- * Parses an HL7 field string into an Hl7Field object.
210
- * @param text The HL7 field text.
211
- * @param context Optional HL7 parsing context.
212
- * @returns The parsed HL7 field.
213
- */
214
- static parse(text, context = new Hl7Context()) {
215
- return new Hl7Field(text.split(context.repetitionSeparator).map((r) => r.split(context.componentSeparator)), context);
216
- }
217
- }
218
- /**
219
- * Returns a formatted string representing the date in ISO-8601 format.
220
- * @param hl7Date Date string.
221
- * @param options Optional configuration Object
222
- * @returns The date in ISO-8601 format.
223
- */
224
- function parseHl7Date(hl7Date, options) {
225
- if (!hl7Date) {
226
- return undefined;
227
- }
228
- options = { ...{ seconds: true, tzOffset: 'Z' }, ...options };
229
- const year = Number.parseInt(hl7Date.substring(0, 4), 10);
230
- const month = Number.parseInt(hl7Date.substring(4, 6), 10);
231
- const date = Number.parseInt(hl7Date.substring(6, 8), 10);
232
- const hours = Number.parseInt(hl7Date.substring(8, 10), 10);
233
- const minutes = Number.parseInt(hl7Date.substring(10, 12), 10);
234
- const seconds = options.seconds ? Number.parseInt(hl7Date.substring(12, 14), 10) : 0;
235
- return `${pad2(year)}-${pad2(month)}-${pad2(date)}T${pad2(hours)}:${pad2(minutes)}:${pad2(seconds)}.000${options.tzOffset}`;
236
- }
237
- function pad2(n) {
238
- return n.toString().padStart(2, '0');
239
- }
240
-
241
- export { Hl7Context, Hl7Field, Hl7Message, Hl7Segment, parseHl7Date };
242
- //# sourceMappingURL=hl7.mjs.map