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:
@@ -440,59 +440,63 @@ class Rv_patient extends MY_Controller
|
|||||||
foreach ($rows['groups'] as $k => $v) {
|
foreach ($rows['groups'] as $k => $v) {
|
||||||
$ready_print = $v['ready_print'];
|
$ready_print = $v['ready_print'];
|
||||||
$gn = $v['group_name'];
|
$gn = $v['group_name'];
|
||||||
|
|
||||||
// MAPPING GROUP NAME KE REPORT CODE
|
|
||||||
$report_codes = $this->get_report_codes_by_group($gn);
|
$report_codes = $this->get_report_codes_by_group($gn);
|
||||||
|
|
||||||
if ($report_codes) {
|
if ($report_codes) {
|
||||||
// Gunakan database untuk ambil report name
|
$rpt_code = $ready_print == 'Y' ? $report_codes['P'] : ($report_codes['NP'] ?? $report_codes['P']);
|
||||||
$rpt = $this->get_report_name_from_db($report_codes['P'], $ready_print);
|
$e_rpt_code = $ready_print == 'Y' ? ($report_codes['E'] ?? $report_codes['P']) : ($report_codes['NE'] ?? $report_codes['NP'] ?? $report_codes['E'] ?? $report_codes['P']);
|
||||||
$e_rpt = $this->get_report_name_from_db($report_codes['E'], $ready_print);
|
$rptq_code = $ready_print == 'Y' ? ($report_codes['Q'] ?? $report_codes['P']) : ($report_codes['NQ'] ?? $report_codes['NP'] ?? $report_codes['P']);
|
||||||
$rptqrcode = isset($report_codes['Q']) ? $this->get_report_name_from_db($report_codes['Q'], $ready_print) : '';
|
|
||||||
|
$rpt = $this->get_report_name_from_code($rpt_code);
|
||||||
// Jika QR tidak ada, gunakan P
|
$e_rpt = $this->get_report_name_from_code($e_rpt_code);
|
||||||
if (empty($rptqrcode)) {
|
$rptqrcode = $this->get_report_name_from_code($rptq_code);
|
||||||
$rptqrcode = $rpt;
|
if (empty($rptqrcode)) $rptqrcode = $rpt;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// FALLBACK untuk group yang belum ada di database
|
$rpt_code = $e_rpt_code = '';
|
||||||
$rpt = $this->get_fallback_report($gn, 'P', $ready_print);
|
$rpt = $this->get_fallback_report($gn, 'P', $ready_print);
|
||||||
$e_rpt = $this->get_fallback_report($gn, 'E', $ready_print);
|
$e_rpt = $this->get_fallback_report($gn, 'E', $ready_print);
|
||||||
$rptqrcode = $this->get_fallback_report($gn, 'Q', $ready_print);
|
$rptqrcode = $this->get_fallback_report($gn, 'Q', $ready_print);
|
||||||
if (empty($rptqrcode)) $rptqrcode = $rpt;
|
if (empty($rptqrcode)) $rptqrcode = $rpt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOGIC KHUSUS MIKRO
|
// LOGIC KHUSUS MIKRO
|
||||||
if ($gn == 'Mikro') {
|
if ($gn == 'Mikro') {
|
||||||
$sql = "SELECT T_OrderDetailResult as result
|
$sql = "SELECT T_OrderDetailResult as result
|
||||||
FROM t_orderdetail
|
FROM t_orderdetail
|
||||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
|
||||||
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y'
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_OrderDetailT_TestID AND Group_ResultDetailIsActive = 'Y'
|
||||||
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' AND
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N' AND
|
||||||
Group_ResultName = 'Mikro'
|
Group_ResultName = 'Mikro'
|
||||||
WHERE T_OrderDetailID = {$v['id']} AND T_OrderDetailIsActive = 'Y' LIMIT 1";
|
WHERE T_OrderDetailID = {$v['id']} AND T_OrderDetailIsActive = 'Y' LIMIT 1";
|
||||||
|
|
||||||
$xresult = $this->db_smartone->query($sql)->row()->result;
|
$xresult = $this->db_smartone->query($sql)->row()->result;
|
||||||
|
|
||||||
if ($xresult != 'Terlampir') {
|
if ($xresult != 'Terlampir') {
|
||||||
$rpt = $this->get_report_name_from_db('LAB-RESULT-P-01', $ready_print);
|
$rpt_code = $ready_print == 'Y' ? 'LAB-RESULT-P-01' : 'LAB-RESULT-NP-01';
|
||||||
$e_rpt = $this->get_report_name_from_db('LAB-RESULT-E-01', $ready_print);
|
$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') {
|
if ($xresult == 'Terlampir' && $exist_lab == 'N') {
|
||||||
$rows['groups'][$k]['group_name'] = 'Lampiran Mikro';
|
$rows['groups'][$k]['group_name'] = 'Lampiran Mikro';
|
||||||
$new_group = $rows['groups'][$k];
|
$new_group = $rows['groups'][$k];
|
||||||
$new_group['group_name'] = 'Mikro';
|
$new_group['group_name'] = 'Mikro';
|
||||||
$new_group['rpt'] = $this->get_report_name_from_db('LAB-RESULT-P-01', 'Y');
|
$new_group['rpt_code'] = 'LAB-RESULT-P-01';
|
||||||
$new_group['e_rpt'] = $this->get_report_name_from_db('LAB-RESULT-E-01', 'Y');
|
$new_group['e_rpt_code'] = 'LAB-RESULT-P-02';
|
||||||
$new_group['rptqrcode'] = $new_group['rpt'];
|
$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);
|
array_push($rows['groups'], $new_group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows['groups'][$k]['rpt'] = $rpt;
|
$rows['groups'][$k]['rpt'] = $rpt;
|
||||||
$rows['groups'][$k]['e_rpt'] = $e_rpt;
|
$rows['groups'][$k]['e_rpt'] = $e_rpt;
|
||||||
$rows['groups'][$k]['rptqrcode'] = $rptqrcode;
|
$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';
|
$rows['groups'][0]['selected'] = 'Y';
|
||||||
@@ -529,43 +533,55 @@ class Rv_patient extends MY_Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function get_report_codes_by_group($group_name)
|
private function get_report_codes_by_group($group_name)
|
||||||
{
|
{
|
||||||
$mapping = [
|
// P = siap cetak, NP = belum siap cetak, E = email siap, NE = email belum siap
|
||||||
'LAB' => ['P' => 'LAB-RESULT-P-01', 'E' => 'LAB-RESULT-E-01', 'Q' => 'LAB-RESULT-Q-01'],
|
$mapping = [
|
||||||
'LAB_EN' => ['P' => 'LAB-RESULT-EN-P-01', 'E' => 'LAB-RESULT-EN-E-01'],
|
'LAB' => ['P' => 'LAB-RESULT-P-01', 'NP' => 'LAB-RESULT-NP-01', 'E' => 'LAB-RESULT-P-02', 'NE' => 'LAB-RESULT-NP-02'],
|
||||||
'Mikro_EN' => ['P' => 'LAB-RESULT-EN-P-01', 'E' => 'LAB-RESULT-EN-E-01'],
|
'LAB_EN' => ['P' => 'LABEN-RESULT-P-01', 'NP' => 'LABEN-RESULT-NP-01', 'E' => 'LABEN-RESULT-P-02'],
|
||||||
'FNA' => ['P' => 'FNA-P-01', 'E' => 'FNA-E-01'],
|
'Mikro' => ['P' => 'MIKRO-RESULT-P-01', 'NP' => 'MIKRO-RESULT-NP-01', 'E' => 'MIKRO-RESULT-P-02'],
|
||||||
'Patologi Anatomi' => ['P' => 'PA-P-01', 'E' => 'PA-E-01'],
|
'Mikro_EN' => ['P' => 'MIKROEN-RESULT-P-01', 'NP' => 'MIKROEN-RESULT-NP-01', 'E' => 'MIKROEN-RESULT-P-02'],
|
||||||
'Papsmear' => ['P' => 'PAP-P-01', 'E' => 'PAP-E-01'],
|
'FNA' => ['P' => 'FNA-RESULT-P-01', 'NP' => 'FNA-RESULT-NP-01', 'E' => 'FNA-RESULT-P-02'],
|
||||||
'Pap Smear (Liquid C Prep)' => ['P' => 'LCP-P-01', 'E' => 'LCP-E-01', 'Q' => 'LCP-Q-01'],
|
'Patologi Anatomi' => ['P' => 'PA-RESULT-P-01', 'NP' => 'PA-RESULT-NP-01', 'E' => 'PA-RESULT-P-02'],
|
||||||
'Pap Smear (Liquid C Prep)_EN' => ['P' => 'LCP-P-01', 'E' => 'LCP-E-01', 'Q' => 'LCP-Q-01'],
|
'Papsmear' => ['P' => 'PAP-RESULT-P-01', 'NP' => 'PAP-RESULT-NP-01', 'E' => 'PAP-RESULT-P-02'],
|
||||||
'Papsmear_EN' => ['P' => 'LCP-P-01', 'E' => 'LCP-E-01', 'Q' => 'LCP-Q-01']
|
'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'],
|
||||||
return isset($mapping[$group_name]) ? $mapping[$group_name] : null;
|
'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'],
|
||||||
|
];
|
||||||
|
|
||||||
private function get_report_name_from_db($report_code, $ready_print = 'Y')
|
return $mapping[$group_name] ?? null;
|
||||||
{
|
}
|
||||||
if (empty($report_code)) return '';
|
|
||||||
|
private function get_report_name_from_code($report_code)
|
||||||
$sql = "SELECT Print_TransactionUrl FROM print_transaction WHERE Print_TransactionCode = ? LIMIT 1";
|
{
|
||||||
$row = $this->db_smartone->query($sql, [$report_code])->row();
|
if (empty($report_code)) return '';
|
||||||
|
$row = $this->db_smartone->query(
|
||||||
if (!$row) return '';
|
"SELECT Print_TransactionUrl FROM print_transaction WHERE Print_TransactionCode = ? LIMIT 1",
|
||||||
|
[$report_code]
|
||||||
// Extract report name from URL
|
)->row();
|
||||||
$url = $row->Print_TransactionUrl;
|
if (!$row) return '';
|
||||||
preg_match('/\/([^\/]+)\.rptdesign/', $url, $matches);
|
preg_match('/\/([^\/]+)\.rptdesign/', $row->Print_TransactionUrl, $matches);
|
||||||
$report_name = isset($matches[1]) ? $matches[1] : '';
|
return $matches[1] ?? '';
|
||||||
|
}
|
||||||
// Tambahkan suffix jika belum ready print
|
|
||||||
if ($ready_print != 'Y' && !empty($report_name)) {
|
private function get_report_name_from_db($report_code, $ready_print = 'Y')
|
||||||
$report_name .= '_not_print';
|
{
|
||||||
}
|
if (empty($report_code)) return '';
|
||||||
|
$row = $this->db_smartone->query(
|
||||||
return $report_name;
|
"SELECT Print_TransactionUrl FROM print_transaction WHERE Print_TransactionCode = ? LIMIT 1",
|
||||||
}
|
[$report_code]
|
||||||
|
)->row();
|
||||||
|
if (!$row) return '';
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
private function get_fallback_report($group_name, $type, $ready_print)
|
private function get_fallback_report($group_name, $type, $ready_print)
|
||||||
{
|
{
|
||||||
@@ -1069,39 +1085,4 @@ private function get_fallback_report($group_name, $type, $ready_print)
|
|||||||
exit;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user