FHM17062601CPONE - tambah Resumeindividucponev8 dengan call sp_sync_kelainan_details_by_orderheader di generateFitnessCategory, dan simpan SQL update SP

This commit is contained in:
sas.fajri
2026-06-25 14:49:49 +07:00
parent 23992e58e7
commit edc331f4ec
3 changed files with 2884 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,154 @@
DROP PROCEDURE IF EXISTS cpone.sp_sync_kelainan_details_by_orderheader;
DELIMITER $$
CREATE DEFINER=`admin`@`localhost` PROCEDURE `cpone`.`sp_sync_kelainan_details_by_orderheader`(IN `p_order_header_id` int)
BEGIN
DECLARE v_mcu_id INT DEFAULT 0;
DECLARE v_numbering VARCHAR(150) DEFAULT '';
DECLARE v_project_id INT DEFAULT 0;
SELECT oh.T_OrderHeaderMgm_McuID
INTO v_mcu_id
FROM cpone.t_orderheader oh
WHERE oh.T_OrderHeaderID = p_order_header_id
AND oh.T_OrderHeaderIsActive = 'Y'
LIMIT 1;
IF v_mcu_id IS NULL OR v_mcu_id = 0 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'T_OrderHeaderID tidak ditemukan atau tidak aktif';
END IF;
SELECT COALESCE(NULLIF(mn.Mcu_NumberTableName, ''), NULLIF(mm.Mgm_McuNumber, ''), '')
INTO v_numbering
FROM cpone.mgm_mcu mm
LEFT JOIN cpone_corporate.mcu_number mn
ON mn.Mcu_NumberMgm_McuID = mm.Mgm_McuID
AND mn.Mcu_NumberIsActive = 'Y'
WHERE mm.Mgm_McuID = v_mcu_id
ORDER BY mn.Mcu_NumberID DESC
LIMIT 1;
SELECT Mcu_ProjectID
INTO v_project_id
FROM cpone_dashboard.mcu_project
WHERE Mcu_ProjectMcuID = v_mcu_id
LIMIT 1;
DELETE FROM cpone_dashboard.kelainan_details
WHERE T_OrderHeaderID = p_order_header_id;
-- NONLAB
INSERT INTO cpone_dashboard.kelainan_details (
Numbering, Tx_KelainanID, Tx_Type, T_OrderHeaderID, T_OrderHeaderDate, T_OrderHeaderLabNumber,
AgePatient, M_PatientID, M_PatientNoReg, M_PatientDOB, M_PatientGender, M_PatientIdentifierValue,
M_PatientNIP, M_PatientJob, M_PatientPosisi, M_PatientDivisi, M_PatientLocation, M_PatientDepartement,
PatientName, M_PatientName, GroupResult, Nat_TestID, Nat_TestCode, Nat_TestName, T_TestName, Result,
Mcu_KelainanID, Mcu_KelainanName, Mcu_KelainanGroupSummaryID, Mcu_KelainanGroupSummaryName,
Mcu_FitnessCategoryID, Mcu_FitnessCategoryName, Mcu_FitnessCategoryEng, Mcu_FitnessCategoryLevel,
Mgm_McuID, Mcu_ProjectID
)
SELECT
v_numbering,
T_KelainanNonLabID,'NONLAB',T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
T_OrderHeaderM_PatientAge,M_PatientID,M_PatientNoReg,M_PatientDOB,M_PatientGender,M_PatientIdentifierValue,
M_PatientNIP,M_PatientJob,M_PatientPosisi,M_PatientDivisi,M_PatientLocation,M_PatientDepartement,
CONCAT(IF(M_TitleName IS NULL,'',CONCAT(M_TitleName,'. ')), IF(M_PatientPrefix IS NULL,'',CONCAT(M_PatientPrefix,' ')), M_PatientName, IF(M_PatientSuffix IS NULL,'',CONCAT(M_PatientSuffix,' '))),
M_PatientName,
IF(Group_ResultName = 'LAB', 'LAB', Nat_TestName),
Nat_TestID,Nat_TestCode,Nat_TestName,T_TestName,'',Mcu_KelainanID,Mcu_KelainanName,
Mcu_KelainanGroupSummaryID,Mcu_KelainanGroupSummaryName,Mcu_FitnessCategoryID,Mcu_FitnessCategoryName,
Mcu_FitnessCategoryEng,Mcu_FitnessCategoryLevel,
v_mcu_id, v_project_id
FROM cpone.t_kelainan_nonlab
JOIN cpone.t_orderheader ON T_KelainanNonLabT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive='Y'
JOIN cpone.m_patient ON T_OrderHeaderM_PatientID=M_PatientID AND M_PatientIsActive='Y'
JOIN cpone.mcu_summarynonlab ON T_KelainanNonLabMcu_SummaryNonlabID=Mcu_SummaryNonlabID AND Mcu_SummaryNonlabIsActive='Y'
JOIN cpone.nat_test ON Mcu_SummaryNonlabNat_TestID=Nat_TestID AND Nat_TestIsActive='Y'
JOIN cpone.t_test ON T_TestNat_TestID=Nat_TestID AND T_TestIsActive='Y'
JOIN cpone.group_resultdetail ON Group_ResultDetailT_TestID=T_TestID AND Group_ResultDetailIsActive='Y'
JOIN cpone.group_result ON Group_ResultDetailGroup_ResultID=Group_ResultID AND Group_ResultIsActive='Y'
JOIN cpone.mcu_kelainan ON Mcu_SummaryNonlabMcu_KelainanID=Mcu_KelainanID AND Mcu_KelainanIsActive='Y'
JOIN cpone.mcu_kelainangroupsummarydetail ON Mcu_KelainanGroupSummaryDetailMcu_KelainanID=Mcu_KelainanID AND Mcu_KelainanGroupSummaryDetailIsActive='Y'
JOIN cpone.mcu_kelainangroupsummary ON Mcu_KelainanGroupSummaryDetailMcu_KelainanGroupSummaryID=Mcu_KelainanGroupSummaryID AND Mcu_KelainanGroupSummaryIsActive='Y'
JOIN cpone.mcu_fitness_category ON Mcu_SummaryNonlabMcu_FitnessCategoryID=Mcu_FitnessCategoryID AND Mcu_FitnessCategoryIsActive='Y'
LEFT JOIN cpone.m_title ON M_PatientM_TitleID=M_TitleID AND M_TitleIsActive='Y'
WHERE T_KelainanNonLabIsActive='Y' AND T_OrderHeaderID=p_order_header_id;
-- LAB
INSERT INTO cpone_dashboard.kelainan_details (
Numbering, Tx_KelainanID, Tx_Type, T_OrderHeaderID, T_OrderHeaderDate, T_OrderHeaderLabNumber,
AgePatient, M_PatientID, M_PatientNoReg, M_PatientDOB, M_PatientGender, M_PatientIdentifierValue,
M_PatientNIP, M_PatientJob, M_PatientPosisi, M_PatientDivisi, M_PatientLocation, M_PatientDepartement,
PatientName, M_PatientName, GroupResult, Nat_TestID, Nat_TestCode, Nat_TestName, T_TestName, Result,
Mcu_KelainanID, Mcu_KelainanName, Mcu_KelainanGroupSummaryID, Mcu_KelainanGroupSummaryName,
Mcu_FitnessCategoryID, Mcu_FitnessCategoryName, Mcu_FitnessCategoryEng, Mcu_FitnessCategoryLevel,
Mgm_McuID, Mcu_ProjectID
)
SELECT v_numbering,T_KelainanLabID,'LAB',T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
T_OrderHeaderM_PatientAge,M_PatientID,M_PatientNoReg,M_PatientDOB,M_PatientGender,M_PatientIdentifierValue,
M_PatientNIP,M_PatientJob,M_PatientPosisi,M_PatientDivisi,M_PatientLocation,M_PatientDepartement,
CONCAT(IF(M_TitleName IS NULL,'',CONCAT(M_TitleName,'. ')), IF(M_PatientPrefix IS NULL,'',CONCAT(M_PatientPrefix,' ')), M_PatientName, IF(M_PatientSuffix IS NULL,'',CONCAT(M_PatientSuffix,' '))),
M_PatientName,IF(Group_ResultName='LAB','LAB',Nat_TestName),Nat_TestID,Nat_TestCode,Nat_TestName,T_TestName,
IFNULL(T_OrderDetailResult,''),Mcu_KelainanID,Mcu_KelainanName,Mcu_KelainanGroupSummaryID,
Mcu_KelainanGroupSummaryName,Mcu_FitnessCategoryID,Mcu_FitnessCategoryName,Mcu_FitnessCategoryEng,
Mcu_FitnessCategoryLevel,
v_mcu_id, v_project_id
FROM cpone.t_kelainan_lab
JOIN cpone.t_orderdetail ON T_KelainanLabT_OrderDetailID=T_OrderDetailID AND T_OrderDetailIsActive='Y'
JOIN cpone.t_orderheader ON T_KelainanLabT_OrderHeaderID=T_OrderHeaderID AND T_OrderHeaderIsActive='Y'
JOIN cpone.m_patient ON T_OrderHeaderM_PatientID=M_PatientID AND M_PatientIsActive='Y'
JOIN cpone.mcu_summarylab ON T_KelainanLabMcu_SummaryLabID=Mcu_SummaryLabID AND Mcu_SummaryLabIsActive='Y'
JOIN cpone.nat_test ON Mcu_SummaryLabNat_TestID=Nat_TestID AND Nat_TestIsActive='Y'
JOIN cpone.t_test ON T_TestNat_TestID=Nat_TestID AND T_TestIsActive='Y'
JOIN cpone.group_resultdetail ON Group_ResultDetailT_TestID=T_TestID AND Group_ResultDetailIsActive='Y'
JOIN cpone.group_result ON Group_ResultDetailGroup_ResultID=Group_ResultID AND Group_ResultIsActive='Y'
JOIN cpone.mcu_kelainan ON Mcu_SummaryLabMcu_KelainanID=Mcu_KelainanID AND Mcu_KelainanIsActive='Y'
JOIN cpone.mcu_kelainangroupsummarydetail ON Mcu_KelainanGroupSummaryDetailMcu_KelainanID=Mcu_KelainanID AND Mcu_KelainanGroupSummaryDetailIsActive='Y'
JOIN cpone.mcu_kelainangroupsummary ON Mcu_KelainanGroupSummaryDetailMcu_KelainanGroupSummaryID=Mcu_KelainanGroupSummaryID AND Mcu_KelainanGroupSummaryIsActive='Y'
JOIN cpone.mcu_fitness_category ON Mcu_SummaryLabMcu_FitnessCategoryID=Mcu_FitnessCategoryID AND Mcu_FitnessCategoryIsActive='Y'
LEFT JOIN cpone.m_title ON M_PatientM_TitleID=M_TitleID AND M_TitleIsActive='Y'
WHERE T_KelainanLabIsActive='Y' AND T_OrderHeaderID=p_order_header_id
GROUP BY T_KelainanLabID;
-- FISIK
INSERT INTO cpone_dashboard.kelainan_details (
Numbering, Tx_KelainanID, Tx_Type, T_OrderHeaderID, T_OrderHeaderDate, T_OrderHeaderLabNumber,
AgePatient, M_PatientID, M_PatientNoReg, M_PatientDOB, M_PatientGender, M_PatientIdentifierValue,
M_PatientNIP, M_PatientJob, M_PatientPosisi, M_PatientDivisi, M_PatientLocation, M_PatientDepartement,
PatientName, M_PatientName, GroupResult, Nat_TestID, Nat_TestCode, Nat_TestName, T_TestName, Result,
Mcu_KelainanID, Mcu_KelainanName, Mcu_KelainanGroupSummaryID, Mcu_KelainanGroupSummaryName,
Mcu_FitnessCategoryID, Mcu_FitnessCategoryName, Mcu_FitnessCategoryEng, Mcu_FitnessCategoryLevel,
Mgm_McuID, Mcu_ProjectID
)
SELECT v_numbering,T_KelainanFiskID,'FISIK',T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
T_OrderHeaderM_PatientAge,M_PatientID,M_PatientNoReg,M_PatientDOB,M_PatientGender,M_PatientIdentifierValue,
M_PatientNIP,M_PatientJob,M_PatientPosisi,M_PatientDivisi,M_PatientLocation,M_PatientDepartement,
CONCAT(IF(M_TitleName IS NULL,'',CONCAT(M_TitleName,'. ')), IF(M_PatientPrefix IS NULL,'',CONCAT(M_PatientPrefix,' ')), M_PatientName, IF(M_PatientSuffix IS NULL,'',CONCAT(M_PatientSuffix,' '))),
M_PatientName,IF(Group_ResultName='LAB','LAB',Nat_TestName),Nat_TestID,Nat_TestCode,Nat_TestName,
CONCAT(IF(label IS NULL, Mcu_KelainanGroupName, CONCAT(label, ' - ',IF(level = 1, parent_level_1,IF(level = 2, parent_level_2, IF(level = 3,parent_level_3,parent_level_4)))))),
IF(Mcu_FisikValueNote = '',Mcu_FisikValueLabel,Mcu_FisikValueNote),Mcu_KelainanID,Mcu_KelainanName,
Mcu_KelainanGroupSummaryID,Mcu_KelainanGroupSummaryName,Mcu_FitnessCategoryID,Mcu_FitnessCategoryName,
Mcu_FitnessCategoryEng,Mcu_FitnessCategoryLevel,
v_mcu_id, v_project_id
FROM cpone.t_kelainan_fisik
JOIN cpone.t_orderheader ON T_KelainanFiskT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive='Y'
JOIN cpone.so_resultentry ON T_KelainanFiskSo_ResultEntryID = So_ResultEntryID AND So_ResultEntryIsActive='Y'
JOIN cpone.t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND T_OrderDetailIsActive='Y'
JOIN cpone.nat_test ON Nat_TestCode = T_OrderDetailT_TestCode AND Nat_TestIsActive='Y'
JOIN cpone.t_test ON T_TestNat_TestID = Nat_TestID AND T_TestIsActive='Y'
JOIN cpone.group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND Group_ResultDetailIsActive='Y'
JOIN cpone.group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultIsActive='Y'
JOIN cpone.m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive='Y'
JOIN cpone.mcu_fisiksummary ON T_KelainanFiskMcu_FisikSummaryID = Mcu_FisikSummaryID AND Mcu_FisikSummaryIsActive='Y'
JOIN cpone.mcu_fisiksummarydetail ON Mcu_FisikSummaryDetailMcu_FisikSummaryID = Mcu_FisikSummaryID AND Mcu_FisikSummaryDetailIsActive='Y'
JOIN cpone.mcu_kelainan ON Mcu_FisikSummaryMcu_KelainanID = Mcu_KelainanID AND Mcu_KelainanIsActive='Y'
JOIN cpone.mcu_kelainangroup ON Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID AND Mcu_KelainanGroupIsActive='Y'
JOIN cpone.mcu_kelainangroupsummarydetail ON Mcu_KelainanGroupSummaryDetailMcu_KelainanID = Mcu_KelainanID AND Mcu_KelainanGroupSummaryDetailIsActive='Y'
JOIN cpone.mcu_kelainangroupsummary ON Mcu_KelainanGroupSummaryDetailMcu_KelainanGroupSummaryID = Mcu_KelainanGroupSummaryID AND Mcu_KelainanGroupSummaryIsActive='Y'
JOIN cpone.mcu_fitness_category ON Mcu_FisikSummaryMcu_FitnessCategoryID = Mcu_FitnessCategoryID AND Mcu_FitnessCategoryIsActive='Y'
JOIN cpone.mcu_fisikvalue ON Mcu_FisikValueT_OrderHeaderID = T_OrderHeaderID AND Mcu_FisikValueIsActive='Y' AND Mcu_FisikValueCode = Mcu_FisikSummaryDetailCode
LEFT JOIN cpone.fisik_template_map ON id_code = Mcu_FisikSummaryDetailCode
LEFT JOIN cpone.m_title ON M_PatientM_TitleID = M_TitleID AND M_TitleIsActive='Y'
WHERE T_KelainanFiskIsActive='Y' AND T_OrderHeaderID=p_order_header_id;
END$$
DELIMITER ;

