db_onedev = $this->load->database("onedev", true); } function lookupantibioticbyname(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $bacteria = $prm['bacteria']; $antibiotic = $prm['antibiotic'];; $all = $prm['all']; $limit = ''; if($all == 'N'){ $limit = ' LIMIT 10'; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = "select COUNT(*) as total FROM(SELECT * from t_antibiotic JOIN t_bacteria ON T_AntibioticT_BacteriaID = T_BacteriaID AND T_BacteriaIsActive = 'Y' WHERE T_BacteriaName LIKE CONCAT('%','{$bacteria}','%') AND T_AntibioticIsActive = 'Y' GROUP BY T_AntibioticID) a"; // $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); $tot_count = 0; $tot_page = 0; if ($query) { $tot_count = $query->result_array()[0]["total"]; $tot_page = ceil($tot_count/$number_limit); } else { $this->sys_error_db("t_antibiotic count", $this->db_onedev); exit; } $sql = "select T_AntibioticID as id, T_AntibioticName as name, T_BacteriaID, T_BacteriaName, t_antibiotic.*, CONCAT(T_AntibioticMinValueR,' - ',T_AntibioticMaxValueR) as descR, CONCAT(T_AntibioticMinValueS,' - ',T_AntibioticMaxValueS) as descS, CONCAT(T_AntibioticMinValueI,' - ',T_AntibioticMaxValueI) as descI from t_antibiotic JOIN t_bacteria ON T_AntibioticT_BacteriaID = T_BacteriaID AND T_BacteriaIsActive = 'Y' WHERE T_BacteriaName LIKE CONCAT('%','{$bacteria}','%') AND T_AntibioticName LIKE CONCAT('%','{$antibiotic}','%') AND T_AntibioticIsActive = 'Y' GROUP BY T_AntibioticID ORDER BY T_BacteriaName ASC, T_AntibioticName ASC limit $number_limit offset $number_offset"; $sql_param = array($search); $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("t_antibiotic select"); exit; } $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function lookupbacteriabyname() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $bacteria = $prm['bacteria']; $antibiotic = $prm['antibiotic']; $limit = ''; if($all == 'N'){ $limit = ' LIMIT 10'; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = "select COUNT(*) as total FROM(SELECT * from t_bacteria LEFT JOIN t_antibiotic ON T_BacteriaID = T_AntibioticT_BacteriaID AND T_AntibioticIsActive = 'Y' where T_BacteriaName LIKE CONCAT('%','{$bacteria}','%') AND IFNULL(T_AntibioticName,'') LIKE CONCAT('%','{$antibiotic}','%') AND T_BacteriaIsActive = 'Y' GROUP BY T_BacteriaID) a"; $sql_param = array($search); // $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $query = $this->db_onedev->query($sql); $tot_count = 0; $tot_page = 0; if ($query) { $tot_count = $query->result_array()[0]["total"]; $tot_page = ceil($tot_count/$number_limit); } else { $this->sys_error_db("t_bacteria count", $this->db_onedev); exit; } $sql = "select T_BacteriaID as id, T_BacteriaName as name, T_BacteriaName as namex, t_bacteria.* from t_bacteria LEFT JOIN t_antibiotic ON T_BacteriaID = T_AntibioticT_BacteriaID AND T_AntibioticIsActive = 'Y' where T_BacteriaName LIKE CONCAT('%','{$bacteria}','%') AND IFNULL(T_AntibioticName,'') LIKE CONCAT('%','{$antibiotic}','%') AND T_BacteriaIsActive = 'Y' GROUP BY T_BacteriaID ORDER BY T_BacteriaName ASC limit $number_limit offset $number_offset"; $sql_param = array($search); $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("t_bacteria select"); exit; } $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function addnewbacteria() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $name = $prm['name']; $sql = "insert into t_bacteria( T_BacteriaName, T_BacteriaCreated, T_BacteriaLastUpdated ) values( ?, now(), now())"; $query = $this->db_onedev->query($sql, array( $name ) ); //echo $query; if (!$query) { $this->sys_error_db("t_bacteria insert"); exit; } $last_id = $this->db_onedev->insert_id(); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); $last_id = $this->db_onedev->insert_id(); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function editbacteria() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id = $prm['id']; $name = $prm['name']; $userid = $this->sys_user["M_UserID"]; $sqlcompany = "update t_bacteria SET T_BacteriaName = ?, T_BacteriaLastUpdated = now() where T_BacteriaID = ? "; $querycompany = $this->db_onedev->query($sqlcompany, array( $name, $id ) ); // echo $query; if (!$querycompany) { $this->sys_error_db("t_bacteria update"); exit; } $result = array ("total" => 1, "records" => array("xid" => $id)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function addnewantibiotic() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $bacteriaid = $prm['bacteriaid']; $T_AntibioticName = $prm['T_AntibioticName']; $T_AntibioticMinValueR = $prm['T_AntibioticMinValueR']; $T_AntibioticMaxValueR = $prm['T_AntibioticMaxValueR']; $T_AntibioticMinInclusiveR = $prm['T_AntibioticMinInclusiveR']; $T_AntibioticMaxInclusiveR = $prm['T_AntibioticMaxInclusiveR']; $T_AntibioticNoteR = $prm['T_AntibioticNoteR']; $T_AntibioticMinValueS = $prm['T_AntibioticMinValueS']; $T_AntibioticMaxValueS = $prm['T_AntibioticMaxValueS']; $T_AntibioticMinInclusiveS = $prm['T_AntibioticMinInclusiveS']; $T_AntibioticMaxInclusiveS = $prm['T_AntibioticMaxInclusiveS']; $T_AntibioticNoteS = $prm['T_AntibioticNoteS']; $T_AntibioticMinValueI = $prm['T_AntibioticMinValueI']; $T_AntibioticMaxValueI = $prm['T_AntibioticMaxValueI']; $T_AntibioticMinInclusiveI = $prm['T_AntibioticMinInclusiveI']; $T_AntibioticMaxInclusiveI = $prm['T_AntibioticMaxInclusiveI']; $T_AntibioticNoteI = $prm['T_AntibioticNoteI']; $userid = $this->sys_user["M_UserID"]; if($bacteriaid == 0){ $errors = array(); if($bacteriaid == 0){ array_push($errors,array('field'=>'bacteria','msg'=>'Bakteri dipilih dulu dong')); } $result = array ("total" => -1,"errors" => $errors, "records" => 0); $this->sys_ok($result); }else{ if($prm['xid'] == 0){ $sql = "insert into t_antibiotic( T_AntibioticName, T_AntibioticT_BacteriaID, T_AntibioticMinValueR, T_AntibioticMaxValueR, T_AntibioticMinInclusiveR, T_AntibioticMaxInclusiveR, T_AntibioticNoteR, T_AntibioticMinValueS, T_AntibioticMaxValueS, T_AntibioticMinInclusiveS, T_AntibioticMaxInclusiveS, T_AntibioticNoteS, T_AntibioticMinValueI, T_AntibioticMaxValueI, T_AntibioticMinInclusiveI, T_AntibioticMaxInclusiveI, T_AntibioticNoteI, T_AntibioticUserID, T_AntibioticCreated, T_AntibioticLastUpdated) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $T_AntibioticName, $bacteriaid, $T_AntibioticMinValueR, $T_AntibioticMaxValueR, $T_AntibioticMinInclusiveR, $T_AntibioticMaxInclusiveR, $T_AntibioticNoteR, $T_AntibioticMinValueS, $T_AntibioticMaxValueS, $T_AntibioticMinInclusiveS, $T_AntibioticMaxInclusiveS, $T_AntibioticNoteS, $T_AntibioticMinValueI, $T_AntibioticMaxValueI, $T_AntibioticMinInclusiveI, $T_AntibioticMaxInclusiveI, $T_AntibioticNoteI, $userid ) ); if (!$query) { $this->sys_error_db("t_antibiotic insert",$this->db_onedev); exit; } $last_id = $this->db_onedev->insert_id(); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); }else{ $sql = "UPDATE t_antibiotic SET T_AntibioticT_BacteriaID = '{$bacteriaid}', T_AntibioticName = '{$T_AntibioticName}', T_AntibioticMinValueR = '{$T_AntibioticMinValueR}', T_AntibioticMaxValueR = '{$T_AntibioticMaxValueR}', T_AntibioticMinInclusiveR = '{$T_AntibioticMinInclusiveR}', T_AntibioticMaxInclusiveR = '{$T_AntibioticMaxInclusiveR}', T_AntibioticNoteR = '{$T_AntibioticNoteR}', T_AntibioticMinValueS = '{$T_AntibioticMinValueS}', T_AntibioticMaxValueS = '{$T_AntibioticMaxValueS}', T_AntibioticMinInclusiveS = '{$T_AntibioticMinInclusiveS}', T_AntibioticMaxInclusiveS = '{$T_AntibioticMaxInclusiveS}', T_AntibioticNoteS = '{$T_AntibioticNoteS}', T_AntibioticMinValueI = '{$T_AntibioticMinValueI}', T_AntibioticMaxValueI = '{$T_AntibioticMaxValueI}', T_AntibioticMinInclusiveI = '{$T_AntibioticMinInclusiveI}', T_AntibioticMaxInclusiveI = '{$T_AntibioticMaxInclusiveI}', T_AntibioticNoteI = '{$T_AntibioticNoteI}', T_AntibioticUserID = '{$userid}', T_AntibioticLastUpdated = now() WHERE T_AntibioticID = '{$prm['xid']}'"; //echo $sql; $query = $this->db_onedev->query($sql); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } } } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function deletebacteria() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $sql = "update t_bacteria SET T_BacteriaIsActive = 'N', T_BacteriaLastUpdated = now() WHERE T_BacteriaID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("t_bacteria delete"); exit; } $sql = "update t_antibiotic SET T_AntibioticIsActive = 'N', T_AntibioticLastUpdated = now() WHERE T_AntibioticT_BacteriaID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("t_antibiotic delete"); exit; } $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function deleteantibiotic() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $sql = "update t_antibiotic SET T_AntibioticIsActive = 'N', T_AntibioticLastUpdated = now() WHERE T_AntibioticID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("t_antibiotic delete"); exit; } $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function searchbacteria(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM t_bacteria WHERE T_BacteriaName like ? AND T_BacteriaIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("t_bacteria count",$this->db_onedev); exit; } $sql = " SELECT T_BacteriaID, T_BacteriaName FROM t_bacteria WHERE T_BacteriaName like ? AND T_BacteriaIsActive = 'Y' ORDER BY T_BacteriaName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("t_bacteria rows",$this->db_onedev); exit; } } function searchbacteriabyname(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM t_bacteria WHERE T_BacteriaName like ? AND T_BacteriaIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("t_bacteria count",$this->db_onedev); exit; } $sql = " SELECT T_BacteriaID, T_BacteriaName FROM t_bacteria WHERE T_BacteriaName like ? AND T_BacteriaIsActive = 'Y' ORDER BY T_BacteriaName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("t_bacteria rows",$this->db_onedev); exit; } } function searchcity(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_city WHERE M_CityName like ? AND M_CityIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_city count",$this->db_onedev); exit; } $sql = " SELECT * FROM m_city WHERE M_CityName like ? AND M_CityIsActive = 'Y' ORDER BY M_CityName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_city rows",$this->db_onedev); exit; } } function searchdistrict(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_district WHERE M_DistrictName like ? AND M_DistrictM_CityID = '{$id}' AND M_DistrictIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_district count",$this->db_onedev); exit; } $sql = " SELECT * FROM m_district WHERE M_DistrictName like ? AND M_DistrictM_CityID = '{$id}' AND M_DistrictIsActive = 'Y' ORDER BY M_DistrictName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_district rows",$this->db_onedev); exit; } } function searchkelurahan(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_kelurahan WHERE M_KelurahanName like ? AND M_KelurahanM_DistrictID = '{$id}' AND M_KelurahanIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_district count",$this->db_onedev); exit; } $sql = " SELECT * FROM m_kelurahan WHERE M_KelurahanName like ? AND M_KelurahanM_DistrictID = '{$id}' AND M_KelurahanIsActive = 'Y' ORDER BY M_KelurahanName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_district rows",$this->db_onedev); exit; } } function searchcompany(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_company WHERE M_CompanyName like ? AND M_CompanyIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_company count",$this->db_onedev); exit; } $sql = " SELECT * FROM m_company WHERE M_CompanyName like ? AND M_CompanyIsActive = 'Y' ORDER BY M_CompanyName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_company rows",$this->db_onedev); exit; } } function searchmou(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_mou WHERE M_MouName like ? AND M_MouM_CompanyID = '{$id}' AND M_MouIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_mou count",$this->db_onedev); exit; } $sql = "SELECT * FROM m_mou WHERE M_MouName like ? AND M_MouM_CompanyID = '{$id}' AND M_MouIsActive = 'Y' ORDER BY M_MouName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); // echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_mou rows",$this->db_onedev); exit; } } function searchdoctor(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName FROM m_doctor WHERE M_DoctorIsActive = 'Y') a WHERE M_DoctorName like ?"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_doctor count",$this->db_onedev); exit; } $sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName FROM m_doctor WHERE M_DoctorIsActive = 'Y') a WHERE M_DoctorName like ? ORDER BY M_DoctorName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_doctor rows",$this->db_onedev); exit; } } function selectaddressdoctor(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $rows = []; $query ="SELECT M_DoctorAddressID, CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as M_DoctorAddressNote FROM m_doctoraddress WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = '{$id}'"; //echo $query; $rows['addressdoctors'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } }