Minimize data errors and duplicate case entries by setting up validations from a label in your CommCare application.
Warning!
Please note you must test this feature on mobile, not app preview or web apps.
Overview
This method utilizes labels, validation conditions, and session instance variables to set up a strict way of preventing users from registering duplicate cases. Please modify the instructions below to fit your specific needs.
Configuration on CommCareHQ
Imagine the following scenario:
- You have a registration form that creates cases of case type = 'People'
- You have mobile workers that create cases using this form.
- In this form, you collect the first name, last name, and date of birth of the case.
- First name field = /data/first_name
- Last name field = /data/last_name
- Date of birth field = /data/date_of_birth
- If the case you are creating shares the same first name, last name, and date of birth with another case, you want to prevent the user from following through with the registration form.
If this scenario seems similar to your needs, please follow the instructions below:
- Turn off easy references by going here:
- Make sure all your questions (such as the first name, last name, and date of birth questions) are set up in the registration form.
- Make sure all your case properties are created.
- Navigate to the relevant registration form where you want to prevent duplicates.
- After the last question you want to check (in this example, it would be date of birth since you are checking all three fields in separate questions) create a label field.
- In the label field, insert a validation condition similar to the following:
count(instance('casedb')/casedb/case[@case_type = 'People'][last_name = /data/last_name][first_name = /data/first_name][date_of_birth = /data/date_of_birth]) = 0
- Change each of the bold parts of the expression to match your application.
- For example, if the case type in your application is "Individual", you would change the text "People" to "Individual"
- In the label field, insert a validation condition similar to the following:
- Add text to warn the user within the "Validation Message" section of the question.
- Save and test.
Your label should look something like this: