Manual Reference Source Test
public class | source

Flow

Mixin Extends:

FlowModel, Helper, Commentable

A flow is a collection of steps representing a screen or card created by the Clinical6 platform. Each flow indicates what the first step is to start the flow and each step has a list of actions the user or system can perform to move to the next step. Flows additionally have a status that starts at initial and can be either transitioned directly through the transition method or by saving the flow or step. Saving a flow will send everything that has been set in the _fields property to the server. Saving a step will only save items in the toSave property and will provide a transition based on completeness, updating the flow status.

Example:

Simple flow
let flow = new Flow({ id: 1, steps: [] });
Simple flow with settings
let flow = new Flow({ id: 1, steps: [] }, { transition: 'manual' });
Set Owner and Owner Type
flow.owner = 23;
flow.ownerType = 'site_start/sites';
Complex Flow
let flow = new Flow({
      id: 1,
      name: 'Dummy Flow',
      first_step: 11,
      steps: [
        {
          id: 11,
          title: 'dummy_5',
          description: 'dummy_6',
          content_type: 'info_screen_with_help',
          help: 'ALL text',
          image: { },
          inputs: [
            {
              title: 'Age',
              question_type: 'text',
              style: 'text',
              choice_list: [],
              id: 'first_name',
            },
            {
              id: 271,
              title: 'Is your facility affiliated with an SMO?',
              question_type: 'single_choice',
              style: 'radio_buttons',
              required: false,
              validation_expression: null,
              instructions: 'Is your facility affiliated with an SMO?',
              choice_list: [
                {
                  id: 371,
                  body: 'Yes',
                },
                {
                  id: 372,
                  body: 'No',
                },
              ],
              locked: null,
            },
          ],
          paths: [
            {
              capture: true,
              button_name: 'Next',
              steps: [
                {
                  step: 12,
                  conditions: [
                    {
                      criteria: '271',
                      operator: '=',
                      value: '371',
                    },
                  ],
                },
              ],
            },
          ],
        },
        {
          id: 12,
          title: 'dummy_5',
          description: 'dummy_6',
          content_type: 'info_screen_with_help',
          help: 'ALL text',
          image: { },
          inputs: [
            {
              title: 'First Name',
              question_type: 'text',
              style: '',
              choice_list: [],
              id: 'first_name',
            },
          ],
          paths: [
            {
              capture: true,
              button_name: 'Next',
              steps: [
                {
                  step: 13,
                  conditions: [],
                },
              ],
            },
          ],
        },
        {
          id: 13,
          title: 'dummy_5',
          description: 'dummy_6',
          content_type: 'info_screen_with_help',
          help: 'ALL text',
          image: { },
          inputs: [
            {
              title: 'First Name',
              question_type: 'text',
              style: '',
              choice_list: [],
              id: 'first_name',
            },
          ],
          paths: [],
        },
      ],
    });

Constructor Summary

Public Constructor
public

constructor(response: Object, settings: Object)

Constructor for Flow.

Member Summary

Public Members
public set

Set _options.entry

public get

Get _options.entry

public get

Get _options.existing_id

public set

Set _options.existing_id

public get

Get Fields flattens the fields to an array to be used for the API endpoint

public
public get

Get _options.captured_value_group_id

public set

Set _options.captured_value_group_id

public get

Get objectType

public set

Set options needed for API flow process collect endpoint

public get

Get options needed for API flow process collect endpoint

public set

Set _options.owner

public get

Get _options.owner

public get

Get _options.owner_type

public set

Set _options.owner_type

public get

Get options needed for API flow process collect endpoint

public set

Set settings needed for API flow process collect endpoint

public get

Get _status

public set

Set _status

public
public
public get
Private Members
private
private
private
private
private

Method Summary

Public Methods
public

Prepare the list of keys to be sent later

public

clone(): Flow

Clones the current object and returns a copy of this instance

public

Completes the flow using transition collect

public

Loop through each step and provide a direct link to the next_step's step. This in essence creates / completes the flow's graph structure.

public

end(step: FlowStep): *

The final action after the last step.

public

Find inputs where certain attributes are equal

public

get(key: String): Any

Get value from key

public

BFS Distance, creates a BFS object based on distance from a.

public

Gets user input data belonging to the flow

public

Johnson Matrix using the key/value as id/distance of the graph

public

Get the longest path from a flowstep

public

Get Status and set it to this._status

public

Loading the steps from server

public

onSave(results: Object): Object

Is run after a successful flow save.

public

postInsights(action: String): Promise<any>

Post Insight on this flow.

public

reset()

Resets the current fields from the flow and its steps.

public

Saves the collected data of the flow.

public

Saves flow attributes / flow data.

public

set(key: String, value: String, existingId: Number)

Set user collected data with a key/value pair for server consumption.

public

Starts the flow using transition collect

public

Generates Plant UML text so that the developer can visualize the flow using external tools.

public

Transition between states using actions

Inherited Summary

From class FlowModel
public
public
public
public
public

draft: *

public
public
public
public
public
public
public
public
public
public

Public Constructors

public constructor(response: Object, settings: Object) source

Constructor for Flow. This expects that steps are in JSON format and is able to be mapped to the FlowStep data type. After each step has been mapped, the constructor will then connect the graph according to each steps available actions.

Override:

FlowModel#constructor

Params:

NameTypeAttributeDescription
response Object
  • nullable: false

JSON formatted response of a flow process. Requires all fields that are necessary for FlowModel

response.id Number

The id of the content

response.name String

The id of the content

response.steps Array

The array of steps in the flow process

response.first_step Number

The id of the first step

response.total Number

The total number of steps

settings Object
  • nullable: true

Flow process settings

settings.transition String
  • optional
  • default: 'auto'
  • nullable: true

Either 'auto' or 'manual', defaults to 'auto'

Public Members

public set entry: Entry source

Set _options.entry

public get entry: Entry source

Get _options.entry

public get existingId: String source

Get _options.existing_id

public set existingId: String source

Set _options.existing_id

public get fields: Object[] source

Get Fields flattens the fields to an array to be used for the API endpoint

public get flowDataGroupId: String source

Get _options.captured_value_group_id

public set flowDataGroupId: String source

Set _options.captured_value_group_id

public get objectType: String source

Get objectType

public set options: Object source

Set options needed for API flow process collect endpoint

public get options: Object source

Get options needed for API flow process collect endpoint

public set owner: String source

Set _options.owner

public get owner: String source

Get _options.owner

public get ownerType: String source

Get _options.owner_type

public set ownerType: String source

Set _options.owner_type

public get settings: Object source

Get options needed for API flow process collect endpoint

public set settings: Object source

Set settings needed for API flow process collect endpoint

public get status: String source

Get _status

public set status: String source

Set _status

public steps: FlowStep[] source

Override:

FlowModel#steps

public total: Number source

Override:

FlowModel#total

public get type: String source

Private Members

private _fields: Object source

private _options: Object source

private _settings: Object source

private _status: String source

private _toSave: String[] source

Public Methods

public addFieldsToSave(array: String[]) source

Prepare the list of keys to be sent later

Params:

NameTypeAttributeDescription
array String[]

A list of keys representing fields that save() will send

Example:

flow.addFieldsToSave([ 23, 42, 189 ]);

public clone(): Flow source

Clones the current object and returns a copy of this instance

Return:

Flow

Returns a copy of this object

Example:

let newFlow = flow.clone();

Test:

public complete(): Promise source

Completes the flow using transition collect

Return:

Promise

Returns a promise via ajax call.

Example:

flow.complete();

public connectGraph() source

Loop through each step and provide a direct link to the next_step's step. This in essence creates / completes the flow's graph structure.

Example:

flow.connectGraph();

Test:

public end(step: FlowStep): * source

The final action after the last step. This function is intended for the user to override.

Params:

NameTypeAttributeDescription
step FlowStep
  • nullable: false

The last step information

Return:

*

Example:

flow.end = (step) => {
 console.log(step);
 return step;
};

public findInputs(whereFn: function): FlowInput[] source

Find inputs where certain attributes are equal

Params:

NameTypeAttributeDescription
whereFn function
  • nullable: false

A function returning a boolean value

Return:

FlowInput[]

Array of FlowInputs corresponding to the filter

Example:

const inputs = flow.findInputs(input => (
  ['single_choice', 'multiple_choice'].indexOf(input.question_type) >= 0
  && input.id === key));

