It is possible to have the criteria in an auto-case close rule reference a parent case. You can just prefix the case property name with "parent/". So for example, to close all child cases whose parent has a case property named "marked_for_close" set to "yes", the criteria would be:
parent/marked_for_close | equals | yes
Currently though, the equals comparison only allows for string comparison, and the value for closed is stored internally as a boolean, so that wouldn't work to check for parent/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
It actually is possible to set up automatic child case closure based on the parent case closing, it just takes a few steps, and isn't exactly immediate:
1) when closing the parent case, set the case property close_case = 'yes'
2) go to the Data tab > automatically close cases, and set a new rule for the child case type with the filter parent/case_close = yes. You will have to specify the # of days after which the case should close if it hasn't been updated. Select the minimum (which I believe is 30). This means that when the parent case closes, the child case will close 30 days later.
3) to make sure these cases don't appear in your case lists, set the case list filter parent/close_case != 'yes' and/or close_case != 'yes' depending on the case type of the module.
It's a bit of a work around, but in the eye of the user, those cases will be gone as soon as the parent is closed, and on the back end, they'll be closed in 30 days.