@quesmed/types 1.0.27 → 1.0.29

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.
@@ -5,7 +5,7 @@ export interface IChapter {
5
5
  id: Id;
6
6
  createdAt: string | Date;
7
7
  updatedAt: string | Date;
8
- explanation: string;
8
+ explanation: string | null;
9
9
  clinical: boolean;
10
10
  pictures: IChapterPicture[];
11
11
  files: IFile[];
@@ -9,9 +9,9 @@ export interface IMarksheet {
9
9
  mockTestId: number | null;
10
10
  }
11
11
  export declare enum EQuestionLike {
12
- LIKE = 0,
13
- DISLIKE = 1,
14
- REMOVE = 2
12
+ NONE = 0,
13
+ LIKE = 1,
14
+ DISLIKE = 2
15
15
  }
16
16
  export declare type IMarksheetMarkJSONB = string | [string] | [IQuestionQAAnswer] | [string[], string[]] | [IPrescribeMark] | null;
17
17
  export interface IMarksheetMark {
@@ -26,7 +26,7 @@ export interface IMarksheetMark {
26
26
  mark: IMarksheetMarkJSONB;
27
27
  like: number;
28
28
  dislike: number;
29
- isLikeByMe: string;
29
+ isLikeByMe: EQuestionLike;
30
30
  discussion: IDiscussion[];
31
31
  }
32
32
  export interface IDiscussion {
@@ -36,7 +36,7 @@ export interface IDiscussion {
36
36
  comment: string;
37
37
  like: number;
38
38
  dislike: number;
39
- isLikeByMe: string;
39
+ isLikeByMe: EQuestionLike;
40
40
  commentId: number;
41
41
  questionId: number;
42
42
  reply: IDiscussion[];
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EQuestionLike = void 0;
4
4
  var EQuestionLike;
5
5
  (function (EQuestionLike) {
6
- EQuestionLike[EQuestionLike["LIKE"] = 0] = "LIKE";
7
- EQuestionLike[EQuestionLike["DISLIKE"] = 1] = "DISLIKE";
8
- EQuestionLike[EQuestionLike["REMOVE"] = 2] = "REMOVE";
6
+ EQuestionLike[EQuestionLike["NONE"] = 0] = "NONE";
7
+ EQuestionLike[EQuestionLike["LIKE"] = 1] = "LIKE";
8
+ EQuestionLike[EQuestionLike["DISLIKE"] = 2] = "DISLIKE";
9
9
  })(EQuestionLike = exports.EQuestionLike || (exports.EQuestionLike = {}));
@@ -38,7 +38,7 @@ export interface IQuestion {
38
38
  export interface IQuestionChoice {
39
39
  id: Id;
40
40
  name: string;
41
- explanation: string;
41
+ explanation: string | null;
42
42
  label: string;
43
43
  answer: boolean;
44
44
  votes: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quesmed/types",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "main": "index.js",
6
6
  "types": "dist/index.d.ts",
@@ -105,69 +105,94 @@ function correctMark(mark) {
105
105
  if (!mark || !mark.mark) {
106
106
  return data;
107
107
  }
108
- const qKeys = Object.keys(mark.question);
109
- const answerKey = qKeys.find((k) => answerRegex.exec(k)) || 'answer';
110
- const answer = mark.question[answerKey];
111
- const flatAnswer = answer[0];
112
- const flatAttempt = mark.mark[0];
113
- if (models_1.EQuestionType.SINGLE_BEST_ANSWER === mark.question.typeId) {
114
- const answer = flatAnswer;
115
- const attempt = flatAttempt;
116
- if (answer === attempt) {
117
- data.correct = true;
118
- }
119
- else {
120
- data.incorrect = true;
121
- }
122
- }
123
- else if (models_1.EQuestionType.QUESTION_ANSWER === mark.question.typeId) {
124
- const answer = flatAnswer.dose.toLowerCase().replace(/\s/g, '');
125
- const attempt = flatAttempt.toLowerCase().replace(/\s/g, '');
126
- if (answer === attempt) {
127
- data.correct = true;
128
- }
129
- else {
130
- data.incorrect = true;
131
- }
132
- }
133
- else if (models_1.EQuestionType.MULTIPLE_ANSWERS === mark.question.typeId) {
134
- const [answerA, answerB] = answer.map((x) => x.sort());
135
- const [attemptA, attemptB] = mark.mark.map((x) => x.sort());
136
- if (answerA.length !== attemptA.length || answerB.length !== attemptB.length) {
137
- data.incorrect = true;
138
- }
139
- else if (attemptA.every((x, i) => x === answerA[i]) && attemptB.every((x, i) => answerB[i])) {
140
- data.correct = true;
141
- }
142
- else {
143
- data.incorrect = true;
108
+ try {
109
+ const qKeys = Object.keys(mark.question);
110
+ const answerKey = qKeys.find((k) => answerRegex.exec(k)) || 'answer';
111
+ const answer = mark.question[answerKey];
112
+ const flatAnswer = answer[0];
113
+ const flatAttempt = mark.mark[0];
114
+ if (models_1.EQuestionType.SINGLE_BEST_ANSWER === mark.question.typeId) {
115
+ const answer = flatAnswer;
116
+ const attempt = flatAttempt;
117
+ if (answer === attempt) {
118
+ data.correct = true;
119
+ }
120
+ else {
121
+ data.incorrect = true;
122
+ }
144
123
  }
145
- }
146
- else if (models_1.EQuestionType.PRESCRIPTION_ANSWER === mark.question.typeId) {
147
- const answers = answer.map(formatPrescribeAnswer);
148
- const attempt = formatPrescribeAnswer(mapPrescribeMarkToAnswer(flatAttempt));
149
- let foundCorrect = false;
150
- let index = 0;
151
- for (const answer of answers) {
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) {
158
- foundCorrect = true;
159
- break;
124
+ else if (models_1.EQuestionType.QUESTION_ANSWER === mark.question.typeId) {
125
+ const answer = flatAnswer.dose.toLowerCase().replace(/\s/g, '');
126
+ let attempt = '';
127
+ if (flatAttempt) {
128
+ attempt = flatAttempt.toLowerCase().replace(/\s/g, '');
129
+ }
130
+ if (answer === attempt) {
131
+ data.correct = true;
132
+ }
133
+ else {
134
+ data.incorrect = true;
160
135
  }
161
- index++;
162
136
  }
163
- if (foundCorrect) {
164
- data.correct = true;
165
- data.correctIndex = index;
137
+ else if (models_1.EQuestionType.MULTIPLE_ANSWERS === mark.question.typeId) {
138
+ const [answerA, answerB] = answer.map((x) => x.sort());
139
+ let [attemptA, attemptB] = [[], []];
140
+ if (Array.isArray(mark.mark) &&
141
+ mark.mark.length === 2 &&
142
+ Array.isArray(mark.mark[0]) &&
143
+ Array.isArray(mark.mark[1])) {
144
+ [attemptA, attemptB] = mark.mark.map((x) => x.sort());
145
+ }
146
+ if (answerA.length !== attemptA.length || answerB.length !== attemptB.length) {
147
+ data.incorrect = true;
148
+ }
149
+ else if (attemptA.every((x, i) => x === answerA[i]) &&
150
+ attemptB.every((_, i) => answerB[i])) {
151
+ data.correct = true;
152
+ }
153
+ else {
154
+ data.incorrect = true;
155
+ }
166
156
  }
167
- else {
168
- data.incorrect = true;
157
+ else if (models_1.EQuestionType.PRESCRIPTION_ANSWER === mark.question.typeId) {
158
+ const answers = answer.map(formatPrescribeAnswer);
159
+ let attempt = formatPrescribeAnswer(mapPrescribeMarkToAnswer({
160
+ drug: '',
161
+ dose: -1,
162
+ units: '',
163
+ route: '',
164
+ frequency: '',
165
+ duration: '',
166
+ }));
167
+ if (typeof flatAttempt === 'object' && Object.keys(flatAttempt).length === 6) {
168
+ attempt = formatPrescribeAnswer(mapPrescribeMarkToAnswer(flatAttempt));
169
+ }
170
+ let foundCorrect = false;
171
+ let index = 0;
172
+ for (const answer of answers) {
173
+ if (answer.dose.value === attempt.dose.value &&
174
+ answer.drug.value === attempt.drug.value &&
175
+ answer.duration.value.split(',').includes(attempt.duration.value) &&
176
+ answer.frequency.value === attempt.frequency.value &&
177
+ answer.route.value === attempt.route.value &&
178
+ answer.units.value === attempt.units.value) {
179
+ foundCorrect = true;
180
+ break;
181
+ }
182
+ index++;
183
+ }
184
+ if (foundCorrect) {
185
+ data.correct = true;
186
+ data.correctIndex = index;
187
+ }
188
+ else {
189
+ data.incorrect = true;
190
+ }
169
191
  }
170
192
  }
193
+ catch (e) {
194
+ console.error(e);
195
+ }
171
196
  return data;
172
197
  }
173
198
  exports.correctMark = correctMark;