@quesmed/types 1.3.5 → 1.3.9
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/package.json +1 -1
- package/utils/commonFunctions.js +15 -5
- package/utils/wordsToNumber.d.ts +1 -0
- package/utils/wordsToNumber.js +48 -0
package/package.json
CHANGED
package/utils/commonFunctions.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.correctMark = exports.formatPrescribeAnswer = exports.mapPrescribeMarkToAnswer = void 0;
|
|
4
4
|
const models_1 = require("../models");
|
|
5
|
+
const wordsToNumber_1 = require("./wordsToNumber");
|
|
5
6
|
const floatRegex = /([0-9]*[.])?[0-9]+/gm;
|
|
7
|
+
const ACCEPTED_FREQ = ['stat', 'od', 'bd', 'tds', 'qds'];
|
|
6
8
|
function mapPrescribeMarkToAnswer(obj) {
|
|
7
9
|
return {
|
|
8
10
|
drug: {
|
|
@@ -10,7 +12,7 @@ function mapPrescribeMarkToAnswer(obj) {
|
|
|
10
12
|
display: false,
|
|
11
13
|
},
|
|
12
14
|
dose: {
|
|
13
|
-
value:
|
|
15
|
+
value: parseFloat(obj.dose),
|
|
14
16
|
display: false,
|
|
15
17
|
},
|
|
16
18
|
units: {
|
|
@@ -70,15 +72,20 @@ function formatPrescribeAnswer(obj) {
|
|
|
70
72
|
obj.units.value = 'units';
|
|
71
73
|
}
|
|
72
74
|
let m;
|
|
73
|
-
const durationMatches =
|
|
75
|
+
const durationMatches = new Set();
|
|
74
76
|
while ((m = floatRegex.exec(obj.duration.value)) !== null) {
|
|
75
77
|
if (m.index === floatRegex.lastIndex) {
|
|
76
78
|
floatRegex.lastIndex++;
|
|
77
79
|
}
|
|
78
|
-
m.forEach((match) => durationMatches.
|
|
80
|
+
m.forEach((match) => durationMatches.add(match));
|
|
79
81
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
const durationWords = (0, wordsToNumber_1.wordsToNumber)(obj.duration.value, false);
|
|
83
|
+
if (durationWords !== 0) {
|
|
84
|
+
durationMatches.add(durationWords.toString());
|
|
85
|
+
}
|
|
86
|
+
obj.duration.value = [...durationMatches].filter((x) => !!x).join(',');
|
|
87
|
+
const orgFrequencyValue = obj.frequency.value.toLowerCase();
|
|
88
|
+
obj.frequency.value = orgFrequencyValue.replace(/\s/g, '');
|
|
82
89
|
const frequencyIncHourly = obj.frequency.value.includes('hour');
|
|
83
90
|
const hourlyFreqInt = parseInt(obj.frequency.value);
|
|
84
91
|
if (obj.frequency.value === 'once-off') {
|
|
@@ -100,6 +107,9 @@ function formatPrescribeAnswer(obj) {
|
|
|
100
107
|
else if (frequencyIncHourly && hourlyFreqInt === 6) {
|
|
101
108
|
obj.frequency.value = 'qds';
|
|
102
109
|
}
|
|
110
|
+
else if (!ACCEPTED_FREQ.includes(obj.frequency.value)) {
|
|
111
|
+
obj.frequency.value = (0, wordsToNumber_1.wordsToNumber)(orgFrequencyValue, true).toString();
|
|
112
|
+
}
|
|
103
113
|
return obj;
|
|
104
114
|
}
|
|
105
115
|
exports.formatPrescribeAnswer = formatPrescribeAnswer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function wordsToNumber(s: string, checkForDigits?: boolean): number;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wordsToNumber = void 0;
|
|
4
|
+
const Small = {
|
|
5
|
+
zero: 0,
|
|
6
|
+
one: 1,
|
|
7
|
+
two: 2,
|
|
8
|
+
three: 3,
|
|
9
|
+
four: 4,
|
|
10
|
+
five: 5,
|
|
11
|
+
six: 6,
|
|
12
|
+
seven: 7,
|
|
13
|
+
eight: 8,
|
|
14
|
+
nine: 9,
|
|
15
|
+
ten: 10,
|
|
16
|
+
eleven: 11,
|
|
17
|
+
twelve: 12,
|
|
18
|
+
thirteen: 13,
|
|
19
|
+
fourteen: 14,
|
|
20
|
+
fifteen: 15,
|
|
21
|
+
sixteen: 16,
|
|
22
|
+
seventeen: 17,
|
|
23
|
+
eighteen: 18,
|
|
24
|
+
nineteen: 19,
|
|
25
|
+
twenty: 20,
|
|
26
|
+
thirty: 30,
|
|
27
|
+
forty: 40,
|
|
28
|
+
fifty: 50,
|
|
29
|
+
sixty: 60,
|
|
30
|
+
seventy: 70,
|
|
31
|
+
eighty: 80,
|
|
32
|
+
ninety: 90,
|
|
33
|
+
};
|
|
34
|
+
function wordsToNumber(s, checkForDigits = false) {
|
|
35
|
+
const words = s.toString().split(/[\s-]+/);
|
|
36
|
+
let total = 0;
|
|
37
|
+
words.forEach((word) => {
|
|
38
|
+
const wordKey = Small[word];
|
|
39
|
+
if (wordKey !== undefined) {
|
|
40
|
+
total += wordKey;
|
|
41
|
+
}
|
|
42
|
+
else if (checkForDigits && !isNaN(parseFloat(word))) {
|
|
43
|
+
total += parseFloat(word);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return total;
|
|
47
|
+
}
|
|
48
|
+
exports.wordsToNumber = wordsToNumber;
|