StandardOutboundPatientDiscoveryDeferredRequest extends AbstractOutboundPatientDiscoveryDeferredRequest { @Override @OutboundProcessingEvent(beforeBuilder = PRPAIN201305UV02EventDescriptionBuilder.class, afterReturningBuilder = MCCIIN000002UV01EventDescriptionBuilder.class, serviceType = "Patient Discovery Deferred Request", version = "1.0") public MCCIIN000002UV01 processPatientDiscoveryAsyncReq(PRPAIN201305UV02 message, AssertionType assertion, NhinTargetCommunitiesType targets) { logInfoServiceProcess(this.getClass()); MCCIIN000002UV01 ack = new MCCIIN000002UV01(); List<UrlInfo> urlInfoList = getTargetEndpoints(targets); if (NullChecker.isNotNullish(urlInfoList)) { createLocalHCIDtoPatientAAMapping(message, assertion, targets); createMessageIdToPatientIdCorrelation(message, assertion); for (UrlInfo urlInfo : urlInfoList) { RespondingGatewayPRPAIN201305UV02RequestType newRequest = createNewRespondingGatewayRequestForOneTarget( message, assertion, targets, urlInfo.getHcid()); auditRequest(message, assertion, msgUtils.convertFirstToNhinTargetSystemType(targets)); if (isPolicyValid(newRequest)) { ack = sendToNhin(newRequest.getPRPAIN201305UV02(), newRequest.getAssertion(), urlInfo, targets. getExchangeName()); } else { ack = HL7AckTransforms.createAckErrorFrom201305(message, "Policy Check Failed"); } } } else { String ackMsg = "No targets were found for the Patient Discovery Request"; LOG.warn(ackMsg); ack = HL7AckTransforms.createAckErrorFrom201305(message, ackMsg); } return ack; } StandardOutboundPatientDiscoveryDeferredRequest();  StandardOutboundPatientDiscoveryDeferredRequest(PatientDiscovery201305Processor pd201305Processor,
        AsyncMessageProcessHelper asyncProcessHelper, PatientDiscoveryPolicyChecker policyChecker,
        OutboundPatientDiscoveryDeferredRequestDelegate delegate, PDDeferredCorrelationDao correlationDao,
        ExchangeManager exchangeManager, PatientDiscoveryDeferredRequestAuditLogger auditLogger); @Override @OutboundProcessingEvent(beforeBuilder = PRPAIN201305UV02EventDescriptionBuilder.class, afterReturningBuilder = MCCIIN000002UV01EventDescriptionBuilder.class, serviceType = "Patient Discovery Deferred Request", version = "1.0") MCCIIN000002UV01 processPatientDiscoveryAsyncReq(PRPAIN201305UV02 message, AssertionType assertion,
        NhinTargetCommunitiesType targets); @Override PatientDiscoveryDeferredRequestAuditLogger getPatientDiscoveryDeferredAuditLogger();  }
