# Case list filtering

**URL:** <https://forum.dimagi.com/t/case-list-filtering/1651>\
**Category:** Users\
**Created:** [February 18, 2014, 12:54pm UTC](https://forum.dimagi.com/t/case-list-filtering/1651 "2014-02-18T12:54:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jennifer\_Hall](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/j/c2a13f/32.png) [@Jennifer\_Hall](https://forum.dimagi.com/u/Jennifer_Hall)\
**Post date:** [February 18, 2014, 12:54pm UTC](https://forum.dimagi.com/t/case-list-filtering/1651/1 "2014-02-18T12:54:35Z")

</div>

Hi,

Can anyone help me understand why my case list filter is not working?

pn\_complete='yes' and pn6\_complete\_mother!='yes' and  
(today()\>=baby\_dob+183) and today()\<=baby\_dob+274)) or (miscarriage='yes'  
and today()\>=(date\_pn1+120))

(which should mean that the postnatal form has been completed but the 6  
month postnatal form has not been completed and the baby is 6-9 months old  
or there was a miscarriage and it is at least 4 months since the woman was  
last visited.)

I'm wondering if it's because I'm using dates, but according to wiki help  
pages for case filtering you just use the property as is (they don't  
explicitly say that but it is what is in the example). I did try this as  
well

pn\_complete='yes' and pn6\_complete\_mother!='yes' and  
(today()\>=(date(baby\_dob)+183) and today()\<=(date(baby\_dob)+274)) or  
(miscarriage='yes' and today()\>=(date(date\_pn1)+120))

but it also doesn't work - with both I end up with no cases showing at all!

I have 'reported an issue' from the web page but that was almost a week ago  
and I haven't heard anything so if anyone has any ideas that would be great!

Thanks

Jenny

---

<div class="post-metadata">

**Author:** ![Sheel\_Shah](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/s/779978/32.png) [@Sheel\_Shah](https://forum.dimagi.com/u/Sheel_Shah)\
**Post date:** [February 18, 2014, 10:32pm UTC](https://forum.dimagi.com/t/case-list-filtering/1651/2 "2014-02-18T22:32:33Z")

</div>

Hi Jenny,

You should use the latter option you suggested (casting the baby\_dob and  
date\_pn1 to date). To be safe your may want to wrap the entire  
calculation inside a date function. So instead of using _(date(baby\_dob) +  
183)_, use \*date(date(baby\_dob) + 183) \*for any places where you're using a  
date calculation.

It also looks like you're missing a set of brackets in your filter.  
Currently you have (to paraphrase):  
pn\_complete and pn\_6\_not\_complete and (baby\_between\_6\_9\_months) or  
(baby\_deceased and no\_mother\_pn1\_visit)

You want:  
pn\_complete and pn\_6\_not\_complete and _(_(baby\_between\_6\_9\_m_o_nths) or  
(baby\_deceased and no\_mother\_pn1\_visit)_)_

So your statement would become:  
pn\_complete='yes' and pn6\_complete\_mother!='yes' and  
((today()\>=date(date(baby\_dob)+183) and today()\<=date(date(baby\_dob)+274))  
or (miscarriage='yes' and today()\>=date(date(date\_pn1)+120)))

If possible, can you check your Case List (Reports tab -\> Case List) to  
verify that you cases that meet the above criteria with the case properties  
correctly set?

Thanks,  
Sheel

> **···**
>
> On Tue, Feb 18, 2014 at 7:54 AM, Jennifer Hall wrote:
> 
> > Hi,
> > 
> > Can anyone help me understand why my case list filter is not working?
> > 
> > pn\_complete='yes' and pn6\_complete\_mother!='yes' and  
> > (today()\>=baby\_dob+183) and today()\<=baby\_dob+274)) or (miscarriage='yes'  
> > and today()\>=(date\_pn1+120))
> > 
> > (which should mean that the postnatal form has been completed but the 6  
> > month postnatal form has not been completed and the baby is 6-9 months old  
> > or there was a miscarriage and it is at least 4 months since the woman was  
> > last visited.)
> > 
> > I'm wondering if it's because I'm using dates, but according to wiki help  
> > pages for case filtering you just use the property as is (they don't  
> > explicitly say that but it is what is in the example). I did try this as  
> > well
> > 
> > pn\_complete='yes' and pn6\_complete\_mother!='yes' and  
> > (today()\>=(date(baby\_dob)+183) and today()\<=(date(baby\_dob)+274)) or  
> > (miscarriage='yes' and today()\>=(date(date\_pn1)+120))
> > 
> > but it also doesn't work - with both I end up with no cases showing at all!
> > 
> > I have 'reported an issue' from the web page but that was almost a week  
> > ago and I haven't heard anything so if anyone has any ideas that would be  
> > great!
> > 
> > Thanks
> > 
> > Jenny
> > 
> > --  
> > 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/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> Sheel Shah  
> Project Manager | Dimagi  
> m: +1.781.428.5419 | skype: sheel\_shah

---

<div class="post-metadata">

