/**
   * This calls the unsecured web service for this method.
   *
   * @param body The message to be sent to the web service.
   * @param assertion The assertion information to go with the message.
   * @return The response from the web service.
   * @throws PatientDiscoveryException
   */
  @AdapterDelegationEvent(
      beforeBuilder = PRPAIN201305UV02EventDescriptionBuilder.class,
      afterReturningBuilder = PRPAIN201306UV02EventDescriptionBuilder.class,
      serviceType = "Patient Discovery",
      version = "1.0")
  public PRPAIN201306UV02 respondingGatewayPRPAIN201305UV02(
      PRPAIN201305UV02 body, AssertionType assertion) throws PatientDiscoveryException {
    String url = null;
    PRPAIN201306UV02 response = new PRPAIN201306UV02();
    String sServiceName = NhincConstants.PATIENT_DISCOVERY_ADAPTER_SERVICE_NAME;

    try {
      if (body != null) {
        LOG.debug("Before target system URL look up.");
        url = oProxyHelper.getAdapterEndPointFromConnectionManager(sServiceName);
        LOG.debug(
            "After target system URL look up. URL for service: " + sServiceName + " is: " + url);

        if (NullChecker.isNotNullish(url)) {
          RespondingGatewayPRPAIN201305UV02RequestType request =
              new RespondingGatewayPRPAIN201305UV02RequestType();
          request.setAssertion(assertion);
          request.setPRPAIN201305UV02(body);
          request.setNhinTargetCommunities(null);

          ServicePortDescriptor<AdapterPatientDiscoveryPortType> portDescriptor =
              new AdapterPatientDiscoveryServicePortDescriptor();
          CONNECTClient<AdapterPatientDiscoveryPortType> client =
              CONNECTClientFactory.getInstance()
                  .getCONNECTClientUnsecured(portDescriptor, url, assertion);

          response =
              (PRPAIN201306UV02)
                  client.invokePort(
                      AdapterPatientDiscoveryPortType.class,
                      "respondingGatewayPRPAIN201305UV02",
                      request);
        } else {
          throw new PatientDiscoveryException(
              "Failed to call the adapter web service (" + sServiceName + ").  The URL is null.");
        }
      } else {
        throw new PatientDiscoveryException(
            "Failed to call the web service (" + sServiceName + ").  The input parameter is null.");
      }
    } catch (Exception e) {
      LOG.error(
          "Failed to call the web service ("
              + sServiceName
              + ").  An unexpected exception occurred.  "
              + "Exception: "
              + e.getMessage(),
          e);
      throw new PatientDiscoveryException(e.fillInStackTrace());
    }

    return response;
  }
  public MCCIIN000002UV01 processPatientDiscoveryAsyncResp(
      PRPAIN201306UV02 request, AssertionType assertion, NhinTargetCommunitiesType target) {
    LOG.debug(
        "Begin EntityPatientDiscoveryDeferredResponseProxyWebServiceSecuredImpl.processPatientDiscoveryAsyncResp(...)");
    MCCIIN000002UV01 response = new MCCIIN000002UV01();

    String serviceName = NhincConstants.PATIENT_DISCOVERY_ENTITY_SECURED_ASYNC_RESP_SERVICE_NAME;

    try {
      LOG.debug("Before target system URL look up.");
      String url = oProxyHelper.getUrlLocalHomeCommunity(serviceName);
      if (LOG.isDebugEnabled()) {
        LOG.debug(
            "After target system URL look up. URL for service: " + serviceName + " is: " + url);
      }

      if (NullChecker.isNotNullish(url)) {
        RespondingGatewayPRPAIN201306UV02SecuredRequestType securedRequest =
            new RespondingGatewayPRPAIN201306UV02SecuredRequestType();
        if (request != null) {
          securedRequest.setNhinTargetCommunities(target);
          securedRequest.setPRPAIN201306UV02(request);
        }
        ServicePortDescriptor<EntityPatientDiscoverySecuredAsyncRespPortType> portDescriptor =
            new EntityPatientDiscoverySecuredAsyncRespServicePortDescriptor();
        CONNECTClient<EntityPatientDiscoverySecuredAsyncRespPortType> client =
            CONNECTClientFactory.getInstance()
                .getCONNECTClientSecured(portDescriptor, url, assertion);
        response =
            (MCCIIN000002UV01)
                client.invokePort(
                    EntityPatientDiscoverySecuredAsyncRespPortType.class,
                    "processPatientDiscoveryAsyncResp",
                    securedRequest);
      } else {
        LOG.error("Failed to call the web service (" + serviceName + ").  The URL is null.");
      }
    } catch (Exception ex) {
      LOG.error(
          "Error: Failed to retrieve url for service: "
              + serviceName
              + " for local home community");
      LOG.error(ex.getMessage(), ex);
    }

    LOG.debug(
        "End EntityPatientDiscoveryDeferredResponseProxyWebServiceSecuredImpl.processPatientDiscoveryAsyncResp(...)");
    return response;
  }
  /**
   * This method retrieves PatientCorrelation from the targeted community.
   *
   * @param msg PRPAIN201309UV02 HL7 type of Request received.
   * @param assertion Assertion received.
   * @return PatientCorrelationresponse.
   */
  public RetrievePatientCorrelationsResponseType retrievePatientCorrelations(
      PRPAIN201309UV02 msg, AssertionType assertion) {
    LOG.debug("Begin retrievePatientCorrelations");
    RetrievePatientCorrelationsResponseType response =
        new RetrievePatientCorrelationsResponseType();
    RetrievePatientCorrelationsSecuredResponseType securedResp =
        new RetrievePatientCorrelationsSecuredResponseType();

    try {
      String url =
          oProxyHelper.getUrlLocalHomeCommunity(
              NhincConstants.PATIENT_CORRELATION_SECURED_SERVICE_NAME);

      if (msg == null) {
        LOG.error("Message was null");
      } else {
        RetrievePatientCorrelationsSecuredRequestType request =
            new RetrievePatientCorrelationsSecuredRequestType();
        request.setPRPAIN201309UV02(msg);

        ServicePortDescriptor<PatientCorrelationSecuredPortType> portDescriptor =
            getRetrieveServicePortDescriptor(NhincConstants.ADAPTER_API_LEVEL.LEVEL_a0);

        CONNECTClient<PatientCorrelationSecuredPortType> client =
            CONNECTClientFactory.getInstance()
                .getCONNECTClientSecured(portDescriptor, url, assertion);

        securedResp =
            (RetrievePatientCorrelationsSecuredResponseType)
                client.invokePort(
                    PatientCorrelationSecuredPortType.class,
                    "retrievePatientCorrelations",
                    request);
        if (securedResp != null && securedResp.getPRPAIN201310UV02() != null) {
          response.setPRPAIN201310UV02(securedResp.getPRPAIN201310UV02());
        }
      }
    } catch (Exception ex) {
      LOG.error("Error calling retrievePatientCorrelations: " + ex.getMessage(), ex);
    }

    LOG.debug("End retrievePatientCorrelations");
    return response;
  }