JavaScript Actions

The action JavaScript function allows you to perform complex actions that are not possible by using standard actions. The target operand is set to the value returned by a JavaScript function you write. The function takes auxiliary operands in the form of parameters.

Adding an Action JavaScript Function

To set up an action JavaScript function:

  1. Enter the type and value of the target operand.
  2. Select the Using JavaScript operator to display the Action JavaScript form:

  3. Enter a description of what the function does in the Description field.
  4. Add the parameters that are to be passed into your JavaScript function. For each one add:

    Parameter Attribute

    Description

    Parameter Name

    A user-defined name for the parameter.

    For symbols and keywords that are not permitted by JavaScript for parameter names, refer to JavaScript Naming Rules for details.

    Parameter Value

    The auxiliary operand the parameter is set to.

  5. Write the JavaScript function in the function code text box.

    Refer to Writing Action JavaScript Functions for details.

  6. Click the OK link to save your changes or the Cancel link to discard them.

Writing Action JavaScript Functions

Action JavaScript functions are of the form:

function action(parameter_1, parameter_2,..., parameter_n) {
    <expression_1>;
    <expression_2>;
    ...
    <expression_n>;
    
    return (value);
}

It must return a value:

  • If a string value is returned, then it is used directly.
  • If a boolean value is returned, then it is converted to a string of true or false. No translation is performed here.
  • If a number value is returned, then it is converted to a string using the default numerical formatter on the system. If custom formatting is required, then this should be done in the JavaScript code and a string value returned instead.
  • If null is returned, then it is treated as an empty string.
  • Any other return value (including undefined) is treated as a fatal error.

JavaScript Conditions

The conditional JavaScript function allow you to create complex conditions that are not possible by using standard conditions. The function takes subject and object operands in the form of parameters and returns a boolean value.

Adding a Conditional JavaScript Function

To set up a conditional JavaScript function:

  1. Select JavaScript in the subject operand drop-down list to display the Conditional JavaScript form:

  2. Enter a description of what the function does in the Description field.
  3. Add the parameters that are to be passed into your JavaScript function. For each one populate the following fields:

    Parameter Attribute

    Description

    Parameter Name

    A user-defined name for the parameter.

    For symbols and keywords that are not permitted by JavaScript for parameter names, refer to JavaScript Naming Rules for details.

    Parameter Value

    The subject or object operand the parameter is set to.

  4. Write the JavaScript function in the function code text box.

  5. Click the OK link to save your changes or the Cancel link to discard them.

Writing Conditional JavaScript Functions

Conditional JavaScript functions are of the form:

function action(parameter_1, parameter_2,..., parameter_n) {
    if {
        <expression_1>;
        <expression_2>;
        ...
        <expression_n>;
    
        return (value);
    }
}

They must return a boolean value:

  • If a boolean value is returned, then it is used directly.
  • If a number is returned, then it is treated as false if zero and true if non-zero.
  • Any other return value (including null and undefined) is treated as a fatal error.

JavaScript Objects

The HL7 Message Modifier filter provides the pre-defined JavaScript object separators  which returns the value of a separator in MSH.2. It has the following properties:

  • separators.field returns the field separator.
  • separators.component returns the component separator.
  • separators.subcomponent returns the subcomponent separator.

For example:

return 'a' + separators.component + 'b1' + separators.subcomponent + 'b2';

returns a^b1&b2 when the default separators are being used in the message.

If you are modifying a segment that is not an MSH segment, then the default separators are displayed in the Result Panel. To preview the correct separators used in the sample message, refer to the Sample Result Panel in the segment's change group or the All Changes.

You can also use the global JavaScript object  dateChangeFormat  to transform date-time formats. Refer to  Global Functions  for details.

JavaScript Naming Rules

The following characters and words are not permitted for parameter names in JavaScript:

Prohibited Characters

The following characters in a parameter name render it invalid and are therefore prohibited:

  • Non-printable characters.
  • Whitespace.
  • JavaScript operators (for example, -, +, *, /, %, \, (, ), [, ], etc.).

Global Variables

The following global variables cannot be used as parameter names:

  • NaN.
  • infinity.
  • undefined.

Reserved Words

arguments

break

case
catch
class
const
continue

dateChangeFormat
debugger
default
delete
do

else
enum
eval
export
extends

false
finally
for
function

if
implements
import
in
instanceof
interface

let

new
null

package
private
protected
public

return

separators
static
super
switch

this
throw
true
try
typeof

var
void

while
with

yield

JavaScript Errors

Refer to Error Handling for details.

Additional Information