public get(key: String): Any source

Get value from key

Params:

NameTypeAttributeDescription
key String

Key must be 'input_id'

Return:

Any

value This is the user response given the key

public getBFS(a: FlowStep): Object source

BFS Distance, creates a BFS object based on distance from a.

Params:

NameTypeAttributeDescription
a FlowStep
  • nullable: false

The starting point for the BFS object

Return:

Object

BFS object based on distance from a in { <flowstep.id>: <distance>} format.

Example:

flow.getBFS(flow.first);

See:

public getData(): Promise source

Gets user input data belonging to the flow

Return:

Promise

A promise with the resulting data

Example:

flow.getData().then((data) => {
  console.log('response', data);
  console.log('flow.data', flow.data);
});

public getJohnsonMatrix(): Object source

Johnson Matrix using the key/value as id/distance of the graph

Return:

Object

{id: {id: distance}} to get diatance of a step id to another step id

Example:

var matrix = flow.getJohnsonMatrix();
console.log(matrix);

See:

public getLongestDistance(a: FlowStep): Number source

Get the longest path from a flowstep

Params:

NameTypeAttributeDescription
a FlowStep
  • nullable: false

The starting step

Return:

Number

0 if nothing is found or the longest path distance

Example:

flow.getLongestDistance(flow.first);

public getStatus(): Promise source

Get Status and set it to this._status

Return:

Promise

A Promise containing the status (String)

Example:

flow.getStatus().then((data) => {
  console.log('response', data);
  console.log('flow.status', flow.status);
});

public loadSteps(): Promise<FlowStep[]> source

Loading the steps from server

This is only necessary if you are using v3 eDiary

Return:

Promise<FlowStep[]>

Returns this flow's new flowsteps

Example:

import { flowService } from 'clinical6';
flowService.getFlow('my_flow').then(flow => flow.loadSteps());

TODO:

  • modify this function later when v3 is out for flows

public onSave(results: Object): Object source

Is run after a successful flow save.

Params:

NameTypeAttributeDescription
results Object
  • nullable: false

results of the save event

Return:

Object

returns the results

Example:

flow.onSave = (response) => {
  // do something with the save response
  return response;
}

public postInsights(action: String): Promise<any> source

Post Insight on this flow.

Params:

NameTypeAttributeDescription
action String
  • nullable: false

The action that is being tracked

Return:

Promise<any>

returns the results

Example:

flow.postInsights('collect') = (response) => {
  // do something with the save response
  return response;
}

Test:

public reset() source

Resets the current fields from the flow and its steps.

Example:

flow.reset();

Test:

public save(): Promise source

Saves the collected data of the flow. This will automatically process a transition.

Return:

Promise

Returns a promise via ajax call.

Example:

flow.save();

Test:

public async saveFlowAttributes(): Promise<Flow> source

Saves flow attributes / flow data. (insert if id doesn't exist, update if it does) This method does NOT submit flow answers, just flow specific data.

Return:

Promise<Flow>

Returns a promise via ajax call.

Example:

import { Flow, clinical6 } from 'clinical6';

// Updates existing flow(has existing id)
const flow = new Flow({...});
flow.saveFlowAttributes();

Test:

public set(key: String, value: String, existingId: Number) source

Set user collected data with a key/value pair for server consumption.

Params:

NameTypeAttributeDescription
key String
  • nullable: false

A key from inputs

value String
  • nullable: false

The value from the user

existingId Number
  • optional

The existing id to update an object to

Example:

flow.set('first_name', 'Joe');
flow.set('last_name', 'Montana');

Test:

public start(): Promise source

Starts the flow using transition collect

Return:

Promise

Returns a promise via ajax call.

Example:

flow.start();

public toPlantUML(): String source

Generates Plant UML text so that the developer can visualize the flow using external tools.

Return:

String

Plant UML String

public transition(action: String): Promise source

Transition between states using actions

Params:

NameTypeAttributeDescription
action String
  • nullable: false

The action must be either 'collect' or 'start'

Return:

Promise

Returns a promise but will alsoassign the new state to the Flow intance

Example:

flow.transition('collect').then((data) => {
  console.log('new status', flow.status);
});