fhir-dosage-utils 1.2.1 → 1.3.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/dist/main.js +166 -146
- package/dist/main.js.map +1 -1
- package/dist/module.js +166 -146
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +35 -19
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
var $8zHUo$i18nextresourcestobackend = require("i18next-resources-to-backend");
|
1
2
|
var $8zHUo$i18next = require("i18next");
|
2
3
|
var $8zHUo$i18nextchainedbackend = require("i18next-chained-backend");
|
3
|
-
var $8zHUo$i18nextresourcestobackend = require("i18next-resources-to-backend");
|
4
4
|
|
5
5
|
|
6
6
|
function $parcel$defineInteropFlag(a) {
|
@@ -18,9 +18,10 @@ function $parcel$interopDefault(a) {
|
|
18
18
|
$parcel$defineInteropFlag(module.exports);
|
19
19
|
|
20
20
|
$parcel$export(module.exports, "default", () => $882b6d93070905b3$export$2e2bcd8739ae039);
|
21
|
+
// Classe(s)
|
21
22
|
|
22
23
|
|
23
|
-
|
24
|
+
// Types
|
24
25
|
function $1c57f108974f2805$export$b1a6aed91fad1636({ quantity: quantity }) {
|
25
26
|
if (quantity.code !== undefined) return quantity.code;
|
26
27
|
if (quantity.unit !== undefined) return quantity.unit;
|
@@ -50,6 +51,133 @@ function $34ebae8ac5b52fcd$export$30c337e25ab8e95b({ extensions: extensions }) {
|
|
50
51
|
}
|
51
52
|
|
52
53
|
|
54
|
+
const $99ea7fa882fd33ad$export$38cd8db2db178f58 = {
|
55
|
+
language: "en",
|
56
|
+
fromFHIRQuantityUnitToString: (0, $1c57f108974f2805$export$b1a6aed91fad1636),
|
57
|
+
fromCodeableConceptToString: (0, $a6c648898dc8c3b6$export$f478f96b98da13a4),
|
58
|
+
fromExtensionsToString: (0, $34ebae8ac5b52fcd$export$30c337e25ab8e95b),
|
59
|
+
displayOrder: [
|
60
|
+
"method",
|
61
|
+
"doseQuantity",
|
62
|
+
"doseRange",
|
63
|
+
"rateRatio",
|
64
|
+
"rateQuantity",
|
65
|
+
"rateRange",
|
66
|
+
"durationDurationMax",
|
67
|
+
"frequencyFrequencyMaxPeriodPeriodMax",
|
68
|
+
"offsetWhen",
|
69
|
+
"dayOfWeek",
|
70
|
+
"timeOfDay",
|
71
|
+
"route",
|
72
|
+
"site",
|
73
|
+
"asNeeded",
|
74
|
+
"boundsDuration",
|
75
|
+
"boundsPeriod",
|
76
|
+
"boundsRange",
|
77
|
+
"countCountMax",
|
78
|
+
"event",
|
79
|
+
"code",
|
80
|
+
"maxDosePerPeriod",
|
81
|
+
"maxDosePerAdministration",
|
82
|
+
"maxDosePerLifetime",
|
83
|
+
"additionalInstruction",
|
84
|
+
"patientInstruction"
|
85
|
+
],
|
86
|
+
displaySeparator: " - ",
|
87
|
+
dateTimeFormatOptions: {}
|
88
|
+
};
|
89
|
+
|
90
|
+
|
91
|
+
class $868b4eaa4f62b9f7$export$f807d9a22ff8372d {
|
92
|
+
// Set up lib, according provided parameters
|
93
|
+
constructor(userConfig, i18nConfig){
|
94
|
+
// User config
|
95
|
+
this.config = {
|
96
|
+
// default attributes
|
97
|
+
...(0, $99ea7fa882fd33ad$export$38cd8db2db178f58),
|
98
|
+
// attributes set by user
|
99
|
+
...userConfig
|
100
|
+
};
|
101
|
+
// I18N config
|
102
|
+
this.i18nConfig = {
|
103
|
+
// default attributes
|
104
|
+
fallbackLng: "en",
|
105
|
+
lng: this.config.language,
|
106
|
+
ns: [
|
107
|
+
"common",
|
108
|
+
"daysOfWeek",
|
109
|
+
"eventTiming",
|
110
|
+
"unitsOfTime"
|
111
|
+
],
|
112
|
+
defaultNS: "common",
|
113
|
+
// attributes set by user
|
114
|
+
...i18nConfig
|
115
|
+
};
|
116
|
+
this.i18nInstance = (0, ($parcel$interopDefault($8zHUo$i18next))).createInstance();
|
117
|
+
}
|
118
|
+
/**
|
119
|
+
* To init i18next properly according requested criteria
|
120
|
+
*/ async init() {
|
121
|
+
// You should wait for init to complete (wait for the callback or promise resolution)
|
122
|
+
// before using the t function!
|
123
|
+
return await this.i18nInstance.use((0, ($parcel$interopDefault($8zHUo$i18nextchainedbackend)))).init(this.i18nConfig);
|
124
|
+
}
|
125
|
+
/**
|
126
|
+
* To change language
|
127
|
+
*/ async changeLanguage(lng) {
|
128
|
+
this.config = {
|
129
|
+
...this.config,
|
130
|
+
language: lng
|
131
|
+
};
|
132
|
+
return this.i18nInstance.changeLanguage(lng);
|
133
|
+
}
|
134
|
+
/**
|
135
|
+
* Get current language
|
136
|
+
*/ getLanguage() {
|
137
|
+
return this.config.language;
|
138
|
+
}
|
139
|
+
/**
|
140
|
+
* To change display order
|
141
|
+
*/ changeDisplayOrder(order) {
|
142
|
+
this.config = {
|
143
|
+
...this.config,
|
144
|
+
displayOrder: order
|
145
|
+
};
|
146
|
+
}
|
147
|
+
/**
|
148
|
+
* Get display order
|
149
|
+
*/ getDisplayOrder() {
|
150
|
+
return this.config.displayOrder;
|
151
|
+
}
|
152
|
+
/**
|
153
|
+
* Get display separator
|
154
|
+
*/ getDisplaySeparator() {
|
155
|
+
return this.config.displaySeparator;
|
156
|
+
}
|
157
|
+
/**
|
158
|
+
* Set display separator
|
159
|
+
*/ changeDisplaySeparator(sep) {
|
160
|
+
this.config = {
|
161
|
+
...this.config,
|
162
|
+
displaySeparator: sep
|
163
|
+
};
|
164
|
+
}
|
165
|
+
/**
|
166
|
+
* Get date time format options
|
167
|
+
*/ getDateTimeFormatOptions() {
|
168
|
+
return this.config.dateTimeFormatOptions;
|
169
|
+
}
|
170
|
+
/**
|
171
|
+
* Set date time format options
|
172
|
+
*/ changeDateTimeFormatOptions(opts) {
|
173
|
+
this.config = {
|
174
|
+
...this.config,
|
175
|
+
dateTimeFormatOptions: opts
|
176
|
+
};
|
177
|
+
}
|
178
|
+
}
|
179
|
+
|
180
|
+
|
53
181
|
// translators
|
54
182
|
// To avoid circular dependancies issue, let's have a single place for exports and imports
|
55
183
|
// Types
|
@@ -210,8 +338,10 @@ function $7895e9944cc835ce$export$fdc6e9cbd31555fb({ ratio: ratio, config: confi
|
|
210
338
|
// quantity
|
211
339
|
let quantityNumerator = numerator?.value;
|
212
340
|
let quantityDenominator = denominator?.value;
|
213
|
-
// Collect
|
341
|
+
// Collect results
|
214
342
|
const parts = [];
|
343
|
+
let noUnits = numeratorUnit === undefined && denominatorUnit === undefined;
|
344
|
+
let separator = noUnits ? "" : " ";
|
215
345
|
// Deal with numerator first
|
216
346
|
if (quantityNumerator !== undefined) {
|
217
347
|
let technicalKey = numeratorUnit !== undefined ? "withUnit" : "withoutUnit";
|
@@ -232,7 +362,7 @@ function $7895e9944cc835ce$export$fdc6e9cbd31555fb({ ratio: ratio, config: confi
|
|
232
362
|
}
|
233
363
|
// Concatenate the result
|
234
364
|
if (parts.length === 0) return undefined;
|
235
|
-
else return parts.join(
|
365
|
+
else return parts.join(separator);
|
236
366
|
}
|
237
367
|
|
238
368
|
|
@@ -900,155 +1030,24 @@ function $2c21ace90ecdbde6$export$9f330b4bf8c0975c({ entry: entry, ...args }) {
|
|
900
1030
|
|
901
1031
|
|
902
1032
|
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
//
|
908
|
-
|
909
|
-
|
910
|
-
fromCodeableConceptToString: (0, $a6c648898dc8c3b6$export$f478f96b98da13a4),
|
911
|
-
fromExtensionsToString: (0, $34ebae8ac5b52fcd$export$30c337e25ab8e95b),
|
912
|
-
displayOrder: [
|
913
|
-
"method",
|
914
|
-
"doseQuantity",
|
915
|
-
"doseRange",
|
916
|
-
"rateRatio",
|
917
|
-
"rateQuantity",
|
918
|
-
"rateRange",
|
919
|
-
"durationDurationMax",
|
920
|
-
"frequencyFrequencyMaxPeriodPeriodMax",
|
921
|
-
"offsetWhen",
|
922
|
-
"dayOfWeek",
|
923
|
-
"timeOfDay",
|
924
|
-
"route",
|
925
|
-
"site",
|
926
|
-
"asNeeded",
|
927
|
-
"boundsDuration",
|
928
|
-
"boundsPeriod",
|
929
|
-
"boundsRange",
|
930
|
-
"countCountMax",
|
931
|
-
"event",
|
932
|
-
"code",
|
933
|
-
"maxDosePerPeriod",
|
934
|
-
"maxDosePerAdministration",
|
935
|
-
"maxDosePerLifetime",
|
936
|
-
"additionalInstruction",
|
937
|
-
"patientInstruction"
|
938
|
-
],
|
939
|
-
displaySeparator: " - ",
|
940
|
-
dateTimeFormatOptions: {},
|
941
|
-
// attributes set by user
|
942
|
-
...args
|
943
|
-
};
|
944
|
-
this.i18nInstance = (0, ($parcel$interopDefault($8zHUo$i18next))).createInstance();
|
945
|
-
}
|
946
|
-
/**
|
947
|
-
* To init i18next properly according requested criteria
|
948
|
-
*/ async init() {
|
949
|
-
// You should wait for init to complete (wait for the callback or promise resolution)
|
950
|
-
// before using the t function!
|
951
|
-
return await this.i18nInstance.use((0, ($parcel$interopDefault($8zHUo$i18nextchainedbackend)))).init({
|
952
|
-
//debug: true,
|
953
|
-
fallbackLng: "en",
|
954
|
-
lng: this.config.language,
|
955
|
-
ns: [
|
956
|
-
"common",
|
957
|
-
"daysOfWeek",
|
958
|
-
"eventTiming",
|
959
|
-
"unitsOfTime"
|
960
|
-
],
|
961
|
-
defaultNS: "common",
|
962
|
-
backend: {
|
963
|
-
backends: [
|
964
|
-
(0, ($parcel$interopDefault($8zHUo$i18nextresourcestobackend)))(// have to cast the function to be webpack / builder friendly
|
965
|
-
async (lng, ns)=>import(`./locales/${lng}/${ns}.json`))
|
966
|
-
]
|
967
|
-
}
|
968
|
-
});
|
1033
|
+
|
1034
|
+
const $74b0cf9d3dbd5b46$var$defaultI18NConfig = {
|
1035
|
+
backend: {
|
1036
|
+
backends: [
|
1037
|
+
(0, ($parcel$interopDefault($8zHUo$i18nextresourcestobackend)))(// have to cast the function to be webpack / builder friendly
|
1038
|
+
async (lng, ns)=>import(`./locales/${lng}/${ns}.json`))
|
1039
|
+
]
|
969
1040
|
}
|
1041
|
+
};
|
1042
|
+
class $74b0cf9d3dbd5b46$export$1c191bca55f84a03 extends (0, $868b4eaa4f62b9f7$export$f807d9a22ff8372d) {
|
970
1043
|
/**
|
971
1044
|
* Factory to create a fine-tuned instance of the utility class
|
972
|
-
*/ static async build(
|
973
|
-
const instance = new $74b0cf9d3dbd5b46$export$1c191bca55f84a03(
|
1045
|
+
*/ static async build(userConfig, i18nConfig = $74b0cf9d3dbd5b46$var$defaultI18NConfig) {
|
1046
|
+
const instance = new $74b0cf9d3dbd5b46$export$1c191bca55f84a03(userConfig, i18nConfig);
|
974
1047
|
await instance.init();
|
975
1048
|
return instance;
|
976
1049
|
}
|
977
1050
|
/**
|
978
|
-
* To change language
|
979
|
-
*/ async changeLanguage(lng) {
|
980
|
-
this.config = {
|
981
|
-
...this.config,
|
982
|
-
language: lng
|
983
|
-
};
|
984
|
-
return this.i18nInstance.changeLanguage(lng);
|
985
|
-
}
|
986
|
-
/**
|
987
|
-
* Get current language
|
988
|
-
*/ getLanguage() {
|
989
|
-
return this.config.language;
|
990
|
-
}
|
991
|
-
/**
|
992
|
-
* To change display order
|
993
|
-
*/ changeDisplayOrder(order) {
|
994
|
-
this.config = {
|
995
|
-
...this.config,
|
996
|
-
displayOrder: order
|
997
|
-
};
|
998
|
-
}
|
999
|
-
/**
|
1000
|
-
* Get display order
|
1001
|
-
*/ getDisplayOrder() {
|
1002
|
-
return this.config.displayOrder;
|
1003
|
-
}
|
1004
|
-
/**
|
1005
|
-
* Get display separator
|
1006
|
-
*/ getDisplaySeparator() {
|
1007
|
-
return this.config.displaySeparator;
|
1008
|
-
}
|
1009
|
-
/**
|
1010
|
-
* Set display separator
|
1011
|
-
*/ changeDisplaySeparator(sep) {
|
1012
|
-
this.config = {
|
1013
|
-
...this.config,
|
1014
|
-
displaySeparator: sep
|
1015
|
-
};
|
1016
|
-
}
|
1017
|
-
/**
|
1018
|
-
* Get date time format options
|
1019
|
-
*/ getDateTimeFormatOptions() {
|
1020
|
-
return this.config.dateTimeFormatOptions;
|
1021
|
-
}
|
1022
|
-
/**
|
1023
|
-
* Set date time format options
|
1024
|
-
*/ changeDateTimeFormatOptions(opts) {
|
1025
|
-
this.config = {
|
1026
|
-
...this.config,
|
1027
|
-
dateTimeFormatOptions: opts
|
1028
|
-
};
|
1029
|
-
}
|
1030
|
-
/**
|
1031
|
-
* From a single dosage, extract specific field(s) requested by user.
|
1032
|
-
* Some use cases could request to split part of the object for given needs (quantity and timing separately)
|
1033
|
-
*/ getFields(dos, ...order) {
|
1034
|
-
// iterate on each key and generate a string from each part
|
1035
|
-
let parts = order.map((entry)=>(0, $2c21ace90ecdbde6$export$9f330b4bf8c0975c)({
|
1036
|
-
config: this.config,
|
1037
|
-
dos: dos,
|
1038
|
-
entry: entry,
|
1039
|
-
i18next: this.i18nInstance
|
1040
|
-
})).filter((s)=>s !== undefined);
|
1041
|
-
// Join each part with a separator
|
1042
|
-
return parts.join(this.config.displaySeparator);
|
1043
|
-
}
|
1044
|
-
/**
|
1045
|
-
* Turn a FHIR Dosage object into text
|
1046
|
-
*/ fromDosageToText(dos) {
|
1047
|
-
// iterate on each key and generate a string from each part
|
1048
|
-
let order = this.config.displayOrder;
|
1049
|
-
return this.getFields(dos, ...order);
|
1050
|
-
}
|
1051
|
-
/**
|
1052
1051
|
* Does this array of Dosage objects contains only "sequential" instructions ?
|
1053
1052
|
*/ containsOnlySequentialInstructions(dosages) {
|
1054
1053
|
// 1. Collect all sequences number
|
@@ -1091,6 +1090,27 @@ class $74b0cf9d3dbd5b46$export$1c191bca55f84a03 {
|
|
1091
1090
|
});
|
1092
1091
|
}
|
1093
1092
|
/**
|
1093
|
+
* From a single dosage, extract specific field(s) requested by user.
|
1094
|
+
* Some use cases could request to split part of the object for given needs (quantity and timing separately)
|
1095
|
+
*/ getFields(dos, ...order) {
|
1096
|
+
// iterate on each key and generate a string from each part
|
1097
|
+
let parts = order.map((entry)=>(0, $2c21ace90ecdbde6$export$9f330b4bf8c0975c)({
|
1098
|
+
config: this.config,
|
1099
|
+
dos: dos,
|
1100
|
+
entry: entry,
|
1101
|
+
i18next: this.i18nInstance
|
1102
|
+
})).filter((s)=>s !== undefined);
|
1103
|
+
// Join each part with a separator
|
1104
|
+
return parts.join(this.config.displaySeparator);
|
1105
|
+
}
|
1106
|
+
/**
|
1107
|
+
* Turn a FHIR Dosage object into text
|
1108
|
+
*/ fromDosageToText(dos) {
|
1109
|
+
// iterate on each key and generate a string from each part
|
1110
|
+
let order = this.config.displayOrder;
|
1111
|
+
return this.getFields(dos, ...order);
|
1112
|
+
}
|
1113
|
+
/**
|
1094
1114
|
* Turn multiple FHIR Dosage objects into text
|
1095
1115
|
*/ fromMultipleDosageToText(dosages) {
|
1096
1116
|
// As we can have concurrent / sequential instructions, we need a generic algorithm to do the job
|