Skip to content

Bespoke Background Information

Henry Mehta edited this page Feb 5, 2021 · 4 revisions

Bespoke Background Information Forms

Introduction

There is a standard background information form. This will not be discussed here, but there are times when this form is not appropriate so new functionality has been developed to allow different information to be gathered.

To use a bespoke background information form create a json file in webcdi > cdi_forms > form_data > background_info. The names of the files will be <instrument>.json. For example, if you want different background information to be collected for Dutch_WS studies the files will be call Dutch_WS.json.

There are 2 pages defined in the file, namely front and back. The front json file will be used to display background information form before completing the survey and the back file is used to gather more information once the survey is completed.

The basic structure of the file is:

Basic JSON Structure

[{
    "page" : "front",
    "help_text" : "Some useful html",
    "contents" : [{
        "fieldset" : "Title",
        "fields" : [{
            "field" : "field_name",
            "div" : ["list of fields", "which are shown if", "previous field_name is selected"] 
            },{
            "field" : field_name2"
            }]
     },{
         "fieldset" "Title 2",
             etc
     }]
},{
    "page" : "back",
    "contents" : [{
        "fieldset" : "Title3",
        "fields" : [{
            "field" : "field_name4",
            "div" : ["list of fields", "which are shown if", "previous field_name is selected"] 
            },{
            "field" : field_name5"
            }]
     },{
         "fieldset" "Title 6",
             etc
     }]
 }]
  1. "page" defines whether the following data is shown before or after the study questions
  2. "help_text" is html which will be shown at the top of the page to give extra instruction to participants
  3. "contents" holds the data to be displayed
  4. "fieldset" is a title with a number of fields within it.
  5. "fields" is a list for fields included within the fieldset section.
  6. "field" is the name of a field within the BackgroundInfo table in the database. If new fields are required they must be added to the database using makemigrations and migrate.
  7. "div" is a list of fields within the BackgroundInfo table in the database. When included in a div list like this they follow the validation code currently specified for the standard form. For example, if the child is born early/late, these radio buttons show and the number field shows when the yes selection is picked but don't if no or prefer not to say is selected

Choices

It is possible to limit/change the options available for certain fields. For example, the US annual incomes do not necessarily apply in other countries. You can change the choices available with the choices keyword. An example is shown below:

        {
            "field" : "annual_income",
            "widget_type" : "Select",
            "required" : "any string",
            "choices" : [
                {
                    "key" : "",
                    "value" : "--------"
                },{
                    "key" : "Low Income",
                    "value" : "< €15.000"
                },{
                    "key" : "Med-Low Income",
                    "value" : "€15.001-€30.000"
                },{
                    "key" : "Medium Income",
                    "value" : "€30.001-€60.000"
                },{
                    "key" : "Med-High Income",
                    "value" : "€60.001-€100.000"
                },{
                    "key" : "High Income",
                    "value" : "> €100.0001"
                }
            ]
        }

As this example shows, choices is a list of key, value pairs. The key is what will be stored within the database and the value is what will be shown to the user. The key must meet the current criteria for the database field. For example, the weight fields are float values so must be numbers, whereas ethnicity is a single character and must be a single character, while the annual_income field is a CharField(max_length=101) so can be a string up to 101 characters.

When choices is used, an optional widget_type field can be included. This specifies the type of Django widget that will be used on the field. If no widget_type is specified, Django will apply the standard form field for the database field type. Please note, this is not necessarily the field used in the standard form.

When required is include it makes the form field required (ie the participant must complete it). The field will default to not required if it is not included.

Adding Help text

We can add help text to a field with the keyword help. This will then display below the field exactly as shown. An example is given below

        {
            "field" : "father_education",
            "choices" : [
                {
                    "key" : "",
                    "value" : "--------"
                },{ 
                    "key" : "5",
                    "value" : "Level 1"
                },{ 
                    "key" : "6",
                    "value" : "Level 2"
                },{ 
                    "key" : "7",
                    "value" : "Level 3"
                },{ 
                    "key" : "8",
                    "value" : "Level 4"
                },{ 
                    "key" : "9",
                    "value" : "Level 5"
                },{ 
                    "key" : "10",
                    "value" : "Level 6"
                },{ 
                    "key" : "11",
                    "value" : "Level 7"
                },{ 
                    "key" : "12",
                    "value" : "Level 8"
                },{ 
                    "key" : "13",
                    "value" : "Level 9"
                }
            ],
            "help" : "Select level of education"
        }

