@quesmed/types 1.0.11 → 1.0.15

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,4 +1,4 @@
1
- import { IQuestion } from './Question';
1
+ import { IPrescribeAnswer, IQuestion } from './Question';
2
2
  import { Id } from './Type';
3
3
  export interface IMarksheet {
4
4
  id: Id;
@@ -13,14 +13,17 @@ export declare enum EQuestionLike {
13
13
  DISLIKE = 1,
14
14
  REMOVE = 2
15
15
  }
16
+ export declare type IMarksheetMarkJSONB = string | [string] | [string[], string[]] | [IPrescribeAnswer] | null;
16
17
  export interface IMarksheetMark {
17
18
  id: Id;
18
19
  index: number;
20
+ marksheetId: Id;
19
21
  questionChoiceId: Id;
20
22
  timeTaken: number;
21
- question: IQuestion;
22
- mark?: string;
23
23
  flagged: boolean;
24
+ questionId: Id;
25
+ question: IQuestion;
26
+ mark: IMarksheetMarkJSONB;
24
27
  like: number;
25
28
  dislike: number;
26
29
  isLikeByMe: string;
@@ -1,6 +1,14 @@
1
- import { IOsceGroup } from "../resolvers/subscription";
2
- import { IOsceStation, IOsceStationMark, IOsceType } from "./OsceStation";
3
- import { Id } from "./Type";
1
+ import { IOsceStation, IOsceStationMark, IOsceType } from './OsceStation';
2
+ import { Id } from './Type';
3
+ import { IUser } from './User';
4
+ export interface IOsceMarksheetUser {
5
+ id: Id;
6
+ createdAt: Date | string;
7
+ osceMarksheetId: Id;
8
+ userId: Id;
9
+ user?: IUser;
10
+ role: EOsceRoles;
11
+ }
4
12
  export interface IOsceMarksheetMark {
5
13
  id: Id;
6
14
  mark: boolean;
@@ -23,7 +31,8 @@ export declare enum EOsceMarksheetAction {
23
31
  CONTINUE = 4,
24
32
  CONNECT = 5,
25
33
  DISCONNECT = 6,
26
- SELECT = 7
34
+ SELECT = 7,
35
+ LEFT = 8
27
36
  }
28
37
  export interface IOsceMarksheet {
29
38
  id: Id;
@@ -32,9 +41,9 @@ export interface IOsceMarksheet {
32
41
  timeTaken: number;
33
42
  osceStationId: Id;
34
43
  osceStation?: IOsceStation;
35
- userId: Id;
44
+ userId?: Id;
45
+ role?: EOsceRoles;
36
46
  solo: boolean;
37
- role: EOsceRoles;
38
47
  score: number;
39
48
  globalScore: number;
40
49
  feedback: string;
@@ -46,7 +55,7 @@ export interface IOsceMarksheet {
46
55
  endedAt: Date | string;
47
56
  timeRemaining: number;
48
57
  marks: IOsceMarksheetMark[];
49
- users: IOsceGroup["members"];
58
+ users: IOsceMarksheetUser[];
50
59
  completed: boolean;
51
60
  }
52
61
  export interface IDashboardOsce {
@@ -18,4 +18,5 @@ var EOsceMarksheetAction;
18
18
  EOsceMarksheetAction[EOsceMarksheetAction["CONNECT"] = 5] = "CONNECT";
19
19
  EOsceMarksheetAction[EOsceMarksheetAction["DISCONNECT"] = 6] = "DISCONNECT";
20
20
  EOsceMarksheetAction[EOsceMarksheetAction["SELECT"] = 7] = "SELECT";
21
+ EOsceMarksheetAction[EOsceMarksheetAction["LEFT"] = 8] = "LEFT";
21
22
  })(EOsceMarksheetAction = exports.EOsceMarksheetAction || (exports.EOsceMarksheetAction = {}));
@@ -7,6 +7,7 @@ export declare enum EQuestionType {
7
7
  MULTIPLE_ANSWERS = 3,
8
8
  PRESCRIPTION_ANSWER = 4
9
9
  }
10
+ export declare type IQuestionAnswer = [string] | [string[], string[]] | IPrescribeAnswer[];
10
11
  export interface IQuestion {
11
12
  id: Id;
12
13
  typeId: Id;
@@ -15,7 +16,7 @@ export interface IQuestion {
15
16
  concept?: IConcept;
16
17
  question: string;
17
18
  explanation?: string;
18
- answer: any;
19
+ answer: IQuestionAnswer;
19
20
  totalVotes: number;
20
21
  choices: IQuestionChoice[];
21
22
  pictures: IQuestionPicture[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quesmed/types",
3
- "version": "1.0.11",
3
+ "version": "1.0.15",
4
4
  "description": "Typescript types for Quesmed",
5
5
  "main": "index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,7 +24,8 @@ export interface ISelectOsceMarksheetStationVar {
24
24
  osceMarksheetId: Id;
25
25
  osceStationId: Id;
26
26
  }
27
- export declare type ISelectOsceMarksheetStationData = boolean;
27
+ export interface ISelectOsceMarksheetStationData extends IOsceMarksheet {
28
+ }
28
29
  export interface IStartOsceMarksheetData extends IOsceMarksheet {
29
30
  }
30
31
  export interface IPrestartOsceMarksheetVar {
@@ -0,0 +1,7 @@
1
+ import { IMarksheetMark } from '../models';
2
+ export interface ICorrectMarkData {
3
+ correct: boolean;
4
+ incorrect: boolean;
5
+ correctIndex: number;
6
+ }
7
+ export declare function correctMark(mark: IMarksheetMark): ICorrectMarkData;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.correctMark = void 0;
4
+ const models_1 = require("../models");
5
+ function formatPrescribeAnswer(obj) {
6
+ obj.drug = obj.drug.toLowerCase().replace(/\s/g, '');
7
+ obj.route = obj.route.toLowerCase().replace(/\s/g, '');
8
+ if (obj.route === 'oral') {
9
+ obj.route = 'po';
10
+ }
11
+ else if (obj.route.includes('intravenous')) {
12
+ obj.route = 'iv';
13
+ }
14
+ else if (obj.route.includes('intramuscular')) {
15
+ obj.route = 'im';
16
+ }
17
+ else if (obj.route.includes('subcutaneous')) {
18
+ obj.route = 'sc';
19
+ }
20
+ else if (obj.route.includes('inhale')) {
21
+ obj.route = 'inh';
22
+ }
23
+ else if (obj.route.includes('nebuli')) {
24
+ obj.route = 'neb';
25
+ }
26
+ obj.units = obj.units.toLowerCase().replace(/\s/g, '');
27
+ if (obj.units === 'milligram' || obj.units === 'milligrams') {
28
+ obj.units = 'mg';
29
+ }
30
+ else if (obj.units === 'microgram' || obj.units === 'micrograms') {
31
+ obj.units = 'mcg';
32
+ }
33
+ else if (obj.units === 'gram' || obj.units === 'grams') {
34
+ obj.units = 'g';
35
+ }
36
+ else if (obj.units === 'unit') {
37
+ obj.units = 'units';
38
+ }
39
+ let m;
40
+ const regex = /\d/gm;
41
+ const durationMatches = [];
42
+ while ((m = regex.exec(obj.duration)) !== null) {
43
+ if (m.index === regex.lastIndex) {
44
+ regex.lastIndex++;
45
+ }
46
+ m.forEach((match) => durationMatches.push(match));
47
+ }
48
+ obj.duration = durationMatches.join(',');
49
+ obj.frequency = obj.frequency.toLowerCase().replace(/\s/g, '');
50
+ if (obj.frequency === 'once-off') {
51
+ obj.frequency = 'stat';
52
+ }
53
+ else if (obj.frequency.includes('once')) {
54
+ obj.frequency = 'po';
55
+ }
56
+ else if (obj.frequency.includes('twice')) {
57
+ obj.frequency = 'bd';
58
+ }
59
+ else if (obj.frequency.includes('trice')) {
60
+ obj.frequency = 'tds';
61
+ }
62
+ return obj;
63
+ }
64
+ const answerRegex = /answer/gi;
65
+ function correctMark(mark) {
66
+ const data = {
67
+ correct: false,
68
+ incorrect: false,
69
+ correctIndex: -1,
70
+ };
71
+ if (!mark || !mark.mark) {
72
+ return data;
73
+ }
74
+ const qKeys = Object.keys(mark.question);
75
+ const answerKey = qKeys.find((k) => answerRegex.exec(k)) || 'answer';
76
+ const answer = mark.question[answerKey];
77
+ const flatAnswer = answer[0];
78
+ const flatAttempt = mark.mark[0];
79
+ if (models_1.EQuestionType.SINGLE_BEST_ANSWER === mark.question.typeId) {
80
+ const answer = flatAnswer;
81
+ const attempt = flatAttempt;
82
+ if (answer === attempt) {
83
+ data.correct = true;
84
+ }
85
+ else {
86
+ data.incorrect = true;
87
+ }
88
+ }
89
+ else if (models_1.EQuestionType.QUESTION_ANSWER === mark.question.typeId) {
90
+ const answer = flatAnswer.toLowerCase().replace(/\s/g, '');
91
+ const attempt = flatAttempt.toLowerCase().replace(/\s/g, '');
92
+ if (answer === attempt) {
93
+ data.correct = true;
94
+ }
95
+ else {
96
+ data.incorrect = true;
97
+ }
98
+ }
99
+ else if (models_1.EQuestionType.MULTIPLE_ANSWERS === mark.question.typeId) {
100
+ const [answerA, answerB] = answer.map((x) => x.sort());
101
+ const [attemptA, attemptB] = mark.mark.map((x) => x.sort());
102
+ if (answerA.length !== attemptA.length || answerB.length !== attemptB.length) {
103
+ data.incorrect = true;
104
+ }
105
+ else if (attemptA.every((x, i) => x === answerA[i]) && attemptB.every((x, i) => answerB[i])) {
106
+ data.correct = true;
107
+ }
108
+ else {
109
+ data.incorrect = true;
110
+ }
111
+ }
112
+ else if (models_1.EQuestionType.PRESCRIPTION_ANSWER === mark.question.typeId) {
113
+ const answers = answer.map(formatPrescribeAnswer);
114
+ const attempt = formatPrescribeAnswer(flatAttempt);
115
+ let foundCorrect = false;
116
+ let index = 0;
117
+ for (const answer of answers) {
118
+ if (answer.dose === attempt.dose &&
119
+ answer.drug === attempt.drug &&
120
+ answer.duration.split(',').includes(attempt.duration) &&
121
+ answer.frequency === attempt.frequency &&
122
+ answer.route === attempt.route &&
123
+ answer.units === attempt.units) {
124
+ foundCorrect = true;
125
+ break;
126
+ }
127
+ index++;
128
+ }
129
+ if (foundCorrect) {
130
+ data.correct = true;
131
+ data.correctIndex = index;
132
+ }
133
+ else {
134
+ data.incorrect = true;
135
+ }
136
+ }
137
+ return data;
138
+ }
139
+ exports.correctMark = correctMark;