/
ACTIVITY_INSERT()

ACTIVITY_INSERT()

Prototype
ACTIVITY_INSERT(activity,[task_ref],[condition],[position], [insert_closed], [parameters])

Insert an activity into a TASK in the current ADMISSION. 

Input Parameters

Parameter

Type

Default Value

Required

Description

Parameter

Type

Default Value

Required

Description

activity

String

 

Yes

A TASK code referring to the activity to be inserted

task_ref

String, Number

 

No

Supported values:

  • NULL: The activity will be inserted in the current TASK (where the FORMULA is being executed)

  • Number: The activity will be inserted in the TASK whose reference is the one provided in TASK_REF 

  • String: The activity will be inserted in a TASK whose TASK CODE is the one provided in TASK_REF 

condition

Boolean

true

No

The activity will only be inserted if this parameter has a true value

position

StringNumber

"LAST"

No

A number indicating the position in the TASK where the activity will be inserted.

Additionally, it is possible to indicate one of the following options:

  • "FIRST": The ACTIVITY will be inserted at the beginning of the TASK (first activity of the TASK)

  • "NEXT":The ACTIVITY will be inserted after the current FORM (the one that is invoking the FORMULA ACTIVITY_INSERT() )

  • "LAST": The ACTIVITY will be inserted at the end of the TASK (last activity of the TASK)

Since API Version 2.7.26 it is possible to indicate a negative value, which is interpreted as the position counting backwards from the last existing FORM

insert_closed

Boolean

null

No

if 'YES' close the form after insert, otherwise keep it open (formula does not consider CLOSED property of workplan of the task) if there are PARAMETERS set, it can provoke form_close()

parameters

JSON

null

No

The parameter called parameters allows to provide a list of values that will be assigned to the ITEMS inserted

It must be a JSON string representing an array of objects with initial values that will be applied to the ITEMS of the ACTIVITIES. Each array item must be an object with 2 properties:

  • code: name of the DATA CODE to which the value will be assigned

  • value: value assigned

The values can be either  simple values or arrays.

The values assigned to each parameter will be stored in the newly created ACTIVITY into the ITEMS whose ITEM_CODE matches the property "code"

See the following examples:

Example of passing 2 parameters with simple values:

 

[ {"code":"PARAMETER.RELATIVE", "value":"RELATIVE.PARENT(M)"}, {"code":"PARAMETER.DIAGNOSE.ICD10", "value":"H60.20"} ]

 

  • The ITEM with ITEM_CODE = "PARAMETER.RELATIVE" will be assigned the value "RELATIVE.PARENT(M)"

  • The ITEM with ITEM_CODE = "PARAMETER.DIAGNOSE.ICD10" will be assigned the value "H60.20"

Note that if the TEMPLATE of the new ACTIVITY does not contain an ITEM with a ITEM_CODE named as any of the parameters provided, then a new ITEM will be created (hidden)

Example of passing 2 parameters with array values:

[ {"code":"HEART_RATE", "value":[87, 97]}, {"code":"HEART_RATE_TIME", "value":["12:00:00","16:00:00"]} ]

 

  • An array of ITEMs with ITEM_CODE = "HEART_RATE" will be created, the ITEM in row 1 will be assigned with the value 87, and the ITEM in row 2 will be assigned with the value 97

  • An array of ITEMs with ITEM_CODE = "HEART_RATE_TIME" will be created, the ITEM in row 1 will be assigned with the value "12:00:00", and the ITEM in row 2 will be assigned with the value "16:00:00"

If the TEMPLATE of the new ACTIVITY already contains an array of ITEM with ITEM_CODE that match the parameter names, then the necessary rows will be added to fit as many values as provided.

Otherwise, a new array of ITEMs will be created (hidden) for each parameter with multiple values

 

Output

As a result of an ACTIVITY_INSERT () formula the "ANSWER" property of the QUESTION will be a reference to the FORM or the REPORT created by the formula.

Execution

on form close (by default)

Examples

Formula

Description

Formula

Description

ACTIVITY_INSERT("F3", , $1)

Conditioned insert: Inserts a an activity (the one with TASK_CODE="F3" in the PROGRAM TEMPLATE) into the current TASK if the reference $1 is equal to 1 or true 

ACTIVITY_INSERT("F3", "SPIRO_TASK", 1, "FIRST")

Inserts a an activity (the one with TASK_CODE="F3" in the PROGRAM TEMPLATE) into the task with task code SPIRO_TASK. The inserted ACTIVITY will be placed the first into the TASK

ACTIVITY_INSERT("F3", "SPIRO_TASK", 1, "FIRST", 1)

Inserts a an activity (the one with TASK_CODE="F3" in the PROGRAM TEMPLATE) into the task with task code SPIRO_TASK. The inserted ACTIVITY will be placed the first into the TASK and will be closed via form_close

ACTIVITY_INSERT("SPIRO.TECHASS.PBD","SPIRO.TECHASS.BAS",1,,,[{"code":"TECHASSCOMM1", "value":"GET_VALUE(TASK, TIME, SCHEDULED)"}, {"code":"TECHASSQP1", "value":"$3"}])

generates an activity with task_code SPIRO.TECHASS.PBD in the task with task code SPIRO.TECHASS.BAS and inserts in created form questions with ITEM_CODE = TECHASSCOMM1 and value = result of formula GET_VALUE (TASK, TIME, SCHEDULED), ITEM_CODE = TECHASSQP1  and value with answer of reference question with id = 3 of form where the formula ACTIVITY_INSERT was executed



 

Related content