@integraciones_doc24/sdk 0.35.1 → 1.2.0

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.
Files changed (95) hide show
  1. package/README.md +131 -83
  2. package/lib/baseSdk/diagnostica.d.ts +6 -6
  3. package/lib/baseSdk/index.js +1 -5
  4. package/lib/baseSdk/user.d.ts +52 -4
  5. package/lib/baseSdk/user.js +67 -25
  6. package/lib/index.d.ts +45 -16
  7. package/lib/schemas.d.ts +236 -30
  8. package/lib/schemas.js +34 -2
  9. package/lib/test.js +36 -1
  10. package/lib/types.d.ts +11 -2
  11. package/lib/userSdk/chat.d.ts +1 -1
  12. package/lib/userSdk/patients.d.ts +23 -2
  13. package/lib/userSdk/patients.js +34 -6
  14. package/lib/userSdk/videoVisit.d.ts +2 -2
  15. package/lib/utils.d.ts +1 -1
  16. package/lib/utils.js +3 -3
  17. package/package.json +2 -2
  18. package/lib/lib/lib/lib/baseSdk/diagnostica.d.ts +0 -6
  19. package/lib/lib/lib/lib/baseSdk/diagnostica.js +0 -79
  20. package/lib/lib/lib/lib/baseSdk/index.d.ts +0 -14
  21. package/lib/lib/lib/lib/baseSdk/index.js +0 -66
  22. package/lib/lib/lib/lib/baseSdk/user.d.ts +0 -9
  23. package/lib/lib/lib/lib/baseSdk/user.js +0 -130
  24. package/lib/lib/lib/lib/index.d.ts +0 -58
  25. package/lib/lib/lib/lib/index.js +0 -22
  26. package/lib/lib/lib/lib/request/index.d.ts +0 -2
  27. package/lib/lib/lib/lib/request/index.js +0 -26
  28. package/lib/lib/lib/lib/request/token.d.ts +0 -2
  29. package/lib/lib/lib/lib/request/token.js +0 -34
  30. package/lib/lib/lib/lib/request/validation.d.ts +0 -10
  31. package/lib/lib/lib/lib/request/validation.js +0 -28
  32. package/lib/lib/lib/lib/schemas.d.ts +0 -1334
  33. package/lib/lib/lib/lib/schemas.js +0 -325
  34. package/lib/lib/lib/lib/test.d.ts +0 -1
  35. package/lib/lib/lib/lib/test.js +0 -55
  36. package/lib/lib/lib/lib/types.d.ts +0 -1
  37. package/lib/lib/lib/lib/types.js +0 -2
  38. package/lib/lib/lib/lib/userSdk/chat.d.ts +0 -9
  39. package/lib/lib/lib/lib/userSdk/chat.js +0 -98
  40. package/lib/lib/lib/lib/userSdk/index.d.ts +0 -24
  41. package/lib/lib/lib/lib/userSdk/index.js +0 -27
  42. package/lib/lib/lib/lib/userSdk/patients.d.ts +0 -5
  43. package/lib/lib/lib/lib/userSdk/patients.js +0 -55
  44. package/lib/lib/lib/lib/userSdk/schedule.d.ts +0 -7
  45. package/lib/lib/lib/lib/userSdk/schedule.js +0 -76
  46. package/lib/lib/lib/lib/userSdk/specialties.d.ts +0 -4
  47. package/lib/lib/lib/lib/userSdk/specialties.js +0 -19
  48. package/lib/lib/lib/lib/userSdk/videoVisit.d.ts +0 -10
  49. package/lib/lib/lib/lib/userSdk/videoVisit.js +0 -147
  50. package/lib/lib/lib/lib/utils.d.ts +0 -4
  51. package/lib/lib/lib/lib/utils.js +0 -19
  52. package/lib/lib/lib/lib/webhook/index.d.ts +0 -8
  53. package/lib/lib/lib/lib/webhook/index.js +0 -55
  54. package/lib/lib/lib/lib/webhook/responses.d.ts +0 -36
  55. package/lib/lib/lib/lib/webhook/responses.js +0 -42
  56. package/lib/lib/lib/lib/webhook/token.d.ts +0 -2
  57. package/lib/lib/lib/lib/webhook/token.js +0 -23
  58. package/lib/lib/lib/src/baseSdk/diagnostica.d.ts +0 -6
  59. package/lib/lib/lib/src/baseSdk/diagnostica.js +0 -79
  60. package/lib/lib/lib/src/baseSdk/index.d.ts +0 -51
  61. package/lib/lib/lib/src/baseSdk/index.js +0 -66
  62. package/lib/lib/lib/src/baseSdk/user.d.ts +0 -9
  63. package/lib/lib/lib/src/baseSdk/user.js +0 -130
  64. package/lib/lib/lib/src/index.d.ts +0 -169
  65. package/lib/lib/lib/src/index.js +0 -22
  66. package/lib/lib/lib/src/request/index.d.ts +0 -2
  67. package/lib/lib/lib/src/request/index.js +0 -26
  68. package/lib/lib/lib/src/request/token.d.ts +0 -2
  69. package/lib/lib/lib/src/request/token.js +0 -34
  70. package/lib/lib/lib/src/request/validation.d.ts +0 -10
  71. package/lib/lib/lib/src/request/validation.js +0 -28
  72. package/lib/lib/lib/src/schemas.d.ts +0 -1340
  73. package/lib/lib/lib/src/schemas.js +0 -325
  74. package/lib/lib/lib/src/types.d.ts +0 -1
  75. package/lib/lib/lib/src/types.js +0 -2
  76. package/lib/lib/lib/src/userSdk/chat.d.ts +0 -9
  77. package/lib/lib/lib/src/userSdk/chat.js +0 -98
  78. package/lib/lib/lib/src/userSdk/index.d.ts +0 -102
  79. package/lib/lib/lib/src/userSdk/index.js +0 -27
  80. package/lib/lib/lib/src/userSdk/patients.d.ts +0 -5
  81. package/lib/lib/lib/src/userSdk/patients.js +0 -55
  82. package/lib/lib/lib/src/userSdk/schedule.d.ts +0 -7
  83. package/lib/lib/lib/src/userSdk/schedule.js +0 -76
  84. package/lib/lib/lib/src/userSdk/specialties.d.ts +0 -4
  85. package/lib/lib/lib/src/userSdk/specialties.js +0 -19
  86. package/lib/lib/lib/src/userSdk/videoVisit.d.ts +0 -10
  87. package/lib/lib/lib/src/userSdk/videoVisit.js +0 -147
  88. package/lib/lib/lib/src/utils.d.ts +0 -4
  89. package/lib/lib/lib/src/utils.js +0 -19
  90. package/lib/lib/lib/src/webhook/index.d.ts +0 -8
  91. package/lib/lib/lib/src/webhook/index.js +0 -55
  92. package/lib/lib/lib/src/webhook/responses.d.ts +0 -36
  93. package/lib/lib/lib/src/webhook/responses.js +0 -42
  94. package/lib/lib/lib/src/webhook/token.d.ts +0 -2
  95. package/lib/lib/lib/src/webhook/token.js +0 -23
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @integraciones_doc24/sdk
2
2
 
