This documentation is for WSO2 Enterprise Integrator version 6.1.1 . View documentation for the latest release.

All docs This doc
Skip to end of metadata
Go to start of metadata

In this tutorial, you will use a BPMN process defined in the Business Process profile of WSO2 EI to manage the process of canceling a doctor's appointment. The appointment cancellation process should be designed according to the following requirement:

  • The patient should be allowed to cancel the appointment (unconditionally) if the appointment date is at least two days away.
  • The patient should not be allowed to cancel the appointment if the appointment date is less than two days away.
  • If the appointment date falls on the second day from the current date, the patient can request for appointment cancellation, which should be manually approved by an administrator.
  • The patient should receive email notifications informing if the appointment cancellation is accepted or rejected.

See the following topics for a description of the concepts that you need to know when creating the artifacts:

Before you begin,

  1. Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.
  2. Download the WSO2 EI ZIP file from here, and then extract the ZIP file.
    The path to this folder will be referred to as <EI_HOME> through out this tutorial.
  3. Select and download the relevant EI tooling ZIP file based on your operating system from here and then extract the ZIP file.
    The path to this folder will be referred to as <EI_TOOLING> through out this tutorial.
    For more detailed installation instructions, see the Installing Enterprise Integrator Tooling.
  4. Download the CAR file that contains the integration artifacts from the previous tutorial from here.
  5. Download the MSF4J service from here and copy the JAR file to <EI_HOME>/wso2/msf4j/deployment/microservices folder. The back-end service is now deployed in the MSF4J profile of WSO2 EI.

Let's get started!

Creating the appointment cancellation process using BPMN

  1. In WSO2 EI Tooling, open the Developer Studio dashboard by clicking the Developer Studio menu and choosing Open Dashboard
  2. Select BPMN Project and create a new project named AppointmentCancellation.
  3. Click Finish and click Yes in the Create an Activiti Project window.

  4. In Developer Studio Dashboard, select BPMN Diagram. Create a file named AppointmentCancellation.bpmn and select the AppointmentCancellation/src/main/resources/diagrams directory as the parent folder.
  5. Click Next, select the option to create an empty diagram as shown below, and click Finish.
  6. Let's start drawing the BPMN process diagram for the appointment cancellation process. The AppointmentCancellation canvas. The Palette on the right side of the AppointmentCancellation canvas contains all the activity symbols that will be used for drawing the process as shown below.

    Let's get started. You can easily drag and drop the activities from the Palette the canvas, and then update the properties and configurations of each activity as explained below.
    1. Add a StartEvent activity.
    2. Select the Properties tab, click Form, click New, update the following and click OK.

      IdpatientName
      NameName of the Patient
      Typestring
      RequiredTrue

    3. Repeat clicking New and adding the following to add the other form properties one by one.

      IdNameTypeRequired
      appointmentNoAppointment NumberlongTrue
      doctorName of the DoctorstringTrue
      reasonReason for cancellationstringTrue
      emailEmail AddressstringTrue

    4. Add a REST Task and name it Get Appointment.


      Select the Properties tab and click Main config and update the following:

      Service URLhttp://localhost:9090/healthcare/appointments/validity/${appointmentNo}
      HTTP methodGet
      Output Variable MappingsnoOfDays:$.status


    5. Add a Parallel Gateway.
    6. Add a User Task and name it Appointment Control Task.
    7. Click Properties, click Main config  and give admin as the Assignee.  
    8. In the Properties tab click Form, click New and update the following.

      To add the two Form values, click New and give the Id and Name and click OK as shown in the example below.

    9. Repeat clicking New and adding the following to add the other form proeprties one by one.

      IdNameTypeVariableReadableWritableRequired
      AppNoAppointment NumberlongappointmentNoTrueFalseTrue
      cancellationReasonReason For The CancellationstringreasonTrueFalseTrue
      doctorNameName of the DoctorstringdoctorTrueFalseTrue

    10. Add another Parallel Gateway.
    11. Add a REST Task.

      Select the Properties tab and click Main config and update the following:

      Service URLhttp://localhost:9090/healthcare/appointments/validity/${appointmentNo}
      HTTP methodDELETE
      Output Variable Mappingsstatus:$.status


    12. Add a MailTask below the second Parallel Gateway and name it Reject cancellation Task.

      Select the Properties tab and click Main config and update the following:

      To${email}
      Fromwso2com@gmail.com
      SubjectAppointment cancellation rejected
      HtmlAppointment cancellation request with Appointment Number ${appointmentNo} has been rejected. Thank you.
      Administration Department 


    13. Add another MailTask above the second Parallel Gateway and name it Approve Cancellation Task.

      To${email}
      Fromwso2com@gmail.com
      SubjectAppointment cancellation successful
      HtmlAppointment cancellation request with Appointment Number ${appointmentNo} has been approved. Thank you.
      Administration Department 


    14. Link each activity by hovering over the element, selecting the arrow sign and dragging it to the connecting element as shown below.
  7. Click the arrow leading from the first Exclusive Gateway to the Approve Cancellation Task, and in the Main config section of the Properties tab add the ${noOfDays >2} condition.
  8. Click the arrow leading from the first Exclusive Gateway to the Reject Cancellation Task, and in the Main config section of the Properties tab add the ${noOfDays<2} condition.
  9. Click on the arrow leading from the second Exclusive Gateway to the Rest Task, and in the Main config section of the Properties tab add the  ${approveCancellation == 'approve'}  condition.
  10. Click on the arrow leading from the second Exclusive Gateway to the Reject Cancellation Task, and in the Main config section of the Properties tab add the ${approveCancellation == 'reject'}  condition.
  11. In the Package Explorer, right-click the AppointmentCancellation project and select Create deployment artifacts. This will create a AppointmentCancellation.bar file in the deployment folder.