**Author:** ![Jennifer\_Hall](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/j/c2a13f/32.png) [@Jennifer\_Hall](https://forum.dimagi.com/u/Jennifer_Hall)\
**Post date:** [February 20, 2014, 8:31am UTC](https://forum.dimagi.com/t/case-list-filtering/1651/3 "2014-02-20T08:31:41Z")

</div>

Hi Sheel,

Thanks for looking at this. I had tried double casting the dates in one of  
the many iterations of this I have tried but that also did not work. I've  
just copied your logic into the case filter but still it is filtering all  
the cases out.

I'm not sure how to use the case filter in the way that you suggest (if I  
try putting the whole filter there it says the syntax is invalid and when I  
looked up the advanced case filter help it doesn't tell you how to search  
on specific case properties). So I downloaded the case list to double  
check and all the cases who have had the first postnatal visit done have  
all the case properties saved (pn\_complete, baby\_dob, miscarriage and  
date\_pn1). None have the pn6\_complete case property (actually called  
pn6\_complete\_mother) yet as this is only added in the 6 month form. It is  
set up to be saved as a case property there and I just did a test form that  
did save it as a case property. So all the cases who have had the first  
postnatal done, and where the baby is 6-9 months old, or there was a  
miscarriage and the visit was more than 4 months ago, should be showing on  
the 6 month list but none of them are!

Jenny

> **···**
>
> On Wednesday, February 19, 2014 12:32:33 AM UTC+2, Sheel Shah wrote: \> \> Hi Jenny, \> \> You should use the latter option you suggested (casting the baby\_dob and \> date\_pn1 to date). To be safe your may want to wrap the entire \> calculation inside a date function. So instead of using \*(date(baby\_dob) \> + 183)\*, use \*date(date(baby\_dob) + 183) \*for any places where you're \> using a date calculation. \> \> It also looks like you're missing a set of brackets in your filter. \> Currently you have (to paraphrase): \> pn\_complete and pn\_6\_not\_complete and (baby\_between\_6\_9\_months) or \> (baby\_deceased and no\_mother\_pn1\_visit) \> \> You want: \> pn\_complete and pn\_6\_not\_complete and \*(\*(baby\_between\_6\_9\_m\*o\*nths) or \> (baby\_deceased and no\_mother\_pn1\_visit)\*)\* \> \> So your statement would become: \> pn\_complete='yes' and pn6\_complete\_mother!='yes' and \> ((today()\>=date(date(baby\_dob)+183) and today()\<=date(date(baby\_dob)+274)) \> or (miscarriage='yes' and today()\>=date(date(date\_pn1)+120))) \> \> If possible, can you check your Case List (Reports tab -\> Case List) to \> verify that you cases that meet the above criteria with the case properties \> correctly set? \> \> Thanks, \> Sheel \> \> \> \> \> On Tue, Feb 18, 2014 at 7:54 AM, Jennifer Hall \<jenny\_...@yahoo.co.uk wrote: \> \>\> Hi, \>\> \>\> Can anyone help me understand why my case list filter is not working? \>\> \>\> pn\_complete='yes' and pn6\_complete\_mother!='yes' and \>\> (today()\>=baby\_dob+183) and today()\<=baby\_dob+274)) or (miscarriage='yes' \>\> and today()\>=(date\_pn1+120)) \>\> \>\> (which should mean that the postnatal form has been completed but the 6 \>\> month postnatal form has not been completed and the baby is 6-9 months old \>\> or there was a miscarriage and it is at least 4 months since the woman was \>\> last visited.) \>\> \>\> I'm wondering if it's because I'm using dates, but according to wiki help \>\> pages for case filtering you just use the property as is (they don't \>\> explicitly say that but it is what is in the example). I did try this as \>\> well \>\> \>\> pn\_complete='yes' and pn6\_complete\_mother!='yes' and \>\> (today()\>=(date(baby\_dob)+183) and today()\<=(date(baby\_dob)+274)) or \>\> (miscarriage='yes' and today()\>=(date(date\_pn1)+120)) \>\> \>\> but it also doesn't work - with both I end up with no cases showing at \>\> all! \>\> \>\> I have 'reported an issue' from the web page but that was almost a week \>\> ago and I haven't heard anything so if anyone has any ideas that would be \>\> great! \>\> \>\> Thanks \>\> \>\> Jenny \>\> \>\> -- \>\> 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-user...@googlegroups.com . \>\> For more options, visit https://groups.google.com/groups/opt\_out. \>\> \> \> \> \> -- \> Sheel Shah \> Project Manager | Dimagi \> m: +1.781.428.5419 | skype: sheel\_shah \> \> \>

---

<div class="post-metadata">