3
- Node.JS library for accessing doc24 api
3
+ Node.JS library for accessing doc24 api
4
4
 
5
5
  ## Installation
6
6
 
@@ -9,48 +9,55 @@
9
9
  ## Usage
10
10
 
11
11
  ```ts
12
- import {doc24Sdk} from '@integraciones_doc24/sdk'
12
+ import {doc24Sdk} from '@integraciones_doc24/sdk';
13
13
 
14
- const getBaseSdk = () => doc24Sdk({
15
- url: 'https://tapi.doc24.com.ar/ws/sdk',
16
- credentials: {
17
- iss: 'myissuer',
18
- key: 'mysecret',
19
- },
20
- });
21
-
22
- const getSpecialities = async (user) => {
23
- const baseSdk = await getBaseSdk()
14
+ const getBaseSdk = () =>
15
+ doc24Sdk({
16
+ url: 'https://tapi.doc24.com.ar/ws/sdk',
17
+ credentials: {
18
+ iss: 'myissuer',
19
+ key: 'mysecret',
20
+ },
21
+ });
22
+
23
+ const getSpecialities = async (user) => {
24
+ const baseSdk = await getBaseSdk();
24
25
 
25
- const userSdk = await baseSdk.getUserInstance(user)
26
+ const userSdk = await baseSdk.getUserInstance(user);
26
27
 
27
- return await userSdk.getSpecialties('instant', 'ES');
28
- }
28
+ return await userSdk.getSpecialties('instant', 'ES');
29
+ };
29
30
 
30
31
  const getRequestHandler = async () => {
31
- const baseSdk = await getBaseSdk()
32
- return baseSdk.getRequestHandler({
33
- credentials: {
34
- iss: 'doc24issuer',
35
- key: 'doc24secret',
36
- },
37
- baseAddress: 'http://myaddress.com/route/to/webhook',
38
- eventHandlers: {
39
- onAppointmentStatusChange: ({id, status, changeDate}) => {
40
- console.log({id, status, changeDate});
41
- },
42
- onConsultationStatusChange: ({id, invitationId, status, changeDate, vcToken}) => {
43
- console.log({id, invitationId, status, changeDate, vcToken});
44
- },
45
- onInvitationStatusChange: ({id, status, changeDate}) => {
46
- console.log({id, status, changeDate});
47
- },
48
- onChatUpdate: ({id, status, patientId, professionalId, date}) => {
49
- console.log({id, status, patientId, professionalId, date});
50
- }
51
- },
52
- });
53
- }
32
+ const baseSdk = await getBaseSdk();
33
+ return baseSdk.getRequestHandler({
34
+ credentials: {
35
+ iss: 'doc24issuer',
36
+ key: 'doc24secret',
37
+ },
38
+ baseAddress: 'http://myaddress.com/route/to/webhook',
39
+ eventHandlers: {
40
+ onAppointmentStatusChange: ({id, status, changeDate}) => {
41
+ console.log({id, status, changeDate});
42
+ },
43
+ onConsultationStatusChange: ({
44
+ id,
45
+ invitationId,
46
+ status,
47
+ changeDate,
48
+ vcToken,
49
+ }) => {
50
+ console.log({id, invitationId, status, changeDate, vcToken});
51
+ },
52
+ onInvitationStatusChange: ({id, status, changeDate}) => {
53
+ console.log({id, status, changeDate});
54
+ },
55
+ onChatUpdate: ({id, status, patientId, professionalId, date}) => {
56
+ console.log({id, status, patientId, professionalId, date});
57
+ },
58
+ },
59
+ });
60
+ };
54
61
  ```
