load->library('ibl_encryptor'); // $this->db = $this->load->database("cpone", true); } private function _mask_name($v) { if (!$v) return $v; $v = trim($v); $words = preg_split('/\s+/', $v); if (count($words) === 1) { $l = mb_strlen($v, 'UTF-8'); if ($l <= 2) return $v; return mb_substr($v, 0, 2, 'UTF-8') . str_repeat('*', $l - 2); } $first = $words[0]; $rest = array_slice($words, 1); $masked = array_map(function($w) { if (!$w) return ''; $init = mb_substr($w, 0, 1, 'UTF-8'); return $init . str_repeat('*', max(3, mb_strlen($w, 'UTF-8') - 1)); }, $rest); return $first . ' ' . implode(' ', $masked); } private function _mask_phone($v) { if (!$v) return $v; $d=preg_replace('/[^0-9]/','',trim($v)); $l=strlen($d); if($l<=4) return '****'; if($l<=8) return substr($d,0,4).str_repeat('*',$l-4); return substr($d,0,4).str_repeat('*',$l-7).substr($d,-3); } private function _mask_email($v) { if (!$v||strpos($v,'@')===false) return $v; [$loc,$dom]=explode('@',$v,2); return mb_substr($loc,0,min(2,mb_strlen($loc,'UTF-8')),'UTF-8').'***@'.$dom; } private function _mask_short($v) { if (!$v) return $v; $v=trim($v); $l=mb_strlen($v,'UTF-8'); if($l<=2) return '***'; return mb_substr($v,0,2,'UTF-8').'***'; } private function _mask_id($v) { if (!$v) return $v; $v=trim($v); $l=strlen($v); if($l<=4) return '****'; return substr($v,0,4).str_repeat('*',max(3,$l-6)).($l>6?substr($v,-2):''); } private function _mask_address($v) { if (!$v) return $v; $v=trim($v); $l=mb_strlen($v,'UTF-8'); if($l<=5) return '***'; return mb_substr($v,0,5,'UTF-8').'***'; } public function index() { // $cek = $this->db->query("select database() as current_db")->result(); // print_r($cek); echo "PATIENT API"; } function getmgmmcu() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $sql = "SELECT Mgm_McuID, CONCAT(Mgm_McuLabel,' ', '[', Mgm_McuNumber, ']') as mcuName, DATE_FORMAT(Mgm_McuStartDate, '%d-%m-%Y') as Mgm_McuStartDate, DATE_FORMAT(Mgm_McuEndDate, '%d-%m-%Y') as Mgm_McuEndDate, Mgm_McuFlagRelasiBayarSendiri, Mgm_McuBisaTambahPemeriksaan, Mgm_McuLabel, Mgm_McuNumber, Mgm_McuNumberNational, Mgm_McuNote, Mgm_McuM_CompanyID FROM mgm_mcu WHERE Mgm_McuIsActive = 'Y'"; $qry = $this->db->query($sql); if ($qry) { $rows = $qry->result_array(); } else { $this->sys_error_db("mcu select error", $this->db); exit; } $result = array( "records" => $rows, "sql" => $this->db->last_query() ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function cekKTP($nik, $tanggal, $bulan, $tahun) { if (strlen($nik) != 16) { return false; } $d = substr($nik, 6, 2); $m = substr($nik, 8, 2); $y = substr($nik, 10, 2); //jika tahun full, ambil 2 digit terakhir if (strlen($tahun == 4)) { $tahun = substr($tahun, 2, 2); } if (intval($d) > 40) { //Wanita $d = intval($d) - 40; } if ($tanggal / $d != 1) { return false; } if ($bulan / $m != 1) { return false; } if ($tahun / $y != 1) { return false; } //setelah berhasil melewati rintangan, berarti nomornya valid (tidak 100% valid) return true; } function normalize_schedule_date($rawDate) { $rawDate = trim((string) $rawDate); if ($rawDate === '') { return ''; } $formats = array('d-m-Y', 'Y-m-d', 'd/m/Y', 'Y/m/d'); foreach ($formats as $format) { $dt = DateTime::createFromFormat($format, $rawDate); if ($dt && $dt->format($format) === $rawDate) { return $dt->format('Y-m-d'); } } $timestamp = strtotime($rawDate); if ($timestamp === false) { return ''; } return date('Y-m-d', $timestamp); } function savecsv() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $datas = $prm['data']; // print_r($prm); // exit; $batchSize = 500; // Define the batch size // Split the array into chunks of 250 records $dataChunks = array_chunk($datas, $batchSize); // Loop through each chunk and insert the batch foreach ($dataChunks as $batchData) { $insertData = []; $sql = "INSERT INTO one_lab_log.log_xls( Mgm_McuID, trx_date, json, userid ) VALUES(?,NOW(),?,?)"; $save_log = $this->db->query($sql, array( $prm['xid'], json_encode($batchData), $userid )); } $exist_patients_arr = []; $exist_pat = []; foreach ($datas as $k => $v) { $timestamp = strtotime($v['TANGGAL_LAHIR']); $pdob = date('Y-m-d', $timestamp); $v['NAMA'] = trim(str_replace("'", "\\'", $v['NAMA'])); $datas[$k]['NAMA'] = trim(str_replace("'", "\\'", $v['NAMA'])); $datas[$k]['LOKASI'] = trim(str_replace("'", "\\'", $v['LOKASI'])); $datas[$k]['DEPARTEMENT'] = trim(str_replace("'", "\\'", $v['DEPARTEMENT'])); $datas[$k]['DIVISI'] = trim(str_replace("'", "\\'", $v['DIVISI'])); $datas[$k]['JOB'] = trim(str_replace("'", "\\'", $v['JOB'])); $datas[$k]['POSISI'] = trim(str_replace("'", "\\'", $v['POSISI'])); $idxxxist = $v['NAMA'] . $pdob . $v['NIP']; if (in_array($idxxxist, $exist_patients_arr)) $exist_pat[] = $idxxxist; else $exist_patients_arr[] = $idxxxist; } // exit; if (count($exist_pat) > 0) { $dt_error = join("
", $exist_pat); $this->sys_error("Ada data pasien yang sama : " . $dt_error); exit; } // bisa upload file excel beberapa kali // $sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterPatientsIsActive = 'N' WHERE Mcu_PreregisterPatientsMgm_McuID = '{$prm['xid']}'"; // $this->db->query($sql); //echo $sql; $this->db->trans_begin(); foreach ($datas as $k => $v) { $timestamp = strtotime($v['TANGGAL_LAHIR']); $pdob = date('Y-m-d', $timestamp); $v['NAMA'] = str_replace("'", "\\'", $v['NAMA']); $patient_id = 0; if ($v['PID'] != '') { $sql = "SELECT * FROM m_patient WHERE M_PatientNoReg = '{$v['PID']}' LIMIT 1"; $query = $this->db->query($sql); if (!$query) { $last_qry = $this->db->last_query(); $this->db->trans_rollback(); $this->sys_error("select m_patient : " . $last_qry); exit; } $exist_r = $query->row_array(); if ($exist_r) { $patient_id = $exist_r["M_PatientID"]; $v['NAMA'] = addslashes($exist_r["M_PatientName"]); $pdob = date('Y-m-d', strtotime($exist_r['M_PatientDOB'])); $title_id = $exist_r["M_PatientM_TitleID"]; $sex_id = $exist_r["M_PatientM_SexID"]; $religion_id = $exist_r["M_PatientReligionCode"]; $v['NIK'] = $v['NIK'] ? $v['NIK'] : $exist_r["M_PatientNIK"]; $v['EMAIL'] = $v['EMAIL'] ? $v['EMAIL'] : $exist_r["M_PatientEmail"]; $v['HP'] = $v['HP'] ? $v['HP'] : $exist_r["M_PatientHP"]; $v['JOB'] = $v['JOB'] ? addslashes($v['JOB']) : addslashes($exist_r["M_PatientJob"]); $v['POSISI'] = $v['POSISI'] ? addslashes($v['POSISI']) : addslashes($exist_r["M_PatientPosisi"]); $v['DIVISI'] = $v['DIVISI'] ? addslashes($v['DIVISI']) : addslashes($exist_r["M_PatientDivisi"]); $v['DEPARTEMENT'] = $v['DEPARTEMENT'] ? addslashes($v['DEPARTEMENT']) : addslashes($exist_r["M_PatientDepartement"]); $v['LOKASI'] = $v['LOKASI'] ? addslashes($v['LOKASI']) : addslashes($exist_r["M_PatientLocation"]); $v['JENIS_KELAMIN'] = intval($exist_r["M_PatientM_SexID"]) == 1 ? 'L' : 'P'; } // echo $sql; } if ($v['KTP'] != '') { $sql = "SELECT * FROM m_patient WHERE M_PatientIdentifierCode = 'NNIDN' AND M_PatientIdentifierValue = '{$v['KTP']}' AND M_PatientDOB = '{$pdob}' AND M_PatientIsActive = 'Y' LIMIT 1"; $query = $this->db->query($sql); if (!$query) { $last_qry = $this->db->last_query(); $this->db->trans_rollback(); $this->sys_error("select m_patient : " . $last_qry); exit; } $exist_r = $query->row_array(); if ($exist_r) { $patient_id = $exist_r["M_PatientID"]; $v['NAMA'] = $exist_r["M_PatientName"]; //$pdob = date('Y-m-d',strtotime($exist_r['M_PatientDOB'])); $title_id = $exist_r["M_PatientM_TitleID"]; $v['EMAIL'] = $v['EMAIL'] ? $v['EMAIL'] : $exist_r["M_PatientEmail"]; $v['JENIS_KELAMIN'] = $v['JENIS_KELAMIN'] ? $v['JENIS_KELAMIN'] : 'L'; $v['HP'] = $v['HP'] ? $v['HP'] : $exist_r["M_PatientHP"]; $v['JOB'] = $v['JOB'] ? $v['JOB'] : $exist_r["M_PatientJob"]; $v['POSISI'] = $v['POSISI'] ? $v['POSISI'] : $exist_r["M_PatientPosisi"]; $v['DIVISI'] = $v['DIVISI'] ? $v['DIVISI'] : $exist_r["M_PatientDivisi"]; $v['LOKASI'] = $v['LOKASI'] ? addslashes($v['LOKASI']) : addslashes($exist_r["M_PatientLocation"]); $v['DEPARTEMENT'] = $v['DEPARTEMENT'] ? $v['DEPARTEMENT'] : $exist_r["M_PatientDepartement"]; } //echo $sql; } $title_id = 0; $sex_id = 0; //$sql = "SELECT * FROM m_title WHERE M_TitleM_SexID = '{$sex_id}' AND M_TitleIsActive = 'Y' ORDER BY M_TitleID ASC LIMIT 1"; //$title_id = $this->db->query($sql)->row()->M_TitleID; if (TRIM($v['JENIS_KELAMIN']) == 'L') { $title_id = 1; $sex_id = 1; } else { $title_id = 3; $sex_id = 2; } $sql_company = "SELECT M_CompanyID, M_CompanyNumber FROM m_company WHERE M_CompanyIsActive = 'Y' AND M_CompanyID = ? LIMIT 1"; $qry_compnay = $this->db->query($sql_company, array($prm['companyID'])); if ($qry_compnay) { $rowcor = $qry_compnay->row_array(); } else { $last_qry = $this->db->last_query(); $this->db->trans_rollback(); $this->sys_error("select company : " . $last_qry); exit; } $v['NAMA'] = trim(str_replace("'", "\\'", $v['NAMA'])); $v['NAMA'] = addslashes($v['NAMA']); $sql_pre = "SELECT * FROM mcu_preregister_patients WHERE ( Mcu_PreregisterPatientsPatientName = '{$v['NAMA']}' AND Mcu_PreregisterPatientsDOB = '{$pdob}' AND Mcu_PreregisterPatientsNIP = '{$v['NIP']}' ) AND Mcu_PreregisterPatientsMgm_McuID = '{$prm['xid']}' AND Mcu_PreregisterPatientsIsActive = 'Y' LIMIT 1"; $qry_pre = $this->db->query($sql_pre); if (!$qry_pre) { $last_qry = $this->db->last_query(); $this->db->trans_rollback(); $this->sys_error("select mcu_preregister_patients : " . $last_qry); exit; } $exist_r = $qry_pre->result_array(); $preregister_patient_id = 0; if (count($exist_r) == 0) { $m_nama = $this->db->escape_str($this->_mask_name($v['NAMA'])); $m_ktp = $this->_mask_id($v['KTP']); $m_nip = $this->_mask_id($v['NIP']); $m_email = $this->_mask_email($v['EMAIL']); $m_hp = $this->_mask_phone($v['HP']); $query = " INSERT INTO mcu_preregister_patients ( Mcu_PreregisterPatientsMgm_McuID, Mcu_PreregisterPatientsCompanyNumber, Mcu_PreregisterPatientsNIP, Mcu_PreregisterPatientsKTP, Mcu_PreregisterPatientsM_PatientID, Mcu_PreregisterPatientsM_TitleID, Mcu_PreregisterPatientsPatientName, Mcu_PreregisterPatientsM_SexID, Mcu_PreregisterPatientsDOB, Mcu_PreregisterPatientsJob, Mcu_PreregisterPatientsEmail, Mcu_PreregisterPatientsHp, Mcu_PreregisterPatientsPosisi, Mcu_PreregisterPatientsDivisi, Mcu_PreregisterPatientsLocation, Mcu_PreregisterPatientsDepartment, Mcu_PreregisterPatientsM_MouNumber, Mcu_PreregisterPatientsOrders, Mcu_PreregisterPatientsCreated, Mcu_PreregisterPatientsUserID ) VALUES( '{$prm['xid']}', '{$rowcor["M_CompanyNumber"]}', '{$m_nip}', '{$m_ktp}', '{$patient_id}', '{$title_id}', '{$m_nama}', {$sex_id}, '{$pdob}', '{$v['JOB']}', '{$m_email}', '{$m_hp}', '{$v['POSISI']}', '{$v['DIVISI']}', '{$v['LOKASI']}', '{$v['DEPARTEMENT']}', '{$v['AGREEMENT']}', '{$v['PEMERIKSAAN']}', NOW(), {$userid} )"; // echo $query; // exit; $rows = $this->db->query($query); if (!$rows) { $last_qry = $this->db->last_query(); $this->db->trans_rollback(); $this->sys_error("insert mcu_preregister_patients : " . $last_qry); exit; } if ($rows) { $last_id_x = $this->db->insert_id(); $preregister_patient_id = intval($last_id_x); if ($patient_id == 0) { $sql = "SELECT * FROM m_patient WHERE M_PatientName = '{$v['NAMA']}' AND M_PatientDOB = '{$pdob}' AND M_PatientNIP = '{$v['NIP']}' AND M_PatientIsActive = 'Y' LIMIT 1"; $query = $this->db->query($sql); if (!$query) { $last_qry = $this->db->last_query(); $this->db->trans_rollback(); $this->sys_error("select m_patient : " . $last_qry); exit; } $exist_r = $query->row_array(); if ($exist_r) { $patient_id = $exist_r["M_PatientID"]; } //echo $sql; } $sql_cor = "SELECT * FROM m_company WHERE M_CompanyID = ? AND M_CompanyIsActive = 'Y' LIMIT 1"; $qry_com = $this->db->query($sql_cor, array($prm['companyID'])); if (!$qry_com) { $last_qry = $this->db->last_query(); $this->db->trans_rollback(); $this->sys_error("select company : " . $last_qry); exit; } $qry_com = $qry_com->row_array(); // print_r($patient_id); // exit; $company_id = 0; if ($v['CORPORATE'] == '') { $company_id = $prm['companyID']; } else { $sql_cor = "SELECT * FROM m_company WHERE M_CompanyNumber = '{$v['CORPORATE']}' AND M_CompanyIsActive = 'Y' LIMIT 1"; $query = $this->db->query($sql_cor); if (!$query) { $last_qry = $this->db->last_query(); $this->db->trans_rollback(); $this->sys_error("select company : " . $last_qry); exit; } $rst_company = $query->row_array(); $company_id = $rst_company['M_CompanyID']; } //echo $patient_id; if ($patient_id == 0) { //echo 'insert new patient'; //$pdob = date('Y-m-d',strtotime($prm['Mcu_PreregisterDetailsDOB'])); $sql = "INSERT INTO m_patient ( M_PatientRegisteredByCompanyID, M_PatientNoReg, M_PatientName, M_PatientM_SexID, M_PatientM_TitleID, M_PatientDOB, M_PatientIdentifierValue, M_PatientNIP, M_PatientJob, M_PatientPosisi, M_PatientDivisi, M_PatientLocation, M_PatientDepartement, M_PatientHP, M_PatientEmail, M_PatientCreatedUserID ) VALUES( '{$company_id}', `fn_numbering_ibl`('PA'), '{$v["NAMA"]}', {$sex_id}, {$title_id}, '{$pdob}', '{$v['KTP']}', '{$v['NIP']}', '{$v['JOB']}', '{$v['POSISI']}', '{$v['DIVISI']}', '{$v['LOKASI']}', '{$v['DEPARTEMENT']}', '{$v['HP']}', '{$v['EMAIL']}', '{$userid}' )"; // echo $sql; // exit; $query = $this->db->query($sql); if (!$query) { $last_qry = $this->db->last_query(); $this->db->trans_rollback(); $this->sys_error("insert m_patient : " . $last_qry); exit; } $patient_id = $this->db->insert_id(); $sql = "INSERT INTO m_patientaddress( M_PatientAddressM_PatientID, M_PatientAddressDescription, M_PatientAddressRegionalCd, M_PatientAddressLocation, M_PatientAddressCity, M_PatientAddressDistrict, M_PatientAddressVillage, M_PatientAddressState, M_PatientAddressCountry, M_PatientAddressCountryCode, M_PatientAddressCreated, M_PatientAddressCreatedUserID ) VALUES ( {$patient_id}, '{$qry_com['M_CompanyAddress']}', '{$qry_com['M_CompanyAddressRegionalCd']}', '{$qry_com['M_CompanyAddressLocation']}', '{$qry_com['M_CompanyAddressCity']}', '{$qry_com['M_CompanyAddressDistrict']}', '{$qry_com['M_CompanyAddressVillage']}', '{$qry_com['M_CompanyAddressState']}', 'INDONESIA', 'ID', NOW(), '{$userid}' )"; $query = $this->db->query($sql); if (!$query) { $last_qry = $this->db->last_query(); $this->db->trans_rollback(); $this->sys_error("insert m_patientaddress : " . $last_qry); exit; } } else { // echo 'masuk'; $data_update_patient = array( 'M_PatientDOB' => $pdob ); if ($v['JENIS_KELAMIN'] == 'L') $data_update_patient['M_PatientM_TitleID'] = 1; else $data_update_patient['M_PatientM_TitleID'] = 3; if ($prm['companyID'] != '') $data_update_patient['M_PatientRegisteredByCompanyID'] = $prm['companyID']; if ($v['EMAIL'] != '') $data_update_patient['M_PatientEmail'] = $v['EMAIL']; if ($v['HP'] != '') $data_update_patient['M_PatientHP'] = $v['HP']; if ($v['JOB'] != '') $data_update_patient['M_PatientJob'] = $v['JOB']; if ($v['POSISI'] != '') $data_update_patient['M_PatientPosisi'] = $v['POSISI']; if ($v['DIVISI'] != '') $data_update_patient['M_PatientDivisi'] = $v['DIVISI']; if ($v['LOKASI'] != '') $data_update_patient['M_PatientLocation'] = $v['LOKASI']; if ($v['DEPARTEMENT'] != '') $data_update_patient['M_PatientDepartement'] = $v['DEPARTEMENT']; $this->db->where('M_PatientID', $patient_id); $this->db->update('m_patient', $data_update_patient); //echo $this->db->last_query(); } $sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterPatientsM_PatientID = {$patient_id} WHERE Mcu_PreregisterPatientsID = {$last_id_x}"; $query = $this->db->query($sql); if (!$query) { $last_qry = $this->db->last_query(); $this->db->trans_rollback(); $this->sys_error("update mcu_preregister_patients : " . $last_qry); exit; } } } else { $preregister_patient_id = intval($exist_r[0]['Mcu_PreregisterPatientsID']); } // Simpan jadwal MCU per preregister patient jika parameter TANGGAL_MCU dikirim $scheduleDate = isset($v['TANGGAL_MCU']) ? $this->normalize_schedule_date($v['TANGGAL_MCU']) : ''; if ($preregister_patient_id > 0 && $scheduleDate !== '') { $sqlSchedule = "INSERT INTO mcu_preregister_date ( Mcu_PreregisterDateMcu_PreregisterPatientsID, Mcu_PreregisterDateCheckinSchedule, Mcu_PreregisterDateIsActive, Mcu_PreregisterDateCreated, Mcu_PreregisterDateCreatedUserID, Mcu_PreregisterDateLastUpdated, Mcu_PreregisterDateLastUpdatedUserID ) VALUES ( ?, ?, 'Y', NOW(), ?, NOW(), ? ) ON DUPLICATE KEY UPDATE Mcu_PreregisterDateIsActive = 'Y', Mcu_PreregisterDateLastUpdated = NOW(), Mcu_PreregisterDateLastUpdatedUserID = VALUES(Mcu_PreregisterDateLastUpdatedUserID)"; $qrySchedule = $this->db->query($sqlSchedule, array( $preregister_patient_id, $scheduleDate, $userid, $userid )); if (!$qrySchedule) { $last_qry = $this->db->last_query(); $this->db->trans_rollback(); $this->sys_error("insert mcu_preregister_date : " . $last_qry); exit; } } } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $this->sys_error("Transaction Failed"); exit; } else { $this->db->trans_commit(); } $result = array( "total" => 1, "records" => array('status' => 'OK') ); $this->sys_ok($result); exit; } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function generatesetup() { $prm = $this->sys_input; $setupcode = $prm['setupcode']; $query = " SELECT mcu_offline_prepare.*, '' as patients, M_CompanyName, '' as agreements, '' as deliveries, '' as doctors, M_MouName as default_mou_name, M_DoctorName as default_doctor_name, DATE_FORMAT(McuOfflinePrepareStartDate,'%d-%m-%Y') as start_date, DATE_FORMAT(McuOfflinePrepareEndDate,'%d-%m-%Y') as end_date, DATE_FORMAT(McuOfflinePreparePromiseDate,'%d-%m-%Y') as promise_date, TIME_FORMAT(McuOfflinePreparePromiseTime,'%H:%i') as promise_time FROM mcu_offline_prepare JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID JOIN m_mou ON McuOfflinePrepareM_MouDefaultID = M_MouID JOIN m_doctor ON McuOfflinePrepareM_DoctorDefaultID = M_DoctorID WHERE McuOfflinePrepareCode = '{$setupcode}' LIMIT 1 "; //echo $query; $row = $this->db->query($query)->row_array(); if ($row) { $row['agreements'] = json_decode($row['McuOfflinePrepareMous']); $row['deliveries'] = json_decode($row['McuOfflinePrepareDeliveries']); $row['doctors'] = json_decode($row['McuOfflinePrepareDoctors']); } $result = array( "total" => 1, "records" => $row ); $this->sys_ok($result); exit; } public function search() { $prm = $this->sys_input; if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $search = $prm["search"]; $nama = $prm["name"]; // echo $norm; $sql_where = " "; $sql_param = array(); if ($search != "") { $sql_where = " AND ( Mcu_PreregisterPatientsKTP like CONCAT('%','{$search}','%') OR Mcu_PreregisterPatientsPatientName like CONCAT('%','{$search}','%')) "; //$sql_param[] = "%$search%"; } $limit = ''; if ($all == 'N') { $limit = ' LIMIT 10'; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit; $sql = " SELECT count(*) as total FROM mcu_preregister_patients JOIN m_sex ON Mcu_PreregisterPatientsM_SexID = M_SexID AND M_SexIsActive = 'Y' WHERE Mcu_PreregisterPatientsMgm_McuID = {$prm['mgm_mcuid']} AND Mcu_PreregisterPatientsIsActive = 'Y' $sql_where "; //echo $sql; $query = $this->db_onedev->query($sql, $sql_param); //echo $this->db_onedev->last_query(); $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_patient count", $this->db_onedev); exit; } /* $sql = "SELECT mcu_offline_prepare.*,M_CompanyName, DATE_FORMAT(McuOfflinePrepareStartDate, '%d.%m.%Y') as start_date, DATE_FORMAT(McuOfflinePrepareEndDate, '%d.%m.%Y') as end_date, '' as agreements FROM mcu_offline_prepare JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID WHERE McuOfflinePrepareIsDownloaded = 'Y' AND McuOfflinePrepareIsActive = 'Y'"; //echo $sq $xrow = $this->db_onedev->query($sql)->row_array();*/ $sql = "SELECT mcu_preregister_patients.*, DATE_FORMAT(Mcu_PreregisterPatientsDOB, '%d-%m-%Y') as dob, m_sexname FROM mcu_preregister_patients JOIN m_sex ON Mcu_PreregisterPatientsM_SexID = M_SexID AND M_SexIsActive = 'Y' WHERE Mcu_PreregisterPatientsMgm_McuID = {$prm['mgm_mcuid']} AND Mcu_PreregisterPatientsIsActive = 'Y' $sql_where ORDER BY Mcu_PreregisterPatientsPatientName ASC limit $number_limit offset $number_offset "; //echo $sql; $query = $this->db_onedev->query($sql); $rows = $query->result_array(); //$this->_add_address($rows); $result = array("total" => $tot_page, "records" => $rows); $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 gotoreg() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $new_status = "Y"; $result = array( "total" => 1, "records" => $prm, ); $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 save() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $datas = $prm['data']; //print_r($prm); // $sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterDetailsIsActive = 'N' WHERE Mcu_PreregisterDetailsMcuOfflinePrepareID = '{$prm['xid']}'"; // $this->db_onedev->query($sql); //echo $sql; //unset($datas[0]); $sql = "SELECT * FROM mcu_offline_prepare JOIN m_mou ON McuOfflinePrepareM_MouDefaultID = M_MouID WHERE McuOfflinePrepareID = {$prm['xid']}"; $data_prepare = $this->db_onedev->query($sql)->row_array(); $default_agreement_code = $data_prepare['M_MouNumber']; $default_tests = $data_prepare['McuOfflinePrepareTests']; foreach ($datas as $k => $v) { $agreement = $v['AGREEMENT']; $tests = $v['PEMERIKSAAN']; if ($agreement == '') { $agreement = $default_agreement_code; } if ($tests == '') { $tests = $default_tests; } $xdate = substr($v['TANGGAL_LAHIR'], 0, 2); $xmonth = substr($v['TANGGAL_LAHIR'], 3, 2); $xyear = substr($v['TANGGAL_LAHIR'], 6, 4); $tgl_lahir = $xdate . '-' . $xmonth . '-' . $xyear; $pdob = date('Y-m-d', strtotime($tgl_lahir)); $v['NAMA'] = str_replace("'", "\\'", $v['NAMA']); $v['NAMA'] = $this->strip_unicode($v['NAMA']); $patient_id = 0; if ($v['PID'] != '') { $sql = "SELECT * FROM m_patient JOIN m_sex ON M_PatientM_SexID = M_SexID WHERE M_PatientNoReg = '{$v['PID']}' LIMIT 1"; $exist_r = $this->db_onedev->query($sql)->row_array(); if ($exist_r) { $patient_id = $exist_r["M_PatientID"]; $v['NAMA'] = $exist_r["M_PatientName"]; $pdob = date('Y-m-d', strtotime($exist_r['M_PatientDOB'])); $title_id = $exist_r["M_PatientM_TitleID"]; $sex_id = $exist_r["M_PatientM_SexID"]; $religion_id = $exist_r["M_PatientM_ReligionID"]; $v['NIK'] = $v['NIK'] ? $v['NIK'] : $exist_r["M_PatientNIK"]; $v['EMAIL'] = $v['EMAIL'] ? $v['EMAIL'] : $exist_r["M_PatientEmail"]; $v['HP'] = $v['HP'] ? $v['HP'] : $exist_r["M_PatientHP"]; $v['KEDUDUKAN'] = $v['KEDUDUKAN'] ? $v['KEDUDUKAN'] : $exist_r["M_PatientKedudukan"]; $v['JABATAN'] = $v['JABATAN'] ? $v['JABATAN'] : $exist_r["M_PatientJabatan"]; $v['JOB'] = $v['JOB'] ? $v['JOB'] : $exist_r["M_PatientJob"]; $v['LOKASI'] = $v['LOKASI'] ? addslashes($v['LOKASI']) : addslashes($exist_r["M_PatientLocation"]); $v['JENIS_KELAMIN'] = $exist_r["M_SexCode"]; } //echo $sql; } if ($v['KTP'] != '') { $enc = $this->ibl_encryptor; $ktp_toks = $enc->query_tokens($v['KTP']); $ktp_conds = []; foreach ($ktp_toks as $tok) { $tok_esc = $this->db_onedev->escape_str($tok); $ktp_conds[] = "JSON_CONTAINS(M_PatientNIK_bidx, '\"$tok_esc\"')"; } $ktp_where = $ktp_conds ? implode(' AND ', $ktp_conds) : '0'; $sql = "SELECT m_patient.*, M_SexCode FROM m_patient JOIN m_sex ON M_PatientM_SexID = M_SexID WHERE M_PatientIsActive = 'Y' AND ({$ktp_where}) LIMIT 1"; $exist_r = $this->db_onedev->query($sql)->row_array(); if ($exist_r) { $patient_id = $exist_r["M_PatientID"]; $v['NAMA'] = $enc->decrypt($exist_r['M_PatientName_enc']) ?? $exist_r["M_PatientName"]; $title_id = $exist_r["M_PatientM_TitleID"]; $sex_id = $exist_r["M_PatientM_SexID"]; $religion_id = $exist_r["M_PatientM_ReligionID"]; $v['NIK'] = $v['NIK'] ? $v['NIK'] : ($enc->decrypt($exist_r['M_PatientNIK_enc'] ?? '') ?? $exist_r["M_PatientNIK"]); $v['EMAIL'] = $v['EMAIL'] ? $v['EMAIL'] : ($enc->decrypt($exist_r['M_PatientEmail_enc'] ?? '') ?? $exist_r["M_PatientEmail"]); $v['HP'] = $v['HP'] ? $v['HP'] : ($enc->decrypt($exist_r['M_PatientHP_enc'] ?? '') ?? $exist_r["M_PatientHP"]); $v['KEDUDUKAN'] = $v['KEDUDUKAN'] ? $v['KEDUDUKAN'] : $exist_r["M_PatientKedudukan"]; $v['JABATAN'] = $v['JABATAN'] ? $v['JABATAN'] : $exist_r["M_PatientJabatan"]; $v['JOB'] = $v['JOB'] ? $v['JOB'] : $exist_r["M_PatientJob"]; $v['LOKASI'] = $v['LOKASI'] ? addslashes($v['LOKASI']) : addslashes($exist_r["M_PatientLocation"]); $v['JENIS_KELAMIN'] = $exist_r["M_SexCode"]; $v['KTP'] = $v['KTP'] ? $v['KTP'] : ($enc->decrypt($exist_r['M_PatientIDNumber_enc'] ?? '') ?? $exist_r["M_PatientIDNumber"]); } } if ($patient_id == 0) { $sex_id = 0; $sql = "SELECT * FROM m_sex WHERE M_SexCode = TRIM('{$v['JENIS_KELAMIN']}') AND M_SexIsActive = 'Y' LIMIT 1"; $sex_id = $this->db_onedev->query($sql)->row()->M_SexID; $title_id = 0; //$sql = "SELECT * FROM m_title WHERE M_TitleM_SexID = '{$sex_id}' AND M_TitleIsActive = 'Y' ORDER BY M_TitleID ASC LIMIT 1"; //$title_id = $this->db_onedev->query($sql)->row()->M_TitleID; if (TRIM($v['JENIS_KELAMIN']) == 'L') $title_id = 2; else $title_id = 4; $religion_id = 0; $sql = "SELECT * FROM m_religion WHERE M_ReligionName = 'OTHERS' AND M_ReligionIsActive = 'Y' LIMIT 1"; $religion_id = $this->db_onedev->query($sql)->row()->M_ReligionID; } $m_nama = $this->db_onedev->escape_str($this->_mask_name($v['NAMA'])); $m_ktp = $this->_mask_id($v['KTP']); $m_nik = $this->_mask_id($v['NIK']); $m_email = $this->_mask_email($v['EMAIL']); $m_hp = $this->_mask_phone($v['HP']); $query = " INSERT INTO mcu_preregister_patients ( Mcu_PreregisterDetailsMcuOfflinePrepareID, Mcu_PreregisterDetailsPID, Mcu_PreregisterDetailsKTP, Mcu_PreregisterDetailsNIK, Mcu_PreregisterDetailsM_TitleID, Mcu_PreregisterDetailsPatientName, Mcu_PreregisterDetailsM_ReligionID, Mcu_PreregisterDetailsEmail, Mcu_PreregisterDetailsHp, Mcu_PreregisterDetailsDOB, Mcu_PreregisterDetailsKedudukan, Mcu_PreregisterDetailsJabatan, Mcu_PreregisterDetailsJob, Mcu_PreregisterDetailsLocation, Mcu_PreregisterDetailsM_SexCode, Mcu_PreregisterPatientsM_MouNumber, Mcu_PreregisterPatientsOrders, Mcu_PreregisterDetailsCreated, Mcu_PreregisterDetailsUserID ) VALUES( '{$prm['xid']}', '{$v['PID']}', '{$m_ktp}', '{$m_nik}', '{$title_id}', '{$m_nama}', '{$religion_id}', '{$m_email}', '{$m_hp}', '{$pdob}', '{$v['KEDUDUKAN']}', '{$v['JABATAN']}', '{$v['JOB']}', '{$v['LOKASI']}', TRIM('{$v['JENIS_KELAMIN']}'), '{$v['AGREEMENT']}', '{$tests}', NOW(), {$userid} )"; //echo $query; $rows = $this->db_onedev->query($query); if ($rows) { $last_id_x = $this->db_onedev->insert_id(); $sql = "SELECT * FROM mcu_offline_prepare JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID WHERE McuOfflinePrepareID = {$prm['xid']}"; $row_header = $this->db_onedev->query($sql)->row_array(); //print_r($row_header); if ($patient_id == 0) { $enc = $this->ibl_encryptor; $name_toks = $enc->query_tokens($v['NAMA']); $name_conds = []; foreach ($name_toks as $tok) { $tok_esc = $this->db_onedev->escape_str($tok); $name_conds[] = "JSON_CONTAINS(M_PatientName_bidx, '\"$tok_esc\"')"; } $name_where = $name_conds ? implode(' AND ', $name_conds) : '0'; $sql = "SELECT M_PatientID FROM m_patient WHERE ({$name_where}) AND M_PatientDOB = '{$pdob}' AND M_PatientIsActive = 'Y' LIMIT 1"; $exist_r = $this->db_onedev->query($sql)->row_array(); if ($exist_r) { $patient_id = $exist_r["M_PatientID"]; } } //echo $patient_id; if ($patient_id == 0) { //echo 'insert new patient'; //$pdob = date('Y-m-d',strtotime($prm['Mcu_PreregisterDetailsDOB'])); $M_PatientM_IdTypeID = 0; $M_PatientIDNumber = NULL; if (isset($v["KTP"]) && $v["KTP"] != '') { $M_PatientM_IdTypeID = 1; $M_PatientIDNumber = $v["KTP"]; } $enc = $this->ibl_encryptor; $dob_str = date('d-m-Y', strtotime($pdob)); $data_insert_patient = [ 'M_PatientName' => $this->_mask_name($v["NAMA"]), 'M_PatientName_enc' => $enc->encrypt($v["NAMA"]), 'M_PatientName_bidx' => $enc->search_bidx($v["NAMA"]), 'M_PatientM_TitleID' => $title_id, 'M_PatientM_SexID' => $sex_id, 'M_PatientM_ReligionID' => $religion_id, 'M_PatientPOB' => '***', 'M_PatientPOB_enc' => $enc->encrypt('-'), 'M_PatientDOB' => $pdob, 'M_PatientDOB_enc' => $enc->encrypt($dob_str), 'M_PatientDOB_bidx' => $enc->search_bidx($dob_str), 'M_PatientNIK' => $v["NIK"], 'M_PatientNIK_bidx' => $enc->search_bidx($v["NIK"] ?? ''), 'M_PatientM_IdTypeID' => $M_PatientM_IdTypeID, 'M_PatientIDNumber' => $M_PatientIDNumber ? $this->_mask_id($M_PatientIDNumber) : null, 'M_PatientIDNumber_enc' => $M_PatientIDNumber ? $enc->encrypt($M_PatientIDNumber) : null, 'M_PatientJabatan' => $v['JABATAN'], 'M_PatientLocation' => $v['LOKASI'], 'M_PatientKedudukan' => $v['KEDUDUKAN'], 'M_PatientJob' => $v['JOB'], 'M_PatientEmail' => $this->_mask_email($v['EMAIL']), 'M_PatientEmail_enc' => $enc->encrypt($v['EMAIL']), 'M_PatientHP' => $this->_mask_phone($v['HP']), 'M_PatientHP_enc' => $enc->encrypt($v['HP']), 'M_PatientHP_bidx' => $enc->search_bidx($v['HP']), 'M_PatientUserID' => $userid, ]; $this->db_onedev->insert('m_patient', $data_insert_patient); $patient_id = $this->db_onedev->insert_id(); //$sql = "SELECT LAST_INSERT_ID() as xid"; //$patient_id = $this->db_onedev->query($sql)->row()->xid; //echo $patient_id ; $enc = $this->ibl_encryptor; $addr_desc = $row_header['M_CompanyAddress']; $this->db_onedev->insert('m_patientaddress', [ 'M_PatientAddressM_PatientID' => $patient_id, 'M_PatientAddressDescription' => $this->_mask_address($addr_desc), 'M_PatientAddressDescription_enc' => $enc->encrypt($addr_desc), 'M_PatientAddressM_KelurahanID' => $row_header['M_CompanyM_KelurahanID'], 'M_PatientAddressCreated' => date('Y-m-d H:i:s'), 'M_PatientAddressUserID' => $userid, ]); //echo $sql; //$patient_addr_id = $this->db_onedev->insert_id(); //$sql = "SELECT * FROM m_patientaddress WHERE M_PatientAddressID = {$patient_addr_id}"; //$ptn_addr = $this->db_onedev->query($sql)->row_array(); //$ptn_addr = json_encode($ptn_addr); //$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_ADD', '{$ptn_addr}', $userid)"); } else { //echo 'masuk'; //$pdob = date('Y-m-d',strtotime($prm['Mcu_PreregisterDetailsDOB'])); $enc = $this->ibl_encryptor; $dob_str2 = date('d-m-Y', strtotime($pdob)); $data_update_patient = [ 'M_PatientDOB' => $pdob, 'M_PatientDOB_enc' => $enc->encrypt($dob_str2), 'M_PatientDOB_bidx'=> $enc->search_bidx($dob_str2), ]; if ($v['JENIS_KELAMIN'] == 'L') $data_update_patient['M_PatientM_TitleID'] = 2; else $data_update_patient['M_PatientM_TitleID'] = 4; if ($v['EMAIL'] != '') { $data_update_patient['M_PatientEmail'] = $this->_mask_email($v['EMAIL']); $data_update_patient['M_PatientEmail_enc'] = $enc->encrypt($v['EMAIL']); } if ($v['HP'] != '') { $data_update_patient['M_PatientHP'] = $this->_mask_phone($v['HP']); $data_update_patient['M_PatientHP_enc'] = $enc->encrypt($v['HP']); $data_update_patient['M_PatientHP_bidx'] = $enc->search_bidx($v['HP']); } if ($v['NIK'] != '') { $data_update_patient['M_PatientNIK'] = $v['NIK']; $data_update_patient['M_PatientNIK_bidx'] = $enc->search_bidx($v['NIK']); } if ($v['JABATAN'] != '') $data_update_patient['M_PatientJabatan'] = $v['JABATAN']; if ($v['KEDUDUKAN'] != '') $data_update_patient['M_PatientKedudukan'] = $v['KEDUDUKAN']; if ($v['LOKASI'] != '') $data_update_patient['M_PatientLocation'] = $v['LOKASI']; if ($v['JOB'] != '') $data_update_patient['M_PatientJob'] = $v['JOB']; if (isset($v["KTP"]) && $v["KTP"] != '') { $data_update_patient['M_PatientM_IdTypeID'] = 1; $data_update_patient['M_PatientIDNumber'] = $this->_mask_id($v["KTP"]); $data_update_patient['M_PatientIDNumber_enc'] = $enc->encrypt($v["KTP"]); } $this->db_onedev->where('M_PatientID', $patient_id); $this->db_onedev->update('m_patient', $data_update_patient); //echo $this->db_onedev->last_query(); //$sql = "SELECT * FROM m_patient WHERE M_PatientID = {$patient_id}"; //$ptn = $this->db_onedev->query($sql)->row_array(); //$ptn = json_encode($ptn); //$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.EDIT', '{$ptn}', $userid)"); } $sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterDetailsM_PatientID = {$patient_id} WHERE Mcu_PreregisterDetailsID = {$last_id_x}"; $this->db_onedev->query($sql); } } $result = array( "total" => 1, "records" => array('status' => 'OK') ); $this->sys_ok($result); exit; } function strip_unicode($inp) { //echo $inp; $result = mb_convert_encoding($inp, 'US-ASCII', 'UTF-8'); //echo $result; $result = str_replace("?", " ", $result); //echo $result; return $result; } 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'])); $dob_str = date('d-m-Y', strtotime($prm['M_PatientDOB'])); $patient_name = $prm['M_PatientName']; $enc = $this->ibl_encryptor; $ptn = [ 'M_PatientName' => $this->_mask_name($patient_name), 'M_PatientName_enc' => $enc->encrypt($patient_name), 'M_PatientName_bidx' => $enc->search_bidx($patient_name), 'M_PatientM_TitleID' => $prm['M_PatientM_TitleID'], 'M_PatientPrefix' => $prm['M_PatientPrefix'], 'M_PatientSuffix' => $prm['M_PatientSuffix'], 'M_PatientDOB' => $pdob, 'M_PatientDOB_enc' => $enc->encrypt($dob_str), 'M_PatientDOB_bidx' => $enc->search_bidx($dob_str), 'M_PatientM_SexID' => $prm['M_PatientM_SexID'], 'M_PatientM_ReligionID' => $prm['M_PatientM_ReligionID'], 'M_PatientEmail' => $this->_mask_email($prm['M_PatientEmail']), 'M_PatientEmail_enc' => $enc->encrypt($prm['M_PatientEmail']), 'M_PatientPOB' => $this->_mask_short($prm['M_PatientPOB']), 'M_PatientPOB_enc' => $enc->encrypt($prm['M_PatientPOB']), 'M_PatientHP' => $this->_mask_phone($prm['M_PatientHP']), 'M_PatientHP_enc' => $enc->encrypt($prm['M_PatientHP']), 'M_PatientHP_bidx' => $enc->search_bidx($prm['M_PatientHP']), 'M_PatientPhone' => $this->_mask_phone($prm['M_PatientPhone']), 'M_PatientPhone_enc' => $enc->encrypt($prm['M_PatientPhone']), 'M_PatientM_IdTypeID' => $prm['M_PatientM_IdTypeID'], 'M_PatientIDNumber' => $this->_mask_id($prm['M_PatientIDNumber']), 'M_PatientIDNumber_enc' => $enc->encrypt($prm['M_PatientIDNumber']), 'M_PatientNIK' => $prm['M_PatientNIK'], 'M_PatientNIK_bidx' => $enc->search_bidx($prm['M_PatientNIK'] ?? ''), 'M_PatientNote' => $prm['M_PatientNote'], 'M_PatientJabatan' => $prm['M_PatientJabatan'], 'M_PatientKedudukan' => $prm['M_PatientKedudukan'], 'M_PatientPJ' => $prm['M_PatientPJ'], 'M_PatientLocation' => $prm['M_PatientLocation'], 'M_PatientJob' => $prm['M_PatientJob'], 'M_PatientUserID' => $userid, ]; $this->db_onedev->insert('m_patient', $ptn); $last_id = $this->db_onedev->insert_id(); $result = array( "total" => 1, "records" => array('status' => 'OK'), "id" => $last_id ); $ptn = $prm; $ptn["M_PatientID"] = $last_id; $ptn["M_PatientDOB"] = $pdob; $ptn = json_encode($ptn); $this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADD', '{$ptn}', $userid)"); $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' WHERE M_PatientID = '{$prm['M_PatientID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1, "records" => array('status' => 'OK') ); $ptn = $prm; $ptn["M_PatientDOB"] = $pdob; $ptn = json_encode($ptn); $this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.DELETE', '{$ptn}', $userid)"); $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_KelurahanName, M_DistrictID, M_DistrictName, M_CityID, M_CityName, '' as action FROM m_patientaddress JOIN m_kelurahan ON M_PatientAddressM_KelurahanID = M_KelurahanID JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID JOIN m_city ON M_DistrictM_CityID = M_CityID 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]['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; //echo $this->db_onedev->last_query(); 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; } } $query = "INSERT INTO m_patientaddress ( M_PatientAddressM_PatientID, M_PatientAddressNote, M_PatientAddressDescription, M_PatientAddressM_KelurahanID, M_PatientAddressCreated ) VALUES( '{$prm['M_PatientAddressM_PatientID']}', '{$prm['M_PatientAddressNote']}', '{$prm['M_PatientAddressDescription']}', '{$prm['M_PatientAddressM_KelurahanID']}', NOW() ) "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1, "records" => array('status' => 'OK') ); $ptn = $prm; $ptn["M_UserID"] = $pdob; $ptn = json_encode($ptn); $this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_ADD', '{$ptn}', $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_patientaddress SET M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}', M_PatientAddressNote = '{$prm['M_PatientAddressNote']}', M_PatientAddressDescription = '{$prm['M_PatientAddressDescription']}', M_PatientAddressM_KelurahanID = '{$prm['M_PatientAddressM_KelurahanID']}' WHERE M_PatientAddressID = '{$prm['M_PatientAddressID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1, "records" => array('status' => 'OK') ); $ptn = $prm; $ptn["M_UserID"] = $pdob; $ptn = json_encode($ptn); $this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_EDIT', '{$ptn}', $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_patientaddress SET M_PatientAddressIsActive = 'N' WHERE M_PatientAddressID = '{$prm['M_PatientAddressID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1, "records" => array('status' => 'OK') ); $ptn = $prm; $ptn["M_UserID"] = $pdob; $ptn = json_encode($ptn); $this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_DELETE', '{$ptn}', $userid)"); $this->sys_ok($result); exit; } }