Manual Reference Source Test

Usage

It is important that all services have an instanced variable that is camel case. This means that UserService has an existing instance userService. The classes are exposed so that the application can extend/create new services if necessary.

Most methods return promises. This makes it easy to implement asynchronous calls.

Top

Administrators can configure your app's carousel content on your Clinical6 dashboard under CMS > Image Carousel. These advertisements consist of a title, an image, an action to be taken when the image is tapped, and detailed action information.

Your advertisements can also be tagged to help organize your content.

Once your carousel images are ready, you can access them through the get method. We highly recommend including device-optimized images<sup>1</sup>. You can filter your images by device-specific versions and tags.

import { advertisementService } from 'clinical6';

let imageVersion = 'galaxy_s4';
let tags = ['government','capital','DC'];

advertisementService.get(imageVersion, tags).then(function(data){
  // display carousel
});

Advertisment settings can be retrieved with the getSettings method.

advertisementService.getSettings();

Top

Alert Messages

Clinical6 allows the ability to send mobile users alert messages notifying them of specific alerts. These messages can be retrieved via the get method. Alert messages can be marked as read via the markRead method. The markRead method requires an alert message id. Alert messages have a status attribute which can be updated with the updateStatus method. The updateStatus method requires an id parameter and a String status parameter.

import { alertMessageService } from 'clinical6';

alertMessageService.get();
alertMessageService.markRead(id);
alertMessageService.updateStatus(id, alertStatus); // ie, 'read'

Users can delete alert messages with the delete method. The method requires an alert message ID value as a parameter.

alertMessageService.delete(id);

You can also use the AlertMessage() object methods read and delete directly on the object:

alertMessageService.get().then(messages => {
  messages[0].read();
  messages[1].delete();
});

Users can delete alert messages with the delete method. The method requires an alert message ID value as a parameter.

alertMessageService.delete(id);

Top

Callbacks

All callbacks on the platform can be retrieved with the getCallbacks method. This method does not take in any parameters.

import { callbackService } from 'clinical6';

callbackService.getCallbacks();

Information for a specific callback can be retrieved with the getCallback method. This method requires the id value of the callback as a parameter.

callbackService.getCallback(id);

Callbacks can be executed with the executeCallback method. This method requires the id value of the callback to execute as a parameter.

callbackService.executeCallback(id);

Top

Conversations

Users can retrieve all conversations with the getConversations method.

import { messageService } from 'clinical6';

messageService.getConversations();

Top

Devices

Devices are required in order to log in or grant access to the server. There are two ways to go about generating a device object, one is to get it from the server and the other is to create it directly.

import { Device, deviceService } from 'clinical6';

// Typically use DeviceService.get()
deviceService.get().then(messages => console.log(messages));

const device = new Device({
  "data": {
    "id": "1",
    "type": "devices",
    "attributes": {
      "udid": "this-is-a-udid-string",
      "technology": "ios",
      "access_token": "cd68fa04e458d6d1a9d29faec6a329d3",
      "push_id": null,
      "created_at": "2017-05-19T17:21:26.311Z",
      "updated_at": "2017-05-19T17:21:26.311Z",
      "app_version": null
    }
  }
});

Inserting a new device will also establish the device as the current device, setting the authtoken accordingly. It requires a mobileApplicationKey which is provided by the server.

import { Device, deviceService } from 'clinical6';
const device = new Device({...});

deviceService.insert();
deviceService.insert(mobileApplicationKey);
deviceService.insert(mobileApplicationKey, 'networkOnly');

const device = new Device({...});

// you could also just call `save` on the device if it doesn't have an id, which will also
// invoke the `insert` method
device.save();

The update method update information on the server about the device.

import { Device, deviceService } from 'clinical6';
const device = new Device({...});

// you can update a device using the `update` method.
deviceService.update(device).then(device => console.log(device));

// you could also just call `save` on the device if it has an id, which will also
// invoke the `update` method
device.save();

The get method will get more information about the device.

import { deviceService } from 'clinical6';

// You will be able to access these devices using the `get` method.
deviceService.get().then(devices => console.log(devices));

// Additionally, you can retrieve the subcategories for a specific device with the `get`
// method, using the ID of the desired device as a parameter.
deviceService.get(23).then(device => console.log(device));

