From 7e3cd75ce526c7f435781c7bcb7850bfee73dca1 Mon Sep 17 00:00:00 2001 From: "sas.fajri" Date: Mon, 8 Jun 2026 16:34:40 +0700 Subject: [PATCH] FHM08062601IBL - ganti pre_cache/delete_cache dengan proxy stream pattern: Reporturl semua kode lewat stream_by_code, tambah stream_report di Rv_patient untuk resultprintadm-v7 Co-Authored-By: Claude Sonnet 4.6 --- .../process/resultprintadm-v7/Rv_patient.php | 49 ++++++++++--------- application/libraries/Reporturl.php | 14 +----- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/application/controllers/mockup/process/resultprintadm-v7/Rv_patient.php b/application/controllers/mockup/process/resultprintadm-v7/Rv_patient.php index d8d20a54..0d445cb2 100644 --- a/application/controllers/mockup/process/resultprintadm-v7/Rv_patient.php +++ b/application/controllers/mockup/process/resultprintadm-v7/Rv_patient.php @@ -1069,34 +1069,39 @@ private function get_fallback_report($group_name, $type, $ready_print) exit; } - public function pre_cache() + public function stream_report() { - $prm = $this->sys_input; + $prm = $this->sys_input; $order_id = intval($prm['order_id'] ?? 0); - if ($order_id <= 0) { - $this->sys_ok(['cached' => false]); + $rptname = preg_replace('/[^a-zA-Z0-9_\-]/', '', $prm['rptname'] ?? ''); + $folder = preg_replace('/[^a-zA-Z0-9_\-]/', '', $prm['folder'] ?? 'lab'); + $atr = ($prm['atr_print'] ?? 'frameset') === 'run' ? 'run' : 'frameset'; + + if ($order_id <= 0 || $rptname === '') { + $this->sys_error('order_id dan rptname wajib diisi'); return; } - $this->load->library('ibl_patient_decrypt'); - $this->ibl_patient_decrypt->populate_cache_by_order($order_id); - $this->sys_ok(['cached' => true]); - } - public function delete_cache() - { - $prm = $this->sys_input; - $order_id = intval($prm['order_id'] ?? 0); - if ($order_id > 0) { - $this->db_smartone->query( - "DELETE FROM patient_print_cache WHERE ppc_order_id = ? OR ppc_created < NOW() - INTERVAL 5 MINUTE", - [$order_id] - ); - } else { - $this->db_smartone->query( - "DELETE FROM patient_print_cache WHERE ppc_created < NOW() - INTERVAL 5 MINUTE" - ); + $user = $this->sys_user['M_StaffName'] ?? $this->sys_user['M_UserUsername'] ?? 'system'; + $tm = round(microtime(true) * 1000); + $birt_url = '/birt/' . $atr . '?__report=report/onelab/' . $folder . '/' . $rptname + . '.rptdesign&__format=pdf&username=' . rawurlencode("'" . $user . "'") + . '&PID=' . $order_id . '&tm=' . $tm; + + $this->load->library('ibl_patient_decrypt'); + $pdf = $this->ibl_patient_decrypt->fetch_birt_pdf($birt_url); + + if ($pdf === false || $pdf === '') { + $this->sys_error('Gagal generate report dari BIRT server'); + return; } - $this->sys_ok(['deleted' => true]); + + $filename = $rptname . '_' . $order_id . '_' . date('Ymd') . '.pdf'; + header('Content-Type: application/pdf'); + header('Content-Disposition: inline; filename="' . $filename . '"'); + header('Content-Length: ' . strlen($pdf)); + echo $pdf; + exit; } } \ No newline at end of file diff --git a/application/libraries/Reporturl.php b/application/libraries/Reporturl.php index 44e4363f..383bb09b 100644 --- a/application/libraries/Reporturl.php +++ b/application/libraries/Reporturl.php @@ -56,14 +56,7 @@ class Reporturl } if($show == 'N'){ - if ($this->should_use_proxy_stream($report_code)) { - return array(true, $this->build_proxy_stream_url($report_code, $params)); - } - - // Populate decrypt cache sebelum return URL raw ke browser - $CI->load->library('ibl_patient_decrypt'); - $CI->ibl_patient_decrypt->pre_cache_and_get_url($final_url); - return array(true, $final_url); + return array(true, $this->build_proxy_stream_url($report_code, $params)); } else{ $CI->load->library('ibl_patient_decrypt'); @@ -74,11 +67,6 @@ class Reporturl } } - private function should_use_proxy_stream($report_code) - { - return strpos((string)$report_code, 'FO-') === 0; - } - private function build_proxy_stream_url($report_code, $params = array()) { $CI = &get_instance();