Avoid Duplication of ID number

Hi, I'm finding a solution to prevent mobile users from entering duplicate ID numbers. Specifically, in our registration form for the 'mch' case type, I'm aiming to ensure that each registration number is unique. For example, if registration number 0001 has already been used, I'd like to prevent the use of 0001 for another registration. I would greatly appreciate your guidance on how to achieve this. Thank you.

Hi Swe,

I have a bit of a solution to this but with some assumptions and limitations to it;

  1. I am assuming you are registering a case and you'd like to add an ID (Could be an external ID to use outside of CommCare).
  2. I am also assuming the cases registered belong the either that mobile worker or the location where the mobile worker is attached to, AND there's an extension of the ID that is generated from the parent or owner of the case. For example, if one mobile worker registers a case with ID 0001 under owner A, and another mobile worker uses the same ID under owner B, we will have two different IDs (A0001 and B0001).
  3. For this to work smoothly also, in case two mobile workers are registering different cases under the same case owner, there needs to be some level of discipline in syncing back to the server, otherwise, there's a chance that there will be duplicate IDs. So if two mobile workers are registering cases under the same owner AND the ID extensions are the same, then it is best if they do it one after the other and not concurrently. This way, the case list is updated for the next mobile worker and they can avoid entering duplicate IDs.

All these however are limitations I have faced and believe someone else could have better solutions to your challenge without such limitations.

Onto the solution;

  1. Create an ID input field, input_id, in the form.
  2. Create a second question which is a 'hidden value' field, search_id, that queries the list of case id for that case type you are trying to register this case in. For example, if the case type is 'teachers', you can use the XPath instance('casedb')/casedb/case[@case_type = 'teachers'][id_var = input_id]. Where id_var is the name of the case field in which the IDs are stored.
  3. Create a third question that only appears when the second question, search_id, is not empty. This can be a label to warn the data entrant that the ID already exists. You can add instructions on a way forward, as well as display the details of the case that was initially registered under this ID.

Like mentioned before, this is how I have approached it before but I believe someone else could have a better approach to it with maybe less steps and zero limitations.

1 Like