Example #1
0
 public function __construct(&$props, $dbArray = null)
 {
     parent::__construct($props, $dbArray);
 }
Example #2
0
 /**
  * $id = Record ID in specific table
  * $type = Determines which table to update ("Pre", "Post", "Therapy")
  *         Pre uses Medication_Hydration Table and ID maps to 'MH_ID'
  *         Post uses Medication_Hydration Table and ID maps to 'MH_ID'
  *         Therapy uses Template_Regimen Table and ID maps to 'Patient_Regimen_ID'
  * $status = Status to set - "Hold", "Cancel", "Clear"
  **/
 function HoldCancel($patient_id = null, $template_id = null, $type = null, $status = null)
 {
     // error_log("HoldCancel - $template_id, $type, $status");
     $jsonRecord = array();
     $jsonRecord['success'] = true;
     if ("Pre" === $type || "Post" === $type || "Therapy" === $type) {
         if ("Hold" === $status || "Cancel" === $status || "Clear" === $status || null === $status) {
             if (null === $status || "Clear" === $status) {
                 $status = "";
             }
             if ("PUT" == $_SERVER['REQUEST_METHOD']) {
                 $table = "Medication_Hydration";
                 $key = "MH_ID";
                 if ("Therapy" == $type) {
                     $table = "Template_Regimen";
                     $key = "Patient_Regimen_ID";
                 }
                 $query = "select * from {$table} where {$key} = '{$template_id}'";
                 // error_log($query);
                 $TreatmentData = $this->Orders->query($query);
                 // error_log("Treatment Data - " . json_encode($TreatmentData[0]));
                 $lookup = new LookUp();
                 $Order_Type = $type;
                 $TID = $TreatmentData[0]["Template_ID"];
                 $Drug_ID = $TreatmentData[0]["Drug_ID"];
                 $Drug_Name = $lookup->getLookupNameByIdAndType($Drug_ID, 2);
                 $PID = $patient_id;
                 // error_log("Status = $status");
                 // error_log("Order_Type = $Order_Type");
                 // error_log("TID = $TID");
                 // error_log("Drug_ID = $Drug_ID");
                 // error_log("Drug_Name = $Drug_Name");
                 // error_log("Drug_Name = " . $Drug_Name[0]["Name"]);
                 if (0 == count($TreatmentData)) {
                     $jsonRecord['success'] = 'false';
                     $jsonRecord['msg'] = "No Record Matches {$id}";
                 } else {
                     if ($this->checkForErrors('Set Hold/Cancel Status FAILED ', $TreatmentData)) {
                         $jsonRecord['success'] = 'false';
                         $jsonRecord['msg'] = $frameworkErr;
                         $this->set('frameworkErr', null);
                     } else {
                         if ("Hold" === $status) {
                             $this->Orders->updateOrderStatusHold($TID, $Drug_Name, $Order_Type, $PID);
                         } else {
                             if ("Cancel" === $status) {
                                 $this->Orders->updateOrderStatusCancelled($TID, $Drug_Name, $Order_Type, $PID);
                             }
                         }
                     }
                 }
             } else {
                 $jsonRecord['success'] = false;
                 $jsonRecord['msg'] = "Invalid COMMAND - " . $_SERVER['REQUEST_METHOD'] . " expected a PUT";
             }
         } else {
             $jsonRecord['success'] = false;
             $jsonRecord['msg'] = "Invalid COMMAND - {$status}, expected a Hold/Cancel or Clear";
         }
     } else {
         $jsonRecord['success'] = false;
         $jsonRecord['msg'] = "Invalid Therapy Type = {$type} expected Pre/Post/Therapy";
     }
     $this->set('jsonRecord', $jsonRecord);
 }
Example #3
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;
 }
