db_onedev = $this->load->database("onedev", true); $this->load->helper(array('form', 'url')); } function getdetails($id){ $rows = []; $sql = "SELECT * FROM t_testconclusion WHERE T_TestConclusionT_TestID = {$id} AND T_TestConclusionIsActive = '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"]; $sql_where = "WHERE T_TestIsResult = 'Y' AND T_TestIsActive = 'Y'"; //$sql_param = array(); if ($search != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " ( T_TestCode like '%$search%' OR T_TestName like '%$search%' ) "; } $sql = " SELECT count(*) as total FROM t_test $sql_where "; //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 t_test.*, '' as details FROM t_test $sql_where GROUP BY T_TestCode ORDER BY T_TestCode ASC limit 0,20"; //echo $sql; $query = $this->db_onedev->query($sql); $rows = $query->result_array(); if($rows){ foreach($rows as $k => $v){ $rows[$k]['details'] = $this->getdetails($v['T_TestID']); } } //$this->_add_address($rows); $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_SamplingSoVerifyFlagWL = '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 getnormalvalue(){ $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $methodeid = $prm['methodeid']; /*$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_SamplingSoVerifyFlagWL = 'N' AND T_SamplingSoIsActive = 'Y'"; //echo $sql; $rows = $this->db_onedev->query($sql)->result_array();*/ if($methodeid == 1){ $rows = array( array( 'id'=>1, 'normalvalue_description'=>' MALE [ 7th - 14th ] 0 - 51', 'mininclusive'=>'N', 'minvalue'=>'0', 'maxinclusive'=>'N', 'maxvalue'=>'0', 'active'=>'Y' ), array( 'id'=>2, 'normalvalue_description'=>' MALE [ 15th - 24th ] 20 - 60', 'mininclusive'=>'N', 'minvalue'=>'0', 'maxinclusive'=>'N', 'maxvalue'=>'0', 'active'=>'Y' ), array( 'id'=>3, 'normalvalue_description'=>' FEMALE [ 7th - 14th ] 0 - 31', 'mininclusive'=>'N', 'minvalue'=>'0', 'maxinclusive'=>'N', 'maxvalue'=>'0', 'active'=>'Y' ), array( 'id'=>4, 'normalvalue_description'=>' FEMALE [ 15th - 24th ] 10 - 60', 'mininclusive'=>'N', 'minvalue'=>'0', 'maxinclusive'=>'N', 'maxvalue'=>'0', 'active'=>'Y' ) ); } if($methodeid == 2){ $rows = array( array( 'id'=>1, 'normalvalue_description'=>' MALE [ 7th - 14th ] 10 - 31', 'mininclusive'=>'N', 'minvalue'=>'0', 'maxinclusive'=>'N', 'maxvalue'=>'0', 'active'=>'Y' ), array( 'id'=>2, 'normalvalue_description'=>' MALE [ 15th - 24th ] 20 - 40', 'mininclusive'=>'N', 'minvalue'=>'0', 'maxinclusive'=>'N', 'maxvalue'=>'0', 'active'=>'Y' ), array( 'id'=>3, 'normalvalue_description'=>' FEMALE [ 7th - 14th ] 15 - 41', 'mininclusive'=>'N', 'minvalue'=>'0', 'maxinclusive'=>'N', 'maxvalue'=>'0', 'active'=>'Y' ), array( 'id'=>4, 'normalvalue_description'=>' FEMALE [ 15th - 24th ] 30 - 60', 'mininclusive'=>'N', 'minvalue'=>'0', 'maxinclusive'=>'N', 'maxvalue'=>'0', 'active'=>'Y' ) ); } $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getgroups(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT Nat_GroupID as id, Nat_GroupName as title, CONCAT('GROUP : ',Nat_GroupName) as fulltitle, '' as childrens FROM nat_group WHERE Nat_GroupIsActive = 'Y' AND ( Nat_GroupCode = 2 OR Nat_GroupCode = 3 ) "; //echo $query; $rows['groups'] = $this->db_onedev->query($query)->result_array(); if($rows['groups']){ foreach($rows['groups'] as $k => $v){ $childrens = array(array('id'=>0, 'title'=>'Semua', 'fulltitle'=>'Subgroub : Semua')); $query =" SELECT Nat_SubGroupID as id, Nat_SubGroupName as title, CONCAT('SUBGROUP : ',Nat_SubGroupName) as fulltitle FROM nat_subgroup WHERE Nat_SubGroupNat_GroupID = {$v['id']} AND Nat_SubGroupIsActive = 'Y' "; //echo $query; $xrst = $this->db_onedev->query($query)->result_array(); if($xrst){ foreach($xrst as $ki => $vi){ array_push($childrens,$vi); } } $rows['groups'][$k]['childrens'] = $childrens ; } } $query =" SELECT M_LangID as id, M_LangName as name FROM m_lang WHERE M_LangIsActive = 'Y' "; //echo $query; $rows['langs'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getsubgroups(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $rows = array(array('id'=>0, 'title'=>'Semua', 'fulltitle'=>'Subgroub : Semua')); $query =" SELECT Nat_SubGroupID as id, Nat_SubGroupName as title, CONCAT('SUBGROUP : ',Nat_SubGroupName) as fulltitle FROM nat_subgroup WHERE Nat_SubGroupNat_GroupID = {$prm['id']} AND Nat_SubGroupIsActive = 'Y' "; //echo $query; $rst = $this->db_onedev->query($query)->result_array(); if($rst){ foreach($rst as $k => $v){ array_push($rows,$v); } } $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_WalkLetterCourierCreated = 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); } } } $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']; $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; } }