Manual Reference Source Test
import Clinical6 from 'clinical6/src/Clinical6.js'
public class | source

Clinical6

Client to the Clinical6 instance

Example:

Clinical6 client = new Clinical6("https://mysite.captivereach.com");
await client.guestSignIn('thisismydeviceid', 'ios', 'thisismypushid');
console.log(client.authToken);

Test:

Constructor Summary

Public Constructor
public

constructor(apiBaseUrl: String)

Constructs the class with baseUrl provided

Member Summary

Public Members
public

Client: Class

public get

Gets the apiBaseUrl

public set

Sets the apiBaseUrl

public get

authToken(authToken: String): String

Gets the authToken from Client.instance.authToken

public set

authToken(authToken: String): String

Sets the authToken for Client.instance.authToken

public set

config(data: Object): Object

Sets the configuration information

public get

Gets the configuration information

public get

Gets the device from Client.instance.device

public set

device(device: Device): Device

Sets the device for Client.instance.device

public set

Gets the mobileApplicationKey from Client.instance.mobileApplicationKey

public get

Sets the mobileApplicationKey for Client.instance.mobileApplicationKey

public
public get

Gets the user from Client.instance.user

public set

user(user: MobileUser): User

Sets the user for Client.instance.user

Private Members
private
private

Method Summary

Public Methods
public

async delete(obj: Object, cacheMode: String): Promise

Deletes an object

public

fetch(url: String, method: String, data: Object): Promise

Prepare and Fetch HTTP request to API

public

async get(params: Object, options: Object): Promise

Updates an object

public

async getChildren(parent: Object, child: Object, options: Object): Promise

Updates an object

public

Retrieves the profile of the current, authenticated mobile user.

public

async insert(obj: Object, cacheMode: String): Promise

Inserts an object

public

log(logEntry: Object, requestInformation: Object, deviceInformation: Object): Promise

Tracks a new event in the log.

public

async register(account: String, password: String, device: Device): Promise<MobileUser>

Register a device for guest, a username, or email

public

Starts the reset password process and sends an email to the user with instructions.

public

resetPassword(token: String, password: String, device: Device): Promise

Sends user's account name via email. This method does not require an access token.

public

signIn(account: String, password: String): Promise

Sign in with device info

public

async signInGuest(): Promise

Sign in with device info

public

Detaches the device from the mobile_user.

public

async update(obj: Object, options: Object): Promise

Updates an object

public

xAuth(json: Object): Promise

Submits the provided JSON to the server.

Public Constructors

public constructor(apiBaseUrl: String) source

Constructs the class with baseUrl provided

Params:

NameTypeAttributeDescription
apiBaseUrl String
  • optional
  • default: 'http://localhost'

Base URL the (sub)domain of the Captive Reach server. Example: 'https://dhsadobe.captivereach.com'

Public Members

public Client: Class source

public get apiBaseUrl: String: String source

Gets the apiBaseUrl

Return:

String

Current apiBaseUrl

public set apiBaseUrl: String: String source

Sets the apiBaseUrl

Return:

String

Current apiBaseUrl

public get authToken(authToken: String): String source

Gets the authToken from Client.instance.authToken

public set authToken(authToken: String): String source

Sets the authToken for Client.instance.authToken

public set config(data: Object): Object source

Sets the configuration information

public get config: Object: Object source

Gets the configuration information

Return:

Object

data - the information in a key value object

public get device: Device source

Gets the device from Client.instance.device

public set device(device: Device): Device source

Sets the device for Client.instance.device

public set mobileApplicationKey: String source

Gets the mobileApplicationKey from Client.instance.mobileApplicationKey

public get mobileApplicationKey(device: String): String source

Sets the mobileApplicationKey for Client.instance.mobileApplicationKey

public storage: Storage source

public get user: User source

Gets the user from Client.instance.user

public set user(user: MobileUser): User source

Sets the user for Client.instance.user

Private Members

private _apiBaseUrl: String source

private _authToken: String source

Public Methods

public async delete(obj: Object, cacheMode: String): Promise source

Deletes an object

Params:

NameTypeAttributeDescription
obj Object
  • optional

Object used for this action

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Returns a promise via ajax call.

Example:

import { clinical6, Site, Client } from 'clinical6';

// Removes obj from server and local storage
const obj = new Site({...}); // Site for example
clinical6.delete(obj);

// No longer in storage
Client.instance.storageUtility.has('sites', { id: obj.id });

// Can also be done using a json description
clinical6.delete({ id: 5, type: '23', options: { cascading: true }});

Test:

