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>
This commit is contained in:
@@ -0,0 +1,282 @@
|
||||
-- PDP: mcu_patient di one_lab_dashboard simpan versi _enc dari m_patient
|
||||
-- Mcu_PatientName dan Mcu_PatientDOB diubah ke TEXT untuk muat ciphertext AES-256-GCM
|
||||
-- SP JOIN ke one_lab.m_patient via Mcu_PreregisterPatientsM_PatientID
|
||||
|
||||
-- ============================================================
|
||||
-- 1. Ubah tipe kolom mcu_patient
|
||||
-- ============================================================
|
||||
ALTER TABLE one_lab_dashboard.mcu_patient
|
||||
MODIFY COLUMN Mcu_PatientName TEXT NULL,
|
||||
MODIFY COLUMN Mcu_PatientDOB TEXT NULL;
|
||||
|
||||
-- ============================================================
|
||||
-- 2. sp_upsert_mcu_patient_by_preregister_id
|
||||
-- ============================================================
|
||||
DROP PROCEDURE IF EXISTS one_lab.sp_upsert_mcu_patient_by_preregister_id;
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `one_lab`.`sp_upsert_mcu_patient_by_preregister_id`(IN `p_preregister_id` int)
|
||||
BEGIN
|
||||
INSERT INTO one_lab_dashboard.mcu_patient (
|
||||
Mcu_PatientPreregisterID,
|
||||
Mcu_PatientMcuID,
|
||||
Mcu_PatientName,
|
||||
Mcu_PatientNIP,
|
||||
Mcu_PatientGender,
|
||||
Mcu_PatientDOB,
|
||||
Mcu_PatientDepartment,
|
||||
Mcu_PatientDivision,
|
||||
Mcu_PatientPosisi,
|
||||
Mcu_PatientOrders,
|
||||
Mcu_PatientIsRegistered,
|
||||
Mcu_PatientOrderID,
|
||||
Mcu_PatientIsActive,
|
||||
Mcu_PatientSyncedAt
|
||||
)
|
||||
SELECT
|
||||
pp.Mcu_PreregisterPatientsID,
|
||||
pp.Mcu_PreregisterPatientsMgm_McuID,
|
||||
mp.M_PatientName_enc,
|
||||
pp.Mcu_PreregisterPatientsNIP,
|
||||
pp.Mcu_PreregisterPatientsGender,
|
||||
mp.M_PatientDOB_enc,
|
||||
pp.Mcu_PreregisterPatientsDepartment,
|
||||
pp.Mcu_PreregisterPatientsDivisi,
|
||||
pp.Mcu_PreregisterPatientsPosisi,
|
||||
pp.Mcu_PreregisterPatientsOrders,
|
||||
pp.Mcu_PreregisterPatientsIsRegistered,
|
||||
CASE
|
||||
WHEN pp.Mcu_PreregisterPatientsIsRegistered = 'Y'
|
||||
AND IFNULL(pp.Mcu_PreregisterPatientsT_OrderHeaderID, 0) > 0
|
||||
THEN pp.Mcu_PreregisterPatientsT_OrderHeaderID
|
||||
ELSE NULL
|
||||
END AS Mcu_PatientOrderID,
|
||||
pp.Mcu_PreregisterPatientsIsActive AS Mcu_PatientIsActive,
|
||||
NOW() AS Mcu_PatientSyncedAt
|
||||
FROM mcu_preregister_patients pp
|
||||
LEFT JOIN one_lab.m_patient mp ON mp.M_PatientID = pp.Mcu_PreregisterPatientsM_PatientID
|
||||
WHERE pp.Mcu_PreregisterPatientsID = p_preregister_id
|
||||
ON DUPLICATE KEY UPDATE
|
||||
Mcu_PatientMcuID = VALUES(Mcu_PatientMcuID),
|
||||
Mcu_PatientName = VALUES(Mcu_PatientName),
|
||||
Mcu_PatientNIP = VALUES(Mcu_PatientNIP),
|
||||
Mcu_PatientGender = VALUES(Mcu_PatientGender),
|
||||
Mcu_PatientDOB = VALUES(Mcu_PatientDOB),
|
||||
Mcu_PatientDepartment = VALUES(Mcu_PatientDepartment),
|
||||
Mcu_PatientDivision = VALUES(Mcu_PatientDivision),
|
||||
Mcu_PatientPosisi = VALUES(Mcu_PatientPosisi),
|
||||
Mcu_PatientOrders = VALUES(Mcu_PatientOrders),
|
||||
Mcu_PatientIsRegistered = VALUES(Mcu_PatientIsRegistered),
|
||||
Mcu_PatientOrderID = VALUES(Mcu_PatientOrderID),
|
||||
Mcu_PatientIsActive = VALUES(Mcu_PatientIsActive),
|
||||
Mcu_PatientSyncedAt = NOW();
|
||||
|
||||
DELETE FROM one_lab_dashboard.mcu_patient_packet
|
||||
WHERE Mcu_PatientPacketPreregisterID = p_preregister_id;
|
||||
|
||||
INSERT INTO one_lab_dashboard.mcu_patient_packet (
|
||||
Mcu_PatientPacketMcu_PatientID,
|
||||
Mcu_PatientPacketPreregisterID,
|
||||
Mcu_PatientPacketCode,
|
||||
Mcu_PatientPacketName
|
||||
)
|
||||
SELECT DISTINCT
|
||||
mp2.Mcu_PatientID,
|
||||
pp.Mcu_PreregisterPatientsID,
|
||||
seqs.order_code AS Mcu_PatientPacketCode,
|
||||
tp.T_PacketName AS Mcu_PatientPacketName
|
||||
FROM mcu_preregister_patients pp
|
||||
INNER JOIN one_lab_dashboard.mcu_patient mp2
|
||||
ON mp2.Mcu_PatientPreregisterID = pp.Mcu_PreregisterPatientsID
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
src.Mcu_PreregisterPatientsID,
|
||||
TRIM(
|
||||
SUBSTRING_INDEX(
|
||||
SUBSTRING_INDEX(src.clean_orders, ',', nums.seq),
|
||||
',', -1
|
||||
)
|
||||
) AS order_code
|
||||
FROM (
|
||||
SELECT p.Mcu_PreregisterPatientsID,
|
||||
REPLACE(IFNULL(p.Mcu_PreregisterPatientsOrders, ''), ' ', '') AS clean_orders
|
||||
FROM mcu_preregister_patients p
|
||||
WHERE p.Mcu_PreregisterPatientsID = p_preregister_id
|
||||
) src
|
||||
INNER JOIN (
|
||||
SELECT ones.n + tens.n * 10 + 1 AS seq
|
||||
FROM
|
||||
(SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
|
||||
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) ones
|
||||
CROSS JOIN
|
||||
(SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
|
||||
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) tens
|
||||
) nums ON nums.seq <= 1 + LENGTH(src.clean_orders) - LENGTH(REPLACE(src.clean_orders, ',', ''))
|
||||
) seqs ON seqs.Mcu_PreregisterPatientsID = pp.Mcu_PreregisterPatientsID
|
||||
INNER JOIN t_packet tp
|
||||
ON tp.T_PacketSasCode = seqs.order_code AND tp.T_PacketIsActive = 'Y'
|
||||
WHERE pp.Mcu_PreregisterPatientsID = p_preregister_id
|
||||
AND LEFT(seqs.order_code, 2) IN ('PN', 'PR')
|
||||
AND seqs.order_code <> '';
|
||||
|
||||
SELECT ROW_COUNT() AS affected_rows;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
-- ============================================================
|
||||
-- 3. sp_upsert_mcu_patient_by_mgm_mcuid
|
||||
-- ============================================================
|
||||
DROP PROCEDURE IF EXISTS one_lab.sp_upsert_mcu_patient_by_mgm_mcuid;
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `one_lab`.`sp_upsert_mcu_patient_by_mgm_mcuid`(IN `p_mgm_mcuid` int)
|
||||
BEGIN
|
||||
INSERT INTO one_lab_dashboard.mcu_patient (
|
||||
Mcu_PatientPreregisterID,
|
||||
Mcu_PatientMcuID,
|
||||
Mcu_PatientName,
|
||||
Mcu_PatientNIP,
|
||||
Mcu_PatientGender,
|
||||
Mcu_PatientDOB,
|
||||
Mcu_PatientDepartment,
|
||||
Mcu_PatientDivision,
|
||||
Mcu_PatientPosisi,
|
||||
Mcu_PatientOrders,
|
||||
Mcu_PatientPemeriksaan,
|
||||
Mcu_PatientIsRegistered,
|
||||
Mcu_PatientOrderID,
|
||||
Mcu_PatientIsActive,
|
||||
Mcu_PatientSyncedAt
|
||||
)
|
||||
SELECT
|
||||
pp.Mcu_PreregisterPatientsID,
|
||||
pp.Mcu_PreregisterPatientsMgm_McuID,
|
||||
mp.M_PatientName_enc,
|
||||
pp.Mcu_PreregisterPatientsNIP,
|
||||
pp.Mcu_PreregisterPatientsGender,
|
||||
mp.M_PatientDOB_enc,
|
||||
pp.Mcu_PreregisterPatientsDepartment,
|
||||
pp.Mcu_PreregisterPatientsDivisi,
|
||||
pp.Mcu_PreregisterPatientsPosisi,
|
||||
pp.Mcu_PreregisterPatientsOrders,
|
||||
(
|
||||
SELECT GROUP_CONCAT(x.pemeriksaan_name ORDER BY x.seq SEPARATOR ', ')
|
||||
FROM (
|
||||
SELECT
|
||||
seqs.seq,
|
||||
CASE
|
||||
WHEN LEFT(seqs.order_code, 2) IN ('PN', 'PR') THEN tp.T_PacketName
|
||||
ELSE tt.T_TestName
|
||||
END AS pemeriksaan_name
|
||||
FROM (
|
||||
SELECT
|
||||
nums.seq,
|
||||
TRIM(
|
||||
SUBSTRING_INDEX(
|
||||
SUBSTRING_INDEX(REPLACE(IFNULL(pp.Mcu_PreregisterPatientsOrders, ''), ' ', ''), ',', nums.seq),
|
||||
',', -1
|
||||
)
|
||||
) AS order_code
|
||||
FROM (
|
||||
SELECT ones.n + tens.n * 10 + 1 AS seq
|
||||
FROM
|
||||
(SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
|
||||
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) ones
|
||||
CROSS JOIN
|
||||
(SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
|
||||
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) tens
|
||||
) nums
|
||||
WHERE nums.seq <= 1 + LENGTH(REPLACE(IFNULL(pp.Mcu_PreregisterPatientsOrders, ''), ' ', ''))
|
||||
- LENGTH(REPLACE(REPLACE(IFNULL(pp.Mcu_PreregisterPatientsOrders, ''), ' ', ''), ',', ''))
|
||||
) seqs
|
||||
LEFT JOIN t_packet tp
|
||||
ON LEFT(seqs.order_code, 2) IN ('PN', 'PR')
|
||||
AND tp.T_PacketSasCode = seqs.order_code AND tp.T_PacketIsActive = 'Y'
|
||||
LEFT JOIN t_test tt
|
||||
ON LEFT(seqs.order_code, 2) NOT IN ('PN', 'PR')
|
||||
AND tt.T_TestSasCode = seqs.order_code AND tt.T_TestIsActive = 'Y'
|
||||
WHERE seqs.order_code <> ''
|
||||
) x
|
||||
WHERE x.pemeriksaan_name IS NOT NULL
|
||||
) AS Mcu_PatientPemeriksaan,
|
||||
pp.Mcu_PreregisterPatientsIsRegistered,
|
||||
CASE
|
||||
WHEN pp.Mcu_PreregisterPatientsIsRegistered = 'Y'
|
||||
AND IFNULL(pp.Mcu_PreregisterPatientsT_OrderHeaderID, 0) > 0
|
||||
THEN pp.Mcu_PreregisterPatientsT_OrderHeaderID
|
||||
ELSE NULL
|
||||
END AS Mcu_PatientOrderID,
|
||||
pp.Mcu_PreregisterPatientsIsActive AS Mcu_PatientIsActive,
|
||||
NOW() AS Mcu_PatientSyncedAt
|
||||
FROM mcu_preregister_patients pp
|
||||
LEFT JOIN one_lab.m_patient mp ON mp.M_PatientID = pp.Mcu_PreregisterPatientsM_PatientID
|
||||
WHERE pp.Mcu_PreregisterPatientsMgm_McuID = p_mgm_mcuid
|
||||
ON DUPLICATE KEY UPDATE
|
||||
Mcu_PatientMcuID = VALUES(Mcu_PatientMcuID),
|
||||
Mcu_PatientName = VALUES(Mcu_PatientName),
|
||||
Mcu_PatientNIP = VALUES(Mcu_PatientNIP),
|
||||
Mcu_PatientGender = VALUES(Mcu_PatientGender),
|
||||
Mcu_PatientDOB = VALUES(Mcu_PatientDOB),
|
||||
Mcu_PatientDepartment = VALUES(Mcu_PatientDepartment),
|
||||
Mcu_PatientDivision = VALUES(Mcu_PatientDivision),
|
||||
Mcu_PatientPosisi = VALUES(Mcu_PatientPosisi),
|
||||
Mcu_PatientOrders = VALUES(Mcu_PatientOrders),
|
||||
Mcu_PatientPemeriksaan = VALUES(Mcu_PatientPemeriksaan),
|
||||
Mcu_PatientIsRegistered = VALUES(Mcu_PatientIsRegistered),
|
||||
Mcu_PatientOrderID = VALUES(Mcu_PatientOrderID),
|
||||
Mcu_PatientIsActive = VALUES(Mcu_PatientIsActive),
|
||||
Mcu_PatientSyncedAt = NOW();
|
||||
|
||||
DELETE ppk
|
||||
FROM one_lab_dashboard.mcu_patient_packet ppk
|
||||
INNER JOIN one_lab_dashboard.mcu_patient mp2
|
||||
ON mp2.Mcu_PatientID = ppk.Mcu_PatientPacketMcu_PatientID
|
||||
WHERE mp2.Mcu_PatientMcuID = p_mgm_mcuid;
|
||||
|
||||
INSERT INTO one_lab_dashboard.mcu_patient_packet (
|
||||
Mcu_PatientPacketMcu_PatientID,
|
||||
Mcu_PatientPacketPreregisterID,
|
||||
Mcu_PatientPacketCode,
|
||||
Mcu_PatientPacketName
|
||||
)
|
||||
SELECT DISTINCT
|
||||
mp2.Mcu_PatientID,
|
||||
pp.Mcu_PreregisterPatientsID,
|
||||
seqs.order_code AS Mcu_PatientPacketCode,
|
||||
tp.T_PacketName AS Mcu_PatientPacketName
|
||||
FROM mcu_preregister_patients pp
|
||||
INNER JOIN one_lab_dashboard.mcu_patient mp2
|
||||
ON mp2.Mcu_PatientPreregisterID = pp.Mcu_PreregisterPatientsID
|
||||
AND mp2.Mcu_PatientMcuID = pp.Mcu_PreregisterPatientsMgm_McuID
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
src.Mcu_PreregisterPatientsID,
|
||||
TRIM(
|
||||
SUBSTRING_INDEX(
|
||||
SUBSTRING_INDEX(src.clean_orders, ',', nums.seq),
|
||||
',', -1
|
||||
)
|
||||
) AS order_code
|
||||
FROM (
|
||||
SELECT p.Mcu_PreregisterPatientsID,
|
||||
REPLACE(IFNULL(p.Mcu_PreregisterPatientsOrders, ''), ' ', '') AS clean_orders
|
||||
FROM mcu_preregister_patients p
|
||||
WHERE p.Mcu_PreregisterPatientsMgm_McuID = p_mgm_mcuid
|
||||
) src
|
||||
INNER JOIN (
|
||||
SELECT ones.n + tens.n * 10 + 1 AS seq
|
||||
FROM
|
||||
(SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
|
||||
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) ones
|
||||
CROSS JOIN
|
||||
(SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
|
||||
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) tens
|
||||
) nums ON nums.seq <= 1 + LENGTH(src.clean_orders) - LENGTH(REPLACE(src.clean_orders, ',', ''))
|
||||
) seqs ON seqs.Mcu_PreregisterPatientsID = pp.Mcu_PreregisterPatientsID
|
||||
INNER JOIN t_packet tp
|
||||
ON tp.T_PacketSasCode = seqs.order_code AND tp.T_PacketIsActive = 'Y'
|
||||
WHERE pp.Mcu_PreregisterPatientsMgm_McuID = p_mgm_mcuid
|
||||
AND LEFT(seqs.order_code, 2) IN ('PN', 'PR')
|
||||
AND seqs.order_code <> '';
|
||||
|
||||
SELECT ROW_COUNT() AS affected_rows;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
Reference in New Issue
Block a user