55
62
 
56
63
  The library exports the function `doc24Sdk`. It takes one parameters of type `SdkParams`, and returns a `BaseSdk`.
@@ -58,69 +65,110 @@ It also returns an extra `getRequestHandler` function that takes a `RequestHandl
58
65
 
59
66
  ```ts
60
67
  type SdkCredentials = {
61
- iss: string;
62
- key: string;
63
- }
68
+ iss: string;
69
+ key: string;
70
+ };
64
71
  type SdkParams = {
65
- url: string;
66
- credentials: SdkCredentials;
72
+ url: string;
73
+ credentials: SdkCredentials;
67
74
  };
68
75
  type BaseSdk = {
69
- getUserInstance: (user: User) => Promise<UserSdk>;
70
- getProfessional: (professionalId: number) => Promise<Professional>;
71
- getAvailableScheduleClinics: () => Promise<AvailableScheduleClinics>
72
- }
76
+ declareUser: (params: DeclareUserParams) => Promise<any>;
77
+ getUserId: (user: User) => Promise<number>;
78
+ getUserInstance: (user: User | number) => Promise<UserSdk>;
79
+ getProfessional: (professionalId: number) => Promise<Professional>;
80
+ getAvailableScheduleClinics: () => Promise<AvailableScheduleClinics>;
81
+ enroll: (params: EnrollmentParams) => Promise<void>;
82
+ getConverageInfo: (identificationValue: string) => Promise<CoverageInfo>;
83
+ sendVerificationCode: (params: SendVerificationCodeParams) => Promise<void>;
84
+ getDiagnosticaHistory: (
85
+ patient: DiagnosticaPatientFilter,
86
+ from: Date,
87
+ to: Date,
88
+ ) => Promise<DiagnosticaHistoryAppointment[]>;
89
+ getDiagnosticaDeepLink: (
90
+ kiosk: string,
91
+ user: DiagnosticaUser,
92
+ patient: DiagnosticaPatient,
93
+ ) => Promise<DiagnosticaDeepLinkResponse>;
94
+ getDiagnosticaAccess: (
95
+ kiosk: string,
96
+ user: DiagnosticaUser,
97
+ patient: DiagnosticaPatient,
98
+ ) => Promise<void>;
99
+ };
73
100
 
