commcare-export map multiple questions to same database column

29 views
Skip to first unread message

crei...@nd.edu

unread,
Jun 22, 2015, 4:42:55 PM6/22/15
to commcar...@googlegroups.com
Hi!

We are currently using the commcare-export tool to do nightly synchs of the data in CommCareHQ. Recently we realized that a few of our forms could be cleaned up with the use of question lists, so we were planning on making a change until we realized that the queries we are using would break if we changed the full xpath to the questions we cared to export from CommCare.

For example what used to be '/data/fires_burning_inside' will now be '/data/fire_questionlist/fires_burning_inside'

Ideally, we would like to be able to make this improvement to question lists so that the form entry is cleaner, and structure our commcare-export queries such that both the old /data/fires_burning_inside and the new /data/fire_questionlist/fires_burning_inside both get mapped to the same database field. Is there any way to elegantly do this? If not, are there any workarounds such as creating two query files representing the old and new structure and grab all form submissions from app_version < xyz with the old and app version >= xyz with the new query?

Thanks for your help!
-Caleb

Daniel Miller

unread,
Jun 22, 2015, 9:25:16 PM6/22/15
to commcar...@googlegroups.com
Hi Caleb,

I can think of two ways you might be able to achieve what you're hoping to do:

1. Editing forms only

In the form, create your new question list and move questions into it. For each question moved into the question list, create a Hidden Value question outside the question list with the same Question ID as the question that was moved into the list, and set its Calculate Condition to the question in the list. For example:

- Create question list: /data/fire_questionlist
- Move /data/fires_burning_inside into the list so its new path is /data/fire_questionlist/fires_burning_inside
- Create hidden value: /data/fires_burning_inside
- Set the Calculate Condition of the hidden value to /data/fire_questionlist/fires_burning_inside

This way the updated app should be completely backward-compatible with the old app, but forms stored on the phone may take up a bit more space (probably not noticeable) since you'll have an extra hidden value for every question moved into a question list.

2. Editing forms as well as the query file used by the commcare-export tool

In the form, move all questions into question lists as desired. In the query file, add a new field mapping for each moved question so you have both the old field mapping (Source Field: form.fires_burning_inside) and the new field (Source Field: form.fire_questionlist.fires_burning_inside) in the same query file sheet. When you run commcare-export, one field will have a value and the other will be blank, depending on the app version. This second solution will not quite achieve what you want by itself since you now have old app data in one field and new app data in another. You can write queries or views in your database to choose the one that is not blank.

Hope that's helpful.

~ Daniel

--
You received this message because you are subscribed to the Google Groups "commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commcare-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Caleb Reinking

unread,
Jun 22, 2015, 10:39:24 PM6/22/15
to commcar...@googlegroups.com
Hi Daniel,

I had not thought of solution #1, and that is a fantastic idea! Thank you for the input, and thank you for your work on CommCare. We have found it to be a very capable software solution for our project.

Thanks,
Caleb

--
You received this message because you are subscribed to a topic in the Google Groups "commcare-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/commcare-users/6aEffDrU6Mk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to commcare-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages