<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><br>Couldn't you accomplish what you are looking for using the "from collect"<br><br>http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/html_single/index.html#d0e3968<br><br>So, applied to your example it would be something like the following.&nbsp; 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.<br><br>import java.util.ArrayList<br><br>rule "patients that have at least 3 consecutive LabResults with value&lt;1 in the last month"<br>when<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $patient: Patient()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $results : ArrayList( size &gt;= 3 )<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; from collect( LabResult( patient == $patient, value &lt; 1, eval( inLastMonth(date) ) )<br>then<br>&nbsp;&nbsp;&nbsp; # Do Something<br>end<br><br><br>--- On <b>Wed, 7/30/08, Yoni Mazar <i>&lt;y.mazar@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">From: Yoni Mazar &lt;y.mazar@gmail.com&gt;<br>Subject: [rules-users] Finding a sequence within the data<br>To: rules-users@lists.jboss.org<br>Date: Wednesday, July 30, 2008, 12:12 PM<br><br><pre>Hi again,<br><br>Sorry for nagging, but I'm failing again and again to implement simple<br>business logic using rules.<br>Lets assume, we have LabResult facts with date and value fields. The<br>business requirement is to detect "patients that have at least 3<br>consecutive<br>LabResults with value&lt;1 in the last month".<br>detecting one fact is
 simple:<br>LabResult(value&lt;1 &amp;&amp; eval(inLastMonth(date)))<br>But detecting 2 consecutive facts, actually requires that there is not a<br>third fact in the middle with value &gt;= 1!<br>something like:<br><br>LabResult(value&lt;1, date1:date, eval(inLastMonth(date1))), <br>LabResult(value&lt;1, date2:date, eval(inLastMonth(date2))), <br>eval(date1.before(date2)),<br>not(   LabResult(value&gt;=1, date3:date, eval(inLastMonth(date3))),<br>        eval(date1.before(date3))<br>        eval(date3.before(date2)) )<br><br>Now, imagine how to detect 3 consecutive facts...<br><br>Does someone has a simple idea how to implement this? How comes that one<br>English sentence is translated to so many lines of code?<br><br>Thanks for the help, Yoni<br><br>-- <br>View this message in context:<br>http://www.nabble.com/Finding-a-sequence-within-the-data-tp18738051p18738051.html<br>Sent from the drools - user mailing list archive at
 Nabble.com.<br><br>_______________________________________________<br>rules-users mailing list<br>rules-users@lists.jboss.org<br>https://lists.jboss.org/mailman/listinfo/rules-users<br></pre></blockquote></td></tr></table><br>