NAV Navbar
Overview UI / JS API
UI / JS
  • Introduction
  • Overview
  • Javascript API
  • UI Notes
  • Introduction

    The Antidote API is organised around REST. The API has predictable URLs and makes proper use of HTTP methods (E.G GET, POST, PATCH, DELETE, PUTS) and status codes (E.G 200, 201, 204, 400, 403, 401...). It also supports cross-origin resource sharing (CORS) which allows you to use the browser to communicate directly and securely with the API without the need for a proxy.

    The API has been broken down into three documents that you should read:

    Overview

    This document will explain how to implement our javascript package, and additionally, for those that are building their own UI, the UI/UX considerations that we expect your own implementation to conform to.

    Javascript API

    Methods

    // Typescript Interface
    interface IAntidoteMedicalScreening {
      init(settings: IMedicalScreeningSettings): IAntidoteMedicalScreening; // This is actually a static method
      start(sessionId: string, onFinish: Function): void;
      destroy(): void;
    }
    
    Method Name Description
    init (static) Initialises the Antidote Medical Screening UI on your site. (Adds in the dom node, bootstraps react)
    start Starts the medical screening session
    destroy Destroy's the instance

    init

    Configuration options for init:

    // Typescript Interface
    interface IMedicalScreeningSettings {
      container?: Element; 
      url?: string;
      modal?: boolean;
      debug?: boolean;
    }
    
    Setting Key Default Description
    container null An Element instance. If no value is provided, it will attempt to find an element on the page with the id of #antidote-medical-screening, and use it. If no element is found, then it will create its own element and append it to the end of the body dom.
    url https://api.cegascreening.com Change the URL the library uses to communicate to the medical library, you could use this to proxy requests, or change medical screening environments.
    modal true Toggle the modal mode or inline mode.
    debug false Toggle debug mode for extra information in your console

    Implementation Examples

    These are some basic implementations that should do a good job of helping you understand how to implement our package into your own application..

    Native / jQuery

    This example will make use of ES6 syntax, you will want to convert it back to ES5 if you don't have transpiling processes in place.

    // Init the medical library
    // For all options, check the API Library page in the library.
    const antidote = Antidote.init({
      modal: true
    });
    
    $('#start-screening').click(startScreening);
    
    function startScreening() {
      // Make a request to your server in any way you prefer this 
      // is needed as you will only be able to init a screening
      // session with your *private* credentials.
      //
      // Keep this key private, do not use it in any browser requests or
      // store it in any javascript code that gets sent to the browser.
    
      $.ajax({
          type: 'POST',
          url: 'https://{{YOUR_SITE_URL}}/start-screening',
          dataType: 'json'
        })
        .done((res) => {
          // After the request to your server, you will be given a
          // session id by the medical screening api this needs
          // to be passed to the javascript library.
    
          console.log('Starting Screening Session: ', res.screening_session_id);
    
          antidote.start(res.screening_session_id, finishScreening);
        })
        .fail(() => {
          console.log('There was a failure in retrieving the screening session id')
        });
    }
    
    function finishScreening() {
      // Now we're in here, all you will need to do is make a call back to your server
      // that will deal with actually making the screening session is finished
      // and receiving a risk score back from the service.
    
      console.log('Triggered finish screening')
    
      $.ajax({
          type: 'POST',
          url: 'https://{{YOUR_SITE_URL}}/finish-screening',
          dataType: 'json'
        })
        .done((res) => {
          // Your Code. (E.G Shows list of conditions next to traveller...)
        })
        .fail(() => {
          console.log('There was a failure in finishing the screening session')
        });
    }
    

    React

    We use Typescript in our example here, however, if you remove the interfaces, types, and generics, the syntax is near 1-1 with ES6. For more information read the Typescript website.

    import * as React from 'react';
    import { MedicalScreening } from 'antidote-medical-screening';
    
    interface IExampleMedicalScreeningProps {
      /**
       * Make a request to get a session id and returns it
       * when resolving the promise.
       *
       * @param {string} sessionId - Previous session id to perform a rescreen
       * @returns {Promise<string>}
       */
      onStart(sessionId?: string): Promise<string>;
    
      /**
       * Makes a request to finish the given session id.
       *
       * @param {string} sessionId
       * @returns {Promise<void>}
       */
      onFinish(sessionId: string): Promise<void>;
    }
    
    interface IExampleMedicalScreeningState {
      isScreening: boolean;
      sessionId?: string;
    }
    
    class ExampleMedicalScreening extends React.Component<IExampleMedicalScreeningProps, IExampleMedicalScreeningState> {
      state = {
        isScreening: false,
        sessionId: null,
      };
    
      private handleStart = () => {
        // Get session id, store it in the state and start screening.
    
        this.props.onStart(this.state.sessionId)
          .then((sessionId) => {
            this.setState({
              isScreening: true,
              sessionId,
            });
          })
          .catch((error) => {
            console.error(error);
    
            throw error;
          });
      };
    
      private handleFinish = () => {
        // Request to finish session, and and stop screening.
    
        this.props.onFinish(this.state.sessionId)
          .then(() => {
            this.setState({
              isScreening: false,
            })
          })
          .catch((error) => {
            console.error(error);
    
            throw error;
          });
      };
    
      render() {
        return (
          <div>
            <button onClick={this.handleStart}>
              {this.state.isScreening ? 'Edit' : 'Start'} Screening
            </button>
    
            {this.state.isScreening && (
              <MedicalScreening
                url={'https://api.cegascreening.com'}
                sessionId={this.state.sessionId}
                onFinish={this.handleFinish}
              />
            )}
          </div>
        );
      }
    }
    

    Angular

    import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
    
    interface IMedicalScreeningSettings {
      container?: Element,
      url?: string,
      modal?: boolean,
      debug?: boolean
    }
    
    interface AntidoteMedicalScreening {
      init(settings: IMedicalScreeningSettings);
      destroy();
      start(sessionId: string, onFinish: Function);
    }
    
    declare const Antidote: AntidoteMedicalScreening;
    
    @Component({
      selector: 'app-root',
      template: `
        <div #medicalScreeningContainer></div>
    
        <button (click)="startScreening()">
          Start Screening
        </button>
      `,
      styleUrls: ['./app.component.css']
    })
    export class AppComponent implements AfterViewInit {
      antidote:AntidoteMedicalScreening = null;
      @ViewChild('medicalScreeningContainer') el:ElementRef;
    
      ngAfterViewInit() {
        this.antidote = Antidote.init({
          container: this.el.nativeElement,
          modal: false,
        });
      }
    
      startScreening() {
        // There should be some code here to deal with posting to your server
        // to get the 'screening-session-id'
    
        this.antidote.start(
          'screening-session-id', 
          this.handleScreeningFinish
        )
      }
    
      handleScreeningFinish() {
        // There should be some code here to deal with posting to your server
        // to finalise the screening session.
    
        console.log('It finished');
      }
    
    }
    

    UI Notes

    These notes are here to help you with building the UI for your application.

    Pages

    Search:

    Screen Condition:

    Condition List:

    Events

    On Start:

    On Screen Condition:

    On Screen Condition Finish: