Is it possible to put a casedb expression in a CommCare module filter

commcare

Is it possible to put a casedb expression in a CommCare module filter? I only want the module to show up if there are cases of the module type.

Best Answer

Yes, this is possible. The module filter (for module with case-type "notification") ends up being:

count(instance('casedb')/casedb/case[@case_type = "notification"][@status = "open"]) > 0

The [@status = "open"] piece is key to get the right behavior in the time period between when the last case is closed and the next sync (when it gets removed from the phone).