io.hcxprotocol.init.HCXIntegrator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hcx-integrator-sdk Show documentation
Show all versions of hcx-integrator-sdk Show documentation
The SDK for HCX Participant System to help in integrating with HCX Gateway easily.
package io.hcxprotocol.init;
import io.hcxprotocol.utils.Operations;
import java.util.Map;
/**
* This class contains the methods to initialize configuration variables, process incoming and outgoing requests.
*/
public class HCXIntegrator extends BaseIntegrator {
/**
* This method is to initialize config factory by passing the configuration as Map.
*
* @param config A Map that contains configuration variables and its values.
*/
public static HCXIntegrator getInstance(Map config) throws Exception {
HCXIntegrator hcxIntegrator = new HCXIntegrator();
hcxIntegrator.setConfig(config);
return hcxIntegrator;
}
/**
* Process the JWE Payload based on the Operation to validate and extract the FHIR Object.
* It has the implementation of below steps.
*
* - Validating HCX Protocol headers
* - Decryption of the payload and extracting FHIR object
* - Validating the FHIR object using HCX FHIR IG.
*
* @param jwePayload The JWE payload from the incoming API request body.
* @param operation The HCX operation name.
* @param output A wrapper map to collect the outcome (errors or response) of the JWE Payload processing.
*
* - output -
*
* {@code {
* "headers":{}, - protocol headers
* "fhirPayload":{}, - fhir object
* "responseObj":{} - success/error response object
* }}
*
* - success response object -
*
* {@code {
* "timestamp": , - unix timestamp
* "correlation_id": "", - fetched from incoming request
* "api_call_id": "" - fetched from incoming request
* }}
*
* - error response object -
*
* {@code {
* "timestamp": , - unix timestamp
* "error": {
* "code" : "", - error code
* "message": "", - error message
* "trace":"" - error trace
* }
* }}
*
*
*
* @return It is a boolean value to understand the incoming request processing is successful or not.
*
* - true - It is successful.
* - false - It is failure.
*
*
*/
public boolean processIncoming(String jwePayload, Operations operation, Map output) throws Exception {
return getIncomingRequest().process(jwePayload, operation, output, getConfig());
}
/**
* Generates the JWE Payload using FHIR Object, Operation and other parameters part of input. This method is used to handle the action API request.
* It has the implementation of the below steps to create JWE Payload and send the request.
*
* - Validating the FHIR object using HCX FHIR IG.
* - Crate HCX Protocol headers based on the request.
* - Fetch the sender encryption public key from the HCX participant registry.
* - Encrypt the FHIR object along with HCX Protocol headers using RFC7516 to create JWE Payload.
* - Generate or fetch the authorization token of HCX Gateway.
* - Trigger HCX Gateway REST API based on operation.
*
* @param fhirPayload The FHIR object created by the participant system.
* @param operation The HCX operation or action defined by specs to understand the functional behaviour.
* @param recipientCode The recipient code from HCX Participant registry.
* @param apiCallId The unique id for each request, to use the custom identifier, pass the same or else
* pass an empty string("") and method will generate a UUID and uses it.
* @param correlationId The unique id for all the messages (requests and responses) that are involved in processing of one cycle,
* to use the custom identifier, pass the same or else pass empty string("") and method will generate a UUID and uses it.
* @param domainHeaders The domain headers to use while creating the JWE Payload.
* @param output A wrapper map to collect the outcome (errors or response) of the JWE Payload generation process using FHIR object.
*
* - output -
*
* {@code {
* "payload":{}, - jwe payload
* "responseObj":{} - success/error response object
* }}
*
* - success response object -
*
* {@code {
* "timestamp": , - unix timestamp
* "correlation_id": "", - fetched from incoming request
* "api_call_id": "" - fetched from incoming request
* }}
*
* - error response object -
*
* {@code {
* "timestamp": , - unix timestamp
* "error": {
* "code" : "", - error code
* "message": "", - error message
* "trace":"" - error trace
* }
* }}
*
*
* @return It is a boolean value to understand the outgoing request generation is successful or not.
*
*
* - true - It is successful.
* - false - It is failure.
*
*/
public boolean processOutgoingRequest(String fhirPayload, Operations operation, String recipientCode, String apiCallId, String correlationId, Map domainHeaders, Map output) throws InstantiationException, IllegalAccessException {
return getOutgoingRequest().process(fhirPayload, operation, recipientCode, apiCallId, correlationId, "", "", domainHeaders, output, getConfig());
}
/**
* Generates the JWE Payload using FHIR Object, Operation and other parameters part of input. This method is used to handle the on_action API request.
* It has the implementation of the below steps to create JWE Payload and send the request.
*
* - Validating the FHIR object using HCX FHIR IG.
* - Crate HCX Protocol headers based on the request and actionJWE payload.
* - Fetch the sender encryption public key from the HCX participant registry.
* - Encrypt the FHIR object along with HCX Protocol headers using RFC7516 to create JWE Payload.
* - Generate or fetch the authorization token of HCX Gateway.
* - Trigger HCX Gateway REST API based on operation.
*
* @param fhirPayload The FHIR object created by the participant system.
* @param operation The HCX operation or action defined by specs to understand the functional behaviour.
* @param apiCallId The unique id for each request, to use the custom identifier, pass the same or else
* pass empty string("") and method will generate a UUID and uses it.
* @param actionJwe The JWE Payload from the incoming request for which the response JWE Payload created here.
* @param onActionStatus The HCX Protocol header status (x-hcx-status) value to use while creating the JEW Payload.
* @param domainHeaders The domain headers to use while creating the JWE Payload.
* @param output A wrapper map to collect the outcome (errors or response) of the JWE Payload generation process using FHIR object.
*
* - output -
*
* {@code {
* "payload":{}, - jwe payload
* "responseObj":{} - success/error response object
* }}
*
* - success response object -
*
* {@code {
* "timestamp": , - unix timestamp
* "correlation_id": "", - fetched from incoming request
* "api_call_id": "" - fetched from incoming request
* }}
*
* - error response object -
*
* {@code {
* "timestamp": , - unix timestamp
* "error": {
* "code" : "", - error code
* "message": "", - error message
* "trace":"" - error trace
* }
* }}
*
*
* @return It is a boolean value to understand the outgoing request generation is successful or not.
*
*
* - true - It is successful.
* - false - It is failure.
*
*/
public boolean processOutgoingCallback(String fhirPayload, Operations operation, String apiCallId, String actionJwe, String onActionStatus, Map domainHeaders, Map output) throws InstantiationException, IllegalAccessException {
return getOutgoingRequest().process(fhirPayload, operation, "", apiCallId, "", actionJwe, onActionStatus, domainHeaders, output, getConfig());
}
}