Families and Households

We currently have a straightforward script, relating to one person. Often applications need more information about the client's circumstance, starting with their living situation.

In general, information is requested about the primary person and this is followed by a simple question that will allow the client to skip to another area of the application. For example, after entering personal details, the client is asked 'Do you live alone?'. If the answer is yes then the person can be treated as single individual who is not living within a household of family or other individuals. Most clients want to get through the application process as quickly as possible, therefore questions such as these provide a good way to move to more relevant parts of the application.

If the client is living with other people, then questions about each person may need to be asked. Loops are used to capture information from each person and depending on how the script author wants to present these questions, they have a choice of loop types: for, while and for-each loop.

IEG also features a Person Tab that allows the client to see who these questions relate to while entering the data. This will appear automatically for a Person entity in the Datastore. Each Person will be represented by an icon (based on the gender and age) and a name. The current Person will be highlighted.

Let's take a scenario for handling family/household data as an extension of the requirements in the basic sample. Here the client is asked if how many people are in the household including the client. Some new question pages need to be added to capture this information.

The first question page will ask about the living situation. For this example there is only one question to ask, as follows: How many people are in the family (excluding yourself)?

Figure 1. Obtaining household size
<question-page id="HouseholdPage" progress="10">
    <title id="LoopControlPage.Title">
        <![CDATA[Household Details]]>
    </title>
    <description id="LoopControlPage.Description">
        <![CDATA[Please tell us some information about your
        household]]>
    </description>
    <icon image="sample_title_household" />
    <cluster>
        <title id="DetailsCluster.Title">
            <![CDATA[Details]]>
        </title>
        <question id="numPeople" control-question="true" 
            control-question-type="IEG_INT32" 
            mandatory="true">
            <label id="NumPeople.Label">
                <![CDATA[How many other people are in your
                household?]]>
            </label>
        </question>
    </cluster>
</question-page>

This question is a control question, i.e. a question used to control the size of a loop and not for data collection purposes. Control questions are not stored in the Datastore schema. It will used in the loop expression of the 'for' loop in the next question page.

The family members question page is within a 'for' loop that will iterate over the number of family members.

Figure 2. Using 'for' loop to collect household members
<loop loop-type="for" loop-expression="numPeople" 
    entity="Person" criteria="isPrimary==false">
    <question-page id="PersonDetailsPage" 
        show-person-tabs="true" 
        progress="20">
        <title id="PersonDetailsPage.Title">
            <![CDATA[Household Member Details]]>
        </title>
        <description id="PersonDetailsPage.Description">
            <![CDATA[Please enter the details for the
                next person in your household]]>
        </description>
        <icon image="sample_title_household" />
        <cluster>
            <title id="DetailsCluster.Title">
                <![CDATA[Person Details]]>
            </title>
            <description id="DetailsCluster.Description">
                <![CDATA[Enter the details for this person
                below]]>
            </description>
            <question id="firstName" mandatory="true">
                <label id="FirstName.Label">
                    <![CDATA[First Name:]]>
                </label>
            </question>
            <question id="lastName">
                <label id="lastName.Label">
                    <![CDATA[Last Name:]]>
                </label>
            </question>
            <question id="gender" mandatory="true">
                <label id="Gender.Label">
                    <![CDATA[Gender:]]>
                </label>
            </question>
        </cluster>
    </question-page>
</loop>

The above is an example of how the client enters the number of family members. But the question could have been asked a different way, for example: 'Do you live with your family?' In this case a condition element in the script can be used to check the value of that question. This would display the family member page if they do live with their family. On this question page, a control question is asked to determine if they would like to capture another family member's details.

This control question would be used in a 'while' loop around the family member question page, as follows:

Figure 3. Using 'while' loop to collect household members
<question-page id="HouseholdPage" progress="10">
    <title id="LoopControlPage.Title">
        <![CDATA[Household Details]]>
    </title>
    <description id="LoopControlPage.Description">
        <![CDATA[Please tell us some information about your
        household]]>
    </description>
    <icon image="sample_title_household" />
    <cluster>
        <title id="DetailsCluster.Title">
            <![CDATA[Details]]>
        </title>
        <question id="livesWithFamily" control-question="true" 
            control-question-type="IEG_BOOLEAN" 
            mandatory="true">
            <label id="NumPeople.Label">
                <![CDATA[Do you live with your family?]]>
            </label>
        </question>
    </cluster>
</question-page>

Using this approach, the control question is a boolean type, as it is used in a condition expression that indicates whether or not the while loop should be entered. The loop, once entered, is iterated over until details of all the household members have been gathered, as follows:

Figure 4. Using while loop to collect household members
<condition expression="livesWithFamily==true">
  <loop loop-type="while" loop-expression="
    anotherMember==true" 
    entity="Person">
      <question-page id="PersonDetailsPage" 
       show-person-tabs="true"
         progress="20">
           <title id="PersonDetailsPage.Title">
               <![CDATA[Household Member Details]]>
           </title>
           <description id="PersonDetailsPage.Description">
               <![CDATA[Please enter the details for 
                 the next person in your household]]>
           </description>
           <icon image="sample_title_household" />
           <cluster>
               <title id="DetailsCluster.Title">
                   <![CDATA[Person Details]]>
               </title>
               <description id="DetailsCluster.Description">
                   <![CDATA[Enter the details for this 
                   person below]]>
               </description>
           <question id="firstName" mandatory="true">
               <label id="FirstName.Label">
                   <![CDATA[First Name:]]>
               </label>
           </question>
           <question id="lastName">
               <label id="lastName.Label">
                   <![CDATA[Last Name:]]>
               </label>
           </question>
           <question id="gender" mandatory="true">
               <label id="Gender.Label">
                   <![CDATA[Gender:]]>
               </label>
           </question>
           </cluster>
           <cluster>
               <question id="anotherMember" 
               control-question="true" 
                 control-question-type="IEG_BOOLEAN">
                   <label id="AnotherMember.Label">
                       <![CDATA[Is there another 
                       household member?]]>
                   </label>
               </question>
           </cluster>
      </question-page>
  </loop>
</condition>