...
Facts
There is one fact named patient
. The result of the rule execution is dosage
.
Code Block | ||
---|---|---|
| ||
package samples.heathcare;
/**
* Patient
*/
public class Patient {
private String medication;
private int age;
private double creatinineLevel;
public String getMedication() {
return medication;
}
public void setMedication(String medication) {
this.medication = medication;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getCreatinineLevel() {
return creatinineLevel;
}
public void setCreatinineLevel(double creatinineLevel) {
this.creatinineLevel = creatinineLevel;
}
}
package samples.heathcare;
/**
* Dose
*/
public class Dose {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
} |
Rule Service Configuration (service.rsl)
An in-line rule set is used within the service.rsl file as follows.
Code Block | ||
---|---|---|
| ||
<ruleService name="HealthCareService" xmlns="http://wso2.org/carbon/rules" targetNamespace="http://com.test/HeathCareService"> <ruleSet> <rule resourceType="regular" sourceType="inline"> <![CDATA[ package HeathCareService import samples.heathcare.Patient; import samples.heathcare.Dose; rule "Rule one" no-loop true when Patient( ( medication in ( "Amoxicillin", "Cefuroxime", "Levofloxacin" ) ) && ( ( age > 16 ) && ( age < 60 ) ) && ( creatinineLevel == 0 ) ) then Dose msg = new Dose(); msg.setMessage("500 mg every 24 hours for 14 days"); insertLogical(msg); end rule "Rule two" no-loop true when Patient( ( medication in ( "Amoxicillin", "Cefuroxime", "Levofloxacin" ) ) && ( ( age > 16) && ( age < 60 ) ) && ( ( creatinineLevel > 0 ) && ( creatinineLevel < 1.5 ) ) ) then Dose msg = new Dose(); msg.setMessage("250 mg every 24 hours for 14 days"); insertLogical(msg); end ]]> </rule> </ruleSet> <operation name="recommendDose"> <input wrapperElementName="patientDetail" namespace="http://com.test/patientDetail"> <fact elementName="patientDetail" namespace="http://com.test/patientDetail" type="samples.heathcare.Patient"></fact> </input> <output wrapperElementName="patientDetailRespone" namespace="http://com.test/patientDetail"> <fact elementName="recommendDose" namespace="http://com.test/patientDetail" type="samples.heathcare.Dose"></fact> </output> </operation> </ruleService> |
Executing the Sample
To execute the sample, run the ant
command from the <BRS_Home>/samples/greeting.service
directory to run the HealthCare Service.
Info |
---|
Before executing this sample, it is recommended that you refer Exposing Rules as Services which explains in detail the process of writing and deploying a business rule. |
...