Creating Surveys for CareSuite

Survey building is a foundational requirement for operationalizing both the Contact and Care applications. Caresuite works with Kobotoolbox as a plug-in form builder to allow users

Caresuite Survey Building Guide

This guide provides comprehensive best practices and anti-patterns for building surveys in Caresuite

Survey Types in Caresuite

Caresuite supports four main types of surveys:

1. Intake Survey

  • Purpose: Data collection for case creation in a project

  • Scope: Project-level (each project has one intake survey)

  • Usage: Used when creating or updating cases

  • Storage: Survey responses are stored on the Case entity

  • Key Features: Required for all projects, used for case creation

2. Demographic Survey

  • Purpose: Profile-level demographic information collection

  • Scope: Organization-level (each organization has one demographic survey)

  • Usage: Used to collect and update profile demographics

  • Storage: Survey responses are stored on the Profile entity (profile.survey)

  • Key Features: Used for global profile search and demographic data collection

3. Follow-Up Survey

  • Purpose: Post-referral follow-up data collection

  • Scope: Project-level (optional, each project can have one follow-up survey)

  • Usage: Completed by case managers post service delivery

  • Storage: Survey responses stored as follow-up survey responses per referral

4. Additional Surveys

  • Purpose: Custom supplemental data collection

  • Scope: Project-level (multiple additional surveys per project are allowed)

  • Usage: Custom surveys for specific data collection needs

  • Storage: Survey responses stored in additionalSurveyResponse table

  • Key Features: Supports single and multiple responses per case per survey


Survey Format Requirements

File Format

  • File Type: XML (.xml extension)

  • MIME Type: text/xml

  • Maximum File Size: 10 MB (MAX_SURVEY_FILESIZE = 10 * 1024 * 1024)

  • Format Standard: XForms/ODK (Open Data Kit) format

  • Compatibility: Must be compatible with Kobo Toolbox format

XML Structure Requirements

Surveys must follow the XForms/ODK XML structure:

Required Namespaces

  • http://www.w3.org/2002/xforms

  • http://www.w3.org/2001/xml-events

  • http://www.w3.org/1999/xhtml

  • http://openrosa.org/javarosa

  • http://www.opendatakit.org/xforms

  • http://openrosa.org/xforms

  • http://www.w3.org/2001/XMLSchema


Supported Data Types

For a more detailed breakdown of stat types see Supported Data Types

✅ Fully Supported Types

1. string (Text)

  • XML Type: type="string"

  • Usage: Text input fields, names, descriptions, notes

  • Query Operators: Equals, Not equals, Begins with, Ends with, Contains, Doesn't contain, Is empty, Is not empty, In, Not in

  • Example:

2. int (Integer)

  • XML Type: type="int"

  • Usage: Whole numbers (age, counts, scores)

  • Query Operators: Equals, Not equals, Greater than, Less than

  • Example:

3. date (Date)

  • XML Type: type="date"

  • Usage: Date fields (no time component)

  • Query Operators: Equals to, After, Before, Between

  • Format: ISO date format (YYYY-MM-DD)

  • Example:

4. select1 (Single Select)

  • XML Type: type="string" with <select1> input

  • Usage: Single-choice dropdown/radio buttons

  • Query Operators: Equals, Not equals, Is empty, Is not empty

  • Example:

5. select (Multi-Select)

  • XML Type: type="string" with <select> input

  • Usage: Multiple-choice checkboxes/lists

  • Storage: Values stored as space-separated string (e.g., "value1 value2 value3")

  • Query Operators: Equals, Not equals, Is empty, Is not empty

  • Example:

❌ Not Supported Types

The following data types are NOT supported and should be avoided:

  • time - Time-only fields (use string or separate date field)

  • dateTime - Date and time combined (use date type and store time separately if needed)

  • decimal - Decimal numbers (may work as int, but not explicitly supported)

  • boolean - Boolean values (use select1 with "yes"/"no" options instead)

  • geopoint - Geographic coordinates (store as separate lat/lng string or int fields)

  • geotrace - Geographic paths

  • geoshape - Geographic shapes/polygons

  • binary - File uploads (not supported in surveys)

  • barcode - Barcode scanning

  • intent - External application intents


Best Practices

1. Field Naming

DO:

  • Use descriptive, lowercase field names with underscores: caller_age, first_time_caller, hear_about_211

  • Use consistent naming conventions throughout the survey

  • Keep field names concise but meaningful

  • Use snake_case for multi-word field names

DON'T:

  • Use spaces in field names

  • Use special characters (except underscores)

  • Use camelCase (use snake_case instead)

  • Use extremely long field names

Example:

2. Field Organization with Groups

DO:

  • Organize related fields using <group> elements

  • Use descriptive group names: group_AARP_careprovider, group_kick_it

  • Nest groups when necessary to create logical hierarchies

Example:

3. Use itext for All Text Content

