branching logic in redcap – how · 2018-12-04 · branching logic – how-to guide 4/17/2017 1...

9
Branching Logic – How-To Guide 4/17/2017 1 Branching Logic in REDCap – How-To Guide This guide describes how to format and apply branching logic, also known as skip logic, to questions using the Online Designer method to build a database in REDCap. Branching logic can be as complex as you need it to be, with many layers of logic. What is branching logic? Branching Logic, also known as skip logic, may be employed when fields in the database need to be hidden during certain circumstances. For example, it may be best to hide fields related to pregnancy if the subject in the database is male. If you wish to make a field visible ONLY when the values of other fields meet certain conditions (and keep it invisible otherwise), you may provide these conditions in the Branching Logic section in the Online Designer, shown by the double green arrow icon . For basic branching, you can simply drag and drop field names as needed in the Branching Logic dialog box in the Online Designer. If your branching logic is more complex, you will create equations using the syntax described below. In the equation you must use the project variable names surrounded by [ ] brackets. You may use mathematical operators (=, <, >, <=, >=, <>) and Boolean logic (and/or). You may nest within many parenthetical levels for more complex logic. You must ALWAYS put single or double quotes around the values in the equation UNLESS you are using > or < with numerical values (i.e., height, weight, BMI – text fields validated as a number). Example: [weight] > 80 (the subject’s weight is greater than 80 kg) The field for which you are constructing the Branching Logic will ONLY be displayed when its equation has been evaluated as TRUE. Please note that for items that are coded numerically, such as dropdowns and radio buttons, you will need to provide the coded numerical value in the equation (rather than the displayed text label). See the examples below. [sex] = "0" Display question if sex = female (Female is coded as 0) [sex] = "0" and [given_birth] = "1" Display question if sex = female (Female coded as 0) and given birth = yes (Yes is coded as 1) ([height] >= 170 or [weight] < 65) and [sex] = "1" Display question if (height is greater than or equal to 170 OR weight is less than 65) AND sex = male (Male is coded as 1) [last_name] <> "" Display question if last name is not blank (if last name field has data) [visit_date] =”” Display question if visit date is blank (if visit date has no data) [race] = “88” Display question if race = other (Other coded as 88) [race(88)] = “1” Display question if ‘Other race’ is checked (Checkbox field type)

Upload: others

Post on 11-Mar-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Branching Logic in REDCap – How · 2018-12-04 · Branching Logic – How-To Guide 4/17/2017 1 Branching Logic in REDCap – How-To Guide This guide describes how to format and

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)

Page 2: Branching Logic in REDCap – How · 2018-12-04 · Branching Logic – How-To Guide 4/17/2017 1 Branching Logic in REDCap – How-To Guide This guide describes how to format and

BranchingLogic–How-ToGuide4/17/2017 2

Whenyouclickonthegreendoublearrowicon,youwillbetakentothescreenbelow.Itisherethatyouwillformatthebranching/skiplogic.

Isitpossibletousebranchinglogictoskipanentiresection?No,branchinglogicmustbeappliedtoeachfield.Itcannotbeappliedattheformorsectionlevel.Sectionheaderswillbehiddenonlyifallfieldsinthatsectionarehidden.Isitpossibletousebranchinglogictoskipanentireformorforms?Branchinglogicwillonlyhidequestions,notentiredatacollectioninstruments.Ifyouhavealist

Page 3: Branching Logic in REDCap – How · 2018-12-04 · Branching Logic – How-To Guide 4/17/2017 1 Branching Logic in REDCap – How-To Guide This guide describes how to format and

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

Page 4: Branching Logic in REDCap – How · 2018-12-04 · Branching Logic – How-To Guide 4/17/2017 1 Branching Logic in REDCap – How-To Guide This guide describes how to format and

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))

Page 5: Branching Logic in REDCap – How · 2018-12-04 · Branching Logic – How-To Guide 4/17/2017 1 Branching Logic in REDCap – How-To Guide This guide describes how to format and

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.

Page 6: Branching Logic in REDCap – How · 2018-12-04 · Branching Logic – How-To Guide 4/17/2017 1 Branching Logic in REDCap – How-To Guide This guide describes how to format and

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:

Page 7: Branching Logic in REDCap – How · 2018-12-04 · Branching Logic – How-To Guide 4/17/2017 1 Branching Logic in REDCap – How-To Guide This guide describes how to format and

BranchingLogic–How-ToGuide4/17/2017 7

[gender]=‘1’and([age]>10and[age]<50)(seeexamplebelow)

(Inthisexample,IdraggedoverthegenderandagefieldssoIcanformatthemusingAdvancedlogic.)

(Ithenformattedthelogicintheadvancedlogicsyntaxbox)

Page 8: Branching Logic in REDCap – How · 2018-12-04 · Branching Logic – How-To Guide 4/17/2017 1 Branching Logic in REDCap – How-To Guide This guide describes how to format and

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

Page 9: Branching Logic in REDCap – How · 2018-12-04 · Branching Logic – How-To Guide 4/17/2017 1 Branching Logic in REDCap – How-To Guide This guide describes how to format and

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