diff --git a/pom.xml b/pom.xml
index b8614a9..080b8fe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,7 +35,7 @@
io.hcxprotocol
hcx-integrator-sdk
- 1.0.5
+ 1.0.7
com.nimbusds
@@ -73,6 +73,11 @@
postgresql
42.3.1
+
+ com.amazonaws
+ aws-java-sdk
+ 1.12.353
+
diff --git a/src/main/java/org/swasth/hcx/HCXApplication.java b/src/main/java/org/swasth/hcx/HCXApplication.java
index 74b5a0c..0a37bab 100644
--- a/src/main/java/org/swasth/hcx/HCXApplication.java
+++ b/src/main/java/org/swasth/hcx/HCXApplication.java
@@ -8,6 +8,7 @@
import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication
+@EnableAsync
public class HCXApplication {
public static void main(String[] args) {
diff --git a/src/main/java/org/swasth/hcx/controllers/BaseController.java b/src/main/java/org/swasth/hcx/controllers/BaseController.java
index ce3f2f7..b19392c 100644
--- a/src/main/java/org/swasth/hcx/controllers/BaseController.java
+++ b/src/main/java/org/swasth/hcx/controllers/BaseController.java
@@ -2,10 +2,11 @@
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.IParser;
+import com.amazonaws.services.dynamodbv2.xspec.S;
import io.hcxprotocol.init.HCXIntegrator;
import io.hcxprotocol.utils.Operations;
-import lombok.SneakyThrows;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.r4.model.*;
import org.slf4j.Logger;
@@ -24,14 +25,15 @@
import org.swasth.hcx.exception.ServiceUnavailbleException;
import org.swasth.hcx.fhirexamples.OnActionFhirExamples;
import org.swasth.hcx.helpers.EventGenerator;
-import org.swasth.hcx.service.HcxIntegratorService;
-import org.swasth.hcx.service.HeaderAuditService;
-import org.swasth.hcx.service.NotificationService;
-import org.swasth.hcx.service.PayerService;
+import org.swasth.hcx.service.*;
import org.swasth.hcx.utils.JSONUtils;
import org.swasth.hcx.utils.OnActionCall;
-import javax.annotation.PostConstruct;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.*;
import static org.swasth.hcx.utils.Constants.*;
@@ -44,6 +46,11 @@ public class BaseController {
@Autowired
private EventGenerator eventGenerator;
+ @Autowired
+ private BeneficiaryService beneficiaryService;
+
+ @Autowired
+ private PostgresService postgresService;
@Autowired
protected Environment env;
@@ -54,26 +61,28 @@ public class BaseController {
protected NotificationService notificationService;
@Autowired
- protected HcxIntegratorService hcxIntegratorService;
+ protected HcxIntegratorService hcxIntegratorService;
private String baseURL;
@Value("${autoresponse}")
private Boolean autoResponse;
+ @Value("${postgres.table.payerData}")
+ private String table;
@Autowired
private PayerService payerService;
private static final Logger logger = LoggerFactory.getLogger(BaseController.class);
- protected Response errorResponse(Response response, ErrorCodes code, java.lang.Exception e){
- ResponseError error= new ResponseError(code, e.getMessage(), e.getCause());
+ protected Response errorResponse(Response response, ErrorCodes code, java.lang.Exception e) {
+ ResponseError error = new ResponseError(code, e.getMessage(), e.getCause());
response.setError(error);
return response;
}
- protected void replaceResourceInBundleEntry(Bundle bundle, String bundleURL, Class matchClass, Bundle.BundleEntryComponent bundleEntry){
+ protected void replaceResourceInBundleEntry(Bundle bundle, String bundleURL, Class matchClass, Bundle.BundleEntryComponent bundleEntry) {
//updating the meta
Meta meta = new Meta();
@@ -81,12 +90,12 @@ protected void replaceResourceInBundleEntry(Bundle bundle, String bundleURL, Cla
meta.setLastUpdated(new Date());
bundle.setMeta(meta);
- for(int i=0; i < bundle.getEntry().size(); i++){
+ for (int i = 0; i < bundle.getEntry().size(); i++) {
System.out.println("in the loop " + i);
Bundle.BundleEntryComponent par = bundle.getEntry().get(i);
DomainResource dm = (DomainResource) par.getResource();
- if(dm.getClass() == matchClass){
- bundle.getEntry().set(i,bundleEntry);
+ if (dm.getClass() == matchClass) {
+ bundle.getEntry().set(i, bundleEntry);
}
}
}
@@ -96,61 +105,123 @@ protected void processAndValidate(String onApiAction, String metadataTopic, Requ
String mid = UUID.randomUUID().toString();
String serviceMode = env.getProperty(SERVICE_MODE);
System.out.println("\n" + "Mode: " + serviceMode + " :: mid: " + mid + " :: Event: " + onApiAction);
- if(StringUtils.equalsIgnoreCase(serviceMode, GATEWAY)) {
- Map pay = new HashMap<>();
- System.out.println("payload received " + requestBody);
- pay.put("payload", String.valueOf(requestBody.get("payload")));
- Map output = new HashMap<>();
- Map outputOfOnAction = new HashMap<>();
- System.out.println("create the oncheck payload");
- Bundle bundle = new Bundle();
- Request req = new Request(requestBody, apiAction);
- HCXIntegrator hcxIntegrator = hcxIntegratorService.getHCXIntegrator(req.getRecipientCode());
- if (COVERAGE_ELIGIBILITY_ONCHECK.equalsIgnoreCase(onApiAction)) {
- boolean result = hcxIntegrator.processIncoming(JSONUtils.serialize(pay), Operations.COVERAGE_ELIGIBILITY_CHECK,output);
- if(!result){
- System.out.println("Error while processing incoming request: " + output);
- }
- System.out.println("outmap after decryption " + output.get("fhirPayload"));
- System.out.println("decryption successful");
- //processing the decrypted incoming bundle
- bundle = p.parseResource(Bundle.class, (String) output.get("fhirPayload"));
- CoverageEligibilityResponse covRes = OnActionFhirExamples.coverageEligibilityResponseExample();
- replaceResourceInBundleEntry(bundle, "https://ig.hcxprotocol.io/v0.7.1/StructureDefinition-CoverageEligibilityResponseBundle.html", CoverageEligibilityRequest.class, new Bundle.BundleEntryComponent().setFullUrl(covRes.getResourceType() + "/" + covRes.getId().toString().replace("#","")).setResource(covRes));
- System.out.println("bundle reply " + p.encodeResourceToString(bundle));
- //sending the onaction call
- sendResponse(apiAction,p.encodeResourceToString(bundle),(String) output.get("fhirPayload"), Operations.COVERAGE_ELIGIBILITY_ON_CHECK, String.valueOf(requestBody.get("payload")),"response.complete" ,outputOfOnAction);
- } else if (CLAIM_ONSUBMIT.equalsIgnoreCase(onApiAction)) {
- boolean result = hcxIntegrator.processIncoming(JSONUtils.serialize(pay), Operations.CLAIM_SUBMIT,output);
- if(!result){
- System.out.println("Error while processing incoming request: " + output);
- }
- System.out.println("outmap after decryption " + output);
- System.out.println("decryption successful");
- //processing the decrypted incoming bundle
- bundle = p.parseResource(Bundle.class, (String) output.get("fhirPayload"));
- ClaimResponse claimRes = OnActionFhirExamples.claimResponseExample();
- replaceResourceInBundleEntry(bundle, "https://ig.hcxprotocol.io/v0.7.1/StructureDefinition-ClaimResponseBundle.html", Claim.class, new Bundle.BundleEntryComponent().setFullUrl(claimRes.getResourceType() + "/" + claimRes.getId().toString().replace("#","")).setResource(claimRes));
- sendResponse(apiAction,p.encodeResourceToString(bundle), (String) output.get("fhirPayload"), Operations.CLAIM_ON_SUBMIT, String.valueOf(requestBody.get("payload")),"response.complete" ,outputOfOnAction);
- } else if (PRE_AUTH_ONSUBMIT.equalsIgnoreCase(onApiAction)) {
- boolean result = hcxIntegrator.processIncoming(JSONUtils.serialize(pay), Operations.PRE_AUTH_SUBMIT,output);
- if(!result){
- System.out.println("Error while processing incoming request: " + output);
- }
- System.out.println("outmap after decryption " + output);
- System.out.println("decryption successful");
- //processing the decrypted incoming bundle
- bundle = p.parseResource(Bundle.class, (String) output.get("fhirPayload"));
- ClaimResponse preAuthRes = OnActionFhirExamples.claimResponseExample();
- preAuthRes.setUse(ClaimResponse.Use.PREAUTHORIZATION);
- replaceResourceInBundleEntry(bundle, "https://ig.hcxprotocol.io/v0.7.1/StructureDefinition-ClaimResponseBundle.html", Claim.class, new Bundle.BundleEntryComponent().setFullUrl(preAuthRes.getResourceType() + "/" + preAuthRes.getId().toString().replace("#","")).setResource(preAuthRes));
- sendResponse(apiAction,p.encodeResourceToString(bundle), (String) output.get("fhirPayload"), Operations.PRE_AUTH_ON_SUBMIT, String.valueOf(requestBody.get("payload")),"response.complete" ,outputOfOnAction);
+ if (StringUtils.equalsIgnoreCase(serviceMode, GATEWAY)) {
+ Map pay = new HashMap<>();
+ System.out.println("payload received " + requestBody);
+ pay.put("payload", String.valueOf(requestBody.get("payload")));
+ Map output = new HashMap<>();
+ Map outputOfOnAction = new HashMap<>();
+ System.out.println("create the oncheck payload");
+ Bundle bundle = new Bundle();
+ Request req = new Request(requestBody, apiAction);
+ HCXIntegrator hcxIntegrator = hcxIntegratorService.getHCXIntegrator(req.getRecipientCode());
+ if (COVERAGE_ELIGIBILITY_CHECK.equalsIgnoreCase(onApiAction)) {
+ boolean result = hcxIntegrator.processIncoming(JSONUtils.serialize(pay), Operations.COVERAGE_ELIGIBILITY_CHECK, output);
+ if (!result) {
+ System.out.println("Error while processing incoming request: " + output);
+ }
+ System.out.println("output map after decryption coverageEligibility" + output.get("fhirPayload"));
+ System.out.println("decryption successful");
+ //processing the decrypted incoming bundle
+ bundle = p.parseResource(Bundle.class, (String) output.get("fhirPayload"));
+ CoverageEligibilityResponse covRes = OnActionFhirExamples.coverageEligibilityResponseExample();
+ covRes.setPatient(new Reference("Patient/RVH1003"));
+ replaceResourceInBundleEntry(bundle, "https://ig.hcxprotocol.io/v0.7.1/StructureDefinition-CoverageEligibilityResponseBundle.html", CoverageEligibilityRequest.class, new Bundle.BundleEntryComponent().setFullUrl(covRes.getResourceType() + "/" + covRes.getId().toString().replace("#", "")).setResource(covRes));
+ System.out.println("bundle reply " + p.encodeResourceToString(bundle));
+ //sending the onaction call
+ sendResponse(apiAction, p.encodeResourceToString(bundle), (String) output.get("fhirPayload"), Operations.COVERAGE_ELIGIBILITY_ON_CHECK, String.valueOf(requestBody.get("payload")), "response.complete", outputOfOnAction);
+ updateMobileNumber(request.getApiCallId());
+ } else if (CLAIM_ONSUBMIT.equalsIgnoreCase(onApiAction)) {
+ boolean result = hcxIntegrator.processIncoming(JSONUtils.serialize(pay), Operations.CLAIM_SUBMIT, output);
+ if (!result) {
+ System.out.println("Error while processing incoming request: " + output);
+ }
+ System.out.println("output map after decryption claim " + output);
+ System.out.println("decryption successful");
+ //processing the decrypted incoming bundle
+ bundle = p.parseResource(Bundle.class, (String) output.get("fhirPayload"));
+ ClaimResponse claimRes = OnActionFhirExamples.claimResponseExample();
+ claimRes.setPatient(new Reference("Patient/RVH1003"));
+ replaceResourceInBundleEntry(bundle, "https://ig.hcxprotocol.io/v0.7.1/StructureDefinition-ClaimResponseBundle.html", Claim.class, new Bundle.BundleEntryComponent().setFullUrl(claimRes.getResourceType() + "/" + claimRes.getId().toString().replace("#", "")).setResource(claimRes));
+ System.out.println("bundle reply " + p.encodeResourceToString(bundle));
+ sendResponse(apiAction, p.encodeResourceToString(bundle), (String) output.get("fhirPayload"), Operations.CLAIM_ON_SUBMIT, String.valueOf(requestBody.get("payload")), "response.complete", outputOfOnAction);
+ updateMobileNumber(request.getApiCallId());
+ } else if (PRE_AUTH_ONSUBMIT.equalsIgnoreCase(onApiAction)) {
+ boolean result = hcxIntegrator.processIncoming(JSONUtils.serialize(pay), Operations.PRE_AUTH_SUBMIT, output);
+ if (!result) {
+ System.out.println("Error while processing incoming request: " + output);
}
+ System.out.println("output map after decryption preauth " + output);
+ System.out.println("decryption successful");
+ //processing the decrypted incoming bundle
+ bundle = p.parseResource(Bundle.class, (String) output.get("fhirPayload"));
+ ClaimResponse preAuthRes = OnActionFhirExamples.claimResponseExample();
+ preAuthRes.setPatient(new Reference("Patient/RVH1003"));
+ preAuthRes.setUse(ClaimResponse.Use.PREAUTHORIZATION);
+ replaceResourceInBundleEntry(bundle, "https://ig.hcxprotocol.io/v0.7.1/StructureDefinition-ClaimResponseBundle.html", Claim.class, new Bundle.BundleEntryComponent().setFullUrl(preAuthRes.getResourceType() + "/" + preAuthRes.getId().toString().replace("#", "")).setResource(preAuthRes));
+ sendResponse(apiAction, p.encodeResourceToString(bundle), (String) output.get("fhirPayload"), Operations.PRE_AUTH_ON_SUBMIT, String.valueOf(requestBody.get("payload")), "response.complete", outputOfOnAction);
+ updateMobileNumber(request.getApiCallId());
+ } else if (COMMUNICATION_ONREQUEST.equalsIgnoreCase(onApiAction)) {
+ HCXIntegrator hcxIntegrator1 = HCXIntegrator.getInstance(initializingConfigMap());
+ boolean result = hcxIntegrator1.processIncoming(JSONUtils.serialize(pay), Operations.COMMUNICATION_REQUEST, output);
+ if (!result) {
+ System.out.println("Error while processing incoming request: " + output);
+ }
+ System.out.println("output map after decryption communication" + output);
+ System.out.println("decryption successful");
+ String selectQuery = String.format("SELECT otp_verification from %s WHERE correlation_id = '%s'", table, request.getCorrelationId());
+ ResultSet resultSet = postgresService.executeQuery(selectQuery);
+ String otpVerification = "";
+ while (resultSet.next()) {
+ otpVerification = resultSet.getString("otp_verification");
+ }
+ if (StringUtils.equalsIgnoreCase(otpVerification, "successful")) {
+ String query1 = String.format("UPDATE %s SET bank_details = '%s' WHERE correlation_id = '%s'", table, "initiated", request.getCorrelationId());
+ postgresService.execute(query1);
+ } else if (StringUtils.equalsIgnoreCase(otpVerification, "Pending")) {
+ String query = String.format("UPDATE %s SET otp_verification = '%s' WHERE correlation_id ='%s'", table, "initiated", request.getCorrelationId());
+ postgresService.execute(query);
+ }
+ }
}
+ }
+ public void processAndValidateRequest(String onApiAction, String metadataTopic, Request request, Map requestBody, String apiAction) throws Exception {
+ IParser p = FhirContext.forR4().newJsonParser().setPrettyPrint(true);
+ String mid = UUID.randomUUID().toString();
+ String serviceMode = env.getProperty(SERVICE_MODE);
+ System.out.println("\n" + "Mode: " + serviceMode + " :: mid: " + mid + " :: Event: " + onApiAction);
+ if (StringUtils.equalsIgnoreCase(serviceMode, GATEWAY)) {
+ Map pay = new HashMap<>();
+ System.out.println("payload received " + requestBody);
+ pay.put("payload", String.valueOf(requestBody.get("payload")));
+ Map output = new HashMap<>();
+ Map outputOfOnAction = new HashMap<>();
+ System.out.println("create the oncheck payload");
+ Bundle bundle = new Bundle();
+ Request req = new Request(requestBody, apiAction);
+ HCXIntegrator hcxIntegrator = hcxIntegratorService.getHCXIntegrator(req.getRecipientCode());
+ if (COVERAGE_ELIGIBILITY_ONCHECK.equalsIgnoreCase(onApiAction)) {
+ boolean result = hcxIntegrator.processIncoming(JSONUtils.serialize(pay), Operations.COVERAGE_ELIGIBILITY_ON_CHECK, output);
+ if (!result) {
+ System.out.println("Error while processing incoming request: " + output);
+ }
+ System.out.println("output map after decryption coverageEligibility" + output.get("fhirPayload"));
+ System.out.println("decryption successful");
+ //processing the decrypted incoming bundle
+ bundle = p.parseResource(Bundle.class, (String) output.get("fhirPayload"));
+ CoverageEligibilityResponse covRes = OnActionFhirExamples.coverageEligibilityResponseExample();
+ covRes.setPatient(new Reference("Patient/RVH1003"));
+ replaceResourceInBundleEntry(bundle, "https://ig.hcxprotocol.io/v0.7.1/StructureDefinition-CoverageEligibilityResponseBundle.html", CoverageEligibilityRequest.class, new Bundle.BundleEntryComponent().setFullUrl(covRes.getResourceType() + "/" + covRes.getId().toString().replace("#", "")).setResource(covRes));
+ System.out.println("bundle reply " + p.encodeResourceToString(bundle));
+ //sending the onaction call
+ onActionCall.sendOnAction(request.getRecipientCode(),(String) output.get("fhirPayload") , Operations.COVERAGE_ELIGIBILITY_ON_CHECK, String.valueOf(requestBody.get("payload")), "response.complete", outputOfOnAction);
+ updateMobileNumber(request.getApiCallId());
+ }
+ }
}
- private void sendResponse(String apiAction, String respfhir, String reqFhir, Operations operation, String actionJwe, String onActionStatus, Map output) throws Exception {
+ private void sendResponse(String apiAction, String respfhir, String reqFhir, Operations operation, String actionJwe, String onActionStatus, Map output) throws Exception {
Request request = new Request(Collections.singletonMap("payload", actionJwe), apiAction);
if (autoResponse || StringUtils.equalsIgnoreCase(request.getRecipientCode(), env.getProperty("mock_payer.participant_code"))) {
onActionCall.sendOnAction(request.getRecipientCode(), respfhir, operation, actionJwe, onActionStatus, output);
@@ -165,7 +236,21 @@ public ResponseEntity