Skip to content

Commit

Permalink
Get the linked metadata even when using the outbound submission ID
Browse files Browse the repository at this point in the history
  • Loading branch information
halprin committed May 15, 2024
1 parent 9838a71 commit 3e674cd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,23 @@ DomainResponse handleResults(DomainRequest request) {
DomainResponse handleMetadata(DomainRequest request) {
try {
String metadataId = request.getPathParams().get("id");
Optional<PartnerMetadata> metadata =
Optional<PartnerMetadata> 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<String> 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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3e674cd

Please sign in to comment.