Manual Reference Source Test

src/helpers/consent/ConsentAdditionalSigner.js

import ConsentAdditionalSignerModel from '../../models/consent/ConsentAdditionalSigner';
import Helper from '../Helper';
import { aggregate } from '../../utilities/ClassUtility';
import { serviceFactory } from '../../utilities/factories/ServiceFactory';

/**
 * Helper class representing an additional signer for a consent form.
 *
 * @extends {ConsentAdditionalSignerModel}
 * @extends {Helper}
 *
 * @example
 *
 *  To have a consent form requires signatures from 3 people, the patient and 2 guardians
 *  you can either use the .save() capability or clinical6
 *
 *  To save or insert, you can either use the .save() capability or clinical6
 *  myConsentAdditionalSigner.save(); // insert if no id, save if id
 *  clinical6.insert(new ConsentAdditionalSigner({...}));
 */

class ConsentAdditionalSigner extends aggregate(ConsentAdditionalSignerModel, Helper) {
  /**
   * Constructor for helper class representing additional signers for a consent form
   *
   * @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 'consent__additional_signatures';
  }

  /** @type {ConsentForm} */
  get form() {
    return this._relationships.form;
  }

  /** @type {ConsentForm} */
  set form(form) {
    this._relationships.form = form;
  }

  /**
   * Created to add signer to the form
   * @return {Promise<ConsentAdditionalSigner>} - Returns a promise via ajax call.
   *
   * @example
   * import { ConsentAdditionalSigner, clinical6 } from 'clinical6';
   *
   * // Inserts new ConsentAdditionalSigner ({no existing id})
   * const consentAdditionalSigner = new ConsentAdditionalSigner({
   * type: "consent__additional_signatures",
   * attributes: {
   *    name: "A name"
   *  },
   *  relationships: {
   *    form: {
   *      data: {
   *        id: 29,
   *        type: "consent__forms"
   *      }
   *    }
   *  }
   * });
   *
   * consentAdditionalSigner.save();
   *
   * // Updates existing ConsentAdditionalSigner (has existing id)
   *    clinical6.get(ConsentAdditionalSigner).then(consentAdditionalSigner => consentAdditionalSigner[0].save());
   */
  async save() {
    const service = serviceFactory.get(this.type);
    return service.insert(this);
  }
}

export default ConsentAdditionalSigner;