db = $this->load->database("regional", true); // string database $this->db_str_doctor = 'one_doctor'; $this->startVt = chr(0x0b); $this->stopFs = chr(0x1c); $this->cr = chr(0x0d); } // url regional pd cabang terkait public function getRegionalIPAddress() { $sql_get = "SELECT S_SystemIPAddressRegional FROM one.conf_systems WHERE S_SystemsIsActive = 'Y'"; $qry = $this->db->query($sql_get); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("get ip regional failed", $this->db); exit; } $data = $qry->result_array(); return $data[0]['S_SystemIPAddressRegional']; } // branch yg aktif function getBranch() { try { $sql = "SELECT M_BranchID, M_BranchCode FROM m_branch WHERE M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'"; $qry = $this->db->query($sql, array()); if (!$qry) { $$response = [ 'status' => false, "message" => $this->db->error()["message"], "msg" => "error get branch data ", 'query' => $this->db->last_query() ]; return $response; } $result = $qry->row_array(); return [ 'status' => true, 'branchId' => $result['M_BranchID'], 'branchCode' => $result['M_BranchCode'] ]; } catch (Exception $exc) { $message = $exc->getMessage(); return [ 'status' => false, 'message' => $message ]; } } // curl public function post($url, $data) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Content-Type: application/text", "Content-Length: " . strlen($data), ]); $result = curl_exec($ch); if (curl_error($ch) != "") { echo json_encode([ "status" => "ERR", "message" => "Http Error : " . curl_error($ch), ]); curl_close($ch); exit(); } curl_close($ch); return $result; } public function get($url, $timeout = 60, $c_timeout = 5) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); $err_msg = curl_error($ch); if ($err_msg != "") { return json_encode(["status" => "ERR", "message" => $err_msg]); } return $result; } function log($msg) { // $dt = Date("Y-m-d H:i:s"); // echo "$dt $msg \n"; echo $msg; } function get_param_z() { $body_z = file_get_contents("php://input"); $body = gzuncompress($body_z); return json_decode($body, true); } function reply($resp) { echo json_encode($resp); } function reply_gz($resp) { //echo json_encode($resp); echo gzcompress(json_encode($resp)); } function download_confirm_order() { // $this->db->trans_begin(); $getBranch = $this->getBranch(); $branchId = $getBranch['branchId']; $branchCode = $getBranch['branchCode']; // $size = round(strlen($j_param) / 1024, 2); // $z_param = gzcompress($j_param, 9); // $size_z = round(strlen($z_param) / 1024, 2); $getIPRegionalAddress = $this->getRegionalIPAddress(); // $test_M_BranchCode = "LA"; $url = "http://$getIPRegionalAddress/one-api/app_doctor/Confirmorder/get_confirm_order/$branchCode"; // $url = "http://$getIPRegionalAddress/one-api/app_doctor/Confirmorder/get_confirm_order/$test_M_BranchCode"; // $this->log("Get to $url "); // $resp = $this->post($url, $z_param); $resp = $this->get($url); $j_resp = json_decode($resp, true); $j_resp_x = $this->get_param_z(); // print_r($j_resp); // print_r($resp); // print_r($j_resp_x); // print_r($j_resp['status']); $order_patient_id_str = ""; $total_updated = 0; if ($j_resp['status'] != "OK") { $this->sys_error($j_resp); exit; } else { $this->db->trans_begin(); $arr_order_patient_id = $j_resp['oneResultOrderPatientID']; if (count($arr_order_patient_id) > 0) { $order_patient_id_str = implode(",", $arr_order_patient_id); $sql_cek = "select OrderPatientID from one_doctor.order_patient left join one_doctor.order_fo ON OrderPatientID = OrderFoOrderPatientID WHERE OrderPatientIsActive = 'Y' AND OrderPatientID IN ($order_patient_id_str) AND (OrderFoIsActive IS NULL OR OrderFoIsActive = 'N')"; // echo $sql_cek; $qry = $this->db->query($sql_cek); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select order_fo by OrderPatientID", $this->db); exit; } $rows_order_cek = $qry->result_array(); // DEBUG // print_r($rows_order_cek); // echo $sql_cek; // $this->db->trans_rollback(); // exit; foreach ($rows_order_cek as $key => $value) { $order_patient_id = $value['OrderPatientID']; // ubah isActive jadi N di order_patient $sql_update_order_patient = "UPDATE one_doctor.order_patient SET OrderPatientIsActive = 'N' WHERE OrderPatientID IN ($order_patient_id) "; $qry_update_order_patient = $this->db->query($sql_update_order_patient); if (!$qry_update_order_patient) { $this->db->trans_rollback(); $this->sys_error_db("update one_doctor.order_patient ", $this->db); exit; } // update details $sql_update_order_patient_details = "UPDATE one_doctor.order_patient_details SET OrderPatientDetailsIsActive = 'N' WHERE OrderPatientDetailsOrderPatientID IN ($order_patient_id) "; $qry_update_order_patient_details = $this->db->query($sql_update_order_patient_details); if (!$qry_update_order_patient_details) { $this->db->trans_rollback(); $this->sys_error_db("update one_doctor.order_patient_details ", $this->db); exit; } $total_updated++; } } $this->db->trans_commit(); echo json_encode([ "status" => "OK", "message" => "data sudah diupdate $order_patient_id_str [$total_updated]", ]); } } function reply_err($message) { echo json_encode(["status" => "ERR", "data" => $message]); exit(); } }