@quesmed/types 1.0.26 → 1.0.27
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/Marksheet.d.ts +2 -2
- package/models/Question.d.ts +12 -0
- package/package.json +1 -1
- package/utils/commonFunctions.js +73 -45
package/models/Marksheet.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPrescribeMark, IQuestion, IQuestionQAAnswer } from './Question';
|
|
2
2
|
import { Id } from './Type';
|
|
3
3
|
export interface IMarksheet {
|
|
4
4
|
id: Id;
|
|
@@ -13,7 +13,7 @@ export declare enum EQuestionLike {
|
|
|
13
13
|
DISLIKE = 1,
|
|
14
14
|
REMOVE = 2
|
|
15
15
|
}
|
|
16
|
-
export declare type IMarksheetMarkJSONB = string | [string] | [IQuestionQAAnswer] | [string[], string[]] | [
|
|
16
|
+
export declare type IMarksheetMarkJSONB = string | [string] | [IQuestionQAAnswer] | [string[], string[]] | [IPrescribeMark] | null;
|
|
17
17
|
export interface IMarksheetMark {
|
|
18
18
|
id: Id;
|
|
19
19
|
index: number;
|
package/models/Question.d.ts
CHANGED
|
@@ -67,7 +67,19 @@ export interface IQuestionPrescribe extends IQuestion {
|
|
|
67
67
|
answer: IPrescribeAnswer[];
|
|
68
68
|
prescribeAnswer: IPrescribeAnswer[];
|
|
69
69
|
}
|
|
70
|
+
export declare type IPrescribeAnswerData<T> = {
|
|
71
|
+
value: T;
|
|
72
|
+
display: boolean;
|
|
73
|
+
};
|
|
70
74
|
export interface IPrescribeAnswer {
|
|
75
|
+
drug: IPrescribeAnswerData<string>;
|
|
76
|
+
dose: IPrescribeAnswerData<number>;
|
|
77
|
+
units: IPrescribeAnswerData<string>;
|
|
78
|
+
route: IPrescribeAnswerData<string>;
|
|
79
|
+
frequency: IPrescribeAnswerData<string>;
|
|
80
|
+
duration: IPrescribeAnswerData<string>;
|
|
81
|
+
}
|
|
82
|
+
export interface IPrescribeMark {
|
|
71
83
|
drug: string;
|
|
72
84
|
dose: number;
|
|
73
85
|
units: string;
|
package/package.json
CHANGED
package/utils/commonFunctions.js
CHANGED
|
@@ -3,67 +3,95 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.correctMark = void 0;
|
|
4
4
|
const models_1 = require("../models");
|
|
5
5
|
const floatRegex = /([0-9]*[.])?[0-9]+/gm;
|
|
6
|
+
function mapPrescribeMarkToAnswer(obj) {
|
|
7
|
+
return {
|
|
8
|
+
drug: {
|
|
9
|
+
value: obj.drug,
|
|
10
|
+
display: false,
|
|
11
|
+
},
|
|
12
|
+
dose: {
|
|
13
|
+
value: obj.dose,
|
|
14
|
+
display: false,
|
|
15
|
+
},
|
|
16
|
+
units: {
|
|
17
|
+
value: obj.units,
|
|
18
|
+
display: false,
|
|
19
|
+
},
|
|
20
|
+
route: {
|
|
21
|
+
value: obj.route,
|
|
22
|
+
display: false,
|
|
23
|
+
},
|
|
24
|
+
frequency: {
|
|
25
|
+
value: obj.frequency,
|
|
26
|
+
display: false,
|
|
27
|
+
},
|
|
28
|
+
duration: {
|
|
29
|
+
value: obj.duration,
|
|
30
|
+
display: false,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
6
34
|
function formatPrescribeAnswer(obj) {
|
|
7
|
-
obj.drug = obj.drug.toLowerCase().replace(/\s/g, '');
|
|
8
|
-
obj.route = obj.route.toLowerCase().replace(/\s/g, '');
|
|
9
|
-
if (obj.route === 'oral') {
|
|
10
|
-
obj.route = 'po';
|
|
35
|
+
obj.drug.value = obj.drug.value.toLowerCase().replace(/\s/g, '');
|
|
36
|
+
obj.route.value = obj.route.value.toLowerCase().replace(/\s/g, '');
|
|
37
|
+
if (obj.route.value === 'oral') {
|
|
38
|
+
obj.route.value = 'po';
|
|
11
39
|
}
|
|
12
|
-
else if (obj.route.includes('intravenous')) {
|
|
13
|
-
obj.route = 'iv';
|
|
40
|
+
else if (obj.route.value.includes('intravenous')) {
|
|
41
|
+
obj.route.value = 'iv';
|
|
14
42
|
}
|
|
15
|
-
else if (obj.route.includes('intramuscular')) {
|
|
16
|
-
obj.route = 'im';
|
|
43
|
+
else if (obj.route.value.includes('intramuscular')) {
|
|
44
|
+
obj.route.value = 'im';
|
|
17
45
|
}
|
|
18
|
-
else if (obj.route.includes('subcutaneous')) {
|
|
19
|
-
obj.route = 'sc';
|
|
46
|
+
else if (obj.route.value.includes('subcutaneous')) {
|
|
47
|
+
obj.route.value = 'sc';
|
|
20
48
|
}
|
|
21
|
-
else if (obj.route.includes('inhale')) {
|
|
22
|
-
obj.route = 'inh';
|
|
49
|
+
else if (obj.route.value.includes('inhale')) {
|
|
50
|
+
obj.route.value = 'inh';
|
|
23
51
|
}
|
|
24
|
-
else if (obj.route.includes('nebuli')) {
|
|
25
|
-
obj.route = 'neb';
|
|
52
|
+
else if (obj.route.value.includes('nebuli')) {
|
|
53
|
+
obj.route.value = 'neb';
|
|
26
54
|
}
|
|
27
|
-
else if (obj.route.includes('topical')) {
|
|
28
|
-
obj.route = 'top';
|
|
55
|
+
else if (obj.route.value.includes('topical')) {
|
|
56
|
+
obj.route.value = 'top';
|
|
29
57
|
}
|
|
30
|
-
obj.units = obj.units.toLowerCase().replace(/\s/g, '');
|
|
31
|
-
if (obj.units === 'milligram' || obj.units === 'milligrams') {
|
|
32
|
-
obj.units = 'mg';
|
|
58
|
+
obj.units.value = obj.units.value.toLowerCase().replace(/\s/g, '');
|
|
59
|
+
if (obj.units.value === 'milligram' || obj.units.value === 'milligrams') {
|
|
60
|
+
obj.units.value = 'mg';
|
|
33
61
|
}
|
|
34
|
-
else if (obj.units === 'microgram' || obj.units === 'micrograms') {
|
|
35
|
-
obj.units = 'mcg';
|
|
62
|
+
else if (obj.units.value === 'microgram' || obj.units.value === 'micrograms') {
|
|
63
|
+
obj.units.value = 'mcg';
|
|
36
64
|
}
|
|
37
|
-
else if (obj.units === 'gram' || obj.units === 'grams') {
|
|
38
|
-
obj.units = 'g';
|
|
65
|
+
else if (obj.units.value === 'gram' || obj.units.value === 'grams') {
|
|
66
|
+
obj.units.value = 'g';
|
|
39
67
|
}
|
|
40
|
-
else if (obj.units === 'unit') {
|
|
41
|
-
obj.units = 'units';
|
|
68
|
+
else if (obj.units.value === 'unit') {
|
|
69
|
+
obj.units.value = 'units';
|
|
42
70
|
}
|
|
43
71
|
let m;
|
|
44
72
|
const durationMatches = [];
|
|
45
|
-
while ((m = floatRegex.exec(obj.duration)) !== null) {
|
|
73
|
+
while ((m = floatRegex.exec(obj.duration.value)) !== null) {
|
|
46
74
|
if (m.index === floatRegex.lastIndex) {
|
|
47
75
|
floatRegex.lastIndex++;
|
|
48
76
|
}
|
|
49
77
|
m.forEach((match) => durationMatches.push(match));
|
|
50
78
|
}
|
|
51
|
-
obj.duration = durationMatches.join(',');
|
|
52
|
-
obj.frequency = obj.frequency.toLowerCase().replace(/\s/g, '');
|
|
53
|
-
if (obj.frequency === 'once-off') {
|
|
54
|
-
obj.frequency = 'stat';
|
|
79
|
+
obj.duration.value = durationMatches.join(',');
|
|
80
|
+
obj.frequency.value = obj.frequency.value.toLowerCase().replace(/\s/g, '');
|
|
81
|
+
if (obj.frequency.value === 'once-off') {
|
|
82
|
+
obj.frequency.value = 'stat';
|
|
55
83
|
}
|
|
56
|
-
else if (obj.frequency.includes('once')) {
|
|
57
|
-
obj.frequency = 'od';
|
|
84
|
+
else if (obj.frequency.value.includes('once')) {
|
|
85
|
+
obj.frequency.value = 'od';
|
|
58
86
|
}
|
|
59
|
-
else if (obj.frequency.includes('nightly')) {
|
|
60
|
-
obj.frequency = 'od';
|
|
87
|
+
else if (obj.frequency.value.includes('nightly')) {
|
|
88
|
+
obj.frequency.value = 'od';
|
|
61
89
|
}
|
|
62
|
-
else if (obj.frequency.includes('twice')) {
|
|
63
|
-
obj.frequency = 'bd';
|
|
90
|
+
else if (obj.frequency.value.includes('twice')) {
|
|
91
|
+
obj.frequency.value = 'bd';
|
|
64
92
|
}
|
|
65
|
-
else if (obj.frequency.includes('trice')) {
|
|
66
|
-
obj.frequency = 'tds';
|
|
93
|
+
else if (obj.frequency.value.includes('trice')) {
|
|
94
|
+
obj.frequency.value = 'tds';
|
|
67
95
|
}
|
|
68
96
|
return obj;
|
|
69
97
|
}
|
|
@@ -117,16 +145,16 @@ function correctMark(mark) {
|
|
|
117
145
|
}
|
|
118
146
|
else if (models_1.EQuestionType.PRESCRIPTION_ANSWER === mark.question.typeId) {
|
|
119
147
|
const answers = answer.map(formatPrescribeAnswer);
|
|
120
|
-
const attempt = formatPrescribeAnswer(flatAttempt);
|
|
148
|
+
const attempt = formatPrescribeAnswer(mapPrescribeMarkToAnswer(flatAttempt));
|
|
121
149
|
let foundCorrect = false;
|
|
122
150
|
let index = 0;
|
|
123
151
|
for (const answer of answers) {
|
|
124
|
-
if (answer.dose === attempt.dose &&
|
|
125
|
-
answer.drug === attempt.drug &&
|
|
126
|
-
answer.duration.split(',').includes(attempt.duration) &&
|
|
127
|
-
answer.frequency === attempt.frequency &&
|
|
128
|
-
answer.route === attempt.route &&
|
|
129
|
-
answer.units === attempt.units) {
|
|
152
|
+
if (answer.dose.value === attempt.dose.value &&
|
|
153
|
+
answer.drug.value === attempt.drug.value &&
|
|
154
|
+
answer.duration.value.split(',').includes(attempt.duration.value) &&
|
|
155
|
+
answer.frequency.value === attempt.frequency.value &&
|
|
156
|
+
answer.route.value === attempt.route.value &&
|
|
157
|
+
answer.units.value === attempt.units.value) {
|
|
130
158
|
foundCorrect = true;
|
|
131
159
|
break;
|
|
132
160
|
}
|