Capturing timestamps for each question

Hello,

I am creating a survey using commcare to capture observational data which involves recording what feeding behavior occurs every 1 - 5 mins (from a list of target behaviors). I was wondering if there is a way to either:

  1. Prompt the enumerator to answer a question ever XX number of mins (so I know approximately when the behavior occurs based on the time that the observation started) OR

  2. If there is a way to add a timestamp within each question or as a hidden value after the question

I saw some previous chats regarding this topic, but it seems that was quite a few years ago (2017) and was not sure if commcare functions have changed since then.

Best,

A committed commcare user!

Hi Teresa,

Unfortunately the "State of the art" on this hasn't changed too much over the years.

In your case, however, I think you may be in luck for having a compatible solution, since it sounds like you are collecting repeated behavior.

Inside of a repeat, the Default Value calculation is only triggered when a repeat is created for the first time, so you could set a timestamp in a hidden value where that default value is set each time a new repeated data group is created. As long as your user workflow tells the user to not proceed into the next repeat until the feeding behavior occurs, you would be able to fairly faithfully capture the timestamp of each observation.

Hello Clayton,

Thank you for this explanation. I think this is a good idea. I have two follow-up questions for you:

  1. For the 'repeat group function' is there a way to set the number of repeats to an unknown number and instead use the answer to the last question in the repeat group govern if the question is repeated or not? For example, the last question in the group could say: completed X behavior, completed Y behavior, or finished eating (i.e. exit group of questions because these behaviors are not occurring anymore). I am seeing that a lot of the commcare guidance indicates that you should have a question before the question group that pre-specifies how many repeat groups you are programing (i.e. there are 5 children in the household so I will collect 5 sets of child demographics only).

  2. I have tried adding a time stamp after my repeat of questions to try to capture the time in which the repeat group was answered every time and it is not working. I have set the calculate condition, in the hidden value, to basically choosing any of the choices from the repeat behavior group (i.e. must have answered the question i have in my repeat group) and the default value to : double(now()). When I download the data, I am just getting a '0' for time. Is there another approach you would recommend so that I can get a time stamp for every time that the repeat group is answered?

Thank you for your help!

Teresa

Hi Teresa,

  1. Yes, you can set up this interaction, although it's a tiny bit tricky. I've included a Copy/Paste snippet below you can paste inside of a form as an example of how to create this interaction:

[Snippet corrected in later followup]

  1. Unfortunately, I don't think you'll be able to rely on a calculation, since those are recomputed regularly in the form. What I'd recommend is instead setting the timestamp as a Default Value at the beginning of a repeat, and having the condition for the next repeat being created as when the question is first answered. This pattern is a little awkward because it means that the timestamp for a question is actually in the next repeat group over, but I think it's the cleanest way to make sure the timestamp is accurate.

Hi Teresa,

Apologies, I noticed a bug in the Copy/Paste snippet I just sent out. A corrected copy is below:

[Code block fixed below]

Hi Clayton,

This is very helpful. I am a new Commcare user and still learning the ropes. Would you be able to help me understand where I would paste this text? I am thinking that some of this text gets pasted in a few different questions that have to be answered yes/no once this text above has been modified, but I am not sure.

Really excited that I can make the application work for this project!

Best regards,
Teresa

If you copy that block of text in whole, then navigate into the form builder and paste into the question list, it'll create a set of questions and groups that you can use as a template for the interaction you want to build.

I'd recommend trying this out first with a totally empty form so you can play around with the pattern.

Hello Clayton,

Thank you for your help with this! I have tried to use this copy/paste without making any edits (starting with "form builder clip version 1" and ending in "null null" using the process you outlined. I pasted the text into the form and clicked 'insert questions'. When I do this, nothing happens. There is just a blank survey. Do you have any hints about what I might be doing wrong?

Thank you for your help!

Best regards,
Teresa

Hi Teresa,

I'm actually having the same issue, oddly. I'm going to retry posting here with a code block, which I think should fix the text. I'll reply again if the copy/paste doesn't work with this new text.

Form Builder clip	version 1
id	type	labelItext:en-default	labelItext:es-default	labelItext:fra-default	appearance	calculateAttr	rawDataAttributes	rawRepeatAttributes	repeat_count	requiredAttr
/conditional_repeat	Group	null	null	null	null	null	null	null	null	null
/conditional_repeat/question1	Trigger	After this label is a repeat which displays some internal info and then asks if you want to see it again	After this label is a repeat which displays some internal info and then asks if you want to see it again	After this label is a repeat which displays some internal info and then asks if you want to see it again	minimal	null	null	null	null	null
/conditional_repeat/host_repeat	Repeat	null	null	null	null	null	"{""jr:template"":""""}"	"{""jr:noAddRemove"":""true()""}"	#form/conditional_repeat/counter_for_repeat	null
/conditional_repeat/host_repeat/question4	Trigger	Useful information goes here!	Useful information goes here!	Useful information goes here!	minimal	null	null	null	null	null
/conditional_repeat/host_repeat/show_again	Select	Do you want to see the useful information again?	Do you want to see the useful information again?	Do you want to see the useful information again?	null	null	null	null	null	true
/conditional_repeat/host_repeat/show_again/yes	Choice	Yes!	Yes!	Yes!	null	null	null	null	null	null
/conditional_repeat/host_repeat/show_again/no	Choice	No thanks, I'd like the form to end!	No thanks, I'd like the form to end!	No thanks, I'd like the form to end!	null	null	null	null	null	null
/conditional_repeat/counter_for_repeat	DataBindOnly	null	null	null	null	count(#form/conditional_repeat/host_repeat) + if(count(/data/conditional_repeat/host_repeat[show_again = 'no' or show_again = '']) > 0, 0, 1)	null	null	null	null

Hi Clayton,

This works! Thank you. I am struggling with one additional thing. I am trying to have all the repeat questions display on the same screen. I tried using a question list, but it seems like this logic is not liking the question list because the repeat function no longer works. Would you be able to give this a look and let me know where I am going wrong?

Form Builder clip version 1
id type labelItext:en-default appearance calculateAttr rawDataAttributes rawRepeatAttributes repeat_count requiredAttr
/question5 FieldList List of behaviors field-list null null null null null
/question5/conditional_repeat Group null null null null null null null
/question5/conditional_repeat/host_repeat Repeat null null null "{""jr:template"":""""}" "{""jr:noAddRemove"":""true()""}" #form/question5/conditional_repeat/counter_for_repeat null
/question5/conditional_repeat/child_behaviors MSelect Child behaviors null null null null null null
/question5/conditional_repeat/child_behaviors/encouragement Choice Encouragement null null null null null null
/question5/conditional_repeat/child_behaviors/choice4 Choice Verbalization null null null null null null
/question5/conditional_repeat/question2 MSelect Caregiver behaviors null null null null null null
/question5/conditional_repeat/question2/choice3 Choice Verbalization null null null null null null
/question5/conditional_repeat/question2/encouragement Choice Encouragement null null null null null null
/question5/conditional_repeat/show_again Select Do you want to see the useful information again? null null null null null true
/question5/conditional_repeat/show_again/yes Choice Yes! null null null null null null
/question5/conditional_repeat/show_again/no Choice No thanks, I'd like the form to end! null null null null null null
/question5/conditional_repeat/counter_for_repeat DataBindOnly null null count(#form/question5/conditional_repeat/host_repeat) + if(count(/data/conditional_repeat/host_repeat[show_again = 'no' or show_again = '']) > 0, 0, 1) null null null null