Well, an accumulate wouldn't be so bad...

when
    $claim : Claim();
    accumulate( $sil: ServiceLineInfo( ) from $claim.getServiceLineInfoList();
         $min: min(
$sil.getServiceRelatedDates().getServiceDates().getBeginDate() ),
         $max: max(
$sil.getServiceRelatedDates().getServiceDates().getEndDate() ) )
then

..if you wouldn't have to guard against those dates on the third level
down being null, but you can add the constraints to the
ServiceLineInfo pattern. If just one these could be null you'll need a
second accumulate, but that would be strange (I think).

That said, the whole shebang is a simple computation that might better
be implemented in the Claim class, as a method.

-W


On 21/02/2014, LarryW <lwake...@tmghealth.com> wrote:
> I'm really new to Drools so this is probably a basic question.  However, it
> has consequences as to coding style.
>
> I have to go through a class and find the lowest and highest dates.  I have
> a simple rule that works, below.  I know there's also a way to do it using
> accumulate, but it's ugly and probably not easily maintainable.  Someone
> told me I should not use java in the THEN segment, but I don't see anyway
> around it.  Is there a better way to write this rule than what I have here?
>
>
> The problem is that the Then segment need only fire once, while the file
> may
> contain any number of service lines.  You have to process all service lines
> before you know if the dates are the lowest and highest.
>
> rule "FindLowestHighestDates"
> when
>         $claim : Claim();
>
> then
>         LocalDate lowestBeginDate =
> $claim.getServiceLineInfoList().get(0).getServiceRelatedDates().getServiceDates().getBeginDate();
>
>         LocalDate highestEndDate =
> $claim.getServiceLineInfoList().get(0).getServiceRelatedDates().getServiceDates().getEndDate();
>
>
>         for (ServiceLineDetail srvc: $claim.getServiceLineInfoList())
>         {
>                 DateRange relDates =
> srvc.getServiceRelatedDates().getServiceDates();
>
>                 if (relDates.getBeginDate() != null &&
> relDates.getBeginDate().isBefore(lowestBeginDate))
>                 {
>                         lowestBeginDate = relDates.getBeginDate();
>                 }
>
>                 if (relDates.getEndDate() != null &&
> relDates.getEndDate().isAfter(highestEndDate))
>                 {
>                         highestEndDate = relDates.getEndDate();
>                 }
>         }
>
>         ClaimDates cd = $claim.getClaimDates();
>         if (cd == null) cd = $claim.createClaimDates();
>
>         DateRange sd = cd.getServiceDates();
>         if (sd == null) sd = cd.createServiceDates();
>
>         sd.setBeginDate(lowestBeginDate);
>         sd.setEndDate(highestEndDate);
> end
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Find-the-lowest-and-highest-dates-tp4028231.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to