Manual Reference Source Test
public class | source

Rule

Mixin Extends:

RuleModel, Helper

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
    }
  }
});

Test:

Static Member Summary

Static Public Members
public static get

Constructor Summary

Public Constructor
public

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

Static Public Members

public static get type: String source

Public Constructors

public constructor(json: Object) source

Constructor for helper class representing an Rule

Override:

RuleModel#constructor

Params:

NameTypeAttributeDescription
json Object

json api response from server

Public Members

public get schedulers: Schedule[] source

public set schedulers: Schedule[] source

Public Methods

public delete(): Promise source

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

Return:

Promise

Returns a promise via ajax call.

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 });

Test:

public eventsByDate(date: *): Promise source

Returns all the events for the rule on the given date.

Params:

NameTypeAttributeDescription
date *

{String} - The date to search for events for. The format of the date must be YYYY-MM-DD. This paramater is optional.

Return:

Promise

Returns a promise via ajax call.

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.

Return:

Promise<Event>

Returns a promise via ajax call.

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:

NameTypeAttributeDescription
timeUnit *

{String} - The time cap for recent events. Must be either 'week' or 'month'. This parameter is optional.

Return:

Promise

Returns a promise via ajax call.

public save(): Promise<Rule> source

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

Return:

Promise<Rule>

Returns a promise via ajax call.

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());

Test:

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:

NameTypeAttributeDescription
timeUnit *

{String} - The time cap for recent events. Must be either 'week' or 'month'. This parameter is optional.

Return:

Promise

Returns a promise via ajax call.