@integraciones_doc24/sdk
v1.15.10
Published
Node.JS library for accessing doc24 api
Downloads
477
Keywords
Readme
@integraciones_doc24/sdk
Node.JS library for accessing doc24 api
Installation
npm i @integraciones_doc24/sdk
Usage
import {doc24Sdk} from '@integraciones_doc24/sdk';
const getBaseSdk = () =>
doc24Sdk({
url: 'https://tapi.doc24.com.ar/ws/sdk',
credentials: {
iss: 'myissuer',
key: 'mysecret',
},
});
const getSpecialities = async (user) => {
const baseSdk = await getBaseSdk();
const userSdk = await baseSdk.getUserInstance(user);
return await userSdk.getSpecialties('instant', 'ES');
};
const getRequestHandler = async () => {
const baseSdk = await getBaseSdk();
return baseSdk.getRequestHandler({
credentials: {
iss: 'doc24issuer',
key: 'doc24secret',
},
baseAddress: 'http://myaddress.com/route/to/webhook',
eventHandlers: {
onAppointmentStatusChange: ({id, status, changeDate}) => {
console.log({id, status, changeDate});
},
onConsultationStatusChange: ({
id,
invitationId,
status,
changeDate,
vcToken,
}) => {
console.log({id, invitationId, status, changeDate, vcToken});
},
onInvitationStatusChange: ({id, status, changeDate}) => {
console.log({id, status, changeDate});
},
onChatUpdate: ({id, status, patientId, professionalId, date}) => {
console.log({id, status, patientId, professionalId, date});
},
},
});
};
The library exports the function doc24Sdk
. It takes one parameters of type SdkParams
, and returns a BaseSdk
.
It also returns an extra getRequestHandler
function that takes a RequestHandlerParams
type SdkCredentials = {
iss: string;
key: string;
};
type SdkParams = {
url: string;
credentials: SdkCredentials;
};
export type BaseSdk = {
declareUser: (params: DeclareUserParams) => Promise<DeclareUserResponse>;
getUserId: (user: User) => Promise<number>;
getUserInstance: (user: User | number) => Promise<UserSdk>;
getProfessional: (professionalId: number) => Promise<Professional>;
getAvailableScheduleClinics: () => Promise<AvailableScheduleClinics>;
enroll: (params: EnrollmentParams) => Promise<void>;
getCoverageInfo: (identificationValue: string) => Promise<CoverageInfo>;
sendVerificationCode: (params: SendVerificationCodeParams) => Promise<void>;
getDiagnosticaHistory: (
patient: DiagnosticaPatientFilter,
from: Date,
to: Date,
) => Promise<DiagnosticaHistoryAppointment[]>;
getDiagnosticaDeepLink: (
kiosk: string,
user: DiagnosticaUser,
patient: DiagnosticaPatient,
) => Promise<DiagnosticaDeepLinkResponse>;
getDiagnosticaAccess: (
kiosk: string,
user: DiagnosticaUser,
patient: DiagnosticaPatient,
) => Promise<void>;
externalLogin: (
params: ExternalLoginParams,
) => Promise<ExternalLoginResponse>;
preExternalEnrollment: (params: PreExternalEnrollmentParams) => Promise<void>;
externalEnrollment: (
params: ExternalEnrollmentParams,
) => Promise<ExternalLoginResponse>;
sendExternalVerificationCode: (
params: SendExternalVerificationCodeParams,
) => Promise<void>;
verifyExternalVerificationCode: (
params: VerifyExternalVerificationCodeParams,
) => Promise<any>;
externalResetPassword: (params: ExternalResetPasswordParams) => Promise<any>;
getExternalStudiesHistoryLink: (
patient: ExternalPatient,
) => Promise<string | null>;
getExternalAppointmentsLink: (
identificationValue: string,
birthdate: Date,
) => Promise<string | null>;
getExternalAppointments: () => Promise<ExternalAppointment[]>;
cancelExternalAppointment: (
appointmentId: ExternalAppointment,
) => Promise<void>;
};
type RequestHandlerParams = {
// Credentials that doc24 should use when singing the jwt
credentials: SdkCredentials;
eventHandlers: Webhook.Events;
// Address in which doc24 should send the requests
baseAddress: string;
};
getRequestHandler
should be called only once, and takes care of managing the webhook that receives events from doc24.
Express example
const handler = await getRequestHandler();
app.all('/doc24', async (req, res) => {
const response = await handler({
headers: req.headers,
body: req.body,
query: req.query,
});
res.status(response.status.code).json(response.data);
});
UserSdk
Most of the methods need a user specified, so getUserInstance
returns an instance of UserSdk
with them.
export type UserSdk = {
declarePatient: (
params: DeclarePatientParams,
) => Promise<DeclarePatientResponse>;
getPatientId: (patient: Patient) => Promise<number>;
deletePatient: (patientId: number) => Promise<void>;
getSpecialties: (
mode: SpecialtyMode,
language: string,
) => Promise<Specialty[]>;
getScheduleDates: (
patientId: number,
filter?: ScheduleAvailabilityFilter,
) => Promise<Date[]>;
getSchedule: (
patientId: number,
specialtyId: number,
filter?: ScheduleFilter,
) => Promise<AvailableAppointment[]>;
getAppointment: (appointmentId: number) => Promise<Appointment>;
getAppointmentByVcToken: (vcToken: string) => Promise<Appointment>;
scheduleVideoVisit: (params: ScheduleParameters) => Promise<string>;
cancelVideoVisit: (vcToken: string) => Promise<void>;
getVideoVisit: (vcToken: string, patientId: number) => Promise<VideoVisit>;
getVideoVisitDetails: (vcId: number) => Promise<VideoVisitDetails>;
getVideoVisitLink: (
vcToken: string,
patientId: number,
) => Promise<string | null>;
getPatientVideoVisitHistory: (
patientId: number,
) => Promise<HistoricalVideoVisit[]>;
getActiveVideoVisits: () => Promise<ActiveVideoVisitData[]>;
getAvailableChatrooms: (
patientId: number,
specialtyId: number,
filter: ChatroomAvailabilityFilter,
) => Promise<AvailableChatroom[]>;
createNewChat: (chatParameters: ChatParameters) => Promise<number>;
getPatientChats: (patientId: number) => Promise<ChatDetails[]>;
getChatPosts: (chatId: number) => Promise<ChatPost[]>;
cancelChat: (chatId: number) => Promise<void>;
sendChatMessage: (chatId: number, message: string) => Promise<number>;
userId: number;
};