Manual Reference Source Test
public class | source

User

Mixin Extends:

UserModel, Helper

Helper class representing a user User.

Constructor Summary

Public Constructor
public

Constructor for helper class representing a User

Member Summary

Public Members
public get
public set
public get
public set
public get
public set
public set
public get
public get
public get
public set
public get
public set
public set
public get
public get
public set
Private Members
private
private

_type: *

Method Summary

Public Methods
public

async addBadge(badge: Badge, cacheMode: String): Promise<AwardedBadge[]|AwardedBadge>

Add Badge

public

async addEntry(entry: Entry, template: EntryTemplate): Promise<Entry[]|Entry>

Add eDiary Entry

public

async addSchedule(schedule: Object): Promise<Schedule>

Add Schedule

public

async delete(): Promise

Removes a related user.

public

async disable(): Promise

Disables a related user.

public

async enable(): Promise

Enable a related user.

public

Gets the consent available strategies associated to this user.

public

async getAwardedBadges(awardedBadge: Object, cacheMode: String): Promise<AwardedBadge[]|AwardedBadge>

Get Awarded Badges

public

async getCohortAssignments(params: Object, options: String): Promise

Gets the cohort assignment associated to this user.

public

async getCohorts(): Promise<Cohort[]>

Gets the list of cohorts after calling this.getCohortAssignments()

public

async getConsentGrants(options: String): Promise

Gets the consent grants associated to this user.

public

async getDataGroup(dataGroup: Object, cacheMode: String): Promise<FlowDataGroup>

Get Flow Data Group for a user based on an id.

public

async getEntries(filter: Object, cacheMode: String): Promise<Entry[]|Entry>

Get eDiary entries

public

Get user notifications

public

Retrieve a related user profile.

public

Returns the registration status of the user.

public

async getSchedules(cacheMode: String): Promise<Schedule[]>

Get Schedules

public

async invite(attributes: Object, relationships: Object): Promise<User>

Sends an invitation to this user

public

Indicates if the password is set

public

async removeAwardedBadge(awardedBadge: Badge, cacheMode: String): Promise<Any>

Add Badge

public

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

public

async resendInvite(options: any): Promise

Resends an invite to a related user.

public

async resetPassword(token: String, password: String, device: Device): Promise<User>

Resets the password given a token and password (and email if user has one).

public

async revokeConsent(cacheMode: String): Promise

Revokes consent for the user

public

async save(): Promise<User>

Saves a user (insert if id doesn't exist, update if it does)

public

Saves a user's profile (insert if id doesn't exist, update if it does)

public

Sends a confirmation email to an email address

public

toInvitation(attributes: Object, relationships: Object): Invitation

Converts the user into an invitation used for sending or accepting an invitation.

public

async unlockUser(unlockToken: String): Promise

Unlocks the user

Inherited Summary

From class UserModel
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public

Public Constructors

public constructor(json: Object) source

Constructor for helper class representing a User

Override:

UserModel#constructor

Params:

NameTypeAttributeDescription
json Object

json api response from server

Public Members

public get cohortAssignments: CohortAssignment[] source

public set cohortAssignments: CohortAssignment[] source

public get cohorts: Cohort[] source

public set cohorts: Cohort[] source

public get devices: Device[] source

public set devices: Device[] source

public set profile: Profile source

public get profile: Profile source

public get relationships: any source

public get role: Role source

public set role: Role source

public get siteMember: SiteMember source

public set siteMember: SiteMember source

public set status: Status source

public get status: Status source

public get type: String source

public set type: String source

Private Members

private _cohortAssignments: *[] source

private _type: * source

Public Methods

public async addBadge(badge: Badge, cacheMode: String): Promise<AwardedBadge[]|AwardedBadge> source

Add Badge

Params:

NameTypeAttributeDescription
badge Badge
  • nullable: false

Badge to add result (by id)

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<AwardedBadge[]|AwardedBadge>

Promise object that returns one object or hashmap

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { Badge, User } from 'clinical6';
const user = new User({ id: 15 });
const badge = new Badge({ id: 5 });

// You will be able to add a badge using the `addBadge` method.
// It returns the "AwardedBadge" relationship
user.addBadge(badge).then(ab => console.log(ab));

public async addEntry(entry: Entry, template: EntryTemplate): Promise<Entry[]|Entry> source

