Flow
Mixin Extends:
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:
let flow = new Flow({ id: 1, steps: [] });
let flow = new Flow({ id: 1, steps: [] }, { transition: 'manual' });
flow.owner = 23;
flow.ownerType = 'site_start/sites';
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 |
|
public get |
Get |
|
public get |
Get |
|
public set |
Set |
|
public get |
Get Fields flattens the fields to an array to be used for the API endpoint |
|
public |
|
|
public get |
Get |
|
public set |
Set |
|
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 |
|
public get |
Get |
|
public get |
Get |
|
public set |
Set |
|
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 |
|
public set |
Set |
|
public |
|
|
public |
|
|
public get |
|
Private Members | ||
private |
|
|
private |
|
|
private |
|
|
private |
|
|
private |
|
Method Summary
Public Methods | ||
public |
addFieldsToSave(array: String[]) Prepare the list of keys to be sent later |
|
public |
Clones the current object and returns a copy of |
|
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 |
The final action after the last step. |
|
public |
findInputs(whereFn: function): FlowInput[] Find inputs where certain attributes are equal |
|
public |
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 |
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 |
async saveFlowAttributes(): Promise<Flow> Saves flow attributes / flow data. |
|
public |
Set user collected data with a key/value pair for server consumption. |
|
public |
Starts the flow using transition collect |
|
public |
toPlantUML(): String Generates Plant UML text so that the developer can visualize the flow using external tools. |
|
public |
transition(action: String): Promise Transition between states using actions |
Inherited Summary
From class FlowModel | ||
public |
|
|
public |
|
|
public |
|
|
public |
|
|
public |
draft: * |
|
public |
|
|
public |
|
|
public |
|
|
public |
|
|
public |
|
|
public |
published: * |
|
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#constructorParams:
Name | Type | Attribute | Description |
response | Object |
|
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 |
|
Flow process settings |
settings.transition | String |
|
Either 'auto' or 'manual', defaults to 'auto' |
Public Members
public get fields: Object[] source
Get Fields flattens the fields to an array to be used for the API endpoint
Private Members
Public Methods
public addFieldsToSave(array: String[]) source
Prepare the list of keys to be sent later
Params:
Name | Type | Attribute | Description |
array | String[] | A list of keys representing fields that |
Example:
flow.addFieldsToSave([ 23, 42, 189 ]);
public clone(): Flow source
Clones the current object and returns a copy of this
instance
Example:
let newFlow = flow.clone();
public complete(): Promise source
Completes the flow using transition collect
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();
public end(step: FlowStep): * source
The final action after the last step. This function is intended for the user to override.
Params:
Name | Type | Attribute | Description |
step | FlowStep |
|
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:
Name | Type | Attribute | Description |
whereFn | function |
|
A function returning a boolean value |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
a | FlowStep |
|
The starting point for the BFS object |
Example:
flow.getBFS(flow.first);
public getData(): Promise source
Gets user input data belonging to the flow
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
Example:
var matrix = flow.getJohnsonMatrix();
console.log(matrix);
public getLongestDistance(a: FlowStep): Number source
Get the longest path from a flowstep
Params:
Name | Type | Attribute | Description |
a | FlowStep |
|
The starting step |
Example:
flow.getLongestDistance(flow.first);
public getStatus(): Promise source
Get Status and set it to this._status
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
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:
Name | Type | Attribute | Description |
results | Object |
|
results of the save event |
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:
Name | Type | Attribute | Description |
action | String |
|
The action that is being tracked |
Example:
flow.postInsights('collect') = (response) => {
// do something with the save response
return response;
}
public save(): Promise source
Saves the collected data of the flow. This will automatically process a transition.
Example:
flow.save();
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.
Example:
import { Flow, clinical6 } from 'clinical6';
// Updates existing flow(has existing id)
const flow = new Flow({...});
flow.saveFlowAttributes();
public set(key: String, value: String, existingId: Number) source
Set user collected data with a key/value pair for server consumption.
Example:
flow.set('first_name', 'Joe');
flow.set('last_name', 'Montana');
public toPlantUML(): String source
Generates Plant UML text so that the developer can visualize the flow using external tools.
public transition(action: String): Promise source
Transition between states using actions
Params:
Name | Type | Attribute | Description |
action | String |
|
The action must be either 'collect' or 'start' |
Example:
flow.transition('collect').then((data) => {
console.log('new status', flow.status);
});