# Ensure uniqueness of an answer (like ID) across (all) cases?

**URL:** <https://forum.dimagi.com/t/ensure-uniqueness-of-an-answer-like-id-across-all-cases/2794>\
**Category:** Users\
**Created:** [June 20, 2016, 6:12pm UTC](https://forum.dimagi.com/t/ensure-uniqueness-of-an-answer-like-id-across-all-cases/2794 "2016-06-20T18:12:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Neumann](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/c/c77e96/32.png) [@Christian\_Neumann](https://forum.dimagi.com/u/Christian_Neumann)\
**Post date:** [June 20, 2016, 6:12pm UTC](https://forum.dimagi.com/t/ensure-uniqueness-of-an-answer-like-id-across-all-cases/2794/1 "2016-06-20T18:12:34Z")

</div>

Hi,

I think I know the answer and I might 'abuse' CommCare with this a little  
bit. Nevertheless want to make sure that I understand it.

For our referral app we are planning to pre-print unique QR codes as  
'referral IDs. These IDs are both handed out to the referred client and are  
recorded/scanned as an answer in the initial registration form. Now I  
wonder if there is a way to ensure that one code/ID is not accidentally  
used for different referral cases. So ideally once one of the pre-printed  
coded is used for the referral case registration, the app would deny  
re-assigning/-scanning this for another referral case.

Of course this can't be done with multiple concurrent, offline deployments,  
but in our case for one screening activity it will be done from only one  
device. So is there a way to access the form-history of all cases (of one  
day?) to check for uniqueness?

Thanks,  
christian

---

<div class="post-metadata">

**Author:** ![William\_Pride](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/w/b19c9b/32.png) [@William\_Pride](https://forum.dimagi.com/u/William_Pride)\
**Post date:** [June 20, 2016, 6:46pm UTC](https://forum.dimagi.com/t/ensure-uniqueness-of-an-answer-like-id-across-all-cases/2794/2 "2016-06-20T18:46:39Z")

</div>

Hey Christian,

Please check out this page  
[https://confluence.dimagi.com/display/commcarepublic/Minimize+Duplicates](https://confluence.dimagi.com/display/commcarepublic/Minimize+Duplicates)  
on minimizing duplicates.

Thanks,  
Will

> **···**
>
> On Mon, Jun 20, 2016 at 2:12 PM, Christian Neumann \< christian.neumann@gmail.com\> wrote:
> 
> > Hi,
> > 
> > I think I know the answer and I might 'abuse' CommCare with this a little  
> > bit. Nevertheless want to make sure that I understand it.
> > 
> > For our referral app we are planning to pre-print unique QR codes as  
> > 'referral IDs. These IDs are both handed out to the referred client and are  
> > recorded/scanned as an answer in the initial registration form. Now I  
> > wonder if there is a way to ensure that one code/ID is not accidentally  
> > used for different referral cases. So ideally once one of the pre-printed  
> > coded is used for the referral case registration, the app would deny  
> > re-assigning/-scanning this for another referral case.
> > 
> > Of course this can't be done with multiple concurrent, offline  
> > deployments, but in our case for one screening activity it will be done  
> > from only one device. So is there a way to access the form-history of all  
> > cases (of one day?) to check for uniqueness?
> > 
> > Thanks,  
> > christian
> > 
> > --  
> > 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-users+unsubscribe@googlegroups.com](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Christian\_Neumann](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/c/c77e96/32.png) [@Christian\_Neumann](https://forum.dimagi.com/u/Christian_Neumann)\
**Post date:** [June 27, 2016, 8:36am UTC](https://forum.dimagi.com/t/ensure-uniqueness-of-an-answer-like-id-across-all-cases/2794/3 "2016-06-27T08:36:06Z")

</div>

Thanks William,

Just found the time now to think more about this and am trying to map this to my use case.

Not sure if I fully understand the situation described on the wiki page. My current take away is: Enabling registration forms on the case list prevents duplicates as users can now always use the case list (and therefore no longer need to make the decision between registration or ‘followups’ before data capture).

In my scenario I actually don’t need both registration and followup forms available (as they happen at different times, different physical locations, and potentially different users). So for me during registrations I would like to ensure that the scanned barcode is unique (for simplicity just among open cases). Is there any way to query/scan the local database of open cases with a validation condition for one question?

christian

> **···**
>
> \> On 20 Jun 2016, at 20:46, William Pride wrote: \> \> Hey Christian, \> \> Please check out this page on minimizing duplicates. \> \> Thanks, \> Will \> \> On Mon, Jun 20, 2016 at 2:12 PM, Christian Neumann \<christian.neumann@gmail.com \> wrote: \> Hi, \> \> I think I know the answer and I might 'abuse' CommCare with this a little bit. Nevertheless want to make sure that I understand it. \> \> For our referral app we are planning to pre-print unique QR codes as 'referral IDs. These IDs are both handed out to the referred client and are recorded/scanned as an answer in the initial registration form. Now I wonder if there is a way to ensure that one code/ID is not accidentally used for different referral cases. So ideally once one of the pre-printed coded is used for the referral case registration, the app would deny re-assigning/-scanning this for another referral case. \> \> Of course this can't be done with multiple concurrent, offline deployments, but in our case for one screening activity it will be done from only one device. So is there a way to access the form-history of all cases (of one day?) to check for uniqueness? \> \> Thanks, \> christian \> \> \> -- \> 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-users+unsubscribe@googlegroups.com . \> For more options, visit https://groups.google.com/d/optout . \> \> \> -- \> 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/AvLVVfBuOOU/unsubscribe . \> To unsubscribe from this group and all its topics, send an email to commcare-users+unsubscribe@googlegroups.com . \> For more options, visit https://groups.google.com/d/optout .

---

<div class="post-metadata">

**Author:** ![William\_Pride](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/w/b19c9b/32.png) [@William\_Pride](https://forum.dimagi.com/u/William_Pride)\
**Post date:** [June 27, 2016, 12:59pm UTC](https://forum.dimagi.com/t/ensure-uniqueness-of-an-answer-like-id-across-all-cases/2794/4 "2016-06-27T12:59:39Z")

</div>

Hey Christian,

Sorry for not being clear enough. The solution I was trying to suggest with  
the link above would be:

1. For each case you register, their barcode is scanned and the string  
associated with the case
2. Then, in the case list on subsequent visits, users would be trained to  
scan the barcode from the case list first when doing the follow up
3. This would filter the case list so that users could see if the scanned  
code matched any existing cases

Given your specifics, though, I agree this isn't the cleanest fit. It is  
possible to do that sort of validation within form entry; however, this  
would require some custom XML and would potentially be slow if your case  
database got too large. If you're still interested, please email me  
directly ([wpride@dimagi.com](mailto:wpride@dimagi.com)) and we can go over the custom XML you'd use  
for this.

Cheers,  
Will

> **···**
>
> On Mon, Jun 27, 2016 at 4:36 AM, Christian Neumann \< christian.neumann@gmail.com\> wrote:
> 
> > Thanks William,
> > 
> > Just found the time now to think more about this and am trying to map this  
> > to my use case.
> > 
> > Not sure if I fully understand the situation described on the wiki page.  
> > My current take away is: Enabling registration forms on the case list  
> > prevents duplicates as users can now always use the case list (and  
> > therefore no longer need to make the decision between registration or  
> > ‘followups’ before data capture).
> > 
> > In my scenario I actually don’t need both registration and followup forms  
> > available (as they happen at different times, different physical locations,  
> > and potentially different users). So for me during registrations I would  
> > like to ensure that the scanned barcode is unique (for simplicity just  
> > among open cases). Is there any way to query/scan the local database of  
> > open cases with a validation condition for one question?
> > 
> > christian
> > 
> > On 20 Jun 2016, at 20:46, William Pride [wpride@dimagi.com](mailto:wpride@dimagi.com) wrote:
> > 
> > Hey Christian,
> > 
> > Please check out this page  
> > [https://confluence.dimagi.com/display/commcarepublic/Minimize+Duplicates](https://confluence.dimagi.com/display/commcarepublic/Minimize+Duplicates)  
> > on minimizing duplicates.
> > 
> > Thanks,  
> > Will
> > 
> > On Mon, Jun 20, 2016 at 2:12 PM, Christian Neumann \< [christian.neumann@gmail.com](mailto:christian.neumann@gmail.com)\> wrote:
> > 
> > > Hi,
> > > 
> > > I think I know the answer and I might 'abuse' CommCare with this a little  
> > > bit. Nevertheless want to make sure that I understand it.
> > > 
> > > For our referral app we are planning to pre-print unique QR codes as  
> > > 'referral IDs. These IDs are both handed out to the referred client and are  
> > > recorded/scanned as an answer in the initial registration form. Now I  
> > > wonder if there is a way to ensure that one code/ID is not accidentally  
> > > used for different referral cases. So ideally once one of the pre-printed  
> > > coded is used for the referral case registration, the app would deny  
> > > re-assigning/-scanning this for another referral case.
> > > 
> > > Of course this can't be done with multiple concurrent, offline  
> > > deployments, but in our case for one screening activity it will be done  
> > > from only one device. So is there a way to access the form-history of all  
> > > cases (of one day?) to check for uniqueness?
> > > 
> > > Thanks,  
> > > christian
> > > 
> > > --  
> > > 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-users+unsubscribe@googlegroups.com](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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/AvLVVfBuOOU/unsubscribe](https://groups.google.com/d/topic/commcare-users/AvLVVfBuOOU/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [commcare-users+unsubscribe@googlegroups.com](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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-users+unsubscribe@googlegroups.com](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Christian\_Neumann](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/c/c77e96/32.png) [@Christian\_Neumann](https://forum.dimagi.com/u/Christian_Neumann)\
**Post date:** [June 27, 2016, 1:52pm UTC](https://forum.dimagi.com/t/ensure-uniqueness-of-an-answer-like-id-across-all-cases/2794/5 "2016-06-27T13:52:06Z")

</div>

Ok. This makes sense now, but like you’ve said doesn’t necessarily match my intended workflow. Will follow up with you as I’m curious about the more advanced usage.

Thanks,  
christian

> **···**
>
> \> On 27 Jun 2016, at 14:59, William Pride wrote: \> \> Hey Christian, \> \> Sorry for not being clear enough. The solution I was trying to suggest with the link above would be: \> \> 1) For each case you register, their barcode is scanned and the string associated with the case \> 2) Then, in the case list on subsequent visits, users would be trained to scan the barcode from the case list first when doing the follow up \> 3) This would filter the case list so that users could see if the scanned code matched any existing cases \> \> Given your specifics, though, I agree this isn't the cleanest fit. It is possible to do that sort of validation within form entry; however, this would require some custom XML and would potentially be slow if your case database got too large. If you're still interested, please email me directly (wpride@dimagi.com ) and we can go over the custom XML you'd use for this. \> \> Cheers, \> Will \> \> On Mon, Jun 27, 2016 at 4:36 AM, Christian Neumann \<christian.neumann@gmail.com \> wrote: \> Thanks William, \> \> Just found the time now to think more about this and am trying to map this to my use case. \> \> Not sure if I fully understand the situation described on the wiki page. My current take away is: Enabling registration forms on the case list prevents duplicates as users can now always use the case list (and therefore no longer need to make the decision between registration or ‘followups’ before data capture). \> \> In my scenario I actually don’t need both registration and followup forms available (as they happen at different times, different physical locations, and potentially different users). So for me during registrations I would like to ensure that the scanned barcode is unique (for simplicity just among open cases). Is there any way to query/scan the local database of open cases with a validation condition for one question? \> \> christian \> \>\> On 20 Jun 2016, at 20:46, William Pride \<wpride@dimagi.com \> wrote: \>\> \>\> Hey Christian, \>\> \>\> Please check out this page on minimizing duplicates. \>\> \>\> Thanks, \>\> Will \>\> \>\> On Mon, Jun 20, 2016 at 2:12 PM, Christian Neumann \<christian.neumann@gmail.com \> wrote: \>\> Hi, \>\> \>\> I think I know the answer and I might 'abuse' CommCare with this a little bit. Nevertheless want to make sure that I understand it. \>\> \>\> For our referral app we are planning to pre-print unique QR codes as 'referral IDs. These IDs are both handed out to the referred client and are recorded/scanned as an answer in the initial registration form. Now I wonder if there is a way to ensure that one code/ID is not accidentally used for different referral cases. So ideally once one of the pre-printed coded is used for the referral case registration, the app would deny re-assigning/-scanning this for another referral case. \>\> \>\> Of course this can't be done with multiple concurrent, offline deployments, but in our case for one screening activity it will be done from only one device. So is there a way to access the form-history of all cases (of one day?) to check for uniqueness? \>\> \>\> Thanks, \>\> christian \>\> \>\> \>\> -- \>\> 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-users+unsubscribe@googlegroups.com . \>\> For more options, visit https://groups.google.com/d/optout . \>\> \>\> \>\> -- \>\> 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/AvLVVfBuOOU/unsubscribe . \>\> To unsubscribe from this group and all its topics, send an email to commcare-users+unsubscribe@googlegroups.com . \>\> For more options, visit https://groups.google.com/d/optout . \> \> \> -- \> 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-users+unsubscribe@googlegroups.com . \> For more options, visit https://groups.google.com/d/optout . \> \> \> -- \> 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/AvLVVfBuOOU/unsubscribe . \> To unsubscribe from this group and all its topics, send an email to commcare-users+unsubscribe@googlegroups.com . \> For more options, visit https://groups.google.com/d/optout .

---

<div class="post-metadata">

**Author:** ![ninafinley](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/ninafinley/32/2749_2.png) [@ninafinley](https://forum.dimagi.com/u/ninafinley)\
**Post date:** [March 10, 2025, 3:21pm UTC](https://forum.dimagi.com/t/ensure-uniqueness-of-an-answer-like-id-across-all-cases/2794/6 "2025-03-10T15:21:40Z")

</div>

Hello,

I have a similar situation to the original poster. I'd like the household registration form to reject household numbers that are already in use. The tablet will have all open household cases from the region loaded.

My plan is to have a hidden value to determine if the entered household number is unique. If yes, the form can be submitted. If not, a label question with validation condition 1=2 will prevent the form from being submitted.

I'm struggling to develop the XPath statement to determine if the household number is unique. The wiki link above is broken. I found a similar post on Stack Exchange and tried their suggestion: [commcare - Checking unique case property (saving an ID) against already-saved case properties of other cases - Web Applications Stack Exchange](https://webapps.stackexchange.com/questions/105520/checking-unique-case-property-saving-an-id-against-already-saved-case-properti). They suggested:

```auto
count(instance('casedb')/casedb/case[your_id_property = /data/id_entered] > 0)

```

Which I modified to:

```auto
count(instance('casedb')/casedb/case[household_number = #form/household_number] > 0)

```

But I get an error that:

"Calculation Error: Error in calculation for /data/check\_existing\_household\_numbers XPath nodeset has more than one node"

Any ideas on how I can check if the household number is unique?

Thank you!

---

<div class="post-metadata">

**Author:** ![ayogi](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@ayogi](https://forum.dimagi.com/u/ayogi)\
**Post date:** [March 11, 2025, 7:16am UTC](https://forum.dimagi.com/t/ensure-uniqueness-of-an-answer-like-id-across-all-cases/2794/7 "2025-03-11T07:16:18Z")

</div>

@ninafinley : I think there is an issue on the last bracket you have used :

```auto
count(instance('casedb')/casedb/case[household_number = #form/household_number] > 0)

```

It should be :

```auto
count(instance('casedb')/casedb/case[household_number = #form/household_number] ) > 0

```

Can you try and reply back if that works for you
