Check duplicate dates within a repeat group

Hi All! I am trying to design a form where the patient has to enter the date and time at which he took his medication. I have used a repeat group.

If the user enters the same date again at any point of time, the system should throw an error message stating 'This seems to be an additional dose for the same date ${date}'.

And if there is a gap between two dates, the system should throw a message that there is missed dose.

1. What is the issue? Please be detailed.

When I add a duplicate entry for date, it should show the note "This is an additional dosage".
If there is a missing date entry, it should show " Missed entry"

3. What have you tried to fix the issue?

I have used join() to join the dates and then when the date is entered within the repeat group, I have tried to check for duplicate dates using if (${position}=1,'', substr(${joindates},0, string-length(${joindates})-string-length(${date})))

I have used (selected(${checkduplicate},${date})) in the relevant field.
When there is a duplicate entry, it not only shows the note with respect to the current date entry but also for the previous entry which is not a duplicate.

I have used this looking at various websites using xlsform. However, they had used it with multiselect questions and I have a form where date is dynamically entered.

The logic for missed dose works only if the dates are entered in chronological order. I could not think of anything where in it would automatically check for the order of the dates and then fire a missed date message!

Can anyone help me here . Attaching the form for reference.

4. Upload any forms or screenshots you can share publicly below.

TestEnteko.xls (184 KB)

Below is the screenshot of how the form would look:

But if I enter the same date in the third row, I should get error message only for that entry. However, it shows error for the previous date as well!

Can someone help me solve this issue!

Regards,

I haven't looked at this in detail but I'd encourage you to look at the first example in this XLSForm. I think that approach will be simpler to reason about than using substrings. You can use selected on any value that is a list of space-separated strings.

2 Likes

Thank you @LN . That was a life saver. Tweaked it a little to obtain the results and its working with respect to duplicate dates entered. I will upload my version in case if someone needs it.
I still have another milestone to achieve. That is, in case if there is a missed date of entry(even if the dates are not entered in chronological order), the system should notify the message that there is a missed day!! I could think of some sort function, but looks like it doesnt exist in xlsform. Will you able to suggest something that could work out. Appreciate your help!

Hint: Another option to find the date in the joined string might be the contains() function, see https://getodk.github.io/xforms-spec/#fn:contains. But the selected() function seems preferable for me here, as better corresponding to the type.

@wroos @LN ..Thanks for the suggestions.
I got the solution .

Attaching the xlsform here in case if anyone finds this helpful. You can add the constraint instead of note. My requirement was to only show a note but the entry can be accepted.
Check duplicates within repeat and figure out missed date within repeat.xls (185.5 KB)

1 Like

You might also use acknowledge type (instead of a note). So, you will get the user confirmation stored ("OK") in the data set and facilitate quality checks.

1 Like