Community Health Toolkit

Value for repeat_count is not recalculated while looping through the repeat block

I am trying to create a form that will ask a series of questions and then at the end will ask the user if the questions should be repeated again for a new entity. If the user answers ‘yes’ then the questions should be repeated and a new instance of the answers should be recorded (and at the end the user should be asked again if they want the questions to be repeated again). If the user answers no, then the form should complete without repeating any more questions.

To do this, I was hoping to use the repeat block and the dynamic repeat_count logic similar to what was described here. Unfortunately, I cannot seem to get this functionality to work with the CHT.

I tried using the exact data from the linked example and I got some obscure XPath error. For some reason it did not seem to like references to the ${plant} repeat block name. This needs some more investigation, and perhaps a discussion in a separate thread.

type name label calculation repeat_count
calculate count 1 + sum(${more_plants_count})
begin_repeat plant Plant ${count}
text species Species
integer estimated_size Estimated size
select_one yes_no more_plants Are there more plants in this area?
calculate more_plants_count if(${more_plants} = ‘yes’, 1, 0)

With this config, my form will ask for the information about one plant species and then will end the repeat block regardless of what my answer is to the more_plants question.

Can anyone see something wrong with my logic or suggest an alternate way to achieve this functionality? Is this a known gap in the CHT functionality? Thank you!

More context: I know that if I leave out the repeat_count value completely, then I can use the + and - buttons in the UI to add information for as many different entities as I want. However that only seems to work in the CHT when the appearance of the repeat block is set to field-list which is not ideal for my use case since I have a large number of questions across multiple pages that I want to repeat. Additionally, I would like to be able to limit the max number of possible repeats to 3 instead of allowing the user to enter repeats infinitely.