@integraciones_doc24/sdk 1.15.6 → 1.15.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
1
  import { RequestMaker } from '../request';
2
2
  export declare const getDiagnosticaMethods: (makeRequest: RequestMaker) => {
3
3
  getDiagnosticaHistory: (patient: {
4
- identificationType: "dni" | "ndi" | "passport" | "credential" | "nn" | "cpf" | "rg";
4
+ gender?: "m" | "f" | "o" | undefined;
5
+ identificationType: "DNI";
5
6
  identificationValue: string;
6
- gender: "m" | "f";
7
7
  }, from: Date, to: Date) => Promise<{
8
8
  date: Date;
9
9
  location: string;
@@ -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;
14
+ gender?: "m" | "f" | "o" | undefined;
15
15
  firstName: string;
16
16
  lastName: string;
17
- birthday: Date;
18
- identificationType: "dni";
17
+ identificationType: "DNI";
19
18
  identificationValue: string;
20
- gender: "m" | "f";
21
19
  phone: string;
22
20
  email: string;
21
+ language: string;
22
+ birthday: Date;
23
23
  }, patient: {
24
+ gender?: "m" | "f" | "o" | undefined;
24
25
  firstName: string;
25
26
  lastName: string;
26
- birthday: Date;
27
- identificationType: "dni";
27
+ identificationType: "DNI";
28
28
  identificationValue: string;
29
- 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;
37
+ gender?: "m" | "f" | "o" | undefined;
38
38
  firstName: string;
39
39
  lastName: string;
40
- birthday: Date;
41
- identificationType: "dni";
40
+ identificationType: "DNI";
42
41
  identificationValue: string;
43
- gender: "m" | "f";
44
42
  phone: string;
45
43
  email: string;
44
+ language: string;
45
+ birthday: Date;
46
46
  }, patient: {
47
+ gender?: "m" | "f" | "o" | undefined;
47
48
  firstName: string;
48
49
  lastName: string;
49
- birthday: Date;
50
- identificationType: "dni";
50
+ identificationType: "DNI";
51
51
  identificationValue: string;
52
- gender: "m" | "f";
52
+ birthday: Date;
53
53
  }) => Promise<void>;
54
54
  };
@@ -6,14 +6,12 @@ const zod_1 = require("zod");
6
6
  const validation_1 = require("../request/validation");
7
7
  const schemas_1 = require("../schemas");
