Minimize Duplicates Method 2: Validating from a Label

Minimize data errors and duplicate case entries by setting up validations from a label in your CommCare application.

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:

  1. Turn off easy references by going here:





  2. Make sure all your questions (such as the first name, last name, and date of birth questions) are set up in the registration form.

  3. Make sure all your case properties are created.

  4. Navigate to the relevant registration form where you want to prevent duplicates. 

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

    1. In the label field, insert a validation condition similar to the following:

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

    2. Change each of the bold parts of the expression to match your application.

      1. For example, if the case type in your application is "Individual", you would change the text "People" to "Individual"

  6. Add text to warn the user within the "Validation Message" section of the question.

  7. Save and test.

 

Your label should look something like this: