@quesmed/types 2.6.20 → 2.6.22

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,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) {
@@ -579,30 +579,12 @@ export const BUILD_QUESTION_MARKSHEET = gql `
579
579
  dislikes
580
580
  isLikedByMe
581
581
  prescribeAnswer: answer {
582
- dose {
583
- value
584
- display
585
- }
586
- drug {
587
- value
588
- display
589
- }
590
- route {
591
- value
592
- display
593
- }
594
- frequency {
595
- display
596
- value
597
- }
598
- duration {
599
- display
600
- value
601
- }
602
- units {
603
- display
604
- value
605
- }
582
+ doseId
583
+ durationId
584
+ drugId
585
+ routeId
586
+ unitId
587
+ frequencyId
606
588
  }
607
589
  }
608
590
  ... on QuestionEMQ {
@@ -1597,30 +1579,12 @@ export const BUILD_MARKSHEET = gql `
1597
1579
  dislikes
1598
1580
  isLikedByMe
1599
1581
  prescribeAnswer: answer {
1600
- dose {
1601
- value
1602
- display
1603
- }
1604
- drug {
1605
- value
1606
- display
1607
- }
1608
- route {
1609
- value
1610
- display
1611
- }
1612
- frequency {
1613
- display
1614
- value
1615
- }
1616
- duration {
1617
- display
1618
- value
1619
- }
1620
- units {
1621
- display
1622
- value
1623
- }
1582
+ doseId
1583
+ durationId
1584
+ drugId
1585
+ routeId
1586
+ unitId
1587
+ frequencyId
1624
1588
  }
1625
1589
  }
1626
1590
  ... on QuestionEMQ {
@@ -2620,30 +2584,12 @@ export const RE_BUILD_MARKSHEET = gql `
2620
2584
  dislikes
2621
2585
  isLikedByMe
2622
2586
  prescribeAnswer: answer {
2623
- dose {
2624
- value
2625
- display
2626
- }
2627
- drug {
2628
- value
2629
- display
2630
- }
2631
- route {
2632
- value
2633
- display
2634
- }
2635
- frequency {
2636
- display
2637
- value
2638
- }
2639
- duration {
2640
- display
2641
- value
2642
- }
2643
- units {
2644
- display
2645
- value
2646
- }
2587
+ doseId
2588
+ durationId
2589
+ drugId
2590
+ routeId
2591
+ unitId
2592
+ frequencyId
2647
2593
  }
2648
2594
  }
2649
2595
  ... on QuestionEMQ {
@@ -3621,30 +3567,12 @@ export const QUICK_BUILD_MARKSHEET = gql `
3621
3567
  dislikes
3622
3568
  isLikedByMe
3623
3569
  prescribeAnswer: answer {
3624
- dose {
3625
- value
3626
- display
3627
- }
3628
- drug {
3629
- value
3630
- display
3631
- }
3632
- route {
3633
- value
3634
- display
3635
- }
3636
- frequency {
3637
- display
3638
- value
3639
- }
3640
- duration {
3641
- display
3642
- value
3643
- }
3644
- units {
3645
- display
3646
- value
3647
- }
3570
+ doseId
3571
+ durationId
3572
+ drugId
3573
+ routeId
3574
+ unitId
3575
+ frequencyId
3648
3576
  }
3649
3577
  }
3650
3578
  ... on QuestionEMQ {
@@ -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
  }
@@ -581,30 +581,12 @@ export const MARKSHEET = gql `
581
581
  dislikes
582
582
  isLikedByMe
583
583
  prescribeAnswer: answer {
584
- dose {
585
- value
586
- display
587
- }
588
- drug {
589
- value
590
- display
591
- }
592
- route {
593
- value
594
- display
595
- }
596
- frequency {
597
- display
598
- value
599
- }
600
- duration {
601
- display
602
- value
603
- }
604
- units {
605
- display
606
- value
607
- }
584
+ doseId
585
+ durationId
586
+ drugId
587
+ routeId
588
+ unitId
589
+ frequencyId
608
590
  }
609
591
  }
610
592
  ... on QuestionEMQ {
@@ -1700,30 +1682,12 @@ export const FLAGGED_QUESTIONS_MARKSHEET = gql `
1700
1682
  dislikes