Add eDiary Entry

Params:

NameTypeAttributeDescription
entry Entry
  • nullable: false

Hashmap to save for entry

template EntryTemplate
  • nullable: false

The entry template, must have id

Return:

Promise<Entry[]|Entry>

Promise object that returns one object or hashmap

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { userService, User, Entry } from 'clinical6';
const user = new User({ id: 5, ... });
const entry = new Entry({ date: '2018-06-02' });

// You can add an entry using the `addEntry` method
user.addEntry(entry).then(entry => console.log(entry));

public async addSchedule(schedule: Object): Promise<Schedule> source

Add Schedule

Params:

NameTypeAttributeDescription
schedule Object
  • nullable: false

The user, must have id

schedule.attributes Object
  • nullable: false

Hashmap to add for schedule

schedule.mobileUser User
  • optional
  • nullable: false

The user, must have id

schedule.mobileUser.id Number
  • optional
  • nullable: false

The user id

Return:

Promise<Schedule>

Promise object that returns one object or hashmap

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { Schedule, User } from 'clinical6';
const schedule = new Schedule({ updatedAt: '2018-06-02' });

// You can add a schedule using the `addSchedule` method
user.addSchedule(schedule).then(result => console.log(result));

public async delete(): Promise source

Removes a related user.

Return:

Promise

Promise object that returns success or failure

Example:

client.getRelatedUsers().then(users => {
  users[0].delete();
});

public async disable(): Promise source

Disables a related user.

Return:

Promise

Promise object that returns success or failure

Example:

client.getRelatedUsers().then(users => {
  users[0].disable();
});

public async enable(): Promise source

Enable a related user.

Return:

Promise

Promise object that returns success or failure

Example:

client.getRelatedUsers().then(users => {
  users[0].enable();
});

public async getAvailableStrategies(options: String): Promise source

Gets the consent available strategies associated to this user.

Params:

NameTypeAttributeDescription
options String
  • optional

Modify the nature of the call and response

options.url String
  • optional

Override the url for this call

options.cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Promise with data (array or object)

Example:

import { User, clinical6 } from 'clinical6';
const user = new User({ id: 23 });
user.getAvailableStrategies();

// Combined with clinical6.get
clinical6.get(User).then(users => { users[0].getAvailableStrategies() });

public async getAwardedBadges(awardedBadge: Object, cacheMode: String): Promise<AwardedBadge[]|AwardedBadge> source

Get Awarded Badges

Params:

NameTypeAttributeDescription
awardedBadge Object
  • optional

Awarded badge to modify result (by id)

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<AwardedBadge[]|AwardedBadge>

Promise object that returns one object or hashmap

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { User } from 'clinical6';
const user = new User({ id: 15 });

// You will be able to access these awardedBadges using the `getAwardedBadges` method.
user.getAwardedBadges().then(awardedBadges => console.log(awardedBadges));

// Get one AwardedBadge
user.getAwardedBadges({ id: 7 }).then(awardedBadges => console.log(awardedBadges));

public async getCohortAssignments(params: Object, options: String): Promise source

Gets the cohort assignment associated to this user.

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 String
  • optional

Modify the nature of the call and response

options.url String
  • optional

Override the url for this call

options.cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Promise with data (array or object)

Example:

import { User, clinical6 } from 'clinical6';
const user = new User({ id: 23 });
user.getCohortAssignments({ id: 5 });

// Combined with clinical6.get
clinical6.get(User).then(users => { users[0].getCohortAssignments() });

public async getCohorts(): Promise<Cohort[]> source

Gets the list of cohorts after calling this.getCohortAssignments()

Return:

Promise<Cohort[]>

Promise returning an array of cohorts

Example:

import { clinical6, Cohort } from 'clinical6';
const users = await clinical6.get(User);
const cohorts = await users[0].getCohorts();
console.log(cohorts);

public async getConsentGrants(options: String): Promise source

Gets the consent grants associated to this user.

Params:

NameTypeAttributeDescription
options String
  • optional

Modify the nature of the call and response

options.url String
  • optional

Override the url for this call

options.cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Promise with data (array or object)

Example:

import { User, clinical6 } from 'clinical6';
const user = new User({ id: 23 });
user.getConsentGrants({ id: 5 });