**Author:** ![Sheel\_Shah](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/s/779978/32.png) [@Sheel\_Shah](https://forum.dimagi.com/u/Sheel_Shah)\
**Post date:** [February 21, 2014, 6:11pm UTC](https://forum.dimagi.com/t/case-list-filtering/1651/4 "2014-02-21T18:11:50Z")

</div>

Hi Jenny,

Lets discuss this off the main mailing list.

Thanks,  
Sheel

> **···**
>
> On Thu, Feb 20, 2014 at 3:31 AM, Jennifer Hall wrote:
> 
> > Hi Sheel,
> > 
> > Thanks for looking at this. I had tried double casting the dates in one  
> > of the many iterations of this I have tried but that also did not work.  
> > I've just copied your logic into the case filter but still it is filtering  
> > all the cases out.
> > 
> > I'm not sure how to use the case filter in the way that you suggest (if I  
> > try putting the whole filter there it says the syntax is invalid and when I  
> > looked up the advanced case filter help it doesn't tell you how to search  
> > on specific case properties). So I downloaded the case list to double  
> > check and all the cases who have had the first postnatal visit done have  
> > all the case properties saved (pn\_complete, baby\_dob, miscarriage and  
> > date\_pn1). None have the pn6\_complete case property (actually called  
> > pn6\_complete\_mother) yet as this is only added in the 6 month form. It is  
> > set up to be saved as a case property there and I just did a test form that  
> > did save it as a case property. So all the cases who have had the first  
> > postnatal done, and where the baby is 6-9 months old, or there was a  
> > miscarriage and the visit was more than 4 months ago, should be showing on  
> > the 6 month list but none of them are!
> > 
> > Jenny
> > 
> > On Wednesday, February 19, 2014 12:32:33 AM UTC+2, Sheel Shah wrote:
> > 
> > > Hi Jenny,
> > > 
> > > You should use the latter option you suggested (casting the baby\_dob and  
> > > date\_pn1 to date). To be safe your may want to wrap the entire  
> > > calculation inside a date function. So instead of using \*(date(baby\_dob)
> > > 
> > > - 183)\*, use \*date(date(baby\_dob) + 183) \*for any places where you're  
> > > using a date calculation.
> > > 
> > > It also looks like you're missing a set of brackets in your filter.  
> > > Currently you have (to paraphrase):  
> > > pn\_complete and pn\_6\_not\_complete and (baby\_between\_6\_9\_months) or  
> > > (baby\_deceased and no\_mother\_pn1\_visit)
> > > 
> > > You want:  
> > > pn\_complete and pn\_6\_not\_complete and _(_(baby\_between\_6\_9\_m_o_nths) or  
> > > (baby\_deceased and no\_mother\_pn1\_visit)_)_
> > > 
> > > So your statement would become:  
> > > pn\_complete='yes' and pn6\_complete\_mother!='yes' and  
> > > ((today()\>=date(date(baby\_dob)+183) and today()\<=date(date(baby\_dob)+274))  
> > > or (miscarriage='yes' and today()\>=date(date(date\_pn1)+120)))
> > > 
> > > If possible, can you check your Case List (Reports tab -\> Case List) to  
> > > verify that you cases that meet the above criteria with the case properties  
> > > correctly set?
> > > 
> > > Thanks,  
> > > Sheel
> > > 
> > > On Tue, Feb 18, 2014 at 7:54 AM, Jennifer Hall [jenny\_...@yahoo.co.uk](mailto:jenny_...@yahoo.co.uk)wrote:
> > > 
> > > > Hi,
> > > > 
> > > > Can anyone help me understand why my case list filter is not working?
> > > > 
> > > > pn\_complete='yes' and pn6\_complete\_mother!='yes' and  
> > > > (today()\>=baby\_dob+183) and today()\<=baby\_dob+274)) or (miscarriage='yes'  
> > > > and today()\>=(date\_pn1+120))
> > > > 
> > > > (which should mean that the postnatal form has been completed but the 6  
> > > > month postnatal form has not been completed and the baby is 6-9 months old  
> > > > or there was a miscarriage and it is at least 4 months since the woman was  
> > > > last visited.)
> > > > 
> > > > I'm wondering if it's because I'm using dates, but according to wiki  
> > > > help pages for case filtering you just use the property as is (they don't  
> > > > explicitly say that but it is what is in the example). I did try this as  
> > > > well
> > > > 
> > > > pn\_complete='yes' and pn6\_complete\_mother!='yes' and  
> > > > (today()\>=(date(baby\_dob)+183) and today()\<=(date(baby\_dob)+274)) or  
> > > > (miscarriage='yes' and today()\>=(date(date\_pn1)+120))
> > > > 
> > > > but it also doesn't work - with both I end up with no cases showing at  
> > > > all!
> > > > 
> > > > I have 'reported an issue' from the web page but that was almost a week  
> > > > ago and I haven't heard anything so if anyone has any ideas that would be  
> > > > great!
> > > > 
> > > > Thanks
> > > > 
> > > > Jenny
> > > > 
> > > > --  
> > > > 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-user...@googlegroups.com](mailto:commcare-user...@googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > Sheel Shah  
> > > Project Manager | Dimagi  
> > > m: +1.781.428.5419 | skype: sheel\_shah
> > > 
> > > --  
> > > 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/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> Sheel Shah  
> Project Manager | Dimagi  
> m: +1.781.428.5419 | skype: sheel\_shah
