db_onedev = $this->load->database("onedev", true); } function lookupmcunonlabbyname(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $testname = $prm['testname']; $testcode = $prm['testcode']; $filter = ''; if(isset($sexid)){ $filter .= "AND ($sexid = 0 or ($sexid > 0 and Nat_SexID = $sexid)) "; } if(isset($flagid)){ $filter .= "AND ($flagid = 0 or ($flagid > 0 and Nat_FlagID = $flagid))"; } $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 nat_test LEFT JOIN nat_mcunormalnolab ON Nat_TestID = Nat_McuNormalNonLabNat_TestID AND Nat_McuNormalNonLabIsActive = 'Y' WHERE Nat_TestIsActive = 'Y' AND Nat_TestIsNonLab <> '' AND Nat_TestIsResult = 'Y' AND Nat_TestName like '%{$testname}%' AND Nat_TestCode like '%{$testcode}%' $filter GROUP BY Nat_TestID) 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("nat_test count", $this->db_onedev); exit; } $sql = "SELECT nat_test.*, Nat_TestID as id, Nat_TestID, IFNULL(Nat_McuNormalNonLabID,0) as Nat_McuNormalNonLabID, Nat_TestName, Nat_TestCode FROM nat_test LEFT JOIN nat_mcunormalnolab ON Nat_TestID = Nat_McuNormalNonLabNat_TestID AND Nat_McuNormalNonLabIsActive = 'Y' WHERE Nat_TestIsActive = 'Y' AND Nat_TestIsNonLab <> '' AND Nat_TestIsResult = 'Y' AND Nat_TestName like '%{$testname}%' AND Nat_TestCode like '%{$testcode}%' $filter GROUP BY Nat_TestID ORDER BY Nat_TestCode 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("nat_test 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); } } function lookupmcunormalnonlabbyid(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $mcunonlabtext = $prm['mcunormalnonlabtext']; $status = $prm['status']; $all = $prm['all']; $filter = ''; if($status != 'A'){ $filter .= "AND status = '{$status}' "; }else{ $filter .= ""; } $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 *, IF(IFNULL(Nat_McuNormalNonLabID,0) > 0 , 'Y', 'N') as status from m_mcunonlab LEFT JOIN nat_mcunormalnolab ON M_McuNonLabID = Nat_McuNormalNonLabM_McuNonLabID AND Nat_McuNormalNonLabNat_TestID = $id AND Nat_McuNormalNonLabIsActive = 'Y' LEFT JOIN nat_test ON Nat_McuNormalNonLabNat_TestID = Nat_TestID AND Nat_TestIsActive = 'Y' WHERE M_McuNonLabIsActive = 'Y' GROUP BY M_McuNonLabID) a WHERE M_McuNonLabText like '%{$mcunonlabtext}%' $filter"; // $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("m_mcunonlab count", $this->db_onedev); exit; } $sql = "SELECT * FROM(select M_McuNonLabID as id, M_McuNonLabID, M_McuNonLabText, Nat_McuNormalNonLabID, Nat_McuNormalNonLabNat_TestID, Nat_McuNormalNonLabM_McuNonLabID, IF(IFNULL(Nat_McuNormalNonLabID,0) > 0 , 'Y', 'N') as status from m_mcunonlab LEFT JOIN nat_mcunormalnolab ON M_McuNonLabID = Nat_McuNormalNonLabM_McuNonLabID AND Nat_McuNormalNonLabNat_TestID = $id AND Nat_McuNormalNonLabIsActive = 'Y' LEFT JOIN nat_test ON Nat_McuNormalNonLabNat_TestID = Nat_TestID AND Nat_TestIsActive = 'Y' WHERE M_McuNonLabIsActive = 'Y') a WHERE M_McuNonLabText like '%{$mcunonlabtext}%' $filter GROUP BY M_McuNonLabID ORDER BY M_McuNonLabID 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("m_mcunonlab 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); } } function listingmcunormalnonlab(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $mcunonlabtext = $prm['mcunormalnonlabtext']; $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 m_mcunonlab WHERE M_McuNonLabIsActive = 'Y' AND M_McuNonLabText like '%{$mcunonlabtext}%'"; // $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("m_mcunonlab count", $this->db_onedev); exit; } $sql = "SELECT * from m_mcunonlab WHERE M_McuNonLabIsActive = 'Y' AND M_McuNonLabText like '%{$mcunonlabtext}%' ORDER BY M_McuNonLabID 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("m_mcunonlab 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); } } function getsexreg(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT * FROM nat_sex WHERE Nat_SexIsActive = 'Y' "; //echo $query; $rows['sexes'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT * FROM nat_testtype WHERE Nat_TestTypeIsActive = 'Y' "; //echo $query; $rows['normalvaluetypees'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT * FROM nat_flag WHERE Nat_FlagIsActive = 'Y' "; //echo $query; $rows['flages'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT 'HARI' as Nat_AgeUnitID,'HARI' as Nat_AgeUnitName UNION SELECT 'BULAN' as Nat_AgeUnitID, 'BULAN' as Nat_AgeUnitName UNION SELECT 'TAHUN' as Nat_AgeUnitID, 'TAHUN' as Nat_AgeUnitName "; //echo $query; $rows['ageunites'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT 'HARI' as Nat_AgeUnitID,'HARI' as Nat_AgeUnitName UNION SELECT 'BULAN' as Nat_AgeUnitID, 'BULAN' as Nat_AgeUnitName UNION SELECT 'TAHUN' as Nat_AgeUnitID, 'TAHUN' as Nat_AgeUnitName "; //echo $query; $rows['minageunites'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT 'HARI' as Nat_AgeUnitID,'HARI' as Nat_AgeUnitName UNION SELECT 'BULAN' as Nat_AgeUnitID, 'BULAN' as Nat_AgeUnitName UNION SELECT 'TAHUN' as Nat_AgeUnitID, 'TAHUN' as Nat_AgeUnitName "; //echo $query; $rows['maxageunites'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT 0 as Nat_SexID, 'Semua' as Nat_SexName UNION SELECT Nat_SexID, Nat_SexName FROM nat_sex WHERE Nat_SexIsActive = 'Y' "; //echo $query; $rows['f_sexs'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT 0 as Nat_FlagID, 'Semua' as Nat_FlagName UNION SELECT Nat_FlagID, Nat_FlagName FROM nat_flag WHERE Nat_FlagIsActive = 'Y'"; //echo $query; $rows['f_flags'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT 'A' as M_StatusID, 'Semua' as M_StatusName UNION SELECT 'Y' as M_StatusID, 'Terpilih' as M_StatusName UNION SELECT 'N' as M_StatusID, 'Belum Terpilih' as M_StatusName "; //echo $query; $rows['f_statuss'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getstatus(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT 'A' as M_StatusID, 'Semua' as M_StatusName UNION SELECT 'Y' as M_StatusID, 'Terpilih' as M_StatusName UNION SELECT 'N' as M_StatusID, 'Belum Terpilih' as M_StatusName "; //echo $query; $rows['f_statuss'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } public function addnewmcunormalnonlab() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $mcunonlabtext = $prm['mcunonlabtext']; $userid = $this->sys_user["M_UserID"]; $sql = "insert into m_mcunonlab( M_McuNonLabText, M_McuNonLabUserID, M_McuNonLabCreated, M_McuNonLabLastUpdated ) values(?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $mcunonlabtext, $userid ) ); if (!$query) { $this->sys_error_db("m_mcunonlab insert",$this->db_onedev); exit; } $last_id = $this->db_onedev->insert_id(); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function saveaddeditmcunormalnonlab() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $testid = $prm['testid']; $mcunonlabid = $prm['M_McuNonLabID']; $mcunonlabmcunormalnonlabid = $prm['Nat_McuNormalNonLabID']; $status = $prm['status']; $userid = $this->sys_user["M_UserID"]; if($status == 'Y'){ $sql = "insert into nat_mcunormalnolab( Nat_McuNormalNonLabNat_TestID, Nat_McuNormalNonLabM_McuNonLabID, Nat_McuNormalNonLabUserID, Nat_McuNormalNonLabCreated, Nat_McuNormalNonLabLastUpdated ) values(?,?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $testid, $mcunonlabid, $userid ) ); if (!$query) { $this->sys_error_db("nat_mcunormalnolab 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 nat_mcunormalnolab SET Nat_McuNormalNonLabIsActive = 'N', Nat_McuNormalNonLabUserID = ?, Nat_McuNormalNonLabCreated = now(), Nat_McuNormalNonLabLastUpdated = now() WHERE Nat_McuNormalNonLabID = ?"; $query = $this->db_onedev->query($sql, array( $userid, $mcunonlabmcunormalnonlabid ) ); if (!$query) { $this->sys_error_db("nat_mcunormalnolab insert",$this->db_onedev); exit; } $last_id = $this->db_onedev->insert_id(); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function saveeditsaran(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $query = " UPDATE m_mcunonlab SET M_McuNonLabText = '{$prm['mcunonlabtext']}', M_McuNonLabIsActive = '{$prm['status']}', M_McuNonLabUserID = {$userid} WHERE M_McuNonLabID = {$prm['id']} "; //echo $query; $action = $this->db_onedev->query($query); if($action){ $result = array( "total" => 1 , "records" => array(), ); $this->sys_ok($result); exit; } else{ $this->sys_error_db($this->db_onedev->last_query(), $this->db_onedev); exit; } } function saveallmcunonlab(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $details = $prm['details']; $userid = $this->sys_user["M_UserID"]; foreach($details as $k => $v){ $query = "UPDATE nat_mcunormalnolab SET Nat_McuNormalNonLabNat_TestID = '{$v['Nat_McuNormalNonLabNat_TestID']}', Nat_McuNormalNonLabAdviceIna = '{$v['Nat_McuNormalNonLabAdviceIna']}', Nat_McuNormalNonLabAdviceEng = '{$v['Nat_McuNormalNonLabAdviceEng']}', Nat_McuNormalNonLabUserID = {$userid}, Nat_McuNormalNonLabCreated = now(), Nat_McuNormalNonLabLastUpdated = now() WHERE Nat_McuNormalNonLabID = {$v['Nat_McuNormalNonLabID']}"; //echo $query; $action = $this->db_onedev->query($query); } if($action){ $result = array( "total" => 1 , "records" => array(), ); $this->sys_ok($result); exit; } else{ $this->sys_error_db($this->db_onedev->last_query(), $this->db_onedev); exit; } } public function deletemcunormalnonlab() { 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 nat_methode SET Nat_MethodeIsActive = 'N' WHERE Nat_MethodeID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("nat_methode delete"); exit; } $sql = "update nat_test SET Nat_TestIsActive = 'N' WHERE Nat_TestNat_MethodeID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("nat_test 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 deletemcunonlab() { 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 nat_test SET Nat_TestIsActive = 'N' WHERE Nat_TestID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("nat_test 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 searchmcunormalnonlab(){ 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 nat_methode WHERE Nat_TestCode like ? AND Nat_MethodeIsActive = '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("nat_methode count",$this->db_onedev); exit; } $sql = " SELECT Nat_MethodeID, Nat_TestCode FROM nat_methode WHERE Nat_TestCode like ? AND Nat_MethodeIsActive = 'Y' ORDER BY Nat_TestCode 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("nat_methode rows",$this->db_onedev); exit; } } function searchmcunormalnonlabbyname(){ 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 nat_methode WHERE Nat_TestCode like ? AND Nat_MethodeIsActive = '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("nat_methode count",$this->db_onedev); exit; } $sql = " SELECT Nat_MethodeID, Nat_TestCode FROM nat_methode WHERE Nat_TestCode like ? AND Nat_MethodeIsActive = 'Y' ORDER BY Nat_TestCode 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("nat_methode rows",$this->db_onedev); exit; } } function searchtest(){ 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_test WHERE T_TestName like ? AND T_TestIsActive = 'Y' AND T_TestIsResult = '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_test count",$this->db_onedev); exit; } $sql = " SELECT * FROM t_test WHERE T_TestName like ? AND T_TestIsActive = 'Y' AND T_TestIsResult = 'Y' ORDER BY T_TestName 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_test rows",$this->db_onedev); exit; } } }