The delete method will remove the device from server and local storage.

import { Device, Client } from 'clinical6';

// Removes device from server and local storage
const device = new Device({
  "id": 1,
  "type": "devices",
  "attributes": {
    "udid": "this-is-a-udid-string",
    "technology": "ios",
    "access_token": "cd68fa04e458d6d1a9d29faec6a329d3",
    "push_id": null,
    "created_at": "2017-05-19T17:21:26.311Z",
    "updated_at": "2017-05-19T17:21:26.311Z",
    "app_version": null
  }
});
device.delete();

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

Top

Dynamic Content

Now for the important stuff: content. Our SDK allows users to access and filter through your Clinical6 content, be it text, images, videos, or other media.

For instance, when a user selects an option from a mobile menu, you can provide the user with content related to that option. The user's selection could direct them to a website (using the SDK's in-app browser), in which case you would want to return a URL. Another menu option might direct the user to a series of pictures with captions and links. In this case, your dynamic content request would return URLs, images<sup>1</sup>, and text.

Possible values for the content_type that can be found in dynamic content JSON responses include:

Content Type JavaScript Attribute Name
Dates Category shared_category
Events Category event_category
Country country
Date date
Date with Time date_time
Location location
Email email
Number number
Text string
Phone Number telephone
Text Area text
Rich Text (HTML) richtext
Time time
Time Zone time_zone
URL url
Files files
Action action
Boolean boolean

In order to get the dynamic content information by id use the getById method and pass in an id to get a Content object:

import { contentService } from 'clinical6';

contentService.getById(655256).then((content) => {
  // content is an instance of Content by default.
});

In order to get favorite dynamic content information use the getContentFavorites method and pass in the permanent link to get Content objects:

contentService.getContentFavorites('permanent_link').then((content_collection) => {
  // content_collection is collection of Content objects by default.
});

In order to get a random dynamic content information use the getRandom method and pass in the permanent_link to get a Content object:

contentService.getRandom('permanent_link').then((content) => {
  // content is an instance of Content by default.
});

In order to insert the dynamic content information use the insertDynamicContent method and pass in a resource string and content object with the inserted information:

contentService.insertDynamicContent(content).then((response) => {
  // Inserts content information based on content.id and resource parameter
});

In order to update the dynamic content information use the updateDynamicContent method and pass in a resource string and content object with the updated information:

contentService.updateDynamicContent(content).then((response) => {
  // Updates content information based on content.id and resource parameter
});

You can also use the Content() object to insert and update by using the "save" method:

import { Content } from 'clinical6';

let car = new Content();
car.set('content_type', 'car');
car.set('title', 'My Car');
car.set('make', 'Toyota')
car.set('model', 'Corolla')
car.set('year', 2006)

// inserts
car.save().then(() => {
  // car now has id

  return car.save(); // car had id so this last save is an update
});

You can retrieve the list of all the vuforia targets associated with a content by using the dynamicContentVuforia method. This method takes the ID value of a content. The vuforia target data is returned in vuforia target model.

contentService.dynamicContentVuforia(id);

An individual status value can be retrieved with the getStatus() method. This method requires type, object, and ownerType with the optional owner if ownerType is 'mobile_user' values as parameters.

contentService.getStatus(type, object, ownerType, owner = undefined);

An to transition from one status to another using an action, use the transition() method. Owner can be null if the owner type is mobile_user.

// transition a flow
contentService.getStatus('start', 'data_collection/flow_process', 'flow_resource_name', 'mobile_user');
// Note that this isn't necessary for flows as it's automatically called when "go" or "save" is called.

// transition a study from new to acknowledged through the "acknowledge" action
const site_id = 3;
const study_id = 15;
contentService.getStatus('acknowledge', 'site_start/study', study_id, 'site_start/site', site_id);

Dynamic Filtering

There are 8 different methods you can use to filter content, depending on the type of filter(s) you want to use.

getByLocation(query);
getByTagNames(query);
getByTagIds(query);
getByDate(query);
getByNumber(query);
getBySearch(query);
getByDate(query);
filter(query);

The first 7 of these methods use Query attributes to filter dynamic content based on their respective type (e.g. location, tag name).

import { Query, contentService } from 'clinical6';

let query = new Query('resource_name');

