コード例 #1
0
ファイル: MdwsDao.php プロジェクト: rmurray1/RAPTOR
 public function makeQuery($functionToInvoke, $args)
 {
     if (!$this->isAuthenticated()) {
         drupal_set_message('TIP: <a href="/drupal/user/logout">Logout</a> and <a href="/drupal/user/login">log back in</a></a>');
         throw new \Exception('Not authenticated in MdwsDao instance ' . $this->instanceTimestamp . '(previous authentication was ' . $this->authenticationTimestamp . ')' . ": Must authenticate before requesting data>>>" . Context::debugGetCallerInfo(2, 10));
     }
     error_log('TODO:makeQuery  --- about to do stuff in makeQuery for ' . $functionToInvoke . '...');
     try {
         // use the DAO factory to obtain the correct SOAP client
         // use the previous SOAP request/response headers to set the ASP.NET_SessionID header if the facde has changed
         error_log('About to get getFacadeNameByFunction ' . microtime());
         $wsdlForFunction = MdwsDaoFactory::getFacadeNameByFunction($functionToInvoke);
         error_log('Done getting getFacadeNameByFunction ' . microtime());
         //if ($wsdlForFunction != $this->currentFacade) {   //Serialization issue with PHP SOAP will try to get new one eacvh time
         error_log('About got set properties of MDWS SOAP CLIENT ' . microtime());
         $this->currentFacade = $wsdlForFunction;
         $cookie = $this->mdwsClient->_cookies["ASP.NET_SessionId"][0];
         $this->mdwsClient = MdwsDaoFactory::getSoapClientByFunction($functionToInvoke);
         $this->mdwsClient->__setCookie("ASP.NET_SessionId", $cookie);
         //error_log(print_r($this->mdwsClient, true));
         error_log('Done setting properties of MDWS SOAP CLIENT ' . microtime());
         //}
         // functionToInvoke is the name of the SOAP call, args is the list of arguments
         // PHP seems to like this format (using the functionToInvoke string as the SOAP name) just fine!
         error_log('TODO:makeQuery  --- soap client looks like this>>>' . print_r($this->mdwsClient, TRUE));
         $soapResult = $this->mdwsClient->{$functionToInvoke}($args);
         // TO object is always stored in "soapCallResult". e.g. select result stored in 'selectResult'
         $resultVarName = strval($functionToInvoke) . "Result";
         // this block of code before the return $soapResult statement is error checking/auto-re-authentication
         if (isset($soapResult->{$resultVarName})) {
             $TOResult = $soapResult->{$resultVarName};
             error_log('TODO:makeQuery  --- soapResult in makeQuery okay?>>>' . isset($TOResult->fault));
             if (isset($TOResult->fault)) {
                 // TODO:makeQuery  - haven't tested this auto-reconnect code atl all. need to write tests
                 // we received a fault - might be a session timeout in which case we want to handle gracefully
                 error_log('TODO:makeQuery  --- deal with a fault?>>>' . $TOResult->fault->message);
                 if (strpos($TOResult->fault->message, MDWS_CXN_TIMEOUT_ERROR_MSG_1) === FALSE || strpos($TOResult->fault->message, MDWS_CXN_TIMEOUT_ERROR_MSG_2) === FALSE || strpos($TOResult->fault->message, MDWS_CXN_TIMEOUT_ERROR_MSG_3) === FALSE) {
                     // TODO:makeQuery  - determine where the creds will be stored - these vars are undefined
                     $this->initClient();
                     error_log('TODO:makeQuery  --- get the credentials now???>>>' . $TOResult->fault->message);
                     $this->connectAndLogin($this->userSiteId, $this->userAccessCode, $this->userVerifyCode);
                     return $this->makeQuery($functionToInvoke, $args);
                 } else {
                     error_log('TODO:makeQuery  --- about to throw exception in makeQuery>>>' . print_r($TOResult, TRUE));
                     throw new \Exception('MdwsDao->makeQuery unhandled exception: ' . $TOResult->fault->message);
                 }
                 //return NULL;    //20140707 - JAM: why is this returning null??
             } else {
                 error_log('TODO:makeQuery Good news --- no fault in makeQuery>>>' . $functionToInvoke);
             }
         }
         /*  Removed 20140815
             // check if call was "select" - cache selected patient ID, if so
             if ($functionToInvoke == 'select') {
                 error_log('Setting selected patient ID>>>[' . $soapResult->selectResult->localPid . ']');
                 $this->selectedPatient = $soapResult->selectResult->localPid;
                 error_log('Check result of setting selected patient ID>>>[' . $this->selectedPatient . ']');
             }
              */
         return $soapResult;
     } catch (\Exception $ex) {
         if (strpos($ex->getMessage(), "connection was forcibly closed")) {
             error_log('TODO:makeQuery  --- 2222 connection was closed makeQuery>>>' . $ex);
             $this->initClient();
             $this->connectAndLogin($this->userSiteId, $this->userAccessCode, $this->userVerifyCode);
             return $this->makeQuery($functionToInvoke, $args);
         } else {
             error_log('TODO:makeQuery  --- 2222 about to throw exception in makeQuery>>>' . print_r($TOResult, TRUE));
             throw $ex;
         }
     }
 }
