The following examples will demonstrate how to use both the equal (eq) and the not equal () operators with the following data types:

  • INT
  • REAL
  • DATE
  • ST
  • FILE

Example 1

The first example will demonstrate how to specify a temperature is not equal to a particular negative value.  The data type is INT so no decimal places are allowed.

    <RuleDef OID=”RULE1″ Name=”This is an example”>
        <Description>The temperature is not equal to -10 degrees F</Description>
        <Expression>ITEM_OID ne (-10)</Expression>

Please be aware of the use of parentheses around the negative value.  This is how you must write your RuleExpression if you want to evaluate negative values enterd as data in the CRF.  If the DataType was REAL, decimal places would be allowed.

Also, if the field was a ST, quotes (“”) must surround the string value.  If these are not present, the RuleExpression will not evaluate correctly.

Example 2

The second example is similar, but it is stating that a value for one item is equal to the value for one item, or not equal to a value from a third item.  The second item is part of the same CRF Version as the first item, but the third item is in a different event CRF.  If you compare two fields together, they must be of the same DataType.  If the third item is comparing an explicit value, it does not have to be the same DataType

    <RuleDef OID=”RULE2″ Name=”This is an example”>
        <Description>Temperature is different and the color of the sun is yellow</Description>
        <Expression>SED_OID.CRF_OID.GROUP_OID._ITEM_OID_3 eq “yellow” or CRF_VERSION_OID.GROUP_OID.ITEM_OID_2 ne ITEM_OID_1</Expression>

As you can see, the path will continue to grow to the left if you have to include the CRF or CRF Version, or the Study Event Definition.  Each piece of the path is separated with a period (.) and everything must be capitalized.

Example 3

The following example uses DATEs with the equal and not equal operators.  The same principle applies where the system can only compare items of the same DataType.

    <RuleDef OID=”RULE3″ Name=”This is an example”>
        <Description>Visit Date is the same as today’s date</Description>
        <Expression>ITEM_OID_1 eq _CURRENT_DATE</Expression>

_CURRENT_DATE is a system level property that will pull the “today’s date” from the server OpenClinica is installed on.

    <RuleDef OID=”RULE4″ Name=”This is an example”>
        <Description>The date is not December 31, 2012r</Description>
        <Expression>ITEM_OID_1 ne 2012-12-31</Expression>

Notice the date must be in the ISO 8601 format otherwise the system will reject the RuleExpression.

Example 4

When an item is defined as a FILE DataType, you can write rules to make sure the field is either blank, or not blank.  You will not be able to write any rules comparing files or saying files are equal to each other.  An example of a correct RuleExpression would be:

    <RuleDef OID=”RULE5″ Name=”This is an example”>
        <Description>no file is provided</Description>
        <Expression>ITEM_OID_1 eq “”</Expression>

“” next to each other in a RuleExpression signifies a blank field for all DataTypes.

As we go through the rest of the operators, we will also demonstrate how to combine multiple operators into a RuleExpression which should provide even greater clarity on how to use Rules.