Conditions in rosters

Overview of conditions

Conditions outside rosters

Conditions in rosters

Conditions in rosters

Conditions in rosters

Conditions in rosters

Conditions in row

Enabling roster row based on attribute

  • Take all members
  • Show only those age >= 15

Enabling roster row based on attribute

  • Click on roster
  • Add enablement condition to roster
  • Craft a condition that enables/disables based on attributes

Enabling based on row number

  • Capture description of program for "Other (specify)" (96)
  • Otherwise, no

Enabling based on row number

  • Click on roster
  • Add enablement condition to roster
  • Craft a condition based on @rowcode

Conditions across rows

General syntax

name_of_roster.Query(x=>x.var_to_query==1)

Item Explanation
name_of_roster Name of the collection to query
Query Query operator
x Anonymous variable that captures the queried content
x.var_to_query Query variable(s); instance of that (those) variable(s)

Common queries

  • Explanation: At least one element of the collection meets the query criteria.
  • Result: true/false.
// check whether there is any member designated as head
members.Any(x=>x.relationship == 1)

/*

Unpacking the expression above

  • members : roster ID for the target roster
  • x : anonymous variable to capture query results
  • x.relationship : query variable relationship in the roster
  • Explanation: All elements of the collection meet the query criteria
  • Result: true/false.

// all household members have a relationship to the head
// that is, the relationship variable is not `null`
members.All(x=>x.relationship != null)

NOTE: this is often a pre-condition for a condition.

See the full example in “Case 2” here

  • Explanation. Count the number of elements that meet the criteria
  • Result. Count.
// number of members designated as household head
members.Count(x=>x.relationship == 1)

Number teas drunk

  • Find teas roster
  • Find question about whether drank yesterday
  • Compose condition about whether any tea drunk yesterday

No more than one head

  • If member is head, confirm count of heads == 1
  • Otherwise, OK

Age of child relative to head

  • Case 1: if head, then no child w/ age diff < 13
  • Case 2: if child, then no head w/ age diff < 13
  • Case 3: if neither head nor child, OK

Age of child relative to head

/* 
CONFIRM THAT THE AGE DIFFERENCE
BETWEEN THE HEAD AND CHILD IS APPROPRIATE
*/

// case 1: if head, no child in the roster whose age difference is too small
s01q03 == 1 ? !members.Any(x=>x.s01q03==3 && (s01q04_years - x.s01q04_years) < 13) :

// case 2: if child, no head whose age diffference is too small
s01q03 == 3 ? !members.Any(x=>x.s01q03==1 && (x.s01q04_years - s01q04_years) < 13) :

// case 3: if neither head nor child, OK
true

Unpacking the code

  • Ternary operator (?:)
    • Before ? ~= if
    • Between ? and : ~= then
    • After : ~= else
  • !Any() == none
  • Variables with and without x. prefix
    • Without: current row (e.g. s01q03 == 1)
    • With: query target