Manual Reference Source Test
public class | source

Cohort

Mixin Extends:

CohortModel, Helper

Helper class representing a cohort.

Example:

// To get a list of Cohorts use clinical6.get
import { clinical6, Cohort } from 'clinical6';
clinical6.get(Cohort).then(c => console.log(c));

// To get a single cohort, you can also use clinical6
clinical6.get({ id: 5, type: 'cohorts'});

// To save or insert, you can either use the .save() capability or clinical6
myCohort.save(); // insert if no id, save if id
clinical6.insert(new Cohort({...}));
clinical6.update(myCohort);

// To delete you can use the .delete() capability or clinical6
myCohort.delete();
clinical6.delete(myCohort);

Test:

Static Member Summary

Static Public Members
public static get

Constructor Summary

Public Constructor
public

Constructor for helper class representing a Cohort

Member Summary

Public Members
public get
public set
public get

users: User[]

public set

users: User[]

Private Members
private
private

Method Summary

Public Methods
public

async addUser(user: User): Promise<CohortAssignment

This will create a CohortAssignment and save it to the server based on this current cohort and the user parameter

public

Deletes a cohort

public

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

Gets the cohort assignment associated to this cohort.

public

async getUsers(): Promise<Users[]>

Gets the list of users after calling this.getAssignments()

public

Removes an assignment from a Cohort.

public

async save(): Promise<Cohort>

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

Inherited Summary

From class CohortModel
public
public
public
public
public

Static Public Members

public static get type: String source

Public Constructors

public constructor(json: Object) source

Constructor for helper class representing a Cohort

Override:

CohortModel#constructor

Params:

NameTypeAttributeDescription
json Object

json api response from server

Public Members

public get assignments: CohortAssignment[] source

public set assignments: CohortAssignment[] source

public get users: User[] source

public set users: User[] source

Private Members

private _assignments: CohortAssignment[] source

private _users: User[] source

Public Methods

public async addUser(user: User): Promise<CohortAssignment source

This will create a CohortAssignment and save it to the server based on this current cohort and the user parameter

Params:

NameTypeAttributeDescription
user User

The user to be added to this cohort

Return:

Promise<CohortAssignment

Returns the cohort assignment

Example:

import { clinical6, User, Cohort } from 'clinical6';
const cohorts = await clinical6.get(Cohort);
const user = new User({...}); // some new user
const assignment = await cohorts[0].addUser(user);

Test:

public delete(): Promise source

Deletes a cohort

Return:

Promise

Returns a promise via ajax call.

Example:

import { Cohort, Client } from 'clinical6';

// Removes cohort from server and local storage
const cohort = new Cohort({...});
cohort.delete();

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

Test:

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

Gets the cohort assignment associated to this cohort.

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 { Cohort, clinical6 } from 'clinical6';
const cohort = new Cohort({ id: 23 });
cohort.getAssignments({ id: 5 });

// Combined with clinical6.get
clinical6.get(Cohort).then(cohorts => { cohorts[0].getAssignments() });

Test:

public async getUsers(): Promise<Users[]> source

Gets the list of users after calling this.getAssignments()

Return:

Promise<Users[]>

Promise returning an array of users

Example:

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

Test:

public async removeUser(obj: CohortAssignment | User): Promise source

Removes an assignment from a Cohort.

Params:

NameTypeAttributeDescription
obj CohortAssignment | User

Object that is to be removed from current Cohort.

Return:

Promise

Promise likely with an empty string or error

Example:

import { clinical6, User, Cohort } from 'clinical6';
const cohorts = await clinical6.get(Cohort);
const user = new User({...}); // some new user
const assignment = await cohorts[0].removeUser(user);

Test:

public async save(): Promise<Cohort> source

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

Return:

Promise<Cohort>

Returns a promise via ajax call.

Example:

import { Cohort, clinical6 } from 'clinical6';

// Inserts new role (no existing id)
const cohort = new Cohort({
  "type": "cohorts",
  "attributes": {
      "name": "name",
      "cohort_type": "static"
  }
});
cohort.save();

// Updates existing cohort(has existing id)
clinical6.get(Cohort).then(cohorts => cohorts[0].save());

Test: