@quesmed/types 2.6.19 → 2.6.21

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.
@@ -1,9 +1,8 @@
1
- import { IMarksheetMark, IPrescribeAnswer, IPrescribeMark } from '../models';
2
- export declare function mapPrescribeMarkToAnswer(obj: IPrescribeMark): IPrescribeAnswer;
3
- export declare function formatPrescribeAnswer(baseAnswer: IPrescribeAnswer): IPrescribeAnswer;
1
+ import { IMarksheetMark, IPrescribeMark, IQuestionPrescription } from '../models';
4
2
  export interface ICorrectMarkData {
5
3
  correct: boolean;
6
4
  incorrect: boolean;
7
5
  correctIndex: number;
8
6
  }
7
+ export declare function mapPrescribeMarkToAnswer(obj: IQuestionPrescription | IPrescribeMark): IPrescribeMark;
9
8
  export declare function correctMark(mark: IMarksheetMark): ICorrectMarkData;
@@ -1,165 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.correctMark = exports.formatPrescribeAnswer = exports.mapPrescribeMarkToAnswer = void 0;
3
+ exports.correctMark = exports.mapPrescribeMarkToAnswer = void 0;
4
4
  const models_1 = require("../models");
5
- const wordsToNumber_1 = require("./wordsToNumber");
6
- const floatRegex = /([0-9]*[.])?[0-9]+/gm;
7
- const ACCEPTED_FREQ = ['stat', 'od', 'bd', 'tds', 'qds'];
8
- function mapPrescribeMarkToAnswer(obj) {
9
- return {
10
- drug: {
11
- value: obj.drug,
12
- display: false,
13
- },
14
- dose: {
15
- value: parseFloat(obj.dose),
16
- display: false,
17
- },
18
- units: {
19
- value: obj.units,
20
- display: false,
21
- },
22
- route: {
23
- value: obj.route,
24
- display: false,
25
- },
26
- frequency: {
27
- value: obj.frequency,
28
- display: false,
29
- },
30
- duration: {
31
- value: obj.duration,
32
- display: false,
33
- },
34
- };
35
- }
36
- exports.mapPrescribeMarkToAnswer = mapPrescribeMarkToAnswer;
37
- function formatPrescribeAnswer(baseAnswer) {
38
- const obj = Object.assign({}, baseAnswer, {
39
- drug: Object.assign({}, baseAnswer.drug, {
40
- value: baseAnswer.drug?.value ?? '',
41
- }),
42
- dose: Object.assign({}, baseAnswer.dose, {
43
- value: baseAnswer.dose?.value ?? 0,
44
- }),
45
- units: Object.assign({}, baseAnswer.units, {
46
- value: baseAnswer.units?.value ?? '',
47
- }),
48
- route: Object.assign({}, baseAnswer.route, {
49
- value: baseAnswer.route?.value ?? '',
50
- }),
51
- frequency: Object.assign({}, baseAnswer.frequency, {
52
- value: baseAnswer.frequency?.value ?? '',
53
- }),
54
- duration: Object.assign({}, baseAnswer.duration, {
55
- value: baseAnswer.duration?.value ?? '',
56
- }),
57
- });
58
- // DRUG
59
- obj.drug.value = obj.drug.value.toLowerCase().replace(/\s/g, '');
60
- // ROUTE
61
- obj.route.value = obj.route.value
62
- .toLowerCase()
63
- .replace(/\s/g, '')
64
- .replace(/\//g, '');
65
- if (obj.route.value.includes('oral')) {
66
- obj.route.value = 'po';
67
- }
68
- else if (obj.route.value.includes('intravenous')) {
69
- obj.route.value = 'iv';
70
- }
71
- else if (obj.route.value.includes('intramuscular')) {
72
- obj.route.value = 'im';
73
- }
74
- else if (obj.route.value.includes('subcutaneous')) {
75
- obj.route.value = 'sc';
76
- }
77
- else if (obj.route.value.includes('inhale')) {
78
- obj.route.value = 'inh';
79
- }
80
- else if (obj.route.value.includes('nebuli')) {
81
- obj.route.value = 'neb';
82
- }
83
- else if (obj.route.value.includes('topical')) {
84
- obj.route.value = 'top';
85
- }
86
- else if (obj.route.value.includes('rectal')) {
87
- obj.route.value = 'pr';
88
- }
89
- // UNITS
90
- obj.units.value = obj.units.value.toLowerCase().replace(/\s/g, '');
91
- switch (obj.units.value) {
92
- case 'milligram':
93
- case 'milligrams':
94
- obj.units.value = 'mg';
95
- break;
96
- case 'microgram':
97
- case 'micrograms':
98
- obj.units.value = 'mcg';
99
- break;
100
- case 'gram':
101
- case 'grams':
102
- obj.units.value = 'g';
103
- break;
104
- case 'unit':
105
- obj.units.value = 'units';
106
- break;
107
- }
108
- // DURATION
109
- let m;
110
- const durationMatches = new Set();
111
- while ((m = floatRegex.exec(obj.duration.value)) !== null) {
112
- if (m.index === floatRegex.lastIndex) {
113
- floatRegex.lastIndex++;
114
- }
115
- m.forEach((match) => durationMatches.add(match));
116
- }
117
- const durationWords = (0, wordsToNumber_1.wordsToNumber)(obj.duration.value, false);
118
- if (durationWords !== 0) {
119
- durationMatches.add(durationWords.toString());
120
- }
121
- obj.duration.value = [...durationMatches].filter((x) => !!x).join(',');
122
- // FREQUENCY
123
- const orgFrequencyValue = obj.frequency.value.toLowerCase();
124
- const timesPerDay = obj.frequency.value.includes('times per day') ||
125
- obj.frequency.value.includes('times a day');
126
- // remove whitespace for processing
127
- obj.frequency.value = orgFrequencyValue.replace(/\s/g, '');
128
- const freqWordsToInt = (0, wordsToNumber_1.wordsToNumber)(orgFrequencyValue, true);
129
- const frequencyIncHourly = obj.frequency.value.includes('hour');
130
- const textToInt = parseInt(obj.frequency.value);
131
- if (obj.frequency.value === 'once-off') {
132
- obj.frequency.value = 'stat';
133
- }
134
- else if (obj.frequency.value.includes('once') ||
135
- (frequencyIncHourly && textToInt === 24) ||
136
- (timesPerDay && freqWordsToInt === 1)) {
137
- obj.frequency.value = 'od';
138
- }
139
- else if (obj.frequency.value.includes('nightly') ||
140
- obj.frequency.value === 'on') {
141
- obj.frequency.value = 'od';
142
- }
143
- else if (obj.frequency.value.includes('twice') ||
144
- (frequencyIncHourly && textToInt === 12) ||
145
- (timesPerDay && freqWordsToInt === 2)) {
146
- obj.frequency.value = 'bd';
147
- }
148
- else if (obj.frequency.value.includes('trice') ||
149
- (frequencyIncHourly && textToInt === 8) ||
150
- (timesPerDay && freqWordsToInt === 3)) {
151
- obj.frequency.value = 'tds';
152
- }
153
- else if ((frequencyIncHourly && textToInt === 6) ||
154
- (timesPerDay && freqWordsToInt === 4)) {
155
- obj.frequency.value = 'qds';
156
- }
157
- else if (!ACCEPTED_FREQ.includes(obj.frequency.value)) {
158
- obj.frequency.value = (0, wordsToNumber_1.wordsToNumber)(orgFrequencyValue, true).toString();
159
- }
160
- return obj;
161
- }
162
- exports.formatPrescribeAnswer = formatPrescribeAnswer;
5
+ const object_1 = require("./object");
163
6
  function createHashMap(arr) {
164
7
  const map = new Map();
165
8
  for (const innerArr of arr) {
@@ -169,6 +12,17 @@ function createHashMap(arr) {
169
12
  }
170
13
  return map;
171
14
  }
15
+ function mapPrescribeMarkToAnswer(obj) {
16
+ return {
17
+ drugId: obj.drugId,
18
+ doseId: obj.doseId,
19
+ durationId: obj.durationId,
20
+ frequencyId: obj.frequencyId,
21
+ unitId: obj.unitId,
22
+ routeId: obj.routeId,
23
+ };
24
+ }
25
+ exports.mapPrescribeMarkToAnswer = mapPrescribeMarkToAnswer;
172
26
  function correctMark(mark) {
173
27
  const data = {
174
28
  correct: false,
@@ -232,41 +86,19 @@ function correctMark(mark) {
232
86
  }
233
87
  }
234
88
  else if (models_1.EQuestionType.PRESCRIPTION_ANSWER === mark.question.typeId) {
235
- const answers = answer.map(formatPrescribeAnswer);
236
- let attempt = formatPrescribeAnswer(mapPrescribeMarkToAnswer({
237
- drug: '',
238
- dose: -1,
239
- units: '',
240
- route: '',
241
- frequency: '',
242
- duration: '',
243
- }));
244
- if (typeof flatAttempt === 'object' &&
245
- Object.keys(flatAttempt).length === 6) {
246
- attempt = formatPrescribeAnswer(mapPrescribeMarkToAnswer(flatAttempt));
247
- }
248
89
  let foundCorrect = false;
249
90
  let index = 0;
250
- for (const answer of answers) {
251
- const doseCorrect = answer.dose.display || answer.dose.value === attempt.dose.value;
252
- const drugCorrect = answer.drug.display || answer.drug.value === attempt.drug.value;
253
- const durationCorrect = answer.duration.display ||
254
- answer.duration.value.split(',').includes(attempt.duration.value) ||
255
- answer.duration.value === attempt.duration.value;
256
- const frequencyCorrect = answer.frequency.display ||
257
- answer.frequency.value === attempt.frequency.value;
258
- const routeCorrect = answer.route.display || answer.route.value === attempt.route.value;
259
- const unitsCorrect = answer.units.display || answer.units.value === attempt.units.value;
260
- if (doseCorrect &&
261
- drugCorrect &&
262
- durationCorrect &&
263
- frequencyCorrect &&
264
- routeCorrect &&
265
- unitsCorrect) {
266
- foundCorrect = true;
267
- break;
91
+ if (typeof flatAttempt === 'object' &&
92
+ Object.keys(flatAttempt).length > 0) {
93
+ const answers = answer.map(mapPrescribeMarkToAnswer);
94
+ const attempt = mapPrescribeMarkToAnswer(flatAttempt);
95
+ for (const answer of answers) {
96
+ if ((0, object_1.compareObjects)(answer, attempt)) {
97
+ foundCorrect = true;
98
+ break;
99
+ }
100
+ index++;
268
101
  }
269
- index++;
270
102
  }
271
103
  if (foundCorrect) {
272
104
  data.correct = true;
@@ -1,5 +1,6 @@
1
1
  export * from './commonFunctions';
2
2
  export * from './lightgallery';
3
+ export * from './object';
3
4
  export * from './offlineLink';
4
5
  export * from './random';
5
6
  export * from './supermemo';
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.printDuration = exports.Uuid4 = void 0;
21
21
  __exportStar(require("./commonFunctions"), exports);
22
22
  __exportStar(require("./lightgallery"), exports);
23
+ __exportStar(require("./object"), exports);
23
24
  __exportStar(require("./offlineLink"), exports);
24
25
  __exportStar(require("./random"), exports);
25
26
  __exportStar(require("./supermemo"), exports);
@@ -0,0 +1 @@
1
+ export declare function compareObjects<T = Record<string, unknown>, V = Record<string, unknown>>(obj1: T, obj2: V): boolean;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compareObjects = void 0;
4
+ function compareObjects(obj1, obj2) {
5
+ const ob1 = obj1;
6
+ const ob2 = obj2;
7
+ const keys1 = Object.keys(ob1);
8
+ const keys2 = Object.keys(ob2);
9
+ if (keys1.length !== keys2.length) {
10
+ return false;
11
+ }
12
+ for (let i = 0; i < keys1.length; i++) {
13
+ const key = keys1[i];
14
+ if (ob1[key] !== ob2[key]) {
15
+ return false;
16
+ }
17
+ }
18
+ return true;
19
+ }
20
+ exports.compareObjects = compareObjects;
@@ -1,6 +1,6 @@
1
1
  import { IBuildConfigData, IPreBuildMarksheet } from '../resolvers/mutation/restricted/marksheet';
2
2
  import { EProductType } from './Product';
3
- import { IPrescribeAnswer, IPrescribeMark, IQuestion, IQuestionChoice, IQuestionQAAnswer } from './Question';
3
+ import { IPrescribeMark, IQuestion, IQuestionChoice, IQuestionQAAnswer } from './Question';
4
4
  import { ETopicType } from './Topic';
5
5
  import { Id } from './Type';
6
6
  import { IUser } from './User';
@@ -92,7 +92,7 @@ export interface IMarksheet {
92
92
  builderConfig?: IBuildConfigData;
93
93
  productId: EProductType;
94
94
  }
95
- export type IMarksheetMarkJSONB = string | [string] | [IQuestionQAAnswer] | [string[], string[]] | [IPrescribeMark] | IPrescribeAnswer | null;
95
+ export type IMarksheetMarkJSONB = string | [string] | [IQuestionQAAnswer] | [string[], string[]] | [IPrescribeMark] | null;
96
96
  export interface IMarksheetMark {
97
97
  id: Id;
98
98
  createdAt: number | Date;
@@ -16,21 +16,15 @@ export interface IQuestionPrescription {
16
16
  id: Id;
17
17
  questionId: Id;
18
18
  doseId: Id;
19
- doseDisplay: string;
20
19
  doseVisible: boolean;
21
20
  drugId: Id;
22
- drugDisplay: string;
23
21
  drugVisible: boolean;
24
22
  routeId: Id;
25
- routeDisplay: string;
26
23
  routeVisible: boolean;
27
24
  frequencyId: Id;
28
- frequencyDisplay: string;
29
25
  frequencyVisible: boolean;
30
26
  durationId: Id;
31
- durationDisplay: string;
32
27
  durationVisible: boolean;
33
28
  unitId: Id;
34
- unitDisplay: string;
35
29
  unitVisible: boolean;
36
30
  }
@@ -25,9 +25,7 @@ export declare enum EQuestionType {
25
25
  PRESCRIPTION_ANSWER = 4,
26
26
  EXTENDED_MATCHING_ANSWER = 5,
27
27
  SELECT_THREE_ANSWER = 6,
28
- RANKING_ANSWER = 7,
29
- MRCP_PART_1 = 8,
30
- MRCP_PART_2 = 9
28
+ RANKING_ANSWER = 7
31
29
  }
32
30
  export declare enum EQuestionLike {
33
31
  NONE = 0,
@@ -62,7 +60,7 @@ export interface IQuestionCommentLike {
62
60
  comment: IQuestionComment;
63
61
  likeTrueDislikeFalse: boolean;
64
62
  }
65
- export type IQuestionAnswer = string | [string] | [IQuestionQAAnswer] | [string[], string[]] | IPrescribeAnswer[] | [string, string][] | [string, string, string] | string[];
63
+ export type IQuestionAnswer = string | [string] | [IQuestionQAAnswer] | [string[], string[]] | IPrescribeMark[] | [string, string][] | [string, string, string] | string[];
66
64
  export type IQuestionAll = IQuestion | IQuestionSBA | IQuestionQA | IQuestionMultiQ | IQuestionPrescribe | IQuestionEMQ | IQuestionSelect3 | IQuestionRanking;
67
65
  export interface IQuestion {
68
66
  id: Id;
@@ -197,8 +195,8 @@ export interface IQuestionRanking extends IQuestion {
197
195
  }
198
196
  export declare function isQuestionPrescribe(data: IQuestionAll): data is IQuestionPrescribe;
199
197
  export interface IQuestionPrescribe extends IQuestion {
200
- answer: IPrescribeAnswer[];
201
- prescribeAnswer: IPrescribeAnswer[];
198
+ answer: IPrescribeMark[];
199
+ prescribeAnswer: IQuestionPrescription[];
202
200
  }
203
201
  export type IPrescribeAnswerData<T> = {
204
202
  value: T;
@@ -213,10 +211,10 @@ export interface IPrescribeAnswer {
213
211
  duration: IPrescribeAnswerData<string>;
214
212
  }
215
213
  export interface IPrescribeMark {
216
- drug: string;
217
- dose: number | string;
218
- units: string;
219
- route: string;
220
- frequency: string;
221
- duration: string;
214
+ drugId: number;
215
+ doseId: number;
216
+ unitId: number;
217
+ routeId: number;
218
+ frequencyId: number;
219
+ durationId: number;
222
220
  }
@@ -18,8 +18,6 @@ export var EQuestionType;
18
18
  EQuestionType[EQuestionType["EXTENDED_MATCHING_ANSWER"] = 5] = "EXTENDED_MATCHING_ANSWER";
19
19
  EQuestionType[EQuestionType["SELECT_THREE_ANSWER"] = 6] = "SELECT_THREE_ANSWER";
20
20
  EQuestionType[EQuestionType["RANKING_ANSWER"] = 7] = "RANKING_ANSWER";
21
- EQuestionType[EQuestionType["MRCP_PART_1"] = 8] = "MRCP_PART_1";
22
- EQuestionType[EQuestionType["MRCP_PART_2"] = 9] = "MRCP_PART_2";
23
21
  })(EQuestionType || (EQuestionType = {}));
24
22
  export var EQuestionLike;
25
23
  (function (EQuestionLike) {
@@ -1,6 +1,6 @@
1
1
  import { ICard } from './Card';
2
2
  import { IConcept } from './Concept';
3
- import { IMarksheet, IMarksheetMark } from './Marksheet';
3
+ import { IMarksheet } from './Marksheet';
4
4
  import { INotification } from './Notification';
5
5
  import { IOsceStation } from './OsceStation';
6
6
  import { IQuestion, IQuestionHighlights } from './Question';
@@ -168,10 +168,9 @@ export interface IUserFlaggedQuestion {
168
168
  updatedAt: number | Date;
169
169
  deletedAt: number | Date;
170
170
  questionId: Id;
171
- question: IQuestion;
171
+ question: Pick<IQuestion, 'id' | 'question' | 'conceptId' | 'typeId' | 'concept'>;
172
172
  userId: Id;
173
173
  markId: Id;
174
- mark: IMarksheetMark;
175
174
  }
176
175
  export interface IUserProgress {
177
176
  id: Id;
@@ -432,8 +432,6 @@ export const getQuestionHighlightsFragment = (typeId) => {
432
432
  case EQuestionType.RANKING_ANSWER:
433
433
  return QUESTION_RANKING_HIGHLIGHT_FIELDS;
434
434
  case EQuestionType.SINGLE_BEST_ANSWER:
435
- case EQuestionType.MRCP_PART_1:
436
- case EQuestionType.MRCP_PART_2:
437
435
  default:
438
436
  return QUESTION_SBA_HIGHLIGHT_FIELDS;
439
437
  }
@@ -453,8 +451,6 @@ export const getQuestionTypeName = (typeId) => {
453
451
  case EQuestionType.RANKING_ANSWER:
454
452
  return 'QuestionRanking';
455
453
  case EQuestionType.SINGLE_BEST_ANSWER:
456
- case EQuestionType.MRCP_PART_1:
457
- case EQuestionType.MRCP_PART_2:
458
454
  default:
459
455
  return 'QuestionSBA';
460
456
  }
@@ -474,8 +470,6 @@ const getQuestionFragment = (typeId) => {
474
470
  case EQuestionType.RANKING_ANSWER:
475
471
  return QUESTION_RANKING_COMMENT_FIELDS;
476
472
  case EQuestionType.SINGLE_BEST_ANSWER:
477
- case EQuestionType.MRCP_PART_1:
478
- case EQuestionType.MRCP_PART_2:
479
473
  default:
480
474
  return QUESTION_SBA_COMMENT_FIELDS;
481
475
  }