diff --git a/application/controllers/tools/Birt_proxy.php b/application/controllers/tools/Birt_proxy.php index 6bf847ae..7aa7bf68 100644 --- a/application/controllers/tools/Birt_proxy.php +++ b/application/controllers/tools/Birt_proxy.php @@ -185,40 +185,24 @@ class Birt_proxy extends MY_Controller $prm = $this->sys_input; $report_code = $prm['report_code'] ?? ''; $order_id = intval($prm['PT_OrderHeaderID'] ?? 0); - $username = $prm['PUsername'] ?? ($this->sys_user['userName'] ?? 'system'); - $tm = round(microtime(true) * 1000); - - $internal_url = $this->_build_internal_report_url_by_code($report_code, $order_id); - if ($internal_url !== false) { - if ($order_id > 0) { - $this->_populate_cache($order_id); + $patient_name = ''; + if ($order_id > 0) { + $cache_id = $this->_populate_cache($order_id); + $patient_name = $this->_resolve_patient_name_by_cache($cache_id); + if ($patient_name === '') { + $patient_name = $this->_resolve_patient_name_by_order($order_id); + } + if ($patient_name === '') { + $patient_name = $this->_resolve_patient_name_from_enc_by_order($order_id); } - - $this->sys_ok(['url' => $internal_url]); - return; } - $row = $this->db_onedev->query( - "SELECT Print_TransactionUrl FROM print_transaction WHERE Print_TransactionCode = ? LIMIT 1", - [$report_code] - )->row_array(); - - if (!$row) { + $url = $this->_build_birt_url_by_code($report_code, $order_id, 0, $patient_name); + if ($url === false) { $this->sys_error("Report code tidak ditemukan: {$report_code}"); return; } - $url = $row['Print_TransactionUrl']; - $url = str_replace('PT_OrderHeaderID', $order_id, $url); - $url = str_replace('PUsername', urlencode($username), $url); - $url = str_replace('TS', $tm, $url); - - // Pre-populate cache — frontend buka URL langsung ke BIRT - // Cache hidup 5 menit, cukup untuk BIRT generate PDF - if ($order_id > 0) { - $this->_populate_cache($order_id); - } - $this->sys_ok(['url' => $url]); } @@ -410,11 +394,6 @@ class Birt_proxy extends MY_Controller private function _build_birt_url_by_code($report_code, $order_id, $payment_id, $patient_name) { - $internal_url = $this->_build_internal_report_url_by_code($report_code, $order_id); - if ($internal_url !== false) { - return $internal_url; - } - $row = $this->db_onedev->query( "SELECT Print_TransactionUrl FROM print_transaction @@ -453,28 +432,6 @@ class Birt_proxy extends MY_Controller return $url; } - private function _build_internal_report_url_by_code($report_code, $order_id) - { - $report_routes = [ - 'LAB-RESULT-P-01' => '/tools/rpt_lab_result/pdf', - ]; - - if (!isset($report_routes[$report_code]) || $order_id <= 0) { - return false; - } - - $params = [ - 'PT_OrderHeaderID' => $order_id, - 'username' => $this->_resolve_report_username(), - ]; - - if (!empty($this->sys_input['token'])) { - $params['token'] = $this->sys_input['token']; - } - - return $report_routes[$report_code] . '?' . http_build_query($params); - } - private function _apply_report_template_hotfix($report_code, $url_template) { $print_report_hotfix = [ @@ -494,7 +451,13 @@ class Birt_proxy extends MY_Controller $hotfix = $print_report_hotfix[$report_code]; - return str_replace($hotfix['from'], $hotfix['to'], $url_template); + $resolved_url = str_replace($hotfix['from'], $hotfix['to'], $url_template); + + if (strpos($resolved_url, 'username=') === false) { + $resolved_url .= (strpos($resolved_url, '?') === false ? '?' : '&') . 'username=PUsername'; + } + + return $resolved_url; } // GET /tools/birt_proxy/header_json?PID=