db_onedev = $this->load->database("onedev", true); $this->load->helper(array('form', 'url')); } function getallsupplies(){ $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $sql = " SELECT M_SuppliesID as supplies_id, M_SuppliesName as supplies_name, 'N' as status FROM m_supplies WHERE M_SuppliesIsActive = 'Y'"; //echo $sql; $rows = $this->db_onedev->query($sql)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getstaffbydate(){ $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $xdate = date('Y-m-d',strtotime($prm['xdate'])); $sql = " SELECT PreOrder_HeaderM_StaffID as id, M_StaffName as name FROM one_preorder_dev.preorder_header JOIN m_staff ON PreOrder_HeaderM_StaffID = M_StaffID WHERE PreOrder_HeaderDate = '{$xdate}' AND PreOrder_HeaderIsActive = 'Y'"; //echo $sql; $rows = $this->db_onedev->query($sql)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getorderbydatestaff(){ $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $xdate = date('Y-m-d',strtotime($prm['xdate'])); $staffid = $prm['staffid']; $sql = "SELECT Preorder_SampleID as trx_id, PreOrder_HeaderNumbering as trx_numbering, DATE_FORMAT(PreOrder_HeaderDate,'%d-%m-%Y') as trx_date, DATE_FORMAT(PreOrder_HeaderTime,'%H:%i') as trx_time, GROUP_CONCAT(DISTINCT T_TestName separator ',') as tests, T_SampleTypeName as sampletype_name, T_SampleTypeID as sampletype_id, IFNULL(Preorder_SuppliesTrxID,0) as supplies_trx_id, M_StaffName as staffname, M_PatientName as patient_name, if(ISNULL(Preorder_SuppliesTrxID),'N','Y') as status FROM one_preorder_dev.preorder_sample JOIN one_preorder_dev.preorder_header ON Preorder_SamplePreOrder_HeaderID = PreOrder_HeaderID AND PreOrder_HeaderIsActive = 'Y' JOIN m_patient ON PreOrder_HeaderM_PatientID = M_PatientID LEFT JOIN one_preorder_dev.preorder_suppliestrx ON Preorder_SamplePreorder_SuppliesTrxID = Preorder_SuppliesTrxID AND Preorder_SuppliesTrxIsActive = 'Y' JOIN m_staff ON PreOrder_HeaderM_StaffID = M_StaffID JOIN one_preorder_dev.preorder_test ON PreOrder_TestPreOrder_HeaderID = PreOrder_HeaderID JOIN t_test ON PreOrder_TestT_TestID = T_TestID JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID AND Preorder_SampleT_SampleTypeID = T_SampleTypeID WHERE PreOrder_HeaderM_StaffID = {$staffid} AND PreOrder_HeaderDate = '{$xdate}' AND PreOrder_HeaderFlagReceivedSupplies = 'N' AND Preorder_SampleIsActive = 'Y' GROUP BY Preorder_SampleID"; //echo $sql; $rows = $this->db_onedev->query($sql)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getdetails($id,$xdate,$status){ $rows = []; $joinheader = "LEFT JOIN one_preorder_dev.preorder_suppliestrx ON Preorder_SamplePreorder_SuppliesTrxID = Preorder_SuppliesTrxID AND Preorder_SuppliesTrxID = {$id} AND Preorder_SuppliesTrxIsActive = 'Y'"; if($status == 'RCV'){ $joinheader = "JOIN one_preorder_dev.preorder_suppliestrx ON Preorder_SamplePreorder_SuppliesTrxID = Preorder_SuppliesTrxID AND Preorder_SuppliesTrxID = {$id} AND Preorder_SuppliesTrxIsActive = 'Y'"; } $sql = "SELECT Preorder_SampleID as trx_id, PreOrder_HeaderNumbering as trx_numbering, DATE_FORMAT(PreOrder_HeaderDate,'%d-%m-%Y') as trx_date, DATE_FORMAT(PreOrder_HeaderTime,'%H:%i') as trx_time, GROUP_CONCAT(DISTINCT T_TestName separator ',') as tests, T_SampleTypeName as sampletype_name, T_SampleTypeID as sampletype_id, IFNULL(Preorder_SuppliesTrxID,0) as supplies_trx_id, M_StaffName as staffname, M_PatientName as patient_name, if(ISNULL(Preorder_SuppliesTrxID),'N','Y') as status FROM one_preorder_dev.preorder_sample JOIN one_preorder_dev.preorder_header ON Preorder_SamplePreOrder_HeaderID = PreOrder_HeaderID AND PreOrder_HeaderIsActive = 'Y' JOIN m_patient ON PreOrder_HeaderM_PatientID = M_PatientID $joinheader JOIN m_staff ON PreOrder_HeaderM_StaffID = M_StaffID JOIN one_preorder_dev.preorder_test ON PreOrder_TestPreOrder_HeaderID = PreOrder_HeaderID JOIN t_test ON PreOrder_TestT_TestID = T_TestID JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID AND Preorder_SampleT_SampleTypeID = T_SampleTypeID WHERE PreOrder_HeaderDate = '{$xdate}' AND Preorder_SampleIsActive = 'Y' GROUP BY Preorder_SampleID"; //echo $sql; $rows = $this->db_onedev->query($sql)->result_array(); return $rows; } function getsupplies($id){ $rows = []; $sql = "SELECT M_SuppliesID as supplies_id, M_SuppliesName as supplies_name, Preorder_SuppliesID as trx_id, Preorder_SuppliesQty as qty, 'Y' as status FROM one_preorder_dev.preorder_supplies JOIN m_supplies ON Preorder_SuppliesM_SuppliesID = M_SuppliesID WHERE Preorder_SuppliesPreorder_SuppliesTrxID = {$id} AND Preorder_SuppliesIsActive = 'Y'"; //echo $sql; $rows = $this->db_onedev->query($sql)->result_array(); return $rows; } function getsuppliesbuffer($id){ $rows = []; $sql = "SELECT M_SuppliesID as supplies_id, M_SuppliesName as supplies_name, Preorder_SuppliesBufferID as trx_id, Preorder_SuppliesBufferQty as qty, 'Y' as status FROM one_preorder_dev.preorder_suppliesbuffer JOIN m_supplies ON Preorder_SuppliesBufferM_SuppliesID = M_SuppliesID WHERE Preorder_SuppliesBufferPreorder_SuppliesTrxID = {$id} AND Preorder_SuppliesBufferIsActive = 'Y'"; //echo $sql; $rows = $this->db_onedev->query($sql)->result_array(); return $rows; } public function search() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $search = $prm["search"]; $status = $prm["stationid"]; $startdate = $prm["startdate"]; $enddate = $prm["enddate"]; $sql_where = "WHERE Preorder_SuppliesTrxStatus = '{$status}' AND ( Preorder_SuppliesTrxDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' ) AND Preorder_SuppliesTrxIsActive = 'Y'"; //$sql_param = array(); if ($search != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " ( Preorder_SuppliesTrxNumbering like '%$search%' OR penerima.M_StaffName like '%$search%' ) "; //$sql_param[] = "%$nama%"; } $sql = " SELECT count(*) as total FROM ( SELECT Preorder_SuppliesTrxID FROM one_preorder_dev.preorder_suppliestrx JOIN m_staff penyampling ON Preorder_SuppliesTrxM_StaffID = penyampling.M_StaffID LEFT JOIN m_staff penerima ON Preorder_SuppliesTrxReceiveM_StaffID = penerima.M_StaffID $sql_where GROUP BY Preorder_SuppliesTrxID ) x "; //echo $sql; $query = $this->db_onedev->query($sql); $tot_count = 0; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_doctor count", $this->db_onedev); exit; } $sql = "SELECT one_preorder_dev.preorder_suppliestrx.*, Preorder_SuppliesTrxID as trx_id, Preorder_SuppliesTrxNumbering as trx_numbering, Preorder_SuppliesTrxDate as trx_date, DATE_FORMAT(Preorder_SuppliesTrxDate ,'%d-%m-%Y') as trx_date_ina, Preorder_SuppliesTrxNote as trx_note, Preorder_SuppliesTrxStatus as status, penyampling.M_StaffName as penyampling_name, IFNULL(penerima.M_StaffName,'-') as penerima_name, '' as details, '' as supplies, '' as buffers, '' as staffs, CASE WHEN Preorder_SuppliesTrxStatus = 'NEW' THEN 'BARU' WHEN Preorder_SuppliesTrxStatus = 'RCV' THEN 'DITERIMA PETUGAS' END as status_name FROM one_preorder_dev.preorder_suppliestrx JOIN m_staff penyampling ON Preorder_SuppliesTrxM_StaffID = penyampling.M_StaffID LEFT JOIN m_staff penerima ON Preorder_SuppliesTrxReceiveM_StaffID = penerima.M_StaffID $sql_where GROUP BY Preorder_SuppliesTrxID ORDER BY Preorder_SuppliesTrxID DESC limit 0,20"; //echo $sql; $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); $rows = $query->result_array(); if($rows){ foreach($rows as $k => $v){ $rows[$k]['details'] = $this->getdetails($v['trx_id'],$v['trx_date'],$v['status']); $rows[$k]['supplies'] = $this->getsupplies($v['trx_id']); $rows[$k]['buffers'] = $this->getsuppliesbuffer($v['trx_id']); $rows[$k]['staffs'] = array(array('id'=>$v['Preorder_SuppliesTrxM_StaffID'],'name'=>$v['penyampling_name'])); } } $result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query()); $this->sys_ok($result); exit; } function getordersamples(){ $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $doctorid = $prm['doctorid']; $doctoraddressid = $prm['doctoraddressid']; $sql = "SELECT 0 as idx, M_SexName, CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname, T_SampleTypeName as samplename, T_OrderHeaderLabNumber as labnumber, T_OrderHeaderID as orderid, T_SampleTypeID as sampleid, 'Y' as active, 'N' as flag_image FROM t_samplingso JOIN t_orderheader ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID JOIN t_sampletype ON T_SamplingSoT_SampleTypeID = T_SampleTypeID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID JOIN m_title ON M_PatientM_TitleID = M_TitleID JOIN m_sex ON M_PatientM_SexID = M_SexID WHERE T_SamplingSoM_DoctorID = {$doctorid} AND T_SamplingSoM_DoctorAddressID = {$doctoraddressid} AND T_SamplingSoFlagWL = 'N' AND T_SamplingSoIsActive = 'Y'"; //echo $sql; $rows = $this->db_onedev->query($sql)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getstation(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT T_SampleStationID as id, T_SampleStationName as name FROM t_samplestation WHERE T_SampleStationIsActive = 'Y' "; //echo $query; $rows['stations'] = $this->db_onedev->query($query)->result_array(); //print_r($statuses); foreach($statuses as $k=>$v){ array_push($rows['statuses'],$v); } $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getdoctoraddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT M_DoctorAddressID as id, M_DoctorAddressDescription as name FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = {$prm['id']} AND M_DoctorAddressIsActive = 'Y' "; //echo $query; $rows = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function save(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $xdate = date('Y-m-d',strtotime($prm["trx_date"])); if($prm['trx_id'] == '0' || $prm['trx_id'] == 0){ $numbering = $this->db_onedev->query("SELECT one_preorder_dev.fn_numbering('SS') as numbering")->row()->numbering; $query ="INSERT INTO one_preorder_dev.preorder_suppliestrx ( Preorder_SuppliesTrxNumbering, Preorder_SuppliesTrxDate, Preorder_SuppliesTrxNote, Preorder_SuppliesTrxM_StaffID, Preorder_SuppliesTrxCreated, Preorder_SuppliesTrxLastUpdated, Preorder_SuppliesTrxUserID ) VALUES( '{$numbering}', '{$xdate}', '{$prm['trx_note']}', '{$prm['staff']['id']}', NOW(), NOW(), '{$userid}' ) "; //echo $query; $saveheader = $this->db_onedev->query($query); $last_id = $this->db_onedev->insert_id(); }else{ $numbering = $this->db_onedev->query("SELECT Preorder_SuppliesTrxNumbering as numbering FROM one_preorder_dev.preorder_suppliestrx WHERE Preorder_SuppliesTrxID = {$prm['trx_id']}")->row()->numbering; $query ="UPDATE one_preorder_dev.preorder_suppliestrx SET Preorder_SuppliesTrxNote = '{$prm['trx_note']}', Preorder_SuppliesTrxLastUpdated = NOW(), Preorder_SuppliesTrxUserID = '{$userid}' WHERE Preorder_SuppliesTrxID = {$prm['trx_id']} "; //echo $query; $saveheader = $this->db_onedev->query($query); $last_id = $prm['trx_id']; } if($saveheader){ if($prm['details']){ foreach($prm['details'] as $k => $v){ if($v['status'] === 'Y'){ $query ="UPDATE one_preorder_dev.preorder_sample SET Preorder_SamplePreorder_SuppliesTrxID = {$last_id}, Preorder_SampleLastUpdated = NOW(), Preorder_SampleUserID = '{$userid}' WHERE Preorder_SampleID = {$v['trx_id']} "; //echo $query; $savedetail = $this->db_onedev->query($query); } if($v['status'] === 'N'){ $query ="UPDATE one_preorder_dev.preorder_sample SET Preorder_SamplePreorder_SuppliesTrxID = 0, Preorder_SampleLastUpdated = NOW(), Preorder_SampleUserID = '{$userid}' WHERE Preorder_SampleID = {$v['trx_id']} "; //echo $query; $savedetail = $this->db_onedev->query($query); } } } if($prm['supplies']){ foreach($prm['supplies'] as $k => $v){ if($v['status'] === 'Y' && ( $v['trx_id'] == 0 || $v['trx_id'] == '0')){ $query ="INSERT INTO one_preorder_dev.preorder_supplies ( Preorder_SuppliesPreorder_SuppliesTrxID, Preorder_SuppliesM_SuppliesID, Preorder_SuppliesQty, Preorder_SuppliesUserID, Preorder_SuppliesCreated, Preorder_SuppliesLastUpdated ) VALUES( {$last_id}, {$v['supplies_id']}, {$v['qty']}, {$userid}, NOW(), NOW() )"; //echo $query; $savesupplies = $this->db_onedev->query($query); } if($v['status'] === 'Y' && ( $v['trx_id'] != 0 || $v['trx_id'] != '0')){ $query ="UPDATE one_preorder_dev.preorder_supplies SET Preorder_SuppliesQty = {$v['qty']}, Preorder_SuppliesLastUpdated = NOW(), Preorder_SuppliesUserID = '{$userid}' WHERE Preorder_SuppliesID = {$v['trx_id']} "; //echo $query; $savesupplies = $this->db_onedev->query($query); } if($v['status'] === 'N' && ( $v['trx_id'] != 0 || $v['trx_id'] != '0')){ $query ="UPDATE one_preorder_dev.preorder_supplies SET Preorder_SuppliesIsActive = 'N', Preorder_SuppliesLastUpdated = NOW(), Preorder_SuppliesUserID = '{$userid}' WHERE Preorder_SuppliesID = {$v['trx_id']} "; //echo $query; $savesupplies = $this->db_onedev->query($query); } } } if($prm['buffers']){ foreach($prm['buffers'] as $k => $v){ if($v['status'] === 'Y' && ( $v['trx_id'] == 0 || $v['trx_id'] == '0')){ $query ="INSERT INTO one_preorder_dev.preorder_suppliesbuffer ( Preorder_SuppliesBufferPreorder_SuppliesTrxID, Preorder_SuppliesBufferM_SuppliesID, Preorder_SuppliesBufferQty, Preorder_SuppliesBufferUserID, Preorder_SuppliesBufferCreated, Preorder_SuppliesBufferLastUpdated ) VALUES( {$last_id}, {$v['supplies_id']}, {$v['qty']}, {$userid}, NOW(), NOW() )"; //echo $query; $savebuffers = $this->db_onedev->query($query); } if($v['status'] === 'Y' && ( $v['trx_id'] != 0 || $v['trx_id'] != '0')){ $query ="UPDATE one_preorder_dev.preorder_suppliesbuffer SET Preorder_SuppliesBufferQty = {$v['qty']}, Preorder_SuppliesBufferLastUpdated = NOW(), Preorder_SuppliesBufferUserID = '{$userid}' WHERE Preorder_SuppliesBufferID = {$v['trx_id']} "; //echo $query; $savebuffers = $this->db_onedev->query($query); } if($v['status'] === 'N' && ( $v['trx_id'] != 0 || $v['trx_id'] != '0')){ $query ="UPDATE one_preorder_dev.preorder_suppliesbuffer SET Preorder_SuppliesBufferIsActive = 'N', Preorder_SuppliesBufferLastUpdated = NOW(), Preorder_SuppliesBufferUserID = '{$userid}' WHERE Preorder_SuppliesBufferID = {$v['trx_id']} "; //echo $query; $savebuffers = $this->db_onedev->query($query); } } } } $result = array( "total" => 1 , "records" => array('status'=>'OK'), "numbering" => $numbering, "id" => $last_id ); $this->sys_ok($result); exit; } function deletetrx(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $query ="UPDATE one_preorder_dev.preorder_suppliestrx SET Preorder_SuppliesTrxIsActive = 'N', Preorder_SuppliesTrxUserID = '{$userid}' WHERE Preorder_SuppliesTrxID = {$prm['trx_id']} "; //echo $query; $saveheader = $this->db_onedev->query($query); $last_id = $prm['trx_id']; $result = array( "total" => 1 , "records" => array('status'=>'OK'), "numbering" => $prm['trx_numbering'], "id" => $prm['trx_id'] ); $this->sys_ok($result); exit; } function doaction(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; if($prm['act'] == 'RELEASEC' || $prm['act'] === 'RCVDOC' ){ $sql = "UPDATE so_walklettercourier SET So_WalkLetterCourierStatus = '{$prm['act']}', So_WalkLetterCourierNote = '{$prm['trx_note']}', So_WalkLetterCourierUserID = {$userid} WHERE So_WalkLetterCourierID = {$prm['trx']['trx_id']} "; $this->db_onedev->query($sql); } if($prm['act'] === 'DONE'){ $details = $prm['details']; $count_n = 0; foreach($details as $k => $v){ if($v['flag_image_receive'] === 'N'){ $count_n++; } if($v['flag_result_receive'] === 'N'){ $count_n++; } $query ="UPDATE so_walklettercourierdetail SET So_WalkLetterCourierDetailFlagReceiveImage = '{$v['flag_image_receive']}', So_WalkLetterCourierDetailFlagReceiveResult = '{$v['flag_result_receive']}', So_WalkLetterCourierDetailUserID = '{$userid}' WHERE So_WalkLetterCourierDetailID = {$v['idx']} "; //echo $query; $savedetail = $this->db_onedev->query($query); } $status = 'DONE'; if($count_n > 0){ $status = 'PARTDONE'; } $sql = "UPDATE so_walklettercourier SET So_WalkLetterCourierStatus = '{$status}', So_WalkLetterCourierNote = '{$prm['trx_note']}', So_WalkLetterCourierUserID = {$userid} WHERE So_WalkLetterCourierID = {$prm['trx']['trx_id']} "; $this->db_onedev->query($sql); } if($prm['act'] == 'FORCEDONE'){ $sql = "UPDATE so_walklettercourier SET So_WalkLetterCourierNote = '{$prm['trx_note']}', So_WalkLetterCourierStatus = 'DONE', So_WalkLetterCourierUserID = {$userid} WHERE So_WalkLetterCourierID = {$prm['trx']['trx_id']} "; $this->db_onedev->query($sql); } $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } }