@integraciones_doc24/sdk 1.3.0 → 1.4.1

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 CHANGED
@@ -80,7 +80,7 @@ type BaseSdk = {
80
80
  getAvailableScheduleClinics: () => Promise<AvailableScheduleClinics>;
81
81
  enroll: (params: EnrollmentParams) => Promise<void>;
82
82
  getConverageInfo: (identificationValue: string) => Promise<CoverageInfo>;
83
- sendVerificationCode: (params: SendVerificationCodeParams) => Promise<void>;
83
+ getVerificationCode: (params: getVerificationCodeParams) => Promise<void>;
84
84
  getDiagnosticaHistory: (
85
85
  patient: DiagnosticaPatientFilter,
86
86
  from: Date,
@@ -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
  };
@@ -1,25 +1,75 @@
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
+ askCode: true;
21
+ userInfo: {
22
+ phone: string;
23
+ email: string;
24
+ };
25
+ } | {
26
+ patientId: number | null;
27
+ askCode: false;
28
+ userId: number;
29
+ }>;
30
+ getUserId: (user: {
5
31
  firstName: string;
6
32
  lastName: string;
7
33
  identificationType: "ndi" | "passport" | "credential";
8
34
  identificationValue: string;
35
+ countryId: string;
36
+ birthdate: Date;
9
37
  gender: "m" | "f";
10
38
  phone: string;
11
39
  email: string;
40
+ }) => Promise<number>;
41
+ getVerificationCode: (params: {
42
+ identificationType: "ndi" | "passport" | "credential";
43
+ identificationValue: string;
44
+ channel: "1" | "2";
45
+ }) => Promise<any>;
46
+ getUserInstance: (user: number | {
47
+ firstName: string;
48
+ lastName: string;
49
+ identificationType: "ndi" | "passport" | "credential";
50
+ identificationValue: string;
12
51
  countryId: string;
13
52
  birthdate: Date;
53
+ gender: "m" | "f";
54
+ phone: string;
55
+ email: string;
14
56
  }) => Promise<any>;
15
- getUserInstance: (...params: any) => Promise<any>;
16
- enroll: (...params: any) => Promise<void>;
57
+ enroll: (params: {
58
+ firstName: string;
59
+ lastName: string;
60
+ birthdate: Date;
61
+ gender: "m" | "f";
62
+ email: string;
63
+ startDate: Date;
64
+ identificationNumber: string;
65
+ plan: string;
66
+ }) => Promise<void>;
17
67
  getConverageInfo: (identificationValue: string) => Promise<{
18
68
  firstName: string | null;
19
69
  lastName: string | null;
70
+ birthdate: Date;
20
71
  gender: "m" | "f";
21
72
  email: string | null;
22
- birthdate: Date;
23
73
  identificationNumber: string;
24
74
  plan: string | null;
25
75
  financerId: number | null;
@@ -8,11 +8,40 @@ 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 data = response.data;
31
+ if (data.ask_code)
32
+ return { askCode: true, userInfo: data.user_info };
33
+ return {
34
+ askCode: false,
35
+ userId: response.data.user_id,
36
+ patientId: response.data.patient_id,
37
+ };
38
+ };
11
39
  const getUserId = async (user) => {
40
+ const path = '/search-user';
12
41
  const mappedUser = {
13
42
  lastname: user.lastName,
14
43
  firstname: user.firstName,
15
- identification_type: utils_1.getIndetificationTypeId(user.identificationType),
44
+ identification_type: utils_1.getIdetificationTypeId(user.identificationType),
16
45
  identification_value: user.identificationValue,
17
46
  birthdate: date_fns_1.format(user.birthdate, 'yyyy-MM-dd'),
18
47
  gender: user.gender.toUpperCase(),
@@ -20,12 +49,41 @@ const getUserMethods = (makeRequest, url, credentials) => {
20
49
  email: user.email,
21
50
  country_id: user.countryId,
22
51
  };
23
- const response = await makeRequest('POST', '/user', {
52
+ const response = await makeRequest('POST', path, {
24
53
  user_data: mappedUser,
25
54
  });
26
55
  return response.data.user_id;
27
56
  };
28
- const getConverageInfo = validation_1.validateFunction(zod_1.tuple([zod_1.string()]), schemas_1.doc24Schemas.coverageInfo, async (identificationValue) => {
57
+ const getVerificationCode = async (params) => {
58
+ const path = '/send-verification-code';
59
+ const mappedParams = {
60
+ identification_type: utils_1.getIdetificationTypeId(params.identificationType),
61
+ identification_value: params.identificationValue,
62
+ channel: parseInt(params.channel),
63
+ };
64
+ await makeRequest('POST', path, mappedParams);
65
+ };
66
+ const getUserInstance = async (user) => {
67
+ const userId = typeof user === 'number' ? user : await getUserId(user);
68
+ return userSdk_1.userSdk(url, credentials, userId);
69
+ };
70
+ const enroll = async (params) => {
71
+ const path = `/enrollment`;
72
+ const mappedUser = {
73
+ firstname: params.firstName,
74
+ lastname: params.lastName,
75
+ gender: params.gender.toUpperCase(),
76
+ identification_number: params.identificationNumber,
77
+ birthdate: date_fns_1.format(params.birthdate, 'yyyy-MM-dd'),
78
+ email: params.email,
79
+ plan: params.plan,
80
+ start_date: date_fns_1.format(params.startDate, 'yyyy-MM-dd'),
81
+ };
82
+ await makeRequest('POST', path, {
83
+ user_data: mappedUser,
84
+ });
85
+ };
86
+ const getConverageInfo = async (identificationValue) => {
29
87
  const path = `/info-coverage/${identificationValue}`;
30
88
  const response = await makeRequest('GET', path);
31
89
  const raw = response.data.info;
@@ -58,31 +116,16 @@ const getUserMethods = (makeRequest, url, credentials) => {
58
116
  : null,
59
117
  };
60
118
  return mappedCoverageInfo;
61
- });
119
+ };
62
120
  return {
63
- declareUser: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.user]), zod_1.number(), getUserId),
121
+ declareUser: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.declareUserParams]), schemas_1.doc24Schemas.declareUserResponse, declareUser),
122
+ getUserId: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.user]), zod_1.number(), getUserId),
123
+ getVerificationCode: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.getVerificationCodeParams]), zod_1.void(), getVerificationCode),
64
124
  getUserInstance: validation_1.validateFunction(zod_1.tuple([zod_1.union([schemas_1.doc24Schemas.user, zod_1.number()])]),
65
125
  // 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,
126
+ zod_1.any(), getUserInstance),
127
+ enroll: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.enrollmentParams]), zod_1.void(), enroll),
128
+ getConverageInfo: validation_1.validateFunction(zod_1.tuple([zod_1.string()]), schemas_1.doc24Schemas.coverageInfo, getConverageInfo),
86
129
  };
