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

Managing a Business Process

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 Business processes topic for descriptions of the concepts that you need to know when creating the artifacts:

Before you begin,

  • Download the product installer from here, and run the installer.
    Let's call the installation location of your product the <EI_HOME> directory. This is located in a place specific to your OS as shown below:
    OSHome directory
    Mac OS/Library/WSO2/EnterpriseIntegrator/6.6.0
    WindowsC:\Program Files\WSO2\EnterpriseIntegrator\6.6.0\
    Ubuntu/usr/lib/wso2/EnterpriseIntegrator/6.6.0
    CentOS/usr/lib64/EnterpriseIntegrator/6.6.0
  • Select the relevant WSO2 Integration Studio based on your operating system and download it from here.
    The path to this folder is referred to as <EI_TOOLING> throughout this tutorial.

    Getting an error message? See the troubleshooting tips given under Installing WSO2 Integration Studio.

  • You need to try out the Using the Gmail Connector tutorial before trying out this tutorial as the Gmail connector that is used in this tutorial is configured using your client ID and secret.
  • Create STMP an email account to send out emails to users that want to cancel an appointment using the Business Process Server (e.g., no-reply@foo.com).


Let's get started!

Configuring the Integration artifacts

  1. Open the ESB Config project that you used when trying out the Using the Gmail Connector tutorial.
  2. Open the PaymentRequestProcessingSequence.xml file that is inside the SampleServices > src > main > synapse-config > sequences directory.
  3. Add an Enrich mediator next to the Call mediator from the Mediators pallet to add the appointment cancellation link to the email that is being sent to the patient. 
  4. Select the Enrich mediator, go to the Properties tab, and update the following:

    FieldValue
    Source TypeSelect inline from the drop-down list.
    Source XML

    Click Browse, add the code given below, and click OK.

    <cancellation_link>https://localhost:9445/bpmn-explorer/</cancellation_link>

    You need to add this link so that it appears in the appointment confirmation email. You can cancel the appointment by clicking this link and starting the appointment cancellation business process.

    Target ActionSelect child from the drop-down list.
    Target XPathClick Browse, add //jsonObject, and click OK.
  5. Save the changes you made to the  PaymentRequestProcessingSequence.xml file.

Creating the appointment cancellation process using BPMN

  1. Open WSO2 Integration Studio.
  2. Go to BP Project → BPMN.
  3. Create a new project named AppointmentCancellation.
  4. Click Finish.
  5. Right-click the project in the navigator, go to New → Other, and select BPMN diagram.
  6. Select the AppointmentCancellation/src/main/resources/diagrams directory as the parent folder, and enter AppointmentCancellation.bpmn for the File name.
  7. Click Next, select the option to create an empty diagram as shown below, and click Finish.
  8. Let's start drawing the BPMN process diagram for the appointment cancellation process in 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 to the canvas, and then update the properties and configurations of each activity as explained below.
    1. Add a StartEvent from the Start Event palette.
    2. Select the Properties tab, click Form, click New, update the following, and click OK.

      IdpatientName
      NameName of the Patient
      Typestring
      RequiredTrue

    3. Repeat the above step and add the following records:

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

    4. Add a REST Task from the WSO2 Tasks palette.

      Select the Properties tab, click General, give the Name as Get Appointment, click Main config and update the following:

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


    5. Add an Exclusive Gateway from the Gateway palette.
    6. Add a User Task from the Task palette 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 add the following:

      IdNameTypeReadableWritableRequired
      approveCancellationDo You Approve the
      Appointment Cancellation Request?
      enumTrueTrueTrue

      Click New next to Form values and add the following:

      IdName
      approveApprove
      rejectReject

    9. Repeat the above step to add the following new records.

      IdNameTypeVariableReadableWritableRequired
      AppNoAppointment NumberlongappointmentNoTrueFalseTrue
      cancellationReasonReason For The CancellationstringreasonTrueFalseTrue
      doctorNameName of the DoctorstringdoctorTrueFalseTrue

    10. Add another Exclusive Gateway from the Gateway palette.
    11. Add a REST Task from the WSO2 Tasks palette.

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

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

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

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

      To${email}
      FromEnter a valid SMTP email address.
      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.


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

      To${email}
      FromEnter a valid SMTP email address.
      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.
  9. 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.
  10. 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.
  11. Click 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.
  12. Click 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.
  13. Click the arrow leading to the Appointment Control Task, open the General tab that is under properties and note the Id.
    Example:
  14. Click the first exclusive gateway, open the General tab that is under properties, and select the ID you noted in the above steps as the value for Default flow.

  15. Save all the changes you have made.
  16. Click Window -> Show View -> Other in the top menu of WSO2 Integration Studio.
  17. Type Package Explorer in the search bar, select it, and click Open.
  18. In the Package Explorer, right-click the AppointmentCancellation project and select Create deployment artifacts

    This will create the 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 from 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="<ENTER_A_VALID_SMTP_EMAIL_ADDRESS>"/>
      <property name="mailServerUseTLS" value="true"/>
      <property name="mailServerUsername" value="<ENTER_A_VALID_SMTP_EMAIL_ADDRESS>"/>
      <property name="mailServerPassword" value="<ENTER_THE_EMAIL_PASSWORD>"/>

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

  1. Start the Business Process profile in WSO2 EI by executing one of the following commands:

  2. Open the management console from  https://localhost:9445/carbon/.
  3. Log in using admin as the username and password.
  4. Go to Main -> Manage -> Add ->BPMN and upload the AppointmentCancellation.bar file by browsing in the workspace directory of your WSO2 Integration Studio instance as shown below. 

Starting the Message Broker profile

Let's start the Message Broker profile:

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. To do this, open the <EI_HOME>/conf/jndi.properties file and update the connection factories and queues at the beginning of the file as follows:

# 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

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

If you do not already have an ESB server added to WSO2 Integration Studio, follow the instructions in the previous tutorial.

If you have already added the ESB profile server and deployed SampleServicesCompositeApplication (in a previous tutorial):

  1. Go to the Servers tab and click  to start the server. 
  2. Right-click SampleServicesCompositeApplication and click Redeploy as shown below.

The server Console will indicate that the CApp has been redeployed successfully.

Starting the back-end service

Download and start the back-end service that will process appointment requests:

  1. Download the JAR file of the back-end service.
  2. Open a terminal and navigate to the location where your saved the back-end service.

  3. Execute the following command to start the service:

    java -jar Hospital-Service-JDK11-2.0.0.jar

The Healthcare service is now active and you can start sending requests to the service.

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 appointments on three separate dates. You will receive confirmation emails for all of the appointments.

  1. Create a JSON file named request.json with a request payload as shown below. Note the following when you create the request payloads.

    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": "2025-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 @request.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: 
    {"appointmentNo":1,"doctorName":"thomas collins","patient":"John
    Doe","actualFee":7000.0,"discount":20,"discounted":5600.0,"paymentID":"8c6e153e-4034-4d5a-b011-391553b15a8f","status":"Settled","cancellation_link":"https://localhost:9445/bpmn-explorer/"}

When configuring the artifacts, you set conditions to reject the cancellation request if it is less than 2 days. Therefore, you can also try setting the appointment date to less than 2 days from the current date and schedule a request. You won't be able to cancel the request when trying out the steps under Canceling appointments using the BPMN explorer.

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.
  5. Let's cancel the appointment that was confirmed.
    1. Enter the appointment details of the appointment that was emailed to you and click Start. Be sure to enter the correct appointment number and email address.
    2. Since the appointment is more than two days from the current date, the appointment cancellation will be approved automatically. 
    3. You will receive an email confirming that the appointment cancellation is approved.
  • If you try to cancel an appointment that is less than two days away from the current date, you receive an email rejecting the cancellation of your appointment.
  • If the appointment date is exactly two days from the current date the appointment cancellation will neither be approved nor rejected automatically. To cancel the request, follow the steps given below.
    1. Click TASKS on the menu bar and see that a manual task has been created for the appointment cancellation. 
    2. You can now assume the role of an administrator in the hospital service and determine if the appointment cancellation should be approved or rejected. 
    3. Let's approve the request: Select Approve and click Complete Task in the appointment control task shown above.
    4. You will receive an email confirming that the appointment cancellation is approved.

Congratulations, you have successfully completed the tutorial! 

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