Deploying the BPMN process in the Business Process profile

Before you begin, apply the following configurations to the business process profile:

  1. Copy the following JARs to the <EI_HOME>/lib directory.
  2. Open the activiti.xml file in the <EI_HOME>/wso2/business-process/conf directory and add the following properties under <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> as shown below to enable the Gmail configurations.

    • Replace the "mailServerHost" and "mailServerPort" property values as follows:

      <property name="mailServerHost" value="smtp.gmail.com"/>
      <property name="mailServerPort" value="587"/>
    • Add the following properties:

      <property name="mailServerDefaultFrom" value="wso2eidemo@gmail.com"/>
      <property name="mailServerUseTLS" value="true"/>
      <property name="mailServerUsername" value="wso2eidemo@gmail.com"/>
      <property name="mailServerPassword" value="wso2carbonuser"/>

You can now deploy the .bar file of the BPMN process using the management console of the business process profile in WSO2 EI.

  1. Open a terminal and navigate to the <EI_HOME>/wso2/business-process/bin directory.
  2. Start the Business Process profile in WSO2 EI by executing one of the following commands:
    • On Linux/Mac OS:  sh wso2server.sh
    • On Windows:  wso2server.bat --run

  3. Open the management console from https://localhost:9445/carbon/.
  4. Log in using admin as the username and password.
  5. Go to Main -> Manage -> Add ->BPMN and upload the AppointmentCancellation.bar file as shown below. 

Deploying the ESB artifacts in the ESB profile

Before you start the ESB profile, configure the profile so that it can connect to the Message Broker profile for reliable messaging:

  1. Open the <EI_HOME>/conf/jndi.properties file and update the connection factories and queues at the beginning of the file so that it now looks like this:

    # register some connection factories
    # connectionfactory.[jndiname] = [ConnectionURL]
    connectionfactory.QueueConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5675'
    connectionfactory.TopicConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5675'
    # register some queues in JNDI using the form
    # queue.[jndiName] = [physicalName]
    queue.MyQueue = example.MyQueue
    queue.PaymentRequestJMSMessageStore=PaymentRequestJMSMessageStore
  2. Copy the following JARs from the <EI_HOME>/wso2/broker/client-lib folder to the <EI_HOME>/lib folder.
    • andes-client-3.2.13.jar
    • geronimo-jms_1.1_spec-1.1.0.wso2v1.jar
    • org.wso2.securevault-1.0.0-wso2v2.jar

Now, let's start the ESB profile in WSO2 EI and upload the ESB artifacts:

  1. Open a terminal and navigate to the <EI_HOME>/bin directory.
  2. Execute one of the following scripts to start the ESB profile of WSO2 EI.
    • On Windows: integrator.bat --run
    • On Linux/Mac OS: sh integrator.sh
  3. In your Web browser, navigate to the WSO2 EI management console using the following URL: https://localhost:9443/carbon/
  4. Log into the management console using the following credentials:
    • Username: admin
    • Password: admin
  5. Deploy the SampleServicesCompositeApplication_1.0.0.car as follows:

    1. On the Main tab of the management console, go to Manage -> Carbon Applications and click Add
    2. Click Choose File, select the SampleServicesCompositeApplication_1.0.0.car file that you downloaded, and click Upload

Starting the Message Broker profile

Let's start the Message Broker profile:

  1. Open a new command line terminal and navigate to the <EI_HOME>/wso2/broker/bin directory.
  2. Execute one of the following commands.
    • On Linux/Mac OS:  sh wso2server.sh
    • On Windows:  wso2server.bat

Starting the back-end service

To be able to send requests to the back-end service (which is an MSF4J service deployed in the MSF4J profile of WSO2 EI), you need to first start the MSF4J runtime:

  1. Open a terminal and navigate to the <EI_HOME>/wso2/msf4j/bin directory.
  2. Start the runtime by executing the MSF4J startup script as shown below.

    sh carbon.sh

The system is now ready to receive appointment reservation requests.

Sending requests to the ESB

