@integraciones_doc24/sdk 1.15.4 → 1.15.6

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";
4
+ identificationType: "dni" | "ndi" | "passport" | "credential" | "nn" | "cpf" | "rg";
5
5
  identificationValue: string;
6
- gender: "m" | "f" | "o";
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
15
  firstName: string;
15
16
  lastName: string;
16
- identificationType: "DNI";
17
+ birthday: Date;
18
+ identificationType: "dni";
17
19
  identificationValue: string;
18
- gender: "m" | "f" | "o";
20
+ gender: "m" | "f";
19
21
  phone: string;
20
22
  email: string;
21
- language: string;
22
- birthday: Date;
23
23
  }, patient: {
24
24
  firstName: string;
25
25
  lastName: string;
26
- identificationType: "DNI";
27
- identificationValue: string;
28
- gender: "m" | "f" | "o";
29
26
  birthday: Date;
27
+ identificationType: "dni";
28
+ identificationValue: string;
29
+ gender: "m" | "f";
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
38
  firstName: string;
38
39
  lastName: string;
39
- identificationType: "DNI";
40
+ birthday: Date;
41
+ identificationType: "dni";
40
42
  identificationValue: string;
41
- gender: "m" | "f" | "o";
43
+ gender: "m" | "f";
42
44
  phone: string;
43
45
  email: string;
44
- language: string;
45
- birthday: Date;
46
46
  }, patient: {
47
47
  firstName: string;
48
48
  lastName: string;
49
- identificationType: "DNI";
50
- identificationValue: string;
51
- gender: "m" | "f" | "o";
52
49
  birthday: Date;
50
+ identificationType: "dni";
51
+ identificationValue: string;
52
+ gender: "m" | "f";
53
53
  }) => Promise<void>;
54
54
  };
@@ -6,12 +6,14 @@ 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 = async (patient, from, to) => {
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) => {
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,
14
+ id_type: patient.identificationType === 'ndi'
15
+ ? 'DNI'
16
+ : patient.identificationType,
15
17
  id_value: patient.identificationValue,
16
18
  },
17
19
  dateFrom: from.toISOString(),
@@ -24,8 +26,12 @@ const getDiagnosticaMethods = (makeRequest) => {
24
26
  exams: i.exams,
25
27
  deepLink: i.deeplink,
26
28
  }));