public fetch(url: String, method: String, data: Object): Promise source

Prepare and Fetch HTTP request to API

Params:

NameTypeAttributeDescription
url String

Path to the endpoint starting with '/'

method String
  • optional

HTTP Method (DELETE|GET|POST|PUT)

data Object
  • optional

JSON payload, required on POST and PUT calls.

Return:

Promise

Resolves on HTTP 200. Rejects on all else.

Test:

public async get(params: Object, options: Object): Promise source

Updates an object

Params:

NameTypeAttributeDescription
params Object
  • optional

Parameters used to get information from server

params.id Number
  • optional

Id to get data from the server

params.type String
  • optional

Type to be used for storage

params.filters Object
  • optional

Filters to be used for get

options Object
  • optional

Options to modify or change behavior/results of the call

options.cacheMode String
  • optional

Override the caching method for this call

options.meta String
  • optional

Pass through and update by reference meta data

Return:

Promise

Returns a promise via ajax call.

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { clinical6, Setting, Site, Client } from 'clinical6';

// You can get sites using an existing instantiated object
const obj = new Site({...}); // Site for example
clinical6.get(obj).then(sites => console.log(sites)); // will get all sites

// If id exists, it will return only one site
obj.id = 5;
clinical6.get(obj).then(site => console.log(site)); // will get site where id = 5

// Using the string of the type
clinical6.get('mobile_users').then(users => console.log(users)); // will return all mobile users

// Using the class name directly
clinical6.get(Setting).then(settings => console.log(settings)); // will return all settings

// Adding filters and cache mode
clinical6.get({ type: 'some_object_type', filters: {}}, 'networkOnly').then(obj => console.log(obj));

Test:

public async getChildren(parent: Object, child: Object, options: Object): Promise source

Updates an object

Params:

NameTypeAttributeDescription
parent Object

Parameters used to get information from server

parent.id Number

Id to get data from the server

parent.type String

Type to be used for storage

child Object
  • optional

Parameters used to get information from server

child.id Number
  • optional

Id to get data from the server

child.type String
  • optional

Type to be used for storage

child.filters Object
  • optional

Filters to be used for get

options Object
  • optional

Options to modify or change behavior/results of the call

options.cacheMode String
  • optional

Override the caching method for this call

options.meta String
  • optional

Pass through and update by reference meta data

Return:

Promise

Returns a promise via ajax call.

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { clinical6, SiteMember } from 'clinical6';

clinical6.getChildren(site, { type: 'trials/site_members' });
clinical6.getChildren(site, new SiteMember());
clinical6.getChildren(user, { type: 'ediary/entries' });  // generates /v3/mobile_users/:id/ediary/entries

Test:

public getProfile(): Promise source

Retrieves the profile of the current, authenticated mobile user.

Return:

Promise

Promise object that returns success or failure

public async insert(obj: Object, cacheMode: String): Promise source

Inserts an object

Params:

NameTypeAttributeDescription
obj Object
  • optional

Object used for this action

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Returns a promise via ajax call.

Example:

import { clinical6, Site, Client } from 'clinical6';

// Removes obj from server and local storage
const obj = new Site({...}); // Site for example
clinical6.insert(obj);

// Now in storage
Client.instance.storageUtility.has('sites', { id: obj.id });

Test:

public log(logEntry: Object, requestInformation: Object, deviceInformation: Object): Promise source

Tracks a new event in the log.

Params:

NameTypeAttributeDescription
logEntry Object
  • optional

The new log entry to track. (optional)

logEntry.message String
  • optional

The message of the log entry. (optional)

logEntry.tag String
  • optional

The tag value of the log entry. (optional)

logEntry.level String

Indicates the level of importance of the log entry. (required)

requestInformation Object
  • optional

The request information of the API call. (optional)

requestInformation.method String
  • optional

The method of the request. (optional)

requestInformation.params String
  • optional

The body or parameters that were sent on the failing/debugging request. (optional)

requestInformationtry.status_code String
  • optional

The response of the request. (optional)

requestInformationtry.url String
  • optional

The URL of the request. (optional)

deviceInformation Object
  • optional

The device information of the device that made the request. (optional)

deviceInformation.app_version String
  • optional

The version of the app that was running on the device. (optional)

deviceInformation.brand String
  • optional

The brand of the device. (optional)

deviceInformation.carrier String
  • optional

The carrier of the device . (optional)

deviceInformation.gps_status String
  • optional

The gps status of the device. (optional)

deviceInformation.latitude Number
  • optional

The latitude value where the device was. (optional)

deviceInformation.longitude Number
  • optional

