@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,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.19",
3
+ "version": "2.6.21",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "keywords": [
6
6
  "quesmed",