fhir-dosage-utils 1.2.1 → 1.3.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/module.js CHANGED
@@ -1,10 +1,11 @@
1
+ import $hgUW1$i18nextresourcestobackend from "i18next-resources-to-backend";
1
2
  import $hgUW1$i18next from "i18next";
2
3
  import $hgUW1$i18nextchainedbackend from "i18next-chained-backend";
3
- import $hgUW1$i18nextresourcestobackend from "i18next-resources-to-backend";
4
-
5
4
 
5
+ // Classe(s)
6
6
 
7
7
 
8
+ // Types
8
9
  function $a620268c8b5a46fd$export$b1a6aed91fad1636({ quantity: quantity }) {
9
10
  if (quantity.code !== undefined) return quantity.code;
10
11
  if (quantity.unit !== undefined) return quantity.unit;
@@ -34,6 +35,133 @@ function $a31aaee21175037d$export$30c337e25ab8e95b({ extensions: extensions }) {
34
35
  }
35
36
 
36
37
 
38
+ const $c03f5f20816d8d50$export$38cd8db2db178f58 = {
39
+ language: "en",
40
+ fromFHIRQuantityUnitToString: (0, $a620268c8b5a46fd$export$b1a6aed91fad1636),
41
+ fromCodeableConceptToString: (0, $f2878500cc217687$export$f478f96b98da13a4),
42
+ fromExtensionsToString: (0, $a31aaee21175037d$export$30c337e25ab8e95b),
43
+ displayOrder: [
44
+ "method",
45
+ "doseQuantity",
46
+ "doseRange",
47
+ "rateRatio",
48
+ "rateQuantity",
49
+ "rateRange",
50
+ "durationDurationMax",
51
+ "frequencyFrequencyMaxPeriodPeriodMax",
52
+ "offsetWhen",
53
+ "dayOfWeek",
54
+ "timeOfDay",
55
+ "route",
56
+ "site",
57
+ "asNeeded",
58
+ "boundsDuration",
59
+ "boundsPeriod",
60
+ "boundsRange",
61
+ "countCountMax",
62
+ "event",
63
+ "code",
64
+ "maxDosePerPeriod",
65
+ "maxDosePerAdministration",
66
+ "maxDosePerLifetime",
67
+ "additionalInstruction",
68
+ "patientInstruction"
69
+ ],
70
+ displaySeparator: " - ",
71
+ dateTimeFormatOptions: {}
72
+ };
73
+
74
+
75
+ class $2422495f2648c580$export$f807d9a22ff8372d {
76
+ // Set up lib, according provided parameters
77
+ constructor(userConfig, i18nConfig){
78
+ // User config
79
+ this.config = {
80
+ // default attributes
81
+ ...(0, $c03f5f20816d8d50$export$38cd8db2db178f58),
82
+ // attributes set by user
83
+ ...userConfig
84
+ };
85
+ // I18N config
86
+ this.i18nConfig = {
87
+ // default attributes
88
+ fallbackLng: "en",
89
+ lng: this.config.language,
90
+ ns: [
91
+ "common",
92
+ "daysOfWeek",
93
+ "eventTiming",
94
+ "unitsOfTime"
95
+ ],
96
+ defaultNS: "common",
97
+ // attributes set by user
98
+ ...i18nConfig
99
+ };
100
+ this.i18nInstance = (0, $hgUW1$i18next).createInstance();
101
+ }
102
+ /**
103
+ * To init i18next properly according requested criteria
104
+ */ async init() {
105
+ // You should wait for init to complete (wait for the callback or promise resolution)
106
+ // before using the t function!
107
+ return await this.i18nInstance.use((0, $hgUW1$i18nextchainedbackend)).init(this.i18nConfig);
108
+ }
109
+ /**
110
+ * To change language
111
+ */ async changeLanguage(lng) {
112
+ this.config = {
113
+ ...this.config,
114
+ language: lng
115
+ };
116
+ return this.i18nInstance.changeLanguage(lng);
117
+ }
118
+ /**
119
+ * Get current language
120
+ */ getLanguage() {
121
+ return this.config.language;
122
+ }
123
+ /**
124
+ * To change display order
125
+ */ changeDisplayOrder(order) {
126
+ this.config = {
127
+ ...this.config,
128
+ displayOrder: order
129
+ };
130
+ }
131
+ /**
132
+ * Get display order
133
+ */ getDisplayOrder() {
134
+ return this.config.displayOrder;
135
+ }
136
+ /**
137
+ * Get display separator
138
+ */ getDisplaySeparator() {
139
+ return this.config.displaySeparator;
140
+ }
141
+ /**
142
+ * Set display separator
143
+ */ changeDisplaySeparator(sep) {
144
+ this.config = {
145
+ ...this.config,
146
+ displaySeparator: sep
147
+ };
148
+ }
149
+ /**
150
+ * Get date time format options
151
+ */ getDateTimeFormatOptions() {
152
+ return this.config.dateTimeFormatOptions;
153
+ }
154
+ /**
155
+ * Set date time format options
156
+ */ changeDateTimeFormatOptions(opts) {
157
+ this.config = {
158
+ ...this.config,
159
+ dateTimeFormatOptions: opts
160
+ };
161
+ }
162
+ }
163
+
164
+
37
165
  // translators
38
166
  // To avoid circular dependancies issue, let's have a single place for exports and imports
39
167
  // Types
@@ -884,155 +1012,24 @@ function $9b1af2fba509609e$export$9f330b4bf8c0975c({ entry: entry, ...args }) {
884
1012
 
885
1013
 
886
1014
 
887
- class $8435b8d847fb3eb7$export$1c191bca55f84a03 {
888
- // Set up lib, according provided parameters
889
- constructor(args){
890
- this.config = {
891
- // default attributes
892
- language: "en",
893
- fromFHIRQuantityUnitToString: (0, $a620268c8b5a46fd$export$b1a6aed91fad1636),
894
- fromCodeableConceptToString: (0, $f2878500cc217687$export$f478f96b98da13a4),
895
- fromExtensionsToString: (0, $a31aaee21175037d$export$30c337e25ab8e95b),
896
- displayOrder: [
897
- "method",
898
- "doseQuantity",
899
- "doseRange",
900
- "rateRatio",
901
- "rateQuantity",
902
- "rateRange",
903
- "durationDurationMax",
904
- "frequencyFrequencyMaxPeriodPeriodMax",
905
- "offsetWhen",
906
- "dayOfWeek",
907
- "timeOfDay",
908
- "route",
909
- "site",
910
- "asNeeded",
911
- "boundsDuration",
912
- "boundsPeriod",
913
- "boundsRange",
914
- "countCountMax",
915
- "event",
916
- "code",
917
- "maxDosePerPeriod",
918
- "maxDosePerAdministration",
919
- "maxDosePerLifetime",
920
- "additionalInstruction",
921
- "patientInstruction"
922
- ],
923
- displaySeparator: " - ",
924
- dateTimeFormatOptions: {},
925
- // attributes set by user
926
- ...args
927
- };
928
- this.i18nInstance = (0, $hgUW1$i18next).createInstance();
929
- }
930
- /**
931
- * To init i18next properly according requested criteria
932
- */ async init() {
933
- // You should wait for init to complete (wait for the callback or promise resolution)
934
- // before using the t function!
935
- return await this.i18nInstance.use((0, $hgUW1$i18nextchainedbackend)).init({
936
- //debug: true,
937
- fallbackLng: "en",
938
- lng: this.config.language,
939
- ns: [
940
- "common",
941
- "daysOfWeek",
942
- "eventTiming",
943
- "unitsOfTime"
944
- ],
945
- defaultNS: "common",
946
- backend: {
947
- backends: [
948
- (0, $hgUW1$i18nextresourcestobackend)(// have to cast the function to be webpack / builder friendly
949
- async (lng, ns)=>import(`./locales/${lng}/${ns}.json`))
950
- ]
951
- }
952
- });
1015
+
1016
+ const $8435b8d847fb3eb7$var$defaultI18NConfig = {
1017
+ backend: {
1018
+ backends: [
1019
+ (0, $hgUW1$i18nextresourcestobackend)(// have to cast the function to be webpack / builder friendly
1020
+ async (lng, ns)=>import(`./locales/${lng}/${ns}.json`))
1021
+ ]
953
1022
  }
1023
+ };
1024
+ class $8435b8d847fb3eb7$export$1c191bca55f84a03 extends (0, $2422495f2648c580$export$f807d9a22ff8372d) {
954
1025
  /**
955
1026
  * Factory to create a fine-tuned instance of the utility class
956
- */ static async build(args) {
957
- const instance = new $8435b8d847fb3eb7$export$1c191bca55f84a03(args);
1027
+ */ static async build(userConfig, i18nConfig = $8435b8d847fb3eb7$var$defaultI18NConfig) {
1028
+ const instance = new $8435b8d847fb3eb7$export$1c191bca55f84a03(userConfig, i18nConfig);
958
1029
  await instance.init();
959
1030
  return instance;
960
1031
  }
961
1032
  /**
962
- * To change language
963
- */ async changeLanguage(lng) {
964
- this.config = {
965
- ...this.config,
966
- language: lng
967
- };
968
- return this.i18nInstance.changeLanguage(lng);
969
- }
970
- /**
971
- * Get current language
972
- */ getLanguage() {
973
- return this.config.language;
974
- }
975
- /**
976
- * To change display order
977
- */ changeDisplayOrder(order) {
978
- this.config = {
979
- ...this.config,
980
- displayOrder: order
981
- };
982
- }
983
- /**
984
- * Get display order
985
- */ getDisplayOrder() {
986
- return this.config.displayOrder;
987
- }
988
- /**
989
- * Get display separator
990
- */ getDisplaySeparator() {
991
- return this.config.displaySeparator;
992
- }
993
- /**
994
- * Set display separator
995
- */ changeDisplaySeparator(sep) {
996
- this.config = {
997
- ...this.config,
998
- displaySeparator: sep
999
- };
1000
- }
1001
- /**
1002
- * Get date time format options
1003
- */ getDateTimeFormatOptions() {
1004
- return this.config.dateTimeFormatOptions;
1005
- }
1006
- /**
1007
- * Set date time format options
1008
- */ changeDateTimeFormatOptions(opts) {
1009
- this.config = {
1010
- ...this.config,
1011
- dateTimeFormatOptions: opts
1012
- };
1013
- }
1014
- /**
1015
- * From a single dosage, extract specific field(s) requested by user.
1016
- * Some use cases could request to split part of the object for given needs (quantity and timing separately)
1017
- */ getFields(dos, ...order) {
1018
- // iterate on each key and generate a string from each part
1019
- let parts = order.map((entry)=>(0, $9b1af2fba509609e$export$9f330b4bf8c0975c)({
1020
- config: this.config,
1021
- dos: dos,
1022
- entry: entry,
1023
- i18next: this.i18nInstance
1024
- })).filter((s)=>s !== undefined);
1025
- // Join each part with a separator
1026
- return parts.join(this.config.displaySeparator);
1027
- }
1028
- /**
1029
- * Turn a FHIR Dosage object into text
1030
- */ fromDosageToText(dos) {
1031
- // iterate on each key and generate a string from each part
1032
- let order = this.config.displayOrder;
1033
- return this.getFields(dos, ...order);
1034
- }
1035
- /**
1036
1033
  * Does this array of Dosage objects contains only "sequential" instructions ?
1037
1034
  */ containsOnlySequentialInstructions(dosages) {
1038
1035
  // 1. Collect all sequences number
@@ -1075,6 +1072,27 @@ class $8435b8d847fb3eb7$export$1c191bca55f84a03 {
1075
1072
  });
1076
1073
  }
1077
1074
  /**
1075
+ * From a single dosage, extract specific field(s) requested by user.
1076
+ * Some use cases could request to split part of the object for given needs (quantity and timing separately)
1077
+ */ getFields(dos, ...order) {
1078
+ // iterate on each key and generate a string from each part
1079
+ let parts = order.map((entry)=>(0, $9b1af2fba509609e$export$9f330b4bf8c0975c)({
1080
+ config: this.config,
1081
+ dos: dos,
1082
+ entry: entry,
1083
+ i18next: this.i18nInstance
1084
+ })).filter((s)=>s !== undefined);
1085
+ // Join each part with a separator
1086
+ return parts.join(this.config.displaySeparator);
1087
+ }
1088
+ /**
1089
+ * Turn a FHIR Dosage object into text
1090
+ */ fromDosageToText(dos) {
1091
+ // iterate on each key and generate a string from each part
1092
+ let order = this.config.displayOrder;
1093
+ return this.getFields(dos, ...order);
1094
+ }
1095
+ /**
1078
1096
  * Turn multiple FHIR Dosage objects into text
1079
1097
  */ fromMultipleDosageToText(dosages) {
1080
1098
  // As we can have concurrent / sequential instructions, we need a generic algorithm to do the job