@quesmed/types 1.3.6 → 1.3.7
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 +12 -3
- 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: {
|
|
@@ -70,14 +72,18 @@ 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
|
-
|
|
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(',');
|
|
81
87
|
obj.frequency.value = obj.frequency.value.toLowerCase().replace(/\s/g, '');
|
|
82
88
|
const frequencyIncHourly = obj.frequency.value.includes('hour');
|
|
83
89
|
const hourlyFreqInt = parseInt(obj.frequency.value);
|
|
@@ -100,6 +106,9 @@ function formatPrescribeAnswer(obj) {
|
|
|
100
106
|
else if (frequencyIncHourly && hourlyFreqInt === 6) {
|
|
101
107
|
obj.frequency.value = 'qds';
|
|
102
108
|
}
|
|
109
|
+
else if (!ACCEPTED_FREQ.includes(obj.frequency.value)) {
|
|
110
|
+
obj.frequency.value = (0, wordsToNumber_1.wordsToNumber)(obj.frequency.value, true).toString();
|
|
111
|
+
}
|
|
103
112
|
return obj;
|
|
104
113
|
}
|
|
105
114
|
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;
|