Not allow the same question answer twice for the same case

598 views
Skip to first unread message

hca...@bu.edu

unread,
Mar 18, 2015, 6:17:15 PM3/18/15
to commcar...@googlegroups.com
Hello all,

I am having difficulty figuring out how to code a form to not allow a user to enter the same answer for a question. For example, in a repeating group question, not allow a user to enter in testing information for "Month 1" of patient treatment twice. Along the same lines, is there a way to prompt or suggest to the user what month of the patient's treatment it is based on their previous entry?

Thanks very much
Hannah

Ameera Hamid

unread,
Mar 19, 2015, 8:57:43 AM3/19/15
to commcar...@googlegroups.com
Hi Hannah,

To prevent a user from entering the same answer you can specify in the validation condition that the answer cannot equal the answer from the previous month. The condition would look something like this;  . != /data/month_1_answer

To prompt or suggest to the user what month it is you can simply use a label that displays a hidden value of the month incremented by the previous visit.

Hope this is helpful!

Ameera

hca...@bu.edu

unread,
Mar 20, 2015, 1:18:26 PM3/20/15
to commcar...@googlegroups.com
Hi Ameera,

Thank you so much for your response. The validation condition you suggested is not working, I think because of the way my question is formatted. I have the question as part of a repeating group. The question ID is "Month_X" and label is "Month of patient's treatment:" with an integer answer format. Since the user can enter 1-25 or higher as the month of treatment, I don't know that your recommendation would work in that scenario.

Again, I really appreciate your help.

Take care,
Hannah

Nate Haduch

unread,
Mar 20, 2015, 6:04:59 PM3/20/15
to commcar...@googlegroups.com
Hi Hannah,

The overall strategy that you want to employ here is to create a list of the months that have already been used and check to see if a new day that is being entered is in that list. Here's one way that I imagine it working:

1) Create a hidden value that contains a list of numbers that have been used. A possible format would be a comma-delimited string of the days (,2,4,12,5,...)
2) Check the string for each number that is being entered. You can use the contains() function to see if a number is in the list with a comma on either end of it, something like contains(/data/day_of_month_list/, ",num,")
3) If it passes this check each time through the repeat group, use the concat() function to add the new number to the end of the list. concat(/data/day_of_month_list/, "num,")

For more information on CommCare functions, please see this reference: https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions

Let me know if this helps.

Cheers,

-- 
Nate Haduch

Technical Support Analyst
Dimagi, Inc | 585 Massachusetts Ave | Suite 3 | Cambridge, MA 02139
web: http://www.dimagi.com/


--
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.




Hannah Carey

unread,
Mar 26, 2015, 9:54:27 PM3/26/15
to commcar...@googlegroups.com
Hi there,

Thank you for your responses. I am having a hard time articulating my question, I think. Is there a phone number I could call?

I'll also again to explain the function I am looking for in a different way, so please bear with me one more time. Essentially, I would like to know how to make answers to a repeating group non-repeatable, including question in date and integer formats. Perhaps there is a different type of question that is better fitted for what I want than the repeating group format?

With your previous suggestion, I do not know how it would work for the questions I am thinking of because I cannot anticipate what month the user is inputting data for. For example, for that Bacteriology form I mentioned previously, I want the user to be able to enter any number between 1 and 25. Say they start with Month 4 of the patient's treatment, so they enter "4" the first time they input test result data into the form. The next month, when they add a new group for new test results, I would like them to no longer be able to enter "4" (to avoid any accidents or data entry errors), and the month after that no longer be allowed to enter "4" or "5." I do not think the functions you described would be applicable to this situation, since the months will vary for each patient.

Does this make more sense?

Thank you again.

Take care,
Hannah

--
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/B0j5L6Qb0MQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to commcare-user...@googlegroups.com.

Derek Hans

unread,
Mar 27, 2015, 7:52:00 AM3/27/15
to commcar...@googlegroups.com
Hi Hannah,
Would it be a reasonable restriction that if someone enters data for month 7, they can no longer enter data for month 6?

William Pride

unread,
Mar 28, 2015, 2:04:15 PM3/28/15
to commcar...@googlegroups.com
Hannah,

I believe Nate's suggestion will work for your case. Let me explain in more detail:

You'll have your question /data/date_question where your user enters the month number.

You'll also have some hidden value, say /data/entered_dates that accumulates the dates that have been entered so far. At first this value will be "" - nothing. 

Your date question will have the validation condition not(contains(/data/entered_dates, concat('-', /data/date_question, '-')) - this will test whether the answer to /data/date_question has already been entered. [note the '-'s - I will explain later] 

We'll use case management to persist the entered_dates between sessions. So, we'll need some intermediary hidden value called, EG, /data/new_entered_dates.

/data/new_entered_dates will have the calculate condition '=concat(/data/entered_dates, '-' /data/date_question, '-') [note the '-'s]

Now we'll save /data/new_entered_dates to some case property (for simplicity, entered_dates)

We'll also _load_ that case property on subsequent form entriers into the hidden value /data/date_question

So, if we enter '4' the first time, the case property will be saved with the value '-4-' and if the user tries to enter this again, the validaiton condition will fail.

This case property will continue to accumulate for subsequent month values. 

The reason we use the '-' is because otherwise if we enter date '14' then later on we will not be able to enter '4' because this is contained within '14'. The '-' allow us to specify the exact value.

If you only want to enforce that the date number must increase then this is even easier. We simply save the last entered month value to the case in some property EG last_date and then enforce that /data/date_question > /data/last_date, saving /data/date_question to property last_date on subsequent form entries.

Hope this all makes sense!

Best,
Will
Reply all
Reply to author
Forward
0 new messages