Package Exports
- @schedule-tribe/pd-sdk
- @schedule-tribe/pd-sdk/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@schedule-tribe/pd-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Schedule SDK Documentation
Welcome to the Schedule SDK documentation. This guide provides an overview of the SDK's functionalities and how to use them to manage medical appointments effectively.
Table of Contents
Installation
To install the Schedule SDK, use npm or yarn:
npm install @schedule-tribe/schedule rich-domain curl2axios axios
Configuration
To use the SDK, you need to configure it with your credentials, tenant, and API URL.
Example Configuration
import Platform, { Config, Credentials, Tenant } from "@schedule-tribe/schedule";
const credentials: Credentials = {
username: '...',
password: '...'
};
const config: Config = {
url: new URL('https://api.example.com'),
tenant: 'SDK1',
credentials: credentials,
emitEvents: true,
mode: 'debug'
};
const platform = new Platform(config);
Usage
Book a Schedule
To book a schedule, use the book method:
import Schedule from "@schedule-tribe/schedule";
const crm = CRM.init(req.body.crm);
const doctorName = Name.init(req.body.doctorName);
const patientName = Name.init(req.body.patientName);
const doctor = Doctor.init({ crm, name: doctorName });
const document = CPF.init(req.body.cpf);
const patient = Patient.init({ name: patientName, document });
const procedure = Procedure.init({ type: req.body.procedure });
const date = Dates.init(req.body.date);
const duration = Duration.init(req.body.duration);
const schedule = Schedule.init({ doctor, date, duration, patient, procedure });
platform.book(schedule).then(result => {
if (result.isOk()) {
console.log('Schedule booked successfully');
} else {
console.error('Failed to book schedule:', result.error());
}
});
Cancel a Schedule
To cancel a schedule, use the cancel method:
import { Id } from "rich-domain";
const scheduleId = Id('1');
platform.cancel(scheduleId).then(result => {
if (result.isOk()) {
console.log('Schedule cancelled successfully');
} else {
console.error('Failed to cancel schedule:', result.error());
}
});
List Schedules
To list all schedules, use the list method:
platform.list().then(result => {
if (result.isOk()) {
console.log('Schedules:', result.value());
} else {
console.error('Failed to list schedules:', result.error());
}
});
Types
Tenant
The Tenant type defines the possible tenants:
export type Tenant = 'SDK1' | 'SDK2';
ScheduleModel
The ScheduleModel type represents the structure of a schedule:
export type ScheduleModel = {
id: string;
date: Date;
duration: number;
doctor: {
id: string;
name: string;
crm: string;
createdAt: Date;
updatedAt: Date;
};
patient: {
id: string;
name: string;
document: string;
createdAt: Date;
updatedAt: Date;
};
procedure: {
id: string;
type: string;
createdAt: Date;
updatedAt: Date;
};
status: string;
createdAt: Date;
updatedAt: Date;
}
Credentials
The Credentials type defines the authentication credentials:
export type Credentials = {
username: string;
password: string;
}
Config
The Config type defines the configuration for the SDK:
export type Config = {
url: URL;
tenant: Tenant;
credentials: Credentials;
emitEvents?: boolean;
mode?: 'debug';
}
Events
The SDK can emit events for schedule actions if emitEvents is enabled in the configuration.
Schedule Canceled Event
contexts.dispatchEvent('schedule:canceled', { id });
Schedule Booked Event
contexts.dispatchEvent('schedule:booked', { schedule });
Error Handling
All methods return a Result object, which can be either Ok or Fail. Use the isOk() method to check if the operation was successful and handle errors accordingly.
License
This project is licensed under the MIT License.
This documentation provides a comprehensive guide to using the Schedule SDK for managing medical appointments. For further details or questions, please refer to the official repository or contact the support team.