fhir-dosage-utils 1.1.1 → 1.2.1
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/LICENSE +661 -0
- package/README.md +1 -1
- package/dist/main.js +95 -65
- package/dist/main.js.map +1 -1
- package/dist/module.js +95 -65
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +10 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/module.js
CHANGED
@@ -36,18 +36,27 @@ function $a31aaee21175037d$export$30c337e25ab8e95b({ extensions: extensions }) {
|
|
36
36
|
|
37
37
|
// translators
|
38
38
|
// To avoid circular dependancies issue, let's have a single place for exports and imports
|
39
|
-
//
|
40
|
-
function $
|
39
|
+
// Types
|
40
|
+
function $a8a8a2e7c5a5225c$export$76d408d587da5203(dos, key) {
|
41
41
|
// If empty, return undefined
|
42
42
|
if (dos.doseAndRate === undefined) return undefined;
|
43
43
|
// Find the first entry that match criteria
|
44
|
-
let
|
44
|
+
let doseAndRate = dos.doseAndRate.find((s)=>s[key] !== undefined);
|
45
|
+
// If not found, skip
|
46
|
+
if (doseAndRate === undefined) return undefined;
|
47
|
+
// return property
|
48
|
+
return doseAndRate[key];
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
function $7cf24331c38efaf1$export$7de3722258b87db9({ config: config, dos: dos, i18next: i18next }) {
|
53
|
+
let doseQuantity = (0, $a8a8a2e7c5a5225c$export$76d408d587da5203)(dos, "doseQuantity");
|
45
54
|
// If not found, skip
|
46
55
|
if (doseQuantity === undefined) return undefined;
|
47
|
-
let quantity = doseQuantity.
|
56
|
+
let quantity = doseQuantity.value || 1;
|
48
57
|
let unit = config.fromFHIRQuantityUnitToString({
|
49
58
|
language: config.language,
|
50
|
-
quantity: doseQuantity
|
59
|
+
quantity: doseQuantity
|
51
60
|
});
|
52
61
|
return i18next.t("fields.doseQuantity", {
|
53
62
|
quantity: quantity,
|
@@ -106,16 +115,14 @@ function $73073500f7f08f16$export$be17d167ed50d870({ range: range, config: confi
|
|
106
115
|
}
|
107
116
|
|
108
117
|
|
118
|
+
|
109
119
|
function $465e6e43e1df9717$export$4cd16590995531a9({ dos: dos, config: config, i18next: i18next }) {
|
110
|
-
|
111
|
-
if (dos.doseAndRate === undefined) return undefined;
|
112
|
-
// Find the first entry that match criteria
|
113
|
-
let doseRange = dos.doseAndRate.find((s)=>s.doseRange !== undefined);
|
120
|
+
let doseRange = (0, $a8a8a2e7c5a5225c$export$76d408d587da5203)(dos, "doseRange");
|
114
121
|
// If not found, skip
|
115
122
|
if (doseRange === undefined) return undefined;
|
116
123
|
// Turn range into a text
|
117
124
|
const text = (0, $73073500f7f08f16$export$be17d167ed50d870)({
|
118
|
-
range: doseRange
|
125
|
+
range: doseRange,
|
119
126
|
config: config,
|
120
127
|
i18next: i18next
|
121
128
|
});
|
@@ -127,20 +134,17 @@ function $465e6e43e1df9717$export$4cd16590995531a9({ dos: dos, config: config, i
|
|
127
134
|
}
|
128
135
|
|
129
136
|
|
130
|
-
|
137
|
+
|
131
138
|
function $bbbd1877a73b7a2b$export$4e24ef8c7997cc56({ dos: dos, config: config, i18next: i18next }) {
|
132
|
-
|
133
|
-
if (dos.doseAndRate === undefined) return undefined;
|
134
|
-
// Find the first entry that match criteria
|
135
|
-
let rateQuantity = dos.doseAndRate.find((s)=>s.rateQuantity !== undefined);
|
139
|
+
let rateQuantity = (0, $a8a8a2e7c5a5225c$export$76d408d587da5203)(dos, "rateQuantity");
|
136
140
|
// If not found, skip
|
137
141
|
if (rateQuantity === undefined) return undefined;
|
138
142
|
// information from rate
|
139
|
-
let value = rateQuantity.
|
143
|
+
let value = rateQuantity.value || 1;
|
140
144
|
// quantity unit
|
141
145
|
let unit = config.fromFHIRQuantityUnitToString({
|
142
146
|
language: config.language,
|
143
|
-
quantity: rateQuantity
|
147
|
+
quantity: rateQuantity
|
144
148
|
});
|
145
149
|
return i18next.t("fields.rateQuantity", {
|
146
150
|
quantity: value,
|
@@ -151,16 +155,14 @@ function $bbbd1877a73b7a2b$export$4e24ef8c7997cc56({ dos: dos, config: config, i
|
|
151
155
|
|
152
156
|
// Utility function
|
153
157
|
|
158
|
+
|
154
159
|
function $09db039855b6d015$export$d3dd7d3522271dba({ dos: dos, config: config, i18next: i18next }) {
|
155
|
-
|
156
|
-
if (dos.doseAndRate === undefined) return undefined;
|
157
|
-
// Find the first entry that match criteria
|
158
|
-
let doseAndRate = dos.doseAndRate.find((s)=>s.rateRange !== undefined);
|
160
|
+
let rateRange = (0, $a8a8a2e7c5a5225c$export$76d408d587da5203)(dos, "rateRange");
|
159
161
|
// If not found, skip
|
160
|
-
if (
|
162
|
+
if (rateRange === undefined) return undefined;
|
161
163
|
// Turn range into a text
|
162
164
|
const rangeText = (0, $73073500f7f08f16$export$be17d167ed50d870)({
|
163
|
-
range:
|
165
|
+
range: rateRange,
|
164
166
|
config: config,
|
165
167
|
i18next: i18next
|
166
168
|
});
|
@@ -218,18 +220,16 @@ function $eb371feb739abc89$export$fdc6e9cbd31555fb({ ratio: ratio, config: confi
|
|
218
220
|
}
|
219
221
|
|
220
222
|
|
223
|
+
|
221
224
|
function $520e93a43a731e9b$export$b71cfd2510242de2({ dos: dos, config: config, i18next: i18next }) {
|
222
|
-
|
223
|
-
if (dos.doseAndRate === undefined) return undefined;
|
224
|
-
// Find the first entry that match criteria
|
225
|
-
let doseAndRate = dos.doseAndRate.find((s)=>s.rateRatio !== undefined);
|
225
|
+
let rateRatio = (0, $a8a8a2e7c5a5225c$export$76d408d587da5203)(dos, "rateRatio");
|
226
226
|
// If not found, skip
|
227
|
-
if (
|
227
|
+
if (rateRatio === undefined) return undefined;
|
228
228
|
// Turn ratio to text
|
229
229
|
const ratioText = (0, $eb371feb739abc89$export$fdc6e9cbd31555fb)({
|
230
230
|
config: config,
|
231
231
|
i18next: i18next,
|
232
|
-
ratio:
|
232
|
+
ratio: rateRatio
|
233
233
|
});
|
234
234
|
if (ratioText === undefined) return undefined;
|
235
235
|
return i18next.t("fields.rateRatio", {
|
@@ -238,11 +238,18 @@ function $520e93a43a731e9b$export$b71cfd2510242de2({ dos: dos, config: config, i
|
|
238
238
|
}
|
239
239
|
|
240
240
|
|
241
|
-
function $
|
241
|
+
function $23009b94f0a4a8ee$export$1d3efc96e203aa6b(dos) {
|
242
242
|
// If empty, return undefined
|
243
243
|
if (dos.timing === undefined || dos.timing.repeat === undefined) return undefined;
|
244
|
+
return dos.timing.repeat;
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
function $9b80fa365533c8a7$export$675ae45fa2875f4a({ dos: dos, i18next: i18next }) {
|
249
|
+
let repeat = (0, $23009b94f0a4a8ee$export$1d3efc96e203aa6b)(dos);
|
250
|
+
// If empty, return undefined
|
251
|
+
if (repeat === undefined) return undefined;
|
244
252
|
// Pickup the repeat interesting attributes
|
245
|
-
let repeat = dos.timing.repeat;
|
246
253
|
let duration = repeat.duration;
|
247
254
|
let max = repeat.durationMax;
|
248
255
|
let unit = repeat.durationUnit;
|
@@ -265,11 +272,12 @@ function $9b80fa365533c8a7$export$675ae45fa2875f4a({ dos: dos, i18next: i18next
|
|
265
272
|
}
|
266
273
|
|
267
274
|
|
275
|
+
|
268
276
|
function $7e1bdc5bf5cdf5bd$export$d663412e0c469ce2({ dos: dos, i18next: i18next }) {
|
277
|
+
let repeat = (0, $23009b94f0a4a8ee$export$1d3efc96e203aa6b)(dos);
|
269
278
|
// If empty, return undefined
|
270
|
-
if (
|
279
|
+
if (repeat === undefined) return undefined;
|
271
280
|
// Pickup the repeat interesting attributes
|
272
|
-
let repeat = dos.timing.repeat;
|
273
281
|
let frequency = repeat.frequency;
|
274
282
|
let max = repeat.frequencyMax;
|
275
283
|
// Do nothing if no frequency / frequencyMax, I am not a wizard
|
@@ -293,11 +301,12 @@ function $7e1bdc5bf5cdf5bd$export$d663412e0c469ce2({ dos: dos, i18next: i18next
|
|
293
301
|
}
|
294
302
|
|
295
303
|
|
304
|
+
|
296
305
|
function $fcc6c325de921010$export$aa31b783699f637({ dos: dos, i18next: i18next }) {
|
306
|
+
let repeat = (0, $23009b94f0a4a8ee$export$1d3efc96e203aa6b)(dos);
|
297
307
|
// If empty, return undefined
|
298
|
-
if (
|
308
|
+
if (repeat === undefined) return undefined;
|
299
309
|
// Pickup the repeat interesting attributes
|
300
|
-
let repeat = dos.timing.repeat;
|
301
310
|
let period = repeat.period;
|
302
311
|
let max = repeat.periodMax;
|
303
312
|
let unit = repeat.periodUnit;
|
@@ -348,6 +357,7 @@ function $f475af73bad0ba43$export$826742c1df3eca39(i18next, arr, linkWord = "and
|
|
348
357
|
}
|
349
358
|
|
350
359
|
|
360
|
+
|
351
361
|
// Function to extract times
|
352
362
|
function $f88800def2ddd9e9$var$extractTime(minutes) {
|
353
363
|
let days = Math.floor(minutes / 1440);
|
@@ -391,10 +401,10 @@ function $f88800def2ddd9e9$var$transformWhen(i18next, when) {
|
|
391
401
|
return finalString;
|
392
402
|
}
|
393
403
|
function $f88800def2ddd9e9$export$433fa514f44031f3({ dos: dos, i18next: i18next }) {
|
404
|
+
let repeat = (0, $23009b94f0a4a8ee$export$1d3efc96e203aa6b)(dos);
|
394
405
|
// If empty, return undefined
|
395
|
-
if (
|
406
|
+
if (repeat === undefined) return undefined;
|
396
407
|
// Pickup the repeat interesting attributes
|
397
|
-
let repeat = dos.timing.repeat;
|
398
408
|
let offset = repeat.offset;
|
399
409
|
let when = repeat.when;
|
400
410
|
// If both are undefined, don't do anything
|
@@ -410,11 +420,12 @@ function $f88800def2ddd9e9$export$433fa514f44031f3({ dos: dos, i18next: i18next
|
|
410
420
|
|
411
421
|
// Function
|
412
422
|
|
423
|
+
|
413
424
|
function $80e4a0390d11feb3$export$f6325e43097e9543({ dos: dos, i18next: i18next }) {
|
425
|
+
let repeat = (0, $23009b94f0a4a8ee$export$1d3efc96e203aa6b)(dos);
|
414
426
|
// If empty, return undefined
|
415
|
-
if (
|
427
|
+
if (repeat === undefined) return undefined;
|
416
428
|
// Pickup the repeat interesting attributes
|
417
|
-
let repeat = dos.timing.repeat;
|
418
429
|
let dayOfWeek = repeat.dayOfWeek;
|
419
430
|
// If empty, skip it
|
420
431
|
if (dayOfWeek === undefined || dayOfWeek.length === 0) return undefined;
|
@@ -432,6 +443,7 @@ function $80e4a0390d11feb3$export$f6325e43097e9543({ dos: dos, i18next: i18next
|
|
432
443
|
|
433
444
|
// Functions
|
434
445
|
|
446
|
+
|
435
447
|
/**
|
436
448
|
* time during the day, in the format hh:mm:ss (a subset of [ISO8601] icon).
|
437
449
|
* There is no date specified. Seconds must be provided due to schema type constraints but may be zero-filled
|
@@ -445,10 +457,10 @@ function $80e4a0390d11feb3$export$f6325e43097e9543({ dos: dos, i18next: i18next
|
|
445
457
|
return parts.join(":");
|
446
458
|
}
|
447
459
|
function $a1b58a85293e76cc$export$ee205fa48981886d({ dos: dos, i18next: i18next }) {
|
460
|
+
let repeat = (0, $23009b94f0a4a8ee$export$1d3efc96e203aa6b)(dos);
|
448
461
|
// If empty, return undefined
|
449
|
-
if (
|
462
|
+
if (repeat === undefined) return undefined;
|
450
463
|
// Pickup the repeat interesting attributes
|
451
|
-
let repeat = dos.timing.repeat;
|
452
464
|
let timeOfDay = repeat.timeOfDay;
|
453
465
|
// If empty, skip it
|
454
466
|
if (timeOfDay === undefined || timeOfDay.length === 0) return undefined;
|
@@ -496,7 +508,8 @@ function $ab507771e2827c53$export$5c69a2202525487a({ dos: dos, config: config, i
|
|
496
508
|
}
|
497
509
|
|
498
510
|
|
499
|
-
//
|
511
|
+
// Functions
|
512
|
+
|
500
513
|
// Duration to string
|
501
514
|
function $ac69a26e361175ba$var$transformDurationToString(i18next, duration, config) {
|
502
515
|
let quantity = duration.value;
|
@@ -516,10 +529,10 @@ function $ac69a26e361175ba$var$transformDurationToString(i18next, duration, conf
|
|
516
529
|
}
|
517
530
|
}
|
518
531
|
function $ac69a26e361175ba$export$b927a06bc51aea32({ dos: dos, config: config, i18next: i18next }) {
|
532
|
+
let repeat = (0, $23009b94f0a4a8ee$export$1d3efc96e203aa6b)(dos);
|
519
533
|
// If empty, return undefined
|
520
|
-
if (
|
534
|
+
if (repeat === undefined) return undefined;
|
521
535
|
// Pickup the repeat interesting attributes
|
522
|
-
let repeat = dos.timing.repeat;
|
523
536
|
let boundsDuration = repeat.boundsDuration;
|
524
537
|
// Do nothing if no boundsDuration, I am not a wizard
|
525
538
|
if (boundsDuration === undefined) return undefined;
|
@@ -534,11 +547,12 @@ function $ac69a26e361175ba$export$b927a06bc51aea32({ dos: dos, config: config, i
|
|
534
547
|
|
535
548
|
// types
|
536
549
|
|
550
|
+
|
537
551
|
function $6b27b297c2af1001$export$8c667cbf7bebaa93({ dos: dos, config: config, i18next: i18next }) {
|
552
|
+
let repeat = (0, $23009b94f0a4a8ee$export$1d3efc96e203aa6b)(dos);
|
538
553
|
// If empty, return undefined
|
539
|
-
if (
|
554
|
+
if (repeat === undefined) return undefined;
|
540
555
|
// Pickup the repeat interesting attributes
|
541
|
-
let repeat = dos.timing.repeat;
|
542
556
|
let boundsRange = repeat.boundsRange;
|
543
557
|
// Do nothing if no boundsRange, I am not a wizard
|
544
558
|
if (boundsRange === undefined) return undefined;
|
@@ -559,11 +573,12 @@ function $6b27b297c2af1001$export$8c667cbf7bebaa93({ dos: dos, config: config, i
|
|
559
573
|
}
|
560
574
|
|
561
575
|
|
576
|
+
|
562
577
|
function $73a945b97fd1a22f$export$498ca7f558a02e67({ dos: dos, i18next: i18next }) {
|
578
|
+
let repeat = (0, $23009b94f0a4a8ee$export$1d3efc96e203aa6b)(dos);
|
563
579
|
// If empty, return undefined
|
564
|
-
if (
|
580
|
+
if (repeat === undefined) return undefined;
|
565
581
|
// Pickup the repeat interesting attributes
|
566
|
-
let repeat = dos.timing.repeat;
|
567
582
|
let count = repeat.count;
|
568
583
|
let countMax = repeat.countMax;
|
569
584
|
// Do nothing if no count, I am not a wizard
|
@@ -869,8 +884,6 @@ function $9b1af2fba509609e$export$9f330b4bf8c0975c({ entry: entry, ...args }) {
|
|
869
884
|
|
870
885
|
|
871
886
|
|
872
|
-
// backends i18next
|
873
|
-
const $8435b8d847fb3eb7$var$localeImport = async (lng, ns)=>import(`./locales/${lng}/${ns}.json`);
|
874
887
|
class $8435b8d847fb3eb7$export$1c191bca55f84a03 {
|
875
888
|
// Set up lib, according provided parameters
|
876
889
|
constructor(args){
|
@@ -933,7 +946,7 @@ class $8435b8d847fb3eb7$export$1c191bca55f84a03 {
|
|
933
946
|
backend: {
|
934
947
|
backends: [
|
935
948
|
(0, $hgUW1$i18nextresourcestobackend)(// have to cast the function to be webpack / builder friendly
|
936
|
-
|
949
|
+
async (lng, ns)=>import(`./locales/${lng}/${ns}.json`))
|
937
950
|
]
|
938
951
|
}
|
939
952
|
});
|
@@ -1020,9 +1033,8 @@ class $8435b8d847fb3eb7$export$1c191bca55f84a03 {
|
|
1020
1033
|
return this.getFields(dos, ...order);
|
1021
1034
|
}
|
1022
1035
|
/**
|
1023
|
-
*
|
1024
|
-
*/
|
1025
|
-
// As we can have concurrent / sequential instructions, we need a generic algorithm to do the job
|
1036
|
+
* Does this array of Dosage objects contains only "sequential" instructions ?
|
1037
|
+
*/ containsOnlySequentialInstructions(dosages) {
|
1026
1038
|
// 1. Collect all sequences number
|
1027
1039
|
let sequencesNumbers = dosages.map((d)=>d.sequence).filter((s)=>s !== undefined);
|
1028
1040
|
// 2. Convert it to a Set
|
@@ -1030,11 +1042,13 @@ class $8435b8d847fb3eb7$export$1c191bca55f84a03 {
|
|
1030
1042
|
// 3. We have a "sequential" situation in two cases
|
1031
1043
|
// A) No sequence number were provided
|
1032
1044
|
// B) All sequence numbers are different
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1045
|
+
return encounteredSequenceNumbers.size === 0 || encounteredSequenceNumbers.size === dosages.length;
|
1046
|
+
}
|
1047
|
+
/**
|
1048
|
+
* Turn this array of Dosage objects into a data structure useful to handle "sequential" and "concurrent" instructions (cf. "sequence" property).
|
1049
|
+
* @returns {Dosage[][]} - A two-dimensional array where each inner array contains Dosage objects belonging to the same sequence numberr.
|
1050
|
+
*/ groupBySequence(dosages) {
|
1051
|
+
// Prepare variables
|
1038
1052
|
let groups = {};
|
1039
1053
|
let sequences = new Set();
|
1040
1054
|
for(let idx = 0; idx < dosages.length; idx++){
|
@@ -1043,23 +1057,39 @@ class $8435b8d847fb3eb7$export$1c191bca55f84a03 {
|
|
1043
1057
|
// Get the sequence number (normally, in real world, it should be present in this case)
|
1044
1058
|
// If no sequence number, assume it is idx + 1
|
1045
1059
|
let sequenceNr = dosage.sequence || idx + 1;
|
1046
|
-
// Generate the text version
|
1047
|
-
let dosageAsText = this.fromDosageToText(dosage);
|
1048
1060
|
// Retrieve of create previous entries for this sequence number
|
1049
1061
|
let localGroup = groups[sequenceNr] || [];
|
1050
1062
|
// Add entry
|
1051
|
-
localGroup.push(
|
1063
|
+
localGroup.push(dosage);
|
1052
1064
|
// Pushback result
|
1053
1065
|
groups[sequenceNr] = localGroup;
|
1054
1066
|
// For reminder of the parsed sequence
|
1055
1067
|
sequences.add(sequenceNr);
|
1056
1068
|
}
|
1057
|
-
//
|
1058
|
-
|
1069
|
+
// By using the Set values, we are sure it is returned in the way Dosages were written
|
1070
|
+
return [
|
1059
1071
|
...sequences.values()
|
1060
1072
|
].map((sequence)=>{
|
1061
1073
|
let concurrentInstructions = groups[sequence];
|
1062
|
-
return
|
1074
|
+
return concurrentInstructions;
|
1075
|
+
});
|
1076
|
+
}
|
1077
|
+
/**
|
1078
|
+
* Turn multiple FHIR Dosage objects into text
|
1079
|
+
*/ fromMultipleDosageToText(dosages) {
|
1080
|
+
// As we can have concurrent / sequential instructions, we need a generic algorithm to do the job
|
1081
|
+
const hasOnlySequentialInstructions = this.containsOnlySequentialInstructions(dosages);
|
1082
|
+
// Sequential instructions
|
1083
|
+
if (hasOnlySequentialInstructions) {
|
1084
|
+
const dosagesAsText = dosages.map((d)=>this.fromDosageToText(d));
|
1085
|
+
return (0, $f475af73bad0ba43$export$826742c1df3eca39)(this.i18nInstance, dosagesAsText, "then");
|
1086
|
+
}
|
1087
|
+
// We have both "sequential" and "concurrent" instructions - time to see what is the configuration
|
1088
|
+
let sortedDosages = this.groupBySequence(dosages);
|
1089
|
+
// Now that data structures are filled, it is a piece of cake to generate the result
|
1090
|
+
let sequentialInstructions = sortedDosages.map((concurrentInstructions)=>{
|
1091
|
+
let concurrentInstructionsAsString = concurrentInstructions.map((dosage)=>this.fromDosageToText(dosage));
|
1092
|
+
return (0, $f475af73bad0ba43$export$826742c1df3eca39)(this.i18nInstance, concurrentInstructionsAsString, "and");
|
1063
1093
|
});
|
1064
1094
|
return (0, $f475af73bad0ba43$export$826742c1df3eca39)(this.i18nInstance, sequentialInstructions, "then");
|
1065
1095
|
}
|