// Combined with clinical6.get
clinical6.get(User).then(users => { users[0].getConsentGrants() });

public async getDataGroup(dataGroup: Object, cacheMode: String): Promise<FlowDataGroup> source

Get Flow Data Group for a user based on an id.

Params:

NameTypeAttributeDescription
dataGroup Object
  • nullable: false

Parameters used to get information from server (such as id)

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<FlowDataGroup>

Promise object that returns one object

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { userService, FlowDataGroup } from 'clinical6';
userService.getDataGroup({ id: 24 });
const capturedValueGroup = new FlowDataGroup( {id: 24 });
userService.getDataGroup(capturedValueGroup);

public async getEntries(filter: Object, cacheMode: String): Promise<Entry[]|Entry> source

Get eDiary entries

Params:

NameTypeAttributeDescription
filter Object
  • optional

Filters to modify result (date, entry_group_id)

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Entry[]|Entry>

Promise object that returns one object or hashmap

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { User } from 'clinical6';
const user = new User({ id: 15 });

// You will be able to access these entry groups using the `get` method.
user.getEntries().then(entry => console.log(entry));

const filters = { entry_group_id: 7, date: '2018-06-02'};
user.getEntries(filter).then(entry => console.log(entry));

public async getNotifications(): Promise<Notification[]> source

Get user notifications

Return:

Promise<Notification[]>

Promise object that returns a list of Notifications

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { User } from 'clinical6';
const user = new User({ id: 15 });

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

public async getProfile(): Promise<Profile> source

Retrieve a related user profile.

Return:

Promise<Profile>

Promise object that returns success or failure

Example:

client.getRelatedUsers().then(users => {
  users[0].getProfile().then(profile => console.log(profile));;
});

public async getRegistrationStatus(): Promise<String> source

Returns the registration status of the user.

Return:

Promise<String>

A Promise with the status

Example:

import { User } from "clinical6";

const user = new User({...});
user.getRegistrationStatus().then(status => console.log(status));

public async getSchedules(cacheMode: String): Promise<Schedule[]> source

Get Schedules

Params:

NameTypeAttributeDescription
cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Schedule[]>

Promise object that returns one object or hashmap

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { User } from 'clinical6';
const user = new User({ id: 15 });

// You will be able to access these schedules using the `getSchedules` method.
user.getSchedules().then(schedules => console.log(schedules));

public async invite(attributes: Object, relationships: Object): Promise<User> source

Sends an invitation to this user

Params:

NameTypeAttributeDescription
attributes Object
  • optional

A list of optional attributes not found in user or profile. This can contain any key/value.

attributes.invitation_token String
  • optional

The token used for accepting an invitation

attributes.password String
  • optional

A password chosen for the user

attributes.relationship String
  • optional

A relationship of the user to patient ('father', 'mother', 'uncle', 'aunt', etc)

relationships Object
  • optional

A list of optional relationships not found in user or profile. This can contain any key/value.

relationships.site Site
  • optional

The user's site

relationships.user_role Role
  • optional

The user's role (especially used if not defined in the user object)

relationships.language Language
  • optional

The user's language (especially used if not defined in the user profile)

Return:

Promise<User>

Returns a promise with the invited user (this user)

Example:

import { User } from "clinical6";

const user = new User({...});
user.invite();

public isPasswordSet(): boolean source

Indicates if the password is set

Return:

boolean

