FHM31052601IBL - populate decrypt cache sebelum semua BIRT/PDF fetch
- Ibl_patient_decrypt: tambah fetch_birt_pdf() + pre_cache_and_get_url() - Reporturl.php: auto pre-cache sebelum return URL atau fetch PDF - Rv_patient.php: pre_cache sebelum return URL ke frontend - tgram/Hasil.php: fetch_birt_pdf() via dl_report() - Qr_report_uploader.php: populate/delete cache wrapping download_file() - Ibl_merge_report_gateway.php: populate/delete cache wrapping Go merge service call - send_email.php: populate_birt_cache() + delete_birt_cache() untuk email attachment Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -60,6 +60,58 @@ function download_pdf(string $url)
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Load ibl_encryptor untuk decrypt PII sebelum fetch PDF dari BIRT
|
||||
define('BASEPATH', true);
|
||||
$_env_file = __DIR__ . '/../.env';
|
||||
if (file_exists($_env_file)) {
|
||||
foreach (file($_env_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $_l) {
|
||||
if (strpos(trim($_l), '#') === 0) continue;
|
||||
[$_k, $_v] = array_map('trim', explode('=', $_l, 2));
|
||||
if ($_k !== '') $_ENV[$_k] = $_v;
|
||||
}
|
||||
}
|
||||
require __DIR__ . '/../application/libraries/Ibl_encryptor.php';
|
||||
$_enc = new Ibl_encryptor();
|
||||
|
||||
// Populate patient_print_cache sebelum fetch PDF dari BIRT
|
||||
function populate_birt_cache(PDO $pdo, $enc, string $birt_url): ?int
|
||||
{
|
||||
parse_str(parse_url($birt_url, PHP_URL_QUERY) ?? '', $params);
|
||||
$order_id = intval($params['PID'] ?? 0);
|
||||
if (!$order_id) return null;
|
||||
|
||||
$patient = $pdo->query(
|
||||
"SELECT M_PatientID, M_PatientName_enc, M_PatientDOB_enc,
|
||||
M_PatientHP_enc, M_PatientEmail_enc, M_PatientDOB
|
||||
FROM t_orderheader
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
WHERE T_OrderHeaderID = {$order_id} LIMIT 1"
|
||||
)->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$patient) return null;
|
||||
|
||||
$addr = $pdo->query(
|
||||
"SELECT M_PatientAddressDescription_enc FROM m_patientaddress
|
||||
WHERE M_PatientAddressM_PatientID = {$patient['M_PatientID']}
|
||||
AND M_PatientAddressIsActive = 'Y' AND M_PatientAddressNote = 'Utama' LIMIT 1"
|
||||
)->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$name = $enc->decrypt($patient['M_PatientName_enc'] ?? '') ?? '';
|
||||
$dob = $enc->decrypt($patient['M_PatientDOB_enc'] ?? '') ?? date('d-m-Y', strtotime($patient['M_PatientDOB'] ?? 'now'));
|
||||
$hp = $enc->decrypt($patient['M_PatientHP_enc'] ?? '') ?? '';
|
||||
$email = $enc->decrypt($patient['M_PatientEmail_enc']?? '') ?? '';
|
||||
$address = $enc->decrypt($addr['M_PatientAddressDescription_enc'] ?? '') ?? '';
|
||||
|
||||
$pdo->exec("DELETE FROM patient_print_cache WHERE ppc_order_id = {$order_id} OR ppc_created < NOW() - INTERVAL 5 MINUTE");
|
||||
$stmt = $pdo->prepare("INSERT INTO patient_print_cache (ppc_order_id, ppc_patient_id, ppc_name, ppc_dob, ppc_hp, ppc_email, ppc_address) VALUES (?,?,?,?,?,?,?)");
|
||||
$stmt->execute([$order_id, $patient['M_PatientID'], $name, $dob, $hp, $email, $address]);
|
||||
return (int)$pdo->lastInsertId();
|
||||
}
|
||||
|
||||
function delete_birt_cache(PDO $pdo, ?int $cache_id): void
|
||||
{
|
||||
if ($cache_id) $pdo->exec("DELETE FROM patient_print_cache WHERE ppc_id = {$cache_id}");
|
||||
}
|
||||
|
||||
function encrypt_pdf(string $input_path, string $password)
|
||||
{
|
||||
$output_path = $input_path . '_enc.pdf';
|
||||
@@ -308,7 +360,9 @@ foreach ($rows as $row) {
|
||||
|
||||
log_msg(" Downloading attachment " . ($idx + 1) . " [{$result}]: {$url}");
|
||||
|
||||
$cache_id = populate_birt_cache($pdo, $GLOBALS['_enc'], $url);
|
||||
$pdf = download_pdf($url);
|
||||
delete_birt_cache($pdo, $cache_id);
|
||||
if ($pdf === false) {
|
||||
log_msg(" Download failed, skipping");
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user