fhir-dosage-utils 1.10.4 → 2.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/README.md CHANGED
@@ -31,3 +31,7 @@ Special thanks to [NHS England](https://digital.nhs.uk/), the author of `Impleme
31
31
  <a href="https://github.com/jy95/fhir-dosage-utils/graphs/contributors">
32
32
  <img src="https://contrib.rocks/image?repo=jy95/fhir-dosage-utils" />
33
33
  </a>
34
+
35
+ ## Star History
36
+
37
+ [![Star History Chart](https://api.star-history.com/svg?repos=jy95/fhir-dosage-utils&type=Date)](https://star-history.com/#jy95/fhir-dosage-utils&Date)
package/dist/main.js CHANGED
@@ -1,12 +1,8 @@
1
- var $8zHUo$i18nextresourcestobackend = require("i18next-resources-to-backend");
2
1
  var $8zHUo$i18next = require("i18next");
3
2
  var $8zHUo$i18nextchainedbackend = require("i18next-chained-backend");
3
+ var $8zHUo$i18nextresourcestobackend = require("i18next-resources-to-backend");
4
4
 
5
5
 
6
- function $parcel$defineInteropFlag(a) {
7
- Object.defineProperty(a, '__esModule', {value: true, configurable: true});
8
- }
9
-
10
6
  function $parcel$export(e, n, v, s) {
11
7
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
12
8
  }
@@ -15,9 +11,9 @@ function $parcel$interopDefault(a) {
15
11
  return a && a.__esModule ? a.default : a;
16
12
  }
17
13
 
18
- $parcel$defineInteropFlag(module.exports);
14
+ $parcel$export(module.exports, "FhirDosageUtils", () => $74b0cf9d3dbd5b46$export$1c191bca55f84a03);
15
+ // Export utility class
19
16
 
20
- $parcel$export(module.exports, "default", () => $882b6d93070905b3$export$2e2bcd8739ae039);
21
17
 
22
18
 
23
19
  function $3d60081b7152576d$export$e7321bf46d18757f(val) {
@@ -57,13 +53,11 @@ function $a6c648898dc8c3b6$export$f478f96b98da13a4({ code: code }) {
57
53
 
58
54
  function $34ebae8ac5b52fcd$export$30c337e25ab8e95b({ extensions: extensions }) {
59
55
  if ((0, $7642ff4865ae4b0f$export$d9ff4a623e416a11)(extensions)) return undefined;
60
- // KIS implementation : print it as provided, without doing anything
61
- // Extensions have so many cases btw, that having a basic function does the trick
62
56
  return extensions.map((extension)=>JSON.stringify(extension)).join(" ");
63
57
  }
64
58
 
65
59
 
66
- const $99ea7fa882fd33ad$export$38cd8db2db178f58 = {
60
+ const $4a853aea29761dad$export$38cd8db2db178f58 = {
67
61
  language: "en",
68
62
  fromFHIRQuantityUnitToString: (0, $1c57f108974f2805$export$b1a6aed91fad1636),
69
63
  fromCodeableConceptToString: (0, $a6c648898dc8c3b6$export$f478f96b98da13a4),
@@ -96,90 +90,38 @@ const $99ea7fa882fd33ad$export$38cd8db2db178f58 = {
96
90
  "patientInstruction"
97
91
  ],
98
92
  displaySeparator: " - ",
99
- dateTimeFormatOptions: {}
93
+ dateTimeFormatOptions: {},
94
+ i18nConfig: {
95
+ backend: {
96
+ backends: [
97
+ (0, ($parcel$interopDefault($8zHUo$i18nextresourcestobackend)))(async (lng, ns)=>import(`./locales/${lng}/${ns}.json`))
98
+ ]
99
+ }
100
+ }
100
101
  };
101
102
 
102
103
 
103
- class $868b4eaa4f62b9f7$export$f807d9a22ff8372d {
104
- constructor(userConfig, i18nConfig){
105
- this.config = {
106
- ...(0, $99ea7fa882fd33ad$export$38cd8db2db178f58),
107
- ...userConfig
108
- };
109
- this.i18nConfig = {
110
- fallbackLng: "en",
111
- lng: this.config.language,
112
- ns: [
113
- "common",
114
- "daysOfWeek",
115
- "eventTiming",
116
- "unitsOfTime",
117
- "quantityComparator"
118
- ],
119
- defaultNS: "common",
120
- ...i18nConfig
121
- };
122
- this.i18nInstance = (0, ($parcel$interopDefault($8zHUo$i18next))).createInstance();
123
- }
124
- /**
125
- * To init i18next properly according requested criteria
126
- */ async init() {
127
- // You should wait for init to complete (wait for the callback or promise resolution)
128
- // before using the t function!
129
- return await this.i18nInstance.use((0, ($parcel$interopDefault($8zHUo$i18nextchainedbackend)))).init(this.i18nConfig);
130
- }
131
- /**
132
- * To change language
133
- */ async changeLanguage(lng) {
134
- this.config = {
135
- ...this.config,
136
- language: lng
137
- };
138
- return this.i18nInstance.changeLanguage(lng);
139
- }
140
- /**
141
- * Get current language
142
- */ getLanguage() {
143
- return this.config.language;
144
- }
145
- /**
146
- * To change display order
147
- */ changeDisplayOrder(order) {
148
- this.config = {
149
- ...this.config,
150
- displayOrder: order
151
- };
152
- }
153
- /**
154
- * Get display order
155
- */ getDisplayOrder() {
156
- return this.config.displayOrder;
157
- }
158
- /**
159
- * Get display separator
160
- */ getDisplaySeparator() {
161
- return this.config.displaySeparator;
162
- }
163
- /**
164
- * Set display separator
165
- */ changeDisplaySeparator(sep) {
166
- this.config = {
167
- ...this.config,
168
- displaySeparator: sep
169
- };
170
- }
171
- /**
172
- * Get date time format options
173
- */ getDateTimeFormatOptions() {
174
- return this.config.dateTimeFormatOptions;
104
+
105
+ class $4f322cc1dbc51a0e$export$d2ca453b913dcdea {
106
+ containsOnlySequentialInstructions(dosages) {
107
+ let sequencesNumbers = dosages.map((d)=>d.sequence).filter((0, $3d60081b7152576d$export$e7321bf46d18757f));
108
+ let encounteredSequenceNumbers = new Set(sequencesNumbers);
109
+ return [
110
+ 0,
111
+ dosages.length
112
+ ].includes(encounteredSequenceNumbers.size);
175
113
  }
176
- /**
177
- * Set date time format options
178
- */ changeDateTimeFormatOptions(opts) {
179
- this.config = {
180
- ...this.config,
181
- dateTimeFormatOptions: opts
182
- };
114
+ groupBySequence(dosages) {
115
+ let sequences = new Set();
116
+ let sequencesMap = new Map();
117
+ for (let dosage of dosages){
118
+ let sequenceNr = dosage.sequence;
119
+ let localGroup = sequencesMap.get(sequenceNr) ?? [];
120
+ localGroup.push(dosage);
121
+ sequencesMap.set(sequenceNr, localGroup);
122
+ sequences.add(sequenceNr);
123
+ }
124
+ return Array.from(sequences, (sequence)=>sequencesMap.get(sequence));
183
125
  }
184
126
  }
185
127
 
@@ -187,7 +129,6 @@ class $868b4eaa4f62b9f7$export$f807d9a22ff8372d {
187
129
 
188
130
  function $5461d5c8b4bc074f$export$76d408d587da5203(dos, key) {
189
131
  if (!(0, $3d60081b7152576d$export$e7321bf46d18757f)(dos.doseAndRate)) return undefined;
190
- // Find the first entry that match criteria
191
132
  let doseAndRate = dos.doseAndRate.find((s)=>(0, $3d60081b7152576d$export$e7321bf46d18757f)(s[key]));
192
133
  if (!(0, $3d60081b7152576d$export$e7321bf46d18757f)(doseAndRate)) return undefined;
193
134
  return doseAndRate[key];
@@ -517,9 +458,9 @@ function $7a065f861a4b61f2$var$transformOffset(i18next, offset) {
517
458
  "h",
518
459
  "min"
519
460
  ];
520
- return order.map((unit)=>time[unit] > 0 ? i18next.t(`unitsOfTime:withCount.${unit}`, {
461
+ return order.filter((unit)=>time[unit] > 0).map((unit)=>i18next.t(`unitsOfTime:withCount.${unit}`, {
521
462
  count: time[unit]
522
- }) : undefined).filter((0, $3d60081b7152576d$export$e7321bf46d18757f)).join(" ");
463
+ })).join(" ");
523
464
  }
524
465
  function $7a065f861a4b61f2$var$transformWhen(i18next, when) {
525
466
  if ((0, $7642ff4865ae4b0f$export$d9ff4a623e416a11)(when)) return undefined;
@@ -847,20 +788,16 @@ function $39ffdeadc450f558$export$346b11a8cb220f02({ dos: dos, config: config, i
847
788
  if (!(0, $3d60081b7152576d$export$e7321bf46d18757f)(dos.maxDosePerPeriod)) return undefined;
848
789
  const maxDosePerPeriod = dos.maxDosePerPeriod;
849
790
  // In R4, it was a single object / In R5, it is an array
850
- // So better to have a generic approach
851
791
  const values = Array.isArray(maxDosePerPeriod) ? maxDosePerPeriod : [
852
792
  maxDosePerPeriod
853
793
  ];
854
- // Only consider not empty array
855
794
  if (values.length === 0) return undefined;
856
795
  // Periods are expressed as ratio (like rateRatio)
857
- const valuesAsString = values.map((period)=>{
858
- return (0, $7895e9944cc835ce$export$fdc6e9cbd31555fb)({
796
+ const valuesAsString = values.map((period)=>(0, $7895e9944cc835ce$export$fdc6e9cbd31555fb)({
859
797
  config: config,
860
798
  i18next: i18next,
861
799
  ratio: period
862
- });
863
- }).filter((0, $3d60081b7152576d$export$e7321bf46d18757f));
800
+ })).filter((0, $3d60081b7152576d$export$e7321bf46d18757f));
864
801
  const maxDosePerPeriodText = (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(i18next, valuesAsString);
865
802
  return i18next.t("fields.maxDosePerPeriod", {
866
803
  count: values.length,
@@ -947,50 +884,46 @@ function $2c21ace90ecdbde6$export$9f330b4bf8c0975c({ entry: entry, ...args }) {
947
884
 
948
885
 
949
886
 
950
-
951
- const $74b0cf9d3dbd5b46$var$defaultI18NConfig = {
952
- backend: {
953
- backends: [
954
- (0, ($parcel$interopDefault($8zHUo$i18nextresourcestobackend)))(async (lng, ns)=>import(`./locales/${lng}/${ns}.json`))
955
- ]
887
+ class $74b0cf9d3dbd5b46$export$1c191bca55f84a03 extends (0, $4f322cc1dbc51a0e$export$d2ca453b913dcdea) {
888
+ constructor(config){
889
+ super();
890
+ this.config = {
891
+ ...(0, $4a853aea29761dad$export$38cd8db2db178f58),
892
+ ...config
893
+ };
894
+ this.i18nInstance = (0, ($parcel$interopDefault($8zHUo$i18next))).createInstance();
956
895
  }
957
- };
958
- class $74b0cf9d3dbd5b46$export$1c191bca55f84a03 extends (0, $868b4eaa4f62b9f7$export$f807d9a22ff8372d) {
959
- /**
960
- * Factory to create a fine-tuned instance of the utility class
961
- */ static async build(userConfig, i18nConfig = $74b0cf9d3dbd5b46$var$defaultI18NConfig) {
962
- const instance = new $74b0cf9d3dbd5b46$export$1c191bca55f84a03(userConfig, i18nConfig);
896
+ async init() {
897
+ return await this.i18nInstance.use((0, ($parcel$interopDefault($8zHUo$i18nextchainedbackend)))).init({
898
+ fallbackLng: "en",
899
+ lng: this.config.language,
900
+ ns: [
901
+ "common",
902
+ "daysOfWeek",
903
+ "eventTiming",
904
+ "unitsOfTime",
905
+ "quantityComparator"
906
+ ],
907
+ defaultNS: "common",
908
+ ...this.config.i18nConfig
909
+ });
910
+ }
911
+ static async build(config = {}) {
912
+ const instance = new $74b0cf9d3dbd5b46$export$1c191bca55f84a03(config);
963
913
  await instance.init();
964
914
  return instance;
965
915
  }
966
- /**
967
- * Does this array of Dosage objects contains only "sequential" instructions ?
968
- */ containsOnlySequentialInstructions(dosages) {
969
- let sequencesNumbers = dosages.map((d)=>d.sequence).filter((0, $3d60081b7152576d$export$e7321bf46d18757f));
970
- let encounteredSequenceNumbers = new Set(sequencesNumbers);
971
- return encounteredSequenceNumbers.size === 0 || encounteredSequenceNumbers.size === dosages.length;
916
+ getProperty(key) {
917
+ return this.config[key];
972
918
  }
973
- /**
974
- * Turn this array of Dosage objects into a data structure useful to handle "sequential" and "concurrent" instructions (cf. "sequence" property).
975
- * @returns {Dosage[][]} - A two-dimensional array where each inner array contains Dosage objects belonging to the same sequence numberr.
976
- */ groupBySequence(dosages) {
977
- let groups = {};
978
- let sequences = new Set();
979
- for(let idx = 0; idx < dosages.length; idx++){
980
- const dosage = dosages[idx];
981
- let sequenceNr = dosage.sequence || idx + 1;
982
- let localGroup = groups[sequenceNr] || [];
983
- localGroup.push(dosage);
984
- groups[sequenceNr] = localGroup;
985
- sequences.add(sequenceNr);
986
- }
987
- // By using the Set values, we are sure it is returned in the way Dosages were written
988
- return Array.from(sequences, (sequence)=>groups[sequence]);
919
+ setProperty(key, value) {
920
+ this.config[key] = value;
989
921
  }
990
- /**
991
- * From a single dosage, extract specific field(s) requested by user.
992
- * Some use cases could request to split part of the object for given needs (quantity and timing separately)
993
- */ getFields(dos, ...order) {
922
+ async changeLanguage(lng) {
923
+ this.config["language"] = lng;
924
+ return this.i18nInstance.changeLanguage(lng);
925
+ }
926
+ getFields(dos, ...order) {
994
927
  let parts = order.map((entry)=>(0, $2c21ace90ecdbde6$export$9f330b4bf8c0975c)({
995
928
  config: this.config,
996
929
  dos: dos,
@@ -999,32 +932,30 @@ class $74b0cf9d3dbd5b46$export$1c191bca55f84a03 extends (0, $868b4eaa4f62b9f7$ex
999
932
  })).filter((0, $3d60081b7152576d$export$e7321bf46d18757f));
1000
933
  return parts.join(this.config.displaySeparator);
1001
934
  }
1002
- /**
1003
- * Turn a FHIR Dosage object into text
1004
- */ fromDosageToText(dos) {
935
+ fromDosageToText(dos) {
1005
936
  let order = this.config.displayOrder;
1006
937
  return this.getFields(dos, ...order);
1007
938
  }
1008
- /**
1009
- * Turn multiple FHIR Dosage objects into text
1010
- */ fromMultipleDosageToText(dosages) {
1011
- const hasOnlySequentialInstructions = this.containsOnlySequentialInstructions(dosages);
1012
- if (hasOnlySequentialInstructions) {
1013
- const dosagesAsText = dosages.map((d)=>this.fromDosageToText(d));
1014
- return (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(this.i18nInstance, dosagesAsText, "then");
1015
- }
1016
- let sortedDosages = this.groupBySequence(dosages);
1017
- let sequentialInstructions = sortedDosages.map((concurrentInstructions)=>{
1018
- let concurrentInstructionsAsString = concurrentInstructions.map((dosage)=>this.fromDosageToText(dosage));
1019
- return (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(this.i18nInstance, concurrentInstructionsAsString, "and");
1020
- });
939
+ fromMultipleDosageToText(dosages) {
940
+ if (this.containsOnlySequentialInstructions(dosages)) return this.convertSequentialDosagesToText(dosages);
941
+ return this.convertGroupedDosagesToText(dosages);
942
+ }
943
+ convertSequentialDosagesToText(dosages) {
944
+ const dosagesAsText = dosages.map((d)=>this.fromDosageToText(d));
945
+ return (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(this.i18nInstance, dosagesAsText, "then");
946
+ }
947
+ convertConcurrentDosagesToText(dosages) {
948
+ const concurrentInstructionsAsString = dosages.map((d)=>this.fromDosageToText(d));
949
+ return (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(this.i18nInstance, concurrentInstructionsAsString, "and");
950
+ }
951
+ convertGroupedDosagesToText(dosages) {
952
+ const sortedDosages = this.groupBySequence(dosages);
953
+ const sequentialInstructions = sortedDosages.map((d)=>this.convertConcurrentDosagesToText(d));
1021
954
  return (0, $93b58b7d2ead3b95$export$826742c1df3eca39)(this.i18nInstance, sequentialInstructions, "then");
1022
955
  }
1023
956
  }
1024
957
 
1025
958
 
1026
- var // Default export to make it user-friendly
1027
- $882b6d93070905b3$export$2e2bcd8739ae039 = (0, $74b0cf9d3dbd5b46$export$1c191bca55f84a03);
1028
959
 
1029
960
 
1030
961
  //# sourceMappingURL=main.js.map