DO:

  • Always use <itext> translations for labels, hints, and option labels

  • Reference text using jr:itext() function

  • Keep actual text content in the itext section, not inline

Example:

4. Conditional Logic (Relevant Attributes)

DO:

  • Use relevant attributes for conditional field display

  • Use clear, readable XPath expressions

  • Test all conditional logic paths

Example:

5. Required Fields

DO:

  • Use required attributes with clear XPath conditions

  • Consider using conditional required logic when appropriate

  • Allow fields to be optional when data may not be available

Example:

6. Validation and Constraints

DO:

  • Use regex constraints for format validation (phone numbers, emails, etc.)

  • Provide clear constraint messages using jr:constraintMsg

  • Validate data at the field level when possible

Example:

7. Calculated Fields

DO:

  • Use calculate attributes for computed values

  • Mark calculated fields as readonly="true()"

  • Include constraints that prevent manual modification if needed

Example:

8. Pre-loaded Values

DO:

  • Use jr:preload for auto-populated values (timestamps, instance IDs)

  • Use appropriate preload parameters

Example:

9. Date Handling

DO:

  • Use date() function for default date values

  • Set default dates using <setvalue> events when appropriate

  • Use date constraints for validation

Example:

10. Incomplete Data Handling

DO:

  • Include options for handling incomplete data collection

  • Provide standard options: "Did Not Ask", "Declined to Answer", "Call Terminated Early", "Crisis Call - Did not ask"

  • Make fields conditionally required based on completion status

Example:


Common Anti-Patterns and Things to Avoid

1. ❌ Using Unsupported Data Types

Problem: Using data types that are not supported (dateTime, time, binary, etc.) will cause issues with data storage, querying, and display.

Solution:

  • Use date instead of dateTime (store time separately if needed)

  • Use string for boolean values with select1 options

  • Use string or separate int fields for geographic coordinates

2. ❌ Inconsistent Field Naming

Problem: Inconsistent naming (mixing camelCase, snake_case, spaces) makes surveys harder to maintain and query.

Solution:

  • Always use snake_case for field names

  • Establish and follow a naming convention document

  • Use descriptive names that indicate the field's purpose

3. ❌ Inline Text Instead of itext

Problem: Hardcoding text directly in field definitions makes translations difficult and maintenance harder.

Solution:

  • Always use <itext> translations

  • Reference text using jr:itext()

  • Keep all user-facing text in the itext section

4. ❌ Missing or Incorrect XML Namespaces

Problem: Missing or incorrect namespaces can cause parsing errors.

Solution:

  • Include all required namespaces in the <h:html> root element

  • Use the exact namespace URIs specified in the format requirements

5. ❌ Overly Complex Conditional Logic

Problem: Very complex relevant or required expressions are hard to maintain and debug.

Solution:

  • Break complex conditions into simpler, testable expressions

  • Use intermediate calculated fields when necessary

  • Document complex logic with comments (if XML comments are supported)

6. ❌ Missing Field Bindings

Problem: Fields defined in the body without corresponding <bind> statements may not work correctly.

Solution:

  • Always create a <bind> element for each field in the form body

  • Ensure nodeset paths match exactly between bind and input elements

  • Include appropriate type, required, and relevant attributes

7. ❌ Incorrect Multi-Select Value Storage

Problem: Expecting multi-select values to be stored as arrays when they're actually space-separated strings.

Solution:

  • Remember that <select> (multi-select) values are stored as space-separated strings

  • When querying, use appropriate string operators

  • When displaying, split the string to get individual values

Example:

8. ❌ File Size Exceeding Limits

Problem: Surveys exceeding 10 MB will be rejected during upload.

Solution:

  • Keep surveys focused and avoid unnecessary fields

  • Optimize itext content (avoid duplicate text)

  • Remove unused fields and groups

  • Consider splitting very large surveys into multiple additional surveys

9. ❌ Missing Validation for Critical Fields

Problem: Critical fields (phone numbers, emails, etc.) without validation can lead to poor data quality.

Solution:

  • Always add regex constraints for phone numbers, emails, postal codes

  • Provide clear, helpful constraint messages

  • Test validation with various valid and invalid inputs

10. ❌ Using dateTime Type for Dates

Problem: Using dateTime type is not supported and may cause errors.

Solution:

  • Always use type="date" for date fields

  • If time is needed, store it in a separate string field

  • Note: The system may accept dateTime in bind statements for metadata fields (like start/end timestamps), but use date for user-entered dates

11. ❌ Missing Incomplete Data Options

Problem: Not providing options for incomplete data collection makes it difficult to track why surveys are incomplete.

Solution:

  • Include an "Incomplete General Screener" or similar field at the beginning

  • Provide standard options for incomplete scenarios

  • Make other fields conditionally required based on completion status

12. ❌ Hardcoding Option Values

Problem: Using option labels as values makes data analysis difficult and error-prone.