query.attribute = 'tag_names';
query.values = ['office'];

contentService.getByTagNames(query).then((data) => {
  // process data returned
});

Comment functionality is available to dynamic content by using the methods getComments and addComment.

import { Content } from 'clinical6';

let car = new Content({
  id: 23,
  content_type: 'car',
  title: 'My Car',
  make: 'Toyota',
  model: 'Corolla',
  year: 2006
});

car.addComment('This is an awesome car!');
car.getComments().then(comments => console.log(comments));

Top

Dynamic Content and Queries

Clinical6 can also get dynamic content using filters by utilizing the filterDynamicContent method and passing in the parmanent link and a Query object.

import { Query, contentService } from 'clinical6';

//creating new query
let query = new Query('resource');

//pass on query to findDynamicContent method
contentService.findDynamicContent(query).then((data) => {
  // process data returned
});

Top

Events

Clinical6 allow for the creation of reminder events. A reminder event represents every occurrence of a reminder. A reminder event has a status that keeps track of the user actions. STATUS: ACTIVE, COMPLETED_ON_TIME, COMPLETED_LATE, IGNORED, PAST

Reminder events can be created with the insertEvent method. This method requires an event object and a ruleId. The ruleId is the id of the rule value that the newly created event belongs to.

import { ruleService } from 'clinical6';

ruleService.insertEvent(event, ruleId);

Mark the event depending on the action given. The result can vary depending on the time this method is called. If an invalid action is given, it will be interpreted as IGNORED.

ruleService.markEvent(ruleId, eventId, eventAction);

Mark the event depending on the action given. The result can vary depending on the time this method is called. If an invalid action is given, it will be interpreted as IGNORED. This particular method does not pass any parameters in the URL. The method takes in an eventChange object with id and event_action attributes. Both attributes are optional and if nothing is passed in a success message will still be returned from the server. If an event ID is provided in the eventChange object, this method will mark that particular event.

ruleService.markEventByObj(ruleId, eventChange);

Event status values can be updated with the updateEvent method. This method requires an event object with an updated status value, ruleId, and an eventId.

ruleService.updateEvent(event, ruleId, eventId); 

The next event for a rule can be retrieved with the getNextEvent method. This method takes a required ruleId value (permanent_link).

ruleService.getNextEvent(ruleId);

Recently created events can be retrieved with the getRecentEvents method. This method takes an optional, String parameter that filters the events based on specified time. The optional time unit parameter must be either "week" or "month".

ruleService.getRecentEvents(timeUnit); 

Recently created events can also be retrieved with the getFilteredRecentEvents method. The difference between this method and getRecentEvents is that this one requires a ruleId. By default, getFilteredRecentEvents will take in a rule ID, filter the recent events, and then return the results. This method takes an optional, String parameter that filters the events based on specified time. The optional time unit parameter must be either "week" or "month".

ruleService.getFilteredRecentEvents(ruleId, timeUnit);

Upcoming events can be retrieved with the getUpcomingEvents method. This method takes a required ruleId value (permanent_link). This method also takes an optional, String parameter, timeUnit, that filters the events based on specified time. The optional time unit parameter must be either "week" or "month".

ruleService.getUpcomingEvents(ruleId, timeUnit);

It is possible to filter events by date using the getEventsByDate method. This method takes in a required ruleId (permanent_link) as well as a required date value in the ISO8601 format YYYY-MM-DD.

ruleService.getEventsByDate(ruleId, date);

Users can get all reminder events by using the getEvents method. This method takes a rule ID as an optional parameter to filter events by rule ID.

ruleService.getEvents(ruleId);

Users can get all reminder events by using the getEventsByRule method. The difference between getEventsByRule and getEvents is that the former method filters the returned events by default and requires a rule ID whereas the latter takes in an optional rule ID value. If no value is passed into getEvents, it will simply return all events.

ruleService.getEventsByRule(ruleId);

Top

Flow

The Clinical6 server can create flows or multi page forms that enable the colleciton of data. The SDK allows you to retrieve the information stored about each flow process so that it can be integrated into the app.

The best way to pull back a flow process is by using the id or resource provided by the server.

import { flowService } from 'clinical6';

flowService.getFlow(id).then(response => flow = response);

In order to save or collect on this flow, the collect method an be called.

