Next I’m going to show you how to integrate a Rule Repository into a simple application. The source code is available for download. If you are not familiar with Windows Presentation Foundation and don’t understand some of the code, that’s ok. We are going to focus on a very small portion of standard c-sharp code.
First, this demo application is going to make two identical, in-memory copies of a Claim object that contains test data.
Next, we want to integrate our Rule Repository to run any rules against the second copy of the Claim. Currently, for testing, it is manually changing the patient’s birth date.
Finally, it databinds both copies of the Claim so that we can visually compare them to see what has changed.
I’m going to run the application before integrating our Rule Repository so you can see what to expect. Notice that the patient birth date is highlighted and displays the modified and original value.
The first step that I am going to take to integrate the rules repository is to create a method called RunClaimRules. This method is going to take a single argument, the Claim object.
In the constructor, instead of manually changing the patient birth date, I am going to pass the second copy of the claim object to my new function.
Inside of the RunClaimRules method I am going to create a new ZipfileRuleRepository object which is in the Enigma.Rules Engine namespace. The constructor takes a single argument, the filename of the rule repository.
Next I will create a RuleSet object and connect it to the repository. I will call the LoadRules method with no arguments, to read all of the rules from the repository.
Finally, I want to call the ruleset’s execute method. Remember, in the repository’s execution plan, we created an argument called Claim? We need to pass that argument into the execute method somehow. The execute method has two overloads. You can pass in an object where the property names match the execution plan arguments. Or you can use a string, object generic dictionary.
I am going to use the first overload and pass in an anonymous class.
That’s all it takes to integrate our rule repository. I will run the application again and you can see that our simple rule from the previous tutorial erased the doctor’s tax id because the DestinationId is 333. As an exercise you can now use the rule editor to modify the rule that we created, or even add more rules to the repository. When you run this application again you won’t have to change any code to see your rule changes applied.