db_onedev = $this->load->database("onedev", true); $this->load->helper(array('form', 'url')); } function getphotos($orderid,$sampletypeid){ $rows = []; //print_r($_SERVER); $urlbase = 'http://'.$_SERVER['SERVER_NAME']."/one-media/one-image-nonlab/"; $sql = "SELECT So_ImageUploadID as id, So_ImageUploadOldName as oldname, CONCAT('{$urlbase}',So_ImageUploadNewName) as newname FROM so_imageupload WHERE So_ImageUploadT_OrderHeaderID = {$orderid} AND So_ImageUploadT_SampleTypeID = {$sampletypeid} AND So_ImageUploadIsActive = 'Y'"; //echo $sql; $rows = $this->db_onedev->query($sql)->result_array(); return $rows; } function getdoctorcouriers(){ $rows = []; $sql = "SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,'...') as name FROM m_doctorso JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID JOIN t_samplingso ON T_SamplingSoM_DoctorID = M_DoctorID AND T_SamplingSoFlagDoctorInOffice = 'N' AND T_SamplingSoFlagWL = 'N' AND T_SamplingSoIsDone = 'N' WHERE M_DoctorSOIsActive = 'Y' GROUP BY M_DoctorID"; //echo $sql; $rows['doctors'] = $this->db_onedev->query($sql)->result_array(); $sql = "SELECT M_StaffID as id, M_StaffName as name FROM m_courier JOIN m_staff ON M_StaffID = M_CourierM_StaffID WHERE M_CourierIsActive = 'Y'"; //echo $sql; $rows['couriers'] = $this->db_onedev->query($sql)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getsetdoctoraddress($doctorid){ $rows = []; $sql = "SELECT M_DoctorAddressID as id, M_DoctorAddressDescription as name FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = {$doctorid} AND M_DoctorAddressIsActive = 'Y'"; //echo $sql; $rows = $this->db_onedev->query($sql)->result_array(); return $rows; } function getdetails($id){ $rows = []; $sql = "SELECT so_walklettercourierdetail.*, M_SexName, CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname, T_SampleTypeName as samplename, T_OrderHeaderLabNumber as labnumber, 'Y' as active, So_WalkLetterCourierDetailFlagImage as flag_image, So_WalkLetterCourierDetailFlagReceiveImage as flag_image_receive, So_WalkLetterCourierDetailFlagReceiveResult as flag_result_receive, So_WalkLetterCourierDetailID as idx, T_OrderHeaderID as orderid, T_SampleTypeID as sampleid FROM so_walklettercourierdetail JOIN t_orderheader ON So_WalkLetterCourierDetailT_OrderHeaderID = T_OrderHeaderID JOIN t_sampletype ON So_WalkLetterCourierDetailT_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 So_WalkLetterCourierDetailSo_WalkLetterCourierID = {$id} AND So_WalkLetterCourierDetailIsActive = '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["namelab"]; $status = $prm["stationid"]; $startdate = $prm["startdate"]; $enddate = $prm["enddate"]; if(!isset($prm['current_page'])) $prm['current_page'] = 1; $sql_where = "WHERE So_WalkLetterCourierStatus = '{$status}' AND ( So_WalkLetterCourierDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' ) AND So_WalkLetterCourierIsActive = 'Y'"; //$sql_param = array(); if ($search != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " ( So_WalkLetterCourierNumbering like '%$search%' ) "; //$sql_param[] = "%$nama%"; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = " SELECT count(*) as total FROM so_walklettercourier JOIN m_doctor ON So_WalkLetterCourierM_DoctorID = M_DoctorID JOIN m_doctoraddress ON So_WalkLetterCourierM_DoctorAddressID = M_DoctorAddressID LEFT JOIN m_staff ON So_WalkLetterCourierM_StaffID = M_StaffID $sql_where "; //echo $sql; $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("m_doctor count", $this->db_onedev); exit; } $sql = "SELECT so_walklettercourier.*, IFNULL(M_StaffName,'-') as courier_name, So_WalkLetterCourierID as trx_id, So_WalkLetterCourierNumbering as trx_numbering, So_WalkLetterCourierDate as trx_date, DATE_FORMAT(So_WalkLetterCourierDate,'%d-%m-%Y') as trx_date_ina, So_WalkLetterCourierNote as trx_note, So_WalkLetterCourierStatus as status, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,'...') as doctor_fullname, M_DoctorAddressDescription as doctor_address, '' as doctoraddress, '' as details, CASE WHEN So_WalkLetterCourierStatus = 'CREATED' THEN 'BARU' WHEN So_WalkLetterCourierStatus = 'RELEASEC' THEN 'DISERAHKAN KURIR' WHEN So_WalkLetterCourierStatus = 'RCVDOC' THEN 'DITERIMA DOKTER' WHEN So_WalkLetterCourierStatus = 'PARTDONE' THEN 'SELESAI SEBAGIAN' ELSE 'SELESAI' END as status_name FROM so_walklettercourier JOIN m_doctor ON So_WalkLetterCourierM_DoctorID = M_DoctorID JOIN m_doctoraddress ON So_WalkLetterCourierM_DoctorAddressID = M_DoctorAddressID LEFT JOIN m_staff ON So_WalkLetterCourierM_StaffID = M_StaffID $sql_where ORDER BY So_WalkLetterCourierID DESC limit $number_limit offset $number_offset"; //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]['doctors'] = $this->getdoctors(); $rows[$k]['doctoraddress'] = $this->getsetdoctoraddress($v['So_WalkLetterCourierM_DoctorID']); $rows[$k]['details'] = $this->getdetails($v['So_WalkLetterCourierID']); } } //$this->_add_address($rows); $result = array("total" => $tot_page, "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 fn_numbering('WLI') as numbering")->row()->numbering; $query ="INSERT INTO so_walklettercourier ( So_WalkLetterCourierNumbering, So_WalkLetterCourierDate, So_WalkLetterCourierNote, So_WalkLetterCourierM_StaffID, So_WalkLetterCourierM_DoctorID, So_WalkLetterCourierM_DoctorAddressID, So_WalkLetterCourierCreated, So_WalkLetterCourierUserID ) VALUES( '{$numbering}', '{$xdate}', '{$prm['trx_note']}', '{$prm['courier']['id']}', '{$prm['doctor']['id']}', '{$prm['doctoraddress']['id']}', NOW(), '{$userid}' ) "; //echo $query; $saveheader = $this->db_onedev->query($query); $last_id = $this->db_onedev->insert_id(); }else{ $numbering = $this->db_onedev->query("SELECT So_WalkLetterCourierNumbering as numbering FROM so_walklettercourier WHERE So_WalkLetterCourierID = {$prm['trx_id']}")->row()->numbering; $query ="UPDATE so_walklettercourier SET So_WalkLetterCourierDate = '{$xdate}', So_WalkLetterCourierNote = '{$prm['trx_note']}', So_WalkLetterCourierM_StaffID = '{$prm['courier']['id']}', So_WalkLetterCourierM_DoctorID = '{$prm['doctor']['id']}', So_WalkLetterCourierM_DoctorAddressID = '{$prm['doctoraddress']['id']}', So_WalkLetterCourierLastUpdated = NOW(), So_WalkLetterCourierUserID = '{$userid}' WHERE So_WalkLetterCourierID = {$prm['trx_id']} "; //echo $query; $saveheader = $this->db_onedev->query($query); $last_id = $prm['trx_id']; } if($saveheader){ foreach($prm['details'] as $k => $v){ if($v['active'] === 'Y' && ($v['idx'] == 0 || $v['idx'] == '0')){ $query ="INSERT INTO so_walklettercourierdetail ( So_WalkLetterCourierDetailSo_WalkLetterCourierID, So_WalkLetterCourierDetailT_OrderHeaderID, So_WalkLetterCourierDetailT_SampleTypeID, So_WalkLetterCourierDetailFlagImage, So_WalkLetterCourierDetailCreated, So_WalkLetterCourierDetailUserID ) VALUES( '{$last_id}', '{$v['orderid']}', '{$v['sampleid']}', '{$v['flag_image']}', NOW(), '{$userid}' )"; //echo $query; $savedetail = $this->db_onedev->query($query); } if($v['active'] === 'Y' && ($v['idx'] != 0 || $v['idx'] != '0')){ $query ="UPDATE so_walklettercourierdetail SET So_WalkLetterCourierDetailSo_WalkLetterCourierID = '{$last_id}', So_WalkLetterCourierDetailT_OrderHeaderID = '{$v['orderid']}', So_WalkLetterCourierDetailT_SampleTypeID = '{$v['sampleid']}', So_WalkLetterCourierDetailFlagImage = '{$v['flag_image']}', So_WalkLetterCourierDetailUserID = '{$userid}' WHERE So_WalkLetterCourierDetailID = {$v['idx']} "; //echo $query; $savedetail = $this->db_onedev->query($query); } if($v['active'] === 'N' && $v['idx'] != 0){ $query ="UPDATE so_walklettercourierdetail SET So_WalkLetterCourierDetailIsActive = 'N', So_WalkLetterCourierDetailUserID = '{$userid}' WHERE So_WalkLetterCourierDetailID = {$v['idx']} "; //echo $query; $savedetail = $this->db_onedev->query($query); } } } $sql = "SELECT * FROM so_walklettercourier WHERE So_WalkLetterCourierID = {$last_id}"; $data_log_header = $this->db_onedev->query($sql)->result(); $sql = "SELECT * FROM so_walklettercourierdetail WHERE So_WalkLetterCourierDetailSo_WalkLetterCourierID = {$last_id}"; $data_log_details = $this->db_onedev->query($sql)->result(); $data_log = json_encode(array('header'=>$data_log_header,'details'=>$data_log_details)); $sql = "INSERT INTO one_log.log_walkletter ( Log_WalkLetterCode, Log_WalkLetterDate, Log_WalkLetterJSON, Log_WalkLetterUserID ) VALUES( 'SAMPLE', CURDATE(), '{$data_log}', {$userid} )"; //echo $sql; $this->db_onedev->query($sql); $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 so_walklettercourier SET So_WalkLetterCourierIsActive = 'N', So_WalkLetterCourierUserID = '{$userid}' WHERE So_WalkLetterCourierID = {$prm['trx_id']} "; //echo $query; $saveheader = $this->db_onedev->query($query); $last_id = $prm['trx_id']; $sql = "SELECT * FROM so_walklettercourier WHERE So_WalkLetterCourierID = {$last_id}"; $data_log_header = $this->db_onedev->query($sql)->result(); $sql = "SELECT * FROM so_walklettercourierdetail WHERE So_WalkLetterCourierDetailSo_WalkLetterCourierID = {$last_id}"; $data_log_details = $this->db_onedev->query($sql)->result(); $data_log = json_encode(array('header'=>$data_log_header,'details'=>$data_log_details)); $sql = "INSERT INTO one_log.log_walkletter ( Log_WalkLetterCode, Log_WalkLetterDate, Log_WalkLetterJSON, Log_WalkLetterUserID ) VALUES( 'SAMPLE', CURDATE(), '{$data_log}', {$userid} )"; $this->db_onedev->query($sql); $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); } $last_id = $prm['trx']['trx_id']; $sql = "SELECT * FROM so_walklettercourier WHERE So_WalkLetterCourierID = {$last_id}"; $data_log_header = $this->db_onedev->query($sql)->result(); $sql = "SELECT * FROM so_walklettercourierdetail WHERE So_WalkLetterCourierDetailSo_WalkLetterCourierID = {$last_id}"; $data_log_details = $this->db_onedev->query($sql)->result(); $data_log = json_encode(array('header'=>$data_log_header,'details'=>$data_log_details)); $sql = "INSERT INTO one_log.log_walkletter ( Log_WalkLetterCode, Log_WalkLetterDate, Log_WalkLetterJSON, Log_WalkLetterUserID ) VALUES( 'SAMPLE', CURDATE(), '{$data_log}', {$userid} )"; //echo $sql; $this->db_onedev->query($sql); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } }