@quesmed/types 1.3.4 → 1.3.8

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.
@@ -82,7 +82,7 @@ export interface IPrescribeAnswer {
82
82
  }
83
83
  export interface IPrescribeMark {
84
84
  drug: string;
85
- dose: number;
85
+ dose: number | string;
86
86
  units: string;
87
87
  route: string;
88
88
  frequency: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quesmed/types",
3
- "version": "1.3.4",
3
+ "version": "1.3.8",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "main": "index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,6 @@
1
- import { IMarksheetMark } from '../models';
1
+ import { IMarksheetMark, IPrescribeAnswer, IPrescribeMark } from '../models';
2
+ export declare function mapPrescribeMarkToAnswer(obj: IPrescribeMark): IPrescribeAnswer;
3
+ export declare function formatPrescribeAnswer(obj: IPrescribeAnswer): IPrescribeAnswer;
2
4
  export interface ICorrectMarkData {
3
5
  correct: boolean;
4
6
  incorrect: boolean;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.correctMark = void 0;
3
+ exports.correctMark = exports.formatPrescribeAnswer = exports.mapPrescribeMarkToAnswer = void 0;
4
4
  const models_1 = require("../models");
5
+ const wordsToNumber_1 = require("./wordsToNumber");
5
6
  const floatRegex = /([0-9]*[.])?[0-9]+/gm;
7
+ const ACCEPTED_FREQ = ['stat', 'od', 'bd', 'tds', 'qds'];
6
8
  function mapPrescribeMarkToAnswer(obj) {
7
9
  return {
8
10
  drug: {
@@ -10,7 +12,7 @@ function mapPrescribeMarkToAnswer(obj) {
10
12
  display: false,
11
13
  },
12
14
  dose: {
13
- value: obj.dose,
15
+ value: parseFloat(obj.dose),
14
16
  display: false,
15
17
  },
16
18
  units: {
@@ -31,6 +33,7 @@ function mapPrescribeMarkToAnswer(obj) {
31
33
  },
32
34
  };
33
35
  }
36
+ exports.mapPrescribeMarkToAnswer = mapPrescribeMarkToAnswer;
34
37
  function formatPrescribeAnswer(obj) {
35
38
  obj.drug.value = obj.drug.value.toLowerCase().replace(/\s/g, '');
36
39
  obj.route.value = obj.route.value.toLowerCase().replace(/\s/g, '');
@@ -69,32 +72,47 @@ function formatPrescribeAnswer(obj) {
69
72
  obj.units.value = 'units';
70
73
  }
71
74
  let m;
72
- const durationMatches = [];
75
+ const durationMatches = new Set();
73
76
  while ((m = floatRegex.exec(obj.duration.value)) !== null) {
74
77
  if (m.index === floatRegex.lastIndex) {
75
78
  floatRegex.lastIndex++;
76
79
  }
77
- m.forEach((match) => durationMatches.push(match));
80
+ m.forEach((match) => durationMatches.add(match));
78
81
  }
79
- obj.duration.value = durationMatches.join(',');
80
- obj.frequency.value = obj.frequency.value.toLowerCase().replace(/\s/g, '');
82
+ const durationWords = (0, wordsToNumber_1.wordsToNumber)(obj.duration.value, false);
83
+ if (durationWords !== 0) {
84
+ durationMatches.add(durationWords.toString());
85
+ }
86
+ obj.duration.value = [...durationMatches].filter((x) => !!x).join(',');
87
+ const orgFrequencyValue = obj.frequency.value.toLowerCase();
88
+ obj.frequency.value = orgFrequencyValue.replace(/\s/g, '');
89
+ const frequencyIncHourly = obj.frequency.value.includes('hour');
90
+ const hourlyFreqInt = parseInt(obj.frequency.value);
81
91
  if (obj.frequency.value === 'once-off') {
82
92
  obj.frequency.value = 'stat';
83
93
  }
84
- else if (obj.frequency.value.includes('once')) {
94
+ else if (obj.frequency.value.includes('once') || (frequencyIncHourly && hourlyFreqInt === 24)) {
85
95
  obj.frequency.value = 'od';
86
96
  }
87
97
  else if (obj.frequency.value.includes('nightly')) {
88
98
  obj.frequency.value = 'od';
89
99
  }
90
- else if (obj.frequency.value.includes('twice')) {
100
+ else if (obj.frequency.value.includes('twice') ||
101
+ (frequencyIncHourly && hourlyFreqInt === 12)) {
91
102
  obj.frequency.value = 'bd';
92
103
  }
93
- else if (obj.frequency.value.includes('trice')) {
104
+ else if (obj.frequency.value.includes('trice') || (frequencyIncHourly && hourlyFreqInt === 8)) {
94
105
  obj.frequency.value = 'tds';
95
106
  }
107
+ else if (frequencyIncHourly && hourlyFreqInt === 6) {
108
+ obj.frequency.value = 'qds';
109
+ }
110
+ else if (!ACCEPTED_FREQ.includes(obj.frequency.value)) {
111
+ obj.frequency.value = (0, wordsToNumber_1.wordsToNumber)(orgFrequencyValue, true).toString();
112
+ }
96
113
  return obj;
97
114
  }
115
+ exports.formatPrescribeAnswer = formatPrescribeAnswer;
98
116
  const answerRegex = /answer/gi;
99
117
  function correctMark(mark) {
100
118
  const data = {
@@ -155,6 +173,7 @@ function correctMark(mark) {
155
173
  }
156
174
  }
157
175
  else if (models_1.EQuestionType.PRESCRIPTION_ANSWER === mark.question.typeId) {
176
+ console.log('answers');
158
177
  const answers = answer.map(formatPrescribeAnswer);
159
178
  let attempt = formatPrescribeAnswer(mapPrescribeMarkToAnswer({
160
179
  drug: '',
@@ -164,18 +183,26 @@ function correctMark(mark) {
164
183
  frequency: '',
165
184
  duration: '',
166
185
  }));
186
+ console.log('attempt');
167
187
  if (typeof flatAttempt === 'object' && Object.keys(flatAttempt).length === 6) {
168
188
  attempt = formatPrescribeAnswer(mapPrescribeMarkToAnswer(flatAttempt));
169
189
  }
170
190
  let foundCorrect = false;
171
191
  let index = 0;
172
192
  for (const answer of answers) {
173
- if (answer.dose.value === attempt.dose.value &&
174
- answer.drug.value === attempt.drug.value &&
175
- answer.duration.value.split(',').includes(attempt.duration.value) &&
176
- answer.frequency.value === attempt.frequency.value &&
177
- answer.route.value === attempt.route.value &&
178
- answer.units.value === attempt.units.value) {
193
+ const doseCorrect = answer.dose.display || answer.dose.value === attempt.dose.value;
194
+ const drugCorrect = answer.drug.display || answer.drug.value === attempt.drug.value;
195
+ const durationCorrect = answer.duration.display ||
196
+ answer.duration.value.split(',').includes(attempt.duration.value);
197
+ const frequencyCorrect = answer.frequency.display || answer.frequency.value === attempt.frequency.value;
198
+ const routeCorrect = answer.route.display || answer.route.value === attempt.route.value;
199
+ const unitsCorrect = answer.units.display || answer.units.value === attempt.units.value;
200
+ if (doseCorrect &&
201
+ drugCorrect &&
202
+ durationCorrect &&
203
+ frequencyCorrect &&
204
+ routeCorrect &&
205
+ unitsCorrect) {
179
206
  foundCorrect = true;
180
207
  break;
181
208
  }
@@ -0,0 +1 @@
1
+ export declare function wordsToNumber(s: string, checkForDigits?: boolean): number;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wordsToNumber = void 0;
4
+ const Small = {
5
+ zero: 0,
6
+ one: 1,
7
+ two: 2,
8
+ three: 3,
9
+ four: 4,
10
+ five: 5,
11
+ six: 6,
12
+ seven: 7,
13
+ eight: 8,
14
+ nine: 9,
15
+ ten: 10,
16
+ eleven: 11,
17
+ twelve: 12,
18
+ thirteen: 13,
19
+ fourteen: 14,
20
+ fifteen: 15,
21
+ sixteen: 16,
22
+ seventeen: 17,
23
+ eighteen: 18,
24
+ nineteen: 19,
25
+ twenty: 20,
26
+ thirty: 30,
27
+ forty: 40,
28
+ fifty: 50,
29
+ sixty: 60,
30
+ seventy: 70,
31
+ eighty: 80,
32
+ ninety: 90,
33
+ };
34
+ function wordsToNumber(s, checkForDigits = false) {
35
+ const words = s.toString().split(/[\s-]+/);
36
+ let total = 0;
37
+ words.forEach((word) => {
38
+ const wordKey = Small[word];
39
+ if (wordKey !== undefined) {
40
+ total += wordKey;
41
+ }
42
+ else if (checkForDigits && !isNaN(parseFloat(word))) {
43
+ total += parseFloat(word);
44
+ }
45
+ });
46
+ return total;
47
+ }
48
+ exports.wordsToNumber = wordsToNumber;