redcap

REDCap accepts only single conditional @HIDECHOICE


I'm using the following action tags in a single-answer multiple choice question to hide choices if certain conditions aren't met in a prior matrix question:

@IF([med_1]<>'3', @HIDECHOICE='1','')
@IF([med_2]<>'3', @HIDECHOICE='2','')
@IF([med_3]<>'3', @HIDECHOICE='3','')

It seems that only one of the @HIDECHOICE options is honored even when the conditions for all of them are met. E.g, if the answers for med_1, med_2, and med_3 are all unequal to 3, only choice 1 for the present question is hidden. Is there a way to set up independent display logic for each choice?


Solution

  • You're quite right. Only the first @HIDECHOICE in a field is honoured. If there are multiple @HIDECHOICE action tags in various @IF() action tags, then only the first @HIDECHOICE that is encountered that is honoured. So in your case, if [med_1] = 3 an [med_2] = 1, then choice 2 would be hidden. The value of [med_3] is irrelevant as that @HIDECHOICE will not be executed.

    You can pass multiple choices into a @HIDECHOICE though, with a comma-separated list, but as you can only reasonably use a single @HIDECHOICE, then you have to construct some pretty gnarly logic. With three variables to test in a binary sense, you have 2**3 terms to evaluate (minus 1, since you don't need a @HIDECHOICE where all three are equal to 3):

    @IF([med_1]<>'3' AND [med_2]<>'3' AND [med_3]<>'3', @HIDECHOICE='1,2,3','')
    @IF([med_1]<>'3' AND [med_2]='3' AND [med_3]<>'3', @HIDECHOICE='1,3','')
    @IF([med_1]<>'3' AND [med_2]<>'3' AND [med_3]='3', @HIDECHOICE='1,2','')
    @IF([med_1]='3' AND [med_2]<>'3' AND [med_3]<>'3', @HIDECHOICE='2,3','')
    @IF([med_1]<>'3' AND [med_2]='3' AND [med_3]='3', @HIDECHOICE='1','')
    @IF([med_1]='3' AND [med_2]<>'3' AND [med_3]='3', @HIDECHOICE='2','')
    @IF([med_1]='3' AND [med_2]='3' AND [med_3]<>'3', @HIDECHOICE='3','')
    

    Adding more conditions will exponentially raise the burden.

    Unfortunately, @HIDECHOICE does not accept piping, otherwise you could use a @CALCTEXT field to generate the comma-separated list of choices to hide, say, [hidechoice], and then pipe it in with @HIDECHOICE='[hidechoice]'. This would turn an O(2^n) operation into an O(n) operation, but has not been implemented.