Cohort
Mixin Extends:
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);
Constructor Summary
Public Constructor | ||
public |
constructor(json: Object) Constructor for helper class representing a Cohort |
Member Summary
Public Members | ||
public get |
|
|
public set |
|
|
public get |
|
|
public set |
|
Private Members | ||
private |
|
|
private |
|
Method Summary
Public Methods | ||
public |
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 |
Gets the list of users after calling this.getAssignments() |
|
public |
async removeUser(obj: CohortAssignment | User): Promise Removes an assignment from a Cohort. |
|
public |
Saves a cohort (insert if id doesn't exist, update if it does) |
Inherited Summary
From class CohortModel | ||
public |
|
|
public |
|
|
public |
|
|
public |
|
|
public |
|
Public Constructors
public constructor(json: Object) source
Constructor for helper class representing a Cohort
Override:
CohortModel#constructorParams:
Name | Type | Attribute | Description |
json | Object | json api response from server |
Public Members
public get assignments: CohortAssignment[] source
public set assignments: CohortAssignment[] source
Private Members
private _assignments: CohortAssignment[] 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:
Name | Type | Attribute | Description |
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);
public delete(): Promise source
Deletes a cohort
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 });
public async getAssignments(params: Object, options: String): Promise source
Gets the cohort assignment associated to this cohort.
Params:
Name | Type | Attribute | Description |
params | Object |
|
Parameters used to get information from server |
params.id | Number |
|
Id to get data from the server |
params.type | String |
|
Type to be used for storage |
params.filters | Object |
|
Filters to be used for get |
options | String |
|
Modify the nature of the call and response |
options.url | String |
|
Override the url for this call |
options.cacheMode | String |
|
Override the caching method for this call |
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() });
public async getUsers(): Promise<Users[]> source
Gets the list of users after calling this.getAssignments()
Example:
import { clinical6, Cohort } from 'clinical6';
const cohorts = await clinical6.get(Cohort);
const users = await cohorts[0].getUsers();
console.log(users);
public async removeUser(obj: CohortAssignment | User): Promise source
Removes an assignment from a Cohort.
Params:
Name | Type | Attribute | Description |
obj | CohortAssignment | User | Object that is to be removed from current Cohort. |
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);
public async save(): Promise<Cohort> source
Saves a cohort (insert if id doesn't exist, update if it does)
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());