fhir-dosage-utils 1.0.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/main.js ADDED
@@ -0,0 +1,1030 @@
1
+ var $8zHUo$i18next = require("i18next");
2
+ var $8zHUo$i18nextchainedbackend = require("i18next-chained-backend");
3
+ var $8zHUo$i18nextresourcestobackend = require("i18next-resources-to-backend");
4
+
5
+
6
+ function $parcel$defineInteropFlag(a) {
7
+ Object.defineProperty(a, '__esModule', {value: true, configurable: true});
8
+ }
9
+
10
+ function $parcel$export(e, n, v, s) {
11
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
12
+ }
13
+
14
+ function $parcel$interopDefault(a) {
15
+ return a && a.__esModule ? a.default : a;
16
+ }
17
+
18
+ $parcel$defineInteropFlag(module.exports);
19
+
20
+ $parcel$export(module.exports, "default", () => $882b6d93070905b3$export$2e2bcd8739ae039);
21
+
22
+
23
+
24
+ function $1c57f108974f2805$export$b1a6aed91fad1636({ quantity: quantity }) {
25
+ if (quantity.code !== undefined) return quantity.code;
26
+ if (quantity.unit !== undefined) return quantity.unit;
27
+ return "";
28
+ }
29
+
30
+
31
+ function $a6c648898dc8c3b6$export$f478f96b98da13a4({ code: code }) {
32
+ // If no code, skip it
33
+ if (code === undefined) return undefined;
34
+ // Take text first
35
+ if (code.text !== undefined) return code.text;
36
+ // If empty, skip it
37
+ if (code.coding === undefined || code.coding.length === 0) return undefined;
38
+ // Take first coding; display first then code
39
+ let firstCode = code.coding[0];
40
+ return firstCode.display || firstCode.code;
41
+ }
42
+
43
+
44
+ function $34ebae8ac5b52fcd$export$30c337e25ab8e95b({ extensions: extensions }) {
45
+ // If no extensions, skip it
46
+ if (extensions === undefined || extensions.length === 0) return undefined;
47
+ // KIS implementation : print it as provided, without doing anything
48
+ // Extensions have so many cases btw, that having a basic function does the trick
49
+ return extensions.map((extension)=>JSON.stringify(extension)).join(" ");
50
+ }
51
+
52
+
53
+ // translators
54
+ // To avoid circular dependancies issue, let's have a single place for exports and imports
55
+ // types
56
+ function $5ab57a471c359130$export$7de3722258b87db9({ config: config, dos: dos, i18next: i18next }) {
57
+ // If empty, return undefined
58
+ if (dos.doseAndRate === undefined) return undefined;
59
+ // Find the first entry that match criteria
60
+ let doseQuantity = dos.doseAndRate.find((s)=>s.doseQuantity !== undefined);
61
+ // If not found, skip
62
+ if (doseQuantity === undefined) return undefined;
63
+ let quantity = doseQuantity.doseQuantity.value || 1;
64
+ let unit = config.fromFHIRQuantityUnitToString({
65
+ language: config.language,
66
+ quantity: doseQuantity.doseQuantity
67
+ });
68
+ return i18next.t("fields.doseQuantity", {
69
+ quantity: quantity,
70
+ unit: unit
71
+ });
72
+ }
73
+
74
+
75
+ // types
76
+ function $9a073aa5b09aa778$export$4cd16590995531a9({ dos: dos, config: config, i18next: i18next }) {
77
+ // If empty, return undefined
78
+ if (dos.doseAndRate === undefined) return undefined;
79
+ // Find the first entry that match criteria
80
+ let doseRange = dos.doseAndRate.find((s)=>s.doseRange !== undefined);
81
+ // If not found, skip
82
+ if (doseRange === undefined) return undefined;
83
+ let low = doseRange.doseRange.low?.value;
84
+ let high = doseRange.doseRange.high?.value;
85
+ let quantityUnit = doseRange.doseRange.high !== undefined ? doseRange.doseRange.high : doseRange.doseRange.low;
86
+ // quantity unit
87
+ let unit = config.fromFHIRQuantityUnitToString({
88
+ language: config.language,
89
+ quantity: quantityUnit
90
+ });
91
+ // Three cases
92
+ // 1. Both low & high are present
93
+ if (high !== undefined && low !== undefined) return i18next.t("fields.doseRange.lowAndHigh", {
94
+ low: low,
95
+ high: high,
96
+ unit: unit
97
+ });
98
+ // 2. Only high is present
99
+ if (high !== undefined) return i18next.t("fields.doseRange.onlyHigh", {
100
+ high: high,
101
+ unit: unit
102
+ });
103
+ // 3. Only low is present
104
+ // Warning, this case is kind dangerous and clinically unsafe so minimal effort on this ...
105
+ return i18next.t("fields.doseRange.onlyLow", {
106
+ low: low,
107
+ unit: unit
108
+ });
109
+ }
110
+
111
+
112
+ // types
113
+ function $052c79abb28cba29$export$4e24ef8c7997cc56({ dos: dos, config: config, i18next: i18next }) {
114
+ // If empty, return undefined
115
+ if (dos.doseAndRate === undefined) return undefined;
116
+ // Find the first entry that match criteria
117
+ let rateQuantity = dos.doseAndRate.find((s)=>s.rateQuantity !== undefined);
118
+ // If not found, skip
119
+ if (rateQuantity === undefined) return undefined;
120
+ // information from rate
121
+ let value = rateQuantity.rateQuantity.value || 1;
122
+ // quantity unit
123
+ let unit = config.fromFHIRQuantityUnitToString({
124
+ language: config.language,
125
+ quantity: rateQuantity.rateQuantity
126
+ });
127
+ return i18next.t("fields.rateQuantity", {
128
+ quantity: value,
129
+ unit: unit
130
+ });
131
+ }
132
+
133
+
134
+ // types
135
+ function $703b645b55481398$export$d3dd7d3522271dba({ dos: dos, config: config, i18next: i18next }) {
136
+ // If empty, return undefined
137
+ if (dos.doseAndRate === undefined) return undefined;
138
+ // Find the first entry that match criteria
139
+ let rateRange = dos.doseAndRate.find((s)=>s.rateRange !== undefined);
140
+ // If not found, skip
141
+ if (rateRange === undefined) return undefined;
142
+ // low / high
143
+ let low = rateRange.rateRange.low;
144
+ let high = rateRange.rateRange.high;
145
+ let quantityLow = low?.value;
146
+ let quantityHigh = high?.value;
147
+ // quantity unit
148
+ let unit = config.fromFHIRQuantityUnitToString({
149
+ language: config.language,
150
+ quantity: high || low
151
+ });
152
+ // Three cases
153
+ // 1. Both low & high are present
154
+ if (quantityHigh !== undefined && quantityLow !== undefined) return i18next.t("fields.rateRange.lowAndHigh", {
155
+ low: quantityLow,
156
+ high: quantityHigh,
157
+ unit: unit
158
+ });
159
+ // 2. Only high is present
160
+ if (quantityHigh !== undefined) return i18next.t("fields.rateRange.onlyHigh", {
161
+ high: quantityHigh,
162
+ unit: unit
163
+ });
164
+ // 3. Only low is present
165
+ // Warning, this case is kind dangerous and clinically unsafe so minimal effort on this ...
166
+ return i18next.t("fields.rateRange.onlyLow", {
167
+ low: quantityLow,
168
+ unit: unit
169
+ });
170
+ }
171
+
172
+
173
+ // types
174
+ function $301791f33da707fa$export$b71cfd2510242de2({ dos: dos, config: config, i18next: i18next }) {
175
+ // If empty, return undefined
176
+ if (dos.doseAndRate === undefined) return undefined;
177
+ // Find the first entry that match criteria
178
+ let rateRatio = dos.doseAndRate.find((s)=>s.rateRatio !== undefined);
179
+ // If not found, skip
180
+ if (rateRatio === undefined) return undefined;
181
+ // num / dem
182
+ let numerator = rateRatio.rateRatio.numerator;
183
+ let denominator = rateRatio.rateRatio.denominator;
184
+ let quantityNum = numerator?.value || 1;
185
+ let quantityDenom = denominator?.value || 1;
186
+ // units as text
187
+ let numeratorUnit = numerator !== undefined ? config.fromFHIRQuantityUnitToString({
188
+ language: config.language,
189
+ quantity: numerator
190
+ }) : "";
191
+ let denominatorUnit = denominator !== undefined ? config.fromFHIRQuantityUnitToString({
192
+ language: config.language,
193
+ quantity: denominator
194
+ }) : "";
195
+ return i18next.t("fields.rateRatio.rateRatio", {
196
+ count: quantityDenom,
197
+ quantityNumerator: quantityNum,
198
+ numeratorUnit: numeratorUnit,
199
+ denominatorUnit: denominatorUnit
200
+ });
201
+ }
202
+
203
+
204
+ function $1270a8f06113f53a$export$675ae45fa2875f4a({ dos: dos, i18next: i18next }) {
205
+ // If empty, return undefined
206
+ if (dos.timing === undefined || dos.timing.repeat === undefined) return undefined;
207
+ // Pickup the repeat interesting attributes
208
+ let repeat = dos.timing.repeat;
209
+ let duration = repeat.duration;
210
+ let max = repeat.durationMax;
211
+ let unit = repeat.durationUnit;
212
+ // Do nothing if no unit, I am not a wizard
213
+ if (unit === undefined) return undefined;
214
+ else return [
215
+ // duration
216
+ duration !== undefined && i18next.t("fields.duration", {
217
+ durationText: i18next.t(`unitsOfTime:withCount.${unit}`, {
218
+ count: duration
219
+ })
220
+ }),
221
+ // durationMax
222
+ max !== undefined && i18next.t("fields.durationMax", {
223
+ durationMaxText: i18next.t(`unitsOfTime:withCount.${unit}`, {
224
+ count: max
225
+ })
226
+ })
227
+ ].filter((s)=>s !== false).join(" ");
228
+ }
229
+
230
+
231
+ function $bc43734b944260d2$export$d663412e0c469ce2({ dos: dos, i18next: i18next }) {
232
+ // If empty, return undefined
233
+ if (dos.timing === undefined || dos.timing.repeat === undefined) return undefined;
234
+ // Pickup the repeat interesting attributes
235
+ let repeat = dos.timing.repeat;
236
+ let frequency = repeat.frequency;
237
+ let max = repeat.frequencyMax;
238
+ // Do nothing if no frequency / frequencyMax, I am not a wizard
239
+ if (frequency === undefined && max === undefined) return undefined;
240
+ else {
241
+ // Three cases
242
+ // 1. Frequency and frequencyMax are present
243
+ if (frequency !== undefined && max !== undefined) return i18next.t("fields.frequency.withfrequencyMax", {
244
+ count: max,
245
+ frequency: frequency
246
+ });
247
+ // 2. Only frequencyMax is present
248
+ if (max !== undefined) return i18next.t("fields.frequencyMax.frequencyMax", {
249
+ count: max
250
+ });
251
+ // 3. Only frequency is present
252
+ return i18next.t("fields.frequency.onlyFrequency", {
253
+ count: frequency
254
+ });
255
+ }
256
+ }
257
+
258
+
259
+ function $b9825dd9e0a2e687$export$aa31b783699f637({ dos: dos, i18next: i18next }) {
260
+ // If empty, return undefined
261
+ if (dos.timing === undefined || dos.timing.repeat === undefined) return undefined;
262
+ // Pickup the repeat interesting attributes
263
+ let repeat = dos.timing.repeat;
264
+ let period = repeat.period;
265
+ let max = repeat.periodMax;
266
+ let unit = repeat.periodUnit;
267
+ // Do nothing if no unit, I am not a wizard
268
+ if (unit === undefined) return undefined;
269
+ else {
270
+ // Three cases
271
+ // 1. period and periodMax are present
272
+ if (period !== undefined && max !== undefined) return i18next.t("fields.periodMax.withPeriod", {
273
+ period: period,
274
+ count: max,
275
+ unit: i18next.t(`unitsOfTime:withoutCount.${unit}`, {
276
+ count: max
277
+ })
278
+ });
279
+ // 2. Only periodMax is present
280
+ if (max !== undefined) return i18next.t("fields.periodMax.onlyPeriodMax", {
281
+ count: max,
282
+ unit: i18next.t(`unitsOfTime:withoutCount.${unit}`, {
283
+ count: max
284
+ })
285
+ });
286
+ // 3. Only period present
287
+ return i18next.t("fields.period.period", {
288
+ count: period,
289
+ unit: i18next.t(`unitsOfTime:withoutCount.${unit}`, {
290
+ count: period
291
+ })
292
+ });
293
+ }
294
+ }
295
+
296
+
297
+ // Functions
298
+ const $93b58b7d2ead3b95$var$linkworsdMap = {
299
+ and: "linkwords.and",
300
+ then: "linkwords.then"
301
+ };
302
+ function $93b58b7d2ead3b95$export$826742c1df3eca39(i18next, arr, linkWord = "and") {
303
+ // Split the array into two parts: all entries except the last one, and the last
304
+ const firstString = arr.slice(0, -1).join(", ");
305
+ const lastString = arr.slice(-1).join("");
306
+ // concatenate the result
307
+ const linkWordTechnicalKey = $93b58b7d2ead3b95$var$linkworsdMap[linkWord];
308
+ const linkWordAsString = arr.length > 1 ? ` ${i18next.t(linkWordTechnicalKey)} ` : "";
309
+ const finalString = firstString + linkWordAsString + lastString;
310
+ return finalString;
311
+ }
312
+
313
+
314
+ // Function to extract times
315
+ function $7a065f861a4b61f2$var$extractTime(minutes) {
316
+ let days = Math.floor(minutes / 1440);
317
+ let hours = Math.floor(minutes % 1440 / 60);
318
+ let remainingMinutes = minutes % 60;
319
+ return {
320
+ days: days,
321
+ hours: hours,
322
+ minutes: remainingMinutes
323
+ };
324
+ }
325
+ // Function to transform offset into a string
326
+ function $7a065f861a4b61f2$var$transformOffset(i18next, offset) {
327
+ if (offset === undefined || offset <= 0) return undefined;
328
+ // extract days / hours / minutes from it
329
+ let time = $7a065f861a4b61f2$var$extractTime(offset);
330
+ // generate part
331
+ let subParts = [
332
+ // days
333
+ time.days > 0 ? i18next.t("unitsOfTime:withCount.d", {
334
+ count: time.days
335
+ }) : undefined,
336
+ // hours
337
+ time.hours > 0 ? i18next.t("unitsOfTime:withCount.h", {
338
+ count: time.hours
339
+ }) : undefined,
340
+ // minutes
341
+ time.minutes > 0 ? i18next.t("unitsOfTime:withCount.min", {
342
+ count: time.minutes
343
+ }) : undefined
344
+ ].filter((s)=>s !== undefined);
345
+ return subParts.join(" ");
346
+ }
347
+ // Function to transform when[] into a string
348
+ function $7a065f861a4b61f2$var$transformWhen(i18next, when) {
349
+ // Only run when array is not empty
350
+ if (when === undefined || when.length === 0) return undefined;
351
+ // Turn it into a string
352
+ const whens = when.map((whenCode)=>i18next.t(`eventTiming:${whenCode}`));
353
+ const finalString = (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(i18next, whens);
354
+ return finalString;
355
+ }
356
+ function $7a065f861a4b61f2$export$433fa514f44031f3({ dos: dos, i18next: i18next }) {
357
+ // If empty, return undefined
358
+ if (dos.timing === undefined || dos.timing.repeat === undefined) return undefined;
359
+ // Pickup the repeat interesting attributes
360
+ let repeat = dos.timing.repeat;
361
+ let offset = repeat.offset;
362
+ let when = repeat.when;
363
+ // If both are undefined, don't do anything
364
+ if (offset === undefined && when === undefined) return undefined;
365
+ return [
366
+ // offset part
367
+ $7a065f861a4b61f2$var$transformOffset(i18next, offset),
368
+ // when part
369
+ $7a065f861a4b61f2$var$transformWhen(i18next, when)
370
+ ].filter((s)=>s !== undefined).join(" ");
371
+ }
372
+
373
+
374
+ // Function
375
+
376
+ function $46f2142e76cf7e45$export$f6325e43097e9543({ dos: dos, i18next: i18next }) {
377
+ // If empty, return undefined
378
+ if (dos.timing === undefined || dos.timing.repeat === undefined) return undefined;
379
+ // Pickup the repeat interesting attributes
380
+ let repeat = dos.timing.repeat;
381
+ let dayOfWeek = repeat.dayOfWeek;
382
+ // If empty, skip it
383
+ if (dayOfWeek === undefined || dayOfWeek.length === 0) return undefined;
384
+ else {
385
+ // Turn it into a string
386
+ const dayOfWeeks = dayOfWeek.map((dayCode)=>i18next.t(`daysOfWeek:${dayCode}`));
387
+ const dayOfWeeksAsString = (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(i18next, dayOfWeeks);
388
+ return i18next.t("fields.dayOfWeek.dayOfWeek", {
389
+ count: dayOfWeek.length,
390
+ dayOfWeek: dayOfWeeksAsString
391
+ });
392
+ }
393
+ }
394
+
395
+
396
+ // Functions
397
+
398
+ /**
399
+ * time during the day, in the format hh:mm:ss (a subset of [ISO8601] icon).
400
+ * There is no date specified. Seconds must be provided due to schema type constraints but may be zero-filled
401
+ * and may be ignored at receiver discretion
402
+ */ function $a846209a7dd119d4$var$formatString(time) {
403
+ // Split the time string by ":"
404
+ var parts = time.split(":");
405
+ // Check if the last part (seconds) is "00", if so, remove it
406
+ if (parts.length > 2 && parts[2] === "00") parts.pop();
407
+ // Join the remaining parts with ":"
408
+ return parts.join(":");
409
+ }
410
+ function $a846209a7dd119d4$export$ee205fa48981886d({ dos: dos, i18next: i18next }) {
411
+ // If empty, return undefined
412
+ if (dos.timing === undefined || dos.timing.repeat === undefined) return undefined;
413
+ // Pickup the repeat interesting attributes
414
+ let repeat = dos.timing.repeat;
415
+ let timeOfDay = repeat.timeOfDay;
416
+ // If empty, skip it
417
+ if (timeOfDay === undefined || timeOfDay.length === 0) return undefined;
418
+ else {
419
+ // Turn it into a string
420
+ const timeOfDays = timeOfDay.map($a846209a7dd119d4$var$formatString);
421
+ const timeOfDaysAsString = (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(i18next, timeOfDays);
422
+ return i18next.t("fields.timeOfDay", {
423
+ timeOfDay: timeOfDaysAsString,
424
+ count: timeOfDays.length
425
+ });
426
+ }
427
+ }
428
+
429
+
430
+ // Function
431
+
432
+ // Turn a list of codeable concept into a string
433
+ function $ee04e2a8ed39962f$var$fromCodeableConceptArrayToString(i18next, codes, config) {
434
+ const codesAsString = codes.map((code)=>config.fromCodeableConceptToString({
435
+ code: code,
436
+ language: config.language
437
+ })).filter((s)=>s !== undefined);
438
+ return (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(i18next, codesAsString);
439
+ }
440
+ function $ee04e2a8ed39962f$export$5c69a2202525487a({ dos: dos, config: config, i18next: i18next }) {
441
+ // Pickup the interesting attributes
442
+ let asNeededBoolean = dos.asNeededBoolean;
443
+ let asNeededCodeableConcept = dos.asNeededCodeableConcept;
444
+ let asNeededFor = dos.asNeededFor;
445
+ let asNeeded = dos.asNeeded;
446
+ // Codeable concept as list, to make algorithm simpler
447
+ let codeableList = asNeededFor || (asNeededCodeableConcept !== undefined ? [
448
+ asNeededCodeableConcept
449
+ ] : []);
450
+ if (codeableList.length > 0) return i18next.t("fields.asNeededFor", {
451
+ reasons: $ee04e2a8ed39962f$var$fromCodeableConceptArrayToString(i18next, codeableList, config)
452
+ });
453
+ else {
454
+ // merge boolean to make it simpler
455
+ let booleanValue = asNeededBoolean || asNeeded || false;
456
+ if (booleanValue) return i18next.t("fields.asNeeded");
457
+ else return undefined;
458
+ }
459
+ }
460
+
461
+
462
+ // types
463
+ // Duration to string
464
+ function $9d632517596957df$var$transformDurationToString(i18next, duration, config) {
465
+ let quantity = duration.value;
466
+ // If common units from HL7, do the job
467
+ if (duration.system === "http://hl7.org/fhir/ValueSet/duration-units") {
468
+ let code = duration.code;
469
+ return i18next.t(`unitsOfTime:withCount.${code}`, {
470
+ count: quantity
471
+ });
472
+ } else {
473
+ // otherwise, it is UCUM, ... so let the user do the job
474
+ let unit = config.fromFHIRQuantityUnitToString({
475
+ language: config.language,
476
+ quantity: duration
477
+ });
478
+ return `${quantity} ${unit}`;
479
+ }
480
+ }
481
+ function $9d632517596957df$export$b927a06bc51aea32({ dos: dos, config: config, i18next: i18next }) {
482
+ // If empty, return undefined
483
+ if (dos.timing === undefined || dos.timing.repeat === undefined) return undefined;
484
+ // Pickup the repeat interesting attributes
485
+ let repeat = dos.timing.repeat;
486
+ let boundsDuration = repeat.boundsDuration;
487
+ // Do nothing if no boundsDuration, I am not a wizard
488
+ if (boundsDuration === undefined) return undefined;
489
+ else {
490
+ let durationText = $9d632517596957df$var$transformDurationToString(i18next, boundsDuration, config);
491
+ return i18next.t("fields.boundsDuration", {
492
+ durationText: durationText
493
+ });
494
+ }
495
+ }
496
+
497
+
498
+ // types
499
+ // Quantity unit to string
500
+ function $2da391a8a8345a3d$var$transformQuantityUnitToString(i18next, quantity, config) {
501
+ let quantityValue = quantity.value;
502
+ // If common units from HL7, do the job
503
+ if (quantity.system === "http://hl7.org/fhir/ValueSet/duration-units") {
504
+ let code = quantity.code;
505
+ return i18next.t(`unitsOfTime:withoutCount.${code}`, {
506
+ count: quantityValue
507
+ });
508
+ } else // otherwise, it is UCUM, ... so let the user do the job
509
+ return config.fromFHIRQuantityUnitToString({
510
+ language: config.language,
511
+ quantity: quantity
512
+ });
513
+ }
514
+ function $2da391a8a8345a3d$export$8c667cbf7bebaa93({ dos: dos, config: config, i18next: i18next }) {
515
+ // If empty, return undefined
516
+ if (dos.timing === undefined || dos.timing.repeat === undefined) return undefined;
517
+ // Pickup the repeat interesting attributes
518
+ let repeat = dos.timing.repeat;
519
+ let boundsRange = repeat.boundsRange;
520
+ // Do nothing if no boundsRange, I am not a wizard
521
+ if (boundsRange === undefined) return undefined;
522
+ else {
523
+ let low = boundsRange.low;
524
+ let high = boundsRange.high;
525
+ // quantity unit
526
+ let unit = $2da391a8a8345a3d$var$transformQuantityUnitToString(i18next, high || low, config);
527
+ // Three cases
528
+ // 1. Both low & high are present
529
+ if (high !== undefined && low !== undefined) return i18next.t("fields.boundsRange.lowAndHigh", {
530
+ low: low.value,
531
+ high: high.value,
532
+ unit: unit
533
+ });
534
+ // 2. Only high is present
535
+ if (high !== undefined) return i18next.t("fields.boundsRange.onlyHigh", {
536
+ high: high.value,
537
+ unit: unit
538
+ });
539
+ // 3. Only low is present
540
+ return i18next.t("fields.boundsRange.onlyLow", {
541
+ low: low.value,
542
+ unit: unit
543
+ });
544
+ }
545
+ }
546
+
547
+
548
+ function $39470eb799331038$export$498ca7f558a02e67({ dos: dos, i18next: i18next }) {
549
+ // If empty, return undefined
550
+ if (dos.timing === undefined || dos.timing.repeat === undefined) return undefined;
551
+ // Pickup the repeat interesting attributes
552
+ let repeat = dos.timing.repeat;
553
+ let count = repeat.count;
554
+ let countMax = repeat.countMax;
555
+ // Do nothing if no count, I am not a wizard
556
+ if (count === undefined && countMax === undefined) return undefined;
557
+ else {
558
+ // Three cases
559
+ // 1. Both count & countMax are present
560
+ if (count !== undefined && countMax !== undefined) return i18next.t("fields.countMax.countMax", {
561
+ count: countMax,
562
+ low: count
563
+ });
564
+ // 2. Only countMax is present
565
+ if (countMax !== undefined) return i18next.t("fields.count.count", {
566
+ count: countMax
567
+ });
568
+ // 3. Only count is present
569
+ return i18next.t("fields.count.count", {
570
+ count: count
571
+ });
572
+ }
573
+ }
574
+
575
+
576
+ // Functions
577
+
578
+ // types
579
+ // Function to clean up the params for dateStyle situation
580
+ // Note: dateStyle and timeStyle can be used with each other,
581
+ // but not with other date-time component options (e.g. weekday, hour, month, etc.).
582
+ function $208be5279f5e6c65$var$generateDateStyleFormatOptions(options) {
583
+ return {
584
+ year: options.dateStyle === undefined ? options.year || "numeric" : undefined,
585
+ month: options.dateStyle === undefined ? options.month || "2-digit" : undefined,
586
+ day: options.dateStyle === undefined ? options.day || "2-digit" : undefined,
587
+ weekday: options.dateStyle === undefined ? options.weekday : undefined
588
+ };
589
+ }
590
+ // Function to clean up the params for timeStyle situation
591
+ function $208be5279f5e6c65$var$generateTimeStyleFormatOptions(options) {
592
+ return {
593
+ hour: options.timeStyle === undefined ? options.hour || "2-digit" : undefined,
594
+ minute: options.timeStyle === undefined ? options.minute || "2-digit" : undefined,
595
+ second: options.timeStyle === undefined ? options.second || "2-digit" : undefined
596
+ };
597
+ }
598
+ function $208be5279f5e6c65$export$a77f8869772ffca4({ config: config, datetimes: datetimes }) {
599
+ let options = config.dateTimeFormatOptions;
600
+ // prepare data for algorithm below
601
+ const entries = datetimes.map((datetime)=>{
602
+ // Convert it to date
603
+ let date = new Date(datetime);
604
+ // other properties
605
+ let hasTimePart = datetime.includes("T");
606
+ let hyphensCount = datetime.split("-").length - 1;
607
+ let hasMonths = hyphensCount >= 1;
608
+ let hasDays = hyphensCount >= 2;
609
+ return {
610
+ date: date,
611
+ hasTimePart: hasTimePart,
612
+ hasMonths: hasMonths,
613
+ hasDays: hasDays
614
+ };
615
+ });
616
+ // Time to do the magic
617
+ const result = entries.map(({ date: date, hasTimePart: hasTimePart, hasMonths: hasMonths, hasDays: hasDays })=>{
618
+ // If only year is defined, print it fully (e.g. 2024)
619
+ if (!hasMonths) {
620
+ let df1 = new Intl.DateTimeFormat(config.language, {
621
+ year: "numeric"
622
+ });
623
+ return df1.format(date);
624
+ }
625
+ // If only year and month are defined, print it nicely (e.g. 2024-03 => May 2024 )
626
+ if (!hasDays) {
627
+ let df2 = new Intl.DateTimeFormat(config.language, {
628
+ year: "numeric",
629
+ month: "long"
630
+ });
631
+ return df2.format(date);
632
+ }
633
+ // If only year / month and days are defined, print it according
634
+ if (!hasTimePart) {
635
+ let df3 = new Intl.DateTimeFormat(config.language, {
636
+ // retrieve value from user
637
+ dateStyle: options.dateStyle,
638
+ // fallback if dateStyle is not defined
639
+ ...$208be5279f5e6c65$var$generateDateStyleFormatOptions(options)
640
+ });
641
+ return df3.format(date);
642
+ }
643
+ // Otherwise, we have a full datetime
644
+ let df4 = new Intl.DateTimeFormat(config.language, {
645
+ // retrieve value from user
646
+ dateStyle: options.dateStyle,
647
+ timeStyle: options.timeStyle,
648
+ // fallback if dateStyle / timeStyle is not defined
649
+ ...$208be5279f5e6c65$var$generateDateStyleFormatOptions(options),
650
+ ...$208be5279f5e6c65$var$generateTimeStyleFormatOptions(options)
651
+ });
652
+ return df4.format(date);
653
+ });
654
+ return result;
655
+ }
656
+ function $208be5279f5e6c65$export$4699e913d5b6ffeb({ config: config, datetime: datetime }) {
657
+ // Can't do magic ;)
658
+ if (datetime === undefined) return undefined;
659
+ // Invoke previous function, and pick up the first entry
660
+ const result = $208be5279f5e6c65$export$a77f8869772ffca4({
661
+ config: config,
662
+ datetimes: [
663
+ datetime
664
+ ]
665
+ });
666
+ return result[0];
667
+ }
668
+
669
+
670
+ function $3bceb6a4d7bec96e$export$3c2848bc0f0e3783({ dos: dos, config: config, i18next: i18next }) {
671
+ // If empty, return undefined
672
+ if (dos.timing === undefined || dos.timing.event === undefined || dos.timing.event.length === 0) return undefined;
673
+ // Generate the string version of them
674
+ let events = dos.timing.event;
675
+ // List to string
676
+ let eventList = (0, $208be5279f5e6c65$export$a77f8869772ffca4)({
677
+ config: config,
678
+ datetimes: events
679
+ });
680
+ let eventsAsString = (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(i18next, eventList);
681
+ return i18next.t("fields.event.event", {
682
+ count: events.length,
683
+ event: eventsAsString
684
+ });
685
+ }
686
+
687
+
688
+ // Function
689
+
690
+ function $6c156f35df44ca41$export$21e3522d6e713036({ dos: dos, config: config, i18next: i18next }) {
691
+ // If empty, return undefined
692
+ if (dos.additionalInstruction === undefined || dos.additionalInstruction.length === 0) return undefined;
693
+ // Turn it into strings
694
+ let additionalInstructions = dos.additionalInstruction.map((instruction)=>config.fromCodeableConceptToString({
695
+ code: instruction,
696
+ language: config.language
697
+ })).filter((s)=>s !== undefined);
698
+ return (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(i18next, additionalInstructions);
699
+ }
700
+
701
+
702
+ // types
703
+ function $e021f207f5cc63d0$export$6e78f21a88fc25ea({ dos: dos, config: config, i18next: i18next }) {
704
+ // If empty, return undefined
705
+ if (dos.maxDosePerLifetime === undefined) return undefined;
706
+ const maxDosePerLifetime = dos.maxDosePerLifetime;
707
+ let unit = config.fromFHIRQuantityUnitToString({
708
+ language: config.language,
709
+ quantity: maxDosePerLifetime
710
+ });
711
+ return i18next.t("fields.maxDosePerLifetime", {
712
+ count: maxDosePerLifetime.value || 1,
713
+ unit: unit
714
+ });
715
+ }
716
+
717
+
718
+ // types
719
+ function $9ad44f2c84a9bdf4$export$58c8a9e040283a66({ dos: dos, config: config, i18next: i18next }) {
720
+ // If empty, return undefined
721
+ if (dos.maxDosePerAdministration === undefined) return undefined;
722
+ const maxDosePerAdministration = dos.maxDosePerAdministration;
723
+ let unit = config.fromFHIRQuantityUnitToString({
724
+ language: config.language,
725
+ quantity: maxDosePerAdministration
726
+ });
727
+ return i18next.t("fields.maxDosePerAdministration", {
728
+ count: maxDosePerAdministration.value || 1,
729
+ unit: unit
730
+ });
731
+ }
732
+
733
+
734
+ // Functions
735
+
736
+ function $45256d2a188dcbd7$export$75a89431d80a701a({ dos: dos, config: config, i18next: i18next }) {
737
+ // If empty, return undefined
738
+ if (dos.timing === undefined || dos.timing.repeat === undefined || dos.timing.repeat.boundsPeriod === undefined) return undefined;
739
+ // Generate the string version of them
740
+ const boundsPeriod = dos.timing.repeat.boundsPeriod;
741
+ let start = (0, $208be5279f5e6c65$export$4699e913d5b6ffeb)({
742
+ config: config,
743
+ datetime: boundsPeriod.start
744
+ });
745
+ let end = (0, $208be5279f5e6c65$export$4699e913d5b6ffeb)({
746
+ config: config,
747
+ datetime: boundsPeriod.end
748
+ });
749
+ // Three cases
750
+ // 1. Both start and end are present
751
+ if (start !== undefined && end !== undefined) return i18next.t("fields.boundsPeriod.startAndEnd", {
752
+ start: start,
753
+ end: end
754
+ });
755
+ // 2. Only start is present
756
+ if (start !== undefined) return i18next.t("fields.boundsPeriod.onlyStart", {
757
+ start: start
758
+ });
759
+ // 3. Only end is present
760
+ return i18next.t("fields.boundsPeriod.onlyEnd", {
761
+ end: end
762
+ });
763
+ }
764
+
765
+
766
+
767
+ function $39ffdeadc450f558$export$346b11a8cb220f02({ dos: dos, config: config, i18next: i18next }) {
768
+ // If empty, return undefined
769
+ if (dos.maxDosePerPeriod === undefined) return undefined;
770
+ const maxDosePerPeriod = dos.maxDosePerPeriod;
771
+ // In R4, it was a single object
772
+ // In R5, it is an array
773
+ // So better to have a generic approach
774
+ const values = Array.isArray(maxDosePerPeriod) ? maxDosePerPeriod : [
775
+ maxDosePerPeriod
776
+ ];
777
+ // Only consider not empty array
778
+ if (values.length === 0) return undefined;
779
+ // Periods are expressed as ratio (like rateRatio)
780
+ const valuesAsString = values.map((period)=>{
781
+ // num / dem
782
+ let numerator = period.numerator;
783
+ let denominator = period.denominator;
784
+ let quantityNum = numerator?.value || 1;
785
+ let quantityDenom = denominator?.value || 1;
786
+ // units as text
787
+ let numeratorUnit = numerator !== undefined ? config.fromFHIRQuantityUnitToString({
788
+ language: config.language,
789
+ quantity: numerator
790
+ }) : "";
791
+ let denominatorUnit = denominator !== undefined ? config.fromFHIRQuantityUnitToString({
792
+ language: config.language,
793
+ quantity: denominator
794
+ }) : "";
795
+ return i18next.t("fields.maxDosePerPeriod.maxDosePerPeriod", {
796
+ count: quantityDenom,
797
+ quantityNumerator: quantityNum,
798
+ numeratorUnit: numeratorUnit,
799
+ denominatorUnit: denominatorUnit
800
+ });
801
+ });
802
+ const maxDosePerPeriodText = (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(i18next, valuesAsString);
803
+ return i18next.t("fields.maxDosePerPeriod.general", {
804
+ count: values.length,
805
+ maxDosePerPeriodText: maxDosePerPeriodText
806
+ });
807
+ }
808
+
809
+
810
+
811
+
812
+ // Map
813
+ const $2c21ace90ecdbde6$var$displayOrders = {
814
+ additionalInstruction: (input)=>(0, $6c156f35df44ca41$export$21e3522d6e713036)(input),
815
+ asNeeded: (input)=>(0, $ee04e2a8ed39962f$export$5c69a2202525487a)(input),
816
+ boundsDuration: (input)=>(0, $9d632517596957df$export$b927a06bc51aea32)(input),
817
+ boundsRange: (input)=>(0, $2da391a8a8345a3d$export$8c667cbf7bebaa93)(input),
818
+ boundsPeriod: (input)=>(0, $45256d2a188dcbd7$export$75a89431d80a701a)(input),
819
+ code: ({ dos: dos, config: config })=>config.fromCodeableConceptToString({
820
+ language: config.language,
821
+ code: dos.timing?.code
822
+ }),
823
+ countCountMax: (input)=>(0, $39470eb799331038$export$498ca7f558a02e67)(input),
824
+ dayOfWeek: (input)=>(0, $46f2142e76cf7e45$export$f6325e43097e9543)(input),
825
+ doseQuantity: (input)=>(0, $5ab57a471c359130$export$7de3722258b87db9)(input),
826
+ doseRange: (input)=>(0, $9a073aa5b09aa778$export$4cd16590995531a9)(input),
827
+ durationDurationMax: (input)=>(0, $1270a8f06113f53a$export$675ae45fa2875f4a)(input),
828
+ event: (input)=>(0, $3bceb6a4d7bec96e$export$3c2848bc0f0e3783)(input),
829
+ extension: ({ dos: dos, config: config })=>config.fromExtensionsToString({
830
+ language: config.language,
831
+ extensions: dos.extension
832
+ }),
833
+ frequencyFrequencyMax: (input)=>(0, $bc43734b944260d2$export$d663412e0c469ce2)(input),
834
+ frequencyFrequencyMaxPeriodPeriodMax: (input)=>{
835
+ let subParts = [
836
+ (0, $bc43734b944260d2$export$d663412e0c469ce2)(input),
837
+ (0, $b9825dd9e0a2e687$export$aa31b783699f637)(input)
838
+ ].filter((s)=>s !== undefined);
839
+ return subParts.length > 0 ? subParts.join(" ") : undefined;
840
+ },
841
+ maxDosePerAdministration: (input)=>(0, $9ad44f2c84a9bdf4$export$58c8a9e040283a66)(input),
842
+ maxDosePerLifetime: (input)=>(0, $e021f207f5cc63d0$export$6e78f21a88fc25ea)(input),
843
+ maxDosePerPeriod: (input)=>(0, $39ffdeadc450f558$export$346b11a8cb220f02)(input),
844
+ method: ({ dos: dos, config: config })=>config.fromCodeableConceptToString({
845
+ language: config.language,
846
+ code: dos.method
847
+ }),
848
+ offsetWhen: (input)=>(0, $7a065f861a4b61f2$export$433fa514f44031f3)(input),
849
+ patientInstruction: ({ dos: dos })=>dos.patientInstruction,
850
+ periodPeriodMax: (input)=>(0, $b9825dd9e0a2e687$export$aa31b783699f637)(input),
851
+ rateQuantity: (input)=>(0, $052c79abb28cba29$export$4e24ef8c7997cc56)(input),
852
+ rateRange: (input)=>(0, $703b645b55481398$export$d3dd7d3522271dba)(input),
853
+ rateRatio: (input)=>(0, $301791f33da707fa$export$b71cfd2510242de2)(input),
854
+ route: ({ dos: dos, config: config })=>config.fromCodeableConceptToString({
855
+ language: config.language,
856
+ code: dos.route
857
+ }),
858
+ site: ({ dos: dos, config: config })=>config.fromCodeableConceptToString({
859
+ language: config.language,
860
+ code: dos.site
861
+ }),
862
+ text: ({ dos: dos })=>dos.text,
863
+ timeOfDay: (input)=>(0, $a846209a7dd119d4$export$ee205fa48981886d)(input)
864
+ };
865
+ function $2c21ace90ecdbde6$export$9f330b4bf8c0975c({ entry: entry, ...args }) {
866
+ // Use map to provide a result without iterate on each key
867
+ return $2c21ace90ecdbde6$var$displayOrders[entry](args);
868
+ }
869
+
870
+
871
+
872
+ // backends i18next
873
+ const $74b0cf9d3dbd5b46$var$localeImport = async (lng, ns)=>import(`./locales/${lng}/${ns}.json`);
874
+ class $74b0cf9d3dbd5b46$export$1c191bca55f84a03 {
875
+ // Set up lib, according provided parameters
876
+ constructor(args){
877
+ this.config = {
878
+ // default attributes
879
+ language: "en",
880
+ fromFHIRQuantityUnitToString: (0, $1c57f108974f2805$export$b1a6aed91fad1636),
881
+ fromCodeableConceptToString: (0, $a6c648898dc8c3b6$export$f478f96b98da13a4),
882
+ fromExtensionsToString: (0, $34ebae8ac5b52fcd$export$30c337e25ab8e95b),
883
+ displayOrder: [
884
+ "method",
885
+ "doseQuantity",
886
+ "doseRange",
887
+ "rateRatio",
888
+ "rateQuantity",
889
+ "rateRange",
890
+ "durationDurationMax",
891
+ "frequencyFrequencyMaxPeriodPeriodMax",
892
+ "offsetWhen",
893
+ "dayOfWeek",
894
+ "timeOfDay",
895
+ "route",
896
+ "site",
897
+ "asNeeded",
898
+ "boundsDuration",
899
+ "boundsPeriod",
900
+ "boundsRange",
901
+ "countCountMax",
902
+ "event",
903
+ "code",
904
+ "maxDosePerPeriod",
905
+ "maxDosePerAdministration",
906
+ "maxDosePerLifetime",
907
+ "additionalInstruction",
908
+ "patientInstruction"
909
+ ],
910
+ displaySeparator: " - ",
911
+ dateTimeFormatOptions: {},
912
+ // attributes set by user
913
+ ...args
914
+ };
915
+ this.i18nInstance = (0, ($parcel$interopDefault($8zHUo$i18next))).createInstance();
916
+ }
917
+ /**
918
+ * To init i18next properly according requested criteria
919
+ */ async init() {
920
+ // You should wait for init to complete (wait for the callback or promise resolution)
921
+ // before using the t function!
922
+ return await this.i18nInstance.use((0, ($parcel$interopDefault($8zHUo$i18nextchainedbackend)))).init({
923
+ //debug: true,
924
+ fallbackLng: "en",
925
+ lng: this.config.language,
926
+ ns: [
927
+ "common",
928
+ "daysOfWeek",
929
+ "eventTiming",
930
+ "unitsOfTime"
931
+ ],
932
+ defaultNS: "common",
933
+ backend: {
934
+ backends: [
935
+ (0, ($parcel$interopDefault($8zHUo$i18nextresourcestobackend)))(// have to cast the function to be webpack / builder friendly
936
+ $74b0cf9d3dbd5b46$var$localeImport)
937
+ ]
938
+ }
939
+ });
940
+ }
941
+ /**
942
+ * Factory to create a fine-tuned instance of the utility class
943
+ */ static async build(args) {
944
+ const instance = new $74b0cf9d3dbd5b46$export$1c191bca55f84a03(args);
945
+ await instance.init();
946
+ return instance;
947
+ }
948
+ /**
949
+ * To change language
950
+ */ async changeLanguage(lng) {
951
+ this.config = {
952
+ ...this.config,
953
+ language: lng
954
+ };
955
+ return this.i18nInstance.changeLanguage(lng);
956
+ }
957
+ /**
958
+ * To change display order
959
+ */ changeDisplayOrder(order) {
960
+ this.config = {
961
+ ...this.config,
962
+ displayOrder: order
963
+ };
964
+ }
965
+ /**
966
+ * Turn a FHIR Dosage object into text
967
+ */ fromDosageToText(dos) {
968
+ // iterate on each key and generate a string from each part
969
+ let order = this.config.displayOrder;
970
+ let parts = order.map((entry)=>(0, $2c21ace90ecdbde6$export$9f330b4bf8c0975c)({
971
+ config: this.config,
972
+ dos: dos,
973
+ entry: entry,
974
+ i18next: this.i18nInstance
975
+ })).filter((s)=>s !== undefined);
976
+ // Join each part with a separator
977
+ return parts.join(this.config.displaySeparator);
978
+ }
979
+ /**
980
+ * Turn multiple FHIR Dosage object into text
981
+ */ fromMultipleDosageToText(dosages) {
982
+ // As we can have concurrent / sequential instructions, we need a generic algorithm to do the job
983
+ // 1. Collect all sequences number
984
+ let sequencesNumbers = dosages.map((d)=>d.sequence).filter((s)=>s !== undefined);
985
+ // 2. Convert it to a Set
986
+ let encounteredSequenceNumbers = new Set(sequencesNumbers);
987
+ // 3. We have a "sequential" situation in two cases
988
+ // A) No sequence number were provided
989
+ // B) All sequence numbers are different
990
+ if (encounteredSequenceNumbers.size === 0 || encounteredSequenceNumbers.size === dosages.length) {
991
+ const dosagesAsText = dosages.map((d)=>this.fromDosageToText(d));
992
+ return (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(this.i18nInstance, dosagesAsText, "then");
993
+ }
994
+ // 4. We have both "sequential" and "concurrent" instructions - time to see what is the configuration
995
+ let groups = {};
996
+ let sequences = new Set();
997
+ for(let idx = 0; idx < dosages.length; idx++){
998
+ // Get dosage object
999
+ const dosage = dosages[idx];
1000
+ // Get the sequence number (normally, in real world, it should be present in this case)
1001
+ // If no sequence number, assume it is idx + 1
1002
+ let sequenceNr = dosage.sequence || idx + 1;
1003
+ // Generate the text version
1004
+ let dosageAsText = this.fromDosageToText(dosage);
1005
+ // Retrieve of create previous entries for this sequence number
1006
+ let localGroup = groups[sequenceNr] || [];
1007
+ // Add entry
1008
+ localGroup.push(dosageAsText);
1009
+ // Pushback result
1010
+ groups[sequenceNr] = localGroup;
1011
+ // For reminder of the parsed sequence
1012
+ sequences.add(sequenceNr);
1013
+ }
1014
+ // 5. Now that data structures are filled, it is a piece of cake to generate the result
1015
+ let sequentialInstructions = [
1016
+ ...sequences.values()
1017
+ ].map((sequence)=>{
1018
+ let concurrentInstructions = groups[sequence];
1019
+ return (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(this.i18nInstance, concurrentInstructions, "and");
1020
+ });
1021
+ return (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(this.i18nInstance, sequentialInstructions, "then");
1022
+ }
1023
+ }
1024
+
1025
+
1026
+ var // Default export to make it user-friendly
1027
+ $882b6d93070905b3$export$2e2bcd8739ae039 = (0, $74b0cf9d3dbd5b46$export$1c191bca55f84a03);
1028
+
1029
+
1030
+ //# sourceMappingURL=main.js.map