flowService.collect(flow);

In order to save or collect specific fields on this flow, the collect method an be called. This will save only the fields specified.

const fields = [
  {
    id: 'id',
    value: 'some value'
  }
];
flowService.collectFields(flow, fields);

Helper methods exist on the Flow object to allow for a simpler save method.

flow.save();  // saves all fields in flow

Let's use helper methods to navigate to the next location.

// The first step in the flow.  This is a FlowStep() object.
const flowStep = flow.first;

// This is an array of steps that contains "button_name" to be used.  Let's say that
// it's "Next" for this example.
flowStep.paths.steps;

// This returns the next FlowStep when applying the action "Next"
const nextStep = flowStep.go('Next');

Let's use helper methods to save data from provided inputs.

// We will first grab the first step of the flow.
const firstStep = flow.first;

// This is a collection of FlowInput() objects.  We need a key and value to modify and save.
firstStep.inputs;

// The FlowInput() object contains a getKey() method.
const ageKey = firstStep.inputs[0].getKey();

// Let's make the value 23 as an example
const ageValue = '23';

// This adds the values to the FlowStep's fields to save
firstStep.set('ageId', ageValue);

// This returns all currently saved fields.  This should have age set to "23"
firstStep.getFields();


//  At this point there are three ways to save.
// This directly saves the step to the server
firstStep.save();

// If the path containing the step "Continue" has the attribute "capture" set to true,
// it will automatically save.
firstStep.go('Continue');

// This saves all fields currently added to the server.
flow.save();

We can also use helper methods to set options to be used for a save.

flow.setOptions({owner: 'permanent_link'});

We can also use methods to addComment and getComments for both flow and flowsteps.

