generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation to send the FHIR result to RS Waters endpoint (#859)
* Refactored to extract common code into helper function and implemented send method for results * Added methods for results and order sender * Fixed typo * Updated tests to reflect new changes * Moved ReportStreamSenderHelper resgistration * Added java docs * Added test coverage * Improved assertions for test
- Loading branch information
1 parent
f283b48
commit 8533fb8
Showing
8 changed files
with
259 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
.../java/gov/hhs/cdc/trustedintermediary/external/reportstream/ReportStreamSenderHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package gov.hhs.cdc.trustedintermediary.external.reportstream; | ||
|
||
import gov.hhs.cdc.trustedintermediary.etor.RSEndpointClient; | ||
import gov.hhs.cdc.trustedintermediary.etor.messages.UnableToSendMessageException; | ||
import gov.hhs.cdc.trustedintermediary.etor.metadata.EtorMetadataStep; | ||
import gov.hhs.cdc.trustedintermediary.wrappers.Logger; | ||
import gov.hhs.cdc.trustedintermediary.wrappers.MetricMetadata; | ||
import gov.hhs.cdc.trustedintermediary.wrappers.formatter.Formatter; | ||
import gov.hhs.cdc.trustedintermediary.wrappers.formatter.FormatterProcessingException; | ||
import gov.hhs.cdc.trustedintermediary.wrappers.formatter.TypeReference; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import javax.inject.Inject; | ||
|
||
/** Helper class for sending messages to ReportStream */ | ||
public class ReportStreamSenderHelper { | ||
private static final ReportStreamSenderHelper INSTANCE = new ReportStreamSenderHelper(); | ||
|
||
@Inject RSEndpointClient rsclient; | ||
@Inject Formatter formatter; | ||
@Inject Logger logger; | ||
@Inject MetricMetadata metadata; | ||
|
||
private ReportStreamSenderHelper() {} | ||
|
||
public static ReportStreamSenderHelper getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
public Optional<String> sendOrderToReportStream(String body, String fhirResourceId) | ||
throws UnableToSendMessageException { | ||
return sendToReportStream(body, fhirResourceId, "order"); | ||
} | ||
|
||
public Optional<String> sendResultToReportStream(String body, String fhirResourceId) | ||
throws UnableToSendMessageException { | ||
return sendToReportStream(body, fhirResourceId, "result"); | ||
} | ||
|
||
protected Optional<String> sendToReportStream( | ||
String body, String fhirResourceId, String messageType) | ||
throws UnableToSendMessageException { | ||
String bearerToken; | ||
String rsResponseBody; | ||
|
||
try { | ||
bearerToken = rsclient.getRsToken(); | ||
rsResponseBody = rsclient.requestWatersEndpoint(body, bearerToken); | ||
} catch (ReportStreamEndpointClientException e) { | ||
throw new UnableToSendMessageException( | ||
"Unable to send " + messageType + " to ReportStream", e); | ||
} | ||
|
||
logger.logInfo("{} successfully sent to ReportStream", messageType); | ||
metadata.put(fhirResourceId, EtorMetadataStep.SENT_TO_REPORT_STREAM); | ||
|
||
Optional<String> sentSubmissionId = getSubmissionId(rsResponseBody); | ||
if (sentSubmissionId.isEmpty()) { | ||
logger.logError("Unable to retrieve sentSubmissionId from ReportStream response"); | ||
} else { | ||
logger.logInfo("ReportStream response's sentSubmissionId={}", sentSubmissionId); | ||
} | ||
|
||
return sentSubmissionId; | ||
} | ||
|
||
protected Optional<String> getSubmissionId(String rsResponseBody) { | ||
try { | ||
Map<String, Object> rsResponse = | ||
formatter.convertJsonToObject(rsResponseBody, new TypeReference<>() {}); | ||
return Optional.ofNullable(rsResponse.get("submissionId").toString()); | ||
} catch (FormatterProcessingException e) { | ||
logger.logError("Unable to get the submissionId", e); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.