Search code examples
drools

Creating Drool Decision Table


So I wanted to try my hand out creating a decision table from a rule that I've already made in a .drl file. Then I wanted to convert it back to a .drl. Didn't see any nifty conversions from drl to xls/csv nor was the jboss documentation comprehensive enough. It could be the rule is too complicated for a simple decision table but I was hoping this community could help me out.

Here is the drl:

    rule "Patient: Compute BMI"
  when        
    $basic : BasicInfoModel(
      notPresent('bmi'),
      isPresent('height'),
      isPresent('weight'),
      $height : value('height', 0.0),
      $weight : value('weight', 0.0))
  then
    modify($basic){
      put('bmi', $weight / Math.pow($height,2))
    };
end

So this rule basically looks at an objects weight and height field and then computes the bmi. I've tried basically taking what I have and putting it into the decision table format but with little success. Nothing really parses (I'm just using the droolsSpreadSheet.compile and printing out what I get, which is a whole of empty rules). Any help would be appreciated!

Update: This is what my excel sheet looks like This is what my rule parses out to:

package DROOLS;
//generated from Decision Table
import basic.BasicInfoModel;
// rule values at A11, header at A6
rule "Computing BMI"
    when
        $patient:BasicInfoModel(notPresent('bmi'), isPresent('height'),isPresent('weight'), $height:value('height', 0.0), $weight:value('weight',0.0) == "20,4")
    then
end

Update #2: I think I figured out my parse issues. Here is my new and improved spreadsheet., Basically found out that I cannot have the Computing BMI: data blank, there must be something in there in order to have the rule parse (Which isn't entirely clear in the docs I read, though that could be because my experience with decision tables is novice putting it lightly).

So now the compile looks more like what I want:

 // rule values at A11, header at A6
rule "Computing BMI"
    when
        $patient:BasicInfoModel(notPresent('bmi'), isPresent('height'), isPresent('weight') == "TRUE")
        $weight:value('weight',0.0), $height:value('height', 0.0)
    then
        modify($patient){put('bmi', $weight / Math.pow($height,2))};
end

Can someone confirm that I have to have real, specific data in the rules in order for them to parse? Can I just use injection elsewhere? Perhaps I should ask a new question on this.


Solution

  • So the answer is yes, you do need parameters, but what I didn't know was that the data doesn't have to be hardcoded like every example I've come across. Thanks to stumbling onto this answer. So now the table looks like this. I hope this helps others who've come across this issue. Also my recommendation is to just make your drools in a .drl rather than go through the spreadsheet, unless you have a bunch of rules that are pretty much copy and paste replicas. That's my two cents anyways.