Esempio n. 1
0
 function checkAV($AccessCode, $VerifyCode)
 {
     $nodevista = new NodeVista();
     $AuthenticateURL = "authenticate";
     $AuthData = array();
     $AuthData["accesscode"] = $AccessCode;
     $AuthData["verifycode"] = $VerifyCode;
     $AuthenticateReturn = $nodevista->post($AuthenticateURL, json_encode($AuthData));
     $aRet = json_decode($AuthenticateReturn);
     $LoginError = "";
     if (array_key_exists("error", $aRet)) {
         $retErr = $aRet->{"error"};
         $LoginError = "Unk";
         if ("Not a valid ACCESS CODE/VERIFY CODE pair." === $retErr) {
             $LoginError = "Authentication failed! Please click \"OK\" and enter your proper Access and Verify Codes";
             $LoginError = "Authentication failed! Please enter your proper Access and Verify Codes below and click \"Login\"";
         } else {
             $LoginError = "Authentication failed! Unknown Error - {$retErr}!<br>Please contact your COMS support personnel";
         }
         error_log("NWLogin - Authentication Check - {$LoginError}");
         return "Failed";
     }
     $UserInfo = $nodevista->get("user/info");
     error_log("NWLogin - User Info Check - {$UserInfo}");
     $jdUserInfo = json_decode($UserInfo);
     $DisplayName = $jdUserInfo->{"name"};
     return $DisplayName;
 }