@Test public void invoke() throws ExchangeManagerException { List<UrlInfo> urlInfoList = createUrlInfoList("1.1", "2.2"); PatientDiscoveryDeferredRequestAuditLogger auditLogger = getAuditLogger(true); when( exchangeManager.getEndpointURLFromNhinTargetCommunities(eq(targets), eq(NhincConstants.PATIENT_DISCOVERY_DEFERRED_REQ_SERVICE_NAME))).thenReturn(urlInfoList); when(pd201305Processor.createNewRequest(request, "1.1")).thenReturn(firstTargetRequest); when(pd201305Processor.createNewRequest(request, "2.2")).thenReturn(secondTargetRequest); when(pd201305Processor.extractPatientIdFrom201305(request)).thenReturn(patientId); when(asyncProcessHelper.copyAssertionTypeObject(assertion)).thenReturn(assertion); when(policyChecker.checkOutgoingPolicy(any(RespondingGatewayPRPAIN201305UV02RequestType.class))).thenReturn( true); when(orchestratableResponse.getResponse()).thenReturn(expectedResponse); when(delegate.process(any(OutboundPatientDiscoveryDeferredRequestOrchestratable.class))).thenReturn( orchestratableResponse); StandardOutboundPatientDiscoveryDeferredRequest standardPatientDiscovery = new StandardOutboundPatientDiscoveryDeferredRequest(pd201305Processor, asyncProcessHelper, policyChecker, delegate, correlationDao, exchangeManager, auditLogger); MCCIIN000002UV01 actualResponse = standardPatientDiscovery.processPatientDiscoveryAsyncReq(request, assertion, targets); assertSame(expectedResponse, actualResponse); ArgumentCaptor<RespondingGatewayPRPAIN201305UV02RequestType> requestArgument = ArgumentCaptor .forClass(RespondingGatewayPRPAIN201305UV02RequestType.class); verify(pd201305Processor).storeLocalMapping(requestArgument.capture()); assertEquals(request, requestArgument.getValue().getPRPAIN201305UV02()); verify(correlationDao).saveOrUpdate("messageId", patientId); requestArgument.getAllValues().clear(); verify(policyChecker, times(2)).checkOutgoingPolicy(requestArgument.capture()); assertEquals(firstTargetRequest, requestArgument.getAllValues().get(0).getPRPAIN201305UV02()); assertEquals(secondTargetRequest, requestArgument.getAllValues().get(1).getPRPAIN201305UV02()); assertNotNull("Assertion MessageId is null", assertion.getMessageId()); verify(mockEJBLogger, atLeast(1)).auditRequestMessage(eq(request), eq(assertion), any(NhinTargetSystemType.class), eq(NhincConstants.AUDIT_LOG_OUTBOUND_DIRECTION), eq(NhincConstants.AUDIT_LOG_NHIN_INTERFACE), eq(Boolean.TRUE), isNull(Properties.class), eq(NhincConstants.PATIENT_DISCOVERY_DEFERRED_REQ_SERVICE_NAME), any(PatientDiscoveryDeferredRequestAuditTransforms.class)); }
@Test public void noTargets() throws ExchangeManagerException { PatientDiscoveryDeferredRequestAuditLogger auditLogger = getAuditLogger(true); when( exchangeManager.getEndpointURLFromNhinTargetCommunities(eq(targets), eq(NhincConstants.PATIENT_DISCOVERY_DEFERRED_REQ_SERVICE_NAME))).thenThrow( new ExchangeManagerException()); StandardOutboundPatientDiscoveryDeferredRequest standardPatientDiscovery = new StandardOutboundPatientDiscoveryDeferredRequest(null, null, null, null, null, exchangeManager, auditLogger); MCCIIN000002UV01 errorResponse = standardPatientDiscovery.processPatientDiscoveryAsyncReq(request, assertion, targets); assertEquals(HL7AckTransforms.ACK_DETAIL_TYPE_CODE_ERROR, errorResponse.getAcknowledgement().get(0) .getAcknowledgementDetail().get(0).getTypeCode().toString()); assertEquals( "No targets were found for the Patient Discovery Request", errorResponse.getAcknowledgement().get(0).getAcknowledgementDetail().get(0).getText().getContent() .get(0).toString()); assertNotNull("Assertion MessageId is null", assertion.getMessageId()); verify(mockEJBLogger, never()).auditRequestMessage(eq(request), eq(assertion), any(NhinTargetSystemType.class), eq(NhincConstants.AUDIT_LOG_OUTBOUND_DIRECTION), eq(NhincConstants.AUDIT_LOG_NHIN_INTERFACE), eq(Boolean.TRUE), isNull(Properties.class), eq(NhincConstants.PATIENT_DISCOVERY_DEFERRED_REQ_SERVICE_NAME), any(PatientDiscoveryDeferredRequestAuditTransforms.class)); }
@Test public void policyFailed() throws ExchangeManagerException { List<UrlInfo> urlInfoList = createUrlInfoList("1.1"); PatientDiscoveryDeferredRequestAuditLogger auditLogger = getAuditLogger(true); when( exchangeManager.getEndpointURLFromNhinTargetCommunities(eq(targets), eq(NhincConstants.PATIENT_DISCOVERY_DEFERRED_REQ_SERVICE_NAME))).thenReturn(urlInfoList); when(pd201305Processor.createNewRequest(eq(request), any(String.class))).thenReturn(firstTargetRequest); when(pd201305Processor.extractPatientIdFrom201305(request)).thenReturn(patientId); when(asyncProcessHelper.copyAssertionTypeObject(assertion)).thenReturn(assertion); when(policyChecker.checkOutgoingPolicy(any(RespondingGatewayPRPAIN201305UV02RequestType.class))).thenReturn( false); StandardOutboundPatientDiscoveryDeferredRequest standardPatientDiscovery = new StandardOutboundPatientDiscoveryDeferredRequest(pd201305Processor, asyncProcessHelper, policyChecker, delegate, correlationDao, exchangeManager, auditLogger); MCCIIN000002UV01 errorResponse = standardPatientDiscovery.processPatientDiscoveryAsyncReq(request, assertion, targets); assertEquals(HL7AckTransforms.ACK_DETAIL_TYPE_CODE_ERROR, errorResponse.getAcknowledgement().get(0) .getAcknowledgementDetail().get(0).getTypeCode().toString()); assertEquals("Policy Check Failed", errorResponse.getAcknowledgement().get(0).getAcknowledgementDetail().get(0) .getText().getContent().get(0).toString()); ArgumentCaptor<RespondingGatewayPRPAIN201305UV02RequestType> requestArgument = ArgumentCaptor .forClass(RespondingGatewayPRPAIN201305UV02RequestType.class); verify(pd201305Processor).storeLocalMapping(requestArgument.capture()); assertEquals(request, requestArgument.getValue().getPRPAIN201305UV02()); verify(correlationDao).saveOrUpdate("messageId", patientId); requestArgument.getAllValues().clear(); verify(policyChecker).checkOutgoingPolicy(requestArgument.capture()); assertEquals(firstTargetRequest, requestArgument.getValue().getPRPAIN201305UV02()); assertNotNull("Assertion MessageId is null", assertion.getMessageId()); verify(mockEJBLogger).auditRequestMessage(eq(request), eq(assertion), any(NhinTargetSystemType.class), eq(NhincConstants.AUDIT_LOG_OUTBOUND_DIRECTION), eq(NhincConstants.AUDIT_LOG_NHIN_INTERFACE), eq(Boolean.TRUE), isNull(Properties.class), eq(NhincConstants.PATIENT_DISCOVERY_DEFERRED_REQ_SERVICE_NAME), any(PatientDiscoveryDeferredRequestAuditTransforms.class)); }
@Test public void auditOffForOutboundPDDeferredReq() throws ExchangeManagerException { List<UrlInfo> urlInfoList = createUrlInfoList("1.1", "2.2"); PatientDiscoveryDeferredRequestAuditLogger auditLogger = getAuditLogger(false); when( exchangeManager.getEndpointURLFromNhinTargetCommunities(eq(targets), eq(NhincConstants.PATIENT_DISCOVERY_DEFERRED_REQ_SERVICE_NAME))).thenReturn(urlInfoList); when(pd201305Processor.createNewRequest(request, "1.1")).thenReturn(firstTargetRequest); when(pd201305Processor.createNewRequest(request, "2.2")).thenReturn(secondTargetRequest); when(pd201305Processor.extractPatientIdFrom201305(request)).thenReturn(patientId); when(asyncProcessHelper.copyAssertionTypeObject(assertion)).thenReturn(assertion); when(policyChecker.checkOutgoingPolicy(any(RespondingGatewayPRPAIN201305UV02RequestType.class))).thenReturn( true); when(orchestratableResponse.getResponse()).thenReturn(expectedResponse); when(delegate.process(any(OutboundPatientDiscoveryDeferredRequestOrchestratable.class))).thenReturn( orchestratableResponse); StandardOutboundPatientDiscoveryDeferredRequest standardPatientDiscovery = new StandardOutboundPatientDiscoveryDeferredRequest(pd201305Processor, asyncProcessHelper, policyChecker, delegate, correlationDao, exchangeManager, auditLogger); MCCIIN000002UV01 actualResponse = standardPatientDiscovery.processPatientDiscoveryAsyncReq(request, assertion, targets); assertSame(expectedResponse, actualResponse); ArgumentCaptor<RespondingGatewayPRPAIN201305UV02RequestType> requestArgument = ArgumentCaptor .forClass(RespondingGatewayPRPAIN201305UV02RequestType.class); verify(pd201305Processor).storeLocalMapping(requestArgument.capture()); assertEquals(request, requestArgument.getValue().getPRPAIN201305UV02()); verify(correlationDao).saveOrUpdate("messageId", patientId); requestArgument.getAllValues().clear(); verify(policyChecker, times(2)).checkOutgoingPolicy(requestArgument.capture()); assertEquals(firstTargetRequest, requestArgument.getAllValues().get(0).getPRPAIN201305UV02()); assertEquals(secondTargetRequest, requestArgument.getAllValues().get(1).getPRPAIN201305UV02()); assertNotNull("Assertion MessageId is null", assertion.getMessageId()); verify(mockEJBLogger, never()).auditRequestMessage(eq(request), eq(assertion), any(NhinTargetSystemType.class), eq(NhincConstants.AUDIT_LOG_OUTBOUND_DIRECTION), eq(NhincConstants.AUDIT_LOG_NHIN_INTERFACE), eq(Boolean.TRUE), isNull(Properties.class), eq(NhincConstants.PATIENT_DISCOVERY_DEFERRED_REQ_SERVICE_NAME), any(PatientDiscoveryDeferredRequestAuditTransforms.class)); }