87
130
  };
88
131
  exports.getUserMethods = getUserMethods;
package/lib/index.d.ts CHANGED
@@ -5,37 +5,63 @@ 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
+ askCode: true;
25
+ userInfo: {
26
+ phone: string;
27
+ email: string;
28
+ };
29
+ } | {
30
+ patientId: number | null;
31
+ askCode: false;
32
+ userId: number;
33
+ }>;
34
+ getUserId: (user: {
9
35
  firstName: string;
10
36
  lastName: string;
11
37
  identificationType: "ndi" | "passport" | "credential";
12
38
  identificationValue: string;
39
+ countryId: string;
40
+ birthdate: Date;
13
41
  gender: "m" | "f";
14
42
  phone: string;
15
43
  email: string;
16
- countryId: string;
17
- birthdate: Date;
18
44
  }) => Promise<number>;
19
45
  getUserInstance: (user: number | {
20
46
  firstName: string;
21
47
  lastName: string;
22
48
  identificationType: "ndi" | "passport" | "credential";
23
49
  identificationValue: string;
50
+ countryId: string;
51
+ birthdate: Date;
24
52
  gender: "m" | "f";
25
53
  phone: string;
26
54
  email: string;
27
- countryId: string;
28
- birthdate: Date;
29
55
  }) => Promise<Doc24.UserSdk>;