Esempio n. 2
0
function NWLogin($AccessCode, $VerifyCode)
{
    include "dbitcon.php";
    include "../framework/library/nodevista.class.php";
    $nodevista = new NodeVista();
    if ($AccessCode === 'COMSAdmin' and $VerifyCode === 'COMS2015!') {
        error_log("Using special Admin Access");
        $_SESSION['role'] = 'All Roles';
        $_SESSION['dname'] = 'Admin';
        $_SESSION['rid'] = '999';
        $_SESSION['Email'] = '*****@*****.**';
        $_SESSION['TemplateAuthoring'] = '1';
        $_SESSION['Role_ID'] = 'A418029A-2C80-40D6-B3E6-77AA7C34434C';
        $_SESSION['AC'] = $AccessCode;
        $_SESSION['VC'] = $VerifyCode;
        $_SESSION['NWLogin'] = 355;
        $globalsq = "SELECT * FROM Globals";
        $getglobals = sqlsrv_query($conn, $globalsq);
        while ($row = sqlsrv_fetch_array($getglobals, SQLSRV_FETCH_ASSOC)) {
            $_SESSION['sitelist'] = $row['sitelist'];
            $_SESSION['domain'] = $row['domain'];
            $_SESSION['vista'] = $row['vista'];
        }
        $usql = "Update Roles set Last_SessionID = '" . $_SESSION['sessionid'] . "' where username = '******'";
        $updateRole = sqlsrv_query($conn, $usql);
        $point = "signed in";
        //PostTrack( $_SESSION[ 'ruser' ], $_SESSION[ 'AC' ], $point, 99, $_SESSION[ 'sessionid' ] );
        $NWLoginR = 1;
        $_SESSION['COMSLogin'] = 1;
        error_log("NWLogin Exit - Session Vars = " . json_encode($_SESSION));
        return $NWLoginR;
    }
    $AuthenticateURL = "authenticate";
    $AuthData = array();
    $AuthData["accesscode"] = $AccessCode;
    $AuthData["verifycode"] = $VerifyCode;
    $AuthenticateReturn = $nodevista->post($AuthenticateURL, json_encode($AuthData));
    $aRet = json_decode($AuthenticateReturn);
    $LoginError = "";
    if (array_key_exists("error", $aRet)) {
        $retErr = $aRet->{"error"};
        $LoginError = "Unk";
        if ("Not a valid ACCESS CODE/VERIFY CODE pair." === $retErr) {
            $LoginError = "Authentication failed! Please click \"OK\" and enter your proper Access and Verify Codes";
            $LoginError = "Authentication failed! Please enter your proper Access and Verify Codes below and click \"Login\"";
        } else {
            $LoginError = "Authentication failed! Unknown Error - {$retErr}!<br>Please contact your COMS support personnel";
        }
        error_log("NWLogin - Authentication Check - {$LoginError}");
        return $LoginError;
    }
    /**
     * User has logged in to VistA, now let's see if their DUZ is in the Roles Table
     **/
    $UserInfo = $nodevista->get("user/info");
    error_log("NWLogin - User Info Check - {$UserInfo}");
    $jdUserInfo = json_decode($UserInfo);
    $DUZ = $jdUserInfo->{"duz"};
    $point = "NWlogin";
    //PostTrack( $_SESSION[ 'ruser' ], $AccessCode, $point, 1, $_SESSION[ 'sessionid' ] );
    $ruser = $_SERVER['REMOTE_USER'];
    $_SESSION['sessionStatus'] = 0;
    $tsql = "SELECT * FROM Roles WHERE username = '******'";
    $getrole = sqlsrv_query($conn, $tsql);
    $flg = false;
    while ($row = sqlsrv_fetch_array($getrole, SQLSRV_FETCH_ASSOC)) {
        $flg = true;
        error_log("Got Role Info " . json_encode($row));
        $_SESSION['role'] = $row['role'];
        $_SESSION['dname'] = $row['DisplayName'];
        $_SESSION['rid'] = $row['rid'];
        $_SESSION['Email'] = $row['Email'];
        $_SESSION['TemplateAuthoring'] = $row['TemplateAuthoring'] === 1 ? 1 : 0;
        // Take into account default of NULL to ensure proper status
        $_SESSION['Role_ID'] = $row['Role_ID'];
        $_SESSION['Preceptee'] = $row['Preceptee'] === 0 ? 0 : 1;
        $_SESSION['Preceptor'] = $row['Preceptor'] === 1 ? 1 : 0;
        $_SESSION['AC'] = $AccessCode;
        $_SESSION['VC'] = $VerifyCode;
        $_SESSION['NWLogin'] = 355;
        $_SESSION['LoginTime'] = microtime(true);
    }
    if ($flg) {
        error_log("Got User - '{$AccessCode}', '{$VerifyCode}' - '{$DUZ}'");
        $globalsq = "SELECT * FROM Globals";
        $getglobals = sqlsrv_query($conn, $globalsq);
        while ($row = sqlsrv_fetch_array($getglobals, SQLSRV_FETCH_ASSOC)) {
            $_SESSION['sitelist'] = $row['sitelist'];
            $_SESSION['domain'] = $row['domain'];
            $_SESSION['vista'] = $row['vista'];
            $_SESSION['port'] = $row['port'];
        }
        $usql = "Update Roles set Last_SessionID = '" . $_SESSION['sessionid'] . "' where username = '******'";
        $updateRole = sqlsrv_query($conn, $usql);
        $point = "signed in";
        //PostTrack( $_SESSION[ 'ruser' ], $_SESSION[ 'AC' ], $point, 99, $_SESSION[ 'sessionid' ] );
        $NWLoginR = 1;
        $_SESSION['COMSLogin'] = 1;
        error_log("NWLogin Exit - Session Vars = " . json_encode($_SESSION));
        return $NWLoginR;
    }
    error_log("No User - '{$AccessCode}', '{$VerifyCode}' - '{$DUZ}'");
    return "Access/Verify Codes valid; however, COMS access is not authorized.<div style=\"color:red;\">Please contact COMS Administrator for access privileges.</div>";
}
Esempio n. 3
0
 function saveVitals($form_data, $patientId)
 {
     // error_log("Patient.Model.saveVitals - " . json_encode($form_data));
     if (empty($patientId)) {
         if (isset($form_data->{'patientId'})) {
             $patientId = $form_data->{'patientId'};
         } else {
             if (isset($form_data->{'PatientID'})) {
                 // MWB - 6/21/2012
                 // The JS Model
                 // calls for the
                 // field name to be
                 // 'PatientID' not
                 // 'patientId',
                 $patientId = $form_data->{'PatientID'};
                 // but not sure how
                 // the 'patientId'
                 // field gets set so
                 // making sure to
                 // check both...
             } else {
                 $retVal = array();
                 $retVal['apperror'] = "Field name ---patientId--- not provided.";
                 return $retVal;
             }
         }
     }
     if (empty($dateTaken)) {
         $dateTaken = $this->getCurrentDate();
     }
     $objDateTime = new DateTime('NOW');
     $observed = $objDateTime->format(DateTime::ISO8601);
     $nodevista = new NodeVista();
     $VistATime = $nodevista->get("current/date");
     $vts = json_decode($VistATime);
     $vtsDateStr = $vts->{'date'};
     // error_log("VistA Time = $VistATime" . $vts->{'date'} . " DateTaken from SQL - " . $dateTaken);
     $theCenturyMultiplier = substr($vtsDateStr, 0, 1);
     $theCentury = 1700 + 100 * $theCenturyMultiplier;
     $theYear = substr($vtsDateStr, 1, 2);
     $y = intval($theCentury, 10) + intval($theYear, 10);
     $theMonth = substr($vtsDateStr, 3, 2);
     $theDay = substr($vtsDateStr, 5, 2);
     $theHr = intval(substr($vtsDateStr, 8, 2), 10);
     $AmPm = "";
     if ($theHr > 12) {
         $theHr = $theHr - 12;
         $AmPm = "PM";
     }
     if ($theHr < 10) {
         $theHr = "0{$theHr}";
     }
     $theMin = substr($vtsDateStr, 10, 2);
     $theDateTimeStr = "{$theMonth}/{$theDay}/{$y} {$theHr}:{$theMin} {$AmPm}";
     // error_log("VistA Time = $VistATime, " . $vts->{'date'} . " - $theDateTimeStr");
     $theDateTime = new DateTime($theDateTimeStr);
     $observed = $theDateTime->format(DateTime::ISO8601);
     $dateTaken = date_format($theDateTime, 'Y-m-d H:i:s');
     // error_log("VistA Time =  $VistATime, " . $vts->{'date'} . " - $theDateTimeStr - Observed = $observed"); //  DateTaken from SQL - $dateTaken");
     if (isset($form_data->{'OEMRecordID'})) {
         $oemRecordId = $form_data->{'OEMRecordID'};
     } else {
         $oemRecordId = null;
     }
     $errMsgList = array();
     $nodevista = new NodeVista();
     $systolic = $form_data->{'Systolic'};
     $diastolic = $form_data->{'Diastolic'};
     if (empty($form_data->{'BP'})) {
         $bp = $systolic . "/" . $diastolic;
     } else {
         $bp = $form_data->{'BP'};
     }
     $bp1 = preg_replace('/\\s+/', '', $bp);
     if ($bp && $bp1 !== "" && $bp1 !== "/") {
         $VitalObj = array('type' => "BP", 'value' => $bp1, 'provider' => $_SESSION['UserDUZ']);
         $PatientData = array('patient' => $form_data->{'DFN'}, 'location' => $_SESSION['sitelist'], 'observed_date_time' => $observed, 'vital' => $VitalObj);
         $PatientData = json_encode($PatientData);
         // error_log("Posting Vital to VistA - patient/vital/add - $PatientData");
         $postRet = $nodevista->post("patient/vital/add", $PatientData);
         $eRet1 = json_decode($postRet, true);
         if (array_key_exists("error", $eRet1)) {
             $errMsgList[] = "Error saving BP to VistA - " . $eRet1["error"];
             $bp = "";
         }
     }
     $height = $form_data->{'Height'};
     if ($height && $height !== "") {
         $VitalObj = array('type' => "HT", 'value' => $height, 'provider' => $_SESSION['UserDUZ']);
         $PatientData = array('patient' => $form_data->{'DFN'}, 'location' => $_SESSION['sitelist'], 'observed_date_time' => $observed, 'vital' => $VitalObj);
         $PatientData = json_encode($PatientData);
         $postRet = $nodevista->post("patient/vital/add", $PatientData);
         $eRet1 = json_decode($postRet, true);
         if (array_key_exists("error", $eRet1)) {
             $errMsgList[] = "Error saving Height to VistA - " . $eRet1["error"];
             $height = "";
         }
     }
     $weight = $form_data->{'Weight'};
     if ($weight && $weight !== "") {
         $VitalObj = array('type' => "WT", 'value' => $weight, 'provider' => $_SESSION['UserDUZ']);
         $PatientData = array('patient' => $form_data->{'DFN'}, 'location' => $_SESSION['sitelist'], 'observed_date_time' => $observed, 'vital' => $VitalObj);
         $PatientData = json_encode($PatientData);
         $postRet = $nodevista->post("patient/vital/add", $PatientData);
         $eRet1 = json_decode($postRet, true);
         if (array_key_exists("error", $eRet1)) {
             $errMsgList[] = "Error saving Weight to VistA - " . $eRet1["error"];
             $weight = "";
         }
     }
     $temp = $form_data->{'Temperature'};
     $tempLoc = $form_data->{'TemperatureLocation'};
     if ($temp && $temp !== "") {
         $VitalObj = array('type' => "T", 'value' => $temp, 'provider' => $_SESSION['UserDUZ']);
         $PatientData = array('patient' => $form_data->{'DFN'}, 'location' => $_SESSION['sitelist'], 'observed_date_time' => $observed, 'vital' => $VitalObj);
         $PatientData = json_encode($PatientData);
         $postRet = $nodevista->post("patient/vital/add", $PatientData);
         $eRet1 = json_decode($postRet, true);
         if (array_key_exists("error", $eRet1)) {
             $errMsgList[] = "Error saving Temperature to VistA - " . $eRet1["error"];
             $temp = "";
         }
     }
     $pulse = $form_data->{'Pulse'};
     if ($pulse && $pulse !== "") {
         $VitalObj = array('type' => "P", 'value' => $pulse, 'provider' => $_SESSION['UserDUZ']);
         $PatientData = array('patient' => $form_data->{'DFN'}, 'location' => $_SESSION['sitelist'], 'observed_date_time' => $observed, 'vital' => $VitalObj);
         $PatientData = json_encode($PatientData);
         $postRet = $nodevista->post("patient/vital/add", $PatientData);
         $eRet1 = json_decode($postRet, true);
         if (array_key_exists("error", $eRet1)) {
             $errMsgList[] = "Error saving Pulse to VistA - " . $eRet1["error"];
             $pulse = "";
         }
     }
     $resp = $form_data->{'Respiration'};
     if ($resp && $resp !== "") {
         $VitalObj = array('type' => "R", 'value' => $resp, 'provider' => $_SESSION['UserDUZ']);
         $PatientData = array('patient' => $form_data->{'DFN'}, 'location' => $_SESSION['sitelist'], 'observed_date_time' => $observed, 'vital' => $VitalObj);
         $PatientData = json_encode($PatientData);
         $postRet = $nodevista->post("patient/vital/add", $PatientData);
         $eRet1 = json_decode($postRet, true);
         if (array_key_exists("error", $eRet1)) {
             $errMsgList[] = "Error saving Respiration to VistA - " . $eRet1["error"];
             $resp = "";
         }
     }
     $pain = $form_data->{'Pain'};
     if ($pain && $pain !== "") {
         $VitalObj = array('type' => "PN", 'value' => $pain, 'provider' => $_SESSION['UserDUZ']);
         $PatientData = array('patient' => $form_data->{'DFN'}, 'location' => $_SESSION['sitelist'], 'observed_date_time' => $observed, 'vital' => $VitalObj);
         $PatientData = json_encode($PatientData);
         $postRet = $nodevista->post("patient/vital/add", $PatientData);
         $eRet1 = json_decode($postRet, true);
         if (array_key_exists("error", $eRet1)) {
             $errMsgList[] = "Error saving Pain to VistA - " . $eRet1["error"];
             $pain = "";
         }
     }
     $spo2 = $form_data->{'SPO2'};
     if ($spo2 && $spo2 !== "") {
         $spo2 = strval($spo2);
         /**********
                     $VitalObj = array('type' => "PO2", 'value' => $spo2, 'provider' => $_SESSION['UserDUZ']);
                     $PatientData = array('patient' => $form_data->{'DFN'}, 'location' => $_SESSION[ 'sitelist' ], 'observed_date_time' => $observed, 'vital' => $VitalObj);
                     $PatientData = json_encode($PatientData);
         // error_log("Saving Pulse Oximetry - Data = $PatientData");
                     $postRet = $nodevista->post("patient/vital/add" , $PatientData);
                     $eRet1 = json_decode( $postRet, true );
                     if (array_key_exists("error", $eRet1)) {
                         $errMsgList[] = "Error saving SPO2 to VistA - " . $eRet1["error"];
                         $spo2 = "";
                     }
         ************/
     }
     if (count($errMsgList) > 0) {
         $errors = implode("\n\r", $errMsgList);
         $AppErr = array();
         $AppErr['apperror'] = $errors;
         return $AppErr;
     }
     // error_log("No VistA Errors...");
     $bsa = $form_data->{'BSA'};
     $bsaMethod = $form_data->{'BSA_Method'};
     $weightFormula = $form_data->{'WeightFormula'};
     $bsaWeight = $form_data->{'BSA_Weight'};
     $templateId = $this->getTemplateIdByPatientID($patientId);
     if (null != $templateId && array_key_exists('error', $templateId)) {
         return $templateId;
     } else {
         if (!empty($templateId)) {
             $templateId = $templateId[0]['id'];
         } else {
             $templateId = null;
         }
     }
     $PS_ID = null;
     if (isset($form_data->{'PS_ID'})) {
         $PS_ID = $form_data->{'PS_ID'};
     }
     /*
      * Not sure if Performance ID is important when saving Vitals. Seems to
      * make sense to save Performance Status if it was set before the Vitals
      * were taken. In other words the template was applied and the
      * Performance Status was set before the vitals were taken. Also use BSA
      * values for WeightFormula and BSA Method if the Start Date of the
      * Template is after the Date Taken
      */
     $query = "SELECT Perf_Status_ID as id,BSA_Method as bsaMethod,Weight_Formula as weightFormula \n                 FROM Patient_Assigned_Templates where Is_Active = 1 and Patient_ID = '{$patientId}' AND Date_Started <= '{$dateTaken}'";
     $record = $this->query($query);
     if (null != $record && array_key_exists('error', $record)) {
         // error_log("getting Performance Status Error - $query");
         return $record;
     } else {
         if (count($record) > 0) {
             if (null === $PS_ID) {
                 // $performanceId = $record[0]['id'];
                 $performanceId = null;
             } else {
                 $performanceId = $PS_ID;
             }
             if ("" == $bsaMethod) {
                 $bsaMethod = $record[0]['bsaMethod'];
             }
             if ("" == $weightFormula) {
                 $weightFormula = $record[0]['weightFormula'];
             }
         }
     }
     // error_log("Performance Status Saved");
     if (null == $oemRecordId) {
         $ob1 = explode("T", $observed);
         $time = explode("-", $ob1[1]);
         $ob2 = $ob1[0] . " " . $time[0];
         // error_log("SQL Time ($ob2) from VistA time ($observed)");
         $observed = $ob2;
         if (!empty($templateId)) {
             $query = "INSERT INTO Patient_History(Patient_ID,Height,Weight,Blood_Pressure,Systolic,Diastolic,BSA,Temperature,TemperatureLocation,Date_Taken, " . "Template_ID, Pulse, Respiration, Pain, OxygenationLevel,BSA_Method,Weight_Formula,BSA_Weight,Performance_ID) values(" . "'" . $patientId . "','" . $height . "','" . $weight . "','" . $bp . "','" . $systolic . "','" . $diastolic . "','" . $bsa . "','{$temp}','{$tempLoc}','" . $observed . "'," . "'" . $templateId . "','" . $pulse . "','" . $resp . "','" . $pain . "','" . $spo2 . "'," . "'" . $bsaMethod . "','" . $weightFormula . "','" . $bsaWeight . "',";
         } else {
             $query = "INSERT INTO Patient_History(Patient_ID,Height,Weight,Blood_Pressure,Systolic,Diastolic,BSA,Temperature,TemperatureLocation,Date_Taken, " . "Pulse, Respiration, Pain, OxygenationLevel,BSA_Method,Weight_Formula,BSA_Weight,Performance_ID) values(" . "'" . $patientId . "','" . $height . "','" . $weight . "','" . $bp . "','" . $systolic . "','" . $diastolic . "','" . $bsa . "','{$temp}','{$tempLoc}','" . $observed . "'," . "'" . $pulse . "','" . $resp . "','" . $pain . "','" . $spo2 . "'," . "'" . $bsaMethod . "','" . $weightFormula . "','" . $bsaWeight . "',";
         }
     } else {
         if (!empty($templateId)) {
             $query = "INSERT INTO Patient_History(Patient_ID,Height,Weight,Blood_Pressure,Systolic,Diastolic,BSA,Temperature,TemperatureLocation,Date_Taken, " . "Template_ID, OEM_ID, Pulse, Respiration, Pain, OxygenationLevel,BSA_Method,Weight_Formula,BSA_Weight,Performance_ID) values(" . "'" . $patientId . "','" . $height . "','" . $weight . "','" . $bp . "','" . $systolic . "','" . $diastolic . "','" . $bsa . "','{$temp}','{$tempLoc}','" . $observed . "'," . "'" . $templateId . "','" . $oemRecordId . "','" . $pulse . "','" . $resp . "','" . $pain . "','" . $spo2 . "'," . "'" . $bsaMethod . "','" . $weightFormula . "','" . $bsaWeight . "',";
         } else {
             $query = "INSERT INTO Patient_History(Patient_ID,Height,Weight,Blood_Pressure,Systolic,Diastolic,BSA,Temperature,Date_Taken, " . "Pulse, Respiration, Pain, OxygenationLevel,BSA_Method,Weight_Formula,BSA_Weight,Performance_ID) values(" . "'" . $patientId . "','" . $height . "','" . $weight . "','" . $bp . "','" . $systolic . "','" . $diastolic . "','" . $bsa . "','{$temp}','{$tempLoc}','" . $observed . "'," . "'" . $pulse . "','" . $resp . "','" . $pain . "','" . $spo2 . "'," . "'" . $bsaMethod . "','" . $weightFormula . "','" . $bsaWeight . "',";
         }
     }
     empty($performanceId) ? $query .= "null)" : ($query .= "'{$performanceId}')");
     // error_log("Patient.Model.saveVitals - $query");
     $result = $this->query($query);
     if ($result) {
         return $result;
     }
     if (!empty($performanceId)) {
         $query = "\n                UPDATE Patient_Assigned_Templates SET\n                    Perf_Status_ID = '{$performanceId}'\n                WHERE Patient_ID = '{$patientId}'\n                    AND Is_Active = 1\n            ";
         return $this->query($query);
     }
 }