Skip to content

Commit

Permalink
Merge pull request #1106 from Shreeja-dev/main
Browse files Browse the repository at this point in the history
fix: correct interaction id for Forward HTTP Request state of CCDA#1011
  • Loading branch information
ratheesh-kr authored Jan 28, 2025
2 parents 52b154a + 12c5b1d commit 17b483c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion hub-prime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>org.techbd</groupId>
<artifactId>hub-prime</artifactId>
<version>0.447.0</version>
<version>0.448.0</version>
<packaging>war</packaging>
<name>Tech by Design Hub (Prime)</name>
<description>Tech by Design Hub (Primary)</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public Object processBundle(final @RequestBody @Nonnull String payload,
try {
final var start = Instant.now();
LOG.info("Bundle processing start at {} for interaction id {}.",
start, getBundleInteractionId(request));
start, getBundleInteractionId(request,coRrelationId));
if (null == interactionId) {
interactionId = getBundleInteractionId(request);
interactionId = getBundleInteractionId(request,coRrelationId);
}
final var dslContext = udiPrimeJpaConfig.dsl();
final var jooqCfg = dslContext.configuration();
Expand Down Expand Up @@ -162,12 +162,12 @@ public Object processBundle(final @RequestBody @Nonnull String payload,
}
if (null == payloadWithDisposition) {
LOG.warn("FHIRService:: ERROR:: Disposition payload is not available.Send Bundle payload to scoring engine for interaction id {}.",
getBundleInteractionId(request));
getBundleInteractionId(request,coRrelationId));
sendToScoringEngine(jooqCfg, request, customDataLakeApi, dataLakeApiContentType,
includeIncomingPayloadInDB, tenantId, payload,
provenance, null, includeOperationOutcome, mtlsStrategy,
interactionId, groupInteractionId, masterInteractionId,
sourceType, requestUriToBeOverriden);
sourceType, requestUriToBeOverriden,coRrelationId);
Instant end = Instant.now();
Duration timeElapsed = Duration.between(start, end);
LOG.info("Bundle processing end for interaction id: {} Time Taken : {} milliseconds",
Expand All @@ -180,7 +180,7 @@ public Object processBundle(final @RequestBody @Nonnull String payload,
includeIncomingPayloadInDB, tenantId, payload,
provenance, payloadWithDisposition, includeOperationOutcome,
mtlsStrategy, interactionId, groupInteractionId,
masterInteractionId, sourceType, requestUriToBeOverriden);
masterInteractionId, sourceType, requestUriToBeOverriden,coRrelationId);
Instant end = Instant.now();
Duration timeElapsed = Duration.between(start, end);
LOG.info("Bundle processing end for interaction id: {} Time Taken : {} milliseconds",
Expand Down Expand Up @@ -300,12 +300,12 @@ private Map<String, Object> registerBundleInteraction(org.jooq.Configuration joo
requestEncountered = new Interactions.RequestEncountered(mutatableReq,
payload.getBytes(),
UUID.fromString(interactionId));
} else if (null != getBundleInteractionId(request)) {
} else if (null != getBundleInteractionId(request,coRrelationId)) {
// If its a converted HL7 payload ,it will already have an interaction id.hence
// do not create new interactionId
requestEncountered = new Interactions.RequestEncountered(mutatableReq,
payload.getBytes(),
UUID.fromString(getBundleInteractionId(request)));
UUID.fromString(getBundleInteractionId(request,coRrelationId)));
} else {
requestEncountered = new Interactions.RequestEncountered(mutatableReq,
payload.getBytes());
Expand Down Expand Up @@ -507,10 +507,13 @@ private void sendToScoringEngine(org.jooq.Configuration jooqCfg, HttpServletRequ
String provenance,
Map<String, Object> validationPayloadWithDisposition, boolean includeOperationOutcome,
String mtlsStrategy, String interactionId, String groupInteractionId,
String masterInteractionId, String sourceType, String requestUriToBeOverriden) {
String masterInteractionId, String sourceType, String requestUriToBeOverriden,String coRrelationId) {
Span span = tracer.spanBuilder("FhirService.sentToScoringEngine").startSpan();
try {
interactionId = null != interactionId ? interactionId : getBundleInteractionId(request);
interactionId = null != interactionId ? interactionId : getBundleInteractionId(request,coRrelationId);
if (StringUtils.isNotEmpty(coRrelationId)) {
interactionId =coRrelationId;
}
LOG.info("FHIRService:: sendToScoringEngine BEGIN for interaction id: {} for", interactionId);

try {
Expand All @@ -523,7 +526,7 @@ private void sendToScoringEngine(org.jooq.Configuration jooqCfg, HttpServletRequ
interactionId);
bundlePayloadWithDisposition = preparePayload(request,
payload,
validationPayloadWithDisposition);
validationPayloadWithDisposition,interactionId);
} else {
LOG.debug("FHIRService:: sendToScoringEngine Send payload without operation outcome interaction id: {}",
interactionId);
Expand Down Expand Up @@ -557,7 +560,7 @@ private void sendToScoringEngine(org.jooq.Configuration jooqCfg, HttpServletRequ
} catch (

Exception e) {
handleError(validationPayloadWithDisposition, e, request);
handleError(validationPayloadWithDisposition, e, request,interactionId);
} finally {
LOG.info("FHIRService:: sendToScoringEngine END for interaction id: {}", interactionId);
}
Expand Down Expand Up @@ -628,7 +631,7 @@ private void handleMtlsResources(String interactionId, String tenantId, org.jooq
: request.getRequestURI();

try {
registerStateForward(jooqCfg, provenance, getBundleInteractionId(request),
registerStateForward(jooqCfg, provenance, getBundleInteractionId(request,interactionId),
requestURI, tenantId,
Optional.ofNullable(bundlePayloadWithDisposition)
.orElse(new HashMap<>()),
Expand Down Expand Up @@ -888,7 +891,7 @@ private void handlePostStdoutPayload(String interactionId, String tenantId, org.
: request.getRequestURI();

try {
registerStateForward(jooqCfg, provenance, getBundleInteractionId(request),
registerStateForward(jooqCfg, provenance, getBundleInteractionId(request,interactionId),
requestURI, tenantId,
Optional.ofNullable(bundlePayloadWithDisposition)
.orElse(new HashMap<>()),
Expand Down Expand Up @@ -1026,7 +1029,7 @@ private WebClient createWebClient(String scoringEngineApiURL,
filter(clientRequest, request, jooqCfg, provenance, tenantId, payload,
bundlePayloadWithDisposition,
includeIncomingPayloadInDB, groupInteractionId,
masterInteractionId, sourceType, requestUriToBeOverriden);
masterInteractionId, sourceType, requestUriToBeOverriden,interactionId);
return Mono.just(clientRequest);
}))
.build();
Expand Down Expand Up @@ -1080,9 +1083,8 @@ private void filter(ClientRequest clientRequest,
String payload,
Map<String, Object> bundlePayloadWithDisposition,
boolean includeIncomingPayloadInDB, String groupInteractionId, String masterInteractionId,
String sourceType, String requestUriToBeOverriden) {
String sourceType, String requestUriToBeOverriden,String interactionId) {

final var interactionId = getBundleInteractionId(request);
LOG.debug("FHIRService:: sendToScoringEngine Filter request before post - BEGIN interaction id: {}",
interactionId);
final var requestURI = StringUtils.isNotEmpty(requestUriToBeOverriden) ? requestUriToBeOverriden
Expand All @@ -1096,7 +1098,7 @@ private void filter(ClientRequest clientRequest,

final var outboundHttpMessage = requestBuilder.toString();

registerStateForward(jooqCfg, provenance, getBundleInteractionId(request), requestURI, tenantId,
registerStateForward(jooqCfg, provenance, getBundleInteractionId(request,interactionId), requestURI, tenantId,
Optional.ofNullable(bundlePayloadWithDisposition).orElse(new HashMap<>()),
outboundHttpMessage, includeIncomingPayloadInDB, payload, groupInteractionId,
masterInteractionId, sourceType);
Expand All @@ -1119,7 +1121,6 @@ private void sendPostRequest(WebClient webClient,
try {
LOG.debug("FHIRService:: sendToScoringEngine Post to scoring engine - BEGIN interaction id: {} tenantID :{}",
interactionId, tenantId);

webClient.post()
.uri("?processingAgent=" + tenantId)
.body(BodyInserters.fromValue(null != bundlePayloadWithDisposition
Expand Down Expand Up @@ -1192,16 +1193,15 @@ private void handleResponse(String response,

private void handleError(Map<String, Object> validationPayloadWithDisposition,
Exception e,
HttpServletRequest request) {
HttpServletRequest request,String interactionId) {

validationPayloadWithDisposition.put("exception", e.toString());
LOG.error("ERROR:: FHIRService:: sendToScoringEngine Exception while sending to scoring engine payload with interaction id: {}",
getBundleInteractionId(request), e);
getBundleInteractionId(request,interactionId), e);
}

private Map<String, Object> preparePayload(HttpServletRequest request, String bundlePayload,
Map<String, Object> payloadWithDisposition) {
final var interactionId = getBundleInteractionId(request);
Map<String, Object> payloadWithDisposition,String interactionId) {
LOG.debug("FHIRService:: addValidationResultToPayload BEGIN for interaction id : {}", interactionId);

Map<String, Object> resultMap = null;
Expand Down Expand Up @@ -1594,7 +1594,10 @@ private void registerStateFailure(org.jooq.Configuration jooqCfg, String dataLak
}
}

private String getBundleInteractionId(HttpServletRequest request) {
private String getBundleInteractionId(HttpServletRequest request,String coRrelationId) {
if (StringUtils.isNotEmpty(coRrelationId)) {
return coRrelationId;
}
return InteractionsFilter.getActiveRequestEnc(request).requestId()
.toString();
}
Expand Down

0 comments on commit 17b483c

Please sign in to comment.