Skip to content

Commit

Permalink
Merge branch 'main' into scripts/README-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
saquino0827 authored Dec 13, 2024
2 parents 196cfd1 + e718efd commit c81c799
Show file tree
Hide file tree
Showing 32 changed files with 513 additions and 418 deletions.
2 changes: 1 addition & 1 deletion e2e/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
implementation 'ca.uhn.hapi.fhir:hapi-fhir-structures-r4:7.6.0'
implementation 'ca.uhn.hapi.fhir:hapi-fhir-caching-caffeine:7.6.0'
implementation 'ca.uhn.hapi.fhir:hapi-fhir-validation-resources-r4:7.6.0'
implementation 'org.fhir:ucum:1.0.8'
implementation 'org.fhir:ucum:1.0.9'

testImplementation 'org.apache.groovy:groovy:4.0.24'
testImplementation 'org.spockframework:spock-core:2.3-groovy-4.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public String openApiSpecification() throws UnableToReadOpenApiSpecificationExce
DomainResponse handleOrders(DomainRequest request) {
return handleMessageRequest(
request,
receivedSubmissionId -> {
inboundReportId -> {
Order<?> orders = orderController.parseOrders(request);
sendOrderUseCase.convertAndSend(orders, receivedSubmissionId);
sendOrderUseCase.convertAndSend(orders, inboundReportId);
return domainResponseHelper.constructOkResponse(new OrderResponse(orders));
},
"order");
Expand All @@ -164,9 +164,9 @@ DomainResponse handleOrders(DomainRequest request) {
DomainResponse handleResults(DomainRequest request) {
return handleMessageRequest(
request,
receivedSubmissionId -> {
inboundReportId -> {
Result<?> results = resultController.parseResults(request);
sendResultUseCase.convertAndSend(results, receivedSubmissionId);
sendResultUseCase.convertAndSend(results, inboundReportId);
return domainResponseHelper.constructOkResponse(new ResultResponse(results));
},
"results");
Expand All @@ -186,8 +186,7 @@ DomainResponse handleMetadata(DomainRequest request) {
var metadata = metadataOptional.get();

Set<String> messageIdsToLink =
partnerMetadataOrchestrator.findMessagesIdsToLink(
metadata.receivedSubmissionId());
partnerMetadataOrchestrator.findMessagesIdsToLink(metadata.inboundReportId());

FhirMetadata<?> responseObject =
partnerMetadataConverter.extractPublicMetadataToOperationOutcome(
Expand Down Expand Up @@ -223,12 +222,12 @@ protected DomainResponse handleMessageRequest(
DomainRequest request,
MessageRequestHandler<DomainResponse> requestHandler,
String messageType) {
String receivedSubmissionId = getReceivedSubmissionId(request);
String inboundReportId = getInboundReportId(request);
boolean markMetadataAsFailed = false;
String errorMessage = "";

try {
return requestHandler.handle(receivedSubmissionId);
return requestHandler.handle(inboundReportId);
} catch (FhirParseException e) {
errorMessage = "Unable to parse " + messageType + " request";
logger.logError(errorMessage, e);
Expand All @@ -243,21 +242,21 @@ protected DomainResponse handleMessageRequest(
if (markMetadataAsFailed) {
try {
partnerMetadataOrchestrator.setMetadataStatusToFailed(
receivedSubmissionId, errorMessage);
inboundReportId, errorMessage);
} catch (PartnerMetadataException innerE) {
logger.logError("Unable to update metadata status", innerE);
}
}
}
}

protected String getReceivedSubmissionId(DomainRequest request) {

String receivedSubmissionId = request.getHeaders().get("recordid");
if (receivedSubmissionId == null || receivedSubmissionId.isEmpty()) {
protected String getInboundReportId(DomainRequest request) {
// recordid is the inbound report id
String inboundReportId = request.getHeaders().get("recordid");
if (inboundReportId == null || inboundReportId.isEmpty()) {
logger.logError("Missing required header or empty: RecordId");
return null;
}
return receivedSubmissionId;
return inboundReportId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public interface RSEndpointClient {
String requestWatersEndpoint(String body, String bearerToken)
throws ReportStreamEndpointClientException;

String requestHistoryEndpoint(String submissionId, String bearerToken)
String requestHistoryEndpoint(String outboundReportId, String bearerToken)
throws ReportStreamEndpointClientException;

String requestDeliveryEndpoint(String reportId, String bearerToken)
String requestDeliveryEndpoint(String inboundReportId, String bearerToken)
throws ReportStreamEndpointClientException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public interface MessageRequestHandler<T> {
/**
* Parses the request, converts and sends the message
*
* @param receivedSubmissionId the ID for the submission returned from ReportStream
* @param inboundReportId the report id created by ReportStream and sent to us in the request
* @return the response
* @throws FhirParseException if there is an error parsing the FHIR data
* @throws UnableToSendMessageException if there is an error sending the message
*/
T handle(String receivedSubmissionId) throws FhirParseException, UnableToSendMessageException;
T handle(String inboundReportId) throws FhirParseException, UnableToSendMessageException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,67 +21,66 @@ public static SendMessageHelper getInstance() {

private SendMessageHelper() {}

public void savePartnerMetadataForReceivedMessage(PartnerMetadata partnerMetadata) {
if (partnerMetadata.receivedSubmissionId() == null) {
public void savePartnerMetadataForInboundMessage(PartnerMetadata partnerMetadata) {
if (partnerMetadata.inboundReportId() == null) {
logger.logWarning(
"Received submissionId is null so not saving metadata for received message");
"inboundReportId is null so not saving metadata for received message");
return;
}
try {
partnerMetadataOrchestrator.updateMetadataForReceivedMessage(partnerMetadata);
partnerMetadataOrchestrator.updateMetadataForInboundMessage(partnerMetadata);
} catch (PartnerMetadataException e) {
logger.logError(
"Unable to save metadata for receivedSubmissionId "
+ partnerMetadata.receivedSubmissionId(),
"Unable to save metadata for inboundReportId "
+ partnerMetadata.inboundReportId(),
e);
}
}

public void saveSentMessageSubmissionId(String receivedSubmissionId, String sentSubmissionId) {
if (sentSubmissionId == null || receivedSubmissionId == null) {
public void saveOutboundReportId(String inboundReportId, String outboundReportId) {
if (outboundReportId == null || inboundReportId == null) {
logger.logWarning(
"Received and/or sent submissionId is null so not saving metadata for sent result");
"inboundReportId and/or outboundReportId is null so not saving metadata for sent result");
return;
}

try {
partnerMetadataOrchestrator.updateMetadataForSentMessage(
receivedSubmissionId, sentSubmissionId);
partnerMetadataOrchestrator.updateMetadataForOutboundMessage(
inboundReportId, outboundReportId);
} catch (PartnerMetadataException e) {
logger.logError(
"Unable to update metadata for received submissionId "
+ receivedSubmissionId
+ " and sent submissionId "
+ sentSubmissionId,
"Unable to update metadata for inboundReportId "
+ inboundReportId
+ " and outboundReportId "
+ outboundReportId,
e);
}
}

public void linkMessage(String receivedSubmissionId) {
if (receivedSubmissionId == null) {
logger.logWarning("Received submissionId is null so not linking messages");
public void linkMessage(String inboundReportId) {
if (inboundReportId == null) {
logger.logWarning("inboundReportId is null so not linking messages");
return;
}

try {
Set<String> messageIdsToLink =
partnerMetadataOrchestrator.findMessagesIdsToLink(receivedSubmissionId);
partnerMetadataOrchestrator.findMessagesIdsToLink(inboundReportId);

if (messageIdsToLink == null || messageIdsToLink.isEmpty()) {
return;
}

// Add receivedSubmissionId to complete the list of messageIds to link
messageIdsToLink.add(receivedSubmissionId);
// Add inboundReportId to complete the list of messageIds to link
messageIdsToLink.add(inboundReportId);

logger.logInfo(
"Found messages to link for receivedSubmissionId {}: {}",
receivedSubmissionId,
"Found messages to link for inboundReportId {}: {}",
inboundReportId,
messageIdsToLink);
partnerMetadataOrchestrator.linkMessages(messageIdsToLink);
} catch (PartnerMetadataException | MessageLinkException e) {
logger.logError(
"Unable to link messages for received submissionId " + receivedSubmissionId, e);
logger.logError("Unable to link messages for inboundReportId " + inboundReportId, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
*/
public interface SendMessageUseCase<T> {

void convertAndSend(final T message, final String submissionId)
void convertAndSend(final T message, final String inboundReportId)
throws UnableToSendMessageException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
/**
* The partner-facing metadata.
*
* @param receivedSubmissionId The received submission ID.
* @param sentSubmissionId The sent submission ID.
* @param inboundReportId The inbound report ID.
* @param outboundReportId The outbound report ID.
* @param timeReceived The time the message was received.
* @param timeDelivered The time the message was delivered.
* @param hash The hash of the message.
* @param deliveryStatus the status of the message based on an enum
*/
public record PartnerMetadata(
String receivedSubmissionId,
String sentSubmissionId,
String inboundReportId,
String outboundReportId,
Instant timeReceived,
Instant timeDelivered,
String hash,
Expand All @@ -36,7 +36,7 @@ public record PartnerMetadata(
}

public PartnerMetadata(
String receivedSubmissionId,
String inboundReportId,
String hash,
PartnerMetadataMessageType messageType,
MessageHdDataType sendingApplicationDetails,
Expand All @@ -45,7 +45,7 @@ public PartnerMetadata(
MessageHdDataType receivingFacilityDetails,
String placerOrderNumber) {
this(
receivedSubmissionId,
inboundReportId,
null,
null,
null,
Expand All @@ -60,9 +60,9 @@ public PartnerMetadata(
placerOrderNumber);
}

public PartnerMetadata(String receivedSubmissionId, PartnerMetadataStatus deliveryStatus) {
public PartnerMetadata(String inboundReportId, PartnerMetadataStatus deliveryStatus) {
this(
receivedSubmissionId,
inboundReportId,
null,
null,
null,
Expand All @@ -77,10 +77,10 @@ public PartnerMetadata(String receivedSubmissionId, PartnerMetadataStatus delive
null);
}

public PartnerMetadata withSentSubmissionId(String sentSubmissionId) {
public PartnerMetadata withOutboundReportId(String outboundReportId) {
return new PartnerMetadata(
this.receivedSubmissionId,
sentSubmissionId,
this.inboundReportId,
outboundReportId,
this.timeReceived,
this.timeDelivered,
this.hash,
Expand All @@ -96,8 +96,8 @@ public PartnerMetadata withSentSubmissionId(String sentSubmissionId) {

public PartnerMetadata withTimeReceived(Instant timeReceived) {
return new PartnerMetadata(
this.receivedSubmissionId,
this.sentSubmissionId,
this.inboundReportId,
this.outboundReportId,
timeReceived,
this.timeDelivered,
this.hash,
Expand All @@ -113,8 +113,8 @@ public PartnerMetadata withTimeReceived(Instant timeReceived) {

public PartnerMetadata withTimeDelivered(Instant timeDelivered) {
return new PartnerMetadata(
this.receivedSubmissionId,
this.sentSubmissionId,
this.inboundReportId,
this.outboundReportId,
this.timeReceived,
timeDelivered,
this.hash,
Expand All @@ -130,8 +130,8 @@ public PartnerMetadata withTimeDelivered(Instant timeDelivered) {

public PartnerMetadata withDeliveryStatus(PartnerMetadataStatus deliveryStatus) {
return new PartnerMetadata(
this.receivedSubmissionId,
this.sentSubmissionId,
this.inboundReportId,
this.outboundReportId,
this.timeReceived,
this.timeDelivered,
this.hash,
Expand All @@ -147,8 +147,8 @@ public PartnerMetadata withDeliveryStatus(PartnerMetadataStatus deliveryStatus)

public PartnerMetadata withFailureMessage(String failureMessage) {
return new PartnerMetadata(
this.receivedSubmissionId,
this.sentSubmissionId,
this.inboundReportId,
this.outboundReportId,
this.timeReceived,
this.timeDelivered,
this.hash,
Expand Down
Loading

0 comments on commit c81c799

Please sign in to comment.