Drools比较工作记忆中的对象

时间:2017-11-28 17:35:35

标签: drools

我试图在工作内存中累积类似的对象,并根据对象属性设置动作。我的规则:由同一提供者在同一天为同一天完成3个或更多程序。条件:相同的服务日期和相同的提供者ID操作:第一个程序为100%,第二个程序为50%,剩余为25%。每个订单项都包含有关该过程的详细信息。

我的模型对象:

public class LineItem  {

  private Date dateOfService;
  private String procedureCode;
  private String providerID;
  private double billedAmount;
  private double allowableAmount;

  //getters and setters
}

Drools规则:

**rule "Multiple Procedures done on the same day by Same Provider"**
lock-on-active true
when
    $lineItem1 : LineLevelData ( $dateOfService : dateOfService , $providerId : providerId, reasonCode == null, $lineNumber : lineNumber ) 
    and
    $lineItem2 : LineLevelData ( lineNumber!= $lineNumber , dateOfService == $dateOfService , providerId == $providerId, reasonCode == null ) 
    and
    accumulate( $lineItem: LineLevelData( dateOfService == $dateOfService , providerId == $providerId, reasonCode == null );
    $list: collectList( $lineItem ) ) 

then 

    System.out.println("List size: " + $list.size () );
    for ( int i = 0; i < $list.size(); i++ ){
        LineLevelData lineItem = (LineLevelData)$list.get(i);
        if(i == 0){
            modify(lineItem){ setReimbursementAmount(0.8* ( lineItem.getBilledAmount() ) ) 
            };
            System.out.println("Line Number: " + lineItem.getLineNumber() );
        }       
        else if(i == 1){
            modify(lineItem) {  setReimbursementAmount(0.5* (lineItem.getBilledAmount() ) ) 
            };
            System.out.println("Line Number: " + lineItem.getLineNumber() );
        }

        else {
            modify(lineItem ){ setReimbursementAmount(0.25* (lineItem.getBilledAmount() ) ) 
            };
            System.out.println("Line Number: " + lineItem.getLineNumber() );
        }
    }

Java代码:

LineLevelData line1Item = new LineLevelData();
line1Item.setLineNumber(1);
line1Item.setProcedureCode("99201");
line1Item.setDateOfService(new GregorianCalendar(2017, 9, 15).getTime());
line1Item.setBilledAmount(1000);
line1Item.setProviderId("670112");
billLineItems.add(line1Item);

LineLevelData line2Item = new LineLevelData();
line2Item.setLineNumber(2);
line2Item.setProcedureCode("99205");
**line2Item.setDateOfService(new GregorianCalendar(2017, 8, 20).getTime());
line2Item.setProviderId("670118");**
line2Item.setBilledAmount(1500);

billLineItems.add(line2Item);

LineLevelData line3Item = new LineLevelData();
line3Item.setLineNumber(3);
line3Item.setProcedureCode("99049");
**line3Item.setDateOfService(new GregorianCalendar(2017, 8, 20).getTime());
line3Item.setProviderId("670118");**
line3Item.setBilledAmount(1000);
billLineItems.add(line3Item);

LineLevelData line4Item = new LineLevelData();
line4Item.setLineNumber(4);
line4Item.setProcedureCode("99058");
**line4Item.setDateOfService(new GregorianCalendar(2017, 8, 20).getTime());**
line4Item.setBilledAmount(520);
**line4Item.setProviderId("670118");**
billLineItems.add(line4Item);


//Inserting facts in working memory
for(LineLevelData billLineItem : buildBillLineItems()){
    kSession.insert(billLineItem);
    log.info("Inserted Line Item : " + billLineItem.getLineNumber());
            }
int rulesFired =  kSession.fireAllRules(new RuleNameEqualsAgendaFilter("Multiple Procedures done on the same day by Same Provider"));

根据我的测试,上面的行号为2,3和4的行应该更新。相反,我得到第1,3和4行。

规则输出:

List size: 3
Line Number: 4
Line Number: 3
Line Number: 1
Multiple Procedures rule is fired...Wed Sep 20 00:00:00 CDT 2017
===========Rule Fired============ : MULTIPLE PROCEDURES DONE ON THE SAME DAY BY SAME PROVIDER
No. of Rules fired: 1

 Line Item Number: 1
 Billed amount: 1500.0
 Reimbursable amount: 375.0
 Reason Code: CHI
 Message: Coverage for all subsequent procedures is 25%
 Line Item Number: 4
 Billed amount: 520.0
 Reimbursable amount: 416.0
 Reason Code: NR
 Message: Submit to Nurse Review. 100% of UCR at 80th percentile. 
 Line Item Number: 3
 Billed amount: 1000.0
 Reimbursable amount: 500.0
 Reason Code: PHY
 Message: Manual review is required. 50% coverage for secondary procedure. 
 **Line Item Number: 2
 Billed amount: 1000.0
 Reimbursable amount: 0.0
 Reason Code: null
 Message: null**

0 个答案:

没有答案