View File

@@ -0,0 +1,150 @@
DROP PROCEDURE `sp_sync_kelainan_details_by_orderheader`;
DELIMITER ;;
CREATE PROCEDURE `sp_sync_kelainan_details_by_orderheader` (IN `p_order_header_id` int)
BEGIN
DECLARE v_mcu_id INT DEFAULT 0;
DECLARE v_numbering VARCHAR(150) DEFAULT '';
DECLARE v_project_id INT DEFAULT 0;
SELECT oh.T_OrderHeaderMgm_McuID
INTO v_mcu_id
FROM cpone.t_orderheader oh
WHERE oh.T_OrderHeaderID = p_order_header_id
AND oh.T_OrderHeaderIsActive = 'Y'
LIMIT 1;
IF v_mcu_id IS NULL OR v_mcu_id = 0 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'T_OrderHeaderID tidak ditemukan atau tidak aktif';
END IF;
SELECT COALESCE(NULLIF(mn.Mcu_NumberTableName, ''), NULLIF(mm.Mgm_McuNumber, ''), '')
INTO v_numbering
FROM cpone.mgm_mcu mm
LEFT JOIN cpone_corporate.mcu_number mn
ON mn.Mcu_NumberMgm_McuID = mm.Mgm_McuID
AND mn.Mcu_NumberIsActive = 'Y'
WHERE mm.Mgm_McuID = v_mcu_id
ORDER BY mn.Mcu_NumberID DESC
LIMIT 1;
SELECT Mcu_ProjectID
INTO v_project_id
FROM cpone_dashboard.mcu_project
WHERE Mcu_ProjectMcuID = v_mcu_id
LIMIT 1;
DELETE FROM cpone_dashboard.kelainan_details
WHERE T_OrderHeaderID = p_order_header_id;
INSERT INTO cpone_dashboard.kelainan_details (
Numbering, Tx_KelainanID, Tx_Type, T_OrderHeaderID, T_OrderHeaderDate, T_OrderHeaderLabNumber,
AgePatient, M_PatientID, M_PatientNoReg, M_PatientDOB, M_PatientGender, M_PatientIdentifierValue,
M_PatientNIP, M_PatientJob, M_PatientPosisi, M_PatientDivisi, M_PatientLocation, M_PatientDepartement,
PatientName, M_PatientName, GroupResult, Nat_TestID, Nat_TestCode, Nat_TestName, T_TestName, Result,
Mcu_KelainanID, Mcu_KelainanName, Mcu_KelainanGroupSummaryID, Mcu_KelainanGroupSummaryName,
Mcu_FitnessCategoryID, Mcu_FitnessCategoryName, Mcu_FitnessCategoryEng, Mcu_FitnessCategoryLevel,
Mgm_McuID, Mcu_ProjectID
)
SELECT
v_numbering,
T_KelainanNonLabID,'NONLAB',T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
T_OrderHeaderM_PatientAge,M_PatientID,M_PatientNoReg,M_PatientDOB,M_PatientGender,M_PatientIdentifierValue,
M_PatientNIP,M_PatientJob,M_PatientPosisi,M_PatientDivisi,M_PatientLocation,M_PatientDepartement,
CONCAT(IF(M_TitleName IS NULL,'',CONCAT(M_TitleName,'. ')), IF(M_PatientPrefix IS NULL,'',CONCAT(M_PatientPrefix,' ')), M_PatientName, IF(M_PatientSuffix IS NULL,'',CONCAT(M_PatientSuffix,' '))),
M_PatientName,
IF(Group_ResultName = 'LAB', 'LAB', Nat_TestName),
Nat_TestID,Nat_TestCode,Nat_TestName,T_TestName,'',Mcu_KelainanID,Mcu_KelainanName,
Mcu_KelainanGroupSummaryID,Mcu_KelainanGroupSummaryName,Mcu_FitnessCategoryID,Mcu_FitnessCategoryName,
Mcu_FitnessCategoryEng,Mcu_FitnessCategoryLevel,
v_mcu_id, v_project_id
FROM cpone.t_kelainan_nonlab
JOIN cpone.t_orderheader ON T_KelainanNonLabT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive='Y'
JOIN cpone.m_patient ON T_OrderHeaderM_PatientID=M_PatientID AND M_PatientIsActive='Y'
JOIN cpone.mcu_summarynonlab ON T_KelainanNonLabMcu_SummaryNonlabID=Mcu_SummaryNonlabID AND Mcu_SummaryNonlabIsActive='Y'
JOIN cpone.nat_test ON Mcu_SummaryNonlabNat_TestID=Nat_TestID AND Nat_TestIsActive='Y'
JOIN cpone.t_test ON T_TestNat_TestID=Nat_TestID AND T_TestIsActive='Y'
JOIN cpone.group_resultdetail ON Group_ResultDetailT_TestID=T_TestID AND Group_ResultDetailIsActive='Y'
JOIN cpone.group_result ON Group_ResultDetailGroup_ResultID=Group_ResultID AND Group_ResultIsActive='Y'
JOIN cpone.mcu_kelainan ON Mcu_SummaryNonlabMcu_KelainanID=Mcu_KelainanID AND Mcu_KelainanIsActive='Y'
JOIN cpone.mcu_kelainangroupsummarydetail ON Mcu_KelainanGroupSummaryDetailMcu_KelainanID=Mcu_KelainanID AND Mcu_KelainanGroupSummaryDetailIsActive='Y'
JOIN cpone.mcu_kelainangroupsummary ON Mcu_KelainanGroupSummaryDetailMcu_KelainanGroupSummaryID=Mcu_KelainanGroupSummaryID AND Mcu_KelainanGroupSummaryIsActive='Y'
JOIN cpone.mcu_fitness_category ON Mcu_SummaryNonlabMcu_FitnessCategoryID=Mcu_FitnessCategoryID AND Mcu_FitnessCategoryIsActive='Y'
LEFT JOIN cpone.m_title ON M_PatientM_TitleID=M_TitleID AND M_TitleIsActive='Y'
WHERE T_KelainanNonLabIsActive='Y' AND T_OrderHeaderID=p_order_header_id;
INSERT INTO cpone_dashboard.kelainan_details (
Numbering, Tx_KelainanID, Tx_Type, T_OrderHeaderID, T_OrderHeaderDate, T_OrderHeaderLabNumber,
AgePatient, M_PatientID, M_PatientNoReg, M_PatientDOB, M_PatientGender, M_PatientIdentifierValue,
M_PatientNIP, M_PatientJob, M_PatientPosisi, M_PatientDivisi, M_PatientLocation, M_PatientDepartement,
PatientName, M_PatientName, GroupResult, Nat_TestID, Nat_TestCode, Nat_TestName, T_TestName, Result,
Mcu_KelainanID, Mcu_KelainanName, Mcu_KelainanGroupSummaryID, Mcu_KelainanGroupSummaryName,
Mcu_FitnessCategoryID, Mcu_FitnessCategoryName, Mcu_FitnessCategoryEng, Mcu_FitnessCategoryLevel,
Mgm_McuID, Mcu_ProjectID
)
SELECT v_numbering,T_KelainanLabID,'LAB',T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
T_OrderHeaderM_PatientAge,M_PatientID,M_PatientNoReg,M_PatientDOB,M_PatientGender,M_PatientIdentifierValue,
M_PatientNIP,M_PatientJob,M_PatientPosisi,M_PatientDivisi,M_PatientLocation,M_PatientDepartement,
CONCAT(IF(M_TitleName IS NULL,'',CONCAT(M_TitleName,'. ')), IF(M_PatientPrefix IS NULL,'',CONCAT(M_PatientPrefix,' ')), M_PatientName, IF(M_PatientSuffix IS NULL,'',CONCAT(M_PatientSuffix,' '))),
M_PatientName,IF(Group_ResultName='LAB','LAB',Nat_TestName),Nat_TestID,Nat_TestCode,Nat_TestName,T_TestName,
IFNULL(T_OrderDetailResult,''),Mcu_KelainanID,Mcu_KelainanName,Mcu_KelainanGroupSummaryID,
Mcu_KelainanGroupSummaryName,Mcu_FitnessCategoryID,Mcu_FitnessCategoryName,Mcu_FitnessCategoryEng,
Mcu_FitnessCategoryLevel,
v_mcu_id, v_project_id
FROM cpone.t_kelainan_lab
JOIN cpone.t_orderdetail ON T_KelainanLabT_OrderDetailID=T_OrderDetailID AND T_OrderDetailIsActive='Y'
JOIN cpone.t_orderheader ON T_KelainanLabT_OrderHeaderID=T_OrderHeaderID AND T_OrderHeaderIsActive='Y'
JOIN cpone.m_patient ON T_OrderHeaderM_PatientID=M_PatientID AND M_PatientIsActive='Y'
JOIN cpone.mcu_summarylab ON T_KelainanLabMcu_SummaryLabID=Mcu_SummaryLabID AND Mcu_SummaryLabIsActive='Y'
JOIN cpone.nat_test ON Mcu_SummaryLabNat_TestID=Nat_TestID AND Nat_TestIsActive='Y'
JOIN cpone.t_test ON T_TestNat_TestID=Nat_TestID AND T_TestIsActive='Y'
JOIN cpone.group_resultdetail ON Group_ResultDetailT_TestID=T_TestID AND Group_ResultDetailIsActive='Y'
JOIN cpone.group_result ON Group_ResultDetailGroup_ResultID=Group_ResultID AND Group_ResultIsActive='Y'
JOIN cpone.mcu_kelainan ON Mcu_SummaryLabMcu_KelainanID=Mcu_KelainanID AND Mcu_KelainanIsActive='Y'
JOIN cpone.mcu_kelainangroupsummarydetail ON Mcu_KelainanGroupSummaryDetailMcu_KelainanID=Mcu_KelainanID AND Mcu_KelainanGroupSummaryDetailIsActive='Y'
JOIN cpone.mcu_kelainangroupsummary ON Mcu_KelainanGroupSummaryDetailMcu_KelainanGroupSummaryID=Mcu_KelainanGroupSummaryID AND Mcu_KelainanGroupSummaryIsActive='Y'
JOIN cpone.mcu_fitness_category ON Mcu_SummaryLabMcu_FitnessCategoryID=Mcu_FitnessCategoryID AND Mcu_FitnessCategoryIsActive='Y'
LEFT JOIN cpone.m_title ON M_PatientM_TitleID=M_TitleID AND M_TitleIsActive='Y'
WHERE T_KelainanLabIsActive='Y' AND T_OrderHeaderID=p_order_header_id
GROUP BY T_KelainanLabID;
INSERT INTO cpone_dashboard.kelainan_details (
Numbering, Tx_KelainanID, Tx_Type, T_OrderHeaderID, T_OrderHeaderDate, T_OrderHeaderLabNumber,
AgePatient, M_PatientID, M_PatientNoReg, M_PatientDOB, M_PatientGender, M_PatientIdentifierValue,
M_PatientNIP, M_PatientJob, M_PatientPosisi, M_PatientDivisi, M_PatientLocation, M_PatientDepartement,
PatientName, M_PatientName, GroupResult, Nat_TestID, Nat_TestCode, Nat_TestName, T_TestName, Result,
Mcu_KelainanID, Mcu_KelainanName, Mcu_KelainanGroupSummaryID, Mcu_KelainanGroupSummaryName,
Mcu_FitnessCategoryID, Mcu_FitnessCategoryName, Mcu_FitnessCategoryEng, Mcu_FitnessCategoryLevel,
Mgm_McuID, Mcu_ProjectID
)
SELECT v_numbering,T_KelainanFiskID,'FISIK',T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
T_OrderHeaderM_PatientAge,M_PatientID,M_PatientNoReg,M_PatientDOB,M_PatientGender,M_PatientIdentifierValue,
M_PatientNIP,M_PatientJob,M_PatientPosisi,M_PatientDivisi,M_PatientLocation,M_PatientDepartement,
CONCAT(IF(M_TitleName IS NULL,'',CONCAT(M_TitleName,'. ')), IF(M_PatientPrefix IS NULL,'',CONCAT(M_PatientPrefix,' ')), M_PatientName, IF(M_PatientSuffix IS NULL,'',CONCAT(M_PatientSuffix,' '))),
M_PatientName,IF(Group_ResultName='LAB','LAB',Nat_TestName),Nat_TestID,Nat_TestCode,Nat_TestName,
CONCAT(IF(label IS NULL, Mcu_KelainanGroupName, CONCAT(label, ' - ',IF(level = 1, parent_level_1,IF(level = 2, parent_level_2, IF(level = 3,parent_level_3,parent_level_4)))))),
IF(Mcu_FisikValueNote = '',Mcu_FisikValueLabel,Mcu_FisikValueNote),Mcu_KelainanID,Mcu_KelainanName,
Mcu_KelainanGroupSummaryID,Mcu_KelainanGroupSummaryName,Mcu_FitnessCategoryID,Mcu_FitnessCategoryName,
Mcu_FitnessCategoryEng,Mcu_FitnessCategoryLevel,
v_mcu_id, v_project_id
FROM cpone.t_kelainan_fisik
JOIN cpone.t_orderheader ON T_KelainanFiskT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive='Y'
JOIN cpone.so_resultentry ON T_KelainanFiskSo_ResultEntryID = So_ResultEntryID AND So_ResultEntryIsActive='Y'
JOIN cpone.t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND T_OrderDetailIsActive='Y'
JOIN cpone.nat_test ON Nat_TestCode = T_OrderDetailT_TestCode AND Nat_TestIsActive='Y'
JOIN cpone.t_test ON T_TestNat_TestID = Nat_TestID AND T_TestIsActive='Y'
JOIN cpone.group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND Group_ResultDetailIsActive='Y'
JOIN cpone.group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultIsActive='Y'
JOIN cpone.m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive='Y'
JOIN cpone.mcu_fisiksummary ON T_KelainanFiskMcu_FisikSummaryID = Mcu_FisikSummaryID AND Mcu_FisikSummaryIsActive='Y'
JOIN cpone.mcu_fisiksummarydetail ON Mcu_FisikSummaryDetailMcu_FisikSummaryID = Mcu_FisikSummaryID AND Mcu_FisikSummaryDetailIsActive='Y'
JOIN cpone.mcu_kelainan ON Mcu_FisikSummaryMcu_KelainanID = Mcu_KelainanID AND Mcu_KelainanIsActive='Y'
JOIN cpone.mcu_kelainangroup ON Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID AND Mcu_KelainanGroupIsActive='Y'
JOIN cpone.mcu_kelainangroupsummarydetail ON Mcu_KelainanGroupSummaryDetailMcu_KelainanID = Mcu_KelainanID AND Mcu_KelainanGroupSummaryDetailIsActive='Y'
JOIN cpone.mcu_kelainangroupsummary ON Mcu_KelainanGroupSummaryDetailMcu_KelainanGroupSummaryID = Mcu_KelainanGroupSummaryID AND Mcu_KelainanGroupSummaryIsActive='Y'
JOIN cpone.mcu_fitness_category ON Mcu_FisikSummaryMcu_FitnessCategoryID = Mcu_FitnessCategoryID AND Mcu_FitnessCategoryIsActive='Y'
JOIN cpone.mcu_fisikvalue ON Mcu_FisikValueT_OrderHeaderID = T_OrderHeaderID AND Mcu_FisikValueIsActive='Y' AND Mcu_FisikValueCode = Mcu_FisikSummaryDetailCode
LEFT JOIN cpone.fisik_template_map ON id_code = Mcu_FisikSummaryDetailCode
LEFT JOIN cpone.m_title ON M_PatientM_TitleID = M_TitleID AND M_TitleIsActive='Y'
WHERE T_KelainanFiskIsActive='Y' AND T_OrderHeaderID=p_order_header_id;
END;;
DELIMITER ;