From 3e674cddb00c8015210535fbbada9f388d2918c6 Mon Sep 17 00:00:00 2001 From: halprin Date: Wed, 15 May 2024 16:27:18 -0600 Subject: [PATCH] Get the linked metadata even when using the outbound submission ID --- .../etor/EtorDomainRegistration.java | 11 +++-- .../etor/EtorDomainRegistrationTest.groovy | 41 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java index 94ee5a494..ce0f14a62 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java @@ -182,20 +182,23 @@ DomainResponse handleResults(DomainRequest request) { DomainResponse handleMetadata(DomainRequest request) { try { String metadataId = request.getPathParams().get("id"); - Optional metadata = + Optional metadataOptional = partnerMetadataOrchestrator.getMetadata(metadataId); - if (metadata.isEmpty()) { + if (metadataOptional.isEmpty()) { return domainResponseHelper.constructErrorResponse( 404, "Metadata not found for ID: " + metadataId); } + var metadata = metadataOptional.get(); + Set messageIdsToLink = - partnerMetadataOrchestrator.findMessagesIdsToLink(metadataId); + partnerMetadataOrchestrator.findMessagesIdsToLink( + metadata.receivedSubmissionId()); FhirMetadata responseObject = partnerMetadataConverter.extractPublicMetadataToOperationOutcome( - metadata.get(), metadataId, messageIdsToLink); + metadata, metadataId, messageIdsToLink); return domainResponseHelper.constructOkResponseFromString( fhir.encodeResourceToJson(responseObject.getUnderlyingOutcome())); diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistrationTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistrationTest.groovy index dda90c6c0..a36120936 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistrationTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistrationTest.groovy @@ -208,6 +208,47 @@ class EtorDomainRegistrationTest extends Specification { 1 * mockResponseHelper.constructOkResponseFromString(_ as String) >> new DomainResponse(expectedStatusCode) } + def "metadata endpoint returns metadata even when the submitted ID is different from ID used for linking"() { + given: + def expectedStatusCode = 200 + def receivedSubmissionId = "receivedSubmissionId" + def sentSubmissionId = "sentSubmissionId" + def metadata = new PartnerMetadata(receivedSubmissionId, "hash", PartnerMetadataMessageType.ORDER, sendingApp, sendingFacility, receivingApp, receivingFacility, "placer_order_number").withSentSubmissionId(sentSubmissionId) + def linkedMessageIds = Set.of(receivedSubmissionId, "Test1", "Test2") + + def connector = new EtorDomainRegistration() + TestApplicationContext.register(EtorDomainRegistration, connector) + + def request = new DomainRequest() + request.setPathParams(["id": sentSubmissionId]) + + def mockPartnerMetadataOrchestrator = Mock(PartnerMetadataOrchestrator) + TestApplicationContext.register(PartnerMetadataOrchestrator, mockPartnerMetadataOrchestrator) + + def mockResponseHelper = Mock(DomainResponseHelper) + TestApplicationContext.register(DomainResponseHelper, mockResponseHelper) + + def mockPartnerMetadataConverter = Mock(PartnerMetadataConverter) + TestApplicationContext.register(PartnerMetadataConverter, mockPartnerMetadataConverter) + + def mockFhir = Mock(HapiFhir) + mockFhir.encodeResourceToJson(_) >> "" + TestApplicationContext.register(HapiFhir, mockFhir) + + TestApplicationContext.injectRegisteredImplementations() + + when: + def res = connector.handleMetadata(request) + def actualStatusCode = res.statusCode + + then: + actualStatusCode == expectedStatusCode + 1 * mockPartnerMetadataOrchestrator.getMetadata(sentSubmissionId) >> Optional.ofNullable(metadata) + 1 * mockPartnerMetadataOrchestrator.findMessagesIdsToLink(receivedSubmissionId) >> linkedMessageIds + 1 * mockPartnerMetadataConverter.extractPublicMetadataToOperationOutcome(_ as PartnerMetadata, _ as String, linkedMessageIds) >> Mock(FhirMetadata) + 1 * mockResponseHelper.constructOkResponseFromString(_ as String) >> new DomainResponse(expectedStatusCode) + } + def "metadata endpoint returns a 404 response when metadata id is not found"() { given: def expectedStatusCode = 404