@integraciones_doc24/sdk 1.15.11 → 1.15.12
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.
- package/README.md +202 -202
- package/lib/baseSdk/diagnostica.d.ts +54 -54
- package/lib/baseSdk/diagnostica.js +82 -82
- package/lib/baseSdk/external.d.ts +177 -177
- package/lib/baseSdk/external.js +96 -96
- package/lib/baseSdk/index.d.ts +2 -2
- package/lib/baseSdk/index.js +74 -74
- package/lib/baseSdk/user.d.ts +91 -91
- package/lib/baseSdk/user.js +136 -136
- package/lib/index.d.ts +365 -365
- package/lib/index.js +22 -22
- package/lib/request/index.d.ts +3 -3
- package/lib/request/index.js +26 -26
- package/lib/request/token.d.ts +2 -2
- package/lib/request/token.js +34 -34
- package/lib/request/validation.d.ts +10 -10
- package/lib/request/validation.js +28 -28
- package/lib/schemas.d.ts +1822 -1816
- package/lib/schemas.js +421 -420
- package/lib/types.d.ts +146 -146
- package/lib/types.js +2 -2
- package/lib/userSdk/chat.d.ts +57 -57
- package/lib/userSdk/chat.js +98 -98
- package/lib/userSdk/external.d.ts +34 -34
- package/lib/userSdk/external.js +72 -72
- package/lib/userSdk/index.d.ts +2 -2
- package/lib/userSdk/index.js +30 -30
- package/lib/userSdk/patients.d.ts +38 -38
- package/lib/userSdk/patients.js +67 -67
- package/lib/userSdk/schedule.d.ts +47 -47
- package/lib/userSdk/schedule.js +81 -81
- package/lib/userSdk/specialties.d.ts +7 -7
- package/lib/userSdk/specialties.js +19 -19
- package/lib/userSdk/videoVisit.d.ts +115 -113
- package/lib/userSdk/videoVisit.js +155 -154
- package/lib/utils.d.ts +2 -2
- package/lib/utils.js +16 -16
- package/lib/webhook/index.d.ts +2 -2
- package/lib/webhook/index.js +56 -56
- package/lib/webhook/responses.d.ts +35 -35
- package/lib/webhook/responses.js +42 -42
- package/lib/webhook/token.d.ts +2 -2
- package/lib/webhook/token.js +23 -23
- package/package.json +36 -36
|
@@ -1,154 +1,155 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVideoVisitMethods = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const validation_1 = require("../request/validation");
|
|
6
|
-
const schemas_1 = require("../schemas");
|
|
7
|
-
const utils_1 = require("../utils");
|
|
8
|
-
const getVideoVisitMethods = (makeRequest) => {
|
|
9
|
-
const scheduleVideoVisit = validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.scheduleParameters]), zod_1.string(), async (params) => {
|
|
10
|
-
const specificParams = params.type === 'appointment'
|
|
11
|
-
? {
|
|
12
|
-
type: 'P',
|
|
13
|
-
appointment_id: params.appointmentId,
|
|
14
|
-
}
|
|
15
|
-
: { type: 'E' };
|
|
16
|
-
const mappedParams = {
|
|
17
|
-
...specificParams,
|
|
18
|
-
patient_id: params.patientId,
|
|
19
|
-
specialty_id: params.specialtyId,
|
|
20
|
-
language: params.language.toUpperCase(),
|
|
21
|
-
details: params.details,
|
|
22
|
-
extra_info: params.extraInfo,
|
|
23
|
-
};
|
|
24
|
-
const response = await makeRequest('POST', '/video-visit', mappedParams);
|
|
25
|
-
return response.data.vc_token;
|
|
26
|
-
});
|
|
27
|
-
const cancelVideoVisit = validation_1.validateFunction(zod_1.tuple([zod_1.string()]), zod_1.undefined(), async (vcToken) => {
|
|
28
|
-
const path = `/video-visit/${vcToken}`;
|
|
29
|
-
await makeRequest('DELETE', path);
|
|
30
|
-
});
|
|
31
|
-
const getVideoVisit = validation_1.validateFunction(zod_1.tuple([zod_1.string(), zod_1.number()]), schemas_1.doc24Schemas.videoVisit, async (vcToken, patientId) => {
|
|
32
|
-
const path = `/video-visit/${vcToken}/${patientId}`;
|
|
33
|
-
const response = await makeRequest('GET', path);
|
|
34
|
-
return mapVideoVisit(response.data);
|
|
35
|
-
});
|
|
36
|
-
const getPatientVideoVisitHistory = validation_1.validateFunction(zod_1.tuple([zod_1.number()]), zod_1.array(schemas_1.doc24Schemas.historicalVideoVisit), async (patientId) => {
|
|
37
|
-
const path = `/video-visit-history/${patientId}`;
|
|
38
|
-
const response = await makeRequest('GET', path);
|
|
39
|
-
return response.data.map((raw) => mapHistoricalVideoVisit(raw));
|
|
40
|
-
});
|
|
41
|
-
const getVideoVisitDetails = validation_1.validateFunction(zod_1.tuple([zod_1.number()]), schemas_1.doc24Schemas.videoVisitDetails, async (vcId) => {
|
|
42
|
-
const path = `/video-visit-records/${vcId}`;
|
|
43
|
-
const response = await makeRequest('GET', path);
|
|
44
|
-
return {
|
|
45
|
-
id: response.data.consultation_id,
|
|
46
|
-
status: response.data.status,
|
|
47
|
-
paymentStatus: response.data.payment_status,
|
|
48
|
-
professional: response.data.professional_id
|
|
49
|
-
? {
|
|
50
|
-
id: response.data.professional_id,
|
|
51
|
-
fullName: response.data.professional,
|
|
52
|
-
}
|
|
53
|
-
: undefined,
|
|
54
|
-
patient: {
|
|
55
|
-
fullName: response.data.patient,
|
|
56
|
-
firstAccessDate: response.data.patient_first_access_date &&
|
|
57
|
-
utils_1.parseDateTime(response.data.patient_first_access_date),
|
|
58
|
-
lastAccessDate: response.data.patient_last_access_date &&
|
|
59
|
-
utils_1.parseDateTime(response.data.patient_last_access_date),
|
|
60
|
-
},
|
|
61
|
-
finishDate: response.data.finish_date &&
|
|
62
|
-
utils_1.parseDateTime(response.data.finish_date),
|
|
63
|
-
retries: response.data.retries,
|
|
64
|
-
language: response.data.language,
|
|
65
|
-
appointment: response.data.appointment_id
|
|
66
|
-
? {
|
|
67
|
-
id: response.data.appointment_id,
|
|
68
|
-
date: utils_1.parseDateTime(`${response.data.appointment_date} ${response.data.appointment_time}`, response.data.time_zone),
|
|
69
|
-
}
|
|
70
|
-
: null,
|
|
71
|
-
report: {
|
|
72
|
-
motive: response.data.motive,
|
|
73
|
-
actualDesease: response.data.actual_desease,
|
|
74
|
-
indications: response.data.indications,
|
|
75
|
-
alertSigns: response.data.alert_signs,
|
|
76
|
-
extendedMotive: response.data.extended_motive,
|
|
77
|
-
diagnose: response.data.diagnose.map((d) => ({
|
|
78
|
-
description: d.diagnostico,
|
|
79
|
-
code: d.codificacion,
|
|
80
|
-
})),
|
|
81
|
-
},
|
|
82
|
-
pdf: {
|
|
83
|
-
atention: response.data.pdf_atention
|
|
84
|
-
? response.data.pdf_atention
|
|
85
|
-
: undefined,
|
|
86
|
-
medication: response.data.pdf_medication,
|
|
87
|
-
images: response.data.pdf_images
|
|
88
|
-
? response.data.pdf_images
|
|
89
|
-
: undefined,
|
|
90
|
-
otherExams: response.data.pdf_other_exams
|
|
91
|
-
? response.data.pdf_other_exams
|
|
92
|
-
: undefined,
|
|
93
|
-
labs: response.data.pdf_labs ? response.data.pdf_labs : undefined,
|
|
94
|
-
},
|
|
95
|
-
files: response.data.files.map((f) => ({
|
|
96
|
-
name: f.nombre_file,
|
|
97
|
-
url: f.file,
|
|
98
|
-
})),
|
|
99
|
-
};
|
|
100
|
-
});
|
|
101
|
-
const getActiveVideoVisits = validation_1.validateFunction(zod_1.tuple([]), zod_1.array(schemas_1.doc24Schemas.activeVideoVisitData), async () => {
|
|
102
|
-
const path = '/active-video-visits';
|
|
103
|
-
const response = await makeRequest('GET', path);
|
|
104
|
-
const consultations = response.data['active-consultations'];
|
|
105
|
-
return consultations.map((s) => ({
|
|
106
|
-
patientId: s.patient_id,
|
|
107
|
-
consultationId: s.consultation_id,
|
|
108
|
-
vcToken: s.vc_token,
|
|
109
|
-
}));
|
|
110
|
-
});
|
|
111
|
-
const getVideoVisitLink = validation_1.validateFunction(zod_1.tuple([zod_1.string(), zod_1.number()]), zod_1.string().nullable(), async (vcToken, patientId) => {
|
|
112
|
-
const path = `/video-visit-link/${vcToken}/${patientId}`;
|
|
113
|
-
const response = await makeRequest('GET', path);
|
|
114
|
-
return response.data.link;
|
|
115
|
-
});
|
|
116
|
-
return {
|
|
117
|
-
scheduleVideoVisit,
|
|
118
|
-
cancelVideoVisit,
|
|
119
|
-
getVideoVisit,
|
|
120
|
-
getPatientVideoVisitHistory,
|
|
121
|
-
getVideoVisitDetails,
|
|
122
|
-
getVideoVisitLink,
|
|
123
|
-
getActiveVideoVisits,
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
exports.getVideoVisitMethods = getVideoVisitMethods;
|
|
127
|
-
const mapVideoVisit = (raw) => {
|
|
128
|
-
var _a, _b;
|
|
129
|
-
return {
|
|
130
|
-
id: raw.vc_id,
|
|
131
|
-
creationDate: utils_1.parseDateTime(raw.creation_date),
|
|
132
|
-
patientId: raw.patient_id,
|
|
133
|
-
user: { id: raw.user_id, email: raw.email, phone: raw.phone },
|
|
134
|
-
vcToken: raw.vc_token,
|
|
135
|
-
appointment: raw.appointment_id
|
|
136
|
-
? {
|
|
137
|
-
id: raw.appointment_id,
|
|
138
|
-
date: utils_1.parseDateTime(`${raw.appointment_date} ${raw.appointment_time}`, raw.time_zone),
|
|
139
|
-
}
|
|
140
|
-
: undefined,
|
|
141
|
-
videoVisit: raw.video_visit_id
|
|
142
|
-
? { id: raw.video_visit_id, status: raw.video_visit_status }
|
|
143
|
-
: undefined,
|
|
144
|
-
paymentStatus: (_a = raw.payment_status) !== null && _a !== void 0 ? _a : undefined,
|
|
145
|
-
atentionId: (_b = raw.atentionId) !== null && _b !== void 0 ? _b : undefined,
|
|
146
|
-
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVideoVisitMethods = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const validation_1 = require("../request/validation");
|
|
6
|
+
const schemas_1 = require("../schemas");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const getVideoVisitMethods = (makeRequest) => {
|
|
9
|
+
const scheduleVideoVisit = validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.scheduleParameters]), zod_1.string(), async (params) => {
|
|
10
|
+
const specificParams = params.type === 'appointment'
|
|
11
|
+
? {
|
|
12
|
+
type: 'P',
|
|
13
|
+
appointment_id: params.appointmentId,
|
|
14
|
+
}
|
|
15
|
+
: { type: 'E' };
|
|
16
|
+
const mappedParams = {
|
|
17
|
+
...specificParams,
|
|
18
|
+
patient_id: params.patientId,
|
|
19
|
+
specialty_id: params.specialtyId,
|
|
20
|
+
language: params.language.toUpperCase(),
|
|
21
|
+
details: params.details,
|
|
22
|
+
extra_info: params.extraInfo,
|
|
23
|
+
};
|
|
24
|
+
const response = await makeRequest('POST', '/video-visit', mappedParams);
|
|
25
|
+
return response.data.vc_token;
|
|
26
|
+
});
|
|
27
|
+
const cancelVideoVisit = validation_1.validateFunction(zod_1.tuple([zod_1.string()]), zod_1.undefined(), async (vcToken) => {
|
|
28
|
+
const path = `/video-visit/${vcToken}`;
|
|
29
|
+
await makeRequest('DELETE', path);
|
|
30
|
+
});
|
|
31
|
+
const getVideoVisit = validation_1.validateFunction(zod_1.tuple([zod_1.string(), zod_1.number()]), schemas_1.doc24Schemas.videoVisit, async (vcToken, patientId) => {
|
|
32
|
+
const path = `/video-visit/${vcToken}/${patientId}`;
|
|
33
|
+
const response = await makeRequest('GET', path);
|
|
34
|
+
return mapVideoVisit(response.data);
|
|
35
|
+
});
|
|
36
|
+
const getPatientVideoVisitHistory = validation_1.validateFunction(zod_1.tuple([zod_1.number()]), zod_1.array(schemas_1.doc24Schemas.historicalVideoVisit), async (patientId) => {
|
|
37
|
+
const path = `/video-visit-history/${patientId}`;
|
|
38
|
+
const response = await makeRequest('GET', path);
|
|
39
|
+
return response.data.map((raw) => mapHistoricalVideoVisit(raw));
|
|
40
|
+
});
|
|
41
|
+
const getVideoVisitDetails = validation_1.validateFunction(zod_1.tuple([zod_1.number()]), schemas_1.doc24Schemas.videoVisitDetails, async (vcId) => {
|
|
42
|
+
const path = `/video-visit-records/${vcId}`;
|
|
43
|
+
const response = await makeRequest('GET', path);
|
|
44
|
+
return {
|
|
45
|
+
id: response.data.consultation_id,
|
|
46
|
+
status: response.data.status,
|
|
47
|
+
paymentStatus: response.data.payment_status,
|
|
48
|
+
professional: response.data.professional_id
|
|
49
|
+
? {
|
|
50
|
+
id: response.data.professional_id,
|
|
51
|
+
fullName: response.data.professional,
|
|
52
|
+
}
|
|
53
|
+
: undefined,
|
|
54
|
+
patient: {
|
|
55
|
+
fullName: response.data.patient,
|
|
56
|
+
firstAccessDate: response.data.patient_first_access_date &&
|
|
57
|
+
utils_1.parseDateTime(response.data.patient_first_access_date),
|
|
58
|
+
lastAccessDate: response.data.patient_last_access_date &&
|
|
59
|
+
utils_1.parseDateTime(response.data.patient_last_access_date),
|
|
60
|
+
},
|
|
61
|
+
finishDate: response.data.finish_date &&
|
|
62
|
+
utils_1.parseDateTime(response.data.finish_date),
|
|
63
|
+
retries: response.data.retries,
|
|
64
|
+
language: response.data.language,
|
|
65
|
+
appointment: response.data.appointment_id
|
|
66
|
+
? {
|
|
67
|
+
id: response.data.appointment_id,
|
|
68
|
+
date: utils_1.parseDateTime(`${response.data.appointment_date} ${response.data.appointment_time}`, response.data.time_zone),
|
|
69
|
+
}
|
|
70
|
+
: null,
|
|
71
|
+
report: {
|
|
72
|
+
motive: response.data.motive,
|
|
73
|
+
actualDesease: response.data.actual_desease,
|
|
74
|
+
indications: response.data.indications,
|
|
75
|
+
alertSigns: response.data.alert_signs,
|
|
76
|
+
extendedMotive: response.data.extended_motive,
|
|
77
|
+
diagnose: response.data.diagnose.map((d) => ({
|
|
78
|
+
description: d.diagnostico,
|
|
79
|
+
code: d.codificacion,
|
|
80
|
+
})),
|
|
81
|
+
},
|
|
82
|
+
pdf: {
|
|
83
|
+
atention: response.data.pdf_atention
|
|
84
|
+
? response.data.pdf_atention
|
|
85
|
+
: undefined,
|
|
86
|
+
medication: response.data.pdf_medication,
|
|
87
|
+
images: response.data.pdf_images
|
|
88
|
+
? response.data.pdf_images
|
|
89
|
+
: undefined,
|
|
90
|
+
otherExams: response.data.pdf_other_exams
|
|
91
|
+
? response.data.pdf_other_exams
|
|
92
|
+
: undefined,
|
|
93
|
+
labs: response.data.pdf_labs ? response.data.pdf_labs : undefined,
|
|
94
|
+
},
|
|
95
|
+
files: response.data.files.map((f) => ({
|
|
96
|
+
name: f.nombre_file,
|
|
97
|
+
url: f.file,
|
|
98
|
+
})),
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
const getActiveVideoVisits = validation_1.validateFunction(zod_1.tuple([]), zod_1.array(schemas_1.doc24Schemas.activeVideoVisitData), async () => {
|
|
102
|
+
const path = '/active-video-visits';
|
|
103
|
+
const response = await makeRequest('GET', path);
|
|
104
|
+
const consultations = response.data['active-consultations'];
|
|
105
|
+
return consultations.map((s) => ({
|
|
106
|
+
patientId: s.patient_id,
|
|
107
|
+
consultationId: s.consultation_id,
|
|
108
|
+
vcToken: s.vc_token,
|
|
109
|
+
}));
|
|
110
|
+
});
|
|
111
|
+
const getVideoVisitLink = validation_1.validateFunction(zod_1.tuple([zod_1.string(), zod_1.number()]), zod_1.string().nullable(), async (vcToken, patientId) => {
|
|
112
|
+
const path = `/video-visit-link/${vcToken}/${patientId}`;
|
|
113
|
+
const response = await makeRequest('GET', path);
|
|
114
|
+
return response.data.link;
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
scheduleVideoVisit,
|
|
118
|
+
cancelVideoVisit,
|
|
119
|
+
getVideoVisit,
|
|
120
|
+
getPatientVideoVisitHistory,
|
|
121
|
+
getVideoVisitDetails,
|
|
122
|
+
getVideoVisitLink,
|
|
123
|
+
getActiveVideoVisits,
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
exports.getVideoVisitMethods = getVideoVisitMethods;
|
|
127
|
+
const mapVideoVisit = (raw) => {
|
|
128
|
+
var _a, _b, _c;
|
|
129
|
+
return {
|
|
130
|
+
id: raw.vc_id,
|
|
131
|
+
creationDate: utils_1.parseDateTime(raw.creation_date),
|
|
132
|
+
patientId: raw.patient_id,
|
|
133
|
+
user: { id: raw.user_id, email: raw.email, phone: raw.phone },
|
|
134
|
+
vcToken: raw.vc_token,
|
|
135
|
+
appointment: raw.appointment_id
|
|
136
|
+
? {
|
|
137
|
+
id: raw.appointment_id,
|
|
138
|
+
date: utils_1.parseDateTime(`${raw.appointment_date} ${raw.appointment_time}`, raw.time_zone),
|
|
139
|
+
}
|
|
140
|
+
: undefined,
|
|
141
|
+
videoVisit: raw.video_visit_id
|
|
142
|
+
? { id: raw.video_visit_id, status: raw.video_visit_status }
|
|
143
|
+
: undefined,
|
|
144
|
+
paymentStatus: (_a = raw.payment_status) !== null && _a !== void 0 ? _a : undefined,
|
|
145
|
+
atentionId: (_b = raw.atentionId) !== null && _b !== void 0 ? _b : undefined,
|
|
146
|
+
waitingTime: (_c = raw.waiting_time) !== null && _c !== void 0 ? _c : undefined,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
const mapHistoricalVideoVisit = (raw) => {
|
|
150
|
+
return {
|
|
151
|
+
...mapVideoVisit(raw),
|
|
152
|
+
professional: raw.professional,
|
|
153
|
+
specialty: raw.specialty,
|
|
154
|
+
};
|
|
155
|
+
};
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const parseDate: (str: string, timeZone?: string | null | undefined) => Date;
|
|
2
|
-
export declare const parseDateTime: (str: string, timeZone?: string | null | undefined) => Date;
|
|
1
|
+
export declare const parseDate: (str: string, timeZone?: string | null | undefined) => Date;
|
|
2
|
+
export declare const parseDateTime: (str: string, timeZone?: string | null | undefined) => Date;
|
package/lib/utils.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseDateTime = exports.parseDate = void 0;
|
|
4
|
-
const date_fns_1 = require("date-fns");
|
|
5
|
-
// import {Doc24} from '.';
|
|
6
|
-
const defaultTimeZone = '-03';
|
|
7
|
-
const parseDate = (str, timeZone) => exports.parseDateTime(`${str} 00:00:00`, timeZone);
|
|
8
|
-
exports.parseDate = parseDate;
|
|
9
|
-
const parseDateTime = (str, timeZone) => date_fns_1.parse(`${str} ${timeZone !== null && timeZone !== void 0 ? timeZone : defaultTimeZone}`, 'yyyy-MM-dd HH:mm:ss X', new Date());
|
|
10
|
-
exports.parseDateTime = parseDateTime;
|
|
11
|
-
// export const getIdetificationTypeId = (type: Doc24.IdentificationType) => {
|
|
12
|
-
// if (type === 'ndi') return 6;
|
|
13
|
-
// if (type === 'passport') return 5;
|
|
14
|
-
// if (type === 'credential') return 999;
|
|
15
|
-
// throw new Error('Invalid identificationType');
|
|
16
|
-
// };
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseDateTime = exports.parseDate = void 0;
|
|
4
|
+
const date_fns_1 = require("date-fns");
|
|
5
|
+
// import {Doc24} from '.';
|
|
6
|
+
const defaultTimeZone = '-03';
|
|
7
|
+
const parseDate = (str, timeZone) => exports.parseDateTime(`${str} 00:00:00`, timeZone);
|
|
8
|
+
exports.parseDate = parseDate;
|
|
9
|
+
const parseDateTime = (str, timeZone) => date_fns_1.parse(`${str} ${timeZone !== null && timeZone !== void 0 ? timeZone : defaultTimeZone}`, 'yyyy-MM-dd HH:mm:ss X', new Date());
|
|
10
|
+
exports.parseDateTime = parseDateTime;
|
|
11
|
+
// export const getIdetificationTypeId = (type: Doc24.IdentificationType) => {
|
|
12
|
+
// if (type === 'ndi') return 6;
|
|
13
|
+
// if (type === 'passport') return 5;
|
|
14
|
+
// if (type === 'credential') return 999;
|
|
15
|
+
// throw new Error('Invalid identificationType');
|
|
16
|
+
// };
|
package/lib/webhook/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Doc24 } from '../types';
|
|
2
|
-
export declare const getRequestHandler: (credentials: Doc24.SdkCredentials, baseSdk: Doc24.BaseSdk, eventHandlers: Doc24.Webhook.Events) => Doc24.Webhook.Handler;
|
|
1
|
+
import { Doc24 } from '../types';
|
|
2
|
+
export declare const getRequestHandler: (credentials: Doc24.SdkCredentials, baseSdk: Doc24.BaseSdk, eventHandlers: Doc24.Webhook.Events) => Doc24.Webhook.Handler;
|
package/lib/webhook/index.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRequestHandler = void 0;
|
|
4
|
-
const token_1 = require("./token");
|
|
5
|
-
const responses_1 = require("./responses");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
7
|
-
const getRequestHandler = (credentials, baseSdk, eventHandlers) => async (request) => {
|
|
8
|
-
const tokenPayload = await token_1.getWebhookToken(request, credentials);
|
|
9
|
-
if (!tokenPayload)
|
|
10
|
-
return responses_1.unauthorizedErrorResponse();
|
|
11
|
-
const body = request.body;
|
|
12
|
-
const error = await handleEvent(body, baseSdk, eventHandlers);
|
|
13
|
-
if (error)
|
|
14
|
-
return responses_1.unexpectedErrorResponse(error);
|
|
15
|
-
return responses_1.successResponse();
|
|
16
|
-
return responses_1.notFoundErrorResponse();
|
|
17
|
-
};
|
|
18
|
-
exports.getRequestHandler = getRequestHandler;
|
|
19
|
-
const handleEvent = async (body, _baseSdk, eventHandlers) => {
|
|
20
|
-
var _a, _b, _c, _d;
|
|
21
|
-
const date = utils_1.parseDateTime(body.fecha_estado);
|
|
22
|
-
if (body.tipo === 'consulta')
|
|
23
|
-
return (_a = eventHandlers.onConsultationStatusChange) === null || _a === void 0 ? void 0 : _a.call(eventHandlers, {
|
|
24
|
-
id: Number(body.id_consulta_virtual),
|
|
25
|
-
invitationId: Number(body.id_invitacion),
|
|
26
|
-
status: body.id_estado,
|
|
27
|
-
changeDate: date,
|
|
28
|
-
vcToken: body.vc_token,
|
|
29
|
-
patientId: body.id_paciente !== undefined ? Number(body.id_paciente) : undefined,
|
|
30
|
-
});
|
|
31
|
-
if (body.tipo === 'invitacion')
|
|
32
|
-
return (_b = eventHandlers.onInvitationStatusChange) === null || _b === void 0 ? void 0 : _b.call(eventHandlers, {
|
|
33
|
-
status: body.id_estado,
|
|
34
|
-
changeDate: date,
|
|
35
|
-
vcToken: body.vc_token,
|
|
36
|
-
appointmentId: Number(body.id_turno),
|
|
37
|
-
patientId: Number(body.id_persona),
|
|
38
|
-
professionalId: Number(body.id_profesional),
|
|
39
|
-
});
|
|
40
|
-
if (body.tipo === 'turno')
|
|
41
|
-
return (_c = eventHandlers.onAppointmentStatusChange) === null || _c === void 0 ? void 0 : _c.call(eventHandlers, {
|
|
42
|
-
id: Number(body.id_turno),
|
|
43
|
-
status: body.id_estado,
|
|
44
|
-
vcToken: body.vc_token,
|
|
45
|
-
changeDate: date,
|
|
46
|
-
});
|
|
47
|
-
if (body.tipo === 'chat')
|
|
48
|
-
return (_d = eventHandlers.onChatUpdate) === null || _d === void 0 ? void 0 : _d.call(eventHandlers, {
|
|
49
|
-
id: Number(body.id_consulta_chat),
|
|
50
|
-
status: body.estado_chat === 'A' ? 'active' : 'ended',
|
|
51
|
-
patientId: Number(body.id_paciente),
|
|
52
|
-
professionalId: Number(body.id_profesional),
|
|
53
|
-
date,
|
|
54
|
-
});
|
|
55
|
-
return 'message_not_understood';
|
|
56
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRequestHandler = void 0;
|
|
4
|
+
const token_1 = require("./token");
|
|
5
|
+
const responses_1 = require("./responses");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const getRequestHandler = (credentials, baseSdk, eventHandlers) => async (request) => {
|
|
8
|
+
const tokenPayload = await token_1.getWebhookToken(request, credentials);
|
|
9
|
+
if (!tokenPayload)
|
|
10
|
+
return responses_1.unauthorizedErrorResponse();
|
|
11
|
+
const body = request.body;
|
|
12
|
+
const error = await handleEvent(body, baseSdk, eventHandlers);
|
|
13
|
+
if (error)
|
|
14
|
+
return responses_1.unexpectedErrorResponse(error);
|
|
15
|
+
return responses_1.successResponse();
|
|
16
|
+
return responses_1.notFoundErrorResponse();
|
|
17
|
+
};
|
|
18
|
+
exports.getRequestHandler = getRequestHandler;
|
|
19
|
+
const handleEvent = async (body, _baseSdk, eventHandlers) => {
|
|
20
|
+
var _a, _b, _c, _d;
|
|
21
|
+
const date = utils_1.parseDateTime(body.fecha_estado);
|
|
22
|
+
if (body.tipo === 'consulta')
|
|
23
|
+
return (_a = eventHandlers.onConsultationStatusChange) === null || _a === void 0 ? void 0 : _a.call(eventHandlers, {
|
|
24
|
+
id: Number(body.id_consulta_virtual),
|
|
25
|
+
invitationId: Number(body.id_invitacion),
|
|
26
|
+
status: body.id_estado,
|
|
27
|
+
changeDate: date,
|
|
28
|
+
vcToken: body.vc_token,
|
|
29
|
+
patientId: body.id_paciente !== undefined ? Number(body.id_paciente) : undefined,
|
|
30
|
+
});
|
|
31
|
+
if (body.tipo === 'invitacion')
|
|
32
|
+
return (_b = eventHandlers.onInvitationStatusChange) === null || _b === void 0 ? void 0 : _b.call(eventHandlers, {
|
|
33
|
+
status: body.id_estado,
|
|
34
|
+
changeDate: date,
|
|
35
|
+
vcToken: body.vc_token,
|
|
36
|
+
appointmentId: Number(body.id_turno),
|
|
37
|
+
patientId: Number(body.id_persona),
|
|
38
|
+
professionalId: Number(body.id_profesional),
|
|
39
|
+
});
|
|
40
|
+
if (body.tipo === 'turno')
|
|
41
|
+
return (_c = eventHandlers.onAppointmentStatusChange) === null || _c === void 0 ? void 0 : _c.call(eventHandlers, {
|
|
42
|
+
id: Number(body.id_turno),
|
|
43
|
+
status: body.id_estado,
|
|
44
|
+
vcToken: body.vc_token,
|
|
45
|
+
changeDate: date,
|
|
46
|
+
});
|
|
47
|
+
if (body.tipo === 'chat')
|
|
48
|
+
return (_d = eventHandlers.onChatUpdate) === null || _d === void 0 ? void 0 : _d.call(eventHandlers, {
|
|
49
|
+
id: Number(body.id_consulta_chat),
|
|
50
|
+
status: body.estado_chat === 'A' ? 'active' : 'ended',
|
|
51
|
+
patientId: Number(body.id_paciente),
|
|
52
|
+
professionalId: Number(body.id_profesional),
|
|
53
|
+
date,
|
|
54
|
+
});
|
|
55
|
+
return 'message_not_understood';
|
|
56
|
+
};
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
export declare const notFoundErrorResponse: () => {
|
|
2
|
-
status: {
|
|
3
|
-
code: number;
|
|
4
|
-
message: string;
|
|
5
|
-
};
|
|
6
|
-
data: {
|
|
7
|
-
error: string;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export declare const unauthorizedErrorResponse: () => {
|
|
11
|
-
status: {
|
|
12
|
-
code: number;
|
|
13
|
-
message: string;
|
|
14
|
-
};
|
|
15
|
-
data: {
|
|
16
|
-
error: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export declare const unexpectedErrorResponse: (details?: unknown) => {
|
|
20
|
-
status: {
|
|
21
|
-
code: number;
|
|
22
|
-
message: string;
|
|
23
|
-
};
|
|
24
|
-
data: {
|
|
25
|
-
error: string;
|
|
26
|
-
details: unknown;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
export declare const successResponse: (data?: unknown) => {
|
|
30
|
-
status: {
|
|
31
|
-
code: number;
|
|
32
|
-
message: string;
|
|
33
|
-
};
|
|
34
|
-
data: unknown;
|
|
35
|
-
};
|
|
1
|
+
export declare const notFoundErrorResponse: () => {
|
|
2
|
+
status: {
|
|
3
|
+
code: number;
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
data: {
|
|
7
|
+
error: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const unauthorizedErrorResponse: () => {
|
|
11
|
+
status: {
|
|
12
|
+
code: number;
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
15
|
+
data: {
|
|
16
|
+
error: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare const unexpectedErrorResponse: (details?: unknown) => {
|
|
20
|
+
status: {
|
|
21
|
+
code: number;
|
|
22
|
+
message: string;
|
|
23
|
+
};
|
|
24
|
+
data: {
|
|
25
|
+
error: string;
|
|
26
|
+
details: unknown;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export declare const successResponse: (data?: unknown) => {
|
|
30
|
+
status: {
|
|
31
|
+
code: number;
|
|
32
|
+
message: string;
|
|
33
|
+
};
|
|
34
|
+
data: unknown;
|
|
35
|
+
};
|
package/lib/webhook/responses.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.successResponse = exports.unexpectedErrorResponse = exports.unauthorizedErrorResponse = exports.notFoundErrorResponse = void 0;
|
|
4
|
-
const notFoundErrorResponse = () => ({
|
|
5
|
-
status: {
|
|
6
|
-
code: 404,
|
|
7
|
-
message: 'Not Found',
|
|
8
|
-
},
|
|
9
|
-
data: {
|
|
10
|
-
error: 'not_found',
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
exports.notFoundErrorResponse = notFoundErrorResponse;
|
|
14
|
-
const unauthorizedErrorResponse = () => ({
|
|
15
|
-
status: {
|
|
16
|
-
code: 401,
|
|
17
|
-
message: 'Unauthorized',
|
|
18
|
-
},
|
|
19
|
-
data: {
|
|
20
|
-
error: 'unauthorized',
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
exports.unauthorizedErrorResponse = unauthorizedErrorResponse;
|
|
24
|
-
const unexpectedErrorResponse = (details) => ({
|
|
25
|
-
status: {
|
|
26
|
-
code: 500,
|
|
27
|
-
message: 'Unhandled Error',
|
|
28
|
-
},
|
|
29
|
-
data: {
|
|
30
|
-
error: 'unhandled_error',
|
|
31
|
-
details,
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
exports.unexpectedErrorResponse = unexpectedErrorResponse;
|
|
35
|
-
const successResponse = (data) => ({
|
|
36
|
-
status: {
|
|
37
|
-
code: 200,
|
|
38
|
-
message: 'Success',
|
|
39
|
-
},
|
|
40
|
-
data,
|
|
41
|
-
});
|
|
42
|
-
exports.successResponse = successResponse;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.successResponse = exports.unexpectedErrorResponse = exports.unauthorizedErrorResponse = exports.notFoundErrorResponse = void 0;
|
|
4
|
+
const notFoundErrorResponse = () => ({
|
|
5
|
+
status: {
|
|
6
|
+
code: 404,
|
|
7
|
+
message: 'Not Found',
|
|
8
|
+
},
|
|
9
|
+
data: {
|
|
10
|
+
error: 'not_found',
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
exports.notFoundErrorResponse = notFoundErrorResponse;
|
|
14
|
+
const unauthorizedErrorResponse = () => ({
|
|
15
|
+
status: {
|
|
16
|
+
code: 401,
|
|
17
|
+
message: 'Unauthorized',
|
|
18
|
+
},
|
|
19
|
+
data: {
|
|
20
|
+
error: 'unauthorized',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
exports.unauthorizedErrorResponse = unauthorizedErrorResponse;
|
|
24
|
+
const unexpectedErrorResponse = (details) => ({
|
|
25
|
+
status: {
|
|
26
|
+
code: 500,
|
|
27
|
+
message: 'Unhandled Error',
|
|
28
|
+
},
|
|
29
|
+
data: {
|
|
30
|
+
error: 'unhandled_error',
|
|
31
|
+
details,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
exports.unexpectedErrorResponse = unexpectedErrorResponse;
|
|
35
|
+
const successResponse = (data) => ({
|
|
36
|
+
status: {
|
|
37
|
+
code: 200,
|
|
38
|
+
message: 'Success',
|
|
39
|
+
},
|
|
40
|
+
data,
|
|
41
|
+
});
|
|
42
|
+
exports.successResponse = successResponse;
|
package/lib/webhook/token.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Doc24 } from '../types';
|
|
2
|
-
export declare const getWebhookToken: (request: Doc24.Webhook.Request, credentials: Doc24.SdkCredentials) => Promise<Record<string, unknown> | undefined>;
|
|
1
|
+
import { Doc24 } from '../types';
|
|
2
|
+
export declare const getWebhookToken: (request: Doc24.Webhook.Request, credentials: Doc24.SdkCredentials) => Promise<Record<string, unknown> | undefined>;
|