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_DoctorName,' ',M_DoctorSufix) as name FROM m_doctorso JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID WHERE M_DoctorSOIsActive = 'Y'"; //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_walkletterresultdetail.*, M_SexName, CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname, T_SampleTypeName as samplename, T_OrderHeaderLabNumber as labnumber, 'Y' as active, So_WalkLetterResultDetailFlagResult as flag_result, So_WalkLetterResultDetailFlagReceiveResult as flag_result_receive, So_WalkLetterResultDetailID as idx, T_OrderHeaderID as orderid, T_SampleTypeID as sampleid FROM so_walkletterresultdetail JOIN t_orderheader ON So_WalkLetterresultDetailT_OrderHeaderID = T_OrderHeaderID JOIN t_sampletype ON So_WalkLetterresultDetailT_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_WalkLetterresultDetailSo_WalkLetterresultID = {$id} AND So_WalkLetterresultDetailIsActive = '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"]; $sql_where = "WHERE So_WalkLetterresultStatus = '{$status}' AND ( So_WalkLetterresultDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' ) AND So_WalkLetterresultIsActive = 'Y'"; //$sql_param = array(); if ($search != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " ( So_WalkLetterresultNumbering like '%$search%' ) "; //$sql_param[] = "%$nama%"; } if(!isset($prm['current_page'])) $prm['current_page'] = 1; $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = " SELECT count(*) as total FROM so_walkletterresult JOIN m_doctor ON So_WalkLetterresultM_DoctorID = M_DoctorID JOIN m_doctoraddress ON So_WalkLetterresultM_DoctorAddressID = M_DoctorAddressID LEFT JOIN m_staff ON So_WalkLetterresultM_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_walkletterresult.*, IFNULL(M_StaffName,'-') as courier_name, So_WalkLetterresultID as trx_id, So_WalkLetterresultNumbering as trx_numbering, So_WalkLetterresultDate as trx_date, DATE_FORMAT(So_WalkLetterresultDate,'%d-%m-%Y') as trx_date_ina, So_WalkLetterresultNote as trx_note, So_WalkLetterresultStatus as status, CONCAT(M_DoctorPrefix,' ',M_DoctorName,' ',M_DoctorSufix) as doctor_fullname, M_DoctorAddressDescription as doctor_address, '' as doctoraddress, '' as details, CASE WHEN So_WalkLetterresultStatus = 'CREATED' THEN 'BARU' WHEN So_WalkLetterresultStatus = 'RELEASEC' THEN 'DISERAHKAN KURIR' WHEN So_WalkLetterresultStatus = 'RCVDOC' THEN 'DITERIMA DOKTER' WHEN So_WalkLetterresultStatus = 'PARTDONE' THEN 'SELESAI SEBAGIAN' ELSE 'SELESAI' END as status_name FROM so_walkletterresult JOIN m_doctor ON So_WalkLetterResultM_DoctorID = M_DoctorID JOIN m_doctoraddress ON So_WalkLetterresultM_DoctorAddressID = M_DoctorAddressID LEFT JOIN m_staff ON So_WalkLetterresultM_StaffID = M_StaffID $sql_where ORDER BY So_WalkLetterresultID 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_WalkLetterResultM_DoctorID']); $rows[$k]['details'] = $this->getdetails($v['So_WalkLetterResultID']); } } //$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_result 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 = 'Y' 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('WLR') as numbering")->row()->numbering; $query ="INSERT INTO so_walkletterresult ( So_WalkLetterresultNumbering, So_WalkLetterresultDate, So_WalkLetterresultNote, So_WalkLetterresultM_StaffID, So_WalkLetterresultM_DoctorID, So_WalkLetterresultM_DoctorAddressID, So_WalkLetterresultCreated, So_WalkLetterresultUserID ) 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_WalkLetterresultNumbering as numbering FROM so_walkletterresult WHERE So_WalkLetterresultID = {$prm['trx_id']}")->row()->numbering; $query ="UPDATE so_walkletterresult SET So_WalkLetterresultDate = '{$xdate}', So_WalkLetterresultNote = '{$prm['trx_note']}', So_WalkLetterresultM_StaffID = '{$prm['result']['id']}', So_WalkLetterresultM_DoctorID = '{$prm['doctor']['id']}', So_WalkLetterresultM_DoctorAddressID = '{$prm['doctoraddress']['id']}', So_WalkLetterresultCreated = NOW(), So_WalkLetterresultUserID = '{$userid}' WHERE So_WalkLetterresultID = {$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_walkletterresultdetail ( So_WalkLetterresultDetailSo_WalkLetterresultID, So_WalkLetterresultDetailT_OrderHeaderID, So_WalkLetterresultDetailT_SampleTypeID, So_WalkLetterresultDetailFlagResult, So_WalkLetterresultDetailCreated, So_WalkLetterresultDetailUserID ) VALUES( '{$last_id}', '{$v['orderid']}', '{$v['sampleid']}', '{$v['flag_result']}', NOW(), '{$userid}' )"; //echo $query; $savedetail = $this->db_onedev->query($query); } if($v['active'] === 'Y' && ($v['idx'] != 0 || $v['idx'] != '0')){ $query ="UPDATE so_walkletterresultdetail SET So_WalkLetterresultDetailSo_WalkLetterresultID = '{$last_id}', So_WalkLetterresultDetailT_OrderHeaderID = '{$v['orderid']}', So_WalkLetterresultDetailT_SampleTypeID = '{$v['sampleid']}', So_WalkLetterresultDetailFlagResult = '{$v['flag_result']}', So_WalkLetterresultDetailUserID = '{$userid}' WHERE So_WalkLetterresultDetailID = {$v['idx']} "; //echo $query; $savedetail = $this->db_onedev->query($query); } if($v['active'] === 'N' && $v['idx'] != 0){ $query ="UPDATE so_walkletterresultdetail SET So_WalkLetterresultDetailIsActive = 'N', So_WalkLetterresultDetailUserID = '{$userid}' WHERE So_WalkLetterresultDetailID = {$v['idx']} "; //echo $query; $savedetail = $this->db_onedev->query($query); } } } //$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( 'RESULT', NOW(), '{$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_walkletterresult SET So_WalkLetterresultIsActive = 'N', So_WalkLetterresultUserID = '{$userid}' WHERE So_WalkLetterresultID = {$prm['trx_id']} "; //echo $query; $saveheader = $this->db_onedev->query($query); $last_id = $prm['trx_id']; //$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( 'RESULT', NOW(), '{$data_log}', {$userid} )"; //echo $sql; $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_walkletterresult SET So_WalkLetterresultStatus = '{$prm['act']}', So_WalkLetterresultNote = '{$prm['trx_note']}', So_WalkLetterresultUserID = {$userid} WHERE So_WalkLetterresultID = {$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_result_receive'] === 'N'){ $count_n++; } if($v['flag_result_receive'] === 'N'){ $count_n++; } $query ="UPDATE so_walkletterresultdetail SET So_WalkLetterresultDetailFlagReceiveResult = '{$v['flag_result_receive']}', So_WalkLetterresultDetailUserID = '{$userid}' WHERE So_WalkLetterresultDetailID = {$v['idx']} "; //echo $query; $savedetail = $this->db_onedev->query($query); } $status = 'DONE'; if($count_n > 0){ $status = 'PARTDONE'; } $sql = "UPDATE so_walkletterresult SET So_WalkLetterresultStatus = '{$status}', So_WalkLetterresultNote = '{$prm['trx_note']}', So_WalkLetterresultUserID = {$userid} WHERE So_WalkLetterresultID = {$prm['trx']['trx_id']} "; $this->db_onedev->query($sql); } if($prm['act'] == 'FORCEDONE'){ $sql = "UPDATE so_walkletterresult SET So_WalkLetterresultNote = '{$prm['trx_note']}', So_WalkLetterresultStatus = 'DONE', So_WalkLetterresultUserID = {$userid} WHERE So_WalkLetterresultID = {$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( 'RESULT', NOW(), '{$data_log}', {$userid} )"; //echo $sql; $this->db_onedev->query($sql); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } }