FHM31052601IBL - search patient by nama/HP/DOB/NIK, hapus address bidx, tambah NIK bidx

- Search sekarang: nama, HP, DOB, NIK (alamat dihapus - boros disk)
- Tambah M_PatientNIK_bidx untuk search by NIK
- Migration script: NIK bidx + hapus address bidx dari m_patientaddress

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sas.fajri
2026-05-31 15:15:33 +07:00
parent 5350ab51cc
commit a2d69d1618
3 changed files with 19 additions and 13 deletions

View File

@@ -92,7 +92,7 @@ class Patient extends MY_Controller
$where_name = ''; $where_name = '';
$where_hp = ''; $where_hp = '';
$where_dob = ''; $where_dob = '';
$where_addr = "AND M_PatientAddressNote = 'Utama'"; $where_nik = '';
if (!empty($prm['noreg'])) { if (!empty($prm['noreg'])) {
$noreg = $this->db_smartone->escape_like_str($prm['noreg']); $noreg = $this->db_smartone->escape_like_str($prm['noreg']);
@@ -102,7 +102,7 @@ class Patient extends MY_Controller
if (!empty($prm['search'])) { if (!empty($prm['search'])) {
$e = explode('+', $prm['search']); $e = explode('+', $prm['search']);
// name — trigram blind index (min 3 karakter) // nama — trigram blind index (min 3 karakter)
if (!empty($e[0]) && mb_strlen(trim($e[0])) >= 3) { if (!empty($e[0]) && mb_strlen(trim($e[0])) >= 3) {
$toks = $this->ibl_encryptor->query_tokens($e[0]); $toks = $this->ibl_encryptor->query_tokens($e[0]);
$conds = []; $conds = [];
@@ -135,15 +135,15 @@ class Patient extends MY_Controller
if ($conds) $where_dob = 'AND (' . implode(' AND ', $conds) . ')'; if ($conds) $where_dob = 'AND (' . implode(' AND ', $conds) . ')';
} }
// address — trigram blind index // nik — trigram blind index
if (!empty($e[3]) && mb_strlen(trim($e[3])) >= 3) { if (!empty($e[3]) && mb_strlen(trim($e[3])) >= 3) {
$toks = $this->ibl_encryptor->query_tokens($e[3]); $toks = $this->ibl_encryptor->query_tokens($e[3]);
$conds = []; $conds = [];
foreach ($toks as $tok) { foreach ($toks as $tok) {
$tok_esc = $this->db_smartone->escape_str($tok); $tok_esc = $this->db_smartone->escape_str($tok);
$conds[] = "JSON_CONTAINS(M_PatientAddressDescription_bidx, '\"$tok_esc\"')"; $conds[] = "JSON_CONTAINS(M_PatientNIK_bidx, '\"$tok_esc\"')";
} }
if ($conds) $where_addr = 'AND (' . implode(' AND ', $conds) . ')'; if ($conds) $where_nik = 'AND (' . implode(' AND ', $conds) . ')';
} }
} }
@@ -163,12 +163,12 @@ class Patient extends MY_Controller
M_PatientM_IdTypeID, M_PatientM_IdTypeID,
M_PatientName_enc, M_PatientHP_enc, M_PatientDOB_enc, M_PatientName_enc, M_PatientHP_enc, M_PatientDOB_enc,
M_PatientEmail_enc, M_PatientPhone_enc, M_PatientPOB_enc, M_PatientEmail_enc, M_PatientPhone_enc, M_PatientPOB_enc,
M_PatientIDNumber_enc, M_PatientAddressDescription_enc M_PatientIDNumber_enc, M_PatientNIK_enc, M_PatientAddressDescription_enc
FROM m_patient FROM m_patient
JOIN m_title ON M_PatientM_TitleID = M_TitleID JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID
AND M_PatientAddressIsActive = 'Y' {$where_addr} AND M_PatientAddressIsActive = 'Y' AND M_PatientAddressNote = 'Utama'
LEFT JOIN m_religion ON M_PatientM_ReligionID = M_ReligionID LEFT JOIN m_religion ON M_PatientM_ReligionID = M_ReligionID
LEFT JOIN patient_signature ON Patient_SignatureM_PatientID = M_PatientID LEFT JOIN patient_signature ON Patient_SignatureM_PatientID = M_PatientID
AND Patient_SignatureIsActive = 'Y' AND Patient_SignatureIsActive = 'Y'
@@ -177,6 +177,7 @@ class Patient extends MY_Controller
{$where_name} {$where_name}
{$where_hp} {$where_hp}
{$where_dob} {$where_dob}
{$where_nik}
GROUP BY M_PatientID GROUP BY M_PatientID
LIMIT {$number_limit} OFFSET {$number_offset}"; LIMIT {$number_limit} OFFSET {$number_offset}";
@@ -205,6 +206,7 @@ class Patient extends MY_Controller
$rows[$k]['M_PatientPhone'] = $phone; $rows[$k]['M_PatientPhone'] = $phone;
$rows[$k]['M_PatientPOB'] = $enc->decrypt($v['M_PatientPOB_enc']) ?? ''; $rows[$k]['M_PatientPOB'] = $enc->decrypt($v['M_PatientPOB_enc']) ?? '';
$rows[$k]['M_PatientIDNumber'] = $enc->decrypt($v['M_PatientIDNumber_enc']) ?? ''; $rows[$k]['M_PatientIDNumber'] = $enc->decrypt($v['M_PatientIDNumber_enc']) ?? '';
$rows[$k]['M_PatientNIK'] = $enc->decrypt($v['M_PatientNIK_enc']) ?? '';
$rows[$k]['dob_ina'] = $dob_dec; $rows[$k]['dob_ina'] = $dob_dec;
$rows[$k]['hp'] = $phone ?: $hp; $rows[$k]['hp'] = $phone ?: $hp;
@@ -269,6 +271,7 @@ class Patient extends MY_Controller
'M_PatientM_IdTypeID' => $M_IdTypeID, 'M_PatientM_IdTypeID' => $M_IdTypeID,
'M_PatientIDNumber' => $this->_mask_id($prm['M_PatientIDNumber']), 'M_PatientIDNumber' => $this->_mask_id($prm['M_PatientIDNumber']),
'M_PatientIDNumber_enc' => $this->ibl_encryptor->encrypt($prm['M_PatientIDNumber']), 'M_PatientIDNumber_enc' => $this->ibl_encryptor->encrypt($prm['M_PatientIDNumber']),
'M_PatientNIK_bidx' => $this->ibl_encryptor->search_bidx($prm['M_PatientNIK'] ?? ''),
'M_PatientNote' => $prm['M_PatientNote'], 'M_PatientNote' => $prm['M_PatientNote'],
'M_PatientUserID' => $userid, 'M_PatientUserID' => $userid,
'M_PatientCreated' => date('Y-m-d H:i:s'), 'M_PatientCreated' => date('Y-m-d H:i:s'),
@@ -294,7 +297,6 @@ class Patient extends MY_Controller
'M_PatientAddressM_PatientID' => $id, 'M_PatientAddressM_PatientID' => $id,
'M_PatientAddressDescription' => $this->_mask_address($address_description), 'M_PatientAddressDescription' => $this->_mask_address($address_description),
'M_PatientAddressDescription_enc' => $this->ibl_encryptor->encrypt($address_description), 'M_PatientAddressDescription_enc' => $this->ibl_encryptor->encrypt($address_description),
'M_PatientAddressDescription_bidx' => $this->ibl_encryptor->search_bidx($address_description),
'M_PatientAddressUserID' => $userid, 'M_PatientAddressUserID' => $userid,
'M_PatientAddressRegionalCd' => $prm['M_PatientAddressRegionalCd'], 'M_PatientAddressRegionalCd' => $prm['M_PatientAddressRegionalCd'],
'M_PatientAddressLocation' => $prm['M_PatientAddressLocation'], 'M_PatientAddressLocation' => $prm['M_PatientAddressLocation'],
@@ -373,6 +375,7 @@ class Patient extends MY_Controller
->set('M_PatientM_IdTypeID', $prm['M_PatientM_IdTypeID']) ->set('M_PatientM_IdTypeID', $prm['M_PatientM_IdTypeID'])
->set('M_PatientIDNumber', $this->_mask_id($prm['M_PatientIDNumber'])) ->set('M_PatientIDNumber', $this->_mask_id($prm['M_PatientIDNumber']))
->set('M_PatientIDNumber_enc', $this->ibl_encryptor->encrypt($prm['M_PatientIDNumber'])) ->set('M_PatientIDNumber_enc', $this->ibl_encryptor->encrypt($prm['M_PatientIDNumber']))
->set('M_PatientNIK_bidx', $this->ibl_encryptor->search_bidx($prm['M_PatientIDNumber'] ?? ''))
->set('M_PatientNote', $prm['M_PatientNote']) ->set('M_PatientNote', $prm['M_PatientNote'])
->set('M_PatientUserID', $userid) ->set('M_PatientUserID', $userid)
->set('M_PatientLastUpdatedUserID', $userid) ->set('M_PatientLastUpdatedUserID', $userid)
@@ -404,7 +407,6 @@ class Patient extends MY_Controller
->set('M_PatientAddressCountryCode', $prm['M_PatientAddressCountryCode']) ->set('M_PatientAddressCountryCode', $prm['M_PatientAddressCountryCode'])
->set('M_PatientAddressDescription', $this->_mask_address($address_description)) ->set('M_PatientAddressDescription', $this->_mask_address($address_description))
->set('M_PatientAddressDescription_enc', $this->ibl_encryptor->encrypt($address_description)) ->set('M_PatientAddressDescription_enc', $this->ibl_encryptor->encrypt($address_description))
->set('M_PatientAddressDescription_bidx', $this->ibl_encryptor->search_bidx($address_description))
->set('M_PatientAddressUserID', $userid) ->set('M_PatientAddressUserID', $userid)
->set('M_PatientAddressLastUpdatedUserID', $userid) ->set('M_PatientAddressLastUpdatedUserID', $userid)
->where('M_PatientAddressID', $id_address) ->where('M_PatientAddressID', $id_address)

View File

@@ -46,7 +46,7 @@ $stmt_upd = $pdo->prepare("UPDATE m_patient SET
M_PatientPhone_enc = ?, M_PatientPhone_enc = ?,
M_PatientPOB_enc = ?, M_PatientPOB_enc = ?,
M_PatientIDNumber_enc = ?, M_PatientIDNumber_enc = ?,
M_PatientNIK_enc = ?, M_PatientNIK_enc = ?, M_PatientNIK_bidx = ?,
M_PatientNIP_enc = ? M_PatientNIP_enc = ?
WHERE M_PatientID = ?"); WHERE M_PatientID = ?");
@@ -72,7 +72,7 @@ while (true) {
$enc->encrypt($row['M_PatientPhone']), $enc->encrypt($row['M_PatientPhone']),
$enc->encrypt($row['M_PatientPOB']), $enc->encrypt($row['M_PatientPOB']),
$enc->encrypt($row['M_PatientIDNumber']), $enc->encrypt($row['M_PatientIDNumber']),
$enc->encrypt($row['M_PatientNIK']), $enc->encrypt($row['M_PatientNIK']), $enc->search_bidx($row['M_PatientNIK']),
$enc->encrypt($row['M_PatientNIP']), $enc->encrypt($row['M_PatientNIP']),
$row['M_PatientID'], $row['M_PatientID'],
]); ]);
@@ -90,7 +90,6 @@ $total = 0;
$stmt_addr = $pdo->prepare("UPDATE m_patientaddress SET $stmt_addr = $pdo->prepare("UPDATE m_patientaddress SET
M_PatientAddressDescription_enc = ?, M_PatientAddressDescription_enc = ?,
M_PatientAddressDescription_bidx = ?,
M_PatientAddressEmail_enc = ?, M_PatientAddressEmail_enc = ?,
M_PatientAddressPhone_enc = ? M_PatientAddressPhone_enc = ?
WHERE M_PatientAddressID = ?"); WHERE M_PatientAddressID = ?");
@@ -109,7 +108,6 @@ while (true) {
foreach ($rows as $row) { foreach ($rows as $row) {
$stmt_addr->execute([ $stmt_addr->execute([
$enc->encrypt($row['M_PatientAddressDescription']), $enc->encrypt($row['M_PatientAddressDescription']),
$enc->search_bidx($row['M_PatientAddressDescription']),
$enc->encrypt($row['M_PatientAddressEmail']), $enc->encrypt($row['M_PatientAddressEmail']),
$enc->encrypt($row['M_PatientAddressPhone']), $enc->encrypt($row['M_PatientAddressPhone']),
$row['M_PatientAddressID'], $row['M_PatientAddressID'],

View File

@@ -119,6 +119,12 @@ ALTER TABLE one_lab.so_resultentrysdsinterpretation
ALTER TABLE one_lab.member_eligible ALTER TABLE one_lab.member_eligible
ADD COLUMN Member_EligibleDescription_enc TEXT NULL AFTER Member_EligibleDescription; ADD COLUMN Member_EligibleDescription_enc TEXT NULL AFTER Member_EligibleDescription;
-- ============================================================
-- one_lab.mcu_resume_results: JSON snapshot hasil lab MCU
-- ============================================================
ALTER TABLE one_lab.mcu_resume_results
ADD COLUMN Mcu_ResumeResultsJSON_enc MEDIUMTEXT NULL AFTER Mcu_ResumeResultsJSON;
-- ============================================================ -- ============================================================
-- one_lab_log.log_patient: audit log perubahan data pasien -- one_lab_log.log_patient: audit log perubahan data pasien
-- Fix charset ke utf8mb4 (default latin1 tidak support JSON UTF-8 dari trigger) -- Fix charset ke utf8mb4 (default latin1 tidak support JSON UTF-8 dari trigger)