Skip to content
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

Rename sent/received submission id to inbound/outbound message id variables #1597

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 -> {
outboundMessageId -> {
Order<?> orders = orderController.parseOrders(request);
sendOrderUseCase.convertAndSend(orders, receivedSubmissionId);
sendOrderUseCase.convertAndSend(orders, outboundMessageId);
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 -> {
outboundMessageId -> {
Result<?> results = resultController.parseResults(request);
sendResultUseCase.convertAndSend(results, receivedSubmissionId);
sendResultUseCase.convertAndSend(results, outboundMessageId);
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.outboundMessageId());

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 outboundMessageId = getOutboundMessageId(request);
boolean markMetadataAsFailed = false;
String errorMessage = "";

try {
return requestHandler.handle(receivedSubmissionId);
return requestHandler.handle(outboundMessageId);
} 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);
outboundMessageId, errorMessage);
} catch (PartnerMetadataException innerE) {
logger.logError("Unable to update metadata status", innerE);
}
}
}
}

protected String getReceivedSubmissionId(DomainRequest request) {
protected String getOutboundMessageId(DomainRequest request) {

String receivedSubmissionId = request.getHeaders().get("recordid");
if (receivedSubmissionId == null || receivedSubmissionId.isEmpty()) {
String outboundMessageId = request.getHeaders().get("recordid");
if (outboundMessageId == null || outboundMessageId.isEmpty()) {
logger.logError("Missing required header or empty: RecordId");
return null;
}
return receivedSubmissionId;
return outboundMessageId;
}
}
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 outboundMessageId the ID for the outbound message returned from ReportStream
* @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 outboundMessageId) throws FhirParseException, UnableToSendMessageException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,67 +21,67 @@ public static SendMessageHelper getInstance() {

private SendMessageHelper() {}

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

public void saveSentMessageSubmissionId(String receivedSubmissionId, String sentSubmissionId) {
if (sentSubmissionId == null || receivedSubmissionId == null) {
public void saveInboundMessageId(String outboundMessageId, String inboundMessageId) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to do both inbound and outbound message saving. @basiliskus Should I leave the old name if that's the case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I think we should remove the Sent part and make it plural. So it would be renamed as saveMessageSubmissionIds or saveSubmissionIds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll rename it to saveMessageSubmissionIds

if (inboundMessageId == null || outboundMessageId == null) {
logger.logWarning(
"Received and/or sent submissionId is null so not saving metadata for sent result");
"Outbound and/or inbound messageId is null so not saving metadata for sent result");
return;
}

try {
partnerMetadataOrchestrator.updateMetadataForSentMessage(
receivedSubmissionId, sentSubmissionId);
partnerMetadataOrchestrator.updateMetadataForInboundMessage(
outboundMessageId, inboundMessageId);
} catch (PartnerMetadataException e) {
logger.logError(
"Unable to update metadata for received submissionId "
+ receivedSubmissionId
+ " and sent submissionId "
+ sentSubmissionId,
"Unable to update metadata for outbound messageId "
+ outboundMessageId
+ " and inbound messageId "
+ inboundMessageId,
e);
}
}

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

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

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

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

logger.logInfo(
"Found messages to link for receivedSubmissionId {}: {}",
receivedSubmissionId,
"Found messages to link for outboundMessageId {}: {}",
outboundMessageId,
messageIdsToLink);
partnerMetadataOrchestrator.linkMessages(messageIdsToLink);
} catch (PartnerMetadataException | MessageLinkException e) {
logger.logError(
"Unable to link messages for received submissionId " + receivedSubmissionId, e);
"Unable to link messages for outbound messageId " + outboundMessageId, e);
}
}
}
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 outboundMessageId The outbound message ID.
* @param inboundMessageId The inbound message 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 outboundMessageId,
String inboundMessageId,
Instant timeReceived,
Instant timeDelivered,
String hash,
Expand All @@ -36,7 +36,7 @@ public record PartnerMetadata(
}

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

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

public PartnerMetadata withSentSubmissionId(String sentSubmissionId) {
public PartnerMetadata withInboundMessageId(String inboundMessageId) {
return new PartnerMetadata(
this.receivedSubmissionId,
sentSubmissionId,
this.outboundMessageId,
inboundMessageId,
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.outboundMessageId,
this.inboundMessageId,
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.outboundMessageId,
this.inboundMessageId,
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.outboundMessageId,
this.inboundMessageId,
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.outboundMessageId,
this.inboundMessageId,
this.timeReceived,
this.timeDelivered,
this.hash,
Expand Down
Loading