Skip to content
This repository has been archived by the owner on Feb 7, 2025. It is now read-only.

Commit

Permalink
Revisit 990 (#1040)
Browse files Browse the repository at this point in the history
* delete sender and receiver from partnerMetadata

* fixed file storage failing test

* fixed EtorDomainRegistrationTest failing test

* MetadataTest changes

* delete sender and receiver columns and ignore unknown properties

* all test pass

* deleted extra colons

* Do not extract receiver from RS history API

* deleted unused variable from unit test

* fixed failing tests

* Remove a ParterMetadata constructor that is no longer needed

* clean-up test new lines

* clean-up test new lines

* Rename test variable

---------

Co-authored-by: halprin <[email protected]>
  • Loading branch information
jorg3lopez and halprin authored Apr 25, 2024
1 parent 815cb40 commit 373dae5
Show file tree
Hide file tree
Showing 17 changed files with 1,720 additions and 1,684 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ConsolidatedSummaryTest extends Specification {

def orderClient = new EndpointClient("/v1/etor/orders")
def labOrderJsonFileString = Files.readString(Path.of("../examples/Test/e2e/orders/002_ORM_O01.fhir"))
def senderName = "PLACE_HOLDER" //TODO: when story #990 is implemented, update this to be the sender from the 002_ORM_O01.fhir message
def senderName = "centracare.com"

when:
def orderResponse = orderClient.submit(labOrderJsonFileString, inboundSubmissionId, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class MetadataTest extends Specification {

[
"linked messages",
"sender name",
"receiver name",
"sender universal id",
"receiver universal id",
"ingestion",
"payload hash",
"delivery status",
Expand Down Expand Up @@ -90,8 +90,8 @@ class MetadataTest extends Specification {

[
"linked messages",
"sender name",
"receiver name",
"sender universal id",
"receiver universal id",
"ingestion",
"payload hash",
"delivery status",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OrderTest extends Specification {

def "an order response is returned from the ETOR order endpoint"() {
given:
def expectedFhirResourceId = "Bundle/1696524903034430000.eb38702e-23df-4650-9e4c-c7d4b3b6b92b"
def expectedFhirResourceId = "Bundle/1713991685806650392.f865cc8e-d438-4d5f-9147-05930f25a997"
def expectedPatientId = "11102779"

when:
Expand All @@ -37,7 +37,7 @@ class OrderTest extends Specification {
def parsedSentPayload = JsonParser.parse(sentPayload)

then:
parsedSentPayload.entry[24].resource.contact.name.text.contains("SADIE S SMITH")
parsedSentPayload.entry[3].resource.contact[0].name.family.contains("SMITH")
}

def "check that ETOR processing code is added to the order before sending to report stream"() {
Expand Down Expand Up @@ -72,7 +72,7 @@ class OrderTest extends Specification {
//test that everything else is the same except the MessageHeader's event, Patient contact, and etor processing tag
parsedSentPayload.entry[0].resource.remove("eventCoding")
parsedLabOrderJsonFile.entry[0].resource.remove("eventCoding")
parsedSentPayload.entry[24].resource.remove("contact")
parsedSentPayload.entry[3].resource.remove("contact")
parsedSentPayload.entry[0].resource.meta.tag.remove(1)

parsedSentPayload == parsedLabOrderJsonFile
Expand Down
14 changes: 14 additions & 0 deletions etor/databaseMigrations/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,17 @@ databaseChangeLog:
columnName: receiving_facility_details
newDataType: jsonb
tableName: metadata

- changeSet:
id: 7
author: Jorge.Lopez
labels: update-metadata-table
context: metadata
comment: delete sender and receiver columns from metadata table
changes:
- dropColumn:
tableName: metadata
columnName: sender
- dropColumn:
tableName: metadata
columnName: receiver
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*
* @param receivedSubmissionId The received submission ID.
* @param sentSubmissionId The sent submission ID.
* @param sender The name of the sender of the message.
* @param receiver The name of the receiver of the message.
* @param timeReceived The time the message was received.
* @param timeDelivered The time the message was delivered.
* @param hash The hash of the message.
Expand All @@ -18,8 +16,6 @@
public record PartnerMetadata(
String receivedSubmissionId,
String sentSubmissionId,
String sender,
String receiver,
Instant timeReceived,
Instant timeDelivered,
String hash,
Expand All @@ -41,11 +37,7 @@ public record PartnerMetadata(

public PartnerMetadata(
String receivedSubmissionId,
String sender,
Instant timeReceived,
Instant timeDelivered,
String hash,
PartnerMetadataStatus deliveryStatus,
PartnerMetadataMessageType messageType,
MessageHdDataType sendingApplicationDetails,
MessageHdDataType sendingFacilityDetails,
Expand All @@ -55,35 +47,6 @@ public PartnerMetadata(
this(
receivedSubmissionId,
null,
sender,
null,
timeReceived,
timeDelivered,
hash,
deliveryStatus,
null,
messageType,
sendingApplicationDetails,
sendingFacilityDetails,
receivingApplicationDetails,
receivingFacilityDetails,
placerOrderNumber);
}

public PartnerMetadata(
String receivedSubmissionId,
String hash,
PartnerMetadataMessageType messageType,
MessageHdDataType sendingApplicationDetails,
MessageHdDataType sendingFacilityDetails,
MessageHdDataType receivingApplicationDetails,
MessageHdDataType receivingFacilityDetails,
String placerOrderNumber) {
this(
receivedSubmissionId,
null,
null,
null,
null,
null,
hash,
Expand All @@ -104,8 +67,6 @@ public PartnerMetadata(String receivedSubmissionId, PartnerMetadataStatus delive
null,
null,
null,
null,
null,
deliveryStatus,
null,
null,
Expand All @@ -120,46 +81,6 @@ public PartnerMetadata withSentSubmissionId(String sentSubmissionId) {
return new PartnerMetadata(
this.receivedSubmissionId,
sentSubmissionId,
this.sender,
this.receiver,
this.timeReceived,
this.timeDelivered,
this.hash,
this.deliveryStatus,
this.failureReason,
this.messageType,
this.sendingApplicationDetails,
this.sendingFacilityDetails,
this.receivingApplicationDetails,
this.receivingFacilityDetails,
this.placerOrderNumber);
}

public PartnerMetadata withSender(String sender) {
return new PartnerMetadata(
this.receivedSubmissionId,
this.sentSubmissionId,
sender,
this.receiver,
this.timeReceived,
this.timeDelivered,
this.hash,
this.deliveryStatus,
this.failureReason,
this.messageType,
this.sendingApplicationDetails,
this.sendingFacilityDetails,
this.receivingApplicationDetails,
this.receivingFacilityDetails,
this.placerOrderNumber);
}

public PartnerMetadata withReceiver(String receiver) {
return new PartnerMetadata(
this.receivedSubmissionId,
this.sentSubmissionId,
this.sender,
receiver,
this.timeReceived,
this.timeDelivered,
this.hash,
Expand All @@ -177,8 +98,6 @@ public PartnerMetadata withTimeReceived(Instant timeReceived) {
return new PartnerMetadata(
this.receivedSubmissionId,
this.sentSubmissionId,
this.sender,
this.receiver,
timeReceived,
this.timeDelivered,
this.hash,
Expand All @@ -196,8 +115,6 @@ public PartnerMetadata withTimeDelivered(Instant timeDelivered) {
return new PartnerMetadata(
this.receivedSubmissionId,
this.sentSubmissionId,
this.sender,
this.receiver,
this.timeReceived,
timeDelivered,
this.hash,
Expand All @@ -215,8 +132,6 @@ public PartnerMetadata withDeliveryStatus(PartnerMetadataStatus deliveryStatus)
return new PartnerMetadata(
this.receivedSubmissionId,
this.sentSubmissionId,
this.sender,
this.receiver,
this.timeReceived,
this.timeDelivered,
this.hash,
Expand All @@ -234,8 +149,6 @@ public PartnerMetadata withFailureMessage(String failureMessage) {
return new PartnerMetadata(
this.receivedSubmissionId,
this.sentSubmissionId,
this.sender,
this.receiver,
this.timeReceived,
this.timeDelivered,
this.hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ public void updateMetadataForReceivedMessage(PartnerMetadata partnerMetadata)
"Unable to retrieve metadata from RS delivery API", e);
}

String sender = "PLACE_HOLDER";
logger.logInfo("Updating metadata with sender: {}, timeReceived: {}", sender, timeReceived);
PartnerMetadata updatedPartnerMetadata =
partnerMetadata.withSender(sender).withTimeReceived(timeReceived);
logger.logInfo("Updating metadata with timeReceived: {}", timeReceived);
PartnerMetadata updatedPartnerMetadata = partnerMetadata.withTimeReceived(timeReceived);
partnerMetadataStorage.saveMetadata(updatedPartnerMetadata);
}

Expand Down Expand Up @@ -137,7 +135,6 @@ public Optional<PartnerMetadata> getMetadata(String receivedSubmissionId)
"Receiver name not found in metadata or delivery status still pending, looking up {} from RS history API",
sentSubmissionId);

String receiver;
String rsStatus;
String rsMessage = "";
String timeDelivered;
Expand All @@ -146,19 +143,18 @@ public Optional<PartnerMetadata> getMetadata(String receivedSubmissionId)
String responseBody =
rsclient.requestHistoryEndpoint(sentSubmissionId, bearerToken);
var parsedResponseBody = getDataFromReportStream(responseBody);
receiver = parsedResponseBody[0];
rsStatus = parsedResponseBody[1];
rsMessage = parsedResponseBody[2];
timeDelivered = parsedResponseBody[3];
rsStatus = parsedResponseBody[0];
rsMessage = parsedResponseBody[1];
timeDelivered = parsedResponseBody[2];
} catch (ReportStreamEndpointClientException | FormatterProcessingException e) {
throw new PartnerMetadataException(
"Unable to retrieve metadata from RS history API", e);
}

var ourStatus = ourStatusFromReportStreamStatus(rsStatus);

logger.logInfo("Updating metadata with receiver {} and status {}", receiver, ourStatus);
partnerMetadata = partnerMetadata.withReceiver(receiver).withDeliveryStatus(ourStatus);
logger.logInfo("Updating metadata with status {}", ourStatus);
partnerMetadata = partnerMetadata.withDeliveryStatus(ourStatus);

if (ourStatus == PartnerMetadataStatus.FAILED) {
partnerMetadata = partnerMetadata.withFailureMessage(rsMessage);
Expand Down Expand Up @@ -280,21 +276,6 @@ String[] getDataFromReportStream(String responseBody) throws FormatterProcessing
Map<String, Object> responseObject =
formatter.convertJsonToObject(responseBody, new TypeReference<>() {});

String receiver;
try {
ArrayList<?> destinations = (ArrayList<?>) responseObject.get("destinations");
Map<?, ?> destination = (Map<?, ?>) destinations.get(0);
String organizationId = destination.get("organization_id").toString();
String service = destination.get("service").toString();
receiver = organizationId + "." + service;
} catch (IndexOutOfBoundsException e) {
// the destinations have not been determined yet by RS
receiver = null;
} catch (Exception e) {
throw new FormatterProcessingException(
"Unable to extract receiver name from response due to unexpected format", e);
}

String overallStatus;
try {
overallStatus = (String) responseObject.get("overallStatus");
Expand Down Expand Up @@ -324,7 +305,7 @@ String[] getDataFromReportStream(String responseBody) throws FormatterProcessing
"Unable to extract timeDelivered due to unexpected format", e);
}

return new String[] {receiver, overallStatus, errorMessages.toString(), timeDelivered};
return new String[] {overallStatus, errorMessages.toString(), timeDelivered};
}

PartnerMetadataStatus ourStatusFromReportStreamStatus(String rsStatus) {
Expand All @@ -342,7 +323,7 @@ PartnerMetadataStatus ourStatusFromReportStreamStatus(String rsStatus) {
}

private boolean metadataIsStale(PartnerMetadata partnerMetadata) {
return partnerMetadata.receiver() == null
return partnerMetadata.receivingFacilityDetails().universalId() == null
|| partnerMetadata.deliveryStatus() == PartnerMetadataStatus.PENDING;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ PartnerMetadata partnerMetadataFromResultSet(ResultSet resultSet) {
return new PartnerMetadata(
resultSet.getString(METADATA_TABLE_RECEIVED_MESSAGE_ID),
resultSet.getString("sent_message_id"),
resultSet.getString("sender"),
resultSet.getString("receiver"),
timeReceived,
timeDelivered,
resultSet.getString("hash_of_message"),
Expand Down Expand Up @@ -198,8 +196,6 @@ private List<DbColumn> createDbColumnsFromMetadata(PartnerMetadata metadata)
false,
Types.VARCHAR),
new DbColumn("sent_message_id", metadata.sentSubmissionId(), true, Types.VARCHAR),
new DbColumn("sender", metadata.sender(), false, Types.VARCHAR),
new DbColumn("receiver", metadata.receiver(), true, Types.VARCHAR),
new DbColumn("hash_of_message", metadata.hash(), false, Types.VARCHAR),
new DbColumn(
"time_received",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ public String getPatientId() {
.flatMap(patient -> patient.getIdentifier().stream())
.filter(
identifier ->
identifier
.getType()
.hasCoding(
"http://terminology.hl7.org/CodeSystem/v2-0203",
"MR"))
"MR".equals(identifier.getType().getCodingFirstRep().getCode()))
.map(Identifier::getValue)
.findFirst()
.orElse("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ public FhirMetadata<?> extractPublicMetadataToOperationOutcome(
createInformationIssueComponent(
"linked messages", messageIdsToLink.toString()));

operation.getIssue().add(createInformationIssueComponent("sender name", metadata.sender()));
operation
.getIssue()
.add(createInformationIssueComponent("receiver name", metadata.receiver()));
.add(
createInformationIssueComponent(
"sender universal id",
metadata.sendingFacilityDetails().universalId()));
operation
.getIssue()
.add(
createInformationIssueComponent(
"receiver universal id",
metadata.receivingFacilityDetails().universalId()));

String ingestion = null;
String delivered = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,19 @@ public void saveMetadata(final PartnerMetadata metadata) throws PartnerMetadataE
}

@Override
public Set<PartnerMetadata> readMetadataForSender(String sender)
public Set<PartnerMetadata> readMetadataForSender(String senderUniversalId)
throws PartnerMetadataException {
try {
return getPartnerMetadata().stream()
.filter(metadata -> metadata.sender().equals(sender))
.filter(
metadata ->
metadata.sendingFacilityDetails()
.universalId()
.equals(senderUniversalId))
.collect(Collectors.toSet());
} catch (Exception e) {
throw new PartnerMetadataException("Failed reading metadata for sender: " + sender, e);
throw new PartnerMetadataException(
"Failed reading metadata for sender: " + senderUniversalId, e);
}
}

Expand Down
Loading

0 comments on commit 373dae5

Please sign in to comment.