74
101
  type RequestHandlerParams = {
75
- // Credentials that doc24 should use when singing the jwt
76
- credentials: SdkCredentials;
77
- eventHandlers: Webhook.Events;
78
- // Address in which doc24 should send the requests
79
- baseAddress: string;
80
- }
102
+ // Credentials that doc24 should use when singing the jwt
103
+ credentials: SdkCredentials;
104
+ eventHandlers: Webhook.Events;
105
+ // Address in which doc24 should send the requests
106
+ baseAddress: string;
107
+ };
81
108
  ```
82
109
 
83
110
  `getRequestHandler` should be called only once, and takes care of managing the webhook that receives events from doc24.
84
111
 
85
112
  ### Express example
113
+
86
114
  ```ts
87
- const handler = await getRequestHandler()
115
+ const handler = await getRequestHandler();
88
116
  app.all('/doc24', async (req, res) => {
89
- const response = await handler({
90
- headers: req.headers,
91
- body: req.body,
92
- query: req.query,
93
- });
117
+ const response = await handler({
118
+ headers: req.headers,
119
+ body: req.body,
120
+ query: req.query,
121
+ });
94
122
 
95
- res.status(response.status.code).json(response.data);
123
+ res.status(response.status.code).json(response.data);
96
124
  });
97
125
  ```
98
126
 
99
127
  ### UserSdk
128
+
100
129
  Most of the methods need a user specified, so `getUserInstance` returns an instance of `UserSdk` with them.
101
130
 
102
131
  ```ts
103
132
  type UserSdk = {
104
- declarePatient: (patient: Patient) => Promise<number>;
105
- getSpecialties: (
106
- mode: SpecialtyMode,
107
- language: string,
108
- ) => Promise<Specialty[]>;
109
- getScheduleDates: (
110
- patientId: number,
111
- filter?: ScheduleAvailabilityFilter,
112
- ) => Promise<Date[]>;
113
- getSchedule: (
114
- patientId: number,
115
- specialtyId: number,
116
- filter?: ScheduleFilter,
117
- ) => Promise<AvailableAppointment[]>;
118
- getAppointment: (appointmentId: number) => Promise<Appointment>;
119
- scheduleVideoVisit: (params: ScheduleParameters) => Promise<string>;
120
- cancelVideoVisit: (vcToken: string) => Promise<void>;
121
- getVideoVisit: (vcToken: string, patientId: number) => Promise<VideoVisit>;
122
- getVideoVisitDetails: (vcId: number) => Promise<VideoVisitDetails>;
123
- getPatientVideoVisitHistory: (patientId: number) => Promise<VideoVisit[]>;
124
- userId: number;
125
- }
126
- ```
133
+ declarePatient: (
134
+ params: DeclarePatientParams,
135
+ ) => Promise<DeclarePatientResponse>;
136
+ getPatientId: (patient: Patient) => Promise<number>;
137
+ getSpecialties: (
138
+ mode: SpecialtyMode,
139
+ language: string,
140
+ ) => Promise<Specialty[]>;
141
+ getScheduleDates: (
142
+ patientId: number,
143
+ filter?: ScheduleAvailabilityFilter,
144
+ ) => Promise<Date[]>;
145
+ getSchedule: (
146
+ patientId: number,
147
+ specialtyId: number,
148
+ filter?: ScheduleFilter,
149
+ ) => Promise<AvailableAppointment[]>;
150
+ getAppointment: (appointmentId: number) => Promise<Appointment>;
151
+ getAppointmentByVcToken: (vcToken: string) => Promise<Appointment>;
152
+ scheduleVideoVisit: (params: ScheduleParameters) => Promise<string>;
153
+ cancelVideoVisit: (vcToken: string) => Promise<void>;
154
+ getVideoVisit: (vcToken: string, patientId: number) => Promise<VideoVisit>;
155
+ getVideoVisitDetails: (vcId: number) => Promise<VideoVisitDetails>;
156
+ getVideoVisitLink: (
157
+ vcToken: string,
158
+ patientId: number,
159
+ ) => Promise<string | null>;
160
+ getPatientVideoVisitHistory: (patientId: number) => Promise<VideoVisit[]>;
161
+ getActiveVideoVisits: () => Promise<ActiveVideoVisitData[]>;
162
+ getAvailableChatrooms: (
163
+ patientId: number,
164
+ specialtyId: number,
165
+ filter: ChatroomAvailabilityFilter,
166
+ ) => Promise<AvailableChatroom[]>;
167
+ createNewChat: (chatParameters: ChatParameters) => Promise<number>;
168
+ getPatientChats: (patientId: number) => Promise<ChatDetails[]>;
169
+ getChatPosts: (chatId: number) => Promise<ChatPost[]>;
170
+ cancelChat: (chatId: number) => Promise<void>;
171
+ sendChatMessage: (chatId: number, message: string) => Promise<number>;
172
+ userId: number;
173
+ };
174
+ ```
@@ -11,22 +11,22 @@ export declare const getDiagnosticaMethods: (makeRequest: RequestMaker) => {
11
11
  deepLink: string;
12
12
  }[]>;
13
13
  getDiagnosticaDeepLink: (kiosk: string, user: {
14
- language: string;
15
14
  firstName: string;
16
15
  lastName: string;
17
- birthday: Date;
18
16
  identificationType: "dni";
19
17
  identificationValue: string;
20
18
  gender: "m" | "f";
21
19
  phone: string;
22
20
  email: string;
21
+ language: string;
22
+ birthday: Date;
23
23
  }, patient: {
24
24
  firstName: string;
25
25
  lastName: string;
26
- birthday: Date;
27
26
  identificationType: "dni";
28
27
  identificationValue: string;
29
28
  gender: "m" | "f";
29
+ birthday: Date;
30
30
  }) => Promise<{
31
31
  forwardingRequired: true;
32
32
  deepLink: string;
@@ -34,21 +34,21 @@ export declare const getDiagnosticaMethods: (makeRequest: RequestMaker) => {
34
34
  forwardingRequired: false;
35
35
  }>;
36
36
  getDiagnosticaAccess: (kiosk: string, user: {
37
- language: string;
38
37
  firstName: string;
39
38
  lastName: string;
40
- birthday: Date;
41
39
  identificationType: "dni";
42
40
  identificationValue: string;
43
41
  gender: "m" | "f";
44
42
  phone: string;
45
43
  email: string;
44
+ language: string;
45
+ birthday: Date;
46
46
  }, patient: {
47
47
  firstName: string;
48
48
  lastName: string;
49
- birthday: Date;
50
49
  identificationType: "dni";
51
50
  identificationValue: string;
52
51
  gender: "m" | "f";
52
+ birthday: Date;
53
53
  }) => Promise<void>;
54
54
  };
@@ -48,13 +48,9 @@ const getBaseSdk = async (url, credentials) => {
48
48
  id: s.id_especialidad,
49
49
  description: s.especialidad,
50
50
  });