Whether or not the password is set (undefined if doesn't exist yet)

Example:

import { User } from "clinical6";

const user = new User({...});
user.getRegistrationStatus().then(() => {
  user.isPasswordSet; // true or false
});

public async removeAwardedBadge(awardedBadge: Badge, cacheMode: String): Promise<Any> source

Add Badge

Params:

NameTypeAttributeDescription
awardedBadge Badge
  • nullable: false

Badge to add result (by id)

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Any>

Promise of action success

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { AwardedBadge, User } from 'clinical6';
const user = new User({ id: 15 });
const awardedBadge = new AwardedBadge({ id: 5 });

// You will be able to add a badge using the `addBadge` method.
// It returns the "AwardedBadge" relationship
user.removeAwardedBadge(awardedBadge).then(data => console.log(data));

public async requestPasswordReset(): Promise source

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

Return:

Promise

Promise object that returns success or failure

Example:

import { User } from 'clinical6';
const user = new User({...});
user.requestPasswordReset();

public async resendInvite(options: any): Promise source

Resends an invite to a related user.

Params:

NameTypeAttributeDescription
options any
  • optional
  • default: {}

Additional options submitted to the server

Return:

Promise

Promise object that returns success or failure

Decorators:

  • deprecate

Example:

client.getRelatedUsers().then(users => {
  users[0].resendInvite({});
});

public async resetPassword(token: String, password: String, device: Device): Promise<User> source

Resets the password given a token and password (and email if user has one).

Params:

NameTypeAttributeDescription
token String
  • nullable: false

Token from request password reset email

password String
  • nullable: false

New password to reset to.

device Device
  • optional

Reset with this device (Default to saved device).

device.id Number
  • nullable: false

Reset with this device (Default to saved device).

Return:

Promise<User>

Promise object that returns success or failure

Example:

import { User } from 'clinical6';
const user = new User({...});
user.resetPassword('adfasdfjkl', 'sekret_password!');

public async revokeConsent(cacheMode: String): Promise source

Revokes consent for the user

Params:

NameTypeAttributeDescription
cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Promise object that returns success or failure

public async save(): Promise<User> source

Saves a user (insert if id doesn't exist, update if it does)

Return:

Promise<User>

Returns a promise via ajax call.

Example:

import { User, userService } from 'clinical6';

// Inserts new user (no existing id)
const user = new User({
  "type": "mobile_users",
  "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
  }
});
user.save();

// Updates existing user (has existing id)
userService.get().then(users => users[0].save());

public async saveProfile(): Promise<Profile> source

Saves a user's profile (insert if id doesn't exist, update if it does)

Return:

Promise<Profile>

Returns a promise via ajax call.

Example:

import { User, userService } from 'clinical6';

const user = new User({...});
user.profile = new Profile({...});
user.profile.age = 25;

// Updates profile
user.saveProfile();

public async sendConfirmation(): Promise source

Sends a confirmation email to an email address

Return:

Promise

Promise object that returns success or failure

Example:

import { User } from 'clinical6';
const user = new User({...});
user.sendConfirmation();

public toInvitation(attributes: Object, relationships: Object): Invitation source

Converts the user into an invitation used for sending or accepting an invitation. We've documented some common examples, however any attribute or relationship key / value will be accepted as long as it's not shared between the two. An attribute cannot also be a relationship.

Params:

NameTypeAttributeDescription
attributes Object
  • optional

A list of optional attributes not found in user or profile. This can contain any key/value.

attributes.invitation_token String
  • optional

The token used for accepting an invitation

attributes.password String
  • optional

A password chosen for the user

attributes.relationship String
  • optional

A relationship of the user to patient ('father', 'mother', 'uncle', 'aunt', etc)

relationships Object
  • optional

A list of optional relationships not found in user or profile. This can contain any key/value.

relationships.site Site
  • optional

The user's site

relationships.user_role Role
  • optional

The user's role (especially used if not defined in the user object)

relationships.language Language
  • optional

The user's language (especially used if not defined in the user profile)

Return:

Invitation

The invitation in which the user was converted

Example:

User to simple invitation
import { User } from 'clinical6';
const user = new User({ email: 'john.brown@parallel6.com' });
user.profile.firstName = 'John';
user.profile.lastName = 'Brown';
const invitation = user.toInvitation();
console.log(invitation);
User to invitation with Site, Role, Language, Token and Password
import { Site, Role, Language, User } from 'clinical6';
const user = new User({ email: 'john.brown@parallel6.com' });
user.profile.firstName = 'John';
user.profile.lastName = 'Brown';
const invitation = user.toInvitation({
 invitation_token: 'asdf12124',
 password: 'mypassword@1'
}, {
 followed: new User({ id: 283 }),
 language: new Language({ id: 43 }),
 site: new Site({ id: 5 }),
 user_role: new Role({ id: 23 })
});
console.log(invitation);

public async unlockUser(unlockToken: String): Promise source

Unlocks the user

Params:

NameTypeAttributeDescription
unlockToken String
  • optional

The unlock token to unlock the user with

Return:

Promise

Promise object that returns success or failure

Example:

import { User } from 'clinical6';
const user = new User({...});
user.unlockUser('123123');