[Documentation Index]

WSO2 BRS - Samples : HealthCare Service

This guide demonstrates a service for recommending dose for a patient . This service uses business rules.

Please follow the User Guide before proceeding with this sample, if you have not already followed the User Guide.

Contents

HealthCare Service

Rules

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

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

Facts

There are one fact and one result - patient and dose.

              
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

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

Deploying Service

You can either create an .aar file and upload or create a rule service using rule service wizard UI. Please refer the User Guide for more information.

Testing Sample

You can use Try-it tool with the requests similar to the following.

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

Another request

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

You can also use the code generation. There is an option for code generation in the services management page. A client using generated stub codes is shown bellow. Codes was generated with option - Unpacks the databinding classes.

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();
        }
    }

References