@integraciones_doc24/sdk 0.39.7 → 0.39.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.
@@ -2,7 +2,6 @@ import { RequestMaker } from '../request';
2
2
  export declare const getScheduleMethods: (makeRequest: RequestMaker) => {
3
3
  getSchedule: (patientId: number, specialtyId: number, filter?: {
4
4
  date?: Date | undefined;
5
- language?: string | undefined;
6
5
  professionalId?: number | undefined;
7
6
  offset?: number | undefined;
8
7
  limit?: number | undefined;
@@ -12,7 +11,6 @@ export declare const getScheduleMethods: (makeRequest: RequestMaker) => {
12
11
  } | undefined) => Promise<{
13
12
  length?: number | null | undefined;
14
13
  ranking?: unknown;
15
- consultation_value?: string | null | undefined;
16
14
  date: Date;
17
15
  type: "appointment" | "chat" | "instant";
18
16
  id: string | number;
@@ -21,17 +19,16 @@ export declare const getScheduleMethods: (makeRequest: RequestMaker) => {
21
19
  fullName: string;
22
20
  logoUrl: string;
23
21
  };
22
+ clinicId: number;
23
+ cost: string;
24
24
  specialty: {
25
25
  id: number;
26
26
  description: string;
27
27
  };
28
- clinicId: number;
29
- cost: string;
30
28
  atentions: number;
31
29
  }[]>;
32
30
  getScheduleDates: (patientId: number, filter?: {
33
31
  specialtyId?: number | undefined;
34
- language?: string | undefined;
35
32
  professionalId?: number | undefined;
36
33
  } | undefined) => Promise<Date[]>;
37
34
  getAppointment: (appointmentId: number) => Promise<{
@@ -7,19 +7,16 @@ const validation_1 = require("../request/validation");
7
7
  const schemas_1 = require("../schemas");
8
8
  const utils_1 = require("../utils");
9
9
  const getScheduleMethods = (makeRequest) => {
10
- const getScheduleDates = async (patientId, filter = {}) => {
11
- var _a;
10
+ const getScheduleDates = validation_1.validateFunction(zod_1.tuple([zod_1.number(), schemas_1.doc24Schemas.scheduleAvailabilityFilter]), zod_1.array(zod_1.date()), async (patientId, filter = {}) => {
12
11
  const mappedFilter = {
13
12
  specialty_id: filter.specialtyId,
14
13
  professional_id: filter.professionalId,
15
- language: (_a = filter.language) !== null && _a !== void 0 ? _a : 'ES',
16
14
  };
17
15
  const path = `/schedule/dates/${patientId}/${JSON.stringify(mappedFilter)}`;
18
16
  const response = await makeRequest('GET', path);
19
- return response.data.available_dates.map((o) => utils_1.parseDate(o.date, o.time_zone));
20
- };
21
- const getSchedule = async (patientId, specialtyId, filter = {}) => {
22
- var _a;
17
+ return response.data.available_dates.map((o) => utils_1.parseDate(o.date));
18
+ });
19
+ const getSchedule = validation_1.validateFunction(zod_1.tuple([zod_1.number(), zod_1.number(), schemas_1.doc24Schemas.scheduleFilter.optional()]), zod_1.array(schemas_1.doc24Schemas.availableAppointment), async (patientId, specialtyId, filter = {}) => {
23
20
  const mappedFilter = {
24
21
  id_professional: filter.professionalId,
25
22
  offset: filter.offset,
@@ -28,13 +25,12 @@ const getScheduleMethods = (makeRequest) => {
28
25
  date: filter.date && date_fns_1.format(filter.date, 'yyyy-MM-dd'),
29
26
  start_hour: filter.startHour,
30
27
  finish_hour: filter.finishHour,
31
- language: (_a = filter.language) !== null && _a !== void 0 ? _a : 'ES',
32
28
  };
33
29
  const path = `/schedule/availability/${patientId}/${specialtyId}/${JSON.stringify(mappedFilter)}`;
34
30
  const response = await makeRequest('GET', path);
35
31
  return response.data.available_appointments.map((a) => ({
36
32
  id: a.id,
37
- date: utils_1.parseDateTime(`${a.date} ${a.hour}`, a.time_zone),
33
+ date: utils_1.parseDateTime(`${a.date} ${a.hour}`),
38
34
  clinicId: a.clinic,
39
35
  professional: {
40
36
  id: a.professional_id,
@@ -50,32 +46,31 @@ const getScheduleMethods = (makeRequest) => {
50
46
  atentions: a.atentions,
51
47
  ranking: a.ranking,
52
48
  length: a.length,
53
- consultation_value: a.consultation_value,
54
49
  }));
55
- };
56
- const getAppointment = async (appointmentId) => {
50
+ });
51
+ const getAppointment = validation_1.validateFunction(zod_1.tuple([zod_1.number()]), schemas_1.doc24Schemas.appointment, async (appointmentId) => {
57
52
  const path = `/appointment/${appointmentId}`;
58
53
  const response = await makeRequest('GET', path);
59
54
  return {
60
55
  id: response.data.id,
61
56
  professionalId: response.data.professional_id,
62
- date: utils_1.parseDateTime(`${response.data.date} ${response.data.hour}`, response.data.time_zone),
57
+ date: utils_1.parseDateTime(`${response.data.date} ${response.data.hour}`),
63
58
  };
64
- };
65
- const getAppointmentByVcToken = async (vcToken) => {
59
+ });
60
+ const getAppointmentByVcToken = validation_1.validateFunction(zod_1.tuple([zod_1.string()]), schemas_1.doc24Schemas.appointment, async (vcToken) => {
66
61
  const path = `/appointmentByToken/${vcToken}`;
67
62
  const response = await makeRequest('GET', path);
68
63
  return {
69
64
  id: response.data.id,
70
65
  professionalId: response.data.professional_id,
71
- date: utils_1.parseDateTime(`${response.data.date} ${response.data.hour}`, response.data.time_zone),
66
+ date: utils_1.parseDateTime(`${response.data.date} ${response.data.hour}`),
72
67
  };
73
- };
68
+ });
74
69
  return {
75
- getSchedule: validation_1.validateFunction(zod_1.tuple([zod_1.number(), zod_1.number(), schemas_1.doc24Schemas.scheduleFilter.optional()]), zod_1.array(schemas_1.doc24Schemas.availableAppointment), getSchedule),
76
- getScheduleDates: validation_1.validateFunction(zod_1.tuple([zod_1.number(), schemas_1.doc24Schemas.scheduleAvailabilityFilter]), zod_1.array(zod_1.date()), getScheduleDates),
77
- getAppointment: validation_1.validateFunction(zod_1.tuple([zod_1.number()]), schemas_1.doc24Schemas.appointment, getAppointment),
78
- getAppointmentByVcToken: validation_1.validateFunction(zod_1.tuple([zod_1.string()]), schemas_1.doc24Schemas.appointment, getAppointmentByVcToken),
70
+ getSchedule,
71
+ getScheduleDates,
72
+ getAppointment,
73
+ getAppointmentByVcToken,
79
74
  };
80
75
  };
81
76
  exports.getScheduleMethods = getScheduleMethods;
@@ -32,9 +32,9 @@ export declare const getVideoVisitMethods: (makeRequest: RequestMaker) => {
32
32
  patientId: number;
33
33
  creationDate: Date;
34
34
  user: {
35
+ id: number;
35
36
  phone: string | null;
36
37
  email: string | null;
37
- id: number;
38
38
  };
39
39
  vcToken: string;
40
40
  }>;
@@ -51,15 +51,13 @@ export declare const getVideoVisitMethods: (makeRequest: RequestMaker) => {
51
51
  atentionId?: number | undefined;
52
52
  id: number | null;
53
53
  patientId: number;
54
- professional: string;
55
54
  creationDate: Date;
56
55
  user: {
56
+ id: number;
57
57
  phone: string | null;
58
58
  email: string | null;
59
- id: number;
60
59
  };
61
60
  vcToken: string;
62
- specialty: string;
63
61
  }[]>;
64
62
  getVideoVisitDetails: (vcId: number) => Promise<{
65
63
  professional?: {
@@ -33,10 +33,10 @@ const getVideoVisitMethods = (makeRequest) => {
33
33
  const response = await makeRequest('GET', path);
34
34
  return mapVideoVisit(response.data);
35
35
  });
36
- const getPatientVideoVisitHistory = validation_1.validateFunction(zod_1.tuple([zod_1.number()]), zod_1.array(schemas_1.doc24Schemas.historicalVideoVisit), async (patientId) => {
36
+ const getPatientVideoVisitHistory = validation_1.validateFunction(zod_1.tuple([zod_1.number()]), zod_1.array(schemas_1.doc24Schemas.videoVisit), async (patientId) => {
37
37
  const path = `/video-visit-history/${patientId}`;
38
38
  const response = await makeRequest('GET', path);
39
- return response.data.map((raw) => mapHistoricalVideoVisit(raw));
39
+ return response.data.map((raw) => mapVideoVisit(raw));
40
40
  });
41
41
  const getVideoVisitDetails = validation_1.validateFunction(zod_1.tuple([zod_1.number()]), schemas_1.doc24Schemas.videoVisitDetails, async (vcId) => {
42
42
  const path = `/video-visit-records/${vcId}`;
@@ -65,7 +65,7 @@ const getVideoVisitMethods = (makeRequest) => {
65
65
  appointment: response.data.appointment_id
66
66
  ? {
67
67
  id: response.data.appointment_id,
68
- date: utils_1.parseDateTime(`${response.data.appointment_date} ${response.data.appointment_time}`, response.data.time_zone),
68
+ date: utils_1.parseDateTime(`${response.data.appointment_date} ${response.data.appointment_time}`),
69
69
  }
70
70
  : null,
71
71
  report: {
@@ -135,7 +135,7 @@ const mapVideoVisit = (raw) => {
135
135
  appointment: raw.appointment_id
136
136
  ? {
137
137
  id: raw.appointment_id,
138
- date: utils_1.parseDateTime(`${raw.appointment_date} ${raw.appointment_time}`, raw.time_zone),
138
+ date: utils_1.parseDateTime(`${raw.appointment_date} ${raw.appointment_time}`),
139
139
  }
140
140
  : undefined,
141
141
  videoVisit: raw.video_visit_id
@@ -145,10 +145,3 @@ const mapVideoVisit = (raw) => {
145
145
  atentionId: (_b = raw.atentionId) !== null && _b !== void 0 ? _b : undefined,
146
146
  };
147
147
  };
148
- const mapHistoricalVideoVisit = (raw) => {
149
- return {
150
- ...mapVideoVisit(raw),
151
- professional: raw.professional,
152
- specialty: raw.specialty,
153
- };
154
- };
package/lib/utils.d.ts CHANGED
@@ -1,2 +1,4 @@
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
+ import { Doc24 } from '.';
2
+ export declare const parseDate: (str: string) => Date;
3
+ export declare const parseDateTime: (str: string) => Date;
4
+ export declare const getIndetificationTypeId: (type: Doc24.IdentificationType) => 1 | 6 | 5 | 999 | 1000 | 9 | 7;
package/lib/utils.js CHANGED
@@ -1,16 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseDateTime = exports.parseDate = void 0;
3
+ exports.getIndetificationTypeId = exports.parseDateTime = exports.parseDate = void 0;
4
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);
5
+ const timeZone = '-03';
6
+ const parseDate = (str) => exports.parseDateTime(`${str} 00:00:00`);
8
7
  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());
8
+ const parseDateTime = (str) => date_fns_1.parse(`${str} ${timeZone}`, 'yyyy-MM-dd HH:mm:ss X', new Date());
10
9
  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
- // };
10
+ const getIndetificationTypeId = (type) => {
11
+ if (type === 'dni')
12
+ return 1;
13
+ if (type === 'ndi')
14
+ return 6;
15
+ if (type === 'passport')
16
+ return 5;
17
+ if (type === 'credential')
18
+ return 999;
19
+ if (type === 'nn')
20
+ return 1000;
21
+ if (type === 'cpf')
22
+ return 9;
23
+ if (type === 'rg')
24
+ return 7;
25
+ throw new Error('Invalid identificationType');
26
+ };
27
+ exports.getIndetificationTypeId = getIndetificationTypeId;
@@ -41,7 +41,6 @@ const handleEvent = async (body, _baseSdk, eventHandlers) => {
41
41
  return (_c = eventHandlers.onAppointmentStatusChange) === null || _c === void 0 ? void 0 : _c.call(eventHandlers, {
42
42
  id: Number(body.id_turno),
43
43
  status: body.id_estado,
44
- vcToken: body.vc_token,
45
44
  changeDate: date,
46
45
  });
47
46
  if (body.tipo === 'chat')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@integraciones_doc24/sdk",
3
- "version": "0.39.7",
3
+ "version": "0.39.8",
4
4
  "publishConfig": {
5
5
  "tag": "0.x"
6
6
  },
@@ -32,4 +32,4 @@
32
32
  "files": [
33
33
  "lib"
34
34
  ]
35
- }
35
+ }
@@ -1,177 +0,0 @@
1
- import { RequestMaker } from '../request';
2
- export declare const getExternalMethods: (makeRequest: RequestMaker) => {
3
- externalLogin: (params: {
4
- user: string;
5
- password: string;
6
- }) => Promise<{
7
- gender?: "m" | "f" | "o" | undefined;
8
- firstName: string;
9
- lastName: string;
10
- countryId: string;
11
- phone: string;
12
- email: string;
13
- birthday: Date;
14
- identificationNumber: string;
15
- }>;
16
- preExternalEnrollment: (params: ({
17
- birthdate: Date;
18
- identificationNumber: string;
19
- } & {
20
- phone: string;
21
- email: string;
22
- }) | ({
23
- birthdate: Date;
24
- identificationNumber: string;
25
- } & {
26
- phone?: undefined;
27
- email: string;
28
- }) | ({
29
- birthdate: Date;
30
- identificationNumber: string;
31
- } & {
32
- email?: undefined;
33
- phone: string;
34
- })) => Promise<void>;
35
- externalEnrollment: (params: ({
36
- birthdate: Date;
37
- identificationNumber: string;
38
- } & {
39
- phone: string;
40
- email: string;
41
- } & {
42
- password: string;
43
- } & {
44
- emailCode: string;
45
- phoneCode: string;
46
- }) | ({
47
- birthdate: Date;
48
- identificationNumber: string;
49
- } & {
50
- phone: string;
51
- email: string;
52
- } & {
53
- password: string;
54
- } & {
55
- phoneCode?: undefined;
56
- emailCode: string;
57
- }) | ({
58
- birthdate: Date;
59
- identificationNumber: string;
60
- } & {
61
- phone: string;
62
- email: string;
63
- } & {
64
- password: string;
65
- } & {
66
- emailCode?: undefined;
67
- phoneCode: string;
68
- }) | ({
69
- birthdate: Date;
70
- identificationNumber: string;
71
- } & {
72
- phone?: undefined;
73
- email: string;
74
- } & {
75
- password: string;
76
- } & {
77
- emailCode: string;
78
- phoneCode: string;
79
- }) | ({
80
- birthdate: Date;
81
- identificationNumber: string;
82
- } & {
83
- phone?: undefined;
84
- email: string;
85
- } & {
86
- password: string;
87
- } & {
88
- phoneCode?: undefined;
89
- emailCode: string;
90
- }) | ({
91
- birthdate: Date;
92
- identificationNumber: string;
93
- } & {
94
- phone?: undefined;
95
- email: string;
96
- } & {
97
- password: string;
98
- } & {
99
- emailCode?: undefined;
100
- phoneCode: string;
101
- }) | ({
102
- birthdate: Date;
103
- identificationNumber: string;
104
- } & {
105
- email?: undefined;
106
- phone: string;
107
- } & {
108
- password: string;
109
- } & {
110
- emailCode: string;
111
- phoneCode: string;
112
- }) | ({
113
- birthdate: Date;
114
- identificationNumber: string;
115
- } & {
116
- email?: undefined;
117
- phone: string;
118
- } & {
119
- password: string;
120
- } & {
121
- phoneCode?: undefined;
122
- emailCode: string;
123
- }) | ({
124
- birthdate: Date;
125
- identificationNumber: string;
126
- } & {
127
- email?: undefined;
128
- phone: string;
129
- } & {
130
- password: string;
131
- } & {
132
- emailCode?: undefined;
133
- phoneCode: string;
134
- })) => Promise<{
135
- gender?: "m" | "f" | "o" | undefined;
136
- firstName: string;
137
- lastName: string;
138
- countryId: string;
139
- phone: string;
140
- email: string;
141
- birthday: Date;
142
- identificationNumber: string;
143
- }>;
144
- sendExternalVerificationCode: (params: {
145
- birthdate: Date;
146
- channel: "1" | "2";
147
- identificationNumber: string;
148
- }) => Promise<void>;
149
- verifyExternalVerificationCode: (params: {
150
- code: string;
151
- birthdate: Date;
152
- channel: "1" | "2";
153
- identificationNumber: string;
154
- }) => Promise<any>;
155
- externalResetPassword: (params: ({
156
- birthdate: Date;
157
- password: string;
158
- identificationNumber: string;
159
- } & {
160
- emailCode: string;
161
- phoneCode: string;
162
- }) | ({
163
- birthdate: Date;
164
- password: string;
165
- identificationNumber: string;
166
- } & {
167
- phoneCode?: undefined;
168
- emailCode: string;
169
- }) | ({
170
- birthdate: Date;
171
- password: string;
172
- identificationNumber: string;
173
- } & {
174
- emailCode?: undefined;
175
- phoneCode: string;
176
- })) => Promise<any>;
177
- };
@@ -1,96 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExternalMethods = void 0;
4
- const date_fns_1 = require("date-fns");
5
- const zod_1 = require("zod");
6
- const validation_1 = require("../request/validation");
7
- const schemas_1 = require("../schemas");
8
- const getExternalMethods = (makeRequest) => {
9
- const externalLogin = async ({ user, password, }) => {
10
- const path = '/external-login';
11
- const response = await makeRequest('POST', path, { user, password });
12
- const info = response.data.login_info;
13
- return {
14
- firstName: info.firstname,
15
- lastName: info.lastname,
16
- countryId: info.country_id,
17
- birthday: new Date(Date.parse(info.birthdate)),
18
- identificationNumber: info.identification_number,
19
- gender: info.gender.toLowerCase(),
20
- email: info.email,
21
- phone: info.telephone,
22
- };
23
- };
24
- const preExternalEnrollment = async (params) => {
25
- const path = '/pre-external-enrollment';
26
- await makeRequest('POST', path, {
27
- identification_number: params.identificationNumber,
28
- birthdate: date_fns_1.format(params.birthdate, 'yyyy-MM-dd'),
29
- email: params.email,
30
- telephone: params.phone,
31
- });
32
- return;
33
- };
34
- const externalEnrollment = async (params) => {
35
- const path = '/external-enrollment';
36
- const response = await makeRequest('POST', path, {
37
- identification_number: params.identificationNumber,
38
- birthdate: date_fns_1.format(params.birthdate, 'yyyy-MM-dd'),
39
- email: params.email,
40
- telephone: params.phone,
41
- password: params.password,
42
- email_code: params.emailCode,
43
- telephone_code: params.phoneCode,
44
- });
45
- const info = response.data.info;
46
- return {
47
- firstName: info.firstname,
48
- lastName: info.lastname,
49
- countryId: info.country_id,
50
- birthday: new Date(Date.parse(info.birthdate)),
51
- identificationNumber: info.identification_number,
52
- gender: info.gender.toLowerCase(),
53
- email: info.email,
54
- phone: info.telephone,
55
- };
56
- };
57
- const sendExternalVerificationCode = async (params) => {
58
- const path = '/send-external-verification-code';
59
- await makeRequest('POST', path, {
60
- identification_number: params.identificationNumber,
61
- birthdate: date_fns_1.format(params.birthdate, 'yyyy-MM-dd'),
62
- channel: params.channel,
63
- });
64
- return;
65
- };
66
- const verifyExternalVerificationCode = async (params) => {
67
- const path = '/verify-external-verification-code';
68
- const response = await makeRequest('POST', path, {
69
- identification_number: params.identificationNumber,
70
- birthdate: date_fns_1.format(params.birthdate, 'yyyy-MM-dd'),
71
- channel: params.channel,
72
- code: params.code,
73
- });
74
- return response.data;
75
- };
76
- const externalResetPassword = async (params) => {
77
- const path = '/external-reset';
78
- const response = await makeRequest('POST', path, {
79
- identification_number: params.identificationNumber,
80
- birthdate: date_fns_1.format(params.birthdate, 'yyyy-MM-dd'),
81
- password: params.password,
82
- email_code: params.emailCode,
83
- telephone_code: params.phoneCode,
84
- });
85
- return response.data;
86
- };
87
- return {
88
- externalLogin: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.externalLoginParams]), schemas_1.doc24Schemas.externalLoginResponse, externalLogin),
89
- preExternalEnrollment: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.preExternalEnrollmentParams]), zod_1.void(), preExternalEnrollment),
90
- externalEnrollment: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.externalEnrollmentParams]), schemas_1.doc24Schemas.externalLoginResponse, externalEnrollment),
91
- sendExternalVerificationCode: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.sendExternalVerificationCodeParams]), zod_1.void(), sendExternalVerificationCode),
92
- verifyExternalVerificationCode: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.verifyExternalVerificationCodeParams]), zod_1.any(), verifyExternalVerificationCode),
93
- externalResetPassword: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.externalResetPasswordParams]), zod_1.any(), externalResetPassword),
94
- };
95
- };
96
- exports.getExternalMethods = getExternalMethods;
@@ -1,34 +0,0 @@
1
- import { RequestMaker } from '../request';
2
- export declare const getExternalMethods: (makeRequest: RequestMaker) => {
3
- getExternalStudiesHistoryLink: (patient: {
4
- gender?: "m" | "f" | "o" | undefined;
5
- identificationType: "DNI";
6
- identificationValue: string;
7
- birthdate: Date;
8
- }) => Promise<string | null>;
9
- getExternalAppointmentsLink: (identificationValue: string, birthdate: Date) => Promise<string | null>;
10
- getExternalAppointments: () => Promise<{
11
- patientIdentification?: string | undefined;
12
- date: Date;
13
- birthdate: Date;
14
- appointment: string;
15
- id: number;
16
- specialty: string;
17
- patientName: string;
18
- clinic: string;
19
- professionalName: string;
20
- modality: string;
21
- }[]>;
22
- cancelExternalAppointment: (appointmentId: {
23
- patientIdentification?: string | undefined;
24
- date: Date;
25
- birthdate: Date;
26
- appointment: string;
27
- id: number;
28
- specialty: string;
29
- patientName: string;
30
- clinic: string;
31
- professionalName: string;
32
- modality: string;
33
- }) => Promise<void>;
34
- };
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExternalMethods = void 0;
4
- const date_fns_1 = require("date-fns");
5
- const zod_1 = require("zod");
6
- const validation_1 = require("../request/validation");
7
- const schemas_1 = require("../schemas");
8
- const utils_1 = require("../utils");
9
- const getExternalMethods = (makeRequest) => {
10
- const getExternalStudiesHistoryLink = async (patient) => {
11
- var _a, _b;
12
- const path = '/history-external-studies';
13
- const response = await makeRequest('POST', path, {
14
- patient: mapPatientData(patient),
15
- });
16
- return (_b = (_a = response.data.info) === null || _a === void 0 ? void 0 : _a.link) !== null && _b !== void 0 ? _b : null;
17
- };
18
- const getExternalAppointmentsLink = async (identificationValue, birthdate) => {
19
- const path = `/external-appointments-link/${identificationValue}/${date_fns_1.format(birthdate, 'yyyy-MM-dd')}`;
20
- const response = await makeRequest('GET', path);
21
- return response.data.link;
22
- };
23
- const getExternalAppointments = async () => {
24
- const path = '/external-appointments';
25
- const response = await makeRequest('GET', path);
26
- return response.data.appointments.map((a) => ({
27
- id: a.appointment_id,
28
- patientIdentification: a.patient_id,
29
- patientName: a.patient_name,
30
- birthdate: utils_1.parseDate(a.birthdate),
31
- appointment: a.appointment,
32
- clinic: a.clinic,
33
- professionalName: a.professional,
34
- date: utils_1.parseDateTime(`${a.day} ${a.hour}:00`),
35
- specialty: a.specialty,
36
- modality: a.modality,
37
- }));
38
- };
39
- const cancelExternalAppointment = async (appointment) => {
40
- const path = `/cancel-external-appointment`;
41
- await makeRequest('POST', path, {
42
- appointment_id: appointment.id,
43
- patient_id: appointment.patientIdentification,
44
- patient_name: appointment.patientName,
45
- birthdate: date_fns_1.format(appointment.birthdate, 'yyyy-MM-dd'),
46
- appointment: appointment.appointment,
47
- clinic: appointment.clinic,
48
- professional: appointment.professionalName,
49
- day: date_fns_1.format(appointment.date, 'yyyy-MM-dd'),
50
- hour: date_fns_1.format(appointment.date, 'HH:mm'),
51
- specialty: appointment.specialty,
52
- modality: appointment.modality,
53
- });
54
- return;
55
- };
56
- return {
57
- getExternalStudiesHistoryLink: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.externalPatient]), zod_1.string().nullable(), getExternalStudiesHistoryLink),
58
- getExternalAppointmentsLink: validation_1.validateFunction(zod_1.tuple([zod_1.string(), zod_1.date()]), zod_1.string().nullable(), getExternalAppointmentsLink),
59
- getExternalAppointments: validation_1.validateFunction(zod_1.tuple([]), zod_1.array(schemas_1.doc24Schemas.externalAppointment), getExternalAppointments),
60
- cancelExternalAppointment: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.externalAppointment]), zod_1.void(), cancelExternalAppointment),
61
- };
62
- };
63
- exports.getExternalMethods = getExternalMethods;
64
- const mapPatientData = (patient) => {
65
- var _a;
66
- return {
67
- birthdate: date_fns_1.format(patient.birthdate, 'yyyy-MM-dd'),
68
- id_type: 'dni',
69
- id_value: patient.identificationValue,
70
- gender: (_a = patient.gender) === null || _a === void 0 ? void 0 : _a.toLocaleUpperCase(),
71
- };
72
- };