Files
BE_IBL/scripts/remask_patient_name.php
sas.fajri 065e3ebb34 FHM31052601IBL - pdp masking & enkripsi patient di controller dan SP mcu
- mask_name nama satu kata: tampil 2 char + bintang sisanya
- masking + enkripsi insert/update m_patient di Registrationv3, ibl_registration/Patient, Patientv4, setupmcuoffline-ibl/Preregister, mcuoffline/Preregisterapp
- masking insert ke mcu_preregister_patients (PatientName, KTP, NIK, Email, Hp)
- search patient pakai bidx, decrypt setelah query di mcuoffline/Preregisterapp
- matching existing patient ganti LIKE ke bidx search
- SP sp_upsert_mcu_patient_by_preregister_id & sp_upsert_mcu_patient_by_mgm_mcuid JOIN m_patient ambil _enc, simpan ke one_lab_dashboard.mcu_patient
- ALTER mcu_patient.Mcu_PatientName dan Mcu_PatientDOB ke TEXT

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 20:10:15 +07:00

78 lines
2.2 KiB
PHP

<?php
/**
* Re-mask M_PatientName dengan format baru: "NAMA DEPAN I******* N****"
* Dekripsi dari _enc lalu masking ulang kolom plaintext
* Jalankan setelah address & NIK migration selesai
*/
define('BASEPATH', true);
foreach (file(__DIR__ . '/../.env', 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();
include __DIR__ . '/../application/config/database.php';
$cfg = $db['default'];
$pdo = new PDO(
"mysql:host={$cfg['hostname']};dbname={$cfg['database']};charset=utf8",
$cfg['username'], $cfg['password'],
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
function mask_name($v) {
if (!$v) return $v;
$v = trim($v);
$words = preg_split('/\s+/', $v);
if (count($words) === 1) {
$l = mb_strlen($v, 'UTF-8');
if ($l <= 2) return $v;
return mb_substr($v, 0, 2, 'UTF-8') . str_repeat('*', $l - 2);
}
$first = $words[0];
$rest = array_slice($words, 1);
$masked = array_map(function($w) {
if (!$w) return '';
$init = mb_substr($w, 0, 1, 'UTF-8');
return $init . str_repeat('*', max(3, mb_strlen($w, 'UTF-8') - 1));
}, $rest);
return $first . ' ' . implode(' ', $masked);
}
echo "=== Re-mask M_PatientName (format baru) ===\n";
$total = 0;
$batch = 500;
$last_id = 0;
$stmt = $pdo->prepare(
"UPDATE m_patient SET M_PatientName = ? WHERE M_PatientID = ?"
);
while (true) {
$rows = $pdo->query(
"SELECT M_PatientID, M_PatientName_enc
FROM m_patient
WHERE M_PatientName_enc IS NOT NULL
AND M_PatientID > {$last_id}
ORDER BY M_PatientID ASC
LIMIT {$batch}"
)->fetchAll(PDO::FETCH_ASSOC);
if (empty($rows)) break;
foreach ($rows as $row) {
$real_name = $enc->decrypt($row['M_PatientName_enc']);
if ($real_name !== null) {
$stmt->execute([mask_name($real_name), $row['M_PatientID']]);
}
$last_id = $row['M_PatientID'];
$total++;
}
echo " {$total} rows...\n";
}
echo "Selesai: {$total} rows\n";