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 a description of the concepts that you need to know when creating the artifacts:
Before you begin,
Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.
Download the product installer from here, and run the installer.
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>throughout this tutorial.For more detailed installation instructions, see the Installing Enterprise Integrator Tooling.
Getting an error message? See the troubleshooting tips given under Installing Enterprise Integrator Tooling.
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.
Download the MSF4J service from here and copy the JAR file to
<EI_HOME>/wso2/msf4j/deployment/microservicesfolder. The back-end service is now deployed in the MSF4J profile of WSO2 EI.Create STMP an email account to send out emails to users that want to cancel an appointment using WSO2 Business Process Server (e.g., no-reply@foo.com).
Let's get started!
- 1 Configuring the Integration artifacts
- 2 Creating the appointment cancellation process using BPMN
- 3 Deploying the BPMN process in the Business Process profile
- 4 Starting the Message Broker profile
- 5 Deploying the ESB artifacts in the ESB profile
- 6 Starting the back-end service
- 7 Sending requests to the ESB
- 8 Canceling appointments using the BPMN explorer
Configuring the Integration artifacts
Open the Developer Studio project that you used when trying out the Using the Gmail Connector tutorial.
Open the
PaymentRequestProcessingSequence.xmlfile that is inside theSampleServices > src > main > synapse-config > sequencesdirectory.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.
Select the Enrich mediator, go to the Properties tab, and update the following:
Field
Value
Source Type
Select inline from the drop-down.
Source XML
Click the browse button, 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 on this link and starting the appointment cancellation business process.
Target Action
Select child from the drop-down.
Target XPath
Click the browse button, add
//jsonObject, and click OK.Save the changes you made to the
PaymentRequestProcessingSequence.xmlfile.
In WSO2 EI Tooling, open the Developer Studio dashboard by clicking the Developer Studio menu and choosing Open Dashboard, and select BPMN Project .
Create a new project named AppointmentCancellation.
Click Finish.
Click Open Perspective in the Open Associated Perspective? window.
In Developer Studio Dashboard, select BPMN Diagram.
Select the
AppointmentCancellation/src/main/resources/diagramsdirectory as the parent folder, and enterAppointmentCancellation.bpmnfor the File name.
Click Next, select the option to create an empty diagram as shown below, and click Finish.
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.Add a StartEvent from the Start Event palette.
Select the Properties tab, click Form, click New, update the following and click OK.
Id
patientName
Name
Name of the Patient
Type
string
Required
True
Repeat clicking New and adding the following to add the other form properties one by one.
Id
Name
Type
Required
appointmentNoAppointment Number
long
True
doctorName of the Doctor
string
True
reasonReason for cancellation
string
True
emailEmail Address
string
True
Add a REST Task from the WSO2 Tasks palette.
Select the Properties tab, click General and give the Name asGet Appointment, then click Main config and update the following:Service URL
http
://localhost:9090/healthcare/appointments/validity/${appointmentNo}HTTP method
GET
Output Variable Mappings
noOfDays:$.statusAdd an Exclusive Gateway from the Gateway palette.
Add a User Task from the Task palette and name it
Appointment Control Task.
Click Properties, click Main config and give
adminas the Assignee.
In the Properties tab click Form, click New and add the following.
Id
Name
Type
Readable
Writable
Required
approveCancellationDo You Approve the
Appointment Cancellation Request?enum
True
True
True
Click New next to Form values and add the following:
Id
Name
approve
Approve
reject
Reject
Repeat clicking New and adding the following to add the other form properties one by one.
Id
Name
Type
Variable
Readable
Writable
Required
AppNoAppointment Number
long
appointmentNo
True
False
True
cancellationReasonReason For The Cancellation
string
reason
True
False
True
doctorNameName of the Doctor
string
doctor
True
False
True
Add another Exclusive Gateway from the Gateway palette.
Add a REST Task from the WSO2 Tasks palette.
Select the Properties tab and click Main config and update the following:Service URL
http://localhost:9090/healthcare/appointments/validity/${appointmentNo}HTTP method
DELETE
Output Variable name
status
Add a MailTask from the Task palette 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}From
Enter a valid SMTP email address.
Subject
Appointment cancellation rejected
Html
Appointment cancellation request with Appointment Number ${appointmentNo} has been rejected. Thank you.
Administration DepartmentAdd another MailTask above the second Parallel Gateway and name it
Approve Cancellation Task.
Select the Properties tab and click Main config and update the following:To
${email}From
Enter a valid SMTP email address.
Subject
Appointment cancellation successful
Html
Appointment cancellation request with Appointment Number ${appointmentNo} has been approved. Thank you.
Administration DepartmentLink each activity by hovering over the element, selecting the arrow sign and dragging it to the connecting element as shown below.
Click on 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.
Click on 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.
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.
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.
Click the arrow leading to the Appointment Control Task, open the General tab that is under properties and note the Id.
Example:
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.
Save all the changes you have made.
Click Window -> Show View -> Other in the top menu of Tooling.
Type
Package Explorerin the search bar, select it and click Open.
In the Package Explorer, right-click the
AppointmentCancellationproject and select Create deployment artifacts.
This will create aAppointmentCancellation.barfile in thedeploymentfolder:
Before you begin, apply the following configurations to the business process profile:
Copy the following JARs to the
<EI_HOME>/libdirectory.Open the
activiti.xmlfile in the<EI_HOME>/wso2/business-process/confdirectory 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
mailServerHostandmailServerPortproperty 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.
Start the Business Process profile in WSO2 EI by executing one of the following commands:
Open the management console from
https://localhost:9445/carbon/.Log in using admin as the username and password.
Go to Main -> Manage -> Add ->BPMN and upload the
AppointmentCancellation.barfile by browsing in the workspace directory of your Tooling instance as shown below.
Let's start the Message Broker 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 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=PaymentRequestJMSMessageStoreNow, let's start the ESB profile in WSO2 EI and upload the ESB artifacts:
Assuming you have already added a server for the ESB profile in Eclipse, on the Servers tab, expand the WSO2 Carbon server, right-click SampleServicesCompositeApplication, and choose Redeploy. The Console window of the ESB profile will indicate that the CApp has been deployed successfully.
If you do not have a server added in Eclipse, refer this tutorial.
You can also deploy the artifacts to the ESB server using a Composite Application Archive (CAR) file.
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:
The system is now ready to receive appointment reservation requests.
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.
Create a JSON file named
request.jsonwith 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" }Open a command line terminal and navigate to the location where you have stored the above request payloads.
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 try setting the appointment date to less than 2 days from the current date and schedule a request too. You won't be able to cancel the request when trying out the steps under 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.
Click the cancellation link in one of the mails, which will take you to the BPMN explorer.
Log in to the BPMN explorer using admin as the username and password.
Click Processes and see that an appointment cancellation process is listed as shown below.
Click Start to begin the cancellation process and the Start Process form will open as shown below.
Let's cancel the appointment that was confirmed.
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.
Since the appointment is more than two days from the current date, the appointment cancellation will be approved automatically.
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 or rejected automatically. To cancel the request, follow the steps given below.
Click TASKS on the menu bar and see that a manual task has been created for the appointment cancellation.
You can now assume the role of an administrator in the hospital service and determine if the appointment cancellation should be approved or rejected.
Let's approve the request: Select Approve and click Complete Task in the appointment control task shown above.
You will receive an email confirming that the appointment cancellation is approved.
Congratulations, you have successfully completed the tutorial!
What's next?
Want to check out the statistics of the business processor? Try out the Analyzing Business Process Statistics tutorial.