Filtering a case list to include cases selected by a previous question


(Ray B) #1

We are modelling health districts as cases.

We allow the user to select 1 or more districts where they will be working in a ‘user configuration’ form, which results in the list of district case IDs being stored in a case property (say district_uids). This is actually stored in a ‘user case’.

In another form we would like to include a single-select list that allows the user to choose from one of the districts selected in the configuration form.

If only one district is chosen, a case filter like the following will work:
[@case_id=/form/district_uid]

However, I’m not sure if/how I can specify a case filter that would include all district cases selected by the user. The following will not work, but may help understand what I’m trying to ask:
[@case_id in /form/district_uids]

Thoughts?

Thanks, Ray


(Clayton Sims) #2

Hi Ray,

You can specify this relationship with the selected() function.

Your predicate would look like

[selected(/data/district_uids, @case_id)]

which would identify whether the case was one of the ids chosen by the multi-select question.

If you are filtering the casedb connector in this way it may have some performance issues if you are dealing with super large case lists, introducing predicates that can reduce the search space (by selecting case_type or similar) will help with that.

-Clayton


(Ray B) #3

Thanks Clayton. I’ll give it a try.


(Ray B) #4

Followup question:

What would a module case filter look like to only have the districts chosen by the multi-select question appear in the case list?

Here is how I access the UIDs:
instance(‘casedb’)/casedb/case[@status=‘open’][@case_type=‘usuario’]/uids_distrito

Thanks, Ray


(Clayton Sims) #5

Hi Ray,

I’m not sure I understand. How are you planning on applying the multi-select question to the “case list”?

If I understand correctly, the mutli-selected ID’s are stored on a case in the ‘uids_distrito’ property, that’s on a single usercase on device? And you’re trying to filter a list of ‘district’ cases?

If so you can put your expression directly in the case list filter to read that property set. I think it would be something like

selected(instance(‘casedb’)/casedb/case[@status=‘open’][@case_type=‘usuario’]/uids_distrito, ./@case_id)

but I may be misunderstanding.


(Ray B) #6

Hi again Clayton,

The suggested predicate, [selected(/data/district_uids,@case_id)], seems to be working great!

Armed with this knowledge, I’ve tried a slight variation, [selected(/data/district_uids,district_uid)] to build a case list where the district UID is stored as a plain case property and not the case_id. However, this appears to returning 1 (and only 1) of the expected cases. Before digging into this further, I wanted to check if you expect the ‘selected’ to work the same with both case IDs (@case_id) and case properties.

Thanks, Ray


(Ray B) #7

Re: “Armed with this knowledge, I’ve tried a slight variation, [selected(/data/district_uids,district_uid)] to build a case list where the district UID is stored as a plain case property and not the case_id. However, this appears to returning 1 (and only 1) of the expected cases. Before digging into this further, I wanted to check if you expect the ‘selected’ to work the same with both case IDs (@case_id) and case properties.”

Looks like this may have been an issue on my end, so no need to respond to this one now. I believe it’s working as desired/intended.

Thanks, Ray


(Ray B) #8

Just closing the loop on this one. Your understanding was correct and it seems like you suggestion was almost correct. Just seems like the case_id reference should be /@case_id and not ./@case_id. I received a “Case List has invalid filter xpath” error when I included the period before /@case_id.

So, thanks again for your help. The desired filtering is now working both within the forms and the module case list.