BranchingLogic–How-ToGuide4/17/2017 1
BranchingLogicinREDCap–How-ToGuideThisguidedescribeshowtoformatandapplybranchinglogic,alsoknownasskiplogic,toquestionsusingtheOnlineDesignermethodtobuildadatabaseinREDCap.Branchinglogiccanbeascomplexasyouneedittobe,withmanylayersoflogic.Whatisbranchinglogic?BranchingLogic,alsoknownasskiplogic,maybeemployedwhenfieldsinthedatabaseneedtobehiddenduringcertaincircumstances.Forexample,itmaybebesttohidefieldsrelatedtopregnancyifthesubjectinthedatabaseismale.IfyouwishtomakeafieldvisibleONLYwhenthevaluesofotherfieldsmeetcertainconditions(andkeepitinvisibleotherwise),youmayprovidetheseconditionsintheBranchingLogicsectionintheOnlineDesigner,shownbythedoublegreenarrowicon.Forbasicbranching,youcansimplydraganddropfieldnamesasneededintheBranchingLogicdialogboxintheOnlineDesigner.Ifyourbranchinglogicismorecomplex,youwillcreateequationsusingthesyntaxdescribedbelow.Intheequationyoumustusetheprojectvariablenamessurroundedby[]brackets.Youmayusemathematicaloperators(=,<,>,<=,>=,<>)andBooleanlogic(and/or).Youmaynestwithinmanyparentheticallevelsformorecomplexlogic.YoumustALWAYSputsingleordoublequotesaroundthevaluesintheequationUNLESSyouareusing>or<withnumericalvalues(i.e.,height,weight,BMI–textfieldsvalidatedasanumber).Example:[weight]>80(thesubject’sweightisgreaterthan80kg)ThefieldforwhichyouareconstructingtheBranchingLogicwillONLYbedisplayedwhenitsequationhasbeenevaluatedasTRUE.Pleasenotethatforitemsthatarecodednumerically,suchasdropdownsandradiobuttons,youwillneedtoprovidethecodednumericalvalueintheequation(ratherthanthedisplayedtextlabel).Seetheexamplesbelow.[sex]="0" Displayquestionifsex=female(Femaleiscodedas0)
[sex]="0"and[given_birth]="1"
Displayquestionifsex=female(Femalecodedas0)andgivenbirth=yes(Yesiscodedas1)
([height]>=170or[weight]<65)and[sex]="1"
Displayquestionif(heightisgreaterthanorequalto170ORweightislessthan65)ANDsex=male(Maleiscodedas1)
[last_name]<>"" Displayquestioniflastnameisnotblank(iflastnamefieldhasdata)
[visit_date]=”” Displayquestionifvisitdateisblank(ifvisitdatehasnodata)
[race]=“88” Displayquestionifrace=other(Othercodedas88)
[race(88)]=“1” Displayquestionif‘Otherrace’ischecked(Checkboxfieldtype)
BranchingLogic–How-ToGuide4/17/2017 2
Whenyouclickonthegreendoublearrowicon,youwillbetakentothescreenbelow.Itisherethatyouwillformatthebranching/skiplogic.
Isitpossibletousebranchinglogictoskipanentiresection?No,branchinglogicmustbeappliedtoeachfield.Itcannotbeappliedattheformorsectionlevel.Sectionheaderswillbehiddenonlyifallfieldsinthatsectionarehidden.Isitpossibletousebranchinglogictoskipanentireformorforms?Branchinglogicwillonlyhidequestions,notentiredatacollectioninstruments.Ifyouhavealist
BranchingLogic–How-ToGuide4/17/2017 3
ofdatacollectioninstruments(DCIs)inaproject(traditional)orevent(longitudinal),youwillseeeveryformevenifyouhideallthefieldswithbranchinglogiconthatform.You'llhavetoclickthroughtheformsor"Save&GotoNextForm."Aworkaroundmaybetoaddadescriptivetext(reversebranchinglogictoshowwhenallfieldsarehidden)thattheformisnotapplicabletothatspecificrecordorjustleavetheformblank.CanfieldsfromdifferentEVENTSbeusedinbranchinglogic(longitudinalonly)?Yes,forlongitudinalprojects(i.e.withmultipleeventsdefined),branchinglogicmayutilizefieldsfromotherevents(i.e.visits,time-points).Thebranchinglogicformatissomewhatdifferentfromthenormalformatbecausetheuniqueeventnamemustbespecifiedinthelogicforthetargetevent.Theuniqueeventnamemustbeprepended(insquarebrackets)tothebeginningofthevariablename(insquarebrackets),i.e.[unique_event_name][variable_name].Uniqueeventnamescanbefoundlistedontheproject'sDefineMyEvent'spageontheright-handsideoftheeventstable,inwhichtheuniquenameisautomaticallygeneratedfromtheeventnamethatyouhavedefined(seebelow).
(ProjectSetuppage)
(DefineMyEventspage)
Forexample,ifthefirsteventintheprojectisnamed"Enrollment",inwhichtheuniqueeventnameforitis"enrollment_arm_1",thenwecansetupthebranchinglogicutilizingthe"weight"fieldfromtheEnrollmentevent:([enrollment_arm_1][weight]/[visit_weight]>1).Thus,presumingthatthisfieldexistsonaformthatisutilizedonmultipleevents,itwillalways
BranchingLogic–How-ToGuide4/17/2017 4
performthebranchinglogicusingthevalueofweightfromtheEnrollmenteventwhileusingthevalueof[visit_weight]forthecurrenteventtheuserison.Isbranchinglogicforcheckboxesdifferent?Yes,specialformattingisneededforthebranchinglogicsyntaxin'checkbox'fieldtypes.Forcheckboxes,simplyaddthecodednumericalvalueinside()parenthesesafterthevariablename:[variablename(code)]Tocheckthevalueofthecheckboxes:'1'=checked'0'=uncheckedSeetheexamplesbelow,inwhichthe'race'fieldhastwooptionscodedas'2'(Asian)and'4'(Caucasian):[race(2)]="1" DisplayquestionifAsianischecked
[race(4)]="0" DisplayquestionifCaucasianisunchecked
[height]>=170and([race(2)]="1"or[race(4)]="1")
Displayquestionifheightisgreaterthanorequalto170ANDAsianORCaucasianischecked
AddingBranchingLogicUsingtheOnlineDesignerForbasicbranching,youcansimplydraganddropfieldnamesasneededintheBranchingLogicdialogboxintheOnlineDesigner.Ifyourbranchinglogicismorecomplex,youwillcreateequationsusingthesyntaxdescribedbelow.Intheequationyoumustusetheprojectvariablenamessurroundedby[]brackets.Youmayusemathematicaloperators(=,<,>,<=,>=,<>)andBooleanlogic(and/or).Youmaynestwithinmanyparentheticallevelsformorecomplexlogic.YoumustALWAYSputsingleordoublequotesaroundthevaluesintheequationUNLESSyouareusing>or<withnumericalvalues.Makesuretheparentheses()areusedcorrectlytobundleconditionstogether:
([gender]=‘1’and([age]>10and[age]<50))or([gender]=‘2’and([age]>14and[age]<55))
BranchingLogic–How-ToGuide4/17/2017 5
Intheexamplebelow,Iwanttoaddbranchinglogictothe“Morethanoncerace/Otherrace–specify:”questionsothatitonlyappearsifsomeoneselects“Morethanonerace/Otherrace(specifybelow).”Toaddbranchinglogic,clickonthedoublegreenarrowabovethequestionyouwanttoaddlogicto.Thelogicgetsappliedtothefieldyouwanttohide(“Morethanonerace…”),notthe‘parent’field(“Race”).Therearetwomethodsofapplyingbranchinglogictoquestions,theAdvancedBranchingLogicSyntaxandtheDrag-N-DropLogicBuilder.YouwouldusetheAdvancedBranchingLogicSyntaxformorecomplexbranchinglogic(i.e.,>=,<=,<>””,=””)andtheDrag-N-DropLogicBuilderforsimplebranchinglogic(i.e.,and/or,=).Evenifusingtheadvancedmethod,itcanbehelpfultodragthedatafieldsyouwanttouseintothe“ShowthefieldONLYif…”boxandthenformatthelogicintheAdvancedsection.
BranchingLogic–How-ToGuide4/17/2017 6
(Add/EditBranchingLogicpage)
Intheexampleabove,the[race_other]fieldwillonlyappearif[demo_race]=‘88’isselected(‘88’=“Morethanonerace/Otherrace”).ShowthefieldONLYif…“ALLbelowaretrue”–EVERYfieldinthesyntaxmustbetruetoshowthefield.Forexample,ifyouwantedafieldtoshowupthesubjectisFemale([gender]=‘1’)ANDtheyaremorethan10yearsold([age]–textfieldvalidatedasanumber),thebranchinglogicwouldbe:[gender]=‘1’and[age]>10ifyouwantedafieldtoshowupthesubjectisFemale([gender]=‘1’)ANDtheyaremorethan10yearsoldANDlessthan50yearsold([age]),thebranchinglogicwouldbe:
BranchingLogic–How-ToGuide4/17/2017 7
[gender]=‘1’and([age]>10and[age]<50)(seeexamplebelow)
(Inthisexample,IdraggedoverthegenderandagefieldssoIcanformatthemusingAdvancedlogic.)
(Ithenformattedthelogicintheadvancedlogicsyntaxbox)
BranchingLogic–How-ToGuide4/17/2017 8
“ANYbelowaretrue”–onlyONEfieldinthesyntaxneedstobetruetoshowthefield.Forexample,ifyouwantedafieldtoshowupifthesubjectisFemale([gender]=‘1’)ORifthesubjectisAfrican-American([race]=‘2’),thelogicwouldbe:[gender]=‘1’or[race]=‘2’(seeexamplebelow)
BranchingLogicTipsYoucanuse<,>,<=,>=symbolstomakebranchinglogicsimplerformultiplechoicefields.Forexample,ifyouwantasecondfieldtoappearifsomeoneselectsanswers1-4butnot5or6forthevariablecalled[question].1,Red2,Orange3,Yellow4,Green
Showthefield
BranchingLogic–How-ToGuide4/17/2017 9
5,Blue6,PurpleYoucanformatthebranchinglogictobe:Showfieldif:[question]<5(theanswervalueof[question]islessthan5)---versus---Showfieldif:[question]=‘1’or[question]=‘2’or[question]=‘3’or[question]=‘4’Whenyouhavealistoffields,suchasmedicationswheresomeonemaybeonupto10medications,butyoudonotwantall10entriestoappearonthepage,justtheonesthatwillhavedata,youcanusethe<>””operatortoformatthis.Fields Branchinglogic–showfieldif:Medication1NameMedication2Name [med1]<>””(medication1isnotblank) Medication3Name [med2]<>””(medication2isnotblank)Medication4Name [med3]<>””(medication3isnotblank)Medication5Name [med4]<>””(medication4isnotblank)Medication6Name [med5]<>””(medication5isnotblank)Medication7Name [med6]<>””(medication6isnotblank)Medication8Name [med7]<>””(medication7isnotblank)Medication9Name [med8]<>””(medication8isnotblank)Medication10Name [med9]<>””(medication9isnotblank)
Hidethefield
Top Related