FHM08062601IBL - fix get_report_codes_by_group pakai kode print_transaction yg benar, tambah rpt_code/e_rpt_code di groups output untuk stream_by_code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sas.fajri
2026-06-08 16:43:14 +07:00
parent 7e3cd75ce5
commit 212e27ff72

View File

@@ -441,21 +441,19 @@ class Rv_patient extends MY_Controller
$ready_print = $v['ready_print'];
$gn = $v['group_name'];
// MAPPING GROUP NAME KE REPORT CODE
$report_codes = $this->get_report_codes_by_group($gn);
if ($report_codes) {
// Gunakan database untuk ambil report name
$rpt = $this->get_report_name_from_db($report_codes['P'], $ready_print);
$e_rpt = $this->get_report_name_from_db($report_codes['E'], $ready_print);
$rptqrcode = isset($report_codes['Q']) ? $this->get_report_name_from_db($report_codes['Q'], $ready_print) : '';
$rpt_code = $ready_print == 'Y' ? $report_codes['P'] : ($report_codes['NP'] ?? $report_codes['P']);
$e_rpt_code = $ready_print == 'Y' ? ($report_codes['E'] ?? $report_codes['P']) : ($report_codes['NE'] ?? $report_codes['NP'] ?? $report_codes['E'] ?? $report_codes['P']);
$rptq_code = $ready_print == 'Y' ? ($report_codes['Q'] ?? $report_codes['P']) : ($report_codes['NQ'] ?? $report_codes['NP'] ?? $report_codes['P']);
// Jika QR tidak ada, gunakan P
if (empty($rptqrcode)) {
$rptqrcode = $rpt;
}
$rpt = $this->get_report_name_from_code($rpt_code);
$e_rpt = $this->get_report_name_from_code($e_rpt_code);
$rptqrcode = $this->get_report_name_from_code($rptq_code);
if (empty($rptqrcode)) $rptqrcode = $rpt;
} else {
// FALLBACK untuk group yang belum ada di database
$rpt_code = $e_rpt_code = '';
$rpt = $this->get_fallback_report($gn, 'P', $ready_print);
$e_rpt = $this->get_fallback_report($gn, 'E', $ready_print);
$rptqrcode = $this->get_fallback_report($gn, 'Q', $ready_print);
@@ -475,16 +473,20 @@ class Rv_patient extends MY_Controller
$xresult = $this->db_smartone->query($sql)->row()->result;
if ($xresult != 'Terlampir') {
$rpt = $this->get_report_name_from_db('LAB-RESULT-P-01', $ready_print);
$e_rpt = $this->get_report_name_from_db('LAB-RESULT-E-01', $ready_print);
$rpt_code = $ready_print == 'Y' ? 'LAB-RESULT-P-01' : 'LAB-RESULT-NP-01';
$e_rpt_code = $ready_print == 'Y' ? 'LAB-RESULT-P-02' : 'LAB-RESULT-NP-02';
$rpt = $this->get_report_name_from_code($rpt_code);
$e_rpt = $this->get_report_name_from_code($e_rpt_code);
}
if ($xresult == 'Terlampir' && $exist_lab == 'N') {
$rows['groups'][$k]['group_name'] = 'Lampiran Mikro';
$new_group = $rows['groups'][$k];
$new_group['group_name'] = 'Mikro';
$new_group['rpt'] = $this->get_report_name_from_db('LAB-RESULT-P-01', 'Y');
$new_group['e_rpt'] = $this->get_report_name_from_db('LAB-RESULT-E-01', 'Y');
$new_group['rpt_code'] = 'LAB-RESULT-P-01';
$new_group['e_rpt_code'] = 'LAB-RESULT-P-02';
$new_group['rpt'] = $this->get_report_name_from_code('LAB-RESULT-P-01');
$new_group['e_rpt'] = $this->get_report_name_from_code('LAB-RESULT-P-02');
$new_group['rptqrcode'] = $new_group['rpt'];
array_push($rows['groups'], $new_group);
}
@@ -493,6 +495,8 @@ class Rv_patient extends MY_Controller
$rows['groups'][$k]['rpt'] = $rpt;
$rows['groups'][$k]['e_rpt'] = $e_rpt;
$rows['groups'][$k]['rptqrcode'] = $rptqrcode;
$rows['groups'][$k]['rpt_code'] = $rpt_code;
$rows['groups'][$k]['e_rpt_code'] = $e_rpt_code;
}
$rows['groups'][0]['selected'] = 'Y';
@@ -530,40 +534,52 @@ class Rv_patient extends MY_Controller
private function get_report_codes_by_group($group_name)
{
// P = siap cetak, NP = belum siap cetak, E = email siap, NE = email belum siap
$mapping = [
'LAB' => ['P' => 'LAB-RESULT-P-01', 'E' => 'LAB-RESULT-E-01', 'Q' => 'LAB-RESULT-Q-01'],
'LAB_EN' => ['P' => 'LAB-RESULT-EN-P-01', 'E' => 'LAB-RESULT-EN-E-01'],
'Mikro_EN' => ['P' => 'LAB-RESULT-EN-P-01', 'E' => 'LAB-RESULT-EN-E-01'],
'FNA' => ['P' => 'FNA-P-01', 'E' => 'FNA-E-01'],
'Patologi Anatomi' => ['P' => 'PA-P-01', 'E' => 'PA-E-01'],
'Papsmear' => ['P' => 'PAP-P-01', 'E' => 'PAP-E-01'],
'Pap Smear (Liquid C Prep)' => ['P' => 'LCP-P-01', 'E' => 'LCP-E-01', 'Q' => 'LCP-Q-01'],
'Pap Smear (Liquid C Prep)_EN' => ['P' => 'LCP-P-01', 'E' => 'LCP-E-01', 'Q' => 'LCP-Q-01'],
'Papsmear_EN' => ['P' => 'LCP-P-01', 'E' => 'LCP-E-01', 'Q' => 'LCP-Q-01']
'LAB' => ['P' => 'LAB-RESULT-P-01', 'NP' => 'LAB-RESULT-NP-01', 'E' => 'LAB-RESULT-P-02', 'NE' => 'LAB-RESULT-NP-02'],
'LAB_EN' => ['P' => 'LABEN-RESULT-P-01', 'NP' => 'LABEN-RESULT-NP-01', 'E' => 'LABEN-RESULT-P-02'],
'Mikro' => ['P' => 'MIKRO-RESULT-P-01', 'NP' => 'MIKRO-RESULT-NP-01', 'E' => 'MIKRO-RESULT-P-02'],
'Mikro_EN' => ['P' => 'MIKROEN-RESULT-P-01', 'NP' => 'MIKROEN-RESULT-NP-01', 'E' => 'MIKROEN-RESULT-P-02'],
'FNA' => ['P' => 'FNA-RESULT-P-01', 'NP' => 'FNA-RESULT-NP-01', 'E' => 'FNA-RESULT-P-02'],
'Patologi Anatomi' => ['P' => 'PA-RESULT-P-01', 'NP' => 'PA-RESULT-NP-01', 'E' => 'PA-RESULT-P-02'],
'Papsmear' => ['P' => 'PAP-RESULT-P-01', 'NP' => 'PAP-RESULT-NP-01', 'E' => 'PAP-RESULT-P-02'],
'Pap Smear (Liquid C Prep)' => ['P' => 'PAPLCP-RESULT-P-01', 'NP' => 'PAPLCP-RESULT-NP-01', 'E' => 'PAPLCP-RESULT-P-02'],
'Pap Smear (Liquid C Prep)_EN' => ['P' => 'PAPLEN-RESULT-P-01', 'NP' => 'PAPLEN-RESULT-NP-01', 'E' => 'PAPLEN-RESULT-P-02'],
'Papsmear_EN' => ['P' => 'PAPLEN-RESULT-P-01', 'NP' => 'PAPLEN-RESULT-NP-01', 'E' => 'PAPLEN-RESULT-P-02'],
'Preparasi Sperma' => ['P' => 'PS-RESULT-P-01', 'NP' => 'PS-RESULT-NP-01', 'E' => 'PS-RESULT-P-02'],
'dfi' => ['P' => 'DFI-RESULT-P-01', 'NP' => 'DFI-RESULT-NP-01', 'E' => 'DFI-RESULT-P-02'],
'DFI' => ['P' => 'DFI-RESULT-P-01', 'NP' => 'DFI-RESULT-NP-01', 'E' => 'DFI-RESULT-P-02'],
'Cytologi' => ['P' => 'CT-RESULT-P-01', 'NP' => 'CT-RESULT-NP-01', 'E' => 'CT-RESULT-P-02'],
];
return isset($mapping[$group_name]) ? $mapping[$group_name] : null;
return $mapping[$group_name] ?? null;
}
private function get_report_name_from_code($report_code)
{
if (empty($report_code)) return '';
$row = $this->db_smartone->query(
"SELECT Print_TransactionUrl FROM print_transaction WHERE Print_TransactionCode = ? LIMIT 1",
[$report_code]
)->row();
if (!$row) return '';
preg_match('/\/([^\/]+)\.rptdesign/', $row->Print_TransactionUrl, $matches);
return $matches[1] ?? '';
}
private function get_report_name_from_db($report_code, $ready_print = 'Y')
{
if (empty($report_code)) return '';
$sql = "SELECT Print_TransactionUrl FROM print_transaction WHERE Print_TransactionCode = ? LIMIT 1";
$row = $this->db_smartone->query($sql, [$report_code])->row();
$row = $this->db_smartone->query(
"SELECT Print_TransactionUrl FROM print_transaction WHERE Print_TransactionCode = ? LIMIT 1",
[$report_code]
)->row();
if (!$row) return '';
// Extract report name from URL
$url = $row->Print_TransactionUrl;
preg_match('/\/([^\/]+)\.rptdesign/', $url, $matches);
$report_name = isset($matches[1]) ? $matches[1] : '';
// Tambahkan suffix jika belum ready print
preg_match('/\/([^\/]+)\.rptdesign/', $row->Print_TransactionUrl, $matches);
$report_name = $matches[1] ?? '';
if ($ready_print != 'Y' && !empty($report_name)) {
$report_name .= '_not_print';
}
return $report_name;
}
@@ -1069,39 +1085,4 @@ private function get_fallback_report($group_name, $type, $ready_print)
exit;
}
public function stream_report()
{
$prm = $this->sys_input;
$order_id = intval($prm['order_id'] ?? 0);
$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;
}
$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;
}
$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;
}
}