Previous Topic

Next Topic

Book Contents

Book Index

Calculation rules

Calculation rules

Characteristic

Description

Definition

A calculation rule sets the value of an item based on a calculation.

Note: There is no real difference between a calculation rule and a constraint rule. Each offers different starting points in the Rule Wizard; the options on the Actions tab change depending on the rule type that you select.

Study objects that can have calculation rules

  • Study designs
  • Study elements
  • Study events
  • Forms
  • Items

Programming experience necessary

Creating a calculation rule is comparable to writing formulas in the Microsoft Excel spreadsheet software.

What to define

You must define:

  • When to evaluate the rule.
  • The rule expression.

    For calculation and constraint rules, you can use the following to define the rule expression:

    • Study objects and their rule model properties.
    • Functions. If you use a function, you define values for its parameters using numeric values, values of study objects and their rule model properties, constants, and data mapping study objects and their rule model properties.
    • Constants.
    • Data mapping study objects and their rule model properties.
  • The action to take after the rule executes.

Example

(without a function)

A calculation rule calculates BMI using height and weight values with RefNames of HT and WT. You create the rule on the form that contains the items.

You provide the following information to create the rule:

  • When to evaluate the rule—On form submission.
  • The rule expression—The rule expression divides the weight value by the height value squared.
  • The action to take after the rule executes—The rule calculates BMI and stores the value in the BMI field.

The following information appears in the Rule Summary section:

 evaluate on Form Submission
 value = this.WT.Value / (this.HT.Value * this.HT.Value)
 always
     set this.BMI.Value = value

You could create the rule with a function, as described in the next example.

Example

(with a function)

A calculation rule uses a function (_BMI) to calculate BMI from height and weight values with RefNames of HT and WT. You create the rule on the form that contains the items.

A programmer creates the function, and a non-programmer provides the following information to create the rule:

  • When to evaluate the rule—On form submission.
  • The rule expression—After you drag the function to the Expression workspace, the Invoke Function dialog box appears, and you can provide values for the parameters. In this case, you provide the weight and height items as parameters.
  • The action to take after the rule executes—The rule calculates BMI and stores the value in the BMI field.

The following information appears in the Rule Summary section:

 evaluate on Form Submission
 value = _BMI(this.HT.Value,this.WT.Value)
 always
     set this.BMI.Value = value

You could create the rule without a function, as described in the previous example.

Copyright © 2013 Oracle and/or its affiliates. All rights reserved.