Example Form

A complete example is given below. 2 forms are used. We gather the background information for Basic Information and Family Background before the survey and all other information after the survey. The fields and structure are almost exactly the same as the standard form, with a few values changed to demonstrate functionality.

instrument.json

[
    {
        "page":"back",
        "contents":[
            {
                "fieldset":"Basic Information",
                "fields":[
                    {
                        "field":"birth_order"
                    },
                    {
                        "field":"multi_birth_boolean",
                        "div":[
                            "multi_birth"
                        ]
                    },
                    {
                        "field":"birth_weight_lb",
                        "widget_type":"Select",
                        "choices":[
                            {
                                "key":"",
                                "value":"--------"
                            },
                            {
                                "key":"1.0",
                                "value":"Less than 3 lbs, 0 oz"
                            },
                            {
                                "key":"3.0",
                                "value":"3 lbs, 0 oz - 3 lbs, 7 oz"
                            },
                            {
                                "key":"3.5",
                                "value":"3 lbs, 8 oz - 3 lbs, 15 oz"
                            },
                            {
                                "key":"4.0",
                                "value":"4 lbs, 0 oz - 4 lbs, 7 oz"
                            },
                            {
                                "key":"4.5",
                                "value":"4 lbs, 8 oz - 4 lbs, 15 oz"
                            },
                            {
                                "key":"5.0",
                                "value":"5 lbs, 0 oz - 5 lbs, 7 oz"
                            },
                            {
                                "key":"5.5",
                                "value":"5 lbs, 8 oz - 5 lbs, 15 oz"
                            },
                            {
                                "key":"6.0",
                                "value":"6 lbs, 0 oz - 6 lbs, 7 oz"
                            },
                            {
                                "key":"6.5",
                                "value":"6 lbs, 8 oz - 6 lbs, 15 oz"
                            },
                            {
                                "key":"7.0",
                                "value":"7 lbs, 0 oz - 7 lbs, 7 oz"
                            },
                            {
                                "key":"7.5",
                                "value":"7 lbs, 8 oz - 7 lbs, 15 oz"
                            },
                            {
                                "key":"8.0",
                                "value":"8 lbs, 0 oz - 8 lbs, 7 oz"
                            },
                            {
                                "key":"8.5",
                                "value":"8 lbs, 8 oz - 8 lbs, 15 oz"
                            },
                            {
                                "key":"9.0",
                                "value":"9 lbs, 0 oz - 9 lbs, 7 oz"
                            },
                            {
                                "key":"9.5",
                                "value":"9 lbs, 8 oz - 9 lbs, 15 oz"
                            },
                            {
                                "key":"10.0",
                                "value":"10 lbs, 0 oz or more"
                            },
                            {
                                "key":"0.0",
                                "value":"Prefer not to disclose"
                            }
                        ]
                    },
                    {
                        "field":"born_on_due_date",
                        "div":[
                            "early_or_late",
                            "due_date_diff"
                        ]
                    }
                ]
            },
            {
                "fieldset":"Family Background",
                "fields":[
                    {
                        "field":"primary_caregiver",
                        "div":[
                            "primary_caregiver_other"
                        ]
                    },
                    {
                        "field":"mother_yob"
                    },
                    {
                        "field":"mother_education",
                        "help":"Choose highest grade completed (12 = high school graduate; 16 = college graduate; 18 = advanced degree)"
                    },
                    {
                        "field":"secondary_caregiver",
                        "div":[
                            "secondary_caregiver_other"
                        ]
                    },
                    {
                        "field":"father_yob"
                    },
                    {
                        "field":"father_education",
                        "help":"Choose highest grade completed (12 = high school graduate; 16 = college graduate; 18 = advanced degree)"
                    },
                    {
                        "field":"annual_income",
                        "widget_type":"Select",
                        "choices":[
                            {
                                "key":"",
                                "value":"--------"
                            },
                            {
                                "key":"<25000",
                                "value":"Under $25,000"
                            },
                            {
                                "key":"25000-50000",
                                "value":"$25,000-$50,000"
                            },
                            {
                                "key":"50000-75000",
                                "value":"$50,000-$75,000"
                            },
                            {
                                "key":"75000-100000",
                                "value":"$75,000-$100,000"
                            },
                            {
                                "key":"100000-125000",
                                "value":"$100,000-$125,000"
                            },
                            {
                                "key":"125000-150000",
                                "value":"$125,000-$150,000"
                            },
                            {
                                "key":"150000-175000",
                                "value":"$150,000-$175,000"
                            },
                            {
                                "key":"175000-200000",
                                "value":"$175,000-$200,000"
                            },
                            {
                                "key":">200000",
                                "value":"Over $200,000"
                            },
                            {
                                "key":"Prefer not to disclose",
                                "value":"Prefer not to disclose"
                            }
                        ]
                    }
                ]
            },
            {
                "fieldset":"Child's Ethnicity",
                "fields":[
                    {
                        "html":"<p>The following information is being collected for the sole purpose of reporting to our grant-funding institute, i.e.,  NIH (National Institute of Health).  NIH requires this information to ensure the soundness and inclusiveness of our research. Your cooperation is appreciated, but optional.</p>"
                    },
                    {
                        "field":"child_hispanic_latino",
                        "label":"My child is (check all that apply):"
                    },
                    {
                        "field":"child_ethnicity",
                        "widget_type":"CheckboxSelectMultiple",
                        "choices":[
                            {
                                "key":"N",
                                "value":"American Indian / Alaska Native"
                            },
                            {
                                "key":"A",
                                "value":"Asian (Far East, Southeast Asia, Indian Sub-continent)"
                            },
                            {
                                "key":"H",
                                "value":"Native Hawaiian or Other Pacific Islander"
                            },
                            {
                                "key":"B",
                                "value":"Black or African American"
                            },
                            {
                                "key":"W",
                                "value":"White"
                            },
                            {
                                "key":"O",
                                "value":"Other"
                            }
                        ]
                    }
                ]
            },
            {
                "fieldset":"Caregiver Information",
                "fields":[
                    {
                        "field":"caregiver_info"
                    }
                ]
            },
            {
                "fieldset":"Language Exposure",
                "fields":[
                    {
                        "field":"other_languages_boolean",
                        "divs":[
                            {
                                "field":"other_languages",
                                "css":"make-selectize",
                                "div":[
                                    "language_from",
                                    "language_days_per_week",
                                    "language_hours_per_day"
                                ]
                            }
                        ]
                    }
                ]
            },
            {
                "fieldset":"Health",
                "fields":[
                    {
                        "field":"ear_infections_boolean",
                        "div":[
                            "ear_infections"
                        ]
                    },
                    {
                        "field":"hearing_loss_boolean",
                        "div":[
                            "hearing_loss"
                        ]
                    },
                    {
                        "field":"vision_problems_boolean",
                        "div":[
                            "vision_problems"
                        ]
                    },
                    {
                        "field":"illnesses_boolean",
                        "div":[
                            "illnesses"
                        ]
                    },
                    {
                        "field":"services_boolean",
                        "div":[
                            "services"
                        ]
                    },
                    {
                        "field":"worried_boolean",
                        "div":[
                            "worried"
                        ]
                    },
                    {
                        "field":"learning_disability_boolean",
                        "div":[
                            "learning_disability"
                        ]
                    }
                ]
            }
        ]
    },
    {
        "page":"front",
        "contents":[
            {
                "fieldset":"Basic Information",
                "fields":[
                    {
                        "field":"form_filler",
                        "div":[
                            "form_filler_other"
                        ]
                    },
                    {
                        "field":"prolific_pid"
                    },
                    {
                        "field":"child_dob"
                    },
                    {
                        "field":"age"
                    },
                    {
                        "field":"sex"
                    },
                    {
                        "field":"country",
                        "div":[
                            "zip_code"
                        ]
                    },
                    {
                        "field":"mother_yob_confirmation"
                    },
                    {
                        "field":"birth_weight_confirmation_lb",
                        "widget_type":"Select"
                    }
                ]
            }
        ]
    }
]

Confirmation Questions

Three fields have been added to allow confirmation of data being entered, namely, mother_yob_confirmation, birth_weight_confirmation_lb and birth_weight_confirmation_kg. The mother_yob_confirmation and appropriate weight field should be in the instrument_form_front.json file. These fields will then be displayed if, and only if, the checkbox 'Would you like participants to answer the confirmation questions(only available when split background information forms are used)' is ticked.

Sibling Data

Though not part of the standard form, a couple of new fields have been added which can be added to the background forms. These are sibling_boolean, sibling_count and sibling_data. sibling_boolean is a boolean field defining if the child has siblings, if so sibling_count and sibling_datashould be enabled. sibling_countis an integer field containing the number of siblings andsibling_data` is a text field in which the participant enters the sex and age of the siblings.