Update MCU patient sync SPs

This commit is contained in:
sas.fajri
2026-05-06 09:39:55 +07:00
parent d03dec2dda
commit 8145e088b1
5 changed files with 132 additions and 0 deletions

View File

@@ -20,6 +20,33 @@ BEGIN
WHERE Mcu_ParticipantDailyMcuID = p_mgm_mcuid
AND Mcu_ParticipantDailyDate = p_schedule_date;
DELETE s
FROM cpone_dashboard.mcu_patient_schedule s
INNER JOIN cpone.mcu_preregister_patients pp
ON pp.Mcu_PreregisterPatientsID = s.Mcu_PatientSchedulePreregisterID
WHERE pp.Mcu_PreregisterPatientsMgm_McuID = p_mgm_mcuid
AND s.Mcu_PatientScheduleDate = p_schedule_date;
INSERT INTO cpone_dashboard.mcu_patient_schedule (
Mcu_PatientSchedulePreregisterID,
Mcu_PatientScheduleDate,
Mcu_PatientScheduleIsActive,
Mcu_PatientScheduleSyncedAt
)
SELECT
DISTINCT
pp.Mcu_PreregisterPatientsID,
p_schedule_date,
'Y',
NOW()
FROM cpone.mcu_preregister_patients pp
INNER JOIN cpone.mcu_preregister_date pd
ON pd.Mcu_PreregisterDateMcu_PreregisterPatientsID = pp.Mcu_PreregisterPatientsID
AND pd.Mcu_PreregisterDateCheckinSchedule = p_schedule_date
AND pd.Mcu_PreregisterDateIsActive = 'Y'
WHERE pp.Mcu_PreregisterPatientsMgm_McuID = p_mgm_mcuid
AND pp.Mcu_PreregisterPatientsIsActive = 'Y';
INSERT INTO cpone_dashboard.mcu_participant_daily (
Mcu_ParticipantDailyMcuID,
Mcu_ParticipantDailyDate,

View File

@@ -0,0 +1,39 @@
DROP PROCEDURE IF EXISTS cpone_dashboard.sp_refresh_mcu_participant_daily_by_mcu;
DELIMITER $$
CREATE PROCEDURE cpone_dashboard.sp_refresh_mcu_participant_daily_by_mcu(IN p_mgm_mcuid INT)
BEGIN
DECLARE v_done INT DEFAULT 0;
DECLARE v_schedule_date DATE;
DECLARE v_total_dates INT DEFAULT 0;
DECLARE cur_dates CURSOR FOR
SELECT DISTINCT pd.Mcu_PreregisterDateCheckinSchedule
FROM cpone.mcu_preregister_patients pp
INNER JOIN cpone.mcu_preregister_date pd
ON pd.Mcu_PreregisterDateMcu_PreregisterPatientsID = pp.Mcu_PreregisterPatientsID
AND pd.Mcu_PreregisterDateIsActive = 'Y'
WHERE pp.Mcu_PreregisterPatientsMgm_McuID = p_mgm_mcuid
AND pp.Mcu_PreregisterPatientsIsActive = 'Y'
AND pd.Mcu_PreregisterDateCheckinSchedule IS NOT NULL
AND pd.Mcu_PreregisterDateCheckinSchedule <> '0000-00-00'
ORDER BY pd.Mcu_PreregisterDateCheckinSchedule;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = 1;
OPEN cur_dates;
dates_loop: LOOP
FETCH cur_dates INTO v_schedule_date;
IF v_done = 1 THEN
LEAVE dates_loop;
END IF;
CALL cpone.sp_refresh_mcu_participant_daily_by_mcu_date(p_mgm_mcuid, v_schedule_date);
SET v_total_dates = v_total_dates + 1;
END LOOP;
CLOSE cur_dates;
SELECT v_total_dates AS processed_dates;
END$$
DELIMITER ;

View File

@@ -12,6 +12,7 @@ BEGIN
Mcu_PatientDepartment,
Mcu_PatientDivision,
Mcu_PatientPosisi,
Mcu_PatientOrders,
Mcu_PatientIsRegistered,
Mcu_PatientOrderID,
Mcu_PatientIsActive,
@@ -27,6 +28,7 @@ BEGIN
pp.Mcu_PreregisterPatientsDepartment,
pp.Mcu_PreregisterPatientsDivisi,
pp.Mcu_PreregisterPatientsPosisi,
pp.Mcu_PreregisterPatientsOrders,
pp.Mcu_PreregisterPatientsIsRegistered,
CASE
WHEN pp.Mcu_PreregisterPatientsIsRegistered = 'Y'
@@ -47,6 +49,7 @@ BEGIN
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),

View File

@@ -0,0 +1,3 @@
ALTER TABLE cpone_dashboard.mcu_patient
ADD COLUMN Mcu_PatientOrders LONGTEXT NULL
AFTER Mcu_PatientPosisi;

View File

@@ -0,0 +1,60 @@
DROP PROCEDURE IF EXISTS cpone.sp_upsert_mcu_patient_by_mgm_mcuid;
DELIMITER $$
CREATE PROCEDURE cpone.sp_upsert_mcu_patient_by_mgm_mcuid(IN p_mgm_mcuid INT)
BEGIN
INSERT INTO cpone_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,
pp.Mcu_PreregisterPatientsPatientName,
pp.Mcu_PreregisterPatientsNIP,
pp.Mcu_PreregisterPatientsGender,
pp.Mcu_PreregisterPatientsDOB,
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 cpone.mcu_preregister_patients pp
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_PatientIsRegistered = VALUES(Mcu_PatientIsRegistered),
Mcu_PatientOrderID = VALUES(Mcu_PatientOrderID),
Mcu_PatientIsActive = VALUES(Mcu_PatientIsActive),
Mcu_PatientSyncedAt = NOW();
SELECT ROW_COUNT() AS affected_rows;
END$$
DELIMITER ;