Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. In WSO2 Integration Studio, add a Property mediator just after the Get Hospital Property mediator in the in-sequence of the API resource to retrieve and store the card number that is sent in the request payload.

     

    With the Property mediator selected, access the Properties tab and fill in the information as in the following table:

    FieldValue
    Property NameSelect New Property
    New Property Namecard_number
    Property Action

    Select set

    Value TypeSelect Expression
    Value Expressionjson-eval($.cardNo)
    DescriptionGet Card Number
    Tip

    For detailed instructions on adding a Property mediator, see Mediating requests to the back-end service.

  2. Go to the first case box of the Switch mediator. Add a Property mediator just after the Log mediator to store the value for uri.var.hospital variable that will be used when sending requests to ChannelingFeeEP.
     

    With the Property mediator selected, access the Properties tab and fill in the information as in the following table:

    FieldValue
    Property NameSelect New Property
    New Property Nameuri.var.hospital
    Property Action

    Select set

    Value TypeSelect LITERAL
    Property Data TypeSelect STRING
    Valuegrandoaks
    DescriptionSet Hospital Variable
  3. Similarly, add property mediators in the other two case boxes in the Switch mediator. Change only the Value field as follows:
    • Case 2: clemency
    • Case 3: pinevalley
  4. Delete the Send mediator by right clicking on the mediator and selecting Delete from Model. Replace this with a Call mediator from the Mediators palette and add GrandOakEP from the Defined Endpoints palette to the empty box adjoining the Call mediator. 

    Replace the Send mediators in the following two case boxes as well and add ClemencyEP and PineValleyEP to the respective boxes adjoining the Call mediators.

    Info

    Replacing with a Call mediator allows us to define other service invocations following this mediator.

    Let's use Property mediators to retrieve and store the values that you get from the response you receive from GrandOakEP, ClemencyEP or PineValleyEP.

  5. Next to the Switch mediator, add a Property mediator to retrieve and store the value sent as appointmentNumber.

     

    With the Property mediator selected, access the Properties tab and fill in the information as in the following table:

    FieldValue
    Property NameSelect New Property
    New Property Nameuri.var.appointment_id
    (This value is used when invoking ChannelingFeeEP)
    Property Action

    Select set

    Value TypeSelect EXPRESSION
    Value Expressionjson-eval($.appointmentNumber)
    DescriptionGet Appointment Number
    Note

    You derive the Value Expression in the above table from the following response that is received from GrandOakEP, ClemencyEP or PineValleyEP:

    Code Block
    {"appointmentNumber":1,   "doctor":
            {"name":"thomas collins",
             "hospital":"grand oak community hospital",
             "category":"surgery","availability":"9.00 a.m - 11.00 a.m",
             "fee":7000.0},
       "patient":
           {"name":"John Doe",
            "dob":"1990-03-19",
            "ssn":"234-23-525",
            "address":"California",
            "phone":"8770586755",
            "email":"johndoe@gmail.com"},
       "fee":7000.0,
       "confirmed":false}
  6. Similarly, add two more Property mediators as follows. They retrieve and store the doctor details and patient details respectively, from the response that is received from GrandOakEP, ClemencyEP or PineValleyEP.

    FieldValue
    Property NameSelect New Property
    New Property Namedoctor_details
    Property Action

    Select set

    Value TypeSelect EXPRESSION
    Value Expressionjson-eval($.doctor)
    DescriptionGet Doctor Details


    Property NameSelect New Property
    New Property Namepatient_details
    Property ActionSelect set
    Value TypeSelect EXPRESSION
    Value Expressionjson-eval($.patient)
    DescriptionGet Patient Details

  7. Add a Call mediator and add ChannelingFeeEP from Defined Endpoints palette to the empty box adjoining the Call mediator. 
  8. Add a Property mediator adjoining the Call mediator box to retrieve and store the value sent as actualFee. Access the Property tab of the mediator and fill in the information as in the following table:

    FieldValue
    Property NameSelect New Property
    New Property Nameactual_fee (This value is used when invoking SettlePaymentEP )
    Property Action

    Select set

    Value TypeSelect EXPRESSION
    Value Expressionjson-eval($.actualFee)
    DescriptionGet Actual Fee

    Note

    You derive the Value Expression in the above table from the following response that is received from ChannelingFeeEP:

    Code Block
    {"patientName":" John Doe ", 
     "doctorName":"thomas collins", 
     "actualFee":"7000.0"}

    Let's use the /wiki/spaces/EI6xx/pages/49612834 to construct the following message payload for the request sent to SettlePaymentEP. 

    Code Block
    {"appointmentNumber":2,
    	"doctor":{
    		"name":"thomas collins",
    		"hospital":"grand oak community hospital",
    		"category":"surgery",
    		"availability":"9.00 a.m - 11.00 a.m",
    		"Fee":7000.0
    	},
    	"patient":{
    		"name":"John Doe",
    		"Dob":"1990-03-19",
    		"ssn":"234-23-525",
    		"address":"California",
    		"phone":"8770586755",
    		"email":"johndoe@gmail.com"
    	},
    	"fee":7000.0,
    	"Confirmed":false,
        "card_number":"1234567890"
    }
  9. Add a PayloadFactory mediator next to the Property mediator, from the mediators palette to construct the above message payload. 

     

    With the Payloadfactory mediator selected, access the properties tab of the mediator and fill in the information as in the following table:

    FieldValueDescription
    Payload FormatSelect Inline-
    Media Type

    Select json

    -
    Payload
    Code Block
    {
    "appointmentNumber":$1,
    "doctor":$2,
    "patient":$3,
    "fee":$4,
    "confirmed":"false",
    "card_number":"$5"
    }
    The message payload to send with the request to SettlePaymentEP. In this payload, $1, $2, $3, $4, and $5 indicate variables.

    We will look at adding the value for the field Args in the following steps.

    Tip

    To avoid getting an error message, first select the Media Type before providing the Payload.

  10. To add the Args field for the PayloadFactory mediator, click the Add (+) icon in the Args field and enter the following information as in the table below. It provides the argument that defines the actual value of the first variable used in the format definition in the previous step.

    FieldValueDescription
    TypeSelect Expression-
    Value

    $ctx:uri.var.appointment_id

    The value for the first variable ($1) in the message payload format.
    Evaluator

    Select xml

    Indicates that the expression provided is in XML.
    Info

    The $ctx method is similar to using the get-property method. This method checks in the message context. For more details on using this method, refer the documentation.

  11. Similarly, click Add and add more arguments to define the other variables that are used in the message payload format definition. Use the following as the Value for each of them: 

    $ctx:doctor_details
    $ctx:patient_details
    $ctx:actual_fee
    $ctx:card_number

  12. Add a Call mediator and add SettlePaymentEP from Defined Endpoints palette to the empty box adjoining the Call mediator.
  13. Add a /wiki/spaces/EI6xx/pages/49616625 mediator to send the response to the client. 
    You should now have a completed configuration that looks like this:
  14. Save the updated REST API configuration.

Packaging the artifacts

Since you created new endpoints, these will need to be packaged into our existing C-App. 

Package the C-App names SampleServicesCompositeApplication project with the artifacts created. 

...

Package the artifacts you created above in the SampleServicesCompositeApplication project: 

  1. Open the pom.xml file of the SampleServicesCompositeApplication project, which is already included in the project explorer.
  2. Select the artifact that needs to be included into the CAR file.

Note

Ensure the following artifact check boxes are selected in the Composite Application Project POM Editor.

  • SampleServices
    • HealthcareAPI
    • ClemencyEP
    • GrandOakEP
    • PineValleyEP
    • ChannelingFeeEP
    • SettlePaymentEP
  • SampleServicesRegistry

Starting the ESB profile and deploying the artifacts

...

Info

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

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

Image Removed

...

server and deployed SampleServicesCompositeApplication (in a previous tutorial):

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

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

Starting the back-end service

...

  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:

    Code Block
    java -jar Hospital-Service-2.0.0-EI7.jar

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

...