@quesmed/types 2.6.211 → 2.6.212

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.
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.evaluateMark = void 0;
4
4
  const models_1 = require("../models");
5
- const object_1 = require("./object");
6
5
  function isPrescribeAnswer(data) {
7
6
  return Object(data).hasOwnProperty('dose');
8
7
  }
@@ -153,21 +152,43 @@ function evaluateMark({ mark, answer, questionTypeId, psaSectionId, choices, })
153
152
  break;
154
153
  }
155
154
  case models_1.EQuestionType.PRESCRIPTION_ANSWER: {
156
- let foundCorrect = false;
157
- if (typeof flatAttempt === 'object' &&
158
- Object.keys(flatAttempt).length > 0) {
159
- const answers = answer.map(mapPrescribeMarkToAnswer);
160
- const attempt = mapPrescribeMarkToAnswer(flatAttempt);
161
- foundCorrect = answers.some((ans) => (0, object_1.compareObjects)(ans, attempt));
162
- }
163
- if (foundCorrect) {
164
- data.score = 1;
165
- data.result = models_1.EMarkResult.Correct;
155
+ if (typeof flatAttempt !== 'object' ||
156
+ !flatAttempt ||
157
+ Object.keys(flatAttempt).length === 0) {
158
+ data.score = 0;
159
+ data.result = models_1.EMarkResult.Incorrect;
160
+ break;
166
161
  }
167
- else {
162
+ const answers = answer.map(mapPrescribeMarkToAnswer);
163
+ const attempt = mapPrescribeMarkToAnswer(flatAttempt);
164
+ // Find all answers with matching drug
165
+ const matchingDrugAnswers = answers.filter((ans) => ans.drugId === attempt.drugId);
166
+ if (matchingDrugAnswers.length === 0) {
168
167
  data.score = 0;
169
168
  data.result = models_1.EMarkResult.Incorrect;
169
+ break;
170
+ }
171
+ // Base score for correct drug
172
+ const DRUG_SCORE = 5;
173
+ const COMPONENT_SCORES = {
174
+ 3: 5,
175
+ 2: 3,
176
+ 1: 2,
177
+ 0: 0, // no components are correct
178
+ };
179
+ // Find the best matching answer (highest component score)
180
+ let bestCorrectCount = -1;
181
+ for (const matchingDrugAnswer of matchingDrugAnswers) {
182
+ const correctCount = Number(matchingDrugAnswer.doseId === attempt.doseId) +
183
+ Number(matchingDrugAnswer.routeId === attempt.routeId) +
184
+ Number(matchingDrugAnswer.frequencyId === attempt.frequencyId);
185
+ if (correctCount > bestCorrectCount) {
186
+ bestCorrectCount = correctCount;
187
+ }
170
188
  }
189
+ data.score = DRUG_SCORE + COMPONENT_SCORES[bestCorrectCount];
190
+ data.result =
191
+ bestCorrectCount === 3 ? models_1.EMarkResult.Correct : models_1.EMarkResult.Partial;
171
192
  break;
172
193
  }
173
194
  case models_1.EQuestionType.EXTENDED_MATCHING_ANSWER: {
@@ -1,5 +1,4 @@
1
1
  import { EMarkResult, EQuestionType, } from '../models';
2
- import { compareObjects } from './object';
3
2
  function isPrescribeAnswer(data) {
4
3
  return Object(data).hasOwnProperty('dose');
5
4
  }
@@ -150,21 +149,43 @@ export function evaluateMark({ mark, answer, questionTypeId, psaSectionId, choic
150
149
  break;
151
150
  }
152
151
  case EQuestionType.PRESCRIPTION_ANSWER: {
153
- let foundCorrect = false;
154
- if (typeof flatAttempt === 'object' &&
155
- Object.keys(flatAttempt).length > 0) {
156
- const answers = answer.map(mapPrescribeMarkToAnswer);
157
- const attempt = mapPrescribeMarkToAnswer(flatAttempt);
158
- foundCorrect = answers.some((ans) => compareObjects(ans, attempt));
159
- }
160
- if (foundCorrect) {
161
- data.score = 1;
162
- data.result = EMarkResult.Correct;
152
+ if (typeof flatAttempt !== 'object' ||
153
+ !flatAttempt ||
154
+ Object.keys(flatAttempt).length === 0) {
155
+ data.score = 0;
156
+ data.result = EMarkResult.Incorrect;
157
+ break;
163
158
  }
164
- else {
159
+ const answers = answer.map(mapPrescribeMarkToAnswer);
160
+ const attempt = mapPrescribeMarkToAnswer(flatAttempt);
161
+ // Find all answers with matching drug
162
+ const matchingDrugAnswers = answers.filter((ans) => ans.drugId === attempt.drugId);
163
+ if (matchingDrugAnswers.length === 0) {
165
164
  data.score = 0;
166
165
  data.result = EMarkResult.Incorrect;
166
+ break;
167
+ }
168
+ // Base score for correct drug
169
+ const DRUG_SCORE = 5;
170
+ const COMPONENT_SCORES = {
171
+ 3: 5,
172
+ 2: 3,
173
+ 1: 2,
174
+ 0: 0, // no components are correct
175
+ };
176
+ // Find the best matching answer (highest component score)
177
+ let bestCorrectCount = -1;
178
+ for (const matchingDrugAnswer of matchingDrugAnswers) {
179
+ const correctCount = Number(matchingDrugAnswer.doseId === attempt.doseId) +
180
+ Number(matchingDrugAnswer.routeId === attempt.routeId) +
181
+ Number(matchingDrugAnswer.frequencyId === attempt.frequencyId);
182
+ if (correctCount > bestCorrectCount) {
183
+ bestCorrectCount = correctCount;
184
+ }
167
185
  }
186
+ data.score = DRUG_SCORE + COMPONENT_SCORES[bestCorrectCount];
187
+ data.result =
188
+ bestCorrectCount === 3 ? EMarkResult.Correct : EMarkResult.Partial;
168
189
  break;
169
190
  }
170
191
  case EQuestionType.EXTENDED_MATCHING_ANSWER: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quesmed/types",
3
- "version": "2.6.211",
3
+ "version": "2.6.212",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "keywords": [
6
6
  "quesmed",