Ejemplo n.º 1
0
 function CumulativeDoseTracking($PatientID = null, $cdhRecordID = null)
 {
     $jsonRecord = array();
     $jsonRecord['success'] = true;
     $query = "";
     $DataTable = "Patient_CumulativeDoseHistory";
     $GUID = "";
     $this->Patient->beginTransaction();
     $Date2 = date("F j, Y");
     $ErrMsg = "";
     if ("GET" == $_SERVER['REQUEST_METHOD']) {
         $controller = 'LookupController';
         $lookupController = new $controller('Lookup', 'lookup', null);
         $query = $lookupController->_getAllCumulativeDoseMeds(null);
         $CumDoseMeds = $this->Patient->query($query);
         // error_log("PatientController.CumulativeDoseTracking - Cumulative Meds List");
         // error_log(json_encode($CumDoseMeds));
         // error_log("CumulativeDoseTracking - GET");
         if ($PatientID) {
             $partialQuery = "SELECT \n                   dt.CumulativeDoseAmt, \n                   dt.CumulativeDoseUnits, \n                   dt.Source,\n                   dt.MedID,\n                   dt.Author,\n                   lu1.Name as MedName,\n                   lu2.Name as Units,\n                   CONVERT(varchar,dt.Date_Changed,101) as Date_Changed\n                   from Patient_CumulativeDoseHistory dt\n                   join LookUp lu1 on lu1.Lookup_ID = dt.MedID\n                   join LookUp lu2 on lu2.Lookup_ID = dt.CumulativeDoseUnits\n                   where Patient_ID = '{$PatientID}'";
             if ($cdhRecordID) {
                 $query = $partialQuery . " and dt.ID = '{$cdhRecordID}' order by Name asc";
             } else {
                 $query = $partialQuery;
             }
         }
         // error_log("CumulativeDoseTracking Query - $query");
         $jsonRecord['msg'] = "No records to find";
         $ErrMsg = "Retrieving Records";
         $PatientsCumMeds = $this->Patient->query($query);
         if ($this->checkForErrors($ErrMsg, $PatientsCumMeds)) {
             $jsonRecord['success'] = false;
             $jsonRecord['msg'] = $this->get('frameworkErr');
             $this->Patient->rollbackTransaction();
             $this->set('jsonRecord', $jsonRecord);
             return;
         }
         $jsonRecord['success'] = 'true';
         $CumMedsList = array();
         if (count($PatientsCumMeds) > 0) {
             // error_log("Patient.Controller.CumulativeDoseTracking.Walking Patients Meds - ");
             $Lifetime = 0;
             $LastKey = "";
             foreach ($PatientsCumMeds as $aMed) {
                 // error_log("Patient. Med - ");
                 // error_log(json_encode($aMed));
                 $rec = $aMed;
                 $this->_AddRecordMed2CumList($CumDoseMeds, $rec);
                 // error_log("Array Key does NOT exist - ");
                 // error_log(json_encode($CumMedsList));
                 if (!array_key_exists($aMed['MedID'], $CumMedsList)) {
                     if ("" != $LastKey) {
                         $CumMedsList[$LastKey]['LifetimeAmt'] += $Lifetime;
                     }
                     $LastKey = $aMed['MedID'];
                     $Lifetime = 0;
                     $CumMedsList[$aMed['MedID']] = array();
                     $CumMedsList[$aMed['MedID']]['MedName'] = $rec['MedName'];
                     $CumMedsList[$aMed['MedID']]['MedMaxDose'] = $rec['MaxCumulativeDoseAmt'];
                     $CumMedsList[$aMed['MedID']]['MaxCumulativeDoseAmt'] = $rec['MaxCumulativeDoseAmt'];
                     $CumMedsList[$aMed['MedID']]['MaxCumulativeDoseUnits'] = $rec['MaxCumulativeDoseUnits'];
                     $CumMedsList[$aMed['MedID']]['LifetimeAmt'] = 0;
                 }
                 $newRec = array();
                 $Lifetime += $rec['CumulativeDoseAmt'];
                 $newRec['Amt'] = $rec['CumulativeDoseAmt'];
                 $newRec['Src'] = $rec['Source'];
                 $newRec['Author'] = $rec['Author'];
                 $CumMedsList[$aMed['MedID']]['Patient'][] = $newRec;
                 // $CumMedsList[$aMed['MedID']]['Patient']['Src'] =
                 // $CumMedsList[$aMed['MedID']]['Patient']['Author'] = $rec['Author'];
                 // error_log("A specific Med - ");
                 // error_log(json_encode($rec));
                 //                        $CumMedsList[] = $rec;
             }
             if ("" != $LastKey) {
                 $CumMedsList[$LastKey]['LifetimeAmt'] += $Lifetime;
                 // error_log("Patient. LastKey = $LastKey; Lifetime Total = $Lifetime");
             }
             unset($jsonRecord['msg']);
             $recs = array();
             foreach ($CumMedsList as $key => $aMed) {
                 $aMed['ID'] = $key;
                 $recs[] = $aMed;
             }
             $jsonRecord['total'] = count($CumMedsList);
             $jsonRecord['records'] = $recs;
         } else {
             // error_log("Patient.Controller.CumulativeDoseTracking.NO Patients Meds - ");
         }
         // error_log("CumMedsList");
         // error_log(json_encode($CumMedsList));
         $this->set('jsonRecord', $jsonRecord);
         return;
     } else {
         if ("POST" == $_SERVER['REQUEST_METHOD']) {
             // error_log("Patient Controller - CumulativeDoseTracking - POST - 2415");
             $MedID = "";
             $MedName = "";
             $Source = "";
             $CumulativeDoseUnits = "";
             $CumulativeDoseUnitsID = "";
             parse_str(file_get_contents("php://input"), $post_vars);
             $lookup = new LookUp();
             // error_log("Input - " . json_encode($post_vars));
             if (isset($post_vars["MedName"])) {
                 $MedName = $post_vars["MedName"];
                 $MedName = $this->NTD_StripLeadingFromDrugName($MedName);
                 $retVal = $lookup->getLookupIdByNameAndType($MedName, 2);
                 // error_log(json_encode($retVal));
                 $MedID = $retVal[0]["id"];
             }
             // error_log("Grabbing MedName 1 - MedID = $MedID, MedName = $MedName");
             /*** MedID is wrong, doesn't match Lookup Table value. **/
             if (isset($post_vars["value"])) {
                 $MedID = $post_vars["value"];
             }
             // error_log("Grabbing MedName 2 - MedID = $MedID, MedName = $MedName");
             if (isset($post_vars["LifetimeDose"])) {
                 $CumulativeDoseAmt = $post_vars["LifetimeDose"];
             }
             if (isset($post_vars["UnitName"])) {
                 $CumulativeDoseUnits = $post_vars["UnitName"];
             }
             if (isset($post_vars["Units"])) {
                 $CumulativeDoseUnitsID = $post_vars["Units"];
             }
             if ("" !== $CumulativeDoseUnits && "" === $CumulativeDoseUnitsID) {
                 $retVal = $lookup->getLookupIdByNameAndType($CumulativeDoseUnits, 11);
                 // error_log("Lookup for CumulativeDoseUnits - $CumulativeDoseUnits; returns: " . json_encode($retVal));
                 $CumulativeDoseUnitsID = $retVal[0]["id"];
                 // error_log("Units = $CumulativeDoseUnits; ID = $CumulativeDoseUnitsID");
             } else {
                 // error_log("Have CumulativeDoseUnitsID = $CumulativeDoseUnitsID");
             }
             if (isset($post_vars["Source"])) {
                 $Source = $post_vars["Source"];
             }
             // error_log("CumulativeDoseTracking - POST");
             /*********************************************************************************
                Sample POST
                URL: http://coms-mwb.dbitpro.com:355/Patient/CumulativeDoseTracking/C4A968D0-06F3-E311-AC08-000C2935B86F
                MEthod: POST
                Headers: Content-Type:application/x-www-form-urlencoded; charset=UTF-8
                Data: value=7A95474E-A99F-E111-903E-000C2935B86F&LifetimeDose=500&Units=32FC87C5-9C38-E111-9B9C-000C2935B86F&Source=Something
                
                Data Collection Method: parse_str(file_get_contents("php://input"),$post_vars);
                Field Access Method: $MedID = $post_vars["value"];
                *********************************************************************************/
             $GUID = $this->Patient->newGUID();
             $query = "INSERT INTO {$DataTable} (ID, Patient_ID, MedID, CumulativeDoseAmt, CumulativeDoseUnits, Source)\n            VALUES (\n                '{$GUID}',\n                '{$PatientID}',\n                '{$MedID}',\n                '{$CumulativeDoseAmt}',\n                '{$CumulativeDoseUnitsID}',\n                '{$Source}'\n            )";
             // error_log("Patient.Controller.CumulativeDoseTracking - POST - $CumulativeDoseUnitsID - QUERY - $query");
             $retVal = $this->Patient->query($query);
             if ($this->checkForErrors($ErrMsg, $retVal)) {
                 $this->Patient->rollbackTransaction();
                 $jsonRecord['success'] = false;
                 $jsonRecord['msg'] = $this->get('frameworkErr');
                 $this->set('jsonRecord', $jsonRecord);
                 return;
             }
             $query = "";
             /* Reset query so we don't run it again in the final step */
         } else {
             if ("PUT" == $_SERVER['REQUEST_METHOD']) {
                 parse_str(file_get_contents("php://input"), $post_vars);
                 if (isset($post_vars["value"])) {
                     $MedID = $post_vars["value"];
                 }
                 if (isset($post_vars["LifetimeDose"])) {
                     $CumulativeDoseAmt = $post_vars["LifetimeDose"];
                 }
                 if (isset($post_vars["UnitName"])) {
                     $CumulativeDoseUnits = $post_vars["UnitName"];
                 } else {
                     if (isset($post_vars["Units"])) {
                         $CumulativeDoseUnits = $post_vars["Units"];
                     }
                 }
                 if ("" !== $CumulativeDoseUnits) {
                     $lookup = new LookUp();
                     $retVal = $lookup->getLookupIdByNameAndType($CumulativeDoseUnits, 11);
                     // error_log(json_encode($retVal));
                     $CumulativeDoseUnitsID = $retVal[0]["id"];
                     // error_log("Units = $CumulativeDoseUnits; ID = $CumulativeDoseUnitsID");
                 }
                 if (isset($post_vars["Source"])) {
                     $Source = $post_vars["Source"];
                 }
                 /* Update table record */
                 $query = "\n                UPDATE {$DataTable}\n                   SET \n                    MedID = '{$MedID}', \n                    CumulativeDoseAmt = '{$CumulativeDoseAmt}', \n                    CumulativeDoseUnits = '{$CumulativeDoseUnitsID}'\n            ";
                 if (isset($Source)) {
                     $query .= ",Source = '{$Source}'";
                 }
                 $query .= " WHERE ID = '{$cdhRecordID}'";
                 $retVal = $this->Patient->query($query);
                 /* Check for errors */
                 if ($this->checkForErrors($ErrMsg, $retVal)) {
                     $this->Patient->rollbackTransaction();
                     $jsonRecord['success'] = false;
                     $jsonRecord['msg'] = $this->get('frameworkErr');
                     $this->set('jsonRecord', $jsonRecord);
                     return;
                 }
                 $query = "";
                 /* Reset query so we don't run it again in the final step */
             } else {
                 if ("DELETE" == $_SERVER['REQUEST_METHOD']) {
                     $query = "DELETE from {$DataTable} WHERE ID = '{$cdhRecordID}'";
                     $retVal = $this->Patient->query($query);
                     /* Check for errors */
                     if ($this->checkForErrors($ErrMsg, $retVal)) {
                         $this->Patient->rollbackTransaction();
                         $jsonRecord['success'] = false;
                         $jsonRecord['msg'] = $this->get('frameworkErr');
                         $this->set('jsonRecord', $jsonRecord);
                         return;
                     }
                     $query = "";
                     /* Reset query so we don't run it again in the final step */
                 } else {
                     $jsonRecord['success'] = false;
                     $jsonRecord['msg'] = "Incorrect method called for CumulativeDoseTracking Service (expected a GET/POST/PUS/DELETE got a " . $_SERVER['REQUEST_METHOD'];
                     $this->Patient->rollbackTransaction();
                     $this->set('jsonRecord', $jsonRecord);
                     return;
                 }
             }
         }
     }
     if ("" !== $query) {
         $retVal = $this->Patient->query($query);
         if ($this->checkForErrors($ErrMsg, $retVal)) {
             $jsonRecord['success'] = false;
             $jsonRecord['msg'] = $this->get('frameworkErr');
             $this->Patient->rollbackTransaction();
         } else {
             $jsonRecord['success'] = 'true';
             if (count($retVal) > 0) {
                 unset($jsonRecord['msg']);
                 $jsonRecord['total'] = count($retVal);
                 $jsonRecord['records'] = $retVal;
             }
         }
     }
     $this->Patient->endTransaction();
     $this->set('jsonRecord', $jsonRecord);
     return;
 }
Ejemplo n.º 2
0
 function saveAllergy($form_data, $patientId)
 {
     if (empty($patientId)) {
         $patientId = $form_data->{'id'};
     }
     // MWB - 5/4/2012 Added checks for parameters below via "isset()".
     // Testing of new patients from MDWS indicated that data is NOT always
     // returned (e.d. AllergenName === "Not Assessed" doesn't return an ID
     // or Type)
     // Not sure if there are other cases where data isn't returned
     // completely, so checked all parameters
     if (isset($form_data->{'allergenId'}, $form_data->{'allergenName'}, $form_data->{'allergenType'})) {
         $allergen = $form_data->{'allergenName'};
         $type = $form_data->{'allergenType'};
         $vaId = $form_data->{'allergenId'};
         if (isset($form_data->{'comment'})) {
             $comment = $form_data->{'comment'};
         } else {
             $comment = '';
         }
     } else {
         $retVal = array();
         $a = array();
         if (DB_TYPE == 'sqlsrv') {
             $x = array();
             $x['SQLSTATE'] = "None";
             $x['code'] = "None";
             $x['message'] = "Allergies Not Assessed for this patient";
             $a[0] = $x;
             $retVal['error'] = $a;
         } else {
             if (DB_TYPE == 'mysql') {
                 $retVal['error'] = "Allergies Not Assessed for this patient";
             }
         }
         return $retVal;
     }
     /*
      * This is the allergen id used in MDWS. We may want to store this at
      * some point. $allergenId = $form_data->{'allergenId'};
      */
     $lookup = new LookUp();
     $lookupId = $lookup->getLookupIdByNameAndType($allergen, 29);
     if (!empty($lookupId[0])) {
         $lookupId = $lookupId[0]['id'];
     } else {
         $lookupId = $lookup->save(29, $allergen, $type);
         $lookupId = $lookupId[0]['lookupid'];
     }
     $query = "SELECT count(*) as count FROM Patient_Allergies where COMS_Allergen_ID = '" . $lookupId . "' AND Patient_ID = '" . $patientId . "'";
     $allergyCount = $this->query($query);
     if ($allergyCount[0]['count'] > 0) {
         $allergyCount['apperror'] = "This allergen already exists for this patient.";
         return $allergyCount;
     }
     $query = "INSERT INTO Patient_Allergies(Patient_ID,VA_Allergen_ID,COMS_Allergen_ID,Comment) values(" . "'" . $patientId . "'," . $vaId . ",'" . $lookupId . "','" . $comment . "')";
     $savedRecord = $this->query($query);
     return $savedRecord;
 }