1701
1683
  isLikedByMe
1702
1684
  prescribeAnswer: answer {
1703
- dose {
1704
- value
1705
- display
1706
- }
1707
- drug {
1708
- value
1709
- display
1710
- }
1711
- route {
1712
- value
1713
- display
1714
- }
1715
- frequency {
1716
- display
1717
- value
1718
- }
1719
- duration {
1720
- display
1721
- value
1722
- }
1723
- units {
1724
- display
1725
- value
1726
- }
1685
+ doseId
1686
+ durationId
1687
+ drugId
1688
+ routeId
1689
+ unitId
1690
+ frequencyId
1727
1691
  }
1728
1692
  }
1729
1693
  ... on QuestionEMQ {
@@ -509,30 +509,12 @@ export const QUESTION = gql `
509
509
  dislikes
510
510
  isLikedByMe
511
511
  prescribeAnswer: answer {
512
- dose {
513
- value
514
- display
515
- }
516
- drug {
517
- value
518
- display
519
- }
520
- route {
521
- value
522
- display
523
- }
524
- frequency {
525
- display
526
- value
527
- }
528
- duration {
529
- display
530
- value
531
- }
532
- units {
533
- display
534
- value
535
- }
512
+ doseId
513
+ durationId
514
+ drugId
515
+ routeId
516
+ unitId
517
+ frequencyId
536
518
  }
537
519
  }
538
520
  ... on QuestionEMQ {
@@ -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,160 +1,5 @@
1
1
  import { EQuestionType, } from '../models';
2
- import { wordsToNumber } from './wordsToNumber';
3
- const floatRegex = /([0-9]*[.])?[0-9]+/gm;
4
- const ACCEPTED_FREQ = ['stat', 'od', 'bd', 'tds', 'qds'];
5
- export function mapPrescribeMarkToAnswer(obj) {
6
- return {
7
- drug: {
8
- value: obj.drug,
9
- display: false,
10
- },
11
- dose: {
12
- value: parseFloat(obj.dose),
13
- display: false,
14
- },
15
- units: {
16
- value: obj.units,
17
- display: false,
18
- },
19
- route: {
20
- value: obj.route,
21
- display: false,
22
- },
23
- frequency: {
24
- value: obj.frequency,
25
- display: false,
26
- },
27
- duration: {
28
- value: obj.duration,
29
- display: false,
30
- },
31
- };
32
- }
33
- export function formatPrescribeAnswer(baseAnswer) {
34
- const obj = Object.assign({}, baseAnswer, {
35
- drug: Object.assign({}, baseAnswer.drug, {
36
- value: baseAnswer.drug?.value ?? '',
37
- }),
38
- dose: Object.assign({}, baseAnswer.dose, {
39
- value: baseAnswer.dose?.value ?? 0,
40
- }),
41
- units: Object.assign({}, baseAnswer.units, {
42
- value: baseAnswer.units?.value ?? '',
43
- }),
44
- route: Object.assign({}, baseAnswer.route, {
45
- value: baseAnswer.route?.value ?? '',
46
- }),
47
- frequency: Object.assign({}, baseAnswer.frequency, {
48
- value: baseAnswer.frequency?.value ?? '',
49
- }),
50
- duration: Object.assign({}, baseAnswer.duration, {
51
- value: baseAnswer.duration?.value ?? '',
52
- }),
53
- });
54
- // DRUG
55
- obj.drug.value = obj.drug.value.toLowerCase().replace(/\s/g, '');
56
- // ROUTE
57
- obj.route.value = obj.route.value
58
- .toLowerCase()
59
- .replace(/\s/g, '')
60
- .replace(/\//g, '');
61
- if (obj.route.value.includes('oral')) {
62
- obj.route.value = 'po';
63
- }
64
- else if (obj.route.value.includes('intravenous')) {
65
- obj.route.value = 'iv';
66
- }
67
- else if (obj.route.value.includes('intramuscular')) {
68
- obj.route.value = 'im';
69
- }
70
- else if (obj.route.value.includes('subcutaneous')) {
71
- obj.route.value = 'sc';
72
- }
73
- else if (obj.route.value.includes('inhale')) {
74
- obj.route.value = 'inh';
75
- }
76
- else if (obj.route.value.includes('nebuli')) {
77
- obj.route.value = 'neb';
78
- }
79
- else if (obj.route.value.includes('topical')) {
80
- obj.route.value = 'top';
81
- }
82
- else if (obj.route.value.includes('rectal')) {
83
- obj.route.value = 'pr';
84
- }
85
- // UNITS
86
- obj.units.value = obj.units.value.toLowerCase().replace(/\s/g, '');
87
- switch (obj.units.value) {
88
- case 'milligram':
89
- case 'milligrams':
90
- obj.units.value = 'mg';
91
- break;
92
- case 'microgram':
93
- case 'micrograms':
94
- obj.units.value = 'mcg';
95
- break;
96
- case 'gram':
97
- case 'grams':
98
- obj.units.value = 'g';
99
- break;
100
- case 'unit':
101
- obj.units.value = 'units';
102
- break;
103
- }
104
- // DURATION
105
- let m;
106
- const durationMatches = new Set();
107
- while ((m = floatRegex.exec(obj.duration.value)) !== null) {
108
- if (m.index === floatRegex.lastIndex) {
109
- floatRegex.lastIndex++;
110
- }
111
- m.forEach((match) => durationMatches.add(match));
112
- }
113
- const durationWords = wordsToNumber(obj.duration.value, false);
114
- if (durationWords !== 0) {
115
- durationMatches.add(durationWords.toString());
116
- }
117
- obj.duration.value = [...durationMatches].filter((x) => !!x).join(',');
118
- // FREQUENCY
119
- const orgFrequencyValue = obj.frequency.value.toLowerCase();
120
- const timesPerDay = obj.frequency.value.includes('times per day') ||
121
- obj.frequency.value.includes('times a day');
122
- // remove whitespace for processing
123
- obj.frequency.value = orgFrequencyValue.replace(/\s/g, '');
124
- const freqWordsToInt = wordsToNumber(orgFrequencyValue, true);
125
- const frequencyIncHourly = obj.frequency.value.includes('hour');
126
- const textToInt = parseInt(obj.frequency.value);
127
- if (obj.frequency.value === 'once-off') {
128
- obj.frequency.value = 'stat';
129
- }
130
- else if (obj.frequency.value.includes('once') ||
131
- (frequencyIncHourly && textToInt === 24) ||
132
- (timesPerDay && freqWordsToInt === 1)) {
133
- obj.frequency.value = 'od';
134
- }
135
- else if (obj.frequency.value.includes('nightly') ||
136
- obj.frequency.value === 'on') {
137
- obj.frequency.value = 'od';
138
- }
139
- else if (obj.frequency.value.includes('twice') ||
140
- (frequencyIncHourly && textToInt === 12) ||
141
- (timesPerDay && freqWordsToInt === 2)) {
142
- obj.frequency.value = 'bd';
143
- }
144
- else if (obj.frequency.value.includes('trice') ||
145
- (frequencyIncHourly && textToInt === 8) ||
146
- (timesPerDay && freqWordsToInt === 3)) {
147
- obj.frequency.value = 'tds';
148
- }
149
- else if ((frequencyIncHourly && textToInt === 6) ||
150
- (timesPerDay && freqWordsToInt === 4)) {
151
- obj.frequency.value = 'qds';
152
- }
153
- else if (!ACCEPTED_FREQ.includes(obj.frequency.value)) {
154
- obj.frequency.value = wordsToNumber(orgFrequencyValue, true).toString();
155
- }
156
- return obj;
157
- }
2
+ import { compareObjects } from './object';
158
3
  function createHashMap(arr) {
159
4
  const map = new Map();
160
5
  for (const innerArr of arr) {
@@ -164,6 +9,16 @@ function createHashMap(arr) {
164
9
  }
165
10
  return map;
166
11
  }
12
+ export function mapPrescribeMarkToAnswer(obj) {
13
+ return {
14
+ drugId: obj.drugId,
15
+ doseId: obj.doseId,
16
+ durationId: obj.durationId,
17
+ frequencyId: obj.frequencyId,
18
+ unitId: obj.unitId,
19
+ routeId: obj.routeId,
20
+ };
21
+ }
167
22
  export function correctMark(mark) {
168
23
  const data = {
169
24
  correct: false,
@@ -227,41 +82,19 @@ export function correctMark(mark) {
227
82
  }
228
83
  }
229
84
  else if (EQuestionType.PRESCRIPTION_ANSWER === mark.question.typeId) {
230
- const answers = answer.map(formatPrescribeAnswer);
231
- let attempt = formatPrescribeAnswer(mapPrescribeMarkToAnswer({
232
- drug: '',
233
- dose: -1,
234
- units: '',
235
- route: '',
236
- frequency: '',
237
- duration: '',
238
- }));
239
- if (typeof flatAttempt === 'object' &&
240
- Object.keys(flatAttempt).length === 6) {
241
- attempt = formatPrescribeAnswer(mapPrescribeMarkToAnswer(flatAttempt));
242
- }
243
85
  let foundCorrect = false;
244
86
  let index = 0;
245
- for (const answer of answers) {
246
- const doseCorrect = answer.dose.display || answer.dose.value === attempt.dose.value;
247
- const drugCorrect = answer.drug.display || answer.drug.value === attempt.drug.value;
248
- const durationCorrect = answer.duration.display ||
249
- answer.duration.value.split(',').includes(attempt.duration.value) ||
250
- answer.duration.value === attempt.duration.value;
251
- const frequencyCorrect = answer.frequency.display ||
252
- answer.frequency.value === attempt.frequency.value;
253
- const routeCorrect = answer.route.display || answer.route.value === attempt.route.value;
254
- const unitsCorrect = answer.units.display || answer.units.value === attempt.units.value;
255
- if (doseCorrect &&
256
- drugCorrect &&
257
- durationCorrect &&
258
- frequencyCorrect &&
259
- routeCorrect &&
260
- unitsCorrect) {
261
- foundCorrect = true;
262
- break;
87
+ if (typeof flatAttempt === 'object' &&
88
+ Object.keys(flatAttempt).length > 0) {
89
+ const answers = answer.map(mapPrescribeMarkToAnswer);
90
+ const attempt = mapPrescribeMarkToAnswer(flatAttempt);
91
+ for (const answer of answers) {
92
+ if (compareObjects(answer, attempt)) {
93
+ foundCorrect = true;
94
+ break;
95
+ }
96
+ index++;
263
97
  }
264
- index++;
265
98
  }
266
99
  if (foundCorrect) {
267
100
  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';
@@ -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';
@@ -0,0 +1 @@
1
+ export declare function compareObjects<T = Record<string, unknown>, V = Record<string, unknown>>(obj1: T, obj2: V): boolean;
@@ -0,0 +1,16 @@
1
+ export function compareObjects(obj1, obj2) {
2
+ const ob1 = obj1;
3
+ const ob2 = obj2;
4
+ const keys1 = Object.keys(ob1);
5
+ const keys2 = Object.keys(ob2);
6
+ if (keys1.length !== keys2.length) {
7
+ return false;
8
+ }
9
+ for (let i = 0; i < keys1.length; i++) {
10
+ const key = keys1[i];
11
+ if (ob1[key] !== ob2[key]) {
12
+ return false;
13
+ }
14
+ }
15
+ return true;
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quesmed/types",
3
- "version": "2.6.20",
3
+ "version": "2.6.22",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "keywords": [
6
6
  "quesmed",