com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_link3' is unknown.

HealthCare Service

This sample demonstrates a service for recommending dosage for a patient through the use of business rules. 

Prerequisites

To run this sample:

Sample configuration

Sample rule definition

Rules

Rule 1 : If the recommended medication is one of Amoxicillin, Cefuroxime, and Levofloxacin, and if the patient is older than 15 or younger than 60 years, the dosage is 500mg every 24 hours for 14 days.

Rule 2 : If the recommended medication is one of Amoxicillin, Cefuroxime, and Levofloxacin, and if the patient is older than 15 or younger than 60 years, and is the patient's Creatinine Level is 1.5, then the dosage is 250 mg every 24 hours for 14 days.
 

Facts

There is one fact named patient. The result of the rule execution is dosage.

 

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.

 

<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 service

To execute the service, run the ant command from the  <PRODUCT_HOME>/samples/healthcare.service directory to run the HealthCare Service.

Before executing this service, it is recommended that you refer Exposing Rules as Services which explains in detail the process of writing and deploying a business rule.

 

Deploying and testing the service

  1. Deploy the rule service through the BRS management console. You can follow either of the two methods:

    • Bundle all artifacts in an .aar file and upload it (Rule Service -> Upload menu).
    • Create using the Rule Service wizard UI (Rule Service -> Create menu).

    The above steps are discussed in detail in section Exposing Rules as Services.
     
  2. After deployment, click on List under Services in the main tab of the management console. The service will appear in the Deployed Services page.
  3. Click HealthCare Service to access the dashboard of the service.
  4. Click Try this service in the Client Operations widget of the dashboard to invoke the Try-it tool.
  5. Issue a request similar to the following in the Try-it tool.

    <medication>Cefuroxime</medication>
    <age>54</age>
    <creatinineLevel>1.2</creatinineLevel>

    The response would be as follows:

    <message>250 mg every 24 hours for 14 days</message>


  6. Send another request as follows:

    <medication>Amoxicillin</medication> 
    <age>20</age>


    You would get the following response:

    <message>500 mg every 24 hours for 14 days</message>
  7. Alternatively, you can click Generate Axis2 Client in the Client Operations widget of the dashboard to invoke the service. A client using generated stub codes is shown below where the codes were generated with the Unpacks the databinding  classes check box checked.

    package org.wso2.carbon.samples;
    
    import org.apache.axis2.AxisFault;
    import org.wso2.carbon.samples.healthCareService.patientDetail.Dose;
    import org.wso2.carbon.samples.healthCareService.patientDetail.Patient;
    import org.wso2.carbon.samples.healthCareService.patientDetail.PatientDetail;
    import org.wso2.carbon.samples.healthCareService.stub.HealthCareServiceStub;
    import java.rmi.RemoteException;
    
    public class HealthCareServiceTestCase {
    
        public static void main(String[] args) {
    
            try {
                HealthCareServiceStub healthCareServiceStub =
                        new HealthCareServiceStub("http://localhost:9763/services/HealthCareService");
    
                PatientDetail patientDetail = new PatientDetail();
                Patient patient = new Patient();
                patient.setAge(43);
                patient.setCreatinineLevel(1.0);
                patient.setMedication("Levofloxacin");
    
                Patient[] patients = new Patient[1];
                patients[0] = patient;
                patientDetail.setPatientDetail(patients);
    
                Dose[] doses = healthCareServiceStub.recommendDose(patients);
                String result = doses[0].getMessage();
                System.out.println(result);
    
            } catch (AxisFault axisFault) {
                axisFault.printStackTrace();
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }

     

 

 

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.