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 reportId variables #1601

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
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 @@ -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
pluckyswan marked this conversation as resolved.
Show resolved Hide resolved
* @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 saveReportIds(String inboundReportId, String outboundReportId) {
pluckyswan marked this conversation as resolved.
Show resolved Hide resolved
if (outboundReportId == null || inboundReportId == null) {
logger.logWarning(
"Received and/or sent submissionId is null so not saving metadata for sent result");
"Inbound 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 @@ -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