Manual Reference Source Test

src/helpers/flow/FlowInput.js

import FlowInputModel from '../../models/flow/FlowInput';
import FlowService from '../../services/FlowService';

/**
 * Helper class representing a flow input object.
 * Required values include:
 * - id
 * - title
 * - question_type
 * - style
 * - choice_list
 *
 * @example
 * let facilityTypeInput = new FlowInput({
 *  id: 7175,
 *  storage_attribute: "some_title",
 *  title: "Facility Type",
 *  body: null,
 *  question_type: "single_choice",
 *  style: "radio_buttons",
 *  required: false,
 *  validation_expression: null,
 *  validation_details: null,
 *  instructions: null,
 *  choice_list: [
 *      { id: 4495, body: "Clinic/Outpatient Facility" },
 *      { id: 4496, body: "Dedicated Research Facility" },
 *      { id: 4497, body: "Hospital" },
 *      { id: 4498, body: "Long-Term Care Facility" },
 *      { id: 4499, body: "Network" }
 *  ],
 *  locked: null
 * });
 *
 * @example
 * let myInput = new FlowInput({
 *  id: 9433,
 *  storage_attribute: "expiration",
 *  title: "License Expiration Date",
 *  body: null,
 *  question_type: "date",
 *  style: "calendar",
 *  required: true,
 *  validation_expression: null,
 *  validation_details: {
 *      min: "current"
 *  },
 *  instructions: null,
 *  choice_list: [],
 *  locked: null
 * });
 *
 * @example
 * let myInput = new FlowInput({
 *  id: 9766,
 *  storage_attribute: "dyn_curriculum_vitae_effective_date",
 *  title: "CV Effective Date",
 *  body: null,
 *  question_type: "date",
 *  style: "calendar",
 *  required: true,
 *  validation_expression: null,
 *  validation_details: {
 *      max: "current",
 *      min: {
 *          value: "current",
 *          subtract: { year: 2 },
 *          add: null
 *      }
 *  },
 *  instructions: null,
 *  choice_list: [],
 *  locked: null
 * });
 */
class FlowInput extends FlowInputModel {
  /**
   * Find a choice object given a string
   *
   * @param  {String}  value   - The item in which to search
   * @return {Object}
   *
   * @example
   * facilityTypeInput.findChoiceByCode('Network');
   * // Should return Choice { id: 4499, code: "Network" }
   */
  findChoiceByCode(value) {
    let _return = null;
    this.choice_list.forEach((choice) => {
      if (value && typeof value === 'string' && typeof choice.code === 'string'
        && choice.code.toLowerCase() === value.toLowerCase()) {
        _return = choice;
      }
    });
    return _return;
  }

  /**
   * Get input data belonging to this flow input
   *
   * @return {Promise} A promise with the resulting data
   *
   * @example
   * facilityTypeInput.getData().then(data => console.log(data));
   */
  getData() {
    return (new FlowService()).getInputDataById(this.id);
  }
}

export default FlowInput;