8
8
  const getDiagnosticaMethods = (makeRequest) => {
9
- const getDiagnosticaHistory = validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.diagnosticaPatientFilter, zod_1.date(), zod_1.date()]), schemas_1.doc24Schemas.diagnosticaHistoryAppointment.array(), async (patient, from, to) => {
9
+ const getDiagnosticaHistory = async (patient, from, to) => {
10
10
  const path = '/history-diagnostica';
11
11
  const response = await makeRequest('POST', path, {
12
12
  patient: {
13
13
  gender: patient.gender,
14
- id_type: patient.identificationType === 'ndi'
15
- ? 'DNI'
16
- : patient.identificationType,
14
+ id_type: patient.identificationType,
17
15
  id_value: patient.identificationValue,
18
16
  },
19
17
  dateFrom: from.toISOString(),
@@ -26,12 +24,8 @@ const getDiagnosticaMethods = (makeRequest) => {
26
24
  exams: i.exams,
27
25
  deepLink: i.deeplink,
28
26
  }));
29
- });
30
- const getDiagnosticaDeepLink = validation_1.validateFunction(zod_1.tuple([
31
- zod_1.string(),
32
- schemas_1.doc24Schemas.diagnosticaUser,
33
- schemas_1.doc24Schemas.diagnosticaPatient,
34
- ]), schemas_1.doc24Schemas.diagnosticaDeepLinkResponse, async (kiosk, user, patient) => {
27
+ };
28
+ const getDiagnosticaDeepLink = async (kiosk, user, patient) => {
35
29
  const path = '/deeplink-diagnostica';
36
30
  const response = await makeRequest('POST', path, {
37
31
  kiosk,
@@ -42,12 +36,8 @@ const getDiagnosticaMethods = (makeRequest) => {
42
36
  if (data.forwarding_required)
43
37
  return { forwardingRequired: true, deepLink: data.deeplink };
44
38
  return { forwardingRequired: false };
45
- });
46
- const getDiagnosticaAccess = validation_1.validateFunction(zod_1.tuple([
47
- zod_1.string(),
48
- schemas_1.doc24Schemas.diagnosticaUser,
49
- schemas_1.doc24Schemas.diagnosticaPatient,
50
- ]), zod_1.void(), async (kiosk, user, patient) => {
39
+ };
40
+ const getDiagnosticaAccess = async (kiosk, user, patient) => {
51
41
  const path = '/access-diagnostica';
52
42
  await makeRequest('POST', path, {
53
43
  kiosk,
@@ -55,18 +45,31 @@ const getDiagnosticaMethods = (makeRequest) => {
55
45
  patient: mapPatientData(patient),
56
46
  });
57
47
  return;
58
- });
59
- return { getDiagnosticaHistory, getDiagnosticaDeepLink, getDiagnosticaAccess };
48
+ };
49
+ return {
50
+ getDiagnosticaHistory: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.diagnosticaPatientFilter, zod_1.date(), zod_1.date()]), schemas_1.doc24Schemas.diagnosticaHistoryAppointment.array(), getDiagnosticaHistory),
51
+ getDiagnosticaDeepLink: validation_1.validateFunction(zod_1.tuple([
52
+ zod_1.string(),
53
+ schemas_1.doc24Schemas.diagnosticaUser,
54
+ schemas_1.doc24Schemas.diagnosticaPatient,
55
+ ]), schemas_1.doc24Schemas.diagnosticaDeepLinkResponse, getDiagnosticaDeepLink),
56
+ getDiagnosticaAccess: validation_1.validateFunction(zod_1.tuple([
57
+ zod_1.string(),
58
+ schemas_1.doc24Schemas.diagnosticaUser,
59
+ schemas_1.doc24Schemas.diagnosticaPatient,
60
+ ]), zod_1.void(), getDiagnosticaAccess),
61
+ };
60
62
  };
61
63
  exports.getDiagnosticaMethods = getDiagnosticaMethods;
62
64
  const mapPatientData = (patient) => {
65
+ var _a;
63
66
  return {
64
67
  name: patient.firstName,
65
68
  surname: patient.lastName,
66
69
  birthday: date_fns_1.format(patient.birthday, 'yyyy-MM-dd'),
67
70
  id_type: 'DNI',
68
71
  id_value: patient.identificationValue,
69
- gender: patient.gender.toLocaleUpperCase(),
72
+ gender: (_a = patient.gender) === null || _a === void 0 ? void 0 : _a.toLocaleUpperCase(),
70
73
  };
71
74
  };
