generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation to send the FHIR result to RS Waters endpoint #859
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
813df8f
Refactored to extract common code into helper function and implemente…
basiliskus 7dafe6f
Added methods for results and order sender
basiliskus db68619
Fixed typo
basiliskus eb6aef1
Updated tests to reflect new changes
basiliskus 1901467
Moved ReportStreamSenderHelper resgistration
basiliskus dcc221d
Added java docs
basiliskus 6fb0d78
Added test coverage
basiliskus a24fce5
Improved assertions for test
basiliskus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that we're using a helper class instead of inheritance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, we're also using a helper class as well in our other PR for the Order/Result Conversion use cases.