@quesmed/types 1.3.3 → 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/models/Question.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { IMarksheetMark } from '../models';
|
|
1
|
+
import { IMarksheetMark, IPrescribeAnswer, IPrescribeMark } from '../models';
|
|
2
|
+
export declare function mapPrescribeMarkToAnswer(obj: IPrescribeMark): IPrescribeAnswer;
|
|
3
|
+
export declare function formatPrescribeAnswer(obj: IPrescribeAnswer): IPrescribeAnswer;
|
|
2
4
|
export interface ICorrectMarkData {
|
|
3
5
|
correct: boolean;
|
|
4
6
|
incorrect: boolean;
|
package/utils/commonFunctions.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.correctMark = void 0;
|
|
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: obj.dose,
|
|
15
|
+
value: parseFloat(obj.dose),
|
|
14
16
|
display: false,
|
|
15
17
|
},
|
|
16
18
|
units: {
|
|
@@ -31,6 +33,7 @@ function mapPrescribeMarkToAnswer(obj) {
|
|
|
31
33
|
},
|
|
32
34
|
};
|
|
33
35
|
}
|
|
36
|
+
exports.mapPrescribeMarkToAnswer = mapPrescribeMarkToAnswer;
|
|
34
37
|
function formatPrescribeAnswer(obj) {
|
|
35
38
|
obj.drug.value = obj.drug.value.toLowerCase().replace(/\s/g, '');
|
|
36
39
|
obj.route.value = obj.route.value.toLowerCase().replace(/\s/g, '');
|
|
@@ -69,32 +72,46 @@ function formatPrescribeAnswer(obj) {
|
|
|
69
72
|
obj.units.value = 'units';
|
|
70
73
|
}
|
|
71
74
|
let m;
|
|
72
|
-
const durationMatches =
|
|
75
|
+
const durationMatches = new Set();
|
|
73
76
|
while ((m = floatRegex.exec(obj.duration.value)) !== null) {
|
|
74
77
|
if (m.index === floatRegex.lastIndex) {
|
|
75
78
|
floatRegex.lastIndex++;
|
|
76
79
|
}
|
|
77
|
-
m.forEach((match) => durationMatches.
|
|
80
|
+
m.forEach((match) => durationMatches.add(match));
|
|
78
81
|
}
|
|
79
|
-
obj.duration.value
|
|
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(',');
|
|
80
87
|
obj.frequency.value = obj.frequency.value.toLowerCase().replace(/\s/g, '');
|
|
88
|
+
const frequencyIncHourly = obj.frequency.value.includes('hour');
|
|
89
|
+
const hourlyFreqInt = parseInt(obj.frequency.value);
|
|
81
90
|
if (obj.frequency.value === 'once-off') {
|
|
82
91
|
obj.frequency.value = 'stat';
|
|
83
92
|
}
|
|
84
|
-
else if (obj.frequency.value.includes('once')) {
|
|
93
|
+
else if (obj.frequency.value.includes('once') || (frequencyIncHourly && hourlyFreqInt === 24)) {
|
|
85
94
|
obj.frequency.value = 'od';
|
|
86
95
|
}
|
|
87
96
|
else if (obj.frequency.value.includes('nightly')) {
|
|
88
97
|
obj.frequency.value = 'od';
|
|
89
98
|
}
|
|
90
|
-
else if (obj.frequency.value.includes('twice')
|
|
99
|
+
else if (obj.frequency.value.includes('twice') ||
|
|
100
|
+
(frequencyIncHourly && hourlyFreqInt === 12)) {
|
|
91
101
|
obj.frequency.value = 'bd';
|
|
92
102
|
}
|
|
93
|
-
else if (obj.frequency.value.includes('trice')) {
|
|
103
|
+
else if (obj.frequency.value.includes('trice') || (frequencyIncHourly && hourlyFreqInt === 8)) {
|
|
94
104
|
obj.frequency.value = 'tds';
|
|
95
105
|
}
|
|
106
|
+
else if (frequencyIncHourly && hourlyFreqInt === 6) {
|
|
107
|
+
obj.frequency.value = 'qds';
|
|
108
|
+
}
|
|
109
|
+
else if (!ACCEPTED_FREQ.includes(obj.frequency.value)) {
|
|
110
|
+
obj.frequency.value = (0, wordsToNumber_1.wordsToNumber)(obj.frequency.value, true).toString();
|
|
111
|
+
}
|
|
96
112
|
return obj;
|
|
97
113
|
}
|
|
114
|
+
exports.formatPrescribeAnswer = formatPrescribeAnswer;
|
|
98
115
|
const answerRegex = /answer/gi;
|
|
99
116
|
function correctMark(mark) {
|
|
100
117
|
const data = {
|
|
@@ -170,12 +187,19 @@ function correctMark(mark) {
|
|
|
170
187
|
let foundCorrect = false;
|
|
171
188
|
let index = 0;
|
|
172
189
|
for (const answer of answers) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
answer.
|
|
177
|
-
|
|
178
|
-
|
|
190
|
+
const doseCorrect = answer.dose.display || answer.dose.value === attempt.dose.value;
|
|
191
|
+
const drugCorrect = answer.drug.display || answer.drug.value === attempt.drug.value;
|
|
192
|
+
const durationCorrect = answer.duration.display ||
|
|
193
|
+
answer.duration.value.split(',').includes(attempt.duration.value);
|
|
194
|
+
const frequencyCorrect = answer.frequency.display || answer.frequency.value === attempt.frequency.value;
|
|
195
|
+
const routeCorrect = answer.route.display || answer.route.value === attempt.route.value;
|
|
196
|
+
const unitsCorrect = answer.units.display || answer.units.value === attempt.units.value;
|
|
197
|
+
if (doseCorrect &&
|
|
198
|
+
drugCorrect &&
|
|
199
|
+
durationCorrect &&
|
|
200
|
+
frequencyCorrect &&
|
|
201
|
+
routeCorrect &&
|
|
202
|
+
unitsCorrect) {
|
|
179
203
|
foundCorrect = true;
|
|
180
204
|
break;
|
|
181
205
|
}
|
|
@@ -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;
|