@quesmed/types 2.6.210 → 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.
@@ -94,19 +94,21 @@ const updateMarksheets = (cache, result, options) => {
94
94
  try {
95
95
  const { input } = variables;
96
96
  for (let i = 0; i < input.length; i++) {
97
- const marksheet = input[i];
97
+ const inputData = input[i];
98
+ const savedMarks = saveMarksheets.find((m) => m.id === inputData.marksheetId)?.marks;
99
+ const savedData = savedMarks?.find((m) => m.id === inputData.markId);
98
100
  cache.writeFragment({
99
101
  id: cache.identify({
100
- id: marksheet.markId,
102
+ id: inputData.markId,
101
103
  __typename: 'MarksheetMark',
102
104
  }),
103
105
  data: {
104
- timeTaken: marksheet.timeTaken || 0,
105
- mark: marksheet.mark,
106
- questionChoiceId: marksheet.choiceId,
106
+ timeTaken: savedData?.timeTaken || 0,
107
+ mark: savedData?.mark,
108
+ questionChoiceId: savedData?.questionChoiceId,
107
109
  isAnswered: true,
108
- result: 0,
109
- score: 0,
110
+ result: savedData?.result,
111
+ score: savedData?.score,
110
112
  },
111
113
  fragment: marksheet_1.NEW_MARK_FIELDS,
112
114
  });
@@ -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: {
@@ -91,19 +91,21 @@ export const updateMarksheets = (cache, result, options) => {
91
91
  try {
92
92
  const { input } = variables;
93
93
  for (let i = 0; i < input.length; i++) {
94
- const marksheet = input[i];
94
+ const inputData = input[i];
95
+ const savedMarks = saveMarksheets.find((m) => m.id === inputData.marksheetId)?.marks;
96
+ const savedData = savedMarks?.find((m) => m.id === inputData.markId);
95
97
  cache.writeFragment({
96
98
  id: cache.identify({
97
- id: marksheet.markId,
99
+ id: inputData.markId,
98
100
  __typename: 'MarksheetMark',
99
101
  }),
100
102
  data: {
101
- timeTaken: marksheet.timeTaken || 0,
102
- mark: marksheet.mark,
103
- questionChoiceId: marksheet.choiceId,
103
+ timeTaken: savedData?.timeTaken || 0,
104
+ mark: savedData?.mark,
105
+ questionChoiceId: savedData?.questionChoiceId,
104
106
  isAnswered: true,
105
- result: 0,
106
- score: 0,
107
+ result: savedData?.result,
108
+ score: savedData?.score,
107
109
  },
108
110
  fragment: NEW_MARK_FIELDS,
109
111
  });
@@ -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.210",
3
+ "version": "2.6.212",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "keywords": [
6
6
  "quesmed",