@quesmed/types 1.3.21 → 1.3.22
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.d.ts +1 -1
- package/utils/commonFunctions.js +23 -10
- package/utils/commonFunctions.mjs +23 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IMarksheetMark, IPrescribeAnswer, IPrescribeMark } from '../models';
|
|
2
2
|
export declare function mapPrescribeMarkToAnswer(obj: IPrescribeMark): IPrescribeAnswer;
|
|
3
|
-
export declare function formatPrescribeAnswer(
|
|
3
|
+
export declare function formatPrescribeAnswer(baseAnswer: IPrescribeAnswer): IPrescribeAnswer;
|
|
4
4
|
export interface ICorrectMarkData {
|
|
5
5
|
correct: boolean;
|
|
6
6
|
incorrect: boolean;
|
package/utils/commonFunctions.js
CHANGED
|
@@ -34,9 +34,13 @@ function mapPrescribeMarkToAnswer(obj) {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
exports.mapPrescribeMarkToAnswer = mapPrescribeMarkToAnswer;
|
|
37
|
-
function formatPrescribeAnswer(
|
|
37
|
+
function formatPrescribeAnswer(baseAnswer) {
|
|
38
|
+
const obj = Object.assign(Object.assign({}, baseAnswer), { drug: Object.assign({}, baseAnswer.drug), dose: Object.assign({}, baseAnswer.dose), units: Object.assign({}, baseAnswer.units), route: Object.assign({}, baseAnswer.route), frequency: Object.assign({}, baseAnswer.frequency), duration: Object.assign({}, baseAnswer.duration) });
|
|
38
39
|
obj.drug.value = obj.drug.value.toLowerCase().replace(/\s/g, '');
|
|
39
|
-
obj.route.value = obj.route.value
|
|
40
|
+
obj.route.value = obj.route.value
|
|
41
|
+
.toLowerCase()
|
|
42
|
+
.replace(/\s/g, '')
|
|
43
|
+
.replace(/\//g, '');
|
|
40
44
|
if (obj.route.value === 'oral') {
|
|
41
45
|
obj.route.value = 'po';
|
|
42
46
|
}
|
|
@@ -62,7 +66,8 @@ function formatPrescribeAnswer(obj) {
|
|
|
62
66
|
if (obj.units.value === 'milligram' || obj.units.value === 'milligrams') {
|
|
63
67
|
obj.units.value = 'mg';
|
|
64
68
|
}
|
|
65
|
-
else if (obj.units.value === 'microgram' ||
|
|
69
|
+
else if (obj.units.value === 'microgram' ||
|
|
70
|
+
obj.units.value === 'micrograms') {
|
|
66
71
|
obj.units.value = 'mcg';
|
|
67
72
|
}
|
|
68
73
|
else if (obj.units.value === 'gram' || obj.units.value === 'grams') {
|
|
@@ -91,17 +96,20 @@ function formatPrescribeAnswer(obj) {
|
|
|
91
96
|
if (obj.frequency.value === 'once-off') {
|
|
92
97
|
obj.frequency.value = 'stat';
|
|
93
98
|
}
|
|
94
|
-
else if (obj.frequency.value.includes('once') ||
|
|
99
|
+
else if (obj.frequency.value.includes('once') ||
|
|
100
|
+
(frequencyIncHourly && hourlyFreqInt === 24)) {
|
|
95
101
|
obj.frequency.value = 'od';
|
|
96
102
|
}
|
|
97
|
-
else if (obj.frequency.value.includes('nightly') ||
|
|
103
|
+
else if (obj.frequency.value.includes('nightly') ||
|
|
104
|
+
obj.frequency.value === 'on') {
|
|
98
105
|
obj.frequency.value = 'od';
|
|
99
106
|
}
|
|
100
107
|
else if (obj.frequency.value.includes('twice') ||
|
|
101
108
|
(frequencyIncHourly && hourlyFreqInt === 12)) {
|
|
102
109
|
obj.frequency.value = 'bd';
|
|
103
110
|
}
|
|
104
|
-
else if (obj.frequency.value.includes('trice') ||
|
|
111
|
+
else if (obj.frequency.value.includes('trice') ||
|
|
112
|
+
(frequencyIncHourly && hourlyFreqInt === 8)) {
|
|
105
113
|
obj.frequency.value = 'tds';
|
|
106
114
|
}
|
|
107
115
|
else if (frequencyIncHourly && hourlyFreqInt === 6) {
|
|
@@ -140,7 +148,9 @@ function correctMark(mark) {
|
|
|
140
148
|
}
|
|
141
149
|
}
|
|
142
150
|
else if (models_1.EQuestionType.QUESTION_ANSWER === mark.question.typeId) {
|
|
143
|
-
const answer = flatAnswer.dose
|
|
151
|
+
const answer = flatAnswer.dose
|
|
152
|
+
.toLowerCase()
|
|
153
|
+
.replace(/\s/g, '');
|
|
144
154
|
let attempt = '';
|
|
145
155
|
if (flatAttempt) {
|
|
146
156
|
attempt = flatAttempt.toLowerCase().replace(/\s/g, '');
|
|
@@ -161,7 +171,8 @@ function correctMark(mark) {
|
|
|
161
171
|
Array.isArray(mark.mark[1])) {
|
|
162
172
|
[attemptA, attemptB] = mark.mark.map((x) => x.sort());
|
|
163
173
|
}
|
|
164
|
-
if (answerA.length !== attemptA.length ||
|
|
174
|
+
if (answerA.length !== attemptA.length ||
|
|
175
|
+
answerB.length !== attemptB.length) {
|
|
165
176
|
data.incorrect = true;
|
|
166
177
|
}
|
|
167
178
|
else if (attemptA.every((x, i) => x === answerA[i]) &&
|
|
@@ -182,7 +193,8 @@ function correctMark(mark) {
|
|
|
182
193
|
frequency: '',
|
|
183
194
|
duration: '',
|
|
184
195
|
}));
|
|
185
|
-
if (typeof flatAttempt === 'object' &&
|
|
196
|
+
if (typeof flatAttempt === 'object' &&
|
|
197
|
+
Object.keys(flatAttempt).length === 6) {
|
|
186
198
|
attempt = formatPrescribeAnswer(mapPrescribeMarkToAnswer(flatAttempt));
|
|
187
199
|
}
|
|
188
200
|
let foundCorrect = false;
|
|
@@ -192,7 +204,8 @@ function correctMark(mark) {
|
|
|
192
204
|
const drugCorrect = answer.drug.display || answer.drug.value === attempt.drug.value;
|
|
193
205
|
const durationCorrect = answer.duration.display ||
|
|
194
206
|
answer.duration.value.split(',').includes(attempt.duration.value);
|
|
195
|
-
const frequencyCorrect = answer.frequency.display ||
|
|
207
|
+
const frequencyCorrect = answer.frequency.display ||
|
|
208
|
+
answer.frequency.value === attempt.frequency.value;
|
|
196
209
|
const routeCorrect = answer.route.display || answer.route.value === attempt.route.value;
|
|
197
210
|
const unitsCorrect = answer.units.display || answer.units.value === attempt.units.value;
|
|
198
211
|
if (doseCorrect &&
|
|
@@ -30,9 +30,13 @@ export function mapPrescribeMarkToAnswer(obj) {
|
|
|
30
30
|
},
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
export function formatPrescribeAnswer(
|
|
33
|
+
export function formatPrescribeAnswer(baseAnswer) {
|
|
34
|
+
const obj = Object.assign(Object.assign({}, baseAnswer), { drug: Object.assign({}, baseAnswer.drug), dose: Object.assign({}, baseAnswer.dose), units: Object.assign({}, baseAnswer.units), route: Object.assign({}, baseAnswer.route), frequency: Object.assign({}, baseAnswer.frequency), duration: Object.assign({}, baseAnswer.duration) });
|
|
34
35
|
obj.drug.value = obj.drug.value.toLowerCase().replace(/\s/g, '');
|
|
35
|
-
obj.route.value = obj.route.value
|
|
36
|
+
obj.route.value = obj.route.value
|
|
37
|
+
.toLowerCase()
|
|
38
|
+
.replace(/\s/g, '')
|
|
39
|
+
.replace(/\//g, '');
|
|
36
40
|
if (obj.route.value === 'oral') {
|
|
37
41
|
obj.route.value = 'po';
|
|
38
42
|
}
|
|
@@ -58,7 +62,8 @@ export function formatPrescribeAnswer(obj) {
|
|
|
58
62
|
if (obj.units.value === 'milligram' || obj.units.value === 'milligrams') {
|
|
59
63
|
obj.units.value = 'mg';
|
|
60
64
|
}
|
|
61
|
-
else if (obj.units.value === 'microgram' ||
|
|
65
|
+
else if (obj.units.value === 'microgram' ||
|
|
66
|
+
obj.units.value === 'micrograms') {
|
|
62
67
|
obj.units.value = 'mcg';
|
|
63
68
|
}
|
|
64
69
|
else if (obj.units.value === 'gram' || obj.units.value === 'grams') {
|
|
@@ -87,17 +92,20 @@ export function formatPrescribeAnswer(obj) {
|
|
|
87
92
|
if (obj.frequency.value === 'once-off') {
|
|
88
93
|
obj.frequency.value = 'stat';
|
|
89
94
|
}
|
|
90
|
-
else if (obj.frequency.value.includes('once') ||
|
|
95
|
+
else if (obj.frequency.value.includes('once') ||
|
|
96
|
+
(frequencyIncHourly && hourlyFreqInt === 24)) {
|
|
91
97
|
obj.frequency.value = 'od';
|
|
92
98
|
}
|
|
93
|
-
else if (obj.frequency.value.includes('nightly') ||
|
|
99
|
+
else if (obj.frequency.value.includes('nightly') ||
|
|
100
|
+
obj.frequency.value === 'on') {
|
|
94
101
|
obj.frequency.value = 'od';
|
|
95
102
|
}
|
|
96
103
|
else if (obj.frequency.value.includes('twice') ||
|
|
97
104
|
(frequencyIncHourly && hourlyFreqInt === 12)) {
|
|
98
105
|
obj.frequency.value = 'bd';
|
|
99
106
|
}
|
|
100
|
-
else if (obj.frequency.value.includes('trice') ||
|
|
107
|
+
else if (obj.frequency.value.includes('trice') ||
|
|
108
|
+
(frequencyIncHourly && hourlyFreqInt === 8)) {
|
|
101
109
|
obj.frequency.value = 'tds';
|
|
102
110
|
}
|
|
103
111
|
else if (frequencyIncHourly && hourlyFreqInt === 6) {
|
|
@@ -135,7 +143,9 @@ export function correctMark(mark) {
|
|
|
135
143
|
}
|
|
136
144
|
}
|
|
137
145
|
else if (EQuestionType.QUESTION_ANSWER === mark.question.typeId) {
|
|
138
|
-
const answer = flatAnswer.dose
|
|
146
|
+
const answer = flatAnswer.dose
|
|
147
|
+
.toLowerCase()
|
|
148
|
+
.replace(/\s/g, '');
|
|
139
149
|
let attempt = '';
|
|
140
150
|
if (flatAttempt) {
|
|
141
151
|
attempt = flatAttempt.toLowerCase().replace(/\s/g, '');
|
|
@@ -156,7 +166,8 @@ export function correctMark(mark) {
|
|
|
156
166
|
Array.isArray(mark.mark[1])) {
|
|
157
167
|
[attemptA, attemptB] = mark.mark.map((x) => x.sort());
|
|
158
168
|
}
|
|
159
|
-
if (answerA.length !== attemptA.length ||
|
|
169
|
+
if (answerA.length !== attemptA.length ||
|
|
170
|
+
answerB.length !== attemptB.length) {
|
|
160
171
|
data.incorrect = true;
|
|
161
172
|
}
|
|
162
173
|
else if (attemptA.every((x, i) => x === answerA[i]) &&
|
|
@@ -177,7 +188,8 @@ export function correctMark(mark) {
|
|
|
177
188
|
frequency: '',
|
|
178
189
|
duration: '',
|
|
179
190
|
}));
|
|
180
|
-
if (typeof flatAttempt === 'object' &&
|
|
191
|
+
if (typeof flatAttempt === 'object' &&
|
|
192
|
+
Object.keys(flatAttempt).length === 6) {
|
|
181
193
|
attempt = formatPrescribeAnswer(mapPrescribeMarkToAnswer(flatAttempt));
|
|
182
194
|
}
|
|
183
195
|
let foundCorrect = false;
|
|
@@ -187,7 +199,8 @@ export function correctMark(mark) {
|
|
|
187
199
|
const drugCorrect = answer.drug.display || answer.drug.value === attempt.drug.value;
|
|
188
200
|
const durationCorrect = answer.duration.display ||
|
|
189
201
|
answer.duration.value.split(',').includes(attempt.duration.value);
|
|
190
|
-
const frequencyCorrect = answer.frequency.display ||
|
|
202
|
+
const frequencyCorrect = answer.frequency.display ||
|
|
203
|
+
answer.frequency.value === attempt.frequency.value;
|
|
191
204
|
const routeCorrect = answer.route.display || answer.route.value === attempt.route.value;
|
|
192
205
|
const unitsCorrect = answer.units.display || answer.units.value === attempt.units.value;
|
|
193
206
|
if (doseCorrect &&
|