27
- };
28
- const getDiagnosticaDeepLink = async (kiosk, user, patient) => {
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) => {
29
35
  const path = '/deeplink-diagnostica';
30
36
  const response = await makeRequest('POST', path, {
31
37
  kiosk,
@@ -36,8 +42,12 @@ const getDiagnosticaMethods = (makeRequest) => {
36
42
  if (data.forwarding_required)
37
43
  return { forwardingRequired: true, deepLink: data.deeplink };
38
44
  return { forwardingRequired: false };
39
- };
40
- const getDiagnosticaAccess = async (kiosk, user, patient) => {
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) => {
41
51
  const path = '/access-diagnostica';
42
52
  await makeRequest('POST', path, {
43
53
  kiosk,
@@ -45,20 +55,8 @@ const getDiagnosticaMethods = (makeRequest) => {
45
55
  patient: mapPatientData(patient),
46
56
  });
47
57
  return;
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
- };
58
+ });
59
+ return { getDiagnosticaHistory, getDiagnosticaDeepLink, getDiagnosticaAccess };
62
60
  };
63
61
  exports.getDiagnosticaMethods = getDiagnosticaMethods;
64
62
  const mapPatientData = (patient) => {
@@ -8,15 +8,12 @@ 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");
12
11
  const getBaseSdk = async (url, credentials) => {
13
12
  const makeRequest = await request_1.getRequestFactory(url, credentials);
14
13
  const diagnosticaMethods = diagnostica_1.getDiagnosticaMethods(makeRequest);
15
- const externalMethods = external_1.getExternalMethods(makeRequest);
16
14
  const userMethods = user_1.getUserMethods(makeRequest, url, credentials);
17
15
  const baseSdk = {
18
16
  ...diagnosticaMethods,
19
- ...externalMethods,
20
17
  ...userMethods,
21
18
  getProfessional: validation_1.validateFunction(zod_1.tuple([zod_1.number()]), schemas_1.doc24Schemas.professional, async (professionalId) => {
22
19
  const path = `/professional/${professionalId}`;
@@ -1,75 +1,25 @@
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: (params: {
5
- user: {
6
- firstName: string;
7
- lastName: string;
8
- identificationType: number;
9
- identificationValue: string;
10
- countryId: string;
11
- birthdate: Date;
12
- gender: "m" | "f" | "o";
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: {
4
+ declareUser: (user: {
31
5
  firstName: string;
32
6
  lastName: string;
33
- identificationType: number;
7
+ identificationType: "dni" | "ndi" | "passport" | "credential" | "nn" | "cpf" | "rg";
34
8
  identificationValue: string;
35
- countryId: string;
36
- birthdate: Date;
37
- gender: "m" | "f" | "o";
9
+ gender: "m" | "f";
38
10
  phone: string;
39
11
  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
- firstName: string;
48
- lastName: string;
49
- identificationType: number;
50
- identificationValue: string;
51
12
  countryId: string;
52
13
  birthdate: Date;
53
- gender: "m" | "f" | "o";
54
- phone: string;
55
- email: string;
56
14
  }) => Promise<any>;
57
- enroll: (params: {
58
- firstName: string;
59
- lastName: string;
60
- birthdate: Date;
61
- gender: "m" | "f" | "o";
62
- email: string;
63
- identificationNumber: string;
64
- startDate: Date;
65
- plan: string;
66
- }) => Promise<void>;
67
- getCoverageInfo: (identificationValue: string) => Promise<{
15
+ getUserInstance: (...params: any) => Promise<any>;
16
+ enroll: (...params: any) => Promise<void>;
17
+ getConverageInfo: (identificationValue: string) => Promise<{
68
18
  firstName: string | null;
69
19
  lastName: string | null;
70
- birthdate: Date;
71
- gender: "m" | "f" | "o";
20
+ gender: "m" | "f";
72
21
  email: string | null;
22
+ birthdate: Date;
73
23
  identificationNumber: string;
74
24
  plan: string | null;
75
25
  financerId: number | null;
@@ -8,40 +8,11 @@ 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: 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
- };
39
11
  const getUserId = async (user) => {
40
- const path = '/search-user';
41
12
  const mappedUser = {
42
13
  lastname: user.lastName,
43
14
  firstname: user.firstName,
44
- identification_type: user.identificationType,
15
+ identification_type: utils_1.getIndetificationTypeId(user.identificationType),
45
16
  identification_value: user.identificationValue,
46
17
  birthdate: date_fns_1.format(user.birthdate, 'yyyy-MM-dd'),
47
18
  gender: user.gender.toUpperCase(),
@@ -49,46 +20,15 @@ const getUserMethods = (makeRequest, url, credentials) => {
49
20
  email: user.email,
50
21
  country_id: user.countryId,
51
22
  };
52
- const response = await makeRequest('POST', path, {
23
+ const response = await makeRequest('POST', '/user', {
53
24
  user_data: mappedUser,
54
25
  });
55
26
  return response.data.user_id;
56
27
  };
57
- const sendVerificationCode = async (params) => {
58
- const path = '/send-verification-code';
59
- const mappedParams = {
60
- identification_type: 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 getCoverageInfo = async (identificationValue) => {
28
+ const getConverageInfo = validation_1.validateFunction(zod_1.tuple([zod_1.string()]), schemas_1.doc24Schemas.coverageInfo, async (identificationValue) => {
87
29
  const path = `/info-coverage/${identificationValue}`;
88
30
  const response = await makeRequest('GET', path);
89
31
  const raw = response.data.info;
90
- if (!raw)
91
- return null;
92
32
  const mappedCoverageInfo = {
93
33
  financerId: raw.id_financiador,
94
34
  defaultAffiliationId: raw.id_afiliacion_default,
@@ -118,16 +58,31 @@ const getUserMethods = (makeRequest, url, credentials) => {
118
58
  : null,
119
59
  };
120
60
  return mappedCoverageInfo;
121
- };
61
+ });
122
62
  return {
123
- declareUser: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.declareUserParams]), schemas_1.doc24Schemas.declareUserResponse, declareUser),
124
- getUserId: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.user]), zod_1.number(), getUserId),
125
- sendVerificationCode: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.sendVerificationCodeParams]), zod_1.void(), sendVerificationCode),
63
+ declareUser: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.user]), zod_1.number(), getUserId),
126
64
  getUserInstance: validation_1.validateFunction(zod_1.tuple([zod_1.union([schemas_1.doc24Schemas.user, zod_1.number()])]),
127
65
  // TODO: validate?
128
- zod_1.any(), getUserInstance),
129
- enroll: validation_1.validateFunction(zod_1.tuple([schemas_1.doc24Schemas.enrollmentParams]), zod_1.void(), enroll),
130
- getCoverageInfo: validation_1.validateFunction(zod_1.tuple([zod_1.string()]), schemas_1.doc24Schemas.coverageInfo, getCoverageInfo),
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
86
  };
132
87
  };
133
88
  exports.getUserMethods = getUserMethods;