Manual Reference Source Test

src/helpers/ediary/EntryGroup.js

import Helper from '../Helper';
import EntryGroupModel from '../../models/ediary/EntryGroup';
import EDiaryService from '../../services/EDiaryService';
import { aggregate } from '../../utilities/ClassUtility';

/**
 * Helper class representing an eDiary Entry Group.
 *
 * @extends {EntryGroupModel}
 * @extends {Helper}
 */
class EntryGroup extends aggregate(EntryGroupModel, Helper) {
  /**
   * Constructor for helper class representing an eDiary Entry Group
   *
   * @param {Object} json - json api response from server
   */
  constructor(json = {}) {
    super(json);
    this.deserializeRelationshipStubs(json);
    this.syncRelationships(json);
  }

  /** @type {String}  - The type */
  static get type() {
    return 'ediary__entry_groups';
  }

  /** @type {EntryGroup} */
  get children() {
    return this._relationships.child_entry_groups || [];
  }

  /** @type {EntryGroup} */
  set children(children) {
    /** @type {EntryGroup} */
    this._relationships.child_entry_groups = children;
  }

  /** @type {EntryGroup} */
  get parent() {
    return this._relationships.parent_entry_group;
  }

  /** @type {EntryGroup} */
  set parent(parent) {
    /** @type {EntryGroup} */
    this._relationships.parent_entry_group = parent;
  }

  /** @type {Entry} */
  get entries() {
    return this._relationships.ediary_entries;
  }

  /** @type {Entry} */
  set entries(entries) {
    /** @type {Entry} */
    this._relationships.ediary_entries = entries;
  }

  /** @type {EntryTemplate[]} */
  get templates() {
    return this._relationships.entry_templates;
  }

  /** @type {EntryTemplate[]} */
  set templates(templates) {
    /** @type {EntryTemplate[]} */
    this._relationships.entry_templates = templates;
  }

  /**
   * Get eDiary entry templates
   *
   * @throws {Clinical6Error}       - If missing token or missing required parameters
   * @param  {Object}   [filters]    - Filters to modify result (date, entry_group_id)
   * @param  {String}   [cacheMode] - Override the caching method for this call
   * @return {Promise<EntryTemplate[] | EntryTemplate>}
   *                                - Promise object that returns one object or hashmap
   *
   * @example
   * import { EntryGroup } from 'clinical6';
   * const group = new EntryGroup({ id: 15, ...});
   *
   * // You will be able to access these entry groups using the `get` method.
   * group.getTemplates().then(templates => console.log(templates));
   *
   * // You can also use the filter for automatic or manual
   * group.getTemplates({ category: 'automatic' }).then(templates => console.log(templates));
   *
   * // additionally after the call, group.templates should now be the returned templates
   * console.log(group.templates);
   */
  getTemplates(filters = undefined, cacheMode = undefined) {
    return (new EDiaryService()).getTemplates(this, filters, cacheMode)
      .then(t => (this._entry_templates = t));
  }
}

export default EntryGroup;