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

Revisit 990 #1040

Merged
merged 17 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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 @@ -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,7 +37,6 @@ public record PartnerMetadata(

public PartnerMetadata(
String receivedSubmissionId,
String sender,
Instant timeReceived,
Instant timeDelivered,
String hash,
Expand All @@ -55,8 +50,6 @@ public PartnerMetadata(
this(
receivedSubmissionId,
null,
sender,
null,
timeReceived,
timeDelivered,
hash,
Expand Down Expand Up @@ -84,8 +77,6 @@ public PartnerMetadata(
null,
null,
null,
null,
null,
hash,
null,
null,
Expand All @@ -104,8 +95,6 @@ public PartnerMetadata(String receivedSubmissionId, PartnerMetadataStatus delive
null,
null,
null,
null,
null,
deliveryStatus,
null,
null,
Expand All @@ -120,46 +109,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 +126,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 +143,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 +160,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 +177,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 @@ -162,8 +162,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 @@ -197,8 +195,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
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class EtorDomainRegistrationTest extends Specification {
given:
def expectedStatusCode = 200
def receivedSubmissionId = "receivedSubmissionId"
def metadata = new PartnerMetadata("receivedSubmissionId", "sender", Instant.now(), null,
def metadata = new PartnerMetadata("receivedSubmissionId", Instant.now(), null,
"hash", PartnerMetadataStatus.DELIVERED, PartnerMetadataMessageType.ORDER,
sendingApp, sendingFacility, receivingApp, receivingFacility, "placer_order_number")
def linkedMessageIds = new HashSet<>(Set.of(receivedSubmissionId, "Test1", "Test2"))
Expand Down
Loading
Loading