Skip to content

Commit

Permalink
Merge branch 'main' into story/1024/transformation-engine-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
basiliskus authored May 7, 2024
2 parents 46306b1 + 9cf6538 commit 7ebbb40
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 21 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 = "centracare.com"
def senderId = "centracare.com"

when:
def orderResponse = orderClient.submit(labOrderJsonFileString, inboundSubmissionId, true)
Expand All @@ -28,12 +28,12 @@ class ConsolidatedSummaryTest extends Specification {
orderResponse.getCode() == expectedStatusCode

when:
def senderNameResponse = ConsolidatedSummaryClient.get(senderName, true)
def senderNameResponse = ConsolidatedSummaryClient.get(senderId, true)
def jsonBody = JsonParser.parseContent(senderNameResponse)

then:
jsonBody.get((jsonBody.keySet().toArray())[0]).stale != null
jsonBody.get((jsonBody.keySet().toArray())[0]).failureReason == null
jsonBody.get(jsonBody.keySet().toArray()[0]).containsKey("failureReason")
jsonBody.get((jsonBody.keySet().toArray())[0]).status != null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,8 @@ public Map<String, Map<String, Object>> getConsolidatedMetadata(String senderNam

public Set<String> findMessagesIdsToLink(String receivedSubmissionId)
throws PartnerMetadataException {
var metadataSet =
partnerMetadataStorage.readMetadataForMessageLinking(receivedSubmissionId);
return metadataSet.stream()
.map(PartnerMetadata::receivedSubmissionId)
.collect(Collectors.toSet());

return partnerMetadataStorage.readMetadataForMessageLinking(receivedSubmissionId);
}

public void linkMessages(Set<String> messageIds) throws MessageLinkException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ Optional<PartnerMetadata> readMetadata(String receivedSubmissionId)
*/
Set<PartnerMetadata> readMetadataForSender(String sender) throws PartnerMetadataException;

Set<PartnerMetadata> readMetadataForMessageLinking(String submissionId)
throws PartnerMetadataException;
Set<String> readMetadataForMessageLinking(String submissionId) throws PartnerMetadataException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Set<PartnerMetadata> readMetadataForSender(String sender)
try {
PreparedStatement statement =
connection.prepareStatement(
"SELECT * FROM metadata WHERE sender = ?");
"SELECT * FROM metadata WHERE sending_facility_details->> 'universalId' = ?");
statement.setString(1, sender);
return statement;
} catch (SQLException e) {
Expand All @@ -110,10 +110,10 @@ public Set<PartnerMetadata> readMetadataForSender(String sender)
}

@Override
public Set<PartnerMetadata> readMetadataForMessageLinking(String submissionId)
public Set<String> readMetadataForMessageLinking(String submissionId)
throws PartnerMetadataException {

Set<PartnerMetadata> metadataSet;
Set<String> metadataSet;
try {
metadataSet =
dao.fetchManyData(
Expand All @@ -122,22 +122,23 @@ public Set<PartnerMetadata> readMetadataForMessageLinking(String submissionId)
PreparedStatement statement =
connection.prepareStatement(
"""
SELECT m2.*
SELECT m2.received_message_id
FROM metadata m1
JOIN metadata m2
ON m1.placer_order_number = m2.placer_order_number
AND (m1.sending_facility_details = m2.sending_facility_details
OR m1.sending_facility_details = m2.receiving_facility_details)
AND m1.received_message_id <> m2.received_message_id
WHERE m1.received_message_id = ?;
-- LIMIT 50 This is a potential fix for load test failures since they link all the ids together;
""");
statement.setString(1, submissionId);
return statement;
} catch (SQLException e) {
throw new RuntimeException(e);
}
},
this::partnerMetadataFromResultSet,
this::idsFromResult,
Collectors.toSet());

return metadataSet;
Expand Down Expand Up @@ -187,6 +188,15 @@ PartnerMetadata partnerMetadataFromResultSet(ResultSet resultSet) {
}
}

String idsFromResult(ResultSet resultSet) {

try {
return resultSet.getString(METADATA_TABLE_RECEIVED_MESSAGE_ID);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

private List<DbColumn> createDbColumnsFromMetadata(PartnerMetadata metadata)
throws FormatterProcessingException {
return List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Set<PartnerMetadata> readMetadataForSender(String senderUniversalId)
}

@Override
public Set<PartnerMetadata> readMetadataForMessageLinking(String receivedSubmissionId)
public Set<String> readMetadataForMessageLinking(String receivedSubmissionId)
throws PartnerMetadataException {
try {
Set<PartnerMetadata> existingMetadata = getPartnerMetadata();
Expand Down Expand Up @@ -146,6 +146,7 @@ public Set<PartnerMetadata> readMetadataForMessageLinking(String receivedSubmiss
.receivingFacilityDetails()))
&& !metadata.receivedSubmissionId()
.equals(receivedSubmissionId))
.map(PartnerMetadata::receivedSubmissionId)
.collect(Collectors.toSet());
} catch (Exception e) {
throw new PartnerMetadataException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ class PartnerMetadataOrchestratorTest extends Specification {
def receivingFacilityDetails = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type")
def partnerMetadata1 = new PartnerMetadata(receivedSubmissionId1, "hash1", PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, placerOrderNumber)
def partnerMetadata2 = new PartnerMetadata(receivedSubmissionId2, "hash2", PartnerMetadataMessageType.RESULT, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, placerOrderNumber)
def metadataSetForMessageLinking = Set.of(partnerMetadata1, partnerMetadata2)
def metadataSetForMessageLinking = Set.of(receivedSubmissionId1, receivedSubmissionId2)
mockPartnerMetadataStorage.readMetadataForMessageLinking(receivedSubmissionId) >> metadataSetForMessageLinking

when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ class FilePartnerMetadataStorageTest extends Specification {
def metadataSetWithMatchingSendingFacilityDetails = FilePartnerMetadataStorage.getInstance().readMetadataForMessageLinking(receivedSubmissionId1)

then:
metadataSetWithMatchingSendingFacilityDetails.contains(otherMatchingSendingFacilityDetailsMetadata1)
!metadataSetWithMatchingSendingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata1)
metadataSetWithMatchingSendingFacilityDetails.contains(otherMatchingSendingFacilityDetailsMetadata1.receivedSubmissionId())
!metadataSetWithMatchingSendingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata1.receivedSubmissionId())

when:
def receivedSubmissionId2 = "receivedSubmissionId2"
Expand All @@ -158,8 +158,8 @@ class FilePartnerMetadataStorageTest extends Specification {
def metadataSetWithMatchingSendingAndReceivingFacilityDetails = FilePartnerMetadataStorage.getInstance().readMetadataForMessageLinking(receivedSubmissionId2)

then:
metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingReceivingFacilityDetailsMetadata2)
!metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata2)
metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingReceivingFacilityDetailsMetadata2.receivedSubmissionId())
!metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata2.receivedSubmissionId())
}

def "readMetadataForMessageLinking returns an empty set when no metadata is found"() {
Expand Down

0 comments on commit 7ebbb40

Please sign in to comment.