コード例 #2
0
ファイル: data_context.php プロジェクト: rmurray1/RAPTOR
 public function getMdwsClient($bRefreshConnection = FALSE)
 {
     if (!isset($this->m_mdwsClient)) {
         $this->m_mdwsClient = MdwsDaoFactory::getMdwsDao(MDWS_EMR_FACADE);
     }
     return $this->m_mdwsClient;
     error_log('WORKFLOWDEBUG>>>Called getMdwsClient for ' . $this->m_sVistaUserID . ' from ' . $_SERVER['REMOTE_ADDR'] . ' in ' . $this->m_nInstanceTimestamp);
     if ($bRefreshConnection && isset($this->m_mdwsClient)) {
         error_log('WORKFLOWDEBUG>>>Refreshing the existing Mdws connection for ' . $this->m_sVistaUserID . ' from ' . $_SERVER['REMOTE_ADDR'] . ' in ' . $this->m_nInstanceTimestamp);
         $this->m_mdwsClient->disconnect();
         unset($this->m_mdwsClient);
     }
     if (isset($this->m_mdwsClient)) {
         error_log('WORKFLOWDEBUG>>>Using existing Mdws connection for ' . $this->m_sVistaUserID . ' from ' . $_SERVER['REMOTE_ADDR'] . ' in ' . $this->m_nInstanceTimestamp);
     } else {
         error_log('WORKFLOWDEBUG>>>Creating NEW Mdws connection for ' . $this->m_sVistaUserID . ' from ' . $_SERVER['REMOTE_ADDR'] . ' in ' . $this->m_nInstanceTimestamp . " CALLER==> " . Context::debugGetCallerInfo(4));
         try {
             $this->m_mdwsClient = MdwsDaoFactory::getMdwsDao(MDWS_EMR_FACADE);
             if (isset($this->m_sVistaUserID)) {
                 //Since we have credentials, go ahead and authenticate now
                 $this->m_mdwsClient->connectAndLogin(VISTA_SITE, $this->m_sVistaUserID, $this->m_sVAPassword);
                 $this->serializeNow();
                 //20140701
             } else {
                 //drupal_set_message('Did NOT hav a user id!', 'warning');
             }
         } catch (\Exception $ex) {
             $sMsg = "Error connecting to EMR service as [{$this->m_sVistaUserID}] -> " . $ex;
             if (FALSE !== strpos($ex, 'Timeout waiting for response from VistA')) {
                 global $user;
                 $tempUID = $user->uid;
                 try {
                     //TODO send an email too
                     $updated_dt = date("Y-m-d H:i:s", time());
                     db_insert('raptor_user_activity_tracking')->fields(array('uid' => $tempUID, 'action_cd' => UATC_ERR_VISTATIMEOUT, 'ipaddress' => $_SERVER['REMOTE_ADDR'], 'updated_dt' => $updated_dt))->execute();
                 } catch (\Exception $ex) {
                     error_log('Trouble updating raptor_user_activity_tracking>>>' . print_r($ex, TRUE));
                 }
             }
             error_context_log($sMsg);
             //die($sMsg);
         }
     }
     return $this->m_mdwsClient;
 }