var flow = new Flow({ owner: 'site_start/site', owner_type: 32});
flow.addComment('hello world');
flow.getComments().then(comments => console.log(comments));
flow.getComments('site_start/labs', 43).then(comments => console.log(comments));
flow.getComments({ objectId: 43, objectType: 'lab_director'}.then((comments) => {
  console.log(comments);
});

flowstep.addComment('hello world');
flowstep.getComments().then(comments => console.log(comments));

Top

Insights

Our SDK also allows developers to track insights into user activity while using the app. A tracker JS object consists of the user action you want to track, the section of the app in which it occurred, the value or detail of the action, the label that the user sees, and other details about the action.

You can track these insights by placing triggers throughout your app that call the postInsights API method.

import { analyticsService } from 'clinical6';

var currentDatetime = '2016-03-01T00:30:42Z';
var coords = {
  lat: '38.9047',
  lng: '-77.0164'
};

analyticsService.postInsights('navigateBack', 'contact', 'navigation', currentDatetime, null, coords.lat, coords.lng);

Top

Location

Clinical6 has a couple of built-in methods that make it easy to get a user's current location, and update the location to the server.

import { locationService } from 'clinical6';

// gets a Promise the current location with the specific latitude or longitude
var location;
var locationPromise = locationService.getCurrent().then((location) => location = data );

// gets a Promise that posts a location to the server
var updateLocationPromise =  locationService.updateLocation(location);

// gets a Promise that posts the current location to the server, no need to pass in a location param
var updateCurrentLocationPromise = locationService.updateCurrentLocation();

Top

Languages

Clinical6 is available in multiple different languages.

Users can get the translations for a given language using the getTranslations method. This method requires the ISO value of a language.

import { languageService } from 'clinical6';

// Returns the translations for a given language.
languageService.getTranslations(id);

Users can get the list of available languages for an application using the getLanguages method.

// Returns the list of available languages for an application.
languageService.getLanguages().then((languages: Language[]) => {
  languages[0].getTranslations() // will get translations for the language;
    .then(()=>{
      console.log(languages[0].translate('welcome_text'));
    });
});

Users can get the list of available languages get translations for each language by adding true to getLanguages.

// Returns the list of available languages for an application and each translation.
languageService.getLanguages(true);

Top

Log

Users can track new log events with the trackLogEvent method. This method takes in a logEntry, requestInformation, and deviceInformation objects as parameters. All parameters are options. However, if a logEntry object is passed in, it must contain a String 'level' attribute.

import { systemService } from 'clinical6';

systemService.log(logEntry, requestInformation, deviceInformation);

Top

Make Request

Clinical6 has a utlity method called fetch that is used in all other methods that makes calles to the server.

import { clinical6 } from 'clinical6';

// gets a Promise with response from the server
var request = clinical6.fetch('/path/to/my/endpoint'); // Automatically is GET
var request = clinical6.fetch('/path/to/my/endpoint', 'POST', {data : 'data to pass on'});

Note: fetch method throws an error if no data is passed on for a PUT or POST request.

Top

Messages

Clinical6 apps can send in-app messages to users using the administrator dashboard or between mobile users. These messages can be retrieved via the getMessages method which retrieves all messages in a conversation given a conversation ID.

import { messageService } from 'clinical6';

messageService.getMessages(1).then(messages => console.log(messages));

Messages can be created with the sendMessage method. The sendMessage method requires a message parameter. The required attributes of the message object are: subject (String), body (String), and recipients (Array).

const message = {
  subject: 'blanditiis',
  body: '0i03jrgt8tinkt4tok5k3oc1w3y40auvi4g5fucxczu0plk6sz4olys2b4o9',
  recipients: ['67', '71']
};
messageService.sendMessage(message);

Mobile Menus

Mobile menus provide the core navigational functionality to Clinical6 apps. Administrators can edit these menus and subcategories using the site's dashboard. Menus primarily consist of a title, a description, an action to be taken, a "featured" indicator, and images<sup>1</sup>.

You will be able to access these menus and subcategories using the get method.

import { mobileMenuService } from 'clinical6';

mobileMenuService.get().then(menus => console.log(menus));

If you want to return only the top menus you can pass top value as the second a parameter.

mobileMenuService.get(null, 'top').then(menus => console.log(menus));

Additionally, you can retrieve the subcategories for a specific mobile menu with the get method, using the ID of the desired mobile menu as a parameter.

mobileMenuService.get(23).then(menus => console.log(menus));

Top

Profiles

Mobile users of the Clinical6 platform can have profiles. Clinical6 allows the ability to retrieve profile information for a user. The current authenticated mobile user profile can be accessed by calling the getProfile method. The method does not take any parameters and will return the profile information encapsulated in a 'profile' object.

In order to get the current mobile user's profile information use the getProfile method:

import { userService } from 'clinical6';

userService.getProfile().then((data) => {
  // display profile information
});

In order to update the current mobile user's profile information use the updateProfile method and pass in a profile object with the updated information:

userService.updateProfile(profile).then((data) => {
  // Updates profile information based on profile parameter
});

You can also update from the Clinical6.Profile object directly using the save method.

userService.getProfile().then(profile => {
  profile.zip_code = '12345';
  profile.save().then((response) => {
    console.log(response);
  });
});

In order to add and get comments on a profile use the addComments and getComments methods.

userService.getProfile().then(profile => {
  profile.addComment('Profile Comment');
  profile.getComments().then((comments) => {
    console.log(comments);
  });
});

There are also various helper functions getFullName and getFullAddress available for a profile instance.

userService.getProfile().then(profile => {
  console.log('Full Name', profile.getFullName());
  console.log('Full Address', profile.getFullAddress());
});

Top

Profile Attributes

Gets all the custom attributes for the profile along with its values. Profile attributes can be retrieved by calling the getProfileAttributes method. The getProfileAttributes method takes two optional parameters: include_hidden and include_values. The include_hidden determines whether the response should include the hidden attributes (Encrypted Data) in the results. The include_values determines whether the response should include the existing values of each attribute. The parameter values must either be set to 'false' or 'true'. By default, if no parameters are passed, include_hidden and include_values will both be set to false.

A profile attribute value can be updated with the updateProfileAttribute method. This method requires a profile object and a profile ID value as parameters. The profile object must contain a key name that's the same as the profile attribute to update. The key's value should be the value of the updated attribute. For example:

const profile = { value: 321, };

The id value is the profile id value.

import { userService } from 'clinical6';

userService.updateProfileAttribute(profile, id);

A new profile attribute can be added with the insertProfileAttribute method. This method requires a profile api_key and a value for the newly created attribute.

userService.insertProfileAttribute(apiKey, val);

A user profile attribute value can be deleted with the deleteProfileAttribute method. This method requires the ID value of the profile attribute value to delete.

userService.deleteProfileAttribute(id);

All profile attribute values for a given apiKey can be retrieved with the getAllProfileAttributes method. This method requires an API key value.

userService.getAllProfileAttributes(apiKey);

Top

Proximity Alerts

You can get all proximity alerts using getProximityAlerts. It's possible to filter proximity alerts with the optional beacon_id parameter.

import { alertMessageService } from 'clinical6';

alertMessageService.getProximityAlerts(event, ruleId);

Top

Project Content

ProjectContent is a helper class whose sole purpose is to wrap custom content from the Clinical6 server. Using these methods require knowledge about the content available on the server and is usually not configurable by the User Interface on the platform.

Declaring and defining a ProjectContent object.

import { ProjectContent } from 'clinical6';

// new ProjectContent(<type>, <options>?, <data>?);
// options requires either id (or owner), type (or ownerType), and has an optional version attribute (default is 'v2')
let lab = new ProjectContent('site_start/labs');  // only type
lab = new ProjectContent('site_start/labs', { id: 2 }); // type with id
lab = new ProjectContent('site_start/labs', { owner: 2 }); // type with owner (same as id)
lab = new ProjectContent('', { owner: 2, type: 'site_start/labs' }); // type with owner (same as id)
lab.name = 'East Clinic Laboratory';
lab.save(); // owner and/or id exists, update existing lab name

lab = new ProjectContent('site_start/labs');
lab.name = 'West Clinic Laborotory';
lab.save()  // owner and id don't exist, create new lab
.then(() => {
  lab.id; // Let's say the after the save is now 3
  lab.options.owner; // this will have the new id ready for the save (3)
});

lab = new ProjectContent('site_start/labs');
lab.getAll().then((labs) => (console.log(labs)); // list all labs, will each be type ProjectContent();

lab = new ProjectContent('site_start/labs', { id: 2 });
lab.getData().then(() => {
  lab.name; // Should be East Clinic Laboratory
});
lab.getSibling(3).then((lab3) => (console.log(lab3.name))); // West Clinic Laborotory

lab.addChild('lab_directors', {
  first_name: 'John',
  last_name: 'Smith'
});

lab.getChildren('lab_directors').then((myLabDirectors) => (console.log(myLabDirectors)));

lab.getChild('lab_directors', 1).then((labDirector1) => {
  labDirector1.first_name = 'Will';
  lab.updateChild('lab_directors', 1, labDirector1);
});


// Set up a lab after it's been instantiated
lab = new ProjectContent();
lab.options = {
  ownerType: 'site_start/labs',
  owner: 4,
  version: 'v2' // this is setup by default
};
lab._data = {
  id: 4,
  name: 'Colorado Springs South Laborotory II'
}
lab.save();


Top

Queries

To get dynamic contents using findDynamicContent method you need to construct and pass in that query. You construct a query via the Query property in your constructed Clinical6 class.

import { Query } from 'clinical6';
var query  = new Query();

A query also accepts the following parameters during construction:

A query class also has several methods that are useful

A query must have the following two attributes set in order to properly perform a search:

The query class has specific methods to help provide advanced searches.

Below is a simple example of how to use the Query model to search Dynamic Contents.

import { Query } from 'clinical6';
//By default, the search mode will be 'search', it can be changed by calling startsWithMode(), endsWithMode(), etc
var query  = new Query();

//Add some values to search for
query.addSearchValue('value1');
query.addSearchValue('value2');
query.addSearchValue('value3');

//Add dynamic content to search 
query.setResource(dynamicContent);

//Perform the search
query.searchContent();
import { Query } from 'clinical6';
var query  = new Query();

//if this query returned these results, when used with findDynamicContent
[{name: 'a', number: 100}, {name: 'c', number: 50}, {name: 'b', number: 10}]

//results for query.ascending('name');
[{name: 'a', number: 100}, {name: 'b', number: 10}, {name: 'c', number: 50}]

//results for query.descending('name')
[{name: 'c', number: 50}, {name: 'b', number: 10}, {name: 'a', number: 100}]

//results for query.limit(1);
[{name: 'a', number: 100}]

// results for query.showMinimal(), if filter attributes were set to just 'name'
[{name: 'a'}, {name: 'c'}, {name: 'b'}]

These methods can also be chained, though this would override conflicting methods like ascending and descending;

import { Query } from 'clinical6';
var query = new Query(filters);

query.ascending('name').limit(2).showMinimal();

// results
[{name: 'a'}, {name: 'b'}]
import { Query } from 'clinical6';
var orderByArr  = [{column: 'attribute1', direction: 'desc'}];
var perPage = 20;

// this query specifies the search values to be applied to get the results. 
// the results will be ordered given logic of the orderByArr, 
// the results will be the contents of page 2
// the number of results per page will be 20
// the results will only display the attributes specified in the filters
// the results will show all results regardless of whether the user favorited them or not
var query = new Query(orderByArr, 2, 20, true, false);

Top

Rules

Clinical6 allows for the creation of reminder events. Reminder events are grouped into reminder rules. A specific reminder rule can be retrieved with the getRule method. The getRule method requires an ID value (the permanent link).

import { ruleService } from 'clinical6';

var rules = ruleService.getRule(id);

All reminder rules can be retrieved with the 'getRules' method.

var rules = ruleService.getRules();

Top

Sections

Clinical6 allows the use of Sections if configured in the instance through a configuration file. Sections start with a parent section and can have children that are either Flow objects, Custom, or other Sections.

Sections can be retrieved with the getSections() method. This method requires resource and ownerType as parameters with owner optional if ownerType is 'mobile_user'. All of the required parameters are String values.

import { sectionService } from 'clinical6';

let mySection;
sectionService.getSections(resource, ownerType, owner).then((data) => mySection = data);

After getSections is called, access the child information for a section, use the following:

mySection.sections;

let section1 = mySection.sections[0];
section1.label;  // the label
section1.type; // the type of object  (flow, section, or custom)
section1.status;  // the status of the section (ie 'initial', 'in_progress', 'completed')
section1.object; // the permanent link of the object it points to

// To get access the data of a section, it is found under the "data" portion if 'getData()' is called, which it is by default.
section1.getData();  // called by default when client.getSections(...) is called
section1.data;  // the new Section() or Flow() object instance

A separate way to get Section information and load children is the following

let mySection = new Section({ resource, ownerType, owner, type });
mySection.getData(); // If you wish to access mySection.data.  'type' is required if you wish to use this.
mySection.getChildren();  // Only use this if children don't already exist or if you wish to refresh the list.  This is recursive and will parse the whole tree.

let section1 = mySection.sections[0];  // same way to access children as before

Top

Surveys

Clinical6 apps can also display surveys for users to take. Administrators can create surveys, add questions, change answer choices, view results, and modify surveys using the Clinical6 dashboard. To retrieve your app's surveys, use the getSurveys method, and - optionally - include tag names and/or tag IDs to filter your surveys.

If you specify tags, you will need to pass an empty array as the first parameter; otherwise the API will filter your results using tag IDs as tag names. If you don't want to filter your results at all, don't pass any parameters.

import { surveyService } from 'clinical6';

var tagNames = [];
var tags = [26,28,32];

// Retrieve surveys with ID of 26, 28, and 32
surveyService.getSurveys(tagNames, tags).then(function(data) {
  // process surveys
});

// Retrieve all surveys
surveyService.getSurveys().then(function(data) {
  // process surveys
});

You can retrieve questions one of two ways:

  1. GET questions associated with a particular survey, or
  2. GET all questions
// Retrieve all questions
surveyService.getQuestions().then(function(data) {
  // process questions
});

// Retrieve questions for a specific survey
var surveyId = 1;
surveyService.getQuestions(surveyId).then(function(data) {
  // process questions
});

When users complete a survey, you can submit their answers to your Clinical6 back end using the following:

var surveyId = 1;
var answers = {
  answers: [
    {
      value: "sample answer",
      choice_id: 3,
      question_id: 1
    }
  ]
};
surveyService.submitAnswers(surveyId, answers);

You can also add comments or get comments from users about a question in the survey by using the addComment and getComment methods.

import { Question } from 'clinical6';

let question = new Question({ id: 23 });
question.addComment('I loved this question');
question.getComments().then(comments => console.log(comments));

Top

Users

In order to manage user-specific data, access, and info, our SDK provides a user sign-in as well as a guest sign-in. With the plugin, as soon as a user launches your app, they will automatically be signed in as a guest. After you build a login page/UI, your users can enter their credentials to sign in to their own account.

In order to sign up for a new user account, profile information and credentials can be used to execute the signUp method:

import { userService } from 'clinical6';

userService.signUp(username, pw, profile).then(function(data){
  // User is created and an authtotken is passed back
}, function(err){
  // error
});

After defining the user's UDID, platform, and push ID, you can use the credentials the user entered to log them in using the signIn method:

userService.signIn(username, password).then(function(data) {
  // User signed in!
}, function(err) {
  // error
});

If, for whatever reason, you want to sign in a user as a guest, you can do so with the signIn method:

userService.signIn().then(function(data) {
  // Guest signed in!
}, function(err) {
  // error
});

The signOut method does not require any authentication token, and is used to sign out any user or guest:

userService.signOut().then(function(data) {
  // Signed out
}, function(err) {
  // error
});

The emailPassword method allows users to reset their passwords. An auth token is not needed for this method.

userService.emailPassword(emailAddress).then(function(data) {
  // emailPassword error
}, function(err) {
  // error
});

The emailAccountName method sends users their forgotten account user names. An auth token is not needed for this method.

userService.emailAccountName(emailAddress).then(function(data) {
  // emailPassword error
}, function(err) {
  // error
});

The resetPassword resets a user's password. Before calling this method, a user must call the 'emailPassword' method to receive a temporary password. Once the user gets a temporary password from the emailPassword method, that should be used as the oldPassword parameter in resetPassword.

userService.resetPassword(newPassword, newPasswordConf, oldPassword);

The deleteCurrentUser method deletes the current mobile user from the system. This action cannot be undone.

userService.deleteCurrentUser();

The disableCurrentUser method disables the current mobile user in the system. The user's access to the system will be revoked. However, this method does not delete any data related to the user.

userService.disableCurrentUser();

The setPin method sets the pin for a user and associates the device with the mobile user.

userService.setPin(json);

The acceptInvitation method sets the pin for an invited mobile user and associates the device with the mobile user.

userService.acceptInvitation(json);

Existing Clinical6 users can invite related mobile users.

An existing user can invite other mobile users with the inviteUser method. This method takes in four required parameters: firstName, emailAddress, phoneNumber, and userRole. All parameters must be String values.

userService.inviteUser(firstName, emailAddress, phoneNumber, userRole);

An individual mobile user can be retrieved with the getUserProfile method. It will return a new Profile object.

userService.getUserProfile(userId);

All related mobile users can be retrieved with the getRelatedMobileUsers method.

userService.getRelatedMobileUsers();

After getting the list of mobile users, they belong to the MobileUser class allowing various methods to be performed.

userService.getRelatedMobileUsers().then(mobileUsers => {

  // add comments
  mobileUsers[0].addComment('MobileUser Comment');

  // get comments
  mobileUsers[0].getComments().then(comments => console.log(comments));

  // delete user
  mobileUsers[0].delete();

  // disable user
  mobileUsers[0].disable();

  // enable user
  mobileUsers[0].enable();

  // get Full Name like "Mark Smith"
  console.log('Full Name', mobileUsers[0].getFullName());

  // get the Profile object pertaining to the related user (if allowed)
  mobileUsers[0].getProfile().then(profile => console.log(profile));

  // resend invite - allows options to allow for any options required for the reinvite
  mobileUsers[0].resendInvite({});
});

Mobile users can update followers, or related mobile users, to disabled status by using the disableUser method. This method takes in the id value of the related mobile user to disable.

userService.disableUser(id);

Mobile users can update followers, or related mobile users, to enabled status by using the enableUser method. This method takes in the id value of the related mobile user to enable.

userService.enableUser(id);

Mobile users can remove followers, or related mobile users, with the deleteUser method. This method takes in the id value of the related mobile user to remove.

userService.deleteUser(id);

Mobile users can resend invitations to related mobile users using the resendInvite method. This method requires the id value of the related mobile user. The options parameter is optional.

userService.resendInvite(id, options);

Top

XAuth

Generic implementation of xAuth. Takes in a JSON and passes it into the server.

import { systemService } from 'clinical6';

systemService.xAuth(json)(json);

Top