/
Child Process Flow activity: PC_PF_SubmitBill_SubProcess_API

Child Process Flow activity: PC_PF_SubmitBill_SubProcess_API

Implementation

  • This Child Process sends the bill to ADVA for Pricing.

  • When ResponseCode is 200 we send the billJSON sent by the client to ADVA through ASB for Pricing.

Process Flow Activity

Initially, we create the default flow.

image-20240718-054714.png

At the start of the event, Gateway

  Defines two flows. We create a default flow.

 

The default condition will only execute when the responseCode is not 200

A Gateway controls the divergence and convergence of a sequence flow. Thus, it determines the branching, forking, merging, and joining of paths.

  1. We create a data mapping to fetch the error backend status.

  1. Create a JSON Layout: This JSON layout contains API Backend Status

  1. Create a Custom Plugin: This Custom plugin is removing \ from JSON data.

Script:

import org.apache.commons.io.IOUtils;

String json = IOUtils.toString(inputStream);
json = json.replaceAll("\\\\", " ").replaceAll("\t", " ").trim().replaceAll("\"\\{", "{").replaceAll("}\\\"", "}");
service.write(json.toString().getBytes(), "default");

  1. Create a Rest Consumer: This Rest Consumer is created for Backend Status.

  1. Create a Context Target:


Implementation

Process Flow Activity

At the start of the event, Gateway Defines two flows. Now we create a subsequent flow.

  1. Create Context Source: To Get response data in restRequest.

  1. Create a JSON Schema: This Layout is created to parse JSON data.

  1. Create Data Mapping: We create this Data Mapping to handle mandatory and process request

  1. Create Custom Plugin: It basically converts the XML to JSON and cleans it to optimize the end JSON.

try{

String keys = "bills,vendorReasons,codeToCodes,procedureCodes,attachments,patientVisitReasons,providers,client,bill_details,icdCodes,programFlags";
String jsonString=new XMLtoJSONResponse().convertData(keys,inputStream,service);
//handle empty array before returning
//uncomment below for debugging
//service.getLogger().error("****" + jsonString);
String postBillJson = jsonString.replace("[\"\"]", "null").replace("\"messageProperties\":\"\"","\"messageProperties\":{}").replace("\"\"","null");
String childContext = "{\"logActivity\" : {\"applicationID\" : \"Adeptia\",\"activityType\" : \"API\",\"subActivity\" : \"Submit\",\"Datetime\" : \"<DateTime>\",\"partnerId\" : \"<PartnerID>\",\"partnerType\" : \"API Partner\",\"processName\" : \"<ProcessName>\",\"notes\" : \"<notes>\"},\"entities\" : {\"entityTransactionId\" : \"<TransactionID>\"}}";
String dateTime = context.get("dateTime");
String restRequest = context.get("restRequest");
String partnerId = context.get("partnerId");
String transactionID = context.get("PC_TransactionID");
String fileName = partnerId+"-"+transactionID;
String filePath = context.get("targetFileLocation");
String processName = context.get("TransactionName");
String tenantID = service.getValueByName("tenantID");
String clientID = service.getValueByName("clientID");
String clientSecret = service.getValueByName("clientSecret");
String env = service.getValueByName("env");
String topicName = "advapro-" + env + "-in-original-bill";
String subject = fileName + ".json";

Map customProperties= new HashMap();
customProperties.put("bvId", partnerId);
customProperties.put("env", env);

//File file = new File(filePath + "\\" + fileName + ".atmp");
//FileOutputStream fout = new FileOutputStream(file);
//BufferedOutputStream bout = new BufferedOutputStream(fout);
//byte[] b = postBillJson.getBytes();
//bout.write(b);
//bout.flush();
//bout.close();
//fout.close();
//File rename = new File(filePath + "\\" + fileName + ".json");
//if (rename.exists()) rename.delete();
//boolean flag = file.renameTo(rename);
//if (!flag == true) {
//throw new Exception("Unable to rename temp file");
//}

ASBImpl.sendMessage("Endpoint=sb://paradigm-prod.servicebus.windows.net/;SharedAccessKeyName=mySas;SharedAccessKey=9eMMah7i1InOKKIzIWVjJxALntc/aciRs+ASbHUGt8Y=",topicName,postBillJson,customProperties,transactionID,tenantID,clientID,clientSecret,subject);

restRequest= restRequest.replaceAll("\"", "\\\\\\\\\"").trim().replaceAll("\r\n", "").replaceAll("\t", "");
restRequest= restRequest.replaceAll("\\\\", " ");
childContext = childContext.replaceAll("<PartnerID>", partnerId).replaceAll("<TransactionID>", transactionID).replaceAll("<ProcessName>", processName).replaceAll("<notes>", restRequest).replaceAll("\"\\{", "{").replaceAll("}\\\"", "}").replaceAll("<DateTime>",dateTime);
context.put("childData",childContext);

}
catch(Exception e){

Logger log = service.getLogger();

log.error(e.getMessage());

throw new Exception(e.getMessage());

}

