Configuration
Module Loading
This SDK can be used in the browser via a global variable.
<script src="dist/clinical6.js"></script>
<script>
const clinical6 = new C6.Clinical6();
clinical6.config.mobileApplicationKey = '123123123211';
clinical6.device.technology = 'web';
clinical6.device.udid = '192.0.0.1';
clinical6.device.appVersion = '0.1';
clinical6.config = {
apiBaseUrl: 'https://dhsadobe.captivereach.com',
track: { flows: false, gps: false }
};
clinical6.signIn(); // will automatically use {guest: true} and device
</script>
This is also to be used with ES6 or TypeScript supported technologies (ionic 2)
import { Component, ViewChild } from '@angular/core';
import { Platform, MenuController, Nav } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { HelloIonicPage } from '../pages/hello-ionic/hello-ionic';
import { ListPage } from '../pages/list/list';
import { AppVersion, Device } from 'ionic-native';
import { clinical6, Flow } from 'clinical6';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
// make HelloIonicPage the root (or first) page
rootPage: any = HelloIonicPage;
pages: Array<{title: string, component: any}>;
constructor(
public platform: Platform,
public menu: MenuController
) {
this.initializeApp();
// set our app's pages
this.pages = [
{ title: 'Hello Ionic', component: HelloIonicPage },
{ title: 'My First List', component: ListPage }
];
}
initializeApp() {
this.platform.ready().then(() => {
const f: Flow = new Flow();
clinical6.config.mobileApplicationKey = '123123123211';
clinical6.apiBaseUrl = 'https://ppdpassport.clinicalreach.com/';
clinical6.device.udid = Device.uuid;
clinical6.device.technology = Device.platform;
AppVersion.getVersionNumber()
.then(s => (clinical6.device.appVersion = s))
.then(() => clinical6.signIn())
.catch(reason => console.log(reason));
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();
});
}
openPage(page) {
// close the menu when clicking a link from the menu
this.menu.close();
// navigate to the new page if it is not the current page
this.nav.setRoot(page.component);
}
}
Initialization
After loading Clinical6 in an HTML file, a new class of Clinical6 instance can be instantiated in JavaScript. You will need to pass in a Clinical6 instance url. If no url is passed, the default url to set will be localhost
.
All services as well as a base Clinical6 class have instantiated objects that are camel case. In this example we use the clinical6
object.
import { clinical6 } from 'clinical6';
clinical6.apiBaseUrl = 'https://mysite.captivereach.com';
The clinical6
object has a config
getter and setter to allow for various settings.
import { clinical6 } from 'clinical6';
clinical6.config = {
apiBaseUrl: 'https://mysite.captivereach.com', // default undefined
authToken: '2384af0j238fdjwe0', // default undefined
track: {
flows: true, // default true, this will automatically call postInsights on a flow 'go' and 'collect'
gps: false // default false, this will automatically use gps when postInsights is called
}
};
In addition, there are direct setters and getters for some of these options for config
.
import { clinical6 } from 'clinical6';
clinical6.apiBaseUrl = 'https://mysite.captivereach.com';
clinical6.authToken = '2384af0j238fdjwe0';
Initialization for Mobile Applications
The clinical6
object for mobile requires a device
and config.mobileApplicationKey
getter and setter to be set. This by default is a Device
object.
import { clinical6 } from 'clinical6';
clinical6.config.mobileApplicationKey = 'adfj8afwe08jf0238fj302fj1'; // default null
clinical6.device.pushId = '28104321'; // default 'FAKE_ID'
clinical6.device.technology = 'ios'; // default null, must be 'android', 'ios', or 'web'
clinical6.device.udid = '2840-1afj03-afjsdf-238fj'; // default null
clinical6.device.appVersion = '0.0.1'; // default null
The device must be registered to the device and a user will establish a session based on this device. This process is handled for you by using clinical6.signIn(account?, password?)
, assuming that clinical6.device
and clinical6.config.mobileApplicationKey
information above has been defined properly.
Initialization for Web Applications
The clinical6
object requires much less to setup and sign in.
import { clinical6 } from 'clinical6';
// only if you need to access the platform as a platform user
clinical6.user.type = 'users';
clinical6.signIn(account, password);
If you want to use platform users set the clinical6.user.type = 'users';
There is an example of this setup under /examples
in the SDK.
CORS
When using the SDK in a Cordova app, CORS is not an issue because the app essentially runs on a file:///
URI. The app controls access through domain whitelisting.
However, when developing against this SDK not in an app, CORS errors often prevents the SDK from working. To bypass CORS errors, do one of the following:
- Update the Clinical6 endpoint to allow your endpoint access (Best solution, may not always be possible)
- Access the Clinical6 endpoint through a proxy that injects CORS headers (2nd best solution, always possible)
- Disable CORS in Chrome (Quickest solution, but NOT recommended as long term development plan. Opens up browser to many vulnerabilities)
NPM Scripts
This repository contains several helpful npm requests that ensures good code quality, runs tests, compiles ECMA6 code to ECMA5, and generates JSDOC documentation from the source code.
The following scripts are available to use for this respository just by navigating to the local installment of this repository and typing in the following in the command-line.
Script | Description |
---|---|
npm run build |
Runs task sequence clean , compile , webpack , lint , and then test |
npm run compile |
Converts the ECMA6 js files in src and test folders code and puts them in src.babel and test.babel directories |
npm run clean |
Deletes generates js files in test.babel and src.babel folders. |
npm run doc |
Compiles all the comments in the source code and creates html files that define all Classes, methods, parameters, and description in a user-friendly format. |
npm install |
Runs task sequence clean , compile , webpack , lint , and then test |
npm run lint |
Checks the source code for code style consistency using ESLINT configurations. |
npm test |
Runs all the unit tests in the test.babel folder |
npm run webpack |
Combines the src.babel js files into clinical6.js that can run on the browser or node environments each class available. |