85 lines
4.6 KiB
SQL
85 lines
4.6 KiB
SQL
-- PDP: Radiology/nonlab BIRT header reads decrypted patient data from patient_print_cache.
|
|
-- Birt_proxy_nonlab populates this cache before fetching BIRT, then deletes it after streaming.
|
|
|
|
USE `one_lab`;
|
|
|
|
DROP PROCEDURE IF EXISTS `sp_rpt_hasil_header_nonLab`;
|
|
|
|
DELIMITER $$
|
|
|
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_rpt_hasil_header_nonLab`(
|
|
IN `PID` int,
|
|
IN `username` varchar(100)
|
|
)
|
|
BEGIN
|
|
DELETE FROM patient_print_cache
|
|
WHERE ppc_created < NOW() - INTERVAL 5 MINUTE;
|
|
|
|
SELECT
|
|
DATE_FORMAT(T_OrderHeaderDate, "%d-%m-%Y") AS T_OrderHeaderDate,
|
|
T_OrderHeaderLabNumber,
|
|
CONCAT(M_TitleName, ". ", COALESCE(NULLIF(ppc.ppc_name, ''), M_PatientName)) AS M_PatientName,
|
|
m_sexname AS Gender,
|
|
M_PatientNoReg,
|
|
COALESCE(NULLIF(ppc.ppc_dob, ''), DATE_FORMAT(M_PatientDOB, "%d-%m-%Y")) AS M_PatientDOB,
|
|
T_OrderHeaderM_PatientAge,
|
|
M_CompanyName AS CorporateName,
|
|
COALESCE(NULLIF(ppc.ppc_address, ''), (
|
|
SELECT CONCAT(M_PatientAddressDescription, ' ', M_DistrictName, ' ', M_CityName)
|
|
FROM m_patientaddress AS p
|
|
LEFT JOIN (SELECT regional_cd, regional_nm AS M_KelurahanName, pro_cd, kab_cd, kec_cd FROM regional) reg_kel
|
|
ON NULLIF(TRIM(p.M_PatientAddressRegionalCd), '') = reg_kel.regional_cd
|
|
LEFT JOIN (SELECT regional_cd, regional_nm AS M_DistrictName FROM regional) reg_kec
|
|
ON CONCAT(reg_kel.pro_cd, reg_kel.kab_cd, reg_kel.kec_cd, '000') = reg_kec.regional_cd
|
|
LEFT JOIN (SELECT regional_cd, regional_nm AS M_CityName FROM regional) reg_kab
|
|
ON CONCAT(reg_kel.pro_cd, reg_kel.kab_cd, '000000') = reg_kab.regional_cd
|
|
WHERE M_PatientAddressM_PatientID = M_PatientID
|
|
ORDER BY M_PatientAddressM_PatientID
|
|
LIMIT 1
|
|
)) AS M_PatientAddress,
|
|
COALESCE(NULLIF(ppc.ppc_hp, ''), M_PatientHp) AS M_PatientHp,
|
|
COALESCE(NULLIF(ppc.ppc_email, ''), M_PatientEmail) AS M_PatientEmail,
|
|
'' AS M_PatientAddressCity,
|
|
COALESCE(NULLIF(ppc.ppc_address, ''), (
|
|
SELECT CONCAT(M_PatientAddressDescription, ' ', M_DistrictName, ' ', M_CityName)
|
|
FROM m_patientaddress AS p
|
|
LEFT JOIN (SELECT regional_cd, regional_nm AS M_KelurahanName, pro_cd, kab_cd, kec_cd FROM regional) reg_kel
|
|
ON NULLIF(TRIM(p.M_PatientAddressRegionalCd), '') = reg_kel.regional_cd
|
|
LEFT JOIN (SELECT regional_cd, regional_nm AS M_DistrictName FROM regional) reg_kec
|
|
ON CONCAT(reg_kel.pro_cd, reg_kel.kab_cd, reg_kel.kec_cd, '000') = reg_kec.regional_cd
|
|
LEFT JOIN (SELECT regional_cd, regional_nm AS M_CityName FROM regional) reg_kab
|
|
ON CONCAT(reg_kel.pro_cd, reg_kel.kab_cd, '000000') = reg_kab.regional_cd
|
|
WHERE M_PatientAddressM_PatientID = M_PatientID
|
|
ORDER BY M_PatientAddressM_PatientID
|
|
LIMIT 1
|
|
)) AS M_PatientAddressState,
|
|
M_CompanyAddress AS CorporateAddress,
|
|
M_CompanyEmail,
|
|
M_CompanyPhone,
|
|
M_CompanyAddressCity,
|
|
'' AS CorporateAddressState,
|
|
CONCAT(IFNULL(pj.M_DoctorPrefix, ''), ' ', IFNULL(pj.M_DoctorPrefix2, ''), ' ', pj.M_DoctorName, ' ', IFNULL(pj.M_DoctorSufix, ''), ' ', IFNULL(pj.M_DoctorSufix2, '')) AS M_DoctorName,
|
|
CONCAT(IFNULL(pjj.M_DoctorPrefix, ''), ' ', IFNULL(pjj.M_DoctorPrefix2, ''), ' ', pjj.M_DoctorName, ' ', IFNULL(pjj.M_DoctorSufix, ''), ' ', IFNULL(pjj.M_DoctorSufix2, '')) AS M_DoctorName2,
|
|
CONCAT(COALESCE(NULLIF(ppc.ppc_dob, ''), DATE_FORMAT(M_PatientDOB, "%d-%m-%Y")), ' / ', T_OrderHeaderM_PatientAge) AS Umur,
|
|
M_PatientNIP,
|
|
M_PatientJob,
|
|
M_PatientPosisi,
|
|
M_PatientDivisi,
|
|
M_PatientLocation,
|
|
CONCAT(M_PatientDepartement, ' - ', M_PatientNIP) AS M_PatientDepartement
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID AND M_TitleIsActive = 'Y'
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID AND M_CompanyIsActive = 'Y'
|
|
LEFT JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
LEFT JOIN m_doctor pjj ON T_OrderHeaderPj2M_DoctorID = pjj.M_DoctorID AND pjj.M_DoctorIsActive = 'Y'
|
|
LEFT JOIN m_doctor pj ON T_OrderHeaderPjM_DoctorID = pj.M_DoctorID AND pj.M_DoctorIsActive = 'Y'
|
|
JOIN so_resultentry ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID AND So_ResultEntryIsActive = 'Y'
|
|
LEFT JOIN patient_print_cache ppc ON ppc.ppc_order_id = T_OrderHeaderID
|
|
WHERE So_ResultEntryID = PID
|
|
AND T_OrderHeaderIsActive = 'Y'
|
|
GROUP BY T_OrderHeaderID;
|
|
END$$
|
|
|
|
DELIMITER ;
|