72
75
  const mapUserData = (user) => {
@@ -4,10 +4,10 @@ export declare const getExternalMethods: (makeRequest: RequestMaker) => {
4
4
  user: string;
5
5
  password: string;
6
6
  }) => Promise<{
7
+ gender?: "m" | "f" | "o" | undefined;
7
8
  firstName: string;
8
9
  lastName: string;
9
10
  countryId: string;
10
- gender: "m" | "f" | "o";
11
11
  phone: string;
12
12
  email: string;
13
13
  birthday: Date;
@@ -132,10 +132,10 @@ export declare const getExternalMethods: (makeRequest: RequestMaker) => {
132
132
  emailCode?: undefined;
133
133
  phoneCode: string;
134
134
  })) => Promise<{
135
+ gender?: "m" | "f" | "o" | undefined;
135
136
  firstName: string;
136
137
  lastName: string;
137
138
  countryId: string;
138
- gender: "m" | "f" | "o";
139
139
  phone: string;
140
140
  email: string;
141
141
  birthday: Date;
@@ -8,12 +8,15 @@ const schemas_1 = require("../schemas");
8
8
  const utils_1 = require("../utils");
9
9
  const diagnostica_1 = require("./diagnostica");
10
10
  const user_1 = require("./user");
11
+ const external_1 = require("./external");
11
12
  const getBaseSdk = async (url, credentials) => {
12
13
  const makeRequest = await request_1.getRequestFactory(url, credentials);
13
14
  const diagnosticaMethods = diagnostica_1.getDiagnosticaMethods(makeRequest);
15
+ const externalMethods = external_1.getExternalMethods(makeRequest);
14
16
  const userMethods = user_1.getUserMethods(makeRequest, url, credentials);
15
17
  const baseSdk = {
16
18
  ...diagnosticaMethods,
19
+ ...externalMethods,
17
20
  ...userMethods,
18
21
  getProfessional: validation_1.validateFunction(zod_1.tuple([zod_1.number()]), schemas_1.doc24Schemas.professional, async (professionalId) => {
19
22
  const path = `/professional/${professionalId}`;
@@ -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
+ identificationType?: number | undefined;
7
+ identificationValue?: string | undefined;
8
+ gender?: "m" | "f" | "o" | undefined;
9
+ phone?: string | undefined;
10
+ firstName: string;
11
+ lastName: string;
12
+ countryId: string;
13
+ birthdate: Date;
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: {
31
+ identificationType?: number | undefined;
32
+ identificationValue?: string | undefined;
33
+ gender?: "m" | "f" | "o" | undefined;
34
+ phone?: string | undefined;
5
35
  firstName: string;
6
36
  lastName: string;
7
- identificationType: "dni" | "ndi" | "passport" | "credential" | "nn" | "cpf" | "rg";
8
- identificationValue: string;
9
- gender: "m" | "f";
10
- phone: string;
37
+ countryId: string;
38
+ birthdate: Date;
11
39
  email: string;
40
+ }) => Promise<number>;
41
+ sendVerificationCode: (params: {
42
+ identificationType: number;
43
+ identificationValue: string;
44
+ channel: "1" | "2";
45
+ }) => Promise<void>;
46
+ getUserInstance: (user: number | {
47
+ identificationType?: number | undefined;
48
+ identificationValue?: string | undefined;
49
+ gender?: "m" | "f" | "o" | undefined;
50
+ phone?: string | undefined;
51
+ firstName: string;
52
+ lastName: string;
12
53
  countryId: string;
13
54
  birthdate: Date;
55
+ email: string;
14
56
  }) => Promise<any>;
15
- getUserInstance: (...params: any) => Promise<any>;
16
- enroll: (...params: any) => Promise<void>;
17
- getConverageInfo: (identificationValue: string) => Promise<{
57
+ enroll: (params: {
58
+ gender?: "m" | "f" | "o" | undefined;
59
+ firstName: string;
60
+ lastName: string;
61
+ birthdate: Date;
62
+ email: string;
63
+ identificationNumber: string;
64
+ startDate: Date;
65
+ plan: string;
66
+ }) => Promise<void>;
67
+ getCoverageInfo: (identificationValue: string) => Promise<{
68
+ gender?: "m" | "f" | "o" | undefined;
18
69
  firstName: string | null;
19
70
  lastName: string | null;
20
- gender: "m" | "f";
21
- email: string | null;
22
71
  birthdate: Date;
72
+ email: string | null;
23
73
  identificationNumber: string;
24
74
  plan: string | null;
25
75
  financerId: number | null;
@@ -8,27 +8,90 @@ 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
+ var _a;
13
+ const path = '/user';
14
+ const mappedUser = {
15
+ lastname: user.lastName,
16
+ firstname: user.firstName,
17
+ identification_type: user.identificationType,
18
+ identification_value: user.identificationValue,
19
+ birthdate: date_fns_1.format(user.birthdate, 'yyyy-MM-dd'),
20
+ gender: (_a = user.gender) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
21
+ phone: user.phone,
22
+ email: user.email,
23
+ country_id: user.countryId,
24
+ };
25
+ const parsedChannel = channel ? parseInt(channel) : channel;
26
+ const response = await makeRequest('POST', path, {
27
+ user_data: mappedUser,
28
+ channel: parsedChannel,
29
+ code,
30
+ });
31
+ const data = response.data;
32
+ if (data.ask_code)
33
+ return { askCode: true, userInfo: data.user_info };
34
+ return {
35
+ askCode: false,
36
+ userId: response.data.user_id,
37
+ patientId: response.data.patient_id,
38
+ };
39
+ };
11
40
  const getUserId = async (user) => {
41
+ var _a;
42
+ const path = '/search-user';
12
43
  const mappedUser = {
13
44
  lastname: user.lastName,
14
45
  firstname: user.firstName,
15
- identification_type: utils_1.getIndetificationTypeId(user.identificationType),
46
+ identification_type: user.identificationType,
16
47
  identification_value: user.identificationValue,
17
48
  birthdate: date_fns_1.format(user.birthdate, 'yyyy-MM-dd'),
18
- gender: user.gender.toUpperCase(),
49
+ gender: (_a = user.gender) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
19
50
  phone: user.phone,
20
51
  email: user.email,
21
52
  country_id: user.countryId,
22
53
  };
23
- const response = await makeRequest('POST', '/user', {
54
+ const response = await makeRequest('POST', path, {
24
55
  user_data: mappedUser,
25
56
  });
26
57
  return response.data.user_id;
27
58
  };
28
- const getConverageInfo = validation_1.validateFunction(zod_1.tuple([zod_1.string()]), schemas_1.doc24Schemas.coverageInfo, async (identificationValue) => {
59
+ const sendVerificationCode = async (params) => {
60
+ const path = '/send-verification-code';
61
+ const mappedParams = {
62
+ identification_type: params.identificationType,
63
+ identification_value: params.identificationValue,
64
+ channel: parseInt(params.channel),
65
+ };
66
+ await makeRequest('POST', path, mappedParams);
67
+ };
68
+ const getUserInstance = async (user) => {
69
+ const userId = typeof user === 'number' ? user : await getUserId(user);
70
+ return userSdk_1.userSdk(url, credentials, userId);
71
+ };
72
+ const enroll = async (params) => {
73
+ var _a;
74
+ const path = `/enrollment`;
75
+ const mappedUser = {
76
+ firstname: params.firstName,
77
+ lastname: params.lastName,
78
+ gender: (_a = params.gender) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
79
+ identification_number: params.identificationNumber,
80
+ birthdate: date_fns_1.format(params.birthdate, 'yyyy-MM-dd'),
81
+ email: params.email,
82
+ plan: params.plan,
83
+ start_date: date_fns_1.format(params.startDate, 'yyyy-MM-dd'),
84
+ };
85
+ await makeRequest('POST', path, {
86
+ user_data: mappedUser,
87
+ });
88
+ };
89
+ const getCoverageInfo = async (identificationValue) => {
29
90
  const path = `/info-coverage/${identificationValue}`;
30
91
  const response = await makeRequest('GET', path);
31
92
  const raw = response.data.info;
93
+ if (!raw)
94
+ return null;
32
95
  const mappedCoverageInfo = {
33
96
  financerId: raw.id_financiador,
34
97
  defaultAffiliationId: raw.id_afiliacion_default,
@@ -58,31 +121,16 @@ const getUserMethods = (makeRequest, url, credentials) => {
58
121
  : null,
59
122
  };
60
123
  return mappedCoverageInfo;
61
- });
124
+ };
62
125
  return {
63
- declareUser: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.user]), zod_1.number(), getUserId),
126
+ declareUser: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.declareUserParams]), schemas_1.doc24Schemas.declareUserResponse, declareUser),
127
+ getUserId: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.user]), zod_1.number(), getUserId),
128
+ sendVerificationCode: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.sendVerificationCodeParams]), zod_1.void(), sendVerificationCode),
64
129
  getUserInstance: validation_1.validateFunction(zod_1.tuple([zod_1.union([schemas_1.doc24Schemas.user, zod_1.number()])]),
65
130
  // 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,
131
+ zod_1.any(), getUserInstance),
132
+ enroll: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.enrollmentParams]), zod_1.void(), enroll),
133
+ getCoverageInfo: validation_1.validateFunction(zod_1.tuple([zod_1.string()]), schemas_1.doc24Schemas.coverageInfo, getCoverageInfo),
86
134
  };
87
135
  };
88
136
  exports.getUserMethods = getUserMethods;