npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@schedule-tribe/pd-sdk

v0.0.4

Published

This package provides TypeScript type definitions for handling Digital Platform in Domain-Driven Design contexts

Downloads

1

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.