30
56
  getProfessional: (professionalId: number) => Promise<{
31
- id: number;
32
- logoUrl: string;
33
57
  firstName: string;
34
58
  lastName: string;
59
+ birthdate: Date;
35
60
  gender: "m" | "f";
36
61
  phone: string | null;
37
62
  email: string;
38
- birthdate: Date;
63
+ id: number;
64
+ logoUrl: string;
39
65
  specialties: {
40
66
  id: number;
41
67
  description: string;
@@ -73,9 +99,9 @@ export declare const doc24Sdk: (params: Doc24.SdkParams) => Promise<{
73
99
  enroll: (params: {
74
100
  firstName: string;
75
101
  lastName: string;
102
+ birthdate: Date;
76
103
  gender: "m" | "f";
77
104
  email: string;
78
- birthdate: Date;
79
105
  startDate: Date;
80
106
  identificationNumber: string;
81
107
  plan: string;
@@ -83,9 +109,9 @@ export declare const doc24Sdk: (params: Doc24.SdkParams) => Promise<{
83
109
  getConverageInfo: (identificationValue: string) => Promise<{
84
110
  firstName: string | null;
85
111
  lastName: string | null;
112
+ birthdate: Date;
86
113
  gender: "m" | "f";
87
114
  email: string | null;
88
- birthdate: Date;
89
115
  identificationNumber: string;
90
116
  plan: string | null;
91
117
  financerId: number | null;
@@ -104,6 +130,11 @@ export declare const doc24Sdk: (params: Doc24.SdkParams) => Promise<{
104
130
  authorizationCode: string | null;
105
131
  authorizationCodeExpiration: Date | null;
106
132
  } | null>;
133
+ getVerificationCode: (params: {
134
+ identificationType: "ndi" | "passport" | "credential";
135
+ identificationValue: string;
136
+ channel: "1" | "2";
137
+ }) => Promise<any>;
107
138
  getDiagnosticaHistory: (patient: {
108
139
  identificationType: "ndi" | "passport" | "credential";
109
140
  identificationValue: string;
@@ -115,22 +146,22 @@ export declare const doc24Sdk: (params: Doc24.SdkParams) => Promise<{
115
146
  deepLink: string;
116
147
  }[]>;
117
148
  getDiagnosticaDeepLink: (kiosk: string, user: {
118
- language: string;
119
149
  firstName: string;
120
150
  lastName: string;
121
- birthday: Date;
122
151
  identificationType: "dni";
123
152
  identificationValue: string;
124
153
  gender: "m" | "f";
125
154
  phone: string;
126
155
  email: string;
156
+ language: string;
157
+ birthday: Date;
127
158
  }, patient: {
128
159
  firstName: string;
129
160
  lastName: string;
130
- birthday: Date;
131
161
  identificationType: "dni";
132
162
  identificationValue: string;
133
163
  gender: "m" | "f";
164
+ birthday: Date;
134
165
  }) => Promise<{
135
166
  forwardingRequired: true;
136
167
  deepLink: string;
@@ -138,22 +169,22 @@ export declare const doc24Sdk: (params: Doc24.SdkParams) => Promise<{
138
169
  forwardingRequired: false;
139
170
  }>;
140
171
  getDiagnosticaAccess: (kiosk: string, user: {
141
- language: string;
142
172
  firstName: string;
143
173
  lastName: string;
144
- birthday: Date;
145
174
  identificationType: "dni";
146
175
  identificationValue: string;
147
176
  gender: "m" | "f";
148
177
  phone: string;
149
178
  email: string;
179
+ language: string;
180
+ birthday: Date;
150
181
  }, patient: {
151
182
  firstName: string;
152
183
  lastName: string;
153
- birthday: Date;
154
184
  identificationType: "dni";
155
185
  identificationValue: string;
156
186
  gender: "m" | "f";
187
+ birthday: Date;
157
188
  }) => Promise<void>;
158
189
  }>;
159
190
  export type { Doc24 } from './types';
package/lib/schemas.d.ts CHANGED
@@ -51,21 +51,21 @@ export declare const doc24Schemas: {
51
51
  lastName: string;
52
52
  identificationType: "ndi" | "passport" | "credential";
53
53
  identificationValue: string;
54
+ countryId: string;
55
+ birthdate: Date;
54
56
  gender: "m" | "f";
55
57
  phone: string;
56
58
  email: string;
57
- countryId: string;
58
- birthdate: Date;
59
59
  }, {
60
60
  firstName: string;
61
61
  lastName: string;
62
62
  identificationType: "ndi" | "passport" | "credential";
63
63
  identificationValue: string;
64
+ countryId: string;
65
+ birthdate: Date;
64
66
  gender: "m" | "f";
65
67
  phone: string;
66
68
  email: string;
67
- countryId: string;
68
- birthdate: Date;
69
69
  }>;
70
70
  patient: import("zod").ZodObject<{
71
71
  firstName: import("zod").ZodString;
@@ -80,17 +80,17 @@ export declare const doc24Schemas: {
80
80
  lastName: string;
81
81
  identificationType: "ndi" | "passport" | "credential";
82
82
  identificationValue: string;
83
- gender: "m" | "f";
84
83
  countryId: string;
85
84
  birthdate: Date;
85
+ gender: "m" | "f";
86
86
  }, {
87
87
  firstName: string;
88
88
  lastName: string;
89
89
  identificationType: "ndi" | "passport" | "credential";
90
90
  identificationValue: string;
91
- gender: "m" | "f";
92
91
  countryId: string;
93
92
  birthdate: Date;
93
+ gender: "m" | "f";
94
94
  }>;
95
95
  specialtyMode: import("zod").ZodEnum<["appointment", "chat", "instant"]>;
96
96
  specialty: import("zod").ZodObject<{
@@ -353,13 +353,13 @@ export declare const doc24Schemas: {
353
353
  email: import("zod").ZodNullable<import("zod").ZodString>;
354
354
  phone: import("zod").ZodNullable<import("zod").ZodString>;
355
355
  }, "strip", import("zod").ZodTypeAny, {
356
- id: number;
357
356
  phone: string | null;
358
357
  email: string | null;
359
- }, {
360
358
  id: number;
359
+ }, {
361
360
  phone: string | null;
362
361
  email: string | null;
362
+ id: number;
363
363
  }>;
364
364
  vcToken: import("zod").ZodString;
365
365
  appointment: import("zod").ZodOptional<import("zod").ZodObject<{
@@ -399,9 +399,9 @@ export declare const doc24Schemas: {
399
399
  patientId: number;
400
400
  creationDate: Date;
401
401
  user: {
402
- id: number;
403
402
  phone: string | null;
404
403
  email: string | null;
404
+ id: number;
405
405
  };
406
406
  vcToken: string;
407
407
  }, {
@@ -419,9 +419,9 @@ export declare const doc24Schemas: {
419
419
  patientId: number;
420
420
  creationDate: Date;
421
421
  user: {
422
- id: number;
423
422
  phone: string | null;
424
423
  email: string | null;
424
+ id: number;
425
425
  };
426
426
  vcToken: string;
427
427
  }>;
@@ -671,14 +671,14 @@ export declare const doc24Schemas: {
671
671
  brief: string;
672
672
  }>;
673
673
  }, "strip", import("zod").ZodTypeAny, {
674
- id: number;
675
- logoUrl: string;
676
674
  firstName: string;
677
675
  lastName: string;
676
+ birthdate: Date;
678
677
  gender: "m" | "f";
679
678
  phone: string | null;
680
679
  email: string;
681
- birthdate: Date;
680
+ id: number;
681
+ logoUrl: string;
682
682
  specialties: {
683
683
  id: number;
684
684
  description: string;
@@ -694,14 +694,14 @@ export declare const doc24Schemas: {
694
694
  brief: string;
695
695
  };
696
696
  }, {
697
- id: number;
698
- logoUrl: string;
699
697
  firstName: string;
700
698
  lastName: string;
699
+ birthdate: Date;
701
700
  gender: "m" | "f";
702
701
  phone: string | null;
703
702
  email: string;
704
- birthdate: Date;
703
+ id: number;
704
+ logoUrl: string;
705
705
  specialties: {
706
706
  id: number;
707
707
  description: string;
@@ -815,13 +815,13 @@ export declare const doc24Schemas: {
815
815
  firstName: import("zod").ZodString;
816
816
  lastName: import("zod").ZodString;
817
817
  }, "strip", import("zod").ZodTypeAny, {
818
- id: number;
819
818
  firstName: string;
820
819
  lastName: string;
821
- }, {
822
820
  id: number;
821
+ }, {
823
822
  firstName: string;
824
823
  lastName: string;
824
+ id: number;
825
825
  }>;
826
826
  patientLastPost: import("zod").ZodNullable<import("zod").ZodDate>;
827
827
  professional: import("zod").ZodObject<{
@@ -853,9 +853,9 @@ export declare const doc24Schemas: {
853
853
  }, "strip", import("zod").ZodTypeAny, {
854
854
  id: number;
855
855
  patient: {
856
- id: number;
857
856
  firstName: string;
858
857
  lastName: string;
858
+ id: number;
859
859
  };
860
860
  professional: {
861
861
  id: number;
@@ -877,9 +877,9 @@ export declare const doc24Schemas: {
877
877
  }, {
878
878
  id: number;
879
879
  patient: {
880
- id: number;
881
880
  firstName: string;
882
881
  lastName: string;
882
+ id: number;
883
883
  };
884
884
  professional: {
885
885
  id: number;
@@ -927,18 +927,18 @@ export declare const doc24Schemas: {
927
927
  }, "strip", import("zod").ZodTypeAny, {
928
928
  firstName: string;
929
929
  lastName: string;
930
+ birthdate: Date;
930
931
  gender: "m" | "f";
931
932
  email: string;
932
- birthdate: Date;
933
933
  startDate: Date;
934
934
  identificationNumber: string;
935
935
  plan: string;
936
936
  }, {
937
937
  firstName: string;
938
938
  lastName: string;
939
+ birthdate: Date;
939
940
  gender: "m" | "f";
940
941
  email: string;
941
- birthdate: Date;
942
942
  startDate: Date;
943
943
  identificationNumber: string;
944
944
  plan: string;
@@ -984,25 +984,25 @@ export declare const doc24Schemas: {
984
984
  email: import("zod").ZodString;
985
985
  language: import("zod").ZodString;
986
986
  }>, "strip", import("zod").ZodTypeAny, {
987
- language: string;
988
987
  firstName: string;
989
988
  lastName: string;
990
- birthday: Date;
991
989
  identificationType: "dni";
992
990
  identificationValue: string;
993
991
  gender: "m" | "f";
994
992
  phone: string;
995
993
  email: string;
996
- }, {
997
994
  language: string;
995
+ birthday: Date;
996
+ }, {
998
997
  firstName: string;
999
998
  lastName: string;
1000
- birthday: Date;
1001
999
  identificationType: "dni";
1002
1000
  identificationValue: string;
1003
1001
  gender: "m" | "f";
1004
1002
  phone: string;
1005
1003
  email: string;
1004
+ language: string;
1005
+ birthday: Date;
1006
1006
  }>;
1007
1007
  diagnosticaPatient: import("zod").ZodObject<{
1008
1008
  firstName: import("zod").ZodString;
@@ -1014,17 +1014,17 @@ export declare const doc24Schemas: {
1014
1014
  }, "strip", import("zod").ZodTypeAny, {
1015
1015
  firstName: string;
1016
1016
  lastName: string;
1017
- birthday: Date;
1018
1017
  identificationType: "dni";
1019
1018
  identificationValue: string;
1020
1019
  gender: "m" | "f";
1020
+ birthday: Date;
1021
1021
  }, {
1022
1022
  firstName: string;
1023
1023
  lastName: string;
1024
- birthday: Date;
1025
1024
  identificationType: "dni";
1026
1025
  identificationValue: string;
1027
1026
  gender: "m" | "f";
1027
+ birthday: Date;
1028
1028
  }>;
1029
1029
  diagnosticaDeepLinkResponse: import("zod").ZodUnion<[import("zod").ZodObject<{
1030
1030
  forwardingRequired: import("zod").ZodLiteral<true>;
@@ -1068,9 +1068,9 @@ export declare const doc24Schemas: {
1068
1068
  }, "strip", import("zod").ZodTypeAny, {
1069
1069
  firstName: string | null;
1070
1070
  lastName: string | null;
1071
+ birthdate: Date;
1071
1072
  gender: "m" | "f";
1072
1073
  email: string | null;
1073
- birthdate: Date;
1074
1074
  identificationNumber: string;
1075
1075
  plan: string | null;
1076
1076
  financerId: number | null;
@@ -1091,9 +1091,9 @@ export declare const doc24Schemas: {
1091
1091
  }, {
1092
1092
  firstName: string | null;
1093
1093
  lastName: string | null;
1094
+ birthdate: Date;
1094
1095
  gender: "m" | "f";
1095
1096
  email: string | null;
1096
- birthdate: Date;
1097
1097
  identificationNumber: string;
1098
1098
  plan: string | null;
1099
1099
  financerId: number | null;
@@ -1112,4 +1112,221 @@ export declare const doc24Schemas: {
1112
1112
  authorizationCode: string | null;
1113
1113
  authorizationCodeExpiration: Date | null;
1114
1114
  }>>;
1115
+ getVerificationCodeParams: import("zod").ZodObject<{
1116
+ identificationType: import("zod").ZodEnum<["ndi", "passport", "credential"]>;
1117
+ identificationValue: import("zod").ZodString;
1118
+ channel: import("zod").ZodEnum<["1", "2"]>;
1119
+ }, "strip", import("zod").ZodTypeAny, {
1120
+ identificationType: "ndi" | "passport" | "credential";
1121
+ identificationValue: string;
1122
+ channel: "1" | "2";
1123
+ }, {
1124
+ identificationType: "ndi" | "passport" | "credential";
1125
+ identificationValue: string;
1126
+ channel: "1" | "2";
1127
+ }>;
1128
+ declareUserParams: import("zod").ZodIntersection<import("zod").ZodObject<{
1129
+ user: import("zod").ZodObject<import("zod").extendShape<{
1130
+ firstName: import("zod").ZodString;
1131
+ lastName: import("zod").ZodString;
1132
+ identificationType: import("zod").ZodEnum<["ndi", "passport", "credential"]>;
1133
+ identificationValue: import("zod").ZodString;
1134
+ countryId: import("zod").ZodString;
1135
+ birthdate: import("zod").ZodDate;
1136
+ gender: import("zod").ZodEnum<["m", "f"]>;
1137
+ }, {
1138
+ phone: import("zod").ZodString;
1139
+ email: import("zod").ZodString;
1140
+ }>, "strip", import("zod").ZodTypeAny, {
1141
+ firstName: string;
1142
+ lastName: string;
1143
+ identificationType: "ndi" | "passport" | "credential";
1144
+ identificationValue: string;
1145
+ countryId: string;
1146
+ birthdate: Date;
1147
+ gender: "m" | "f";
1148
+ phone: string;
1149
+ email: string;
1150
+ }, {
1151
+ firstName: string;
1152
+ lastName: string;
1153
+ identificationType: "ndi" | "passport" | "credential";
1154
+ identificationValue: string;
1155
+ countryId: string;
1156
+ birthdate: Date;
1157
+ gender: "m" | "f";
1158
+ phone: string;
1159
+ email: string;
1160
+ }>;
1161
+ }, "strip", import("zod").ZodTypeAny, {
1162
+ user: {
1163
+ firstName: string;
1164
+ lastName: string;
1165
+ identificationType: "ndi" | "passport" | "credential";
1166
+ identificationValue: string;
1167
+ countryId: string;
1168
+ birthdate: Date;
1169
+ gender: "m" | "f";
1170
+ phone: string;
1171
+ email: string;
1172
+ };
1173
+ }, {
1174
+ user: {
1175
+ firstName: string;
1176
+ lastName: string;
1177
+ identificationType: "ndi" | "passport" | "credential";
1178
+ identificationValue: string;
1179
+ countryId: string;
1180
+ birthdate: Date;
1181
+ gender: "m" | "f";
1182
+ phone: string;
1183
+ email: string;
1184
+ };
1185
+ }>, import("zod").ZodObject<{
1186
+ channel: import("zod").ZodOptional<import("zod").ZodEnum<["1", "2"]>>;
1187
+ code: import("zod").ZodOptional<import("zod").ZodString>;
1188
+ }, "strip", import("zod").ZodTypeAny, {
1189
+ code?: string | undefined;
1190
+ channel?: "1" | "2" | undefined;
1191
+ }, {
1192
+ code?: string | undefined;
1193
+ channel?: "1" | "2" | undefined;
1194
+ }>>;
1195
+ declareUserResponse: import("zod").ZodUnion<[import("zod").ZodObject<{
1196
+ userInfo: import("zod").ZodObject<{
1197
+ email: import("zod").ZodString;
1198
+ phone: import("zod").ZodString;
1199
+ }, "strip", import("zod").ZodTypeAny, {
1200
+ phone: string;
1201
+ email: string;
1202
+ }, {
1203
+ phone: string;
1204
+ email: string;
1205
+ }>;
1206
+ askCode: import("zod").ZodLiteral<true>;
1207
+ }, "strip", import("zod").ZodTypeAny, {
1208
+ askCode: true;
1209
+ userInfo: {
1210
+ phone: string;
1211
+ email: string;
1212
+ };
1213
+ }, {
1214
+ askCode: true;
1215
+ userInfo: {
1216
+ phone: string;
1217
+ email: string;
1218
+ };
1219
+ }>, import("zod").ZodObject<{
1220
+ askCode: import("zod").ZodLiteral<false>;
1221
+ patientId: import("zod").ZodNullable<import("zod").ZodNumber>;
1222
+ userId: import("zod").ZodNumber;
1223
+ }, "strip", import("zod").ZodTypeAny, {
1224
+ patientId: number | null;
1225
+ askCode: false;
1226
+ userId: number;
1227
+ }, {
1228
+ patientId: number | null;
1229
+ askCode: false;
1230
+ userId: number;
1231
+ }>]>;
1232
+ declarePatientParams: import("zod").ZodIntersection<import("zod").ZodObject<{
1233
+ patient: import("zod").ZodObject<{
1234
+ firstName: import("zod").ZodString;
1235
+ lastName: import("zod").ZodString;
1236
+ identificationType: import("zod").ZodEnum<["ndi", "passport", "credential"]>;
1237
+ identificationValue: import("zod").ZodString;
1238
+ countryId: import("zod").ZodString;
1239
+ birthdate: import("zod").ZodDate;
1240
+ gender: import("zod").ZodEnum<["m", "f"]>;
1241
+ }, "strip", import("zod").ZodTypeAny, {
1242
+ firstName: string;
1243
+ lastName: string;
1244
+ identificationType: "ndi" | "passport" | "credential";
1245
+ identificationValue: string;
1246
+ countryId: string;
1247
+ birthdate: Date;
1248
+ gender: "m" | "f";
1249
+ }, {
1250
+ firstName: string;
1251
+ lastName: string;
1252
+ identificationType: "ndi" | "passport" | "credential";
1253
+ identificationValue: string;
1254
+ countryId: string;
1255
+ birthdate: Date;
1256
+ gender: "m" | "f";
1257
+ }>;
1258
+ }, "strip", import("zod").ZodTypeAny, {
1259
+ patient: {
1260
+ firstName: string;
1261
+ lastName: string;
1262
+ identificationType: "ndi" | "passport" | "credential";
1263
+ identificationValue: string;
1264
+ countryId: string;
1265
+ birthdate: Date;
1266
+ gender: "m" | "f";
1267
+ };
1268
+ }, {
1269
+ patient: {
1270
+ firstName: string;
1271
+ lastName: string;
1272
+ identificationType: "ndi" | "passport" | "credential";
1273
+ identificationValue: string;
1274
+ countryId: string;
1275
+ birthdate: Date;
1276
+ gender: "m" | "f";
1277
+ };
1278
+ }>, import("zod").ZodObject<{
1279
+ channel: import("zod").ZodOptional<import("zod").ZodEnum<["1", "2"]>>;
1280
+ code: import("zod").ZodOptional<import("zod").ZodString>;
1281
+ }, "strip", import("zod").ZodTypeAny, {
1282
+ code?: string | undefined;
1283
+ channel?: "1" | "2" | undefined;
1284
+ }, {
1285
+ code?: string | undefined;
1286
+ channel?: "1" | "2" | undefined;
1287
+ }>>;
1288
+ declarePatientResponse: import("zod").ZodUnion<[import("zod").ZodObject<{
1289
+ userInfo: import("zod").ZodObject<{
1290
+ email: import("zod").ZodString;
1291
+ phone: import("zod").ZodString;
1292
+ }, "strip", import("zod").ZodTypeAny, {
1293
+ phone: string;
1294
+ email: string;
1295
+ }, {
1296
+ phone: string;
1297
+ email: string;
1298
+ }>;
1299
+ askCode: import("zod").ZodLiteral<true>;
1300
+ }, "strip", import("zod").ZodTypeAny, {
1301
+ askCode: true;
1302
+ userInfo: {
1303
+ phone: string;
1304
+ email: string;
1305
+ };
1306
+ }, {
1307
+ askCode: true;
1308
+ userInfo: {
1309
+ phone: string;
1310
+ email: string;
1311
+ };
1312
+ }>, import("zod").ZodObject<{
1313
+ askCode: import("zod").ZodLiteral<false>;
1314
+ patientId: import("zod").ZodNullable<import("zod").ZodNumber>;
1315
+ }, "strip", import("zod").ZodTypeAny, {
1316
+ patientId: number | null;
1317
+ askCode: false;
1318
+ }, {
1319
+ patientId: number | null;
1320
+ askCode: false;
1321
+ }>]>;
1322
+ verificationParams: import("zod").ZodObject<{
1323
+ channel: import("zod").ZodOptional<import("zod").ZodEnum<["1", "2"]>>;
1324
+ code: import("zod").ZodOptional<import("zod").ZodString>;
1325
+ }, "strip", import("zod").ZodTypeAny, {
1326
+ code?: string | undefined;
1327
+ channel?: "1" | "2" | undefined;
1328
+ }, {
1329
+ code?: string | undefined;
1330
+ channel?: "1" | "2" | undefined;
1331
+ }>;
1115
1332
  };
package/lib/schemas.js CHANGED
@@ -14,6 +14,8 @@ const basePersonData = zod_1.object({
14
14
  birthdate: zod_1.date(),
15
15
  gender,
16
16
  });
17
+ const patient = basePersonData;
18
+ const user = basePersonData.extend({ phone: zod_1.string(), email: zod_1.string() });
17
19
  const specialtyMode = zod_1.enum(['appointment', 'chat', 'instant']);
18
20
  const specialty = zod_1.object({
19
21
  id: zod_1.number(),
@@ -172,12 +174,48 @@ const coverageInfo = zod_1.object({
172
174
  authorizationCode: zod_1.string().nullable(),
173
175
  authorizationCodeExpiration: zod_1.date().nullable(),
174
176
  }).nullable();
177
+ const getVerificationCodeParams = zod_1.object({
178
+ identificationType,
179
+ identificationValue: zod_1.string(),
180
+ channel: zod_1.enum(['1', '2']),
181
+ });
182
+ const verificationParams = zod_1.object({
183
+ channel: zod_1.enum(['1', '2']).optional(),
184
+ code: zod_1.string().optional(),
185
+ });
186
+ const declareUserParams = zod_1.object({
187
+ user,
188
+ }).and(verificationParams);
189
+ const declarePatientParams = zod_1.object({
190
+ patient,
191
+ }).and(verificationParams);
192
+ const declarePatientResponse = zod_1.object({
193
+ userInfo: zod_1.object({
194
+ email: zod_1.string(),
195
+ phone: zod_1.string(),
196
+ }),
197
+ askCode: zod_1.literal(true),
198
+ }).or(zod_1.object({
199
+ askCode: zod_1.literal(false),
200
+ patientId: zod_1.number().nullable(),
201
+ }));
202
+ const declareUserResponse = zod_1.object({
203
+ userInfo: zod_1.object({
204
+ email: zod_1.string(),
205
+ phone: zod_1.string(),
206
+ }),
207
+ askCode: zod_1.literal(true),
208
+ }).or(zod_1.object({
209
+ askCode: zod_1.literal(false),
210
+ patientId: zod_1.number().nullable(),
211
+ userId: zod_1.number(),
212
+ }));
175
213
  exports.doc24Schemas = {
176
214
  identificationType,
177
215
  sdkCredentials,
178
216
  sdkParams: zod_1.object({ url: zod_1.string(), credentials: sdkCredentials }),
179
- user: basePersonData.extend({ phone: zod_1.string(), email: zod_1.string() }),
180
- patient: basePersonData,
217
+ user,
218
+ patient,
181
219
  specialtyMode,
182
220
  specialty,
183
221
  scheduleAvailabilityFilter,
@@ -291,4 +329,10 @@ exports.doc24Schemas = {
291
329
  diagnosticaPatient,
292
330
  diagnosticaDeepLinkResponse,
293
331
  coverageInfo,
332
+ getVerificationCodeParams,
333
+ declareUserParams,
334
+ declareUserResponse,
335
+ declarePatientParams,
336
+ declarePatientResponse,
337
+ verificationParams,
294
338
  };
package/lib/types.d.ts CHANGED
@@ -30,19 +30,28 @@ export declare namespace Doc24 {
30
30
  type DiagnosticaPatient = TypeOf<typeof doc24Schemas.diagnosticaPatient>;
31
31
  type DiagnosticaHistoryAppointment = TypeOf<typeof doc24Schemas.diagnosticaHistoryAppointment>;
32
32
  type DiagnosticaDeepLinkResponse = TypeOf<typeof doc24Schemas.diagnosticaDeepLinkResponse>;
33
+ type getVerificationCodeParams = TypeOf<typeof doc24Schemas.getVerificationCodeParams>;
34
+ type DeclareUserParams = TypeOf<typeof doc24Schemas.declareUserParams>;
35
+ type DeclareUserResponse = TypeOf<typeof doc24Schemas.declareUserResponse>;
36
+ type DeclarePatientParams = TypeOf<typeof doc24Schemas.declarePatientParams>;
37
+ type DeclarePatientResponse = TypeOf<typeof doc24Schemas.declarePatientResponse>;
38
+ type VerificationParams = TypeOf<typeof doc24Schemas.verificationParams>;
33
39
  type BaseSdk = {
34
- declareUser: (user: User) => Promise<number>;
40
+ declareUser: (params: DeclareUserParams) => Promise<DeclareUserResponse>;
41
+ getUserId: (user: User) => Promise<number>;
35
42
  getUserInstance: (user: User | number) => Promise<UserSdk>;
36
43
  getProfessional: (professionalId: number) => Promise<Professional>;
37
44
  getAvailableScheduleClinics: () => Promise<AvailableScheduleClinics>;
38
45
  enroll: (params: EnrollmentParams) => Promise<void>;
39
46
  getConverageInfo: (identificationValue: string) => Promise<CoverageInfo>;
47
+ getVerificationCode: (params: getVerificationCodeParams) => Promise<any>;
40
48
  getDiagnosticaHistory: (patient: DiagnosticaPatientFilter, from: Date, to: Date) => Promise<DiagnosticaHistoryAppointment[]>;
41
49
  getDiagnosticaDeepLink: (kiosk: string, user: DiagnosticaUser, patient: DiagnosticaPatient) => Promise<DiagnosticaDeepLinkResponse>;
42
50
  getDiagnosticaAccess: (kiosk: string, user: DiagnosticaUser, patient: DiagnosticaPatient) => Promise<void>;
43
51
  };
44
52
  type UserSdk = {
45
- declarePatient: (patient: Patient) => Promise<number>;
53
+ declarePatient: (params: DeclarePatientParams) => Promise<DeclarePatientResponse>;
54
+ getPatientId: (patient: Patient) => Promise<number>;
46
55
  getSpecialties: (mode: SpecialtyMode, language: string) => Promise<Specialty[]>;
47
56
  getScheduleDates: (patientId: number, filter?: ScheduleAvailabilityFilter) => Promise<Date[]>;
48
57
  getSchedule: (patientId: number, specialtyId: number, filter?: ScheduleFilter) => Promise<AvailableAppointment[]>;
@@ -24,9 +24,9 @@ export declare const getChatMethods: (makeRequest: RequestMaker) => {
24
24
  getPatientChats: (patientId: number) => Promise<{
25
25
  id: number;
26
26
  patient: {
27
- id: number;
28
27
  firstName: string;
29
28
  lastName: string;
29
+ id: number;
30
30
  };
31
31
  professional: {
32
32
  id: number;
@@ -1,12 +1,35 @@
1
1
  import { RequestMaker } from '../request';
2
2
  export declare const getPatientMethods: (makeRequest: RequestMaker) => {
3
- declarePatient: (patient: {
3
+ declarePatient: (params: {
4
+ patient: {
5
+ firstName: string;
6
+ lastName: string;
7
+ identificationType: "ndi" | "passport" | "credential";
8
+ identificationValue: string;
9
+ countryId: string;
10
+ birthdate: Date;
11
+ gender: "m" | "f";
12
+ };
13
+ } & {
14
+ code?: string | undefined;
15
+ channel?: "1" | "2" | undefined;
16
+ }) => Promise<{
17
+ askCode: true;
18
+ userInfo: {
19
+ phone: string;
20
+ email: string;
21
+ };
22
+ } | {
23
+ patientId: number | null;
24
+ askCode: false;
25
+ }>;
26
+ getPatientId: (patient: {
4
27
  firstName: string;
5
28
  lastName: string;
6
29
  identificationType: "ndi" | "passport" | "credential";
7
30
  identificationValue: string;
8
- gender: "m" | "f";
9
31
  countryId: string;
10
32
  birthdate: Date;
33
+ gender: "m" | "f";
11
34
  }) => Promise<number>;
12
35
  };
@@ -7,21 +7,50 @@ const validation_1 = require("../request/validation");
7
7
  const schemas_1 = require("../schemas");
8
8
  const utils_1 = require("../utils");
9
9
  const getPatientMethods = (makeRequest) => {
10
- const declarePatient = validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.patient]), zod_1.number(), async (patient) => {
10
+ const declarePatient = async ({ patient, channel, code, }) => {
11
+ const path = '/patient';
11
12
  const mappedPatient = {
12
13
  lastname: patient.lastName,
13
14
  firstname: patient.firstName,
14
- identification_type: utils_1.getIndetificationTypeId(patient.identificationType),
15
+ identification_type: utils_1.getIdetificationTypeId(patient.identificationType),
15
16
  identification_value: patient.identificationValue,
16
17
  birthdate: date_fns_1.format(patient.birthdate, 'yyyy-MM-dd'),
17
18
  gender: patient.gender.toUpperCase(),
18
19
  country_id: patient.countryId,
19
20
  };
20
- const response = await makeRequest('POST', '/patient', {
21
+ const parsedChannel = channel ? parseInt(channel) : channel;
22
+ const response = await makeRequest('POST', path, {
23
+ user_data: mappedPatient,
24
+ channel: parsedChannel,
25
+ code,
26
+ });
27
+ const data = response.data;
28
+ if (data.ask_code)
29
+ return {
30
+ userInfo: data.user_info,
31
+ askCode: true,
32
+ };
33
+ return { askCode: false, patientId: data.patient_id };
34
+ };
35
+ const getPatientId = async (patient) => {
36
+ const path = '/search-patient';
37
+ const mappedPatient = {
38
+ lastname: patient.lastName,
39
+ firstname: patient.firstName,
40
+ identification_type: utils_1.getIdetificationTypeId(patient.identificationType),
41
+ identification_value: patient.identificationValue,
42
+ birthdate: date_fns_1.format(patient.birthdate, 'yyyy-MM-dd'),
43
+ gender: patient.gender.toUpperCase(),
44
+ country_id: patient.countryId,
45
+ };
46
+ const response = await makeRequest('POST', path, {
21
47
  user_data: mappedPatient,
22
48
  });
23
49
  return response.data.patient_id;
24
- });
25
- return { declarePatient };
50
+ };
51
+ return {
52
+ declarePatient: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.declarePatientParams]), schemas_1.doc24Schemas.declarePatientResponse, declarePatient),
53
+ getPatientId: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.patient]), zod_1.number(), getPatientId),
54
+ };
26
55
  };
27
56
  exports.getPatientMethods = getPatientMethods;
@@ -32,9 +32,9 @@ export declare const getVideoVisitMethods: (makeRequest: RequestMaker) => {
32
32
  patientId: number;
33
33
  creationDate: Date;
34
34
  user: {
35
- id: number;
36
35
  phone: string | null;
37
36
  email: string | null;
37
+ id: number;
38
38
  };
39
39
  vcToken: string;
40
40
  }>;
@@ -53,9 +53,9 @@ export declare const getVideoVisitMethods: (makeRequest: RequestMaker) => {
53
53
  patientId: number;
54
54
  creationDate: Date;
55
55
  user: {
56
- id: number;
57
56
  phone: string | null;
58
57
  email: string | null;
58
+ id: number;
59
59
  };
60
60
  vcToken: string;
61
61
  }[]>;
package/lib/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { Doc24 } from '.';
2
2
  export declare const parseDate: (str: string) => Date;
3
3
  export declare const parseDateTime: (str: string) => Date;
4
- export declare const getIndetificationTypeId: (type: Doc24.IdentificationType) => 6 | 5 | 999;
4
+ export declare const getIdetificationTypeId: (type: Doc24.IdentificationType) => 6 | 5 | 999;
package/lib/utils.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIndetificationTypeId = exports.parseDateTime = exports.parseDate = void 0;
3
+ exports.getIdetificationTypeId = exports.parseDateTime = exports.parseDate = void 0;
4
4
  const date_fns_1 = require("date-fns");
5
5
  const timeZone = '-03';
6
6
  const parseDate = (str) => exports.parseDateTime(`${str} 00:00:00`);
7
7
  exports.parseDate = parseDate;
8
8
  const parseDateTime = (str) => date_fns_1.parse(`${str} ${timeZone}`, 'yyyy-MM-dd HH:mm:ss X', new Date());
9
9
  exports.parseDateTime = parseDateTime;
10
- const getIndetificationTypeId = (type) => {
10
+ const getIdetificationTypeId = (type) => {
11
11
  if (type === 'ndi')
12
12
  return 6;
13
13
  if (type === 'passport')
@@ -16,4 +16,4 @@ const getIndetificationTypeId = (type) => {
16
16
  return 999;
17
17
  throw new Error('Invalid identificationType');
18
18
  };
19
- exports.getIndetificationTypeId = getIndetificationTypeId;
19
+ exports.getIdetificationTypeId = getIdetificationTypeId;
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@integraciones_doc24/sdk",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "publishConfig": {
5
- "tag": "1.x"
5
+ "tag": "latest"
6
6
  },
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "scripts": {
10
10
  "build": "tsc",
11
- "prepublish": "npm run build"
11
+ "prepublish": "npm run build",
12
+ "test": "npx tsx test"
12
13
  },
13
14
  "keywords": [],
14
15
  "author": "",