51
- const mapSpecialityER = (s) => ({
52
- id: s.specialty_id,
53
- description: s.specialty,
54
- });
55
51
  const mapped = {
56
52
  specialties: response.data.specialties.map(mapSpeciality),
57
- specialtiesER: response.data.specialties_er.map(mapSpecialityER),
53
+ specialtiesER: response.data.specialties_er.map(mapSpeciality),
58
54
  professionals: response.data.professionals.map((p) => ({
59
55
  id: p.id_profesional,
60
56
  fullName: p.denominacion,
@@ -1,25 +1,73 @@
1
1
  import { RequestMaker } from '../request';
2
2
  import { Doc24 } from '../types';
3
3
  export declare const getUserMethods: (makeRequest: RequestMaker, url: string, credentials: Doc24.SdkCredentials) => {
4
- declareUser: (user: {
4
+ declareUser: (params: {
5
+ user: {
6
+ firstName: string;
7
+ lastName: string;
8
+ identificationType: "ndi" | "passport" | "credential";
9
+ identificationValue: string;
10
+ countryId: string;
11
+ birthdate: Date;
12
+ gender: "m" | "f";
13
+ phone: string;
14
+ email: string;
15
+ };
16
+ } & {
17
+ code?: string | undefined;
18
+ channel?: "1" | "2" | undefined;
19
+ }) => Promise<{
20
+ patientId: number | null;
21
+ userInfo: {
22
+ phone: string;
23
+ email: string;
24
+ };
25
+ askCode: boolean;
26
+ userId: number;
27
+ }>;
28
+ getUserId: (user: {
5
29
  firstName: string;
6
30
  lastName: string;
7
31
  identificationType: "ndi" | "passport" | "credential";
8
32
  identificationValue: string;
33
+ countryId: string;
34
+ birthdate: Date;
9
35
  gender: "m" | "f";
10
36
  phone: string;
11
37
  email: string;
38
+ }) => Promise<number>;
39
+ sendVerificationCode: (params: {
40
+ identificationType: "ndi" | "passport" | "credential";
41
+ identificationValue: string;
42
+ channel: "1" | "2";
43
+ }) => Promise<any>;
44
+ getUserInstance: (user: number | {
45
+ firstName: string;
46
+ lastName: string;
47
+ identificationType: "ndi" | "passport" | "credential";
48
+ identificationValue: string;
12
49
  countryId: string;
13
50
  birthdate: Date;
51
+ gender: "m" | "f";
52
+ phone: string;
53
+ email: string;
14
54
  }) => Promise<any>;
15
- getUserInstance: (...params: any) => Promise<any>;
16
- enroll: (...params: any) => Promise<void>;
55
+ enroll: (params: {
56
+ firstName: string;
57
+ lastName: string;
58
+ birthdate: Date;
59
+ gender: "m" | "f";
60
+ email: string;
61
+ startDate: Date;
62
+ identificationNumber: string;
63
+ plan: string;
64
+ }) => Promise<void>;
17
65
  getConverageInfo: (identificationValue: string) => Promise<{
18
66
  firstName: string | null;
19
67
  lastName: string | null;
68
+ birthdate: Date;
20
69
  gender: "m" | "f";
21
70
  email: string | null;
22
- birthdate: Date;
23
71
  identificationNumber: string;
24
72
  plan: string | null;
25
73
  financerId: number | null;
@@ -8,11 +8,39 @@ const schemas_1 = require("../schemas");
8
8
  const userSdk_1 = require("../userSdk");
9
9
  const utils_1 = require("../utils");
10
10
  const getUserMethods = (makeRequest, url, credentials) => {
11
+ const declareUser = async ({ user, channel, code, }) => {
12
+ const path = '/user';
13
+ const mappedUser = {
14
+ lastname: user.lastName,
15
+ firstname: user.firstName,
16
+ identification_type: utils_1.getIdetificationTypeId(user.identificationType),
17
+ identification_value: user.identificationValue,
18
+ birthdate: date_fns_1.format(user.birthdate, 'yyyy-MM-dd'),
19
+ gender: user.gender.toUpperCase(),
20
+ phone: user.phone,
21
+ email: user.email,
22
+ country_id: user.countryId,
23
+ };
24
+ const parsedChannel = channel ? parseInt(channel) : channel;
25
+ const response = await makeRequest('POST', path, {
26
+ user_data: mappedUser,
27
+ channel: parsedChannel,
28
+ code,
29
+ });
30
+ const mappedResponse = {
31
+ userId: response.data.user_id,
32
+ patientId: response.data.patient_id,
33
+ userInfo: response.data.user_info,
34
+ askCode: response.data.ask_code,
35
+ };
36
+ return mappedResponse;
37
+ };
11
38
  const getUserId = async (user) => {
39
+ const path = '/user';
12
40
  const mappedUser = {
13
41
  lastname: user.lastName,
14
42
  firstname: user.firstName,
15
- identification_type: utils_1.getIndetificationTypeId(user.identificationType),
43
+ identification_type: utils_1.getIdetificationTypeId(user.identificationType),
16
44
  identification_value: user.identificationValue,
17
45
  birthdate: date_fns_1.format(user.birthdate, 'yyyy-MM-dd'),
18
46
  gender: user.gender.toUpperCase(),
@@ -20,12 +48,41 @@ const getUserMethods = (makeRequest, url, credentials) => {
20
48
  email: user.email,
21
49
  country_id: user.countryId,
22
50
  };
23
- const response = await makeRequest('POST', '/user', {
51
+ const response = await makeRequest('POST', path, {
24
52
  user_data: mappedUser,
25
53
  });
26
54
  return response.data.user_id;
27
55
  };
28
- const getConverageInfo = validation_1.validateFunction(zod_1.tuple([zod_1.string()]), schemas_1.doc24Schemas.coverageInfo, async (identificationValue) => {
56
+ const sendVerificationCode = async (params) => {
57
+ const path = '/send-verification-code';
58
+ const mappedParams = {
59
+ identification_type: utils_1.getIdetificationTypeId(params.identificationType),
60
+ identification_value: params.identificationValue,
61
+ channel: parseInt(params.channel),
62
+ };
63
+ await makeRequest('POST', path, mappedParams);
64
+ };
65
+ const getUserInstance = async (user) => {
66
+ const userId = typeof user === 'number' ? user : await getUserId(user);
67
+ return userSdk_1.userSdk(url, credentials, userId);
68
+ };
69
+ const enroll = async (params) => {
70
+ const path = `/enrollment`;
71
+ const mappedUser = {
72
+ firstname: params.firstName,
73
+ lastname: params.lastName,
74
+ gender: params.gender.toUpperCase(),
75
+ identification_number: params.identificationNumber,
76
+ birthdate: date_fns_1.format(params.birthdate, 'yyyy-MM-dd'),
77
+ email: params.email,
78
+ plan: params.plan,
79
+ start_date: date_fns_1.format(params.startDate, 'yyyy-MM-dd'),
80
+ };
81
+ await makeRequest('POST', path, {
82
+ user_data: mappedUser,
83
+ });
84
+ };
85
+ const getConverageInfo = async (identificationValue) => {
29
86
  const path = `/info-coverage/${identificationValue}`;
30
87
  const response = await makeRequest('GET', path);
31
88
  const raw = response.data.info;
@@ -58,31 +115,16 @@ const getUserMethods = (makeRequest, url, credentials) => {
58
115
  : null,
59
116
  };
60
117
  return mappedCoverageInfo;
61
- });
118
+ };
62
119
  return {
63
- declareUser: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.user]), zod_1.number(), getUserId),
120
+ declareUser: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.declareUserParams]), schemas_1.doc24Schemas.declareUserResponse, declareUser),
121
+ getUserId: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.user]), zod_1.number(), getUserId),
122
+ sendVerificationCode: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.sendVerificationCodeParams]), zod_1.void(), sendVerificationCode),
64
123
  getUserInstance: validation_1.validateFunction(zod_1.tuple([zod_1.union([schemas_1.doc24Schemas.user, zod_1.number()])]),
65
124
  // TODO: validate?
66
- zod_1.any(), async (user) => {
67
- const userId = typeof user === 'number' ? user : await getUserId(user);
68
- return userSdk_1.userSdk(url, credentials, userId);
69
- }),
70
- enroll: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.enrollmentParams]), zod_1.void(), async (params) => {
71
- const path = `/enrollment`;
72
- await makeRequest('POST', path, {
73
- user_data: {
74
- firstname: params.firstName,
75
- lastname: params.lastName,
76
- gender: params.gender.toUpperCase(),
77
- identification_number: params.identificationNumber,
78
- birthdate: date_fns_1.format(params.birthdate, 'yyyy-MM-dd'),
79
- email: params.email,
80
- plan: params.plan,
81
- start_date: date_fns_1.format(params.startDate, 'yyyy-MM-dd'),
82
- },
83
- });
84
- }),
85
- getConverageInfo,
125
+ zod_1.any(), getUserInstance),
126
+ enroll: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.enrollmentParams]), zod_1.void(), enroll),
127
+ getConverageInfo: validation_1.validateFunction(zod_1.tuple([zod_1.string()]), schemas_1.doc24Schemas.coverageInfo, getConverageInfo),
86
128
  };
