As long as the form submission doesn't have any errors associated with it, it will by default be included in a form export, even if the case that it opened/is related to is closed.
I'm assuming in this case that you've loaded a the member
case into your form, and that you can load the member case ID id into
/data/member_id
What you want to get is:
The count of all member
cases which are children of this case's parent, for which the member case has the property mm_is_in_tb_treatment = 'yes'
For now we can create a new hidden value to store the parent household's case ID, since it'll make understanding the full query below easier.
New hidden value: /data/parent_id
:
instance('casedb')/casedb/case[@case_id = /data/member_id]/index/parent
All cases which are children of that parent would be referenced as:
instance('casedb')/casedb/case[index/parent = /data/parent_id]
You can now add your new filter directly to the end of that statement and introduce the count
count(instance('casedb')/casedb/case[index/parent = /data/parent_id][mm_is_in_tb_treatment = 'yes']
If you wanted, you could further specify that you (for safety) only want to include children that are member
cases and which are open. You can also collapse back the parent ID reference if you want a one-line expression:
count(instance('casedb')/casedb/case[@case_type='member'][@status='open'][index/parent = instance('casedb')/casedb/case[@case_id = /data/member_id]/index/parent][mm_is_in_tb_treatment = 'yes']
Best Answer
This can be accomplished by adding a filter based on the
position()
of the current element, but the syntax will be a bit of a hack because you need to introduce a second predicate filter after the current one to constrain the scope.Example: If your current filter is
property < 50
I believe you can replace it with
property < 50][position() < N
where
N
is the number of results you want.NOTE: You won't be able to see "more" cases, so the user will have go to back and forth in order to see additional results.
Update: It looks like HQ no longer allows you to use
][
to introduce a second predicate filter expression, so this doesn't work at the moment.