Couldn't you accomplish what you are looking for using the "from collect"

http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/html_single/index.html#d0e3968

So, applied to your example it would be something like the following.  Note, I'm not sure how patient is tied to your LabResult, but I added in what I thought it might be b/c you'd want to constrain the fact that there were 3 or more results for a given patient, not just 3 or more lab results for all patients in the current working memory.

import java.util.ArrayList

rule "patients that have at least 3 consecutive LabResults with value<1 in the last month"
when
        $patient: Patient()
        $results : ArrayList( size >= 3 )
                            from collect( LabResult( patient == $patient, value < 1, eval( inLastMonth(date) ) )
then
    # Do Something
end


--- On Wed, 7/30/08, Yoni Mazar <y.mazar@gmail.com> wrote:
From: Yoni Mazar <y.mazar@gmail.com>
Subject: [rules-users] Finding a sequence within the data
To: rules-users@lists.jboss.org
Date: Wednesday, July 30, 2008, 12:12 PM

Hi again,

Sorry for nagging, but I'm failing again and again to implement simple
business logic using rules.
Lets assume, we have LabResult facts with date and value fields. The
business requirement is to detect "patients that have at least 3
consecutive
LabResults with value<1 in the last month".
detecting one fact is simple:
LabResult(value<1 && eval(inLastMonth(date)))
But detecting 2 consecutive facts, actually requires that there is not a
third fact in the middle with value >= 1!
something like:

LabResult(value<1, date1:date, eval(inLastMonth(date1))),
LabResult(value<1, date2:date, eval(inLastMonth(date2))),
eval(date1.before(date2)),
not( LabResult(value>=1, date3:date, eval(inLastMonth(date3))),
eval(date1.before(date3))
eval(date3.before(date2)) )

Now, imagine how to detect 3 consecutive facts...

Does someone has a simple idea how to implement this? How comes that one
English sentence is translated to so many lines of code?

Thanks for the help, Yoni

--
View this message in context:
http://www.nabble.com/Finding-a-sequence-within-the-data-tp18738051p18738051.html
Sent from the drools - user mailing list archive at Nabble.com.

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users