Example: If your study has a number of questions that could only be answered after a child was born, you may wish to define branching logic based on the date of birth or the expected delivery date. The branching logic could be defined a couple of different ways. This first method is more complicated and uses calculations. Thus the second method is preferred. Both are shown for your benefit.
Method 1 - Branching Logic based on a calculated field:
One way to define branching logic is to use the results of a calculated field as the trigger to display the conditional field. For example, a calculated field could be created that displays the number of days since the birth of a child. That field could also display negative values as the number of days in the future until the delivery of the child. The date, calculated field and the field with the associated branching logic could be built similar to the following:
The formula for the calculated field "Days Until / Since Birth" would be as follows:
Calculated Field Formula "days_birth"
datediff([child_dob], "today", "d", "mdy", true)
Branching logic on the "Weight" field would be based on the results of the above calculated field "Days Until / Since Birth". For example, the branching logic could be defined as follows:
Branching Logic Formula
([dob_days] >= 0) and ([child_dob] <> "")
The second half of the "and" expression specifies that the date of birth field must not be blank. This will guarantee that the branching logic will not take place until a date of birth is entered.
In this first example below, the child is not to be born until tomorrow, so the calculated "Days Until Birth" is displayed, but the weight field does not show:
In this second example, the child is 3 days old, so the branching logic formula permits the weight field to be displayed:
Method 2 - Embed the datediff function into the branching logic
Alternatively, the "datediff" function could be embedded directly into the branching logic so a calculated field would not be necessary. The date and associated field with branching logic could be built similar to the following:
Branching Logic Function
( datediff( [child_dob], "today", "d", "dmy", true ) >= 0 ) and ( [dob] <> "" )
Again, the second part of the "and" expression specifies that the date of birth field must not be blank. This will assure that the branching logic will not take place unless a date of birth is specified.