Solution:

  • Always use lowercase, underscore-separated values

  • Keep labels human-readable but values consistent

  • Example: label="Female", value="female" (not "Female" as the value)

Problem: Flat field structures make surveys harder to navigate and understand.

Solution:

  • Group related fields using <group> elements

  • Create logical hierarchies (e.g., group_callback_contact/telephone_001)

  • Use descriptive group names

14. ❌ Missing Meta Instance ID

Problem: Not including a meta/instanceID field makes it difficult to track survey instances.

Solution:

  • Always include a meta section with instanceID

  • Use jr:preload="uid" to auto-generate unique IDs

  • Keep it readonly

Example:


Field Naming Conventions

  1. Use snake_case: caller_age, first_time_caller, hear_about_211

  2. Be descriptive: caller_frequency not freq

  3. Use prefixes for groups: group_AARP_careprovider, group_kick_it

  4. Use suffixes for related fields: telephone_001, email_001, givenName, familyName

  5. Keep names concise: Avoid extremely long names, but prioritize clarity

Examples from Production Surveys

Good Examples:

  • Incomplete_General_Screener

  • caller_frequency

  • caller_age

  • BTS_Date

  • group_kick_it

  • group_callback_contact

Avoid:

  • Mixed case without separation: callerAge, CallerFrequency

  • Spaces: caller age, first time caller

  • Special characters: caller-age, caller.age

  • Too generic: field1, data, value


Survey Structure Guidelines

1. Logical Flow

  • Start with screener/incomplete data options

  • Group related questions together

  • Use conditional logic to show/hide sections

  • End with optional metadata fields

2. Required vs Optional Fields

  • Make fields required only when absolutely necessary

  • Use conditional required logic when appropriate

  • Consider data collection scenarios (incomplete calls, declined answers)

3. Group Organization

  • Use groups to organize related fields

  • Create nested groups for sub-sections

  • Name groups descriptively

4. Field Ordering

  • Order fields logically (general to specific, required to optional)

  • Keep conditional fields near their parent fields

  • Group similar field types together when possible


Testing and Validation

Before Uploading

  1. Validate XML Structure

    • Check for well-formed XML

    • Verify all namespaces are present

    • Ensure all fields have corresponding bind statements

  2. Test in Kobo Toolbox (Required)

    • Build/test surveys in Kobo Toolbox first

    • Verify all conditional logic works correctly

    • Test with various data inputs

  3. Review Field Names

    • Ensure consistent naming convention

    • Check for typos in nodeset paths

    • Verify bind paths match input ref paths

  4. Test Conditional Logic

    • Test all relevant/required conditions

    • Verify calculated fields work correctly

    • Check pre-loaded values populate

  5. Check File Size

    • Ensure file is under 10 MB

    • Optimize if necessary

After Uploading

  1. Test Survey Flow

    • Complete a test survey response

    • Verify all fields appear/disappear correctly

    • Check validation messages

  2. Verify Data Storage

    • Submit a test response

    • Check that data is stored correctly

    • Verify multi-select values are stored properly

  3. Test Querying

    • Test advanced search with survey fields

    • Verify date queries work correctly

    • Check select field filtering


Troubleshooting

Common Errors

1. "Only xml file is allowed"

  • Cause: File is not recognized as XML

  • Solution: Ensure file has .xml extension and correct MIME type (text/xml)

2. "Survey file must be provided"

  • Cause: No file was uploaded

  • Solution: Ensure file input has a valid file selected

3. "File size exceeds limit"

  • Cause: File is larger than 10 MB

  • Solution: Reduce file size by removing unused fields, optimizing text content, or splitting into multiple surveys

4. Survey fields not appearing in search

  • Cause: Field type may not be supported, or metadata not parsed correctly

  • Solution: Verify field uses supported type (string, int, date, select1, select)

5. Multi-select values not displaying correctly

  • Cause: Expecting array when values are space-separated strings

  • Solution: Split space-separated string when processing: value.split(' ')

6. Date fields not queryable

  • Cause: Using dateTime type instead of date

  • Solution: Change to type="date" in bind statement

Debugging Tips

  1. Download Existing Survey

    • Use the "Download Survey" button to see the current survey XML

    • Compare with your new survey to identify differences

  2. Check Survey Metadata

    • View survey metadata in the project settings

    • Verify all fields are listed with correct types

  3. Test Incrementally

    • Start with a simple survey and add complexity gradually

    • Test after each major change

  4. Review Logs

    • Check server logs for XML parsing errors

    • Look for specific field or namespace errors


Additional Resources

  • Kobo Toolbox: https://kobotoolbox.org (Recommended tool for building and testing surveys)

  • ODK XForms Specification: https://getodk.github.io/xforms-spec/

  • XForms Documentation: https://www.w3.org/TR/xforms/


Summary Checklist

When building a survey, ensure:

Last updated

Was this helpful?