Example #4
0
 private function MatchGetInfo4OnePatient($lastFour, $comspatientModel)
 {
     error_log("MyMDWS Controller - MatchGetInfo4OnePatient() - Entry Point, DFN = " . $this->_dfn);
     $patient = $comspatientModel->getPatientIdByDFN($this->_dfn);
     if ($this->checkForErrors('Get Patient Record by DFN Failed. ', $patient)) {
         $jsonRecord['success'] = false;
         $jsonRecord['message'] = $this->get('frameworkErr');
         $this->set('jsonRecord', $jsonRecord);
         error_log("MyMDWS Controller - MatchGetInfo4OnePatient() - call to Patient Model -> getPatientIdByDFN() FAILED - " . $this->get('frameworkErr'));
         return $jsonRecord;
     }
     if (count($patient) > 0) {
         error_log("Have one or more Patient Records");
     } else {
         error_log("NO Patient Records");
     }
     error_log("MyMDWS Controller - MatchGetInfo4OnePatient() - Got Patient By DFN (" . $this->_dfn . "), No Errors - " . json_encode($patient));
     $patient = $comspatientModel->selectByPatientId($patient[0]['id']);
     if ($this->checkForErrors('Get Patient Info Failed. ', $patient)) {
         $jsonRecord['success'] = false;
         $jsonRecord['message'] = $this->get('frameworkErr');
         $this->set('jsonRecord', $jsonRecord);
         // return;	<-- MWB - 5/4/2012 Can't return null, need to return the jsonRecord
         return $jsonRecord;
     }
     error_log("Got Patient Info, No Errors (look for id in element 0) - " . json_encode($patient));
     $patientTemplate = $comspatientModel->getTemplateIdByPatientID($patient[0]['id']);
     if ($this->checkForErrors('Get Patient Template Failed. ', $patientTemplate)) {
         $jsonRecord['success'] = false;
         $jsonRecord['message'] = $this->get('frameworkErr');
         $this->set('jsonRecord', $jsonRecord);
         return $jsonRecord;
     } elseif (!empty($patientTemplate)) {
         $details = $comspatientModel->getPatientDetailInfo($patient[0]['id']);
         if ($this->checkForErrors('Get Patient Details Failed. ', $details)) {
             $jsonRecord['success'] = false;
             $jsonRecord['message'] = $this->get('frameworkErr');
             $this->set('jsonRecord', $jsonRecord);
             return $jsonRecord;
         }
     } else {
         $details = $this->createEmptyTemplateArray();
     }
     error_log("Got Patient Details " . json_encode($details));
     if ('' === $details[0]['TemplateID']) {
         $detail = $details[0];
     } else {
         $detail = $this->TreatmentStatus($details[0]);
         if ($detail['TreatmentStatus'] == "Ended") {
             $detail = array();
             $detail['TemplateID'] = '';
             $detail['TemplateName'] = '';
             $detail['TemplateDescription'] = '';
             $detail['TreatmentStart'] = '';
             $detail['TreatmentEnd'] = '';
             $detail['TreatmentStatus'] = '';
             $detail['Goal'] = '';
             $detail['ClinicalTrial'] = '';
             $detail['WeightFormula'] = '';
             $detail['BSAFormula'] = '';
             $detail['PerformanceStatus'] = '';
         }
     }
     $patient[0] = array_merge($patient[0], $detail);
     $lookup = new LookUp();
     $amputations = $lookup->getLookupDescByNameAndType($patient[0]['id'], '30');
     if ($this->checkForErrors('Get Patient Amputations Failed. ', $amputations)) {
         $jsonRecord['success'] = false;
         $jsonRecord['message'] = $this->get('frameworkErr');
         $this->set('jsonRecord', $jsonRecord);
         return;
     }
     $tmpAmputations = array();
     foreach ($amputations as $amputation) {
         array_push($tmpAmputations, $amputation);
     }
     $patient[0]['Amputations'] = $tmpAmputations;
     $VPR = $this->getVitalsFromVistA($this->_dfn);
     $VPR_New = array();
     $VPR_Data = array();
     $VPR_Data_Items = array();
     $NameInfo = array();
     $NameInfo["Name"] = $this->_Name;
     $NameInfo["pName"] = $this->_pName;
     $NameInfo["fullName"] = $this->_fullName;
     $NameInfo["briefId"] = $lastFour;
     $NameInfo["dateOfBirth"] = $this->_dob;
     $NameInfo["genderCode"] = "urn:va:pat-gender:M";
     $NameInfo["gender"] = $this->_gender;
     $NameInfo["age"] = $this->_age;
     $NameInfo["dfn"] = $this->_dfn;
     $NameInfo["ssn"] = $this->_ssn;
     $fullname = array();
     $fullname[] = $NameInfo;
     // $VPR_Data_Items = array_merge( $VPR_Data_Items, json_decode($VPR), $NameInfo, json_encode($VPR1) );
     $VPR_Data_Items = array_merge($VPR_Data_Items, $fullname, $VPR);
     $VPR_Data["items"] = $VPR_Data_Items;
     $VPR_New["data"] = $VPR_Data;
     $patient[0]["VPR"] = $VPR_New;
     $this->patient = $patient[0];
     error_log("MyMDWS Controller - MatchGetInfo4OnePatient() - EXIT Point, patient = " . json_encode($patient[0]));
     return null;
 }
Example #5
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;
 }
Example #6
0
 public function getSearchInput()
 {
     return $this->_getInputSelect(parent::getSearchValue(), parent::getSearchName());
 }