The longitude value where the device was. (optional)

deviceInformation.manufacturer String
  • optional

The manufacturer of the device. (optional)

deviceInformation.network_status String
  • optional

The network status of the device. (optional)

deviceInformation.os_version String
  • optional

The OS version of the device. (optional)

deviceInformation.push_id String
  • optional

The push ID value of the device. (optional)

deviceInformation.token String
  • optional

The token value of the device. (optional)

deviceInformation.udid String
  • optional

The UDID value of the device. (optional)

deviceInformation.technology String
  • optional

The technology of the device. (optional)

Return:

Promise

Promise object that returns success or failure

Example:

Log
import { systemService } from 'Clinical6';
systemService.log({
 "message": "MyText",
 "tag": "MyString",
 "level": "Error"
}, {
  "url": "MyString",
  "method": "MyString",
  "params": "MyText",
  "status_code": "MyString"
}, {
  "udid": "MyString",
  "token": "MyString",
  "push_id": "MyString",
  "app_version": "MyString",
  "os_version": "MyString",
  "network_status": "MyString",
  "gps_status": "MyString",
  "latitude": "1.5",
  "longitude": "1.5",
  "brand": "MyString",
  "manufacturer": "MyString",
  "carrier": "MyString"
});
Success Response
{
  "status": "ok",
  "message": "Debug Log was successfully created"
}

Test:

public async register(account: String, password: String, device: Device): Promise<MobileUser> source

Register a device for guest, a username, or email

Params:

NameTypeAttributeDescription
account String
  • optional

MobileUser object in which to insert

password String
  • optional

Password must exist if guest is false

device Device
  • optional

Device with id to register

Return:

Promise<MobileUser>

Registered Mobile User

Example:

import { clinical6 } from 'clinical6';
const mobileUser = new MobileUser({...});

// you can register a guest using the `register` method.
clinical6.register()
 .then(mobileUser => console.log(mobileUser));

// Register using an account name
clinical6.register('abc', 'asdf', device)
 .then(mobileUser => console.log(mobileUser));

// Register using an email address
clinical6.register('test@test.com', 'asdf', device)
 .then(mobileUser => console.log(mobileUser));

Test:

public requestPasswordReset(account: String): Promise source

Starts the reset password process and sends an email to the user with instructions.

Params:

NameTypeAttributeDescription
account String

Either the account name or email address

Return:

Promise

Promise object that returns success or failure

Throw:

Clinical6Error

If missing required parameters

Example:

import { clinical6 } from 'clinical6';
clinical6.requestPasswordReset('test@test.com'); // email
clinical6.requestPasswordReset('jsmith'); // account

Test:

public resetPassword(token: String, password: String, device: Device): Promise source

Sends user's account name via email. This method does not require an access token.

Params:

NameTypeAttributeDescription
token String

Token from email.

password String

New password for the account.

device Device
  • optional

Reset with this device (Default to saved device).

Return:

Promise

Promise object that returns success or failure

Test:

public signIn(account: String, password: String): Promise source

Sign in with device info

Params:

NameTypeAttributeDescription
account String

The username associated with the user account

password String

The password for the user

Return:

Promise

Promise object that returns success or failure

Test:

public async signInGuest(): Promise source

Sign in with device info

Return:

Promise

Promise object that returns success or failure

public signOut(): Promise source

Detaches the device from the mobile_user. If the current mobile_user is a guest, his information will be destroyed. After this method is executed the device won't have any access_token associated and won't be able to make other requests until it signs in.

This method does not require access token.

Return:

Promise

Promise object that returns success or failure

Test:

public async update(obj: Object, options: Object): Promise source

Updates an object

Params:

NameTypeAttributeDescription
obj Object
  • optional

Object used for this action

options Object
  • optional

Options to override the call

options.cacheMode String
  • optional

Override the caching method for this call

options.meta Object
  • optional

Apply meta data to be passed to this call

Return:

Promise

Returns a promise via ajax call.

Example:

import { clinical6, Site, Client } from 'clinical6';

// Updates a site
const obj = new Site({...}); // Site for example
obj.data = `Updated Data`;
clinical6.update(obj);

// Updates a site and applies meta data
const obj = new Site({...}); // Site for example
obj.data = `Updated Data`;
clinical6.update(obj, { cacheMode: 'networkOnly', meta: { something: 23 }});

Test:

public xAuth(json: Object): Promise source

Submits the provided JSON to the server.

Params:

NameTypeAttributeDescription
json Object

The JSON value with the attributes to validate.

Return:

Promise

Promise object that returns success or failure