- Ibl_patient_decrypt: helper populate/delete patient_print_cache + decrypt_row - Inform_consent, Medical_checkup_report: decrypt langsung dari _enc (direct SQL) - Kartu_kontrol, Rpt_t_002, Rpt_t_002_eng: populate cache sebelum call SP, delete cache setelah SP selesai Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
101 lines
4.5 KiB
PHP
101 lines
4.5 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Helper untuk decrypt PII pasien sebelum call SP/BIRT
|
|
* Populate patient_print_cache, run callback, delete cache
|
|
*/
|
|
class Ibl_patient_decrypt
|
|
{
|
|
private $db;
|
|
private $enc;
|
|
|
|
public function __construct()
|
|
{
|
|
$CI = &get_instance();
|
|
$this->db = $CI->load->database('onedev', true);
|
|
$CI->load->library('ibl_encryptor');
|
|
$this->enc = $CI->ibl_encryptor;
|
|
}
|
|
|
|
// Populate cache, return cache_id untuk cleanup
|
|
public function populate_cache_by_order($order_id)
|
|
{
|
|
$order_id = intval($order_id);
|
|
if (!$order_id) return null;
|
|
|
|
$patient = $this->db->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 = ? LIMIT 1",
|
|
[$order_id]
|
|
)->row_array();
|
|
|
|
if (!$patient) return null;
|
|
|
|
$addr = $this->db->query(
|
|
"SELECT M_PatientAddressDescription_enc FROM m_patientaddress
|
|
WHERE M_PatientAddressM_PatientID = ?
|
|
AND M_PatientAddressIsActive = 'Y'
|
|
AND M_PatientAddressNote = 'Utama'
|
|
LIMIT 1",
|
|
[$patient['M_PatientID']]
|
|
)->row_array();
|
|
|
|
$enc = $this->enc;
|
|
$this->_insert_cache(
|
|
$order_id,
|
|
$patient['M_PatientID'],
|
|
$enc->decrypt($patient['M_PatientName_enc'] ?? '') ?? '',
|
|
$enc->decrypt($patient['M_PatientDOB_enc'] ?? '') ?? date('d-m-Y', strtotime($patient['M_PatientDOB'] ?? 'now')),
|
|
$enc->decrypt($patient['M_PatientHP_enc'] ?? '') ?? '',
|
|
$enc->decrypt($patient['M_PatientEmail_enc']?? '') ?? '',
|
|
$enc->decrypt($addr['M_PatientAddressDescription_enc'] ?? '') ?? ''
|
|
);
|
|
|
|
return $this->db->insert_id();
|
|
}
|
|
|
|
// Decrypt langsung dari query result (untuk controller dengan SQL sendiri)
|
|
public function decrypt_row(array $row): array
|
|
{
|
|
$enc = $this->enc;
|
|
if (!empty($row['M_PatientName_enc'])) $row['M_PatientName'] = $enc->decrypt($row['M_PatientName_enc']) ?? $row['M_PatientName'] ?? '';
|
|
if (!empty($row['M_PatientDOB_enc'])) $row['M_PatientDOB'] = $enc->decrypt($row['M_PatientDOB_enc']) ?? $row['M_PatientDOB'] ?? '';
|
|
if (!empty($row['M_PatientHP_enc'])) $row['M_PatientHP'] = $enc->decrypt($row['M_PatientHP_enc']) ?? '';
|
|
if (!empty($row['M_PatientEmail_enc'])) $row['M_PatientEmail'] = $enc->decrypt($row['M_PatientEmail_enc']) ?? '';
|
|
if (!empty($row['M_PatientPOB_enc'])) $row['M_PatientPOB'] = $enc->decrypt($row['M_PatientPOB_enc']) ?? '';
|
|
if (!empty($row['M_PatientAddressDescription_enc'])) $row['M_PatientAddressDescription'] = $enc->decrypt($row['M_PatientAddressDescription_enc']) ?? '';
|
|
if (!empty($row['phone_enc'])) $row['phone'] = $enc->decrypt($row['phone_enc']) ?? '';
|
|
if (!empty($row['alamat_enc'])) $row['alamat'] = $enc->decrypt($row['alamat_enc']) ?? '';
|
|
if (!empty($row['dob_enc'])) $row['dob'] = $enc->decrypt($row['dob_enc']) ?? '';
|
|
foreach (array_keys($row) as $k) { if (substr($k, -4) === '_enc') unset($row[$k]); }
|
|
return $row;
|
|
}
|
|
|
|
// Hapus cache by id
|
|
public function delete_cache($cache_id)
|
|
{
|
|
if ($cache_id) {
|
|
$this->db->query("DELETE FROM patient_print_cache WHERE ppc_id = ?", [$cache_id]);
|
|
}
|
|
// Cleanup expired juga
|
|
$this->db->query("DELETE FROM patient_print_cache WHERE ppc_created < NOW() - INTERVAL 5 MINUTE");
|
|
}
|
|
|
|
private function _insert_cache($order_id, $patient_id, $name, $dob, $hp, $email, $address)
|
|
{
|
|
$this->db->query(
|
|
"DELETE FROM patient_print_cache WHERE ppc_order_id = ? OR ppc_created < NOW() - INTERVAL 5 MINUTE",
|
|
[$order_id]
|
|
);
|
|
$this->db->query(
|
|
"INSERT INTO patient_print_cache (ppc_order_id, ppc_patient_id, ppc_name, ppc_dob, ppc_hp, ppc_email, ppc_address, ppc_created)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, NOW())",
|
|
[$order_id, $patient_id, $name, $dob, $hp, $email, $address]
|
|
);
|
|
}
|
|
}
|