db_onedev = $this->load->database("onedev", true); } public function search() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $norm = $prm["snorm"]; $nama = str_replace("'", "\\'", $prm["name"]); // echo $norm; $sql_where = "WHERE M_PatientIsActive = 'Y' "; $sql_param = array(); if ($nama != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_PatientName like ? "; $sql_param[] = "%$nama%"; } if ($norm != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_PatientNoReg like ? "; $sql_param[] = "%$norm%"; } $limit = ''; if($all == 'N'){ $limit = ' LIMIT 100'; } $number_limit = 100; $number_offset = ($prm['current_page'] - 1) * $number_limit ; //echo $this->db_onedev->last_query(); $tot_count = 0; $tot_page = 0; $sql = "SELECT M_PatientID, M_PatientNoReg, M_PatientPrefix, M_PatientName, M_PatientSuffix, M_PatientHP, M_PatientEmail, M_PatientPOB, M_PatientPhone, M_PatientIDNumber, DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as M_PatientDOB, M_PatientNote, M_PatientNIK, M_PatientJabatan, M_PatientKedudukan, M_PatientPJ, M_PatientLocation, M_PatientJob, M_PatientM_SexID, M_SexName, M_PatientM_TitleID, M_TitleName, M_PatientM_ReligionID, M_ReligionName, M_PatientM_IdTypeID, M_IdTypeName, M_PatientIDNumber, IF(ISNULL(M_PatientSuspendID),'active','suspend' ) as status FROM m_patient LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID LEFT JOIN m_sex ON M_PatientM_SexID = M_SexID LEFT JOIN m_religion ON M_PatientM_ReligionID = M_ReligionID LEFT JOIN m_idtype ON M_PatientM_IdTypeID = M_IdTypeID LEFT JOIN m_patientsuspend ON M_PatientSuspendM_PatientID = M_PatientID AND M_PatientSuspendIsActive = 'Y' $sql_where ORDER BY M_PatientName DESC limit 100 "; // $sql; $query = $this->db_onedev->query($sql, $sql_param); $rows = $query->result_array(); if($rows){ foreach($rows as $k => $v){ $rows[$k]['M_PatientName'] = stripslashes($rows[$k]['M_PatientName']); $rows[$k]['M_PatientPOB'] = stripslashes($rows[$k]['M_PatientPOB']); //$rows[$k]['verification_px'] = $this->add_verification_test($v['M_PatientID']); } } //$this->_add_address($rows); $result = array("total" => 1, "records" => $rows, "sql"=> $this->db_onedev->last_query()); $this->sys_ok($result); exit; } function getsexreg(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT * FROM m_title WHERE M_TitleIsActive = 'Y' "; //echo $query; $rows['titles'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT * FROM m_sex WHERE M_SexIsActive = 'Y' "; //echo $query; $rows['sexes'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT * FROM m_religion WHERE M_ReligionIsActive = 'Y' "; //echo $query; $rows['religions'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT * FROM m_idtype WHERE M_IdTypeIsActive = 'Y' "; //echo $query; $rows['kartuidentitass'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function searchcity(){ 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 m_city WHERE M_CityName like ? AND M_CityIsActive = '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("m_city count",$this->db_onedev); exit; } $sql = " SELECT * FROM m_city WHERE M_CityName like ? AND M_CityIsActive = 'Y' ORDER BY M_CityName DESC "; $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("m_city rows",$this->db_onedev); exit; } } function getdistrict(){ $prm = $this->sys_input; $query =" SELECT * FROM m_district WHERE M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array($prm['id']))->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getkelurahan(){ $prm = $this->sys_input; $query =" SELECT * FROM m_kelurahan WHERE M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array($prm['id']))->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function search_country(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $search = $prm['search']; if($search == ''){ $search = 'Indonesia'; } $sql = "SELECT * FROM terminology WHERE attribute_path = 'Address.country' AND display LIKE '%$search%' ORDER BY display ASC LIMIT 20 "; $qry = $this->db_onedev->query($sql); $rows = $qry->result_array(); $result = array( "records" => $rows, "sql" => $this->db_onedev->last_query() ); $this->sys_ok($result); exit; } function searchregion(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $search = $prm['search']; $sql = "SELECT r.regional_cd, r.regional_cd AS id, r.regional_nm, r.full_name AS text_nm, r.pro_cd, IFNULL(pro.regional_nm,'') AS pro_nm, r.kab_cd, IFNULL(kab.regional_nm,'') AS kab_nm, r.kec_cd, IFNULL(kec.regional_nm,'') AS kec_nm, r.kel_cd, IFNULL(kel.regional_nm,'') AS kel_nm, r.status_cd, r.old_nm FROM regional r LEFT JOIN regional pro ON CONCAT(r.pro_cd, REPEAT('0', 8)) = pro.regional_cd LEFT JOIN regional kab ON CONCAT(r.pro_cd, r.kab_cd, REPEAT('0', 6)) = kab.regional_cd LEFT JOIN regional kec ON CONCAT(r.pro_cd, r.kab_cd, r.kec_cd, REPEAT('0', 3)) = kec.regional_cd LEFT JOIN regional kel ON CONCAT(r.pro_cd, r.kab_cd, r.kec_cd, r.kel_cd) = kel.regional_cd WHERE (MATCH(r.full_name) AGAINST('%$search%' IN BOOLEAN MODE) OR r.full_name LIKE '%$search%' OR r.regional_nm LIKE '%$search%' OR r.full_name REGEXP '$search' OR r.regional_nm REGEXP '$search' OR LOWER(r.full_name) LIKE LOWER('%$search%') OR LOWER(r.regional_nm) LIKE LOWER('%$search%')) LIMIT 100 "; $qry = $this->db_onedev->query($sql); if (!$qry) { $this->sys_error_db("search wilayah select error", $this->db_onedev); exit; } $rows = $qry->result_array(); $result = array( "records" => $rows, "sql" => $this->db_onedev->last_query() ); $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"]; $sql = "SELECT * FROM m_patient WHERE M_PatientID = {$prm['M_PatientID']}"; $rows_before = $this->db_onedev->query($sql)->row_array(); $pdob = date('Y-m-d',strtotime($prm['M_PatientDOB'])); $prm['M_PatientName'] = str_replace("'", "\\'", $prm['M_PatientName']); $prm['M_PatientPOB'] = str_replace("'", "\\'", $prm['M_PatientPOB']); $sql ="UPDATE m_patient SET M_PatientM_TitleID = ?, M_PatientPrefix = ?, M_PatientName = ?, M_PatientSuffix = ?, M_PatientDOB = ?, M_PatientM_SexID = ?, M_PatientM_ReligionID = ?, M_PatientEmail = ?, M_PatientPOB = ?, M_PatientHP = ?, M_PatientPhone = ?, M_PatientM_IdTypeID = ?, M_PatientIDNumber = ?, M_PatientNote = ?, M_PatientNIK = ?, M_PatientJabatan = ?, M_PatientKedudukan = ?, M_PatientPJ = ?, M_PatientLocation = ?, M_PatientJob = ?, M_PatientUserID = ?, M_PatientLastUpdatedUserID = ?, M_PatientLastUpdated = NOW() WHERE M_PatientID = ? "; //echo $query; $query = $this->db_onedev->query($sql, array( $prm['M_PatientM_TitleID'], $prm['M_PatientPrefix'], $prm['M_PatientName'], $prm['M_PatientSuffix'], $pdob, $prm['M_PatientM_SexID'], $prm['M_PatientM_ReligionID'], $prm['M_PatientEmail'], $prm['M_PatientPOB'], $prm['M_PatientHP'], $prm['M_PatientPhone'], $prm['M_PatientM_IdTypeID'], $prm['M_PatientIDNumber'], $prm['M_PatientNote'], $prm['M_PatientNIK'], $prm['M_PatientJabatan'], $prm['M_PatientKedudukan'], $prm['M_PatientPJ'], $prm['M_PatientLocation'], $prm['M_PatientJob'], $userid, $userid, $prm['M_PatientID'] )); if(!$query){ echo $this->db_onedev->last_query(); $this->sys_error_db("save patient error", $this->db_onedev); exit; } $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function newpatient(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $pdob = date('Y-m-d',strtotime($prm['M_PatientDOB'])); $prm['M_PatientName'] = str_replace("'", "\\'", $prm['M_PatientName']); $query ="INSERT INTO m_patient ( M_PatientM_TitleID, M_PatientPrefix, M_PatientName, M_PatientSuffix, M_PatientDOB, M_PatientM_SexID, M_PatientM_ReligionID, M_PatientEmail, M_PatientPOB, M_PatientHP, M_PatientPhone, M_PatientM_IdTypeID, M_PatientIDNumber, M_PatientNote, M_PatientNIK, M_PatientJabatan, M_PatientKedudukan, M_PatientPJ, M_PatientLocation, M_PatientJob, M_PatientUserID, M_PatientCreatedUserID, M_PatientCreated ) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,NOW() ) "; //echo $query; $rows = $this->db_onedev->query($query,array( $prm['M_PatientM_TitleID'], $prm['M_PatientPrefix'], $prm['M_PatientName'], $prm['M_PatientSuffix'], $pdob, $prm['M_PatientM_SexID'], $prm['M_PatientM_ReligionID'], $prm['M_PatientEmail'], $prm['M_PatientPOB'], $prm['M_PatientHP'], $prm['M_PatientPhone'], $prm['M_PatientM_IdTypeID'], $prm['M_PatientIDNumber'], $prm['M_PatientNote'], $prm['M_PatientNIK'], $prm['M_PatientJabatan'], $prm['M_PatientKedudukan'], $prm['M_PatientPJ'], $prm['M_PatientLocation'], $prm['M_PatientJob'], $userid, $userid )); $rows = $this->db_onedev->query($query); $last_id = $this->db_onedev->insert_id(); $result = array( "total" => 1 , "records" => array('status'=>'OK'), "id" => $last_id ); $this->sys_ok($result); exit; } function deletepatient(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $query ="UPDATE m_patient SET M_PatientIsActive = 'N', M_PatientUserID = {$userid} WHERE M_PatientID = '{$prm['M_PatientID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function getaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT m_patientaddress.*, M_PatientAddressRegionalCd, M_PatientAddressState, M_PatientAddressCity, M_PatientAddressDistrict, M_PatientAddressVillage, '' as action FROM m_patientaddress WHERE M_PatientAddressIsActive = 'Y' AND M_PatientAddressM_PatientID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array($prm['id']))->result_array(); if($rows){ foreach($rows as $k => $v){ $rows[$k]['M_PatientAddressDescription'] = stripslashes($v['M_PatientAddressDescription']); $rows[$k]['action'] = 'delete'; $rows[$k]['action'] .= 'edit'; } } $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function savenewaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $count_addrs = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_patientaddress WHERE M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}' AND M_PatientAddressIsActive = 'Y'")->row()->countx; if($count_addrs == 0){ $prm['M_PatientAddressNote'] = 'Utama'; } else{ $count_addrs_utama = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_patientaddress WHERE M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}' AND M_PatientAddressNote = 'Utama' AND M_PatientAddressIsActive = 'Y'")->row()->countx; if($count_addrs_utama > 0 && strtolower($prm['M_PatientAddressNote']) == 'utama'){ $rx = date('YmdHis'); $prm['M_PatientAddressNote'] = 'Utama_'.$rx; } } $prm['M_PatientAddressDescription'] = str_replace("'", "\\'", $prm['M_PatientAddressDescription']); $sql ="INSERT INTO m_patientaddress ( M_PatientAddressM_PatientID, M_PatientAddressNote, M_PatientAddressDescription, M_PatientAddressRegionalCd, M_PatientAddressState, M_PatientAddressCity, M_PatientAddressDistrict, M_PatientAddressVillage, M_PatientAddressCreated, M_PatientAddressUserID, M_PatientAddressCreatedUserID ) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ? ) "; //echo $query; $query = $this->db_onedev->query($sql,array( $prm['M_PatientAddressM_PatientID'], $prm['M_PatientAddressNote'], $prm['M_PatientAddressDescription'], $prm['region']['id'], $prm['region']['pro_nm'], $prm['region']['kab_nm'], $prm['region']['kec_nm'], $prm['region']['kel_nm'], $userid, $userid )); //echo $this->db_onedev->last_query(); if(!$query){ $this->sys_error_db("save new address error", $this->db_onedev); exit; } $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function saveeditaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $prm['M_PatientAddressDescription'] = str_replace("'", "\\'", $prm['M_PatientAddressDescription']); $sql = "SELECT * FROM m_patientaddress WHERE M_PatientAddressID = {$prm['M_PatientAddressID']}"; $rows_before = $this->db_onedev->query($sql)->row_array(); $query ="UPDATE m_patientaddress SET M_PatientAddressM_PatientID = ?, M_PatientAddressNote = ?, M_PatientAddressDescription = ?, M_PatientAddressRegionalCd = ?, M_PatientAddressState = ?, M_PatientAddressCity = ?, M_PatientAddressDistrict = ?, M_PatientAddressVillage = ?, M_PatientAddressUpdated = NOW(), M_PatientAddressUpdatedUserID = ?, M_PatientAddressUserID = ? WHERE M_PatientAddressID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array( $prm['M_PatientAddressM_PatientID'], $prm['M_PatientAddressNote'], $prm['M_PatientAddressDescription'], $prm['region']['id'], $prm['region']['pro_nm'], $prm['region']['kab_nm'], $prm['region']['kec_nm'], $prm['region']['kel_nm'], $userid, $userid, $prm['M_PatientAddressID'] )); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function deleteaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $query ="UPDATE m_patientaddress SET M_PatientAddressIsActive = 'N', M_PatientAddressUserID = ?, M_PatientAddressDeletedUserID = ?, M_PatientAddressDeleted = NOW() WHERE M_PatientAddressID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array( $userid, $userid, $prm['M_PatientAddressID'] )); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); } }