sys_debug(); try { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } */ class Patient extends MY_Controller { var $db_smartone; public function index() { echo "Patient API"; } public function __construct() { parent::__construct(); $this->db_smartone = $this->load->database("clinicdev", true); } public function search() { $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'nolab' => '%', 'noreg' => '%', 'name' => '%', 'hp' => '%', 'dob' => '%', 'address' => '%', 'status' => 0 ]; if ($prm['noreg'] != '') $q['noreg'] = "%{$prm['noreg']}%"; if ($prm['nolab'] != '') $q['nolab'] = "%{$prm['nolab']}%"; if ($prm['status'] != '') $q['status'] = $prm['status']; if ($prm['search'] != '') { $e = explode('+', $prm['search']); if (isset($e[0])) $q['name'] = "%{$e[0]}%"; if (isset($e[1])) $q['hp'] = "%{$e[1]}%"; if (isset($e[2])) $q['dob'] = "%{$e[2]}%"; if (isset($e[3])) $q['address'] = "%{$e[3]}%"; } // QUERY TOTAL $sql = "select count(*) total from c_orderheader join one.m_patient on c_orderheaderm_patientid = m_patientid join one.m_title on M_PatientM_TitleID = M_TitleID where C_OrderHeaderNumber like ? and M_PatientName LIKE ? and M_PatientHP LIKE ? and M_PatientDOB LIKE ? and C_OrderHeaderIsActive = 'Y' and ((C_OrderHeaderM_StatusID = ? and ? <> 0) or C_OrderHeaderM_StatusID = 0)"; $query = $this->db_smartone->query($sql, array($q['nolab'], $q['name'], $q['hp'], $q['dob'], $q['status'], $q['status'])); if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_patient count",$this->db_smartone); exit; } // set locales $this->db_smartone->query("SET @@lc_time_names = 'id_ID'"); $sql = "select M_PatientID, M_PatientNoReg, concat(M_TitleName,' ',M_PatientName) M_PatientName, M_PatientHP, M_PatientDOB, M_PatientNote, 'X' as M_PatientAddress, M_PatientNote, C_OrderHeaderID, C_OrderHeaderNumber, M_StatusCode, C_OrderHeaderM_PatientAge, C_OrderHeaderComplaint, C_OrderHeaderIsLab, C_OrderHeaderIsReceipt, C_OrderHeaderDate, dayname(C_OrderHeaderDate) `day` from c_orderheader join one.m_patient on c_orderheaderm_patientid = m_patientid join one.m_title on M_PatientM_TitleID = M_TitleID join m_status on c_orderheaderm_statusid = m_statusid where C_OrderHeaderNumber like ? and M_PatientName LIKE ? and ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL) OR M_PatientHP IS NULL) and M_PatientDOB LIKE ? and C_OrderHeaderIsActive = 'Y' and ((C_OrderHeaderM_StatusID = ? and ? <> 0) or C_OrderHeaderM_StatusID = 0) limit 0,{$max_rst}"; $query = $this->db_smartone->query($sql, array($q['nolab'], $q['name'], $q['hp'], $q['dob'], $q['status'], $q['status'])); if ($query) { $rows = $query->result_array(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_patient rows",$this->db_smartone); exit; } } }