To demonstrate how the BPMN process for appointment cancellation works, let's send three separate requests to the ESB profile of WSO2 EI. These requests will create three separate doctor's appointments on three separate dates. You will receive confirmation emails for all of the appointments.

  1. First, create JSON files with three separate request payloads as shown below. Note the following when you create the request payloads.

    Set the "appointment_date" as follows:

    • In request1.json, leave a gap less than 2 days between the current date and the "appointment_date".

    • In request2.json, leave a 2-day gap between the current date and the "appointment_date".
    • In request3.json, leave at least a 3-day gap between the current date and the "appointment_date".

    Make sure you provide a valid email address so that you can test the email being sent to the patient. 

    {
    "name": "John Doe",
    "dob": "1940-03-19",
    "ssn": "234-23-525",
    "address": "California",
    "phone": "8770586755",
    "email": "johndoe@gmail.com",
    "doctor": "thomas collins",
    "hospital": "grand oak community hospital",
    "cardNo": "7844481124110331",
    "appointment_date": "2017-04-02"
    }
    {
    "name": "John Doe",
    "dob": "1940-03-19",
    "ssn": "234-23-525",
    "address": "California",
    "phone": "8770586755",
    "email": "johndoe@gmail.com",
    "doctor": "thomas collins",
    "hospital": "grand oak community hospital",
    "cardNo": "7844481124110331",
    "appointment_date": "2017-04-02"
    }
    {
    "name": "John Doe",
    "dob": "1940-03-19",
    "ssn": "234-23-525",
    "address": "California",
    "phone": "8770586755",
    "email": "johndoe@gmail.com",
    "doctor": "thomas collins",
    "hospital": "grand oak community hospital",
    "cardNo": "7844481124110331",
    "appointment_date": "2017-04-02"
    }
  2. Open a command line terminal and navigate to the location where you have stored the above request payloads.
  3.  Execute the following command, which will send the request1.json payload as a request.

    curl -v -X POST --data @request1.json http://localhost:8280/healthcare/categories/surgery/reserve --header "Content-Type:application/json"

    You will see the response as follows:

    {"message":"Payment request successfully submitted. Payment confirmation will be sent via email."}

    An email will be sent to the provided patient email address with the following details:

    Subject: Payment Status
     
    Message: 
    {
    "Appointment Number": 1,
    "Doctor":"thomas collins",
    "patient":"John Doe",
    "actualFee":"7000.0",
    "discount":"0",
    "discounted":"7000.0",
    "status":"Settled",
    "cancellation link" : "https://localhost:9445/bpmn-explorer/"
    }
  4. Execute the following commands to send appointment reservation requests using the request2.json and request3.json payloads respectively.
  5. You will receive separate emails confirming the above appointments.

Canceling appointments using the BPMN explorer

Let's now look at how to cancel the doctor's appointments. If you successfully, completed the previous steps, you will now have three emails confirming three appointments. The cancellation link is provided in each mail. 

  1. Click the cancellation link in one of the mails, which will take you to the BPMN explorer
  2. Log in to the BPMN explorer using admin as the username and password.
  3. Click Processes and see that an appointment cancellation process is listed as shown below.
  4. Click Start to begin the cancellation process and the Start Process form will open as shown below.

    We will first cancel the appointment that was confirmed from the request1.json payload. That is, the appointment date should be less than two days from the current date. 
    1. Enter the appointment details in the above form and click Start. Be mindful of the following values:
      • Appointment Number: This should be the number you received in the appointment confirmation email.
      • Email Address: A notification email will be sent to this address after the cancellation process is completed. Be sure to enter a valid email address in this field.
    2. You will now receive an email rejecting the cancellation of your appointment because your appointment date is only two days from the current date.

    Now let's cancel the appointment that was confirmed from the request2.json payload. That is, the appointment date should be exactly two days from the current date.
    1. Click PROCESSES in the menu bar and start the AppointmentCancellation process again. The Start Process form will open again.
    2. Enter the appointment details of the second appointment that was emailed to you and click Start. Be sure to enter the correct appointment number and email address.
    3. Since the appointment falls exactly two days from the current date, the appointment cancellation will neither be approved or rejected automatically.
    4. Click TASKS on the menu bar and see that a manual task has been created for the appointment cancellation. 
    5. You can now assume the role of an administrator in the hospital service and determine if the appointment cancellation should be approved or rejected. 
    6. Let's approve the request: Select Approve and click Complete Task in the appointment control task shown above.
    7. You will receive an email confirming that the appointment cancellation is approved.

    Now let's cancel the appointment that was confirmed from request3.json. That is, the date of appointment should be more than two days away from the current date.
    1. Click PROCESSES in the menu bar and start the AppointmentCancellation process again. The Start Process form will open again.
    2. Enter the appointment details of the third appointment that was emailed to you and click Start. Be sure to enter the correct appointment number and email address.
    3. Since the appointment is more than two days from the current date, the appointment cancellation will neither be approved automatically. 
    4. You will receive an email confirming that the appointment cancellation is approved.
  • No labels