87
129
  };
88
130
  exports.getUserMethods = getUserMethods;
package/lib/index.d.ts CHANGED
@@ -5,37 +5,61 @@ export declare const doc24Sdk: (params: Doc24.SdkParams) => Promise<{
5
5
  eventHandlers: Doc24.Webhook.Events;
6
6
  baseAddress: string;
7
7
  }) => Promise<Doc24.Webhook.Handler>;
8
- declareUser: (user: {
8
+ declareUser: (params: {
9
+ user: {
10
+ firstName: string;
11
+ lastName: string;
12
+ identificationType: "ndi" | "passport" | "credential";
13
+ identificationValue: string;
14
+ countryId: string;
15
+ birthdate: Date;
16
+ gender: "m" | "f";
17
+ phone: string;
18
+ email: string;
19
+ };
20
+ } & {
21
+ code?: string | undefined;
22
+ channel?: "1" | "2" | undefined;
23
+ }) => Promise<{
24
+ patientId: number | null;
25
+ userInfo: {
26
+ phone: string;
27
+ email: string;
28
+ };
29
+ askCode: boolean;
30
+ userId: number;
31
+ }>;
32
+ getUserId: (user: {
9
33
  firstName: string;
10
34
  lastName: string;
11
35
  identificationType: "ndi" | "passport" | "credential";
12
36
  identificationValue: string;
37
+ countryId: string;
38
+ birthdate: Date;
13
39
  gender: "m" | "f";
14
40
  phone: string;
15
41
  email: string;
16
- countryId: string;
17
- birthdate: Date;
18
42
  }) => Promise<number>;
19
43
  getUserInstance: (user: number | {
20
44
  firstName: string;
21
45
  lastName: string;
22
46
  identificationType: "ndi" | "passport" | "credential";
23
47
  identificationValue: string;
48
+ countryId: string;
49
+ birthdate: Date;
24
50
  gender: "m" | "f";
25
51
  phone: string;
26
52
  email: string;
27
- countryId: string;
28
- birthdate: Date;
29
53
  }) => Promise<Doc24.UserSdk>;
30
54
  getProfessional: (professionalId: number) => Promise<{
31
- id: number;
32
- logoUrl: string;
33
55
  firstName: string;
34
56
  lastName: string;
57
+ birthdate: Date;
35
58
  gender: "m" | "f";
36
59
  phone: string | null;
37
60
  email: string;
38
- birthdate: Date;
61
+ id: number;
62
+ logoUrl: string;
39
63
  specialties: {
40
64
  id: number;
41
65
  description: string;
@@ -73,9 +97,9 @@ export declare const doc24Sdk: (params: Doc24.SdkParams) => Promise<{
73
97
  enroll: (params: {
74
98
  firstName: string;
75
99
  lastName: string;
100
+ birthdate: Date;
76
101
  gender: "m" | "f";
77
102
  email: string;
78
- birthdate: Date;
79
103
  startDate: Date;
80
104
  identificationNumber: string;
81
105
  plan: string;
@@ -83,9 +107,9 @@ export declare const doc24Sdk: (params: Doc24.SdkParams) => Promise<{
83
107
  getConverageInfo: (identificationValue: string) => Promise<{
84
108
  firstName: string | null;
85
109
  lastName: string | null;
110
+ birthdate: Date;
86
111
  gender: "m" | "f";
87
112
  email: string | null;
88
- birthdate: Date;
89
113
  identificationNumber: string;
90
114
  plan: string | null;
91
115
  financerId: number | null;
@@ -104,6 +128,11 @@ export declare const doc24Sdk: (params: Doc24.SdkParams) => Promise<{
104
128
  authorizationCode: string | null;
105
129
  authorizationCodeExpiration: Date | null;
106
130
  } | null>;
131
+ sendVerificationCode: (params: {
132
+ identificationType: "ndi" | "passport" | "credential";
133
+ identificationValue: string;
134
+ channel: "1" | "2";
135
+ }) => Promise<any>;
107
136
  getDiagnosticaHistory: (patient: {
108
137
  identificationType: "ndi" | "passport" | "credential";
109
138
  identificationValue: string;
@@ -115,22 +144,22 @@ export declare const doc24Sdk: (params: Doc24.SdkParams) => Promise<{
115
144
  deepLink: string;
116
145
  }[]>;
117
146
  getDiagnosticaDeepLink: (kiosk: string, user: {
118
- language: string;
119
147
  firstName: string;
120
148
  lastName: string;
121
- birthday: Date;
122
149
  identificationType: "dni";
123
150
  identificationValue: string;
124
151
  gender: "m" | "f";
125
152
  phone: string;
126
153
  email: string;
154
+ language: string;
155
+ birthday: Date;
127
156
  }, patient: {
128
157
  firstName: string;
129
158
  lastName: string;
130
- birthday: Date;
131
159
  identificationType: "dni";
132
160
  identificationValue: string;
133
161
  gender: "m" | "f";
162
+ birthday: Date;
134
163
  }) => Promise<{
135
164
  forwardingRequired: true;
136
165
  deepLink: string;
@@ -138,22 +167,22 @@ export declare const doc24Sdk: (params: Doc24.SdkParams) => Promise<{
138
167
  forwardingRequired: false;
139
168
  }>;
140
169
  getDiagnosticaAccess: (kiosk: string, user: {
141
- language: string;
142
170
  firstName: string;
143
171
  lastName: string;
144
- birthday: Date;
145
172
  identificationType: "dni";
146
173
  identificationValue: string;
147
174
  gender: "m" | "f";
148
175
  phone: string;
149
176
  email: string;
177
+ language: string;
178
+ birthday: Date;
150
179
  }, patient: {
151
180
  firstName: string;
152
181
  lastName: string;
153
- birthday: Date;
154
182
  identificationType: "dni";
155
183
  identificationValue: string;
156
184
  gender: "m" | "f";
185
+ birthday: Date;
157
186
  }) => Promise<void>;
158
187
  }>;
159
188
  export type { Doc24 } from './types';