db_onedev = $this->load->database("onedev", true); $this->db_oneklinik = $this->load->database("onedev", true); $this->load->library('ibl_encryptor'); } public function search() { $prm = $this->sys_input; $id = $this->db_onedev->escape_str($prm['id']); $sql = "SELECT orderID, orderDate, orderNumber, orderIsScreening, orderIsAnamnese, orderIsCheck, orderAge as patient_age, DATE_FORMAT(orderDate,'%d-%m-%Y') as order_date, 'N' divider, M_PatientID, M_PatientNoReg, M_PatientPrefix, M_PatientSuffix, concat(M_TitleName,' ',IFNULL(M_PatientPrefix,''),' ',M_PatientName,' ',IFNULL(M_PatientSuffix,'')) M_PatientNameRaw, M_PatientNote, M_PatientNIK, M_PatientJabatan, M_PatientKedudukan, M_PatientPJ, M_PatientLocation, M_PatientJob, M_PatientM_SexID, M_SexName, M_TitleID, M_TitleName, M_PatientM_TitleID, M_PatientM_ReligionID, IFNULL(M_ReligionName,'-') M_ReligionName, M_PatientM_IdTypeID, IF(ISNULL(M_PatientSuspendID),'active','suspend') as status, M_PatientAddressRegionalCd, M_PatientName_enc, M_PatientHP_enc, M_PatientDOB_enc, M_PatientEmail_enc, M_PatientPhone_enc, M_PatientPOB_enc, M_PatientIDNumber_enc, M_PatientNIK_enc, M_PatientAddressDescription_enc FROM one_klinik.`order` JOIN m_patient ON M_PatientID = orderM_PatientID AND M_PatientIsActive = 'Y' JOIN m_title ON M_PatientM_TitleID = M_TitleID JOIN m_sex ON M_PatientM_SexID = M_SexID JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressIsActive = 'Y' LEFT JOIN m_religion ON M_PatientM_ReligionID = M_ReligionID LEFT JOIN m_patientsuspend ON M_PatientSuspendM_PatientID = M_PatientID AND M_PatientSuspendIsActive = 'Y' WHERE orderNumber = '{$id}' AND M_PatientSuspendID IS NULL GROUP BY M_PatientID"; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("order rows", $this->db_onedev); return; } $rows = $query->result_array(); $enc = $this->ibl_encryptor; foreach ($rows as $k => $v) { $rows[$k]['M_PatientName'] = $enc->decrypt($v['M_PatientName_enc']) ?? $v['M_PatientNameRaw']; $rows[$k]['M_PatientHP'] = $enc->decrypt($v['M_PatientHP_enc']) ?? ''; $rows[$k]['M_PatientEmail'] = $enc->decrypt($v['M_PatientEmail_enc']) ?? ''; $rows[$k]['M_PatientPOB'] = $enc->decrypt($v['M_PatientPOB_enc']) ?? ''; $rows[$k]['M_PatientPhone'] = $enc->decrypt($v['M_PatientPhone_enc']) ?? ''; $rows[$k]['M_PatientIDNumber'] = $enc->decrypt($v['M_PatientIDNumber_enc']) ?? ''; $rows[$k]['M_PatientNIK'] = $enc->decrypt($v['M_PatientNIK_enc']) ?? ''; $rows[$k]['M_PatientDOB'] = $enc->decrypt($v['M_PatientDOB_enc']) ?? ''; $rows[$k]['dob_ina'] = $rows[$k]['M_PatientDOB']; $rows[$k]['M_PatientAddressDescription'] = $enc->decrypt($v['M_PatientAddressDescription_enc']) ?? ''; $rows[$k]['M_PatientAddress'] = $rows[$k]['M_PatientAddressDescription']; foreach (array_keys($rows[$k]) as $col) { if (substr($col, -4) === '_enc') unset($rows[$k][$col]); } unset($rows[$k]['M_PatientNameRaw']); $info = $this->db_onedev->query("SELECT fn_fo_patient_visit(?) info", [$v['M_PatientID']])->row(); $rows[$k]['info'] = json_decode($info->info); } $this->sys_ok(["total" => count($rows), "records" => $rows]); } function get_data(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $result = array('data' => ''); $sql = "SELECT orderScreeningKesanUmum as kesan_umum, orderScreeningValueKesadaran as kesadaran, orderScreeningValuePernafasan as pernafasan, orderScreeningValueResikoJatuh as resiko_jatuh, orderScreeningValueNyeriDada as nyeri_dada, orderScreeningValueSkalaNyeri as skala_nyeri, orderScreeningValueBatuk as batuk, orderScreeningValueKeputusan as keputusan FROM one_klinik.order_screening WHERE orderScreeningOrderID = ? AND orderScreeningIsActive = 'Y' LIMIT 1"; $query = $this->db_oneklinik->query($sql,array($prm['orderid'])); if(!$query){ $this->sys_error("Gagal get data"); echo $this->db_oneklinik->last_query(); } $result = $query->row_array(); $this->sys_ok($result); exit; } function getsexreg() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $rows['default_location'] = []; $rows['doctors'] = $this->db_onedev->query( "SELECT M_DoctorID as id, M_DoctorCode as code, M_DoctorName as name, M_DoctorMcuDefaultKlinik as is_default, M_DoctorMcuPriceKlinik as price FROM m_doctormcu JOIN m_doctor ON M_DoctorMcuM_DoctorID = M_DoctorID WHERE M_DoctorMcuIsActive = 'Y'" )->result_array(); $rows['default_doctor'] = []; foreach ($rows['doctors'] as $value) { if ($value['is_default'] == 'Y') { $rows['default_doctor'] = $value; break; } } $rows['titles'] = $this->db_onedev->query("SELECT * FROM m_title WHERE M_TitleIsActive = 'Y'")->result_array(); $rows['sexes'] = $this->db_onedev->query("SELECT * FROM m_sex WHERE M_SexIsActive = 'Y'")->result_array(); $rows['religions'] = $this->db_onedev->query("SELECT * FROM m_religion WHERE M_ReligionIsActive = 'Y'")->result_array(); $rows['kartuidentitass'] = $this->db_onedev->query("SELECT * FROM m_idtype WHERE M_IdTypeIsActive = 'Y'")->result_array(); $branch = $this->db_onedev->query("SELECT * FROM m_branch WHERE M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'")->row_array(); if ($branch) { $rows['default_location']['city_address'] = $this->db_onedev->query("SELECT * FROM m_city WHERE M_CityIsActive = 'Y' AND M_CityID = ?", [$branch['M_BranchM_CityID']])->row_array(); $rows['default_location']['cities'] = $this->db_onedev->query("SELECT * FROM m_city WHERE M_CityIsActive = 'Y' AND M_CityM_ProvinceID = ?", [$rows['default_location']['city_address']['M_CityM_ProvinceID']])->result_array(); $rows['default_location']['province_address'] = $this->db_onedev->query("SELECT * FROM m_province WHERE M_ProvinceIsActive = 'Y' AND M_ProvinceID = ?", [$rows['default_location']['city_address']['M_CityM_ProvinceID']])->row_array(); $rows['default_location']['provinces'] = $this->db_onedev->query("SELECT * FROM m_province WHERE M_ProvinceIsActive = 'Y'")->result_array(); $rows['default_location']['districts'] = $this->db_onedev->query("SELECT * FROM m_district WHERE M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ?", [$branch['M_BranchM_CityID']])->result_array(); $rows['default_location']['district_address'] = $this->db_onedev->query("SELECT * FROM m_district WHERE M_DistrictIsActive = 'Y' AND M_DistrictID = ?", [$branch['M_BranchM_DistrictID']])->row_array(); $rows['default_location']['kelurahans'] = $this->db_onedev->query("SELECT * FROM m_kelurahan WHERE M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?", [$branch['M_BranchM_DistrictID']])->result_array(); $rows['default_location']['kelurahan_address'] = $this->db_onedev->query("SELECT * FROM m_kelurahan WHERE M_KelurahanIsActive = 'Y' AND M_KelurahanID = ?", [$branch['M_BranchM_KelurahanID']])->row_array(); } $this->sys_ok(["total" => count($rows), "records" => $rows]); exit; } protected function objToArray($obj) { // Not an object or array if (!is_object($obj) && !is_array($obj)) { return $obj; } // Parse array foreach ($obj as $key => $value) { $arr[$key] = $this->objToArray($value); } // Return parsed array return $arr; } public function list_patient() { $prm = $this->sys_input; $max_rst = 20; $tot_count = 0; $number_limit = 20; $number_offset = (!isset($prm['current_page'])?1:$prm['current_page'] - 1) * $number_limit ; $xdate = $prm['date']; $status = $prm['status']; $sql = "SELECT 'N' divider, M_PatientName, M_PatientName_enc, M_PatientHP, M_PatientHP_enc, M_PatientDOB, M_PatientDOB_enc, M_PatientEmail, M_PatientEmail_enc, M_PatientPhone, M_PatientPhone_enc, M_PatientPOB, M_PatientPOB_enc, M_PatientIDNumber, M_PatientIDNumber_enc, M_PatientNIK, M_PatientNIK_enc, M_PatientPhoto, M_PatientPhotoThumb, `order`.*,DATE_FORMAT(orderDate,'%d-%m-%Y') as date_order, '' as kode_status, '' as status, M_TitleName, M_PatientNoReg, M_PatientM_SexID FROM one_klinik.`order` JOIN m_patient ON orderM_PatientID = M_PatientID LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID WHERE orderIsActive = 'Y' AND DATE(orderDate) = ? AND orderIsScreening = ? LIMIT $number_limit offset $number_offset"; //echo $sql; $query = $this->db_oneklinik->query($sql,array($xdate,$status)); //echo $this->db_oneklinik->last_query(); if ($query) { $rows = $query->result_array(); $enc = $this->ibl_encryptor; foreach ($rows as $k => $v) { $rows[$k]['M_PatientName'] = $enc->decrypt($v['M_PatientName_enc'] ?? '') ?: $v['M_PatientName']; $rows[$k]['M_PatientHP'] = $enc->decrypt($v['M_PatientHP_enc'] ?? '') ?: $v['M_PatientHP']; $rows[$k]['M_PatientDOB'] = $enc->decrypt($v['M_PatientDOB_enc'] ?? '') ?: $v['M_PatientDOB']; $rows[$k]['M_PatientEmail'] = $enc->decrypt($v['M_PatientEmail_enc'] ?? '') ?: $v['M_PatientEmail']; $rows[$k]['M_PatientPhone'] = $enc->decrypt($v['M_PatientPhone_enc'] ?? '') ?: $v['M_PatientPhone']; $rows[$k]['M_PatientPOB'] = $enc->decrypt($v['M_PatientPOB_enc'] ?? '') ?: $v['M_PatientPOB']; $rows[$k]['M_PatientIDNumber'] = $enc->decrypt($v['M_PatientIDNumber_enc'] ?? '') ?: $v['M_PatientIDNumber']; $rows[$k]['M_PatientNIK'] = $enc->decrypt($v['M_PatientNIK_enc'] ?? '') ?: $v['M_PatientNIK']; $rows[$k]['patient_name'] = trim(($v['M_TitleName'] ?? '') . ' ' . $rows[$k]['M_PatientName']); } $result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_oneklinik->last_query()); $this->sys_ok($result); } else { $this->sys_error_db("m_patient rows",$this->db_oneklinik); exit; } } function process_now(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userID = $this->sys_user['M_UserID']; //print_r($prm['subgroup']); $sql = "INSERT INTO one_klinik.order_status ( orderStatusOrderID, orderStatusCode, orderStatusValue, orderStatusUserID ) VALUES( ?,?,?,? )"; $query = $this->db_oneklinik->query($sql,array($prm['orderID'],'S','Y',$userID)); if(!$query){ $this->sys_error("Gagal Process"); } $sql = "UPDATE one_klinik.`order` SET orderIsScreening = 'Y', orderUserID = ? WHERE orderID = ?"; $query = $this->db_oneklinik->query($sql,array($userID,$prm['orderID'])); if(!$query){ $this->sys_error("Gagal Update"); } $result = array('process'=>'OK'); $this->sys_ok($result); exit; } function cancel_now(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userID = $this->sys_user['M_UserID']; //print_r($prm['subgroup']); $sql = "INSERT INTO one_klinik.order_status ( orderStatusOrderID, orderStatusCode, orderStatusValue, orderStatusUserID ) VALUES( ?,?,?,? )"; $query = $this->db_oneklinik->query($sql,array($prm['orderID'],'S','N',$userID)); if(!$query){ $this->sys_error("Gagal Process"); } $sql = "UPDATE one_klinik.`order` SET orderIsScreening = 'N', orderUserID = ? WHERE orderID = ?"; $query = $this->db_oneklinik->query($sql,array($userID,$prm['orderID'])); if(!$query){ $this->sys_error("Gagal Process"); } $result = array('process'=>'OK'); $this->sys_ok($result); exit; } function end_session(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userID = $this->sys_user['M_UserID']; //print_r($prm['subgroup']); $sql = "SELECT COUNT(*) as xcount FROM one_klinik.order_screening WHERE orderScreeningOrderID = ? AND orderScreeningIsActive = 'Y'"; $query = $this->db_oneklinik->query($sql,array($prm['orderID'])); if(!$query){ $this->sys_error("count exist"); echo $this->db_oneklinik->last_query(); } $check_exist = $query->row()->xcount; if($check_exist == 0){ $sql = "INSERT one_klinik.order_screening ( orderScreeningOrderID, orderScreeningKesanUmum, orderScreeningValueKesadaran, orderScreeningValuePernafasan, orderScreeningValueResikoJatuh, orderScreeningValueNyeriDada, orderScreeningValueSkalaNyeri, orderScreeningValueBatuk, orderScreeningValueKeputusan, orderScreeningCreated, orderScreeningUserID ) VALUES( ?,?,?,?,?,?,?,?,?,NOW(),? )"; $query = $this->db_oneklinik->query($sql,array( $prm['orderID'], $prm['kesan_umum'], $prm['kesadaran'], $prm['pernafasan'], $prm['resiko_jatuh'], $prm['nyeri_dada'], $prm['skala_nyeri'], $prm['batuk'], $prm['keputusan'], $userID) ); if(!$query){ $this->sys_error("Gagal insert"); } }else{ $sql = "UPDATE one_klinik.order_screening SET orderScreeningKesanUmum = ?, orderScreeningValueKesadaran = ?, orderScreeningValuePernafasan = ?, orderScreeningValueResikoJatuh = ?, orderScreeningValueNyeriDada = ?, orderScreeningValueSkalaNyeri = ?, orderScreeningValueBatuk = ?, orderScreeningValueKeputusan = ?, orderScreeningUserID = ? WHERE orderScreeningOrderID = ? "; $query = $this->db_oneklinik->query($sql,[ $prm['kesan_umum'], $prm['kesadaran'], $prm['pernafasan'], $prm['resiko_jatuh'], $prm['nyeri_dada'], $prm['skala_nyeri'], $prm['batuk'], $prm['keputusan'], $userID, $prm['orderID'] ]); if(!$query){ echo $this->db_oneklinik->last_query(); $this->sys_error("Gagal Update"); } } $sql = "INSERT INTO one_klinik.order_status ( orderStatusOrderID, orderStatusCode, orderStatusValue, orderStatusUserID ) VALUES( ?,?,?,? )"; $query = $this->db_oneklinik->query($sql,array($prm['orderID'],'S','D',$userID)); if(!$query){ $this->sys_error("Gagal End"); } $sql = "UPDATE one_klinik.`order` SET orderIsScreening = 'D', orderUserID = ? WHERE orderID = ?"; $query = $this->db_oneklinik->query($sql,array($userID,$prm['orderID'])); if(!$query){ $this->sys_error("Gagal ENd"); } $result = array('process'=>'OK'); $this->sys_ok($result); exit; } }