Rule
Helper class representing a rule.
Example:
import { Rule, ruleService } from 'clinical6';
// Typically use RuleService.get()
ruleService.get().then(rules => console.log(rules));
const rule = new Rule({
"data": {
"id": "1",
"type": "rules",
"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
}
}
});
Constructor Summary
Public Constructor | ||
public |
constructor(json: Object) Constructor for helper class representing an Rule |
Member Summary
Public Members | ||
public get |
|
|
public set |
|
Method Summary
Public Methods | ||
public |
Saves a rule (insert if id doesn't exist, update if it does) |
|
public |
eventsByDate(date: *): Promise Returns all the events for the rule on the given date. |
|
public |
Returns the next event for the rule. |
|
public |
recentEvents(timeUnit: *): Promise Returns the most recent events for the rule. |
|
public |
Saves a rule (insert if id doesn't exist, update if it does) |
|
public |
upcomingEvents(timeUnit: *): Promise Returns the events that will occur soon for the rule. |
Inherited Summary
From class RuleModel | ||
public |
|
|
public |
|
|
public |
|
|
public |
|
|
public |
|
Public Constructors
public constructor(json: Object) source
Constructor for helper class representing an Rule
Override:
RuleModel#constructorParams:
Name | Type | Attribute | Description |
json | Object | json api response from server |
Public Methods
public delete(): Promise source
Saves a rule (insert if id doesn't exist, update if it does)
Example:
import { Rule, Client } from 'clinical6';
// Removes rule from server and local storage
const rule = new Rule({
"id": 1,
"type": "rules",
"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
}
});
rule.delete();
// No longer in storage
Client.instance.storageUtility.has('rules', { id: 1 });
public eventsByDate(date: *): Promise source
Returns all the events for the rule on the given date.
Params:
Name | Type | Attribute | Description |
date | * | {String} - The date to search for events for. The format of the date must be YYYY-MM-DD. This paramater is optional. |
public nextEvent(): Promise<Event> source
Returns the next event for the rule. A 404 status will be returned if there isn't a next rule.
public recentEvents(timeUnit: *): Promise source
Returns the most recent events for the rule. The optional time unit caps the amount of returned events by length of time.
Params:
Name | Type | Attribute | Description |
timeUnit | * | {String} - The time cap for recent events. Must be either 'week' or 'month'. This parameter is optional. |
public save(): Promise<Rule> source
Saves a rule (insert if id doesn't exist, update if it does)
Example:
import { Rule, ruleService } from 'clinical6';
// Insert is different from other inserts. Uses mobile application key
const rule = new Rule({
"type": "rules",
"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
}
});
rule.save();
// After you have the authtoken and then you've logged in
// Updates existing rule (has existing id)
ruleService.get().then(rules => rules[0].save());
public upcomingEvents(timeUnit: *): Promise source
Returns the events that will occur soon for the rule. The optional time unit caps the amount of returned events by length of time.
Params:
Name | Type | Attribute | Description |
timeUnit | * | {String} - The time cap for recent events. Must be either 'week' or 'month'. This parameter is optional. |