db_regional = $this->load->database("regional", true); } public function search() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $code = $prm["code"]; $nama = $prm["name"]; $date = $prm['date']; $status = $prm["status"]; $branch = $prm['branch']; $e = explode('+', $prm['name']); if (isset($e[0])) $nama = "%{$e[0]}%"; if (isset($e[1])) $alamat = "%{$e[1]}%"; if (isset($e[2])) $nohp = "%{$e[2]}%"; // echo $norm; $sql_where = ""; $sql_param = array(); if ($code != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_DoctorCode like ?"; $sql_param[] = "$code"; //$prm['current_page'] = 1; } if ($nama != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_DoctorName like ?"; $sql_param[] = "$nama"; //$prm['current_page'] = 1; } if ($alamat != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_DoctorAddressDescription like ?"; $sql_param[] = "$alamat"; //$prm['current_page'] = 1; } if ($nohp != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_DoctorHP like ?"; $sql_param[] = "$nohp"; //$prm['current_page'] = 1; } if ($sql_where != "") $sql_where .= " and "; // Order masih dalam status registrasi $sql_where .= " M_DoctorIsMarketingConfirm = '{$status}' AND M_DoctorIsActive = 'Y'"; if ($sql_where != "") { $sql_where = " where $sql_where"; } if($branch != ""){ $sql_where = "$sql_where AND left(M_DoctorOldCode,2) = '{$branch}'"; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = " SELECT count(*) as total FROM ( SELECT M_DoctorID, GROUP_CONCAT(DISTINCT CONCAT(M_DoctorAddressNote, '^',M_DoctorAddressDescription) SEPARATOR '+') as doctor_address, M_DoctorAddressDescription FROM m_doctor JOIN m_sex ON M_DoctorM_SexID = M_SexID LEFT JOIN m_religion ON M_DoctorM_ReligionID = M_ReligionID LEFT JOIN m_staff ON M_DoctorM_StaffID = M_StaffID LEFT JOIN m_doctoraddress ON M_DoctorID = M_DoctorAddressM_DoctorID AND M_DoctorAddressIsActive = 'Y' $sql_where GROUP BY M_DoctorID ) x "; $query = $this->db_regional->query($sql, $sql_param); $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_regional); exit; } // untuk total sebelum tanggal filter $sql_where2 = ""; $sql_where2 .= " M_DoctorIsMarketingConfirm = 'N' AND M_DoctorIsActive = 'Y' AND date(M_DoctorCreated) <= '{$date}'"; if ($sql_where2 != "") { $sql_where2 = " where $sql_where2"; } $sql2 = " SELECT count(*) as total FROM ( SELECT M_DoctorID, CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as doctor_address, M_DoctorAddressDescription FROM m_doctor LEFT JOIN m_doctoraddress ON M_DoctorID = M_DoctorAddressM_DoctorID AND M_DoctorAddressIsActive = 'Y' $sql_where2 GROUP BY M_DoctorID ) a "; $query2 = $this->db_regional->query($sql2); $tot_page2 = 0; if ($query2) { $tot_count2 = $query2->result_array()[0]["total"]; $tot_page2 = $tot_count2; } else { $this->sys_error_db("m_doctor count", $this->db_regional); exit; } $doctor_field = " M_DoctorID, M_DoctorOldCode, M_DoctorCode , M_DoctorPrefix , M_DoctorPrefix2 , M_DoctorName , M_DoctorSufix , M_DoctorSufix2 , M_DoctorSufix3 , M_DoctorM_SexID , M_DoctorM_ReligionID, M_DoctorM_StaffID, IFNULL(M_DoctorEmail,'') as M_DoctorEmail, M_DoctorHP , M_DoctorNote, M_DoctorPhone , M_DoctorIsMarketingConfirm, ifnull(M_DoctorPjIsPJ,'N') M_DoctorIsPJ, ifnull(M_DoctorPjIsDefaultPJ,'N') M_DoctorIsDefaultPJ , M_DoctorM_SpecialID , ifnull(M_DoctorPjIsClinic,'N') M_DoctorIsClinic , ifnull(M_DoctorPjIsDefault,'N') M_DoctorIsDefault , M_DoctorEmailIsDefault, M_DoctorIsDefaultMcu, M_DoctorCreated , M_DoctorLastUpdated, M_DoctorIsActive, M_DoctorReportCode , M_DoctorPrivateRequest, M_DoctorM_UserID , M_DoctorM_StaffNIK, M_DoctorM_SpecialistID, DATE_FORMAT(M_DoctorDOB,'%d%m%Y') M_DoctorDOB, "; $sql = "SELECT $doctor_field CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as doctor_fullname, M_SexName, M_ReligionName, Nat_StaffID, Nat_StaffNIK, IF(Nat_StaffNIK = '' OR Nat_StaffNIK IS NULL, '', Nat_StaffName) as Nat_StaffName, IF(M_DoctorM_SpecialistID = 0 OR M_DoctorM_SpecialistID IS NULL, '', M_SpecialistName) as M_SpecialistName, IF(M_DoctorIsMarketingConfirm = 'N', 'Belum dikonfirmasi marketing','Sudah dikonfirmasi marketing') as status, GROUP_CONCAT(DISTINCT CONCAT(M_DoctorAddressNote, '^',M_DoctorAddressDescription) SEPARATOR '+') as M_DoctorAddressNote, GROUP_CONCAT(DISTINCT CONCAT(M_DoctorAddressNote, '^',M_DoctorAddressDescription) SEPARATOR '+') as doctor_address, 'Belum dikonfirmasi marketing' as status, M_DoctorAddressDescription FROM m_doctor JOIN m_sex ON M_DoctorM_SexID = M_SexID left join m_doctorpj on M_DoctorID = M_DoctorPjM_DoctorID left JOIN m_religion ON M_DoctorM_ReligionID = M_ReligionID left JOIN nat_staff ON M_DoctorM_StaffNIK = Nat_StaffNIK left join m_doctoraddress ON M_DoctorID = M_DoctorAddressM_DoctorID AND M_DoctorAddressIsActive = 'Y' LEFT JOIN m_specialist ON M_DoctorM_SpecialistID = M_SpecialistID $sql_where GROUP BY M_DoctorID ORDER BY M_DoctorName ASC limit $number_limit offset $number_offset"; $query = $this->db_regional->query($sql, $sql_param); // echo $this->db_regional->last_query(); $rows = $query->result_array(); if($rows){ foreach($rows as $k => $v){ //$rows[$k]['verification_px'] = $this->add_verification_test($v['M_PatientID']); } } //$this->_add_address($rows); $result = array("total" => $tot_page,"total_filter" => $tot_page2,"records" => $rows, "sql"=> $this->db_regional->last_query()); $this->sys_ok($result); exit; } public function searchconfirm() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $code = $prm["code"]; $nama = $prm["name"]; $date = $prm['date']; $e = explode('+', $prm['name']); if (isset($e[0])) $nama = "%{$e[0]}%"; if (isset($e[1])) $alamat = "%{$e[1]}%"; if (isset($e[2])) $nohp = "%{$e[2]}%"; // echo $norm; $sql_where = ""; $sql_param = array(); if ($code != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_DoctorCode like ?"; $sql_param[] = "$code"; //$prm['current_page'] = 1; } if ($nama != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_DoctorName like ?"; $sql_param[] = "$nama"; //$prm['current_page'] = 1; } if ($alamat != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_DoctorAddressDescription like ?"; $sql_param[] = "$alamat"; //$prm['current_page'] = 1; } if ($nohp != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_DoctorHP like ?"; $sql_param[] = "$nohp"; //$prm['current_page'] = 1; } if ($sql_where != "") $sql_where .= " and "; // Order masih dalam status registrasi $sql_where .= " M_DoctorIsMarketingConfirm = 'Y' AND M_DoctorIsActive = 'Y'"; if ($sql_where != "") { $sql_where = " where $sql_where"; //$prm['current_page'] = 1; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = " SELECT count(*) as total FROM ( SELECT M_DoctorID, GROUP_CONCAT(DISTINCT CONCAT(M_DoctorAddressNote, '^',M_DoctorAddressDescription) SEPARATOR '+') as doctor_address, M_DoctorAddressDescription FROM m_doctor JOIN m_sex ON M_DoctorM_SexID = M_SexID LEFT JOIN m_religion ON M_DoctorM_ReligionID = M_ReligionID LEFT JOIN m_staff ON M_DoctorM_StaffID = M_StaffID left join m_doctoraddress ON M_DoctorID = M_DoctorAddressM_DoctorID AND M_DoctorAddressIsActive = 'Y' $sql_where GROUP BY M_DoctorID ) x "; $query = $this->db_regional->query($sql, $sql_param); $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_regional); exit; } $doctor_field = " M_DoctorID, M_DoctorOldCode, M_DoctorCode , M_DoctorPrefix , M_DoctorPrefix2 , M_DoctorName , M_DoctorSufix , M_DoctorSufix2 , M_DoctorSufix3 , M_DoctorM_SexID , M_DoctorM_ReligionID, M_DoctorM_StaffID, IFNULL(M_DoctorEmail,'') as M_DoctorEmail, M_DoctorHP , M_DoctorNote, M_DoctorPhone , M_DoctorIsMarketingConfirm, ifnull(M_DoctorPjIsPJ,'N') M_DoctorIsPJ, ifnull(M_DoctorPjIsDefaultPJ,'N') M_DoctorIsDefaultPJ , M_DoctorM_SpecialID , ifnull(M_DoctorPjIsClinic,'N') M_DoctorIsClinic , ifnull(M_DoctorPjIsDefault,'N') M_DoctorIsDefault , M_DoctorEmailIsDefault, M_DoctorIsDefaultMcu, M_DoctorCreated , M_DoctorLastUpdated, M_DoctorIsActive, M_DoctorReportCode , M_DoctorPrivateRequest, M_DoctorM_UserID , M_DoctorCreated, "; $sql = "SELECT $doctor_field CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as doctor_fullname, M_SexName, M_ReligionName, M_StaffName, GROUP_CONCAT(DISTINCT CONCAT(M_DoctorAddressNote, '^',M_DoctorAddressDescription) SEPARATOR '+') as M_DoctorAddressNote, GROUP_CONCAT(DISTINCT CONCAT(M_DoctorAddressNote, '^',M_DoctorAddressDescription) SEPARATOR '+') as doctor_address, 'Telah dikonfirmasi marketing' as status, M_DoctorAddressDescription FROM m_doctor JOIN m_sex ON M_DoctorM_SexID = M_SexID left join m_doctorpj on M_DoctorID = M_DoctorPjM_DoctorID left JOIN m_religion ON M_DoctorM_ReligionID = M_ReligionID left JOIN m_staff ON M_DoctorM_StaffID = M_StaffID left join m_doctoraddress ON M_DoctorID = M_DoctorAddressM_DoctorID AND M_DoctorAddressIsActive = 'Y' $sql_where GROUP BY M_DoctorID ORDER BY M_DoctorName ASC limit $number_limit offset $number_offset"; $query = $this->db_regional->query($sql, $sql_param); // echo $this->db_regional->last_query(); $rows = $query->result_array(); if($rows){ foreach($rows as $k => $v){ //$rows[$k]['verification_px'] = $this->add_verification_test($v['M_PatientID']); } } //$this->_add_address($rows); $result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_regional->last_query()); $this->sys_ok($result); exit; } function getsexreg(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT * FROM m_sex WHERE M_SexIsActive = 'Y' "; //echo $query; $rows['sexes'] = $this->db_regional->query($query)->result_array(); $query =" SELECT * FROM m_religion WHERE M_ReligionIsActive = 'Y' "; //echo $query; $rows['religions'] = $this->db_regional->query($query)->result_array(); $query =" SELECT 0 as M_StaffID, 'Semua' as M_StaffName UNION SELECT M_StaffID, M_StaffName FROM m_staff WHERE M_StaffIsActive = 'Y' and M_StaffM_PositionID = '2' "; //echo $query; $rows['staffs'] = $this->db_regional->query($query)->result_array(); $query =" SELECT '' as M_BranchCode, 'Semua' as M_BranchName UNION SELECT M_BranchCode, M_BranchName FROM m_branch WHERE M_BranchIsActive = 'Y' "; //echo $query; $rows['branchs'] = $this->db_regional->query($query)->result_array(); $query =" SELECT * FROM nat_jpa WHERE Nat_JpaIsActive = 'Y' "; //echo $query; $rows['jpas'] = $this->db_regional->query($query)->result_array(); $query =" SELECT M_SpecialistID as id, M_SpecialistName as name FROM m_specialist WHERE M_SpecialistIsActive = 'Y' "; // echo $query; $rows['specialistes'] = $this->db_regional->query($query)->result_array(); //print_r($rows['specialistes']); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getnewcode(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $sql = $this->db_regional->query("SELECT `fn_numbering`('DOCTOR') as code")->row(); $newcode = $sql->code; $sql = "UPDATE m_doctor SET M_DoctorIsMarketingConfirm = 'Y' ,M_DoctorCode = '{$newcode}' WHERE M_DoctorID = {$prm['M_DoctorID']}"; $this->db_regional->query($sql); $result = array( "total" => 1, "records" => array(), "newcode" => $newcode ); $this->sys_ok($result); exit; } function removecode(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $sql = "UPDATE m_doctor SET M_DoctorIsMarketingConfirm = 'N' ,M_DoctorCode = '' WHERE M_DoctorID = {$prm['M_DoctorID']}"; $this->db_regional->query($sql); $result = array( "total" => 1, "records" => array(), "newcode" => $newcode ); $this->sys_ok($result); exit; } function attachdoctor(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $sql = "UPDATE m_doctor SET M_DoctorIsMarketingConfirm = 'Y' ,M_DoctorCode = '{$prm['attacth_code']}' WHERE M_DoctorID = {$prm['M_DoctorID']}"; $this->db_regional->query($sql); $result = array( "total" => 1, "records" => array(), "newcode" => $newcode ); $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_regional->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_regional); exit; } $sql = " SELECT M_CityID as id, M_CityName as name FROM m_city WHERE M_CityName like ? AND M_CityIsActive = 'Y' ORDER BY M_CityName DESC "; $query = $this->db_regional->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_regional->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_regional); exit; } } function searchstaff(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $name = $prm['name']; $hirarkiid = intval($prm['id']) - 1; // QUERY TOTAL $sql = "SELECT count(*) as total FROM nat_staff left join m_position ON Nat_StaffM_PositionID = M_PositionID WHERE Nat_StaffIsActive = 'Y' and M_PositionIsMarketing = 'Y' AND (Nat_StaffName like '%{$name}%' OR Nat_StaffNIK like '%{$name}%')"; $query = $this->db_regional->query($sql); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("nat_staff count",$this->db_regional); exit; } $sql = " SELECT * FROM(SELECT *, CONCAT(Nat_StaffName, ' [',Nat_StaffNIK,']') as Nat_StaffNames FROM nat_staff left join m_position ON Nat_StaffM_PositionID = M_PositionID WHERE Nat_StaffIsActive = 'Y' and M_PositionIsMarketing = 'Y') a WHERE (Nat_StaffName like '%{$name}%' OR Nat_StaffNIK like '%{$name}%') AND Nat_StaffIsActive = 'Y' ORDER BY Nat_StaffName ASC "; $query = $this->db_regional->query($sql); if ($query) { $rows = $query->result_array(); //echo $this->db_regional->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("nat_staff rows",$this->db_regional); exit; } } function getdistrict(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT M_DistrictID as id, M_DistrictName as name FROM m_district WHERE M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ? "; //echo $query; $rows = $this->db_regional->query($query,array($prm['id']))->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getkelurahan(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT M_KelurahanID as id, M_KelurahanName as name FROM m_kelurahan WHERE M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ? "; //echo $query; $rows = $this->db_regional->query($query,array($prm['id']))->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getjpa(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT * FROM nat_jpa WHERE Nat_JpaIsActive = 'Y' "; //echo $query; $rows = $this->db_regional->query($query)->result_array(); // $rows['jpas'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function save_old(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; // ambil data lama $sql = "select * from m_doctor where M_DoctorID = ?"; $qry = $this->db_regional->query($sql,array($prm["id"])); $rows = $qry->result_array(); $old_doctor = array(); if (count($rows) > 0 ) $old_doctor = $rows[0]; $query ="UPDATE m_doctor SET M_DoctorOldCode = '{$prm['oldcode']}', M_DoctorCode = '{$prm['newcode']}', M_DoctorIsMarketingConfirm = 'Y' WHERE M_DoctorID = '{$prm['id']}' "; //echo $query; $rows = $this->db_regional->query($query); // ambil data baru $sql = "select * from m_doctor where M_DoctorID = ?"; $qry = $this->db_regional->query($sql,array($prm["id"])); $rows = $qry->result_array(); $new_doctor = array(); if (count($rows) > 0 ) $new_doctor = $rows[0]; $d_doctor = json_encode(array("old" => $old_doctor , "new" => $new_doctor)); $this->db_regional->query("call one_log.log_me('DOCTOR','DOCTOR_EDIT','{$d_doctor}',$userid)"); $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"]; // ambil data lama $sql = "select * from m_doctor where M_DoctorID = ?"; $qry = $this->db_regional->query($sql,array($prm["id"])); $rows = $qry->result_array(); $old_doctor = array(); if (count($rows) > 0 ) $old_doctor = $rows[0]; if($prm['M_DoctorEmail'] == ''){ $prm['M_DoctorEmailIsDefault'] = 'N'; } $x_dob = $prm['M_DoctorDOB']; $updated_dob = substr($x_dob, 0,2).'-'.substr($x_dob, 2,2).'-'.substr($x_dob, 4,4); $xxdob = date("Y-m-d", strtotime($updated_dob)); $query ="UPDATE m_doctor SET M_DoctorPrefix = '{$prm['M_DoctorPrefix']}', M_DoctorPrefix2 = '{$prm['M_DoctorPrefix2']}', M_DoctorName = '{$prm['M_DoctorName']}', M_DoctorSufix = '{$prm['M_DoctorSufix']}', M_DoctorSufix2 = '{$prm['M_DoctorSufix2']}', M_DoctorSufix3 = '{$prm['M_DoctorSufix3']}', M_DoctorM_SexID = '{$prm['M_DoctorM_SexID']}', M_DoctorM_ReligionID = '{$prm['M_DoctorM_ReligionID']}', M_DoctorM_StaffID = '{$prm['M_DoctorM_StaffID']}', M_DoctorM_StaffNIK = '{$prm['M_DoctorM_StaffNIK']}', M_DoctorEmail = '{$prm['M_DoctorEmail']}', M_DoctorHP = '{$prm['M_DoctorHP']}', M_DoctorNote = '{$prm['M_DoctorNote']}', M_DoctorPhone = '{$prm['M_DoctorPhone']}', M_DoctorEmailIsDefault = '{$prm['M_DoctorEmailIsDefault']}', M_DoctorDOB = '{$xxdob}', M_DoctorM_SpecialistID = {$prm['M_DoctorM_SpecialistID']} WHERE M_DoctorID = '{$prm['M_DoctorID']}' "; //echo $query; $rows = $this->db_regional->query($query); foreach($prm['addresses'] as $k => $v){ $sql = " UPDATE m_doctoraddress SET M_DoctorAddressNat_JpaID = {$v['jpa']['id']} WHERE M_DoctorAddressID = {$v['M_DoctorAddressID']}"; $this->db_regional->query($sql); } // ambil data baru $sql = "select * from m_doctor where M_DoctorID = ?"; $qry = $this->db_regional->query($sql,array($prm["id"])); $rows = $qry->result_array(); $new_doctor = array(); if (count($rows) > 0 ) $new_doctor = $rows[0]; $d_doctor = json_encode(array("old" => $old_doctor , "new" => $new_doctor)); //$this->db_regional->query("call one_log.log_me('DOCTOR','DOCTOR_EDIT','{$d_doctor}',$userid)"); $this->sys_ok($result); exit; } function newdoctor(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $ispj = $prm['M_DoctorIsPJ']; $isdefaultpj = $prm['M_DoctorIsDefaultPJ']; $isdefault = $prm['M_DoctorIsDefault']; $isclinic = $prm['M_DoctorIsClinic']; $query ="INSERT INTO m_doctor ( M_DoctorPrefix, M_DoctorPrefix2, M_DoctorName, M_DoctorSufix, M_DoctorSufix2, M_DoctorSufix3, M_DoctorM_SexID, M_DoctorM_ReligionID, M_DoctorM_StaffID, M_DoctorEmail, M_DoctorHP, M_DoctorNote, M_DoctorPhone, M_DoctorIsMarketingConfirm, M_DoctorIsPJ, M_DoctorIsDefaultPJ, M_DoctorIsClinic, M_DoctorIsDefault, M_DoctorEmailIsDefault, M_DoctorM_UserID ) VALUES( '{$prm['M_DoctorPrefix']}', '{$prm['M_DoctorPrefix2']}', '{$prm['M_DoctorName']}', '{$prm['M_DoctorSufix']}', '{$prm['M_DoctorSufix2']}', '{$prm['M_DoctorSufix3']}', '{$prm['M_DoctorM_SexID']}', '{$prm['M_DoctorM_ReligionID']}', '{$prm['M_DoctorM_StaffID']}', '{$prm['M_DoctorEmail']}', '{$prm['M_DoctorHP']}', '{$prm['M_DoctorNote']}', '{$prm['M_DoctorPhone']}', '{$prm['M_DoctorIsMarketingConfirm']}', '{$prm['M_DoctorIsPJ']}', '{$prm['M_DoctorIsDefaultPJ']}', '{$prm['M_DoctorIsClinic']}', '{$prm['M_DoctorIsDefault']}', '{$prm['M_DoctorEmailIsDefault']}', $userid ) "; //echo $query; $rows = $this->db_regional->query($query); $last_id = $this->db_regional->insert_id(); if($rows){ if($isdefault == 'Y'){ $querydefault ="UPDATE m_doctorpj SET M_DoctorPjIsDefault = 'N' WHERE M_DoctorPjIsDefault = 'Y' "; $rows = $this->db_regional->query($querydefault); } if($isdefaultpj == 'Y'){ $querydefault ="UPDATE m_doctorpj SET M_DoctorPjIsDefaultPJ = 'N' WHERE M_DoctorPjIsDefaultPJ = 'Y' "; $rows = $this->db_regional->query($querydefault); } if($ispj == 'Y' || $isdefaultpj == 'Y' || $isdefault == 'Y' || $isclinic === 'Y'){ $querypj ="INSERT INTO m_doctorpj ( M_DoctorPjM_DoctorID, M_DoctorPjIsPJ, M_DoctorPjIsDefaultPJ, M_DoctorPjIsClinic, M_DoctorPjIsDefault, M_DoctorPjCreated ) VALUES( '{$last_id}', '{$prm['M_DoctorIsPJ']}', '{$prm['M_DoctorIsDefaultPJ']}', '{$prm['M_DoctorIsClinic']}', '{$prm['M_DoctorIsDefault']}', NOW() ) "; $rows = $this->db_regional->query($querypj); } } $result = array( "total" => 1 , "records" => array('status'=>'OK'), "id" => $last_id ); //sipe tambah log doctor $prm["M_DoctorID"] = $last_id; $prm["M_DoctorM_UserID"] = $userid; $d_doctor = json_encode($prm); $this->db_regional->query("call one_log.log_me('DOCTOR','DOCTOR_ADD','{$d_doctor}',$userid)"); $this->sys_ok($result); exit; } function deletedoctor(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; // sipe nambah ambil userid $userid = $this->sys_user["M_UserID"]; $query ="UPDATE m_doctor SET M_DoctorIsActive = 'N' WHERE M_DoctorID = '{$prm['M_DoctorID']}' "; //echo $query; $rows = $this->db_regional->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); //adi tambah log doctor $prm["M_DoctorM_UserID"] = $userid; $d_doctor = json_encode($prm); $this->db_regional->query("call one_log.log_me('DOCTOR','DOCTOR_DELETE','{$d_doctor}',$userid)"); $this->sys_ok($result); exit; } function getaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT m_doctoraddress.*, M_KelurahanName, M_DistrictID, M_DistrictName, M_CityID, M_CityName,Nat_JpaName, '' as action, '' as jpa, '' as jpas, '' as kelurahan, '' as kelurahans, '' as district, '' as districts, '' as city, '' as cities FROM m_doctoraddress JOIN m_kelurahan ON M_DoctorAddressM_KelurahanID = M_KelurahanID JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID JOIN m_city ON M_DistrictM_CityID = M_CityID left join nat_jpa on M_DoctorAddressNat_JpaID = Nat_JpaID WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = ? "; //echo $query; $rows = $this->db_regional->query($query,array($prm['id']))->result_array(); if($rows){ $sql = "SELECT Nat_JpaID as id, Nat_JpaName as name FROM nat_jpa WHERE Nat_JpaIsActive = 'Y'"; $jpas = $this->db_regional->query($sql)->result_array(); foreach($rows as $k => $v){ $rows[$k]['jpa'] = array('id'=>$v['M_DoctorAddressNat_JpaID'],'name'=>$v['Nat_JpaName']); $rows[$k]['kelurahan'] = array('id'=>$v['M_DoctorAddressM_KelurahanID'],'name'=>$v['M_KelurahanName']); $rows[$k]['kelurahans'] = array(array('id'=>$v['M_DoctorAddressM_KelurahanID'],'name'=>$v['M_KelurahanName'])); $rows[$k]['district'] = array('id'=>$v['M_DistrictID'],'name'=>$v['M_DistrictName']); $rows[$k]['districts'] = array(array('id'=>$v['M_DistrictID'],'name'=>$v['M_DistrictName'])); $rows[$k]['city'] = array('id'=>$v['M_CityID'],'name'=>$v['M_CityName']); $rows[$k]['cities'] = array(array('id'=>$v['M_CityID'],'name'=>$v['M_CityName'])); $rows[$k]['jpas'] = $jpas; } } $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_regional->query("SELECT COUNT(*) as countx FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = '{$prm['M_DoctorAddressM_DoctorID']}' AND M_DoctorAddressIsActive = 'Y'")->row()->countx; //echo $this->db_regional->last_query(); if($count_addrs == 0){ $prm['M_DoctorAddressNote'] = 'Utama'; } else{ $count_addrs_utama = $this->db_regional->query("SELECT COUNT(*) as countx FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = '{$prm['M_DoctorAddressM_DoctorID']}' AND M_DoctorAddressNote = 'Utama' AND M_DoctorAddressIsActive = 'Y'")->row()->countx; if($count_addrs_utama > 0 && strtolower($prm['M_DoctorAddressNote']) == 'utama'){ $rx = date('YmdHis'); $prm['M_DoctorAddressNote'] = 'Utama_'.$rx; } } $query ="INSERT INTO m_doctoraddress ( M_DoctorAddressM_DoctorID, M_DoctorAddressNote, M_DoctorAddressDescription, M_DoctorAddressM_KelurahanID, M_DoctorAddressNat_JpaID, M_DoctorAddressCreated ) VALUES( '{$prm['M_DoctorAddressM_DoctorID']}', '{$prm['M_DoctorAddressNote']}', '{$prm['M_DoctorAddressDescription']}', '{$prm['M_DoctorAddressM_KelurahanID']}', '{$prm['M_DoctorAddressNat_JpaID']}', NOW() ) "; //echo $query; $rows = $this->db_regional->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); //adi tambah log doctor $prm["M_DoctorM_UserID"] = $userid; $d_doctor = json_encode($prm); $this->db_regional->query("call one_log.log_me('DOCTOR','DOCTOR_ADDR','{$d_doctor}',$userid)"); $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; $query ="UPDATE m_doctoraddress SET M_DoctorAddressM_DoctorID = '{$prm['M_DoctorAddressM_DoctorID']}', M_DoctorAddressNote = '{$prm['M_DoctorAddressNote']}', M_DoctorAddressDescription = '{$prm['M_DoctorAddressDescription']}', M_DoctorAddressM_KelurahanID = '{$prm['M_DoctorAddressM_KelurahanID']}', M_DoctorAddressNat_JpaID = '{$prm['M_DoctorAddressNat_JpaID']}' WHERE M_DoctorAddressID = '{$prm['M_DoctorAddressID']}' "; // echo $query; $rows = $this->db_regional->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); //adi tambah log doctor $prm["M_DoctorM_UserID"] = $userid; $d_doctor = json_encode($prm); $this->db_regional->query("call one_log.log_me('DOCTOR','DOCTOR_ADDR_EDIT','{$d_doctor}',$userid)"); $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_doctoraddress SET M_DoctorAddressIsActive = 'N' WHERE M_DoctorAddressID = '{$prm['M_DoctorAddressID']}' "; //echo $query; $rows = $this->db_regional->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); //adi tambah log doctor $prm["M_DoctorM_UserID"] = $userid; $d_doctor = json_encode($prm); $this->db_regional->query("call one_log.log_me('DOCTOR','DOCTOR_ADDR_DELETE','{$d_doctor}',$userid)"); $this->sys_ok($result); exit; } }