try{

String keys = "bills,vendorReasons,codeToCodes,procedureCodes,attachments,patientVisitReasons,providers,client,bill_details,icdCodes,programFlags";
String jsonString=new XMLtoJSONResponse().convertData(keys,inputStream,service);
//handle empty array before returning
//uncomment below for debugging
//service.getLogger().error("****" + jsonString);
String postBillJson = jsonString.replace("[\"\"]", "null").replace("\"messageProperties\":\"\"","\"messageProperties\":{}").replace("\"\"","null");
String childContext = "{\"logActivity\" : {\"applicationID\" : \"Adeptia\",\"activityType\" : \"API\",\"subActivity\" : \"Submit\",\"Datetime\" : \"<DateTime>\",\"partnerId\" : \"<PartnerID>\",\"partnerType\" : \"API Partner\",\"processName\" : \"<ProcessName>\",\"notes\" : \"<notes>\"},\"entities\" : {\"entityTransactionId\" : \"<TransactionID>\"}}";
String dateTime = context.get("dateTime");
String restRequest = context.get("restRequest");
String partnerId = context.get("partnerId");
String transactionID = context.get("PC_TransactionID");
String fileName = partnerId+"-"+transactionID;
String filePath = context.get("targetFileLocation");
String processName = context.get("TransactionName");
String tenantID = service.getValueByName("tenantID");
String clientID = service.getValueByName("clientID");
String clientSecret = service.getValueByName("clientSecret");
String env = service.getValueByName("env");
String topicName = "advapro-" + env + "-in-original-bill";
String subject = fileName + ".json";

Map customProperties= new HashMap();
customProperties.put("bvId", partnerId);
customProperties.put("env", env);

//File file = new File(filePath + "\\" + fileName + ".atmp");
//FileOutputStream fout = new FileOutputStream(file);
//BufferedOutputStream bout = new BufferedOutputStream(fout);
//byte[] b = postBillJson.getBytes();
//bout.write(b);
//bout.flush();
//bout.close();
//fout.close();
//File rename = new File(filePath + "\\" + fileName + ".json");
//if (rename.exists()) rename.delete();
//boolean flag = file.renameTo(rename);
//if (!flag == true) {
//throw new Exception("Unable to rename temp file");
//}

ASBImpl.sendMessage("Endpoint=sb://paradigm-prod.servicebus.windows.net/;SharedAccessKeyName=mySas;SharedAccessKey=9eMMah7i1InOKKIzIWVjJxALntc/aciRs+ASbHUGt8Y=",topicName,postBillJson,customProperties,transactionID,tenantID,clientID,clientSecret,subject);

restRequest= restRequest.replaceAll("\"", "\\\\\\\\\"").trim().replaceAll("\r\n", "").replaceAll("\t", "");
restRequest= restRequest.replaceAll("\\\\", " ");
childContext = childContext.replaceAll("<PartnerID>", partnerId).replaceAll("<TransactionID>", transactionID).replaceAll("<ProcessName>", processName).replaceAll("<notes>", restRequest).replaceAll("\"\\{", "{").replaceAll("}\\\"", "}").replaceAll("<DateTime>",dateTime);
context.put("childData",childContext);

}
catch(Exception e){

Logger log = service.getLogger();

log.error(e.getMessage());

throw new Exception(e.getMessage());

}

  1. Create Custom Plugin: We create this Custom Plugin for Backend Status in API sub process.

 

Related content

Outbound Child Process Flow activity: PC_PF_SubProcess_BillStatus_API
Outbound Child Process Flow activity: PC_PF_SubProcess_BillStatus_API
More like this
Inbound Parent Process Flow activity: PC_PF_SubmitBill_MainProcess_API
Inbound Parent Process Flow activity: PC_PF_SubmitBill_MainProcess_API
More like this