diff --git a/application/controllers/mockup/mcuoffline/Resumeindividucponev8.php b/application/controllers/mockup/mcuoffline/Resumeindividucponev8.php
new file mode 100644
index 0000000..56cf555
--- /dev/null
+++ b/application/controllers/mockup/mcuoffline/Resumeindividucponev8.php
@@ -0,0 +1,2580 @@
+db_onedev = $this->load->database("onedev", true);
+ $this->load->library('Mcudashboard');
+ // $this->load->library("SsPriceMou");
+ }
+ private function sync_resume_status_dashboard($resumeID)
+ {
+ $resumeID = intval($resumeID);
+ if ($resumeID <= 0) {
+ return;
+ }
+ $this->mcudashboard->upsert_patient_resume_status($resumeID);
+ }
+
+ private function upsert_published_dashboard_on_new_to_val($orderID, $oldStatus, $newStatus, $userID)
+ {
+ $orderID = intval($orderID);
+ $userID = intval($userID);
+ $oldStatus = strtoupper(trim((string)$oldStatus));
+ $newStatus = strtoupper(trim((string)$newStatus));
+
+ if ($orderID <= 0 || !($oldStatus === 'NEW' && $newStatus === 'VAL')) {
+ return;
+ }
+
+ $sql = "INSERT INTO published_mcu_dashboard (
+ Published_McuDasboardT_OrderHeaderID,
+ Published_McuDasboardStatus,
+ Published_McuDasboardIsActive,
+ Published_McuDasboardCreated,
+ Published_McuDasboardCreatedUserID,
+ Published_McuDasboardLastUpdated,
+ Published_McuDasboardLastUpdatedUserID
+ )
+ VALUES (?, 'N', 'Y', NOW(), ?, NOW(), ?)
+ ON DUPLICATE KEY UPDATE
+ Published_McuDasboardStatus = 'N',
+ Published_McuDasboardIsActive = 'Y',
+ Published_McuDasboardLastUpdated = NOW(),
+ Published_McuDasboardLastUpdatedUserID = VALUES(Published_McuDasboardLastUpdatedUserID)";
+ $this->db_onedev->query($sql, array($orderID, $userID, $userID));
+ }
+
+ private function ensure_publish_dashboard_file($orderID, $userID)
+ {
+ $orderID = intval($orderID);
+ $userID = intval($userID);
+ if ($orderID <= 0) {
+ return;
+ }
+
+ // Ensure published row exists for this order.
+ $sql = "INSERT INTO published_mcu_dashboard (
+ Published_McuDasboardT_OrderHeaderID,
+ Published_McuDasboardStatus,
+ Published_McuDasboardIsActive,
+ Published_McuDasboardCreated,
+ Published_McuDasboardCreatedUserID,
+ Published_McuDasboardLastUpdated,
+ Published_McuDasboardLastUpdatedUserID
+ )
+ VALUES (?, 'N', 'Y', NOW(), ?, NOW(), ?)
+ ON DUPLICATE KEY UPDATE
+ Published_McuDasboardIsActive = 'Y',
+ Published_McuDasboardLastUpdated = NOW(),
+ Published_McuDasboardLastUpdatedUserID = VALUES(Published_McuDasboardLastUpdatedUserID)";
+ $this->db_onedev->query($sql, array($orderID, $userID, $userID));
+
+ $sql = "SELECT Published_McuDasboardID
+ FROM published_mcu_dashboard
+ WHERE Published_McuDasboardT_OrderHeaderID = ?
+ AND Published_McuDasboardIsActive = 'Y'
+ ORDER BY Published_McuDasboardID DESC
+ LIMIT 1";
+ $qry = $this->db_onedev->query($sql, array($orderID));
+ if (!$qry || $qry->num_rows() === 0) {
+ return;
+ }
+ $publishedID = intval($qry->row()->Published_McuDasboardID);
+ if ($publishedID <= 0) {
+ return;
+ }
+
+ // Mark as processing before file generation.
+ $this->db_onedev->query(
+ "UPDATE published_mcu_dashboard
+ SET Published_McuDasboardStatus = 'P',
+ Published_McuDasboardLastUpdated = NOW(),
+ Published_McuDasboardLastUpdatedUserID = ?
+ WHERE Published_McuDasboardID = ?",
+ array($userID, $publishedID)
+ );
+
+ $rtn = $this->mcudashboard->generate_dashboard_files(0, $publishedID);
+ $isOk = false;
+ if (is_array($rtn) && isset($rtn[0]) && $rtn[0] === true && isset($rtn[1]) && is_array($rtn[1])) {
+ foreach ($rtn[1] as $item) {
+ if (isset($item['status']) && strtoupper($item['status']) === 'OK') {
+ $isOk = true;
+ break;
+ }
+ }
+ }
+
+ $this->db_onedev->query(
+ "UPDATE published_mcu_dashboard
+ SET Published_McuDasboardStatus = ?,
+ Published_McuDasboardLastUpdated = NOW(),
+ Published_McuDasboardLastUpdatedUserID = ?
+ WHERE Published_McuDasboardID = ?",
+ array($isOk ? 'Y' : 'N', $userID, $publishedID)
+ );
+
+ // Keep cpone_dashboard mirror in sync if SP is available.
+ $this->db_onedev->query("CALL cpone.sp_sync_published_mcu_dashboard_by_orderheaderid(?)", array($orderID));
+ }
+ public function getsetup()
+ {
+ try {
+ // if (!$this->isLogin) {
+ // $this->sys_error("Invalid Token");
+ // exit;
+ // }
+ $sql = "SELECT * FROM mgm_mcu WHERE Mgm_McuIsActive = 'Y'";
+ $qry = $this->db_onedev->query($sql, []);
+ if (!$qry) {
+ $message = $this->db_onedev->error();
+ $last_qry = $this->db_onedev->last_query();
+ $message['last_qry'] = $last_qry;
+ $this->sys_error($message);
+ exit;
+ }
+ $data = $qry->result_array();
+ $result = [
+ "records" => $data,
+ ];
+ $this->sys_ok($result);
+ } catch (Exception $exc) {
+ $message = $exc->getMessage();
+ $this->sys_error($message);
+ }
+ }
+
+ function get_report_mcu()
+ {
+ if (!$this->isLogin) {
+ $this->sys_error("Invalid Token");
+ exit;
+ }
+
+ $prm = $this->sys_input;
+ $mgmMcuID = 0;
+ if (isset($prm['Mgm_McuID'])) {
+ $mgmMcuID = intval($prm['Mgm_McuID']);
+ } else if (isset($prm['setupID'])) {
+ $mgmMcuID = intval($prm['setupID']);
+ }
+
+ if ($mgmMcuID <= 0) {
+ $this->sys_error("Mgm_McuID is required");
+ exit;
+ }
+
+ $sql = "SELECT
+ t.Mcu_ReportUrlTemplateID AS id,
+ t.Mcu_ReportUrlTemplateName AS reportName,
+ t.Mcu_ReportUrlTemplateType AS reportType,
+ t.Mcu_ReportUrlTemplateUrl AS reportUrl,
+ t.Mcu_ReportUrlTemplateParams AS reportParams,
+ IF(mr.Mgm_McuReportMcu_ReportUrlTemplateID = t.Mcu_ReportUrlTemplateID, 'Y', 'N') AS selected
+ FROM mcu_report_url_template t
+ LEFT JOIN mgm_mcureport mr
+ ON mr.Mgm_McuReportMcu_ReportUrlTemplateID = t.Mcu_ReportUrlTemplateID
+ AND mr.Mgm_McuReportMgm_McuID = ?
+ AND mr.Mgm_McuReportIsActive = 'Y'
+ WHERE t.Mcu_ReportUrlTemplateIsActive = 'Y'
+ ORDER BY t.Mcu_ReportUrlTemplateName ASC";
+ $query = $this->db_onedev->query($sql, array($mgmMcuID));
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+
+ $rows = $query->result_array();
+ $selected = null;
+ foreach ($rows as $row) {
+ if ($row['selected'] === 'Y') {
+ $selected = $row;
+ break;
+ }
+ }
+
+ $result = array(
+ "total" => count($rows),
+ "records" => $rows,
+ "selected" => $selected
+ );
+ $this->sys_ok($result);
+ exit;
+ }
+ function search()
+ {
+ if (!$this->isLogin) {
+ $this->sys_error("Invalid Token");
+ exit;
+ }
+
+ $prm = $this->sys_input;
+ $search = '%' . $prm['search'] . '%';
+ $page = $prm["page"];
+ $startDate = $prm["startDate"];
+ $endDate = $prm["endDate"];
+ $setupID = $prm["setupID"];
+ $ROW_PER_PAGE = 20;
+ $start_offset = 0;
+ // print_r($prm);
+
+ if (isset($prm["page"])) {
+ if (
+ is_numeric($prm["page"]) && $prm["page"] > 0
+ ) {
+ $start_offset = ($page - 1) * $ROW_PER_PAGE;
+ }
+ }
+ $sql = "SELECT
+ COUNT(T_OrderHeaderID) AS total
+ FROM t_orderheader
+ JOIN m_patient
+ ON T_OrderHeaderM_PatientID = M_PatientID
+ JOIN corporate
+ ON T_OrderHeaderCorporateID = CorporateID
+ JOIN m_branch ON T_OrderHeaderM_BranchID = M_BranchID
+ LEFT JOIN m_title
+ ON M_PatientM_TitleID = M_TitleID
+ WHERE (DATE_FORMAT(T_OrderHeaderDate, '%Y-%m-%d') BETWEEN ? AND ?)
+ AND (M_PatientName LIKE ? OR T_OrderHeaderLabNumber LIKE ?)
+ AND T_OrderHeaderMgm_McuID = ?
+ AND T_OrderHeaderIsActive = 'Y'
+ ORDER BY T_OrderHeaderLabNumber
+ ";
+ $query = $this->db_onedev->query($sql, [$startDate, $endDate, $search, $search, $setupID]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $totalPage = $query->row_array()['total'];
+ $sql = "SELECT
+ T_OrderHeaderID AS orderID,
+ IFNULL(reFisik.So_ResultEntryID, 0) AS reIDHaji,
+ IFNULL(Mcu_ResumeStatus, 'NEW') as status,
+ T_OrderHeaderM_BranchID AS branchID,
+ DATE_FORMAT(T_OrderHeaderDate, '%d-%m-%Y') AS orderDate,
+ T_OrderHeaderLabNumber AS labNumber,
+ T_OrderHeaderM_PatientID AS patientID,
+ T_OrderHeaderCorporateID AS corporateID,
+ T_OrderHeaderMgm_McuID AS setupID,
+ IF(M_BackgroundReportCode IS NULL OR M_BackgroundReportCode = '', 'DFLT', M_BackgroundReportCode) AS bg_code,
+ IF(M_BackgroundReportPrm IS NULL OR M_BackgroundReportPrm = '', '', M_BackgroundReportPrm) AS bg_prm,
+ UPPER(T_OrderHeaderM_PatientAge) AS patientAge,
+ DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') AS patientDOB,
+ M_PatientNoReg AS patientReg,
+ M_PatientName AS patientName,
+ UPPER(CONCAT(IF(ISNULL(M_TitleName),'',CONCAT(M_TitleName,'.')),
+ ' ',
+ IFNULL(M_PatientPrefix,''),
+ ' ',
+ M_PatientName,
+ ' ',
+ IFNULL(M_PatientSuffix,''))) AS patientFullname,
+ CASE
+ WHEN LOWER(M_PatientGender) = 'male' THEN 'LAKI-LAKI'
+ WHEN LOWER(M_PatientGender) = 'female' THEN 'PEREMPUAN'
+ END patientGender,
+ M_PatientPhoto AS patientFoto,
+ M_PatientPhotoThumb AS patientFotoThumb,
+ CorporateCode AS corporateCode,
+ UPPER(CorporateName) AS corporateName,
+ M_BranchCode AS branchID,
+ M_BranchName AS branchName
+ FROM t_orderheader
+ JOIN m_patient
+ ON T_OrderHeaderM_PatientID = M_PatientID
+ JOIN corporate
+ ON T_OrderHeaderCorporateID = CorporateID
+ JOIN m_branch ON T_OrderHeaderM_BranchID = M_BranchID
+ LEFT JOIN mgm_background_report ON T_OrderHeaderMgm_McuID = Mgm_BackgroundReportMgm_McuID
+ AND Mgm_BackgroundReportIsActive = 'Y'
+ LEFT JOIN m_background_report ON Mgm_BackgroundReportM_BackgroundReportCode = M_BackgroundReportCode
+ AND M_BackgroindReportIsActive = 'Y'
+ LEFT JOIN m_title
+ ON M_PatientM_TitleID = M_TitleID
+ LEFT JOIN mcu_resume
+ ON T_OrderHeaderID = Mcu_ResumeT_OrderHeaderID
+ AND Mcu_ResumeIsActive = 'Y'
+ LEFT JOIN so_resultentry reFisik
+ ON T_OrderHeaderID = reFisik.So_ResultEntryT_OrderHeaderID
+ AND reFisik.So_ResultEntryIsActive = 'Y'
+ AND reFisik.So_ResultEntryNonlab_TemplateID = '27'
+ WHERE (DATE_FORMAT(T_OrderHeaderDate, '%Y-%m-%d') BETWEEN ? AND ?)
+ AND (M_PatientName LIKE ? OR T_OrderHeaderLabNumber LIKE ?)
+ AND T_OrderHeaderMgm_McuID = ?
+ AND T_OrderHeaderIsActive = 'Y'
+ ORDER BY T_OrderHeaderLabNumber
+ LIMIT ? OFFSET ? ";
+ $query = $this->db_onedev->query($sql, [$startDate, $endDate, $search, $search, $setupID, $ROW_PER_PAGE, $start_offset]);
+ $sql_search = $this->db_onedev->last_query();
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ // echo $this->db_onedev->last_query();
+ $result = [
+ "total" => ceil($totalPage / $ROW_PER_PAGE),
+ "records" => $query->result_array(),
+ "sql" => $sql_search
+ ];
+ $this->sys_ok($result);
+ }
+
+ function getdetail()
+ {
+ if (!$this->isLogin) {
+ $this->sys_error("Invalid Token");
+ exit;
+ }
+
+ $prm = $this->sys_input;
+ $orderid = $prm['orderid'];
+ $sql = "SELECT
+ Mcu_ResumeID as resumeID,
+ Mcu_ResumeM_DoctorID as resumeDoctorID,
+ Mcu_ResumeT_OrderHeaderID as orderID,
+ Mcu_ResumeStatus as status,
+ Mcu_ResumeVerification as verivication,
+ Mcu_ResumeValidation as validation,
+ Mcu_ResumeKesimpulan as kesimpulan,
+ IFNULL(Mcu_ResumeEngConlusion, '') as conclusion,
+ Mcu_ResumeRekomendasi as rekomendasi,
+ IFNULL(Mcu_ResumeEngRecomendation, '') as recomendation,
+ Mcu_ResumeSaran as saran,
+ IFNULL(Mcu_ResumeEngAdvice, '') as advice,
+ IFNULL(Mcu_ResumeEngAdvice, '') as saran_eng,
+ IFNULL(Mcu_ResumeMcu_FitnessCategoryID, 0) as fitnessCategory,
+ CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSuffix,' ', M_DoctorSuffix2, ' ') doctorName
+ FROM
+ mcu_resume
+ LEFT JOIN mcu_resume_eng ON Mcu_ResumeEngMcu_ResumeID = Mcu_ResumeID AND Mcu_ResumeEngIsActive = 'Y'
+ LEFT JOIN m_doctor
+ ON Mcu_ResumeM_DoctorID = M_DoctorID
+ WHERE Mcu_ResumeT_OrderHeaderID = ?
+ AND Mcu_ResumeIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [$orderid]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ // echo $this->db_onedev->last_query();
+ $getHeader = $query->result_array();
+ $dataHeader = array();
+ if (count($getHeader) == 0) {
+ $dataHeader = array(
+ "resumeID" => 0,
+ "resumeDoctorID" => 0,
+ "orderID" => $orderid,
+ "status" => 'NEW',
+ "verivication" => 'N',
+ "validation" => 'N',
+ "kesimpulan" => '',
+ "rekomendasi" => '',
+ "saran" => '',
+ "conclusion" => '',
+ "recomendation" => '',
+ "advice" => '',
+ "fitnessCategory" => 0,
+ "doctorName" => "",
+ "puasaStatus" => null,
+ "puasaLabel" => ""
+ );
+ } else {
+ $dataHeader = $getHeader[0];
+ $dataHeader['puasaStatus'] = null;
+ $dataHeader['puasaLabel'] = "";
+ }
+
+ $sqlPuasa = "SELECT
+ OrderPhlebotomyStatus
+ FROM order_phlebotomy
+ WHERE OrderPhlebotomyT_OrderHeaderID = ?
+ AND OrderPhlebotomyRequirement = 'puasa_tp'
+ AND OrderPhlebotomyIsActive = 'Y'
+ ORDER BY OrderPhlebotomyID DESC
+ LIMIT 1";
+ $queryPuasa = $this->db_onedev->query($sqlPuasa, [$orderid]);
+ if (!$queryPuasa) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+
+ $puasaRow = $queryPuasa->row_array();
+ if (!empty($puasaRow)) {
+ $statusPuasa = strtoupper(trim($puasaRow['OrderPhlebotomyStatus']));
+ $labelPuasa = "";
+
+ if ($statusPuasa === 'P') {
+ $labelPuasa = "Puasa";
+ } else if ($statusPuasa === 'T') {
+ $labelPuasa = "Tidak Puasa";
+ }
+
+ $dataHeader['puasaStatus'] = $statusPuasa;
+ $dataHeader['puasaLabel'] = $labelPuasa;
+ }
+
+ $sql = "SELECT * FROM (
+ SELECT
+ T_OrderDetailID AS detailOrderID,
+ Group_ResultName AS groupResultName,
+ So_ResultEntryID AS resultID,
+ So_ResultEntryValidation1 AS resultValidation,
+ So_ResultEntryStatus AS resultStatus,
+ T_OrderDetailT_TestID AS testID,
+ T_TestName AS testName,
+ IFNULL(Mcu_ResumeDetailsID, 0) AS resumeDetailsID,
+ IFNULL(Mcu_ResumeID, 0) AS resumeID,
+ Mcu_ResumeKesimpulan AS resumeKesimpulan,
+ Mcu_ResumeRekomendasi AS resumeRekomendasi,
+ Mcu_ResumeSaran AS resumeSaran,
+ IFNULL(Mcu_ResumeEngAdvice, '') AS resumeAdvice,
+ IFNULL(Mcu_ResumeEngRecomendation, '') AS resumeRecomendation,
+ IFNULL(Mcu_ResumeEngConlusion, '') AS resumeConclusion,
+ Mcu_ResumeDetailsResult resumeDetailResult,
+ So_ResultEntryDetailResult AS resumeEntryResult,
+ Group_ResultResumeMcu AS category,
+ CASE
+ WHEN Group_ResultResumeMcu = 'NONLAB' THEN
+ CASE
+ WHEN Mcu_ResumeSaran IS NOT NULL AND TRIM(Mcu_ResumeSaran) <> '' THEN Mcu_ResumeSaran
+ WHEN Mcu_ResumeSaran IS NULL OR TRIM(Mcu_ResumeSaran) <> '' THEN fn_getadvicenonlab(So_ResultEntryID)
+ ELSE Mcu_ResumeSaran
+ END
+ WHEN Group_ResultResumeMcu = 'FISIK' THEN
+ CASE
+ WHEN Mcu_ResumeSaran IS NOT NULL AND TRIM(Mcu_ResumeSaran) <> '' THEN Mcu_ResumeSaran
+ WHEN Mcu_ResumeSaran IS NULL OR TRIM(Mcu_ResumeSaran) <> '' THEN fn_getadvicefisik(So_ResultEntryID)
+ ELSE Mcu_ResumeSaran
+ END
+ ELSE Mcu_ResumeSaran
+ END AS saranso,
+ fn_countabnormal(So_ResultEntryID) AS isNormal,
+ TRIM(CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSuffix,' ', M_DoctorSuffix2, ' ')) doctorName,
+ Mcu_ResumeM_DoctorID AS doctorID,
+ IFNULL(Mcu_ResumeStatus,'NEW') AS status,
+ CASE
+ WHEN Mcu_ResumeDetailsResult IS NULL OR TRIM(Mcu_ResumeDetailsResult) = '' THEN So_ResultEntryDetailResult
+ WHEN Mcu_ResumeDetailsResult IS NOT NULL OR TRIM(Mcu_ResumeDetailsResult) <> '' THEN Mcu_ResumeDetailsResult
+ END AS result
+ FROM t_orderdetail
+ JOIN so_resultentry
+ ON T_OrderDetailT_OrderHeaderID = So_ResultEntryT_OrderHeaderID
+ AND T_OrderDetailID = So_ResultEntryT_OrderDetailID
+ AND So_ResultEntryIsActive = 'Y' AND T_OrderDetailIsActive = 'Y'
+ AND So_ResultEntryValidation1 = 'Y'
+ JOIN group_resultdetail
+ ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID
+ AND Group_ResultDetailIsActive ='Y'
+ JOIN group_result
+ ON Group_ResultID = Group_ResultDetailGroup_ResultID
+ AND Group_ResultResumeMcu IN ('NONLAB', 'FISIK')
+ AND Group_ResultIsActive ='Y'
+ JOIN t_test
+ ON T_OrderDetailT_TestID= T_TestID
+ AND T_TestIsActive = 'Y'
+ LEFT JOIN nonlab_template_mcu
+ ON T_TestNat_TestID = NonlabTemplateMcuT_TestID
+ AND NonlabTemplateMcuM_LangID = 1
+ AND NonlabTemplateMcuIsActive = 'Y'
+ LEFT JOIN so_resultentrydetail
+ ON So_ResultEntryID = So_ResultEntryDetailSo_ResultEntryID
+ AND NonlabTemplateMcuNonlabTemplateDetailID = So_ResultEntryDetailNonlab_TemplateDetailID
+ AND So_ResultEntryDetailIsActive = 'Y'
+ AND T_OrderDetailIsActive = 'Y'
+ LEFT JOIN mcu_resume
+ ON T_OrderDetailT_OrderHeaderID = Mcu_ResumeT_OrderHeaderID AND Mcu_ResumeIsActive = 'Y'
+ LEFT JOIN mcu_resume_eng ON Mcu_ResumeEngMcu_ResumeID = Mcu_ResumeID AND Mcu_ResumeEngIsActive = 'Y'
+ LEFT JOIN mcu_resumedetails
+ ON T_OrderDetailID = Mcu_ResumeDetailsT_OrderDetailID
+ AND Mcu_ResumeDetailsIsActive = 'Y'
+ AND Mcu_ResumeID = Mcu_ResumeDetailsMcu_ResumeID
+ LEFT JOIN m_doctor
+ ON Mcu_ResumeM_DoctorID = M_DoctorID
+ AND M_DoctorIsActive = 'Y'
+ LEFT JOIN so_resultentry_category_result
+ ON So_ResultEntryCategoryResultSo_ResultEntryID = So_ResultEntryID
+ AND So_ResultEntryCategoryResultIsActive = 'Y'
+ WHERE T_OrderDetailT_OrderHeaderID = ?
+ GROUP BY T_OrderDetailT_TestID
+ UNION
+ (SELECT
+ T_OrderDetailID AS detailOrderID,
+ 'ADDITIONAL' AS groupResultName,
+ So_ResultEntryID AS resultID,
+ So_ResultEntryValidation1 AS resultValidation,
+ So_ResultEntryStatus AS resultStatus,
+ T_OrderDetailT_TestID AS testID,
+ 'ADDITIONAL' AS testName,
+ IFNULL(Mcu_ResumeDetailsID, 0) AS resumeDetailsID,
+ IFNULL(Mcu_ResumeID, 0) AS resumeID,
+ Mcu_ResumeKesimpulan AS resumeKesimpulan,
+ Mcu_ResumeRekomendasi AS resumeRekomendasi,
+ Mcu_ResumeSaran AS resumeSaran,
+ IFNULL(Mcu_ResumeEngAdvice, '') AS resumeAdvice,
+ IFNULL(Mcu_ResumeEngRecomendation, '') AS resumeRecomendation,
+ IFNULL(Mcu_ResumeEngConlusion, '') AS resumeConclusion,
+ Mcu_ResumeDetailsResult resumeDetailResult,
+ 'Terlampir' AS resumeEntryResult,
+ 'ADDITIONAL' AS category,
+ '' AS saranso,
+ fn_countabnormal(So_ResultEntryID) AS isNormal,
+ TRIM(CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSuffix,' ', M_DoctorSuffix2, ' ')) doctorName,
+ Mcu_ResumeM_DoctorID AS doctorID,
+ IFNULL(Mcu_ResumeStatus,'NEW') AS status,
+ 'Terlampir' AS result
+ FROM t_orderdetail
+ JOIN so_resultentry
+ ON T_OrderDetailT_OrderHeaderID = So_ResultEntryT_OrderHeaderID
+ AND T_OrderDetailID = So_ResultEntryT_OrderDetailID
+ AND So_ResultEntryIsActive = 'Y' AND T_OrderDetailIsActive = 'Y'
+ JOIN t_test
+ ON T_OrderDetailT_TestID= T_TestID
+ AND T_TestIsActive = 'Y'
+ JOIN so_resultentrydetail
+ ON So_ResultEntryID = So_ResultEntryDetailSo_ResultEntryID
+ AND So_ResultEntryDetailIsActive = 'Y'
+ AND T_OrderDetailIsActive = 'Y'
+ LEFT JOIN mcu_resume
+ ON T_OrderDetailT_OrderHeaderID = Mcu_ResumeT_OrderHeaderID AND Mcu_ResumeIsActive = 'Y'
+ LEFT JOIN mcu_resume_eng ON Mcu_ResumeEngMcu_ResumeID = Mcu_ResumeID AND Mcu_ResumeEngIsActive = 'Y'
+ LEFT JOIN mcu_resumedetails
+ ON T_OrderDetailID = Mcu_ResumeDetailsT_OrderDetailID
+ AND Mcu_ResumeDetailsIsActive = 'Y'
+ AND Mcu_ResumeID = Mcu_ResumeDetailsMcu_ResumeID
+ LEFT JOIN m_doctor
+ ON Mcu_ResumeM_DoctorID = M_DoctorID
+ AND M_DoctorIsActive = 'Y'
+ WHERE T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailT_TestID IN (2571,2573,2573,3450,2572)
+ GROUP BY T_OrderDetailT_TestID LIMIT 1)
+ ) x
+ ORDER BY category";
+ $queryGetDetail = "";
+ $query = $this->db_onedev->query($sql, [$orderid, $orderid]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $queryGetDetail = $this->db_onedev->last_query();
+ // echo $this->db_onedev->last_query();
+ $data = $query->result_array();
+ if(count($data) == 0){
+ $data = [];
+ }
+ $this->load->library("Kesimpulanfisik");
+ //getlab
+ // {
+ // "detailOrderID": "1632088",
+ // "groupResultName": "Pemeriksaan Fisik",
+ // "resultID": "97",
+ // "resultValidation": "Y",
+ // "resultStatus": "NEW",
+ // "testID": "2562",
+ // "testName": "Pemeriksaan Fisik",
+ // "resumeDetailsID": "3",
+ // "resumeID": "2",
+ // "resumeKesimpulan": "Pada saat ini didapatkan kelainan berupa :
Takhikardi ( 120 x/menit ), Laju pernafasan ( 15 x/menit ), Tekanan Darah 120/80 mmHg ( Prehipertensi ), Suhu Febri, Overweight ( BMI : 24.09 )
Hernia : Umbilikus (D), Inguinal (D, S) edit",
+ // "resumeRekomendasi": null,
+ // "resumeSaran": null,
+ // "resumeDetailResult": "Pada saat ini didapatkan kelainan berupa :
Takhikardi ( 120 x/menit ), Laju pernafasan ( 15 x/menit ), Tekanan Darah 120/80 mmHg ( Prehipertensi ), Suhu Febri, Overweight ( BMI : 24.09 )
Hernia : Umbilikus (D), Inguinal (D, S)",
+ // "resumeEntryResult": null,
+ // "category": "FISIK",
+ // "isNormal": 1,
+ // "doctorName": null,
+ // "doctorID": "0",
+ // "status": "NEW",
+ // "result": "Pada saat ini didapatkan kelainan berupa :
Takhikardi ( 120 x/menit ), Laju pernafasan ( 15 x/menit ), Tekanan Darah 120/80 mmHg ( Prehipertensi ), Suhu Febri, Overweight ( BMI : 24.09 )
Hernia : Umbilikus (D), Inguinal (D, S)"
+ // }
+ $lab = $this->getlab($orderid, 'N');
+ $labArr = [];
+ for ($i = 0; $i < count($lab); $i++) {
+ $isNormal = 0;
+
+ if ($lab[$i]['resultIsNormal'] == "N") {
+ $isNormal = 1;
+ }
+ $data[] = [
+ "detailOrderID" => $lab[$i]['orderDetailID'],
+ "groupResultName" => $lab[$i]['groupName'],
+ "resultID" => $lab[$i]['resultID'],
+ "resultValidation" => $lab[$i]['resultValidation'],
+ "resultStatus" => $lab[$i]['resultStatus'],
+ "testID" => $lab[$i]['testID'],
+ "subGroupID" => $lab[$i]['subGroupID'],
+ "testName" => $lab[$i]['groupName'],
+ "resumeDetailsID" => $lab[$i]['resumeDetailsID'],
+ "resumeID" => $lab[$i]['resumeID'],
+ "resumeKesimpulan" => $lab[$i]['resumeKesimpulan'],
+ "resumeRekomendasi" => $lab[$i]['resumeRekomendasi'],
+ "resumeSaran" => $lab[$i]['saran'],
+ "resumeAdvice" => $lab[$i]['resumeAdvice'],
+ "resumeRecomendation" => $lab[$i]['resumeRecomendation'],
+ "resumeConclusion" => $lab[$i]['resumeConclusion'],
+ "saranso" => $lab[$i]['saran'],
+ "resumeDetailResult" => $lab[$i]['resumeDetailResult'],
+ "resumeEntryResult" => $lab[$i]['kelainan'],
+ "generateKelainan" => $lab[$i]['generateKelainan'],
+ "category" => "LAB",
+ "isNormal" => $isNormal,
+ "doctorName" => '',
+ "doctorID" => '',
+ "status" => $lab[$i]['resultStatus'],
+ "result" => $lab[$i]['kelainan']
+ ];
+ }
+
+ // $kesimpulanFisik =
+ // $kesimpulanFisik = $this->kesimpulanfisik->kesimpulan('97');
+ for ($i = 0; $i < count($data); $i++) {
+ if ($data[$i]['category'] == 'FISIK') {
+ $kesimpulanFisik = $this->kesimpulanfisik->kesimpulan($data[$i]['resultID']);
+ $data[$i]['result'] = $kesimpulanFisik;
+ if ($kesimpulanFisik != 'Tidak ditemukan kelainan.') {
+ $data[$i]['isNormal'] = 1;
+ } else {
+ $data[$i]['isNormal'] = 0;
+ }
+ }
+ }
+ $kesimpulanarr = [];
+ $saranArr = [];
+ for ($i = 0; $i < count($data); $i++) {
+ if (trim($data[0]['resumeKesimpulan']) == '' || $data[0]['resumeKesimpulan'] == null) {
+ if (intval($data[$i]['isNormal']) > 0) {
+ if (trim($data[$i]['result']) != '') {
+ # code ..
+ $kesimpulanarr[] = $data[$i]['result'];
+ }
+ }
+ }
+ if (trim($data[0]['resumeSaran']) == '' || $data[0]['resumeSaran'] == null) {
+ if (intval($data[$i]['isNormal']) > 0) {
+ if (trim($data[$i]['saranso']) != '') {
+ $explodeSaran = explode("@", $data[$i]['saranso']);
+ if (count($explodeSaran) > 0) {
+ array_push($saranArr, ...$explodeSaran);
+ }
+ }
+ }
+ }
+ }
+ // if (count($kesimpulanarr) > 0) {
+ // $kesimpulan = implode(", ", $kesimpulanarr);
+ // $saran = (implode(", ", array_unique($saranArr)));
+ // $dataHeader['kesimpulan'] = $kesimpulan;
+ // $dataHeader['saran'] = $saran;
+ // for ($i = 0; $i < count($data); $i++) {
+ // $data[$i]['resumeKesimpulan'] = $kesimpulan;
+ // $data[$i]['resumeSaran'] = $saran;
+ // }
+ // }
+ // if (trim($kesimpulan) != '') {
+ // if ($kesimpulanFisik != 'Tidak ditemukan kelainan.') {
+ // $kesimpulan = $kesimpulan . ", \n" . $kesimpulanFisik;
+ // }
+ // } else {
+ // if ($kesimpulanFisik != 'Tidak ditemukan kelainan.') {
+ // $kesimpulan = $kesimpulanFisik;
+ // }
+ // }
+ $dataHeader['detail'] = $data;
+
+ $result = [
+ "header" => $dataHeader,
+ "records" => $data,
+ "qry" => $queryGetDetail
+ ];
+ $this->sys_ok($result);
+ }
+ function getdoctor()
+ {
+ if (!$this->isLogin) {
+ $this->sys_error("Invalid Token");
+ exit;
+ }
+ $prm = $this->sys_input;
+ $search = $prm['search'];
+ $query = " SELECT M_DoctorID,
+ M_DoctorID doctorID,
+ M_DoctorPrefix,
+ M_DoctorPrefix2,
+ M_DoctorName,
+ M_DoctorSuffix,
+ M_DoctorSuffix2,
+ M_DoctorCode ,
+ CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSuffix,' ', M_DoctorSuffix2, ' ') doctorName
+ FROM m_doctor
+ WHERE M_DoctorIsActive = 'Y'
+ AND CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSuffix,' ', M_DoctorSuffix2, ' ') LIKE '%$search%'
+ ";
+ //echo $query;
+ $rows = $this->db_onedev->query($query)->result_array();
+
+ $result = array(
+ "total" => count($rows),
+ "records" => $rows,
+ "query" => $this->db_onedev->last_query()
+ );
+ $this->sys_ok($result);
+ exit;
+ }
+ function getFitnessCategory()
+ {
+ if (!$this->isLogin) {
+ $this->sys_error("Invalid Token");
+ exit;
+ }
+ $prm = $this->sys_input;
+
+ $query = "SELECT
+ Mcu_FitnessCategoryID id,
+ CONCAT(Mcu_FitnessCategoryName, ' (',Mcu_FitnessCategoryEng,')' ) as name,
+ Mcu_FitnessCategoryEng as nameEng,
+ Mcu_FitnessCategoryLevel as level
+ FROM `mcu_fitness_category`
+ WHERE `Mcu_FitnessCategoryIsActive` = 'Y';
+ ";
+ //echo $query;
+ $rows = $this->db_onedev->query($query)->result_array();
+
+ $result = array(
+ "total" => count($rows),
+ "records" => $rows,
+ "query" => $this->db_onedev->last_query()
+ );
+ $this->sys_ok($result);
+ exit;
+ }
+ function save()
+ {
+ if (!$this->isLogin) {
+ $this->sys_error("Invalid Token");
+ exit;
+ }
+ $prm = $this->sys_input;
+ $act = $prm['data']['act'];
+ $data = $prm['data'];
+ $userid = $this->sys_user["M_UserID"];
+ if ($act == 'VAL') {
+ if (
+ $data['fitnessCategory'] == '' ||
+ intval($data['fitnessCategory']) == 0 ||
+ $data['fitnessCategory'] == null
+ ) {
+ $this->sys_error("Pilih kategori fitness atau generate terlebih dahulu");
+ exit;
+ }
+
+ $sql = "SELECT IFNULL(GROUP_CONCAT(DISTINCT So_ResultEntryValidation1), 'Y') as val
+ FROM t_orderdetail
+ JOIN so_resultentry
+ ON T_OrderDetailT_OrderHeaderID = So_ResultEntryT_OrderHeaderID
+ AND T_OrderDetailID = So_ResultEntryT_OrderDetailID
+ AND So_ResultEntryIsActive = 'Y' AND T_OrderDetailIsActive = 'Y'
+ AND So_ResultEntryT_OrderHeaderID = ?
+ JOIN group_resultdetail
+ ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID
+ AND T_OrderDetailT_TestID NOT IN (2571,2573,2573,3450,2572)
+ AND Group_ResultDetailIsActive ='Y'
+ JOIN group_result
+ ON Group_ResultID = Group_ResultDetailGroup_ResultID AND Group_ResultID <> 35
+ AND Group_ResultResumeMcu IN ('NONLAB', 'FISIK')
+ AND Group_ResultIsActive ='Y' AND T_OrderDetailIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [$data['orderID']]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error_db("Error cek validasi " . $this->db_onedev->last_query());
+ exit;
+ }
+ $cekValidation = $query->row_array();
+ $expdCek = explode(',', $cekValidation['val']);
+ if (in_array('N', $expdCek) && $cekValidation['val'] != null && trim($cekValidation['val']) != '' && count($expdCek) > 0) {
+ $this->sys_error("Hasil Nonlab atau fisik belum di validasi .....");
+ exit;
+ }
+ }
+
+ $status = 'NEW';
+ $statusLog = $act;
+ $val = 'N';
+ $dt = '0000-00-00 00:00:00';
+ $verification = 'N';
+ $verificationUserID = 0;
+ $verificationDateTime = null;
+ $statusBefore = 'NEW';
+ if ($act == 'VAL') {
+ $status = 'VAL';
+ $val = 'Y';
+ $dt = date("Y-m-d H:i:s");
+ $verification = 'Y';
+ $verificationUserID = $userid;
+ $verificationDateTime = $dt;
+ } else if ($act == 'UNVAL') {
+ $val = 'N';
+ $status = 'NEW';
+ $dt = date("Y-m-d H:i:s");
+ $verification = 'N';
+ $verificationUserID = 0;
+ $verificationDateTime = null;
+ }
+ $jsonBefore = "";
+ $jsonAfter = "";
+ //insert mcu_resume
+ $resumeID = 0;
+ $sql = "SELECT *
+ FROM mcu_resume
+ WHERE Mcu_ResumeT_OrderHeaderID = ?
+ AND Mcu_ResumeIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [$data['orderID']]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+
+ $dataCek = $query->result_array();
+ if (count($dataCek) > 0 && isset($dataCek[0]['Mcu_ResumeStatus'])) {
+ $statusBefore = $dataCek[0]['Mcu_ResumeStatus'];
+ }
+ if (count($dataCek) == 0) {
+ $sql = "INSERT INTO mcu_resume
+ (Mcu_ResumeT_OrderHeaderID,
+ Mcu_ResumeStatus,
+ Mcu_ResumeValidation,
+ Mcu_ResumeValidationDateTime,
+ Mcu_ResumeValidationUserID,
+ Mcu_ResumeVerification,
+ Mcu_ResumeVerificationDateTime,
+ Mcu_ResumeVerificationUserID,
+ Mcu_ResumeKesimpulan,
+ Mcu_ResumeRekomendasi,
+ Mcu_ResumeSaran,
+ Mcu_ResumeMcu_FitnessCategoryID)
+ VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
+ $query = $this->db_onedev->query($sql, [
+ $data['orderID'],
+ $status,
+ $val,
+ $dt,
+ $userid,
+ $verification,
+ $verificationDateTime,
+ $verificationUserID,
+ $data['header']['kesimpulan'],
+ $data['header']['rekomendasi'],
+ $data['header']['saran'],
+ $data['fitnessCategory'],
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $resumeID = $this->db_onedev->insert_id();
+
+ $sql = "INSERT INTO mcu_resume_eng(
+ Mcu_ResumeEngMcu_ResumeID,
+ Mcu_ResumeEngAdvice,
+ Mcu_ResumeEngConlusion,
+ Mcu_ResumeEngRecomendation,
+ Mcu_ResumeEngCreated,
+ Mcu_ResumeEngCreatedUserID)
+ VALUES(?,?,?,?,NOW(),?)";
+ $query = $this->db_onedev->query($sql, [
+ $resumeID,
+ $data['header']['advice'],
+ $data['header']['conclusion'],
+ $data['header']['recomendation'],
+ $userid
+ ]);
+ } else {
+ if ($act != 'VAL' && $act != 'UNVAL') {
+ $statusLog = "UPDATE";
+ }
+ // if ($act == 'VAL') {
+ // // $this->generate_kelainan_lab($data['orderID']);
+
+ // }
+ $jsonBefore = $dataCek[0];
+
+
+ $resumeID = $dataCek[0]['Mcu_ResumeID'];
+
+ //get detail for log
+ $sql = "SELECT *
+ FROM mcu_resumedetails
+ WHERE
+ Mcu_ResumeDetailsMcu_ResumeID = ?
+ AND Mcu_ResumeDetailsIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [$resumeID,]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $detail = $query->result_array();
+ $jsonBefore['detail'] = $detail;
+ $sql = "UPDATE mcu_resume
+ SET Mcu_ResumeStatus = ?,
+ Mcu_ResumeValidation = ?,
+ Mcu_ResumeValidationDateTime = ?,
+ Mcu_ResumeValidationUserID = ?,
+ Mcu_ResumeVerification = ?,
+ Mcu_ResumeVerificationDateTime = ?,
+ Mcu_ResumeVerificationUserID = ?,
+ Mcu_ResumeKesimpulan = ?,
+ Mcu_ResumeRekomendasi = ?,
+ Mcu_ResumeSaran = ?,
+ Mcu_ResumeMcu_FitnessCategoryID = ?
+ WHERE Mcu_ResumeID = ?";
+ $query = $this->db_onedev->query($sql, [
+ $status,
+ $val,
+ $dt,
+ $userid,
+ $verification,
+ $verificationDateTime,
+ $verificationUserID,
+ $data['header']['kesimpulan'],
+ $data['header']['rekomendasi'],
+ $data['header']['saran'],
+ $data['fitnessCategory'],
+ $resumeID,
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $sql = "SELECT * FROM mcu_resume_eng WHERE Mcu_ResumeEngMcu_ResumeID = ? AND Mcu_ResumeEngIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [
+ $resumeID,
+ ]);
+ $cekEng = $query->result_array();
+ if (empty($cekEng)) {
+ $sql = "INSERT INTO mcu_resume_eng(
+ Mcu_ResumeEngMcu_ResumeID,
+ Mcu_ResumeEngAdvice,
+ Mcu_ResumeEngConlusion,
+ Mcu_ResumeEngRecomendation,
+ Mcu_ResumeEngCreated,
+ Mcu_ResumeEngCreatedUserID)
+ VALUES(?,?,?,?,NOW(),?)";
+ $query = $this->db_onedev->query($sql, [
+ $resumeID,
+ $data['header']['advice'],
+ $data['header']['conclusion'],
+ $data['header']['recomendation'],
+ $userid
+ ]);
+ } else {
+ $sql = "UPDATE mcu_resume_eng
+ SET Mcu_ResumeEngAdvice = ?,
+ Mcu_ResumeEngConlusion = ?,
+ Mcu_ResumeEngRecomendation = ?
+ WHERE Mcu_ResumeEngMcu_ResumeID = ? AND Mcu_ResumeEngIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [
+ $data['header']['advice'],
+ $data['header']['conclusion'],
+ $data['header']['recomendation'],
+ $resumeID,
+ ]);
+ }
+ }
+ for ($i = 0; $i < count($data['detail']); $i++) {
+ $detail = $data['detail'][$i];
+ $result = $detail['result'];
+ if ($result == null) {
+ $result = '';
+ }
+ if ($detail['category'] == 'LAB') {
+
+ $sql = "SELECT Mcu_ResumeDetailsID
+ FROM mcu_resumedetails
+ WHERE Mcu_ResumeDetailsNat_SubSubGroupID = ?
+ AND Mcu_ResumeDetailsMcu_ResumeID = ?
+ AND Mcu_ResumeDetailsIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [$detail['subGroupID'], $resumeID,]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $cekDetail = $query->result_array();
+ // print_r($cekDetail);
+ if (count($cekDetail) == 0) {
+ $sql = "INSERT INTO mcu_resumedetails(
+ Mcu_ResumeDetailsMcu_ResumeID,
+ Mcu_ResumeDetailsCategory,
+ Mcu_ResumeDetailsNat_SubSubGroupID,
+ Mcu_ResumeDetailsResult,
+ Mcu_ResumeDetailsCreated,
+ Mcu_ResumeDetailsUserID)
+ VALUES(?,?,?,?,NOW(),?)";
+ $query = $this->db_onedev->query($sql, [
+ $resumeID,
+ $detail['category'],
+ $detail['subGroupID'],
+ $result,
+ $userid,
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ } else {
+ $sql = "UPDATE mcu_resumedetails
+ SET Mcu_ResumeDetailsResult = ?,
+ Mcu_ResumeDetailsLastUpdated = NOW(),
+ Mcu_ResumeDetailsUserID = ?
+ WHERE Mcu_ResumeDetailsID = ?";
+ $query = $this->db_onedev->query($sql, [
+ $result,
+ $userid,
+ $cekDetail[0]['Mcu_ResumeDetailsID']
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ }
+ } else {
+ $sql = "SELECT Mcu_ResumeDetailsID
+ FROM mcu_resumedetails
+ WHERE Mcu_ResumeDetailsT_OrderDetailID = ?
+ AND Mcu_ResumeDetailsT_TestID = ?
+ AND Mcu_ResumeDetailsCategory = ?
+ AND Mcu_ResumeDetailsIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [
+ $detail['detailOrderID'],
+ $detail['testID'],
+ $detail['category'],
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $cekDetail = $query->result_array();
+ if (count($cekDetail) == 0) {
+ $sql = "INSERT INTO mcu_resumedetails(
+ Mcu_ResumeDetailsMcu_ResumeID,
+ Mcu_ResumeDetailsCategory,
+ Mcu_ResumeDetailsT_OrderDetailID,
+ Mcu_ResumeDetailsT_TestID,
+ Mcu_ResumeDetailsResult,
+ Mcu_ResumeDetailsCreated,
+ Mcu_ResumeDetailsUserID)
+ VALUES(?,?,?,?,?,NOW(),?)";
+ $query = $this->db_onedev->query($sql, [
+ $resumeID,
+ $detail['category'],
+ $detail['detailOrderID'],
+ $detail['testID'],
+ $result,
+ $userid,
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ } else {
+ $sql = "UPDATE mcu_resumedetails
+ SET Mcu_ResumeDetailsResult = ?,
+ Mcu_ResumeDetailsLastUpdated = NOW(),
+ Mcu_ResumeDetailsUserID = ?
+ WHERE Mcu_ResumeDetailsID = ?";
+ $query = $this->db_onedev->query($sql, [
+ $result,
+ $userid,
+ $cekDetail[0]['Mcu_ResumeDetailsID']
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ }
+ }
+ }
+ $sql = "SELECT *
+ FROM mcu_resume
+ WHERE Mcu_ResumeID = ?
+ AND Mcu_ResumeIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [$resumeID]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $jsonAfter = $query->result_array()[0];
+ //get detail for log
+ $sql = "SELECT *
+ FROM mcu_resumedetails
+ WHERE
+ Mcu_ResumeDetailsMcu_ResumeID = ?
+ AND Mcu_ResumeDetailsIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [$resumeID,]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $detail = $query->result_array();
+ $jsonAfter['detail'] = $detail;
+
+ $sql = "INSERT INTO cpone_log.log_mcu_resume
+ (log_Mcu_ResumeMcu_ResumeID,
+ log_Mcu_ResumeJsonBefore,
+ log_Mcu_ResumeJsonAfter,
+ log_Mcu_ResumeJsonPrm,
+ log_Mcu_ResumeType,
+ log_Mcu_ResumeUserID,
+ log_Mcu_ResumeCreated)
+ VALUES(?,?,?,?,?,?,NOW())";
+ $query = $this->db_onedev->query($sql, [
+ $resumeID,
+ json_encode($jsonBefore),
+ json_encode($jsonAfter),
+ json_encode($prm),
+ $statusLog,
+ $userid
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $this->upsert_published_dashboard_on_new_to_val($data['orderID'], $statusBefore, $status, $userid);
+ if ($status === 'VAL' && $val === 'Y') {
+ $this->ensure_publish_dashboard_file($data['orderID'], $userid);
+ }
+ $this->sync_resume_status_dashboard($resumeID);
+ $this->sys_ok('ok');
+ }
+ function getlab($id, $isApi)
+ {
+ $prm = $this->sys_input;
+
+ // Mcu_KelainanName AS kelainanName,
+ // Mcu_KelainanGroupName AS kelainanGroupName,
+ // LEFT JOIN t_kelainan_lab
+ // ON T_OrderDetailT_OrderHeaderID = T_KelainanLabT_OrderHeaderID
+ // AND T_OrderDetailID = T_KelainanLabT_OrderDetailID
+ // AND T_TestNat_TestID = T_KelainanLabNat_TestID
+ // AND T_KelainanLabIsActive = 'Y'
+ // LEFT JOIN mcu_summarylab
+ // ON T_KelainanLabMcu_SummaryLabID = Mcu_SummaryLabID
+ // AND T_TestNat_TestID = Mcu_SummaryLabNat_TestID
+ // AND Mcu_SummaryLabIsActive = 'Y'
+ // LEFT join mcu_kelainan on Mcu_SummaryLabMcu_KelainanID = Mcu_KelainanID
+ // AND Mcu_KelainanIsActive = 'Y'
+ // LEFT join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID
+ // AND Mcu_KelainanGroupIsActive = 'Y'
+ $sql = "SELECT
+ T_OrderDetailID,
+ '' AS smLabID,
+ '' AS natTestID,
+ '' AS value,
+ '' AS kelainanID,
+ '' AS smLabType,
+ '' AS isNormal,
+ '' AS methode,
+ '' AS methodeID,
+ '' AS kelainanSaran,
+ T_OrderDetailT_OrderHeaderID AS orderID,
+ T_OrderDetailID AS orderDetailID,
+ T_OrderDetailT_TestID AS testID,
+ T_OrderDetailT_TestCode AS testCode,
+ T_OrderDetailT_TestSasCode AS testSasCode,
+ T_OrderDetailT_TestName AS testName,
+ T_OrderDetailResult AS result,
+ IFNULL(Nat_SubSubGroupID, 0) AS subGroupID,
+ T_OrderDetailMinValue AS minValues,
+ T_OrderDetailMaxValue AS maxValues,
+ IFNULL(Nat_SubSubGroupName, T_OrderDetailT_TestName) AS groupName,
+ T_TestNat_TestID AS natTestID,
+ T_TestIsQuantitative as isKuantitatif,
+ CASE
+ WHEN T_OrderDetailResultFlag IS NULL THEN 'Y'
+ WHEN T_OrderDetailResultFlag = '' THEN 'Y'
+ ELSE 'N'
+ END testNormal,
+ T_OrderDetailResultFlag,
+ null AS resultID,
+ 'N' AS resultValidation,
+ 'NEW' AS resultStatus,
+ Mcu_ResumeDetailsID AS resumeDetailsID,
+ CASE
+ WHEN Mcu_ResumeDetailsMcu_ResumeID IS NULL THEN 'N'
+ WHEN Mcu_ResumeDetailsMcu_ResumeID IS NOT NULL THEN 'Y'
+ END as hasResult,
+ Mcu_ResumeID AS resumeID ,
+ Mcu_ResumeKesimpulan AS resumeKesimpulan ,
+ Mcu_ResumeRekomendasi AS resumeRekomendasi ,
+ Mcu_ResumeSaran AS resumeSaran ,
+ Mcu_ResumeDetailsResult AS resumeDetailResult ,
+ Mcu_ResumeDetailsResult AS resumeEntryResult
+ FROM t_orderdetail
+ JOIN group_resultdetail
+ ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID
+ AND Group_ResultDetailIsActive ='Y'
+ JOIN group_result
+ ON Group_ResultID = Group_ResultDetailGroup_ResultID
+ AND Group_ResultResumeMcu IN ('LAB')
+ JOIN t_test
+ ON T_OrderDetailT_TestID = T_TestID
+ JOIN nat_test ON T_TestNat_TestID = Nat_TestID
+ LEFT JOIN nat_subsubgroup
+ ON T_TestNat_SubSubGroupID = Nat_SubSubGroupID
+ LEFT JOIN mcu_resume
+ ON T_OrderDetailT_OrderHeaderID = Mcu_ResumeT_OrderHeaderID
+ AND Mcu_ResumeIsActive = 'Y'
+ LEFT JOIN mcu_resumedetails
+ -- ON T_OrderDetailID = Mcu_ResumeDetailsT_OrderDetailID
+ ON Mcu_ResumeDetailsMcu_ResumeID = Mcu_ResumeID
+ AND T_TestNat_SubSubGroupID = Mcu_ResumeDetailsNat_SubSubGroupID
+ AND Mcu_ResumeDetailsIsActive = 'Y'
+ WHERE T_OrderDetailT_OrderHeaderID = {$id}
+ AND T_OrderDetailIsActive = 'Y'
+ AND Nat_TestIsResult = 'Y'";
+
+ // echo $sql;
+ $query = $this->db_onedev->query($sql, []);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $test = $query->result_array();
+ for ($i = 0; $i < count($test); $i++) {
+ $e = $test[$i];
+ $kelainan = '';
+ $saran = '';
+ $rstNormal = 'Y';
+ if ($e['hasResult'] == 'Y' && ($e['resumeDetailResult'] != null || trim($e['resumeDetailResult']) != "")) {
+ $kelainan = $e['resumeDetailResult'];
+ if (trim($e['resumeDetailResult']) !== 'Dalam batas normal') {
+ $rstNormal = 'N';
+ }
+ } else {
+ if ($e['result'] !== null) {
+ # code...
+ if ($e['testNormal'] == 'N' && is_numeric($e['result'])) {
+ if (floatval($e['result']) >= floatval($e['maxValues'])) {
+ $kelainan = $e['testName'] . " meningkat ({$e['result']})";
+ }
+ if (floatval($e['result']) < floatval($e['minValues'])) {
+ $kelainan = $e['testName'] . " menurun ({$e['result']})";
+ }
+ $rstNormal = 'N';
+ }
+ if ($e['testNormal'] == 'N' && !is_numeric($e['result'])) {
+ $kelainan = $e['testName'] . " ({$e['result']})";
+ $rstNormal = 'N';
+ }
+ if ($e['testNormal'] == 'Y') {
+ $kelainan = "Dalam batas normal";
+ $rstNormal = 'Y';
+ }
+ }
+ }
+ $test[$i]['kelainan'] = $kelainan;
+ $test[$i]['generateKelainan'] = $this->generatekelainancek($e);
+ $test[$i]['resultIsNormal'] = $rstNormal;
+ $test[$i]['saran'] = $saran;
+ }
+ $newGab = [];
+
+ $group = [];
+ //penggabungan test
+ for ($i = 0; $i < count($test); $i++) {
+ $e = $test[$i];
+
+ if (!in_array($e['groupName'], $group)) {
+ $group[] = $e['groupName'];
+ if ($e['resultIsNormal'] == 'Y') {
+ $e['kelainan'] = '';
+ $e['generateKelainan'] = '';
+ }
+ $newGab[] = $e;
+ } else {
+ for ($k = 0; $k < count($newGab); $k++) {
+ $nv = $newGab[$k];
+ if ($e['groupName'] == $nv['groupName']) {
+
+ if ($test[$i]['resultIsNormal'] == 'N') {
+ # code...
+ if (trim($newGab[$k]['kelainan']) == "") {
+ $newGab[$k]['kelainan'] = $test[$i]['kelainan'];
+ } else {
+ if ($newGab[$k]['kelainan'] != $test[$i]['kelainan']) {
+ $newGab[$k]['kelainan'] = $newGab[$k]['kelainan'] . ', ' . $test[$i]['kelainan'];
+ }
+ }
+ if (trim($newGab[$k]['saran']) == "" && trim($test[$i]['saran']) != '') {
+ $newGab[$k]['saran'] = $test[$i]['saran'];
+ $newGab[$k]['saranArr'][] = $test[$i]['saran'];
+ } else {
+ if (trim($test[$i]['saran']) != '') {
+ $newGab[$k]['saran'] = $newGab[$k]['saran'] . '@' . $test[$i]['saran'];
+ }
+ }
+ if ($newGab[$k]['testIDKelainan'] == '' && !isset($newGab[$k]['testIDKelainan'])) {
+ # code...
+ $newGab[$k]['testIDKelainan'] = $test[$i]['testID'];
+ } else {
+ $newGab[$k]['testIDKelainan'] = $newGab[$k]['testIDKelainan'] . ',' . $test[$i]['testID'];
+ }
+ }
+ if (trim($newGab[$k]['generateKelainan']) == "") {
+ $newGab[$k]['generateKelainan'] = $test[$i]['generateKelainan'];
+ } else {
+ if ($newGab[$k]['generateKelainan'] != $test[$i]['generateKelainan']) {
+ $newGab[$k]['generateKelainan'] = $newGab[$k]['generateKelainan'] . ', ' . $test[$i]['generateKelainan'];
+ }
+ }
+ $newGab[$k]['testID'] = $newGab[$k]['testID'] . ', ' . $test[$i]['testID'];
+ // $newGab[$k]['generateKelainan'] = $newGab[$k]['generateKelainan'] . ', ' . $test[$i]['generateKelainan'];
+ }
+ }
+ }
+ }
+ for ($i = 0; $i < count($newGab); $i++) {
+ $newGab[$i]['normalValue'] = '';
+ if (trim(str_replace(',', '', $newGab[$i]['kelainan'])) != '') {
+ $newGab[$i]['resultIsNormal'] = 'N';
+ } else {
+ $newGab[$i]['resultIsNormal'] = 'Y';
+ $newGab[$i]['kelainan'] = 'Dalam batas normal';
+ }
+
+ //saran unique
+ $expldSaran = explode('@', $newGab[$i]['saran']);
+ $expldSaranUnique = array_unique($expldSaran);
+ $newGab[$i]['saran'] = implode('@', $expldSaranUnique);
+ $expldTestIdKelainan = explode('@', $newGab[$i]['testIDKelainan']);
+ $expldTestIdKelainanUnique = array_unique($expldTestIdKelainan);
+ $newGab[$i]['testIDKelainan'] = implode(',', $expldTestIdKelainanUnique);
+ }
+ if ($isApi == 'Y') {
+ $this->sys_ok([
+ "test" => $test,
+ 'gab' => $newGab
+ ]);
+ } else {
+ return $newGab;
+ }
+ }
+ function generatekelainancek($e)
+ {
+ $kelainan = "";
+ $rstNormal = "";
+ if ($e['result'] !== null) {
+ if ($e['testNormal'] == 'N' && is_numeric($e['result'])) {
+ if (floatval($e['result']) >= floatval($e['maxValues'])) {
+ $kelainan = $e['testName'] . " meningkat ({$e['result']})";
+ }
+ if (floatval($e['result']) < floatval($e['minValues'])) {
+ $kelainan = $e['testName'] . " menurun ({$e['result']})";
+ }
+ $rstNormal = 'N';
+ }
+ if ($e['testNormal'] == 'N' && !is_numeric($e['result'])) {
+ $kelainan = $e['testName'] . " ({$e['result']})";
+ $rstNormal = 'N';
+ }
+ if ($e['testNormal'] == 'Y') {
+ $kelainan = $e['testName'] . " ({$e['result']}) " . "dalam batas normal";
+ $rstNormal = 'Y';
+ }
+ } else {
+ $kelainan = "" . $e['testName'] . " belum ada hasil" . "";
+ $rstNormal = 'Y';
+ }
+ return $kelainan;
+ }
+ function getlabtest($id, $isApi)
+ {
+ $prm = $this->sys_input;
+
+ $this->generate_kelainan_lab($id);
+ // Mcu_KelainanName AS kelainanName,
+ // Mcu_KelainanGroupName AS kelainanGroupName,
+ // LEFT JOIN t_kelainan_lab
+ // ON T_OrderDetailT_OrderHeaderID = T_KelainanLabT_OrderHeaderID
+ // AND T_OrderDetailID = T_KelainanLabT_OrderDetailID
+ // AND T_TestNat_TestID = T_KelainanLabNat_TestID
+ // AND T_KelainanLabIsActive = 'Y'
+ // LEFT JOIN mcu_summarylab
+ // ON T_KelainanLabMcu_SummaryLabID = Mcu_SummaryLabID
+ // AND T_TestNat_TestID = Mcu_SummaryLabNat_TestID
+ // AND Mcu_SummaryLabIsActive = 'Y'
+ // LEFT join mcu_kelainan on Mcu_SummaryLabMcu_KelainanID = Mcu_KelainanID
+ // AND Mcu_KelainanIsActive = 'Y'
+ // LEFT join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID
+ // AND Mcu_KelainanGroupIsActive = 'Y'
+ $sql = "SELECT
+ T_OrderDetailID,
+ '' AS smLabID,
+ '' AS natTestID,
+ '' AS value,
+ '' AS kelainanID,
+ '' AS smLabType,
+ '' AS isNormal,
+ '' AS methode,
+ '' AS methodeID,
+ '' AS kelainanSaran,
+ T_OrderDetailT_OrderHeaderID AS orderID,
+ T_OrderDetailID AS orderDetailID,
+ T_OrderDetailT_TestID AS testID,
+ T_OrderDetailT_TestCode AS testCode,
+ T_OrderDetailT_TestSasCode AS testSasCode,
+ T_OrderDetailT_TestName AS testName,
+ T_OrderDetailResult AS result,
+ IFNULL(Nat_SubSubGroupID, 0) AS subGroupID,
+ T_OrderDetailMinValue AS minValues,
+ T_OrderDetailMaxValue AS maxValues,
+ IFNULL(Nat_SubSubGroupName, T_OrderDetailT_TestName) AS groupName,
+ T_TestNat_TestID AS natTestID,
+ T_TestIsQuantitative as isKuantitatif,
+ CASE
+ WHEN T_OrderDetailResultFlag IS NULL THEN 'Y'
+ WHEN T_OrderDetailResultFlag = '' THEN 'Y'
+ ELSE 'N'
+ END testNormal,
+ T_OrderDetailResultFlag,
+ null AS resultID,
+ 'N' AS resultValidation,
+ 'NEW' AS resultStatus,
+ Mcu_ResumeDetailsID AS resumeDetailsID,
+ CASE
+ WHEN Mcu_ResumeDetailsMcu_ResumeID IS NULL THEN 'N'
+ WHEN Mcu_ResumeDetailsMcu_ResumeID IS NOT NULL THEN 'Y'
+ END as hasResult,
+ Mcu_ResumeID AS resumeID ,
+ Mcu_ResumeKesimpulan AS resumeKesimpulan ,
+ Mcu_ResumeRekomendasi AS resumeRekomendasi ,
+ Mcu_ResumeSaran AS resumeSaran ,
+ Mcu_ResumeDetailsResult AS resumeDetailResult ,
+ Mcu_ResumeDetailsResult AS resumeEntryResult
+ FROM t_orderdetail
+ JOIN group_resultdetail
+ ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID
+ AND Group_ResultDetailIsActive ='Y'
+ JOIN group_result
+ ON Group_ResultID = Group_ResultDetailGroup_ResultID
+ AND Group_ResultResumeMcu IN ('LAB')
+ JOIN t_test
+ ON T_OrderDetailT_TestID = T_TestID
+ JOIN nat_test ON T_TestNat_TestID = Nat_TestID
+ LEFT JOIN nat_subsubgroup
+ ON T_TestNat_SubSubGroupID=Nat_SubSubGroupID
+ LEFT JOIN mcu_resume
+ ON T_OrderDetailT_OrderHeaderID = Mcu_ResumeT_OrderHeaderID
+ AND Mcu_ResumeIsActive = 'Y'
+ LEFT JOIN mcu_resumedetails
+ -- ON T_OrderDetailID = Mcu_ResumeDetailsT_OrderDetailID
+ ON Mcu_ResumeDetailsMcu_ResumeID = Mcu_ResumeID
+ AND T_TestNat_SubSubGroupID = Mcu_ResumeDetailsNat_SubSubGroupID
+ AND Mcu_ResumeDetailsIsActive = 'Y'
+ WHERE T_OrderDetailT_OrderHeaderID = {$id}
+ AND T_OrderDetailIsActive = 'Y'
+ AND Nat_TestIsResult = 'Y'";
+
+ // echo $sql;
+ $query = $this->db_onedev->query($sql, []);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $test = $query->result_array();
+ for ($i = 0; $i < count($test); $i++) {
+ $e = $test[$i];
+ $kelainan = '';
+ $saran = '';
+ $rstNormal = 'Y';
+ // if ($e['hasResult'] == 'Y') {
+ // $kelainan = $e['resumeDetailResult'];
+ // if (trim($e['resumeDetailResult']) !== 'Dalam batas normal') {
+ // $rstNormal = 'N';
+ // }
+ // } else
+ if (true) {
+ if ($e['result'] !== null) {
+ # code...
+ if ($e['testNormal'] == 'N' && is_numeric($e['result'])) {
+ if (floatval($e['result']) >= floatval($e['maxValues'])) {
+ $kelainan = $e['testName'] . " meningkat ({$e['result']})";
+ }
+ if (floatval($e['result']) < floatval($e['minValues'])) {
+ $kelainan = $e['testName'] . " menurun ({$e['result']})";
+ }
+ $rstNormal = 'N';
+ }
+ if ($e['testNormal'] == 'N' && !is_numeric($e['result'])) {
+ $kelainan = $e['testName'] . " ({$e['result']})";
+ $rstNormal = 'N';
+ }
+ if ($e['testNormal'] == 'Y') {
+ $kelainan = "Dalam batas normal";
+ $rstNormal = 'Y';
+ }
+ }
+ // if ($e['smLabID'] != null) {
+ // // print_r("masuk else");
+ // if ($e['testNormal'] == 'Y') {
+ // if ($e['smLabType'] == '<' || $e['smLabType'] == '<=') {
+ // $ket = 'menurun';
+ // $value_comparison = $e['minValues'];
+ // }
+ // if ($e['smLabType'] == '>' || $e['smLabType'] == '>=') {
+ // $ket = 'meningkat';
+ // $value_comparison = $e['maxValues'];
+ // }
+ // //echo "Y";
+ // // if ($e['methode'] == 'N' && $this->dynamic_comparison($e['value'], $e['smLabType'], $value_comparison)) {
+ // if ($e['smLabType'] == '<' || $e['smLabType'] == '<=') {
+ // $ket = 'menurun';
+ // }
+ // if ($e['smLabType'] == '>' || $e['smLabType'] == '>=') {
+ // $ket = 'meningkat';
+ // }
+ // $kelainan = "";
+ // // $kelainan = $e['testName'] . " " . $ket . "({$e['result']})";
+ // if ($e['kelainanSaran'] != null) {
+ // # code...
+ // $saran = $e['kelainanSaran'];
+ // }
+ // $rstNormal = 'Y';
+ // // }
+ // } else {
+ // $value_comparison = $e['value'];
+ // if ($e['smLabType'] == '!=' || $e['smLabType'] == '==') {
+ // // if ($this->dynamic_comparison($e['value'], $e['smLabType'], $value_comparison)) {
+ // //echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
+ // //langsung hasil
+ // // $kelainan = $e;
+ // $kelainan = $e['testName'] . " " . "{$e['result']}";
+ // if ($e['kelainanSaran'] != null) {
+ // # code...
+ // $saran = $e['kelainanSaran'];
+ // }
+ // $rstNormal = 'N';
+ // // }
+ // } else {
+ // // if (is_numeric($e['value']) && $this->dynamic_comparison($e['value'], $e['smLabType'], $value_comparison)) {
+ // if ($e['smLabType'] == '<' || $e['smLabType'] == '<=') {
+ // $ket = 'menurun';
+ // }
+ // if ($e['smLabType'] == '>' || $e['smLabType'] == '>=') {
+ // $ket = 'meningkat';
+ // }
+ // // $kelainan = $e;
+ // $kelainan = $e['testName'] . " " . $ket . "({$e['result']})";
+ // if ($e['kelainanSaran'] != null) {
+ // # code...
+ // $saran = $e['kelainanSaran'];
+ // }
+ // $rstNormal = 'N';
+ // // }
+ // }
+ // }
+ // }
+
+
+ // $sql = "SELECT
+ // Mcu_SummaryLabID AS smLabID,
+ // Mcu_SummaryLabNat_TestID AS natTestID,
+ // Mcu_SummaryLabValue AS value,
+ // Mcu_summaryLabMcu_KelainanID AS kelainanID,
+ // Mcu_SummaryLabType AS smLabType,
+ // Mcu_SummaryLabIsNormalValue AS isNormal,
+ // Mcu_SummaryLabWithMethode AS methode,
+ // Mcu_SummaryLabNat_MethodeID AS methodeID,
+ // Mcu_KelainanName AS kelainanName,
+ // Mcu_KelainanGroupName AS kelainanGroupName,
+ // `fn_getadvicebykelainanid`(Mcu_summaryLabMcu_KelainanID) AS kelainanSaran
+ // FROM mcu_summarylab
+ // join mcu_kelainan on Mcu_SummaryLabMcu_KelainanID = Mcu_KelainanID
+ // join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID
+ // WHERE Mcu_SummaryLabNat_TestID = '{$e['natTestID']}'
+ // AND Mcu_SummaryLabIsActive = 'Y'";
+ // $query = $this->db_onedev->query($sql, []);
+ // // echo $this->db_onedev->last_query();
+ // // exit;
+ // if (!$query) {
+ // $message = $this->db_onedev->error();
+ // $message['qry'] = $this->db_onedev->last_query();
+ // $this->sys_error($message);
+ // exit;
+ // }
+ // $normalValue = $query->result_array();
+ // // echo $normalValue;
+ // // exit;
+ // $test[$i]['normalValue'] = $normalValue;
+ // // $test[$i]['test'] = $normalValue;
+
+ // for ($k = 0; $k < count($normalValue); $k++) {
+ // $ket = '';
+ // $nv = $normalValue[$k];
+ // // if ($e['value'] != null && trim($e['value']) != '') {
+
+ // if ($nv['isNormal'] == 'Y') {
+ // if ($nv['smLabType'] == '<' || $nv['smLabType'] == '<=') {
+ // $ket = 'menurun';
+ // $value_comparison = $e['minValues'];
+ // }
+ // if ($nv['smLabType'] == '>' || $nv['smLabType'] == '>=') {
+ // $ket = 'meningkat';
+ // $value_comparison = $e['maxValues'];
+ // }
+ // //echo "Y";
+ // if ($nv['methode'] == 'N' && $this->dynamic_comparison($e['value'], $nv['smLabType'], $value_comparison)) {
+ // if ($nv['smLabType'] == '<' || $nv['smLabType'] == '<=') {
+ // $ket = 'menurun';
+ // }
+ // if ($nv['smLabType'] == '>' || $nv['smLabType'] == '>=') {
+ // $ket = 'meningkat';
+ // }
+ // $kelainan = $e['testName'] . " " . $ket . "({$e['result']})";
+ // $saran = $nv['kelainanSaran'];
+ // $rstNormal = 'N';
+ // }
+ // } else {
+ // $value_comparison = $nv['value'];
+ // if ($nv['smLabType'] == '!=' || $nv['smLabType'] == '==') {
+ // if ($this->dynamic_comparison($e['value'], $nv['smLabType'], $value_comparison)) {
+ // //echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
+ // //langsung hasil
+ // // $kelainan = $nv;
+ // $kelainan = $e['testName'] . " " . "{$e['result']}";
+ // $saran = $nv['kelainanSaran'];
+ // $rstNormal = 'N';
+ // }
+ // } else {
+ // if (is_numeric($e['value']) && $this->dynamic_comparison($e['value'], $nv['smLabType'], $value_comparison)) {
+ // if ($nv['smLabType'] == '<' || $nv['smLabType'] == '<=') {
+ // $ket = 'menurun';
+ // }
+ // if ($nv['smLabType'] == '>' || $nv['smLabType'] == '>=') {
+ // $ket = 'meningkat';
+ // }
+ // // $kelainan = $nv;
+ // $kelainan = $e['testName'] . " " . $ket . "({$e['result']})";
+ // $saran = $nv['kelainanSaran'];
+ // $rstNormal = 'N';
+ // }
+ // }
+ // }
+ // // }
+ // }
+ }
+ $test[$i]['kelainan'] = $kelainan;
+ $test[$i]['resultIsNormal'] = $rstNormal;
+ $test[$i]['saran'] = $saran;
+ }
+ $newGab = [];
+
+ $group = [];
+ //penggabungan test
+ for ($i = 0; $i < count($test); $i++) {
+ $e = $test[$i];
+
+ if (!in_array($e['groupName'], $group)) {
+ $group[] = $e['groupName'];
+ if ($e['resultIsNormal'] == 'Y') {
+ $e['kelainan'] = '';
+ }
+ $newGab[] = $e;
+ } else {
+ for ($k = 0; $k < count($newGab); $k++) {
+ $nv = $newGab[$k];
+ if ($e['groupName'] == $nv['groupName']) {
+
+ if ($test[$i]['resultIsNormal'] == 'N') {
+ # code...
+ if (trim($newGab[$k]['kelainan']) == "") {
+ $newGab[$k]['kelainan'] = $test[$i]['kelainan'];
+ } else {
+ if ($newGab[$k]['kelainan'] != $test[$i]['kelainan']) {
+ $newGab[$k]['kelainan'] = $newGab[$k]['kelainan'] . ', ' . $test[$i]['kelainan'];
+ }
+ }
+ if (trim($newGab[$k]['saran']) == "" && trim($test[$i]['saran']) != '') {
+ $newGab[$k]['saran'] = $test[$i]['saran'];
+ $newGab[$k]['saranArr'][] = $test[$i]['saran'];
+ } else {
+ if (trim($test[$i]['saran']) != '') {
+ $newGab[$k]['saran'] = $newGab[$k]['saran'] . '@' . $test[$i]['saran'];
+ }
+ }
+ if ($newGab[$k]['testIDKelainan'] == '' && !isset($newGab[$k]['testIDKelainan'])) {
+ # code...
+ $newGab[$k]['testIDKelainan'] = $test[$i]['testID'];
+ } else {
+ $newGab[$k]['testIDKelainan'] = $newGab[$k]['testIDKelainan'] . ',' . $test[$i]['testID'];
+ }
+ }
+ $newGab[$k]['testID'] = $newGab[$k]['testID'] . ', ' . $test[$i]['testID'];
+ }
+ }
+ }
+ }
+ for ($i = 0; $i < count($newGab); $i++) {
+ $newGab[$i]['normalValue'] = '';
+ if (trim(str_replace(',', '', $newGab[$i]['kelainan'])) != '') {
+ $newGab[$i]['resultIsNormal'] = 'N';
+ } else {
+ $newGab[$i]['resultIsNormal'] = 'Y';
+ $newGab[$i]['kelainan'] = 'Dalam batas normal';
+ }
+
+ //saran unique
+ $expldSaran = explode('@', $newGab[$i]['saran']);
+ $expldSaranUnique = array_unique($expldSaran);
+ $newGab[$i]['saran'] = implode('@', $expldSaranUnique);
+ $expldTestIdKelainan = explode('@', $newGab[$i]['testIDKelainan']);
+ $expldTestIdKelainanUnique = array_unique($expldTestIdKelainan);
+ $newGab[$i]['testIDKelainan'] = implode(',', $expldTestIdKelainanUnique);
+ }
+ if ($isApi == 'Y') {
+ $this->sys_ok([
+ "test" => $test,
+ 'gab' => $newGab
+ ]);
+ } else {
+ return $newGab;
+ }
+ }
+ function dynamic_comparison($varleft, $op, $varright)
+ {
+
+ switch ($op) {
+ case "=":
+ return $varleft == $varright;
+ case "!=":
+ return $varleft != $varright;
+ case ">=":
+ return $varleft >= $varright;
+ case "<=":
+ return $varleft <= $varright;
+ case ">":
+ return $varleft > $varright;
+ case "<":
+ return $varleft < $varright;
+ default:
+ return true;
+ }
+ }
+
+
+
+ function generate_kelainan_lab($orderid)
+ {
+ $sql = "SELECT
+ T_OrderHeaderID,T_OrderHeaderLabNumber,
+ T_TestName, T_OrderDetailID, T_OrderDetailResult, T_OrderDetailNat_MethodeID,
+ T_OrderDetailNat_MethodeID, T_OrderDetailNat_MethodeName,
+ T_OrderDetailMinValue, T_OrderDetailMaxValue, T_OrderDetailMinValueInclusive,
+ T_OrderDetailMaxValueInclusive,
+ Mcu_SummaryLabID,
+ Mcu_SummaryLabValue,
+ Mcu_SummaryLabNat_MethodeID,
+ Mcu_SummaryLabWithMethode,
+ Mcu_SummaryLabType,
+ Mcu_SummaryLabIsNormalValue,
+ Mcu_SummaryLabIsRange,
+ Mcu_SummaryLabMinInclusive,
+ Mcu_SummaryLabMinValue,
+ Mcu_SummaryLabMaxInclusive,
+ Mcu_SummaryLabMaxValue,
+ Mcu_KelainanID, Mcu_KelainanName, Mcu_KelainanClasification,
+ Nat_TestID,
+ Nat_TestCode,
+ mcu_kelainangroup.*
+ from t_orderdetail
+ join t_orderheader on T_OrderHeaderID = {$orderid}
+ and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
+ and T_OrderDetailIsActive = 'Y'
+ JOIN m_patient
+ ON T_OrderHeaderM_PatientID = M_PatientID
+ join t_test
+ on T_OrderDetailT_TestID = T_TestID
+ join nat_test ON T_TestNat_TestID = Nat_TestID
+ join mcu_summarylab on T_TestNat_TestID = Mcu_SummaryLabNat_TestID AND Mcu_SummaryLabIsActive = 'Y'
+ AND (Mcu_SummaryLabGender = 'A' OR (Mcu_SummaryLabGender <> 'A' AND Mcu_SummaryLabGender = CASE
+ WHEN LOWER(M_PatientGender) = 'male' THEN 'M'
+ WHEN LOWER(M_PatientGender) = 'female' THEN 'F'
+ else ''
+ END))
+ join mcu_kelainan on Mcu_SummaryLabMcu_KelainanID = Mcu_KelainanID
+ join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID";
+ //echo $sql;
+ $qry = $this->db_onedev->query($sql);
+ if (!$qry) {
+ echo $this->db_onedev->last_query();
+ echo json_encode([
+ "status" => "ERR",
+ "message" => "Error get order | " . $this->db_onedev->error()["message"]
+ ]);
+ exit;
+ }
+
+ $rows = $qry->result_array();
+ $results = [];
+
+
+
+ foreach ($rows as $r) {
+ $result_value = $r['T_OrderDetailResult'];
+
+ $value_comparison = 0;
+ //echo $r['Mcu_SummaryLabIsNormalValue'];
+ $kelainan = [];
+ $notavailable = [];
+ if (trim($result_value) == 'NA') {
+ $notavailable = $r;
+ } elseif ($r['Mcu_SummaryLabIsNormalValue'] == 'Y') {
+ if ($r['Mcu_SummaryLabType'] == '<' || $r['Mcu_SummaryLabType'] == '<=') {
+ $value_comparison = $r['T_OrderDetailMinValue'];
+ }
+ if ($r['Mcu_SummaryLabType'] == '>' || $r['Mcu_SummaryLabType'] == '>=') {
+ $value_comparison = $r['T_OrderDetailMaxValue'];
+ }
+ //echo "Y";
+ if ($r['Mcu_SummaryLabWithMethode'] == 'N' && $this->dynamic_comparison($result_value, $r['Mcu_SummaryLabType'], $value_comparison)) {
+ //echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
+ $kelainan = $r;
+ $results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName'], 'orderdetailID' => $r['T_OrderDetailID'], 'orderheaderID' => $r['T_OrderHeaderID'], 'nat_testID' => $r['Nat_TestID'], 'mcu_summarylabID' => $r['Mcu_SummaryLabID']);
+ }
+ } else if ($r['Mcu_SummaryLabIsRange'] == 'Y') {
+ // Mcu_SummaryLabIsNormalValue,
+ // Mcu_SummaryLabIsRange,
+ // Mcu_SummaryLabMinInclusive,
+ // Mcu_SummaryLabMinValue,
+ // Mcu_SummaryLabMaxInclusive,
+ // Mcu_SummaryLabMaxValue,
+ $isWithinMin = $r['Mcu_SummaryLabMinInclusive'] === 'Y' ? floatval($result_value) >= floatval($r['Mcu_SummaryLabMinValue']) : floatval($result_value) > floatval($r['Mcu_SummaryLabMinValue']);
+ $isWithinMax = $r['Mcu_SummaryLabMaxInclusive'] === 'Y' ? floatval($result_value) <= floatval($r['Mcu_SummaryLabMaxValue']) : floatval($result_value) < floatval($r['Mcu_SummaryLabMaxValue']);
+
+ if ($isWithinMax && $isWithinMin) {
+ $kelainan = $r;
+ $results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName'], 'orderdetailID' => $r['T_OrderDetailID'], 'orderheaderID' => $r['T_OrderHeaderID'], 'nat_testID' => $r['Nat_TestID'], 'mcu_summarylabID' => $r['Mcu_SummaryLabID']);
+ }
+ } else {
+ $value_comparison = $r['Mcu_SummaryLabValue'];
+ if ($r['Mcu_SummaryLabType'] == '!=' || $r['Mcu_SummaryLabType'] == '==') {
+ if ($this->dynamic_comparison($result_value, $r['Mcu_SummaryLabType'], $value_comparison)) {
+ //echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
+ $kelainan = $r;
+ $results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName'], 'orderdetailID' => $r['T_OrderDetailID'], 'orderheaderID' => $r['T_OrderHeaderID'], 'nat_testID' => $r['Nat_TestID'], 'mcu_summarylabID' => $r['Mcu_SummaryLabID']);
+ }
+ } else {
+ if (is_numeric($result_value) && $this->dynamic_comparison($result_value, $r['Mcu_SummaryLabType'], $value_comparison)) {
+ //echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
+ $kelainan = $r;
+ $results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName'], 'orderdetailID' => $r['T_OrderDetailID'], 'orderheaderID' => $r['T_OrderHeaderID'], 'nat_testID' => $r['Nat_TestID'], 'mcu_summarylabID' => $r['Mcu_SummaryLabID']);
+ }
+ }
+ }
+
+ if (count($results) > 0) {
+ $sql = "UPDATE t_kelainan_lab
+ SET T_KelainanLabIsActive = 'N'
+ WHERE
+ T_KelainanLabT_OrderHeaderID = {$orderid}";
+ $this->db_onedev->query($sql);
+
+ foreach ($results as $v_result) {
+ $sql_kel_lab = "SELECT *
+ FROM t_kelainan_lab
+ WHERE T_KelainanLabT_OrderDetailID = ?
+ GROUP BY T_KelainanLabT_OrderDetailID";
+ $qry_kel_lab = $this->db_onedev->query($sql_kel_lab, array($v_result['orderdetailID']));
+ if ($qry_kel_lab) {
+ $rows_kel = $qry_kel_lab->result_array();
+ } else {
+ $this->sys_error_db("select kelainan lab", $this->db_onedev);
+ exit;
+ }
+
+ if (count($rows_kel) > 0) {
+
+ // print_r($v_result['orderdetailID']);
+ // exit;
+
+ $sql_update_kel = "UPDATE t_kelainan_lab
+ SET T_KelainanLabT_OrderDetailID = {$v_result['orderdetailID']},
+ T_KelainanLabT_OrderHeaderID = {$v_result['orderheaderID']},
+ T_KelainanLabNat_TestID = {$v_result['nat_testID']},
+ T_KelainanLabMcu_SummaryLabID = {$v_result['mcu_summarylabID']},
+ T_KelainanLabCreatedUserID = 1,
+ T_KelainanLabIsActive = 'Y',
+ T_KelainanLabCreated = NOW()
+ WHERE T_KelainanLabID = {$rows_kel[0]['T_KelainanLabID']}";
+ $qry_update_kel = $this->db_onedev->query($sql_update_kel);
+ if (!$qry_update_kel) {
+ echo $this->db_onedev->last_query();
+ //$this->db_onedev->trans_rollback();
+ $this->sys_error_db('error', 'Error update lab: ' . $this->db_onedev);
+ exit;
+ }
+ } else {
+ // print_r('insert');
+ // exit;
+ $sql_insert_lab = "INSERT INTO t_kelainan_lab(
+ T_KelainanLabT_OrderDetailID,
+ T_KelainanLabT_OrderHeaderID,
+ T_KelainanLabNat_TestID,
+ T_KelainanLabMcu_SummaryLabID,
+ T_KelainanLabCreatedUserID,
+ T_KelainanLabCreated)
+ VALUES(
+ '{$v_result['orderdetailID']}',
+ '{$v_result['orderheaderID']}',
+ '{$v_result['nat_testID']}',
+ '{$v_result['mcu_summarylabID']}',
+ 1,
+ NOW())";
+ $qry_insert_lab = $this->db_onedev->query($sql_insert_lab);
+
+ if (!$qry_insert_lab) {
+ //$this->db_onedev->trans_rollback();
+ echo $this->db_onedev->last_query();
+ $this->sys_error_db('error', 'Error insert kelainan lab: ' . $this->db_onedev);
+ exit;
+ }
+ }
+ }
+ }
+ }
+ }
+ function savedoctor()
+ {
+ if (!$this->isLogin) {
+ $this->sys_error("Invalid Token");
+ exit;
+ }
+ $prm = $this->sys_input;
+ $id = $prm['id'];
+ $doctorid = $prm['doctorid'];
+ $userid = $this->sys_user["M_UserID"];
+ //insert mcu_resume
+ $resumeID = 0;
+ $jsonBefore = "";
+ $jsonAfter = "";
+ $status = 'NEW DOCTOR';
+ $sql = "SELECT *
+ FROM mcu_resume
+ WHERE Mcu_ResumeT_OrderHeaderID = ?
+ AND Mcu_ResumeIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [$id]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+
+ $dataCek = $query->result_array();
+ $jsonBefore = $dataCek;
+ if (count($dataCek) == 0) {
+ $sql = "INSERT INTO mcu_resume
+ (Mcu_ResumeT_OrderHeaderID,
+ Mcu_ResumeStatus,
+ Mcu_ResumeM_DoctorID,
+ Mcu_ResumeCreated,
+ Mcu_ResumeUserID
+ )
+ VALUES(?,'NEW',?,NOW(),?)";
+ $query = $this->db_onedev->query($sql, [
+ $id,
+ $doctorid,
+ $userid,
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $resumeID = $this->db_onedev->insert_id();
+ } else {
+ $status = 'UPDATE DOCTOR';
+ $resumeID = $dataCek[0]['Mcu_ResumeID'];
+ $sql = "UPDATE mcu_resume
+ SET Mcu_ResumeM_DoctorID = ?,
+ Mcu_ResumeUserID = ?
+ WHERE Mcu_ResumeID = ?";
+ $query = $this->db_onedev->query($sql, [
+ $doctorid,
+ $userid,
+ $resumeID,
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ }
+ $sql = "SELECT *
+ FROM mcu_resume
+ WHERE Mcu_ResumeT_OrderHeaderID = ?
+ AND Mcu_ResumeIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [$id]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+
+ $dataCek = $query->result_array();
+ $jsonAfter = $dataCek;
+ $sql = "INSERT INTO cpone_log.log_mcu_resume
+ (log_Mcu_ResumeMcu_ResumeID,
+ log_Mcu_ResumeJsonBefore,
+ log_Mcu_ResumeJsonAfter,
+ log_Mcu_ResumeJsonPrm,
+ log_Mcu_ResumeType,
+ log_Mcu_ResumeUserID,
+ log_Mcu_ResumeCreated)
+ VALUES(?,?,?,?,?,?,NOW())";
+ $query = $this->db_onedev->query($sql, [
+ $resumeID,
+ json_encode($jsonBefore),
+ json_encode($jsonAfter),
+ json_encode($prm),
+ $status,
+ $userid
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $this->sync_resume_status_dashboard($resumeID);
+ $this->sys_ok('OK');
+ exit;
+ }
+ function cobaGenerate($orderID, $userID)
+ {
+ $this->load->library('Etlfisik');
+ $rtn = $this->etlfisik->generate_kelainan_by_order($orderID, $userID);
+ echo json_encode($rtn);
+ }
+ function generateKesimpulanSaran($id, $debug = 'N')
+ {
+ //get kelainan nonlab
+ $sql = "SELECT
+ T_KelainanNonLabID AS kelainanNonlabID,
+ T_KelainanNonLabT_OrderHeaderID as orderID,
+ Mcu_KelainanID as kelainanID,
+ T_KelainanNonLabMcu_SummaryNonlabID As summaryID,
+ Mcu_KelainanName as kelainanName,
+ fn_get_translate_word_separator_comma(Mcu_KelainanName,2) as kelainanNameEng,
+ 'NONLAB' as type
+ FROM
+ t_kelainan_nonlab
+ JOIN mcu_summarynonlab
+ ON T_KelainanNonLabMcu_SummaryNonlabID = Mcu_SummaryNonlabID
+ AND T_KelainanNonLabT_OrderHeaderID = ?
+ AND T_KelainanNonLabIsActive = 'Y'
+ JOIN mcu_kelainan
+ ON Mcu_SummaryNonlabMcu_KelainanID = Mcu_KelainanID
+ AND Mcu_KelainanIsActive = 'Y'
+ GROUP BY Mcu_KelainanID
+ ";
+ $query = $this->db_onedev->query($sql, [$id]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error_db("Error get kelainan nonlab");
+ exit;
+ }
+ $kelainanNonlab = $query->result_array();
+
+ //get kelainan lab
+ $sql = "SELECT
+ T_KelainanLabID as kelainanLabID,
+ T_KelainanLabT_OrderHeaderID as orderID,
+ Mcu_KelainanID as kelainanID,
+ Mcu_SummaryLabID as summaryID,
+ Mcu_KelainanName as kelainanName,
+ fn_get_translate_word_separator_comma(Mcu_KelainanName,2) as kelainanNameEng,
+ 'LAB' as type
+ FROM t_kelainan_lab
+ JOIN mcu_summarylab
+ ON T_KelainanLabMcu_SummaryLabID = Mcu_SummaryLabID
+ AND Mcu_SummaryLabIsActive = 'Y'
+ AND T_KelainanLabT_OrderHeaderID = ?
+ JOIN mcu_kelainan
+ ON Mcu_summaryLabMcu_KelainanID = Mcu_KelainanID
+ AND Mcu_KelainanIsActive = 'Y'
+ AND T_KelainanLabIsActive = 'Y'
+ GROUP BY Mcu_KelainanID
+ ";
+ $query = $this->db_onedev->query($sql, [$id]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error_db("Error get kelainan lab");
+ exit;
+ }
+ $kelainanLab = $query->result_array();
+
+ //get kelainan fisik
+ $sql = "SELECT
+ T_KelainanFiskID as kelainanFisikID,
+ T_KelainanFiskT_OrderHeaderID orderID,
+ Mcu_FisikSummaryID summaryID,
+ Mcu_KelainanID as kelainanID ,
+ Mcu_KelainanName as kelainanName,
+ fn_get_translate_word_separator_comma(Mcu_KelainanName,2) as kelainanNameEng,
+ 'FISIK' as type
+ FROM t_kelainan_fisik
+ JOIN mcu_fisiksummary
+ ON T_KelainanFiskMcu_FisikSummaryID = Mcu_FisikSummaryID
+ AND Mcu_FisikSummaryIsActive = 'Y'
+ AND T_KelainanFiskT_OrderHeaderID = ?
+ AND T_KelainanFiskIsActive = 'Y'
+ JOIN mcu_kelainan
+ ON Mcu_FisikSummaryMcu_KelainanID = Mcu_KelainanID
+ AND Mcu_KelainanIsActive = 'Y'
+ GROUP BY Mcu_KelainanID
+ ";
+ $query = $this->db_onedev->query($sql, [$id]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error_db("Error get kelainan fisik");
+ exit;
+ }
+ $kelainanFisik = $query->result_array();
+
+ $arrMcuKelainanID = array();
+ $arrMcuKelainanIDEng = array();
+ $kesimpulan = "";
+ $counterKesimpulan = 1;
+ $conclusion = "";
+ $counterConclusion = 1;
+ for ($i = 0; $i < count($kelainanNonlab); $i++) {
+ $kesimpulan .= "- " . $kelainanNonlab[$i]['kelainanName'] . "\n";
+ $counterKesimpulan += 1;
+ array_push($arrMcuKelainanID, $kelainanNonlab[$i]['kelainanID']);
+
+ $conclusion .= "- " . $kelainanNonlab[$i]['kelainanNameEng'] . "\n";
+ $counterConclusion += 1;
+ array_push($arrMcuKelainanIDEng, $kelainanNonlab[$i]['kelainanNameEng']);
+ }
+ for ($i = 0; $i < count($kelainanLab); $i++) {
+ $kesimpulan .= "- " . $kelainanLab[$i]['kelainanName'] . "\n";
+ $counterKesimpulan += 1;
+ array_push($arrMcuKelainanID, $kelainanLab[$i]['kelainanID']);
+
+ $conclusion .= "- " . $kelainanLab[$i]['kelainanNameEng'] . "\n";
+ $counterConclusion += 1;
+ array_push($arrMcuKelainanIDEng, $kelainanLab[$i]['kelainanNameEng']);
+ }
+ for ($i = 0; $i < count($kelainanFisik); $i++) {
+ $kesimpulan .= "- " . $kelainanFisik[$i]['kelainanName'] . "\n";
+ $counterKesimpulan += 1;
+ array_push($arrMcuKelainanID, $kelainanFisik[$i]['kelainanID']);
+
+ $conclusion .= "- " . $kelainanFisik[$i]['kelainanNameEng'] . "\n";
+ $counterConclusion += 1;
+ array_push($arrMcuKelainanIDEng, $kelainanFisik[$i]['kelainanNameEng']);
+ }
+ //get kelainan saran nonlab
+
+ if(count($arrMcuKelainanID) > 0){
+
+ $sql = "SELECT
+ Nat_AdvicekelainanID adviceID,
+ Nat_AdvicekelainanMcu_KelainanID mcuKelainanID,
+ Nat_AdviceIna saranIna,
+ IF(Nat_AdviceEng = '',Nat_AdviceIna, Nat_AdviceEng) saranEng,
+ fn_get_translate_word_separator_comma(Nat_AdviceIna,2) as translate_eng
+ FROM nat_advice_kelainan
+ JOIN nat_advice
+ ON Nat_AdvicekelainanNat_AdviceID = Nat_AdviceID
+ AND Nat_AdvicekelainanMcu_KelainanID IN ?
+ AND Nat_AdviceIsActive = 'Y'
+ AND Nat_AdvicekelainanIsActive = 'Y'
+ group by Nat_AdviceIna
+ ";
+
+ $query = $this->db_onedev->query($sql, [$arrMcuKelainanID]);
+ //echo $this->db_onedev->last_query();
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error_db("Error cek validasi 3 " . $this->db_onedev->last_query());
+ exit;
+ }
+ $arrSaran = $query->result_array();
+ if (count($arrSaran) > 0) {
+ foreach ($arrSaran as $key => $value) {
+ $adv = $value['saranEng'];
+ if (trim($adv) == '' || $adv == $value['saranIna']) {
+ $adv = $value['translate_eng'];
+ }
+ $arrSaran[$key]['saranEng'] = $adv;
+ }
+ }
+
+ }
+
+ $saran = "";
+ $counterSaran = 1;
+ $advice = "";
+ $counterAdvice = 1;
+ for ($i = 0; $i < count($arrSaran); $i++) {
+ $saran .= "- " . $arrSaran[$i]['saranIna'] . "\n";
+ $counterSaran += 1;
+ $advice .= "- " . $arrSaran[$i]['saranEng'] . "\n";
+ $counterAdvice += 1;
+ }
+ if ($debug == 'Y') {
+ $this->sys_ok(array(
+ "kesimpulan" => $kesimpulan,
+ "saran" => $saran,
+ "advice" => $advice,
+ "conclusion" => $conclusion,
+ ));
+ } else {
+ return array(
+ "kesimpulan" => $kesimpulan,
+ "saran" => $saran,
+ "advice" => $advice,
+ "conclusion" => $conclusion,
+ );
+ }
+ }
+ function generateFitnessCategory()
+ {
+ if (!$this->isLogin) {
+ $this->sys_error("Invalid Token");
+ exit;
+ }
+ $prm = $this->sys_input;
+ $id = $prm['orderid'];
+ $kesimpulanPrm = $prm['kesimpulan'];
+ $saranPrm = $prm['saran'];
+ $rekomendasiPrm = $prm['rekomendasi'];
+ $conclusionPrm = $prm['conclusion'];
+ $advicePrm = $prm['advice'];
+ $recomendationPrm = $prm['recomendation'];
+
+ $userid = $this->sys_user["M_UserID"];
+
+ $sql = "SELECT IFNULL(GROUP_CONCAT(DISTINCT So_ResultEntryValidation1), 'Y') as val
+ FROM t_orderdetail
+ JOIN so_resultentry
+ ON T_OrderDetailT_OrderHeaderID = So_ResultEntryT_OrderHeaderID
+ AND T_OrderDetailID = So_ResultEntryT_OrderDetailID
+ AND So_ResultEntryIsActive = 'Y' AND T_OrderDetailIsActive = 'Y'
+ AND So_ResultEntryT_OrderHeaderID = ?
+ JOIN group_resultdetail
+ ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID
+ AND T_OrderDetailT_TestID NOT IN (2571,2573,2573,3450,2572)
+ AND Group_ResultDetailIsActive ='Y'
+ JOIN group_result
+ ON Group_ResultID = Group_ResultDetailGroup_ResultID AND Group_ResultID <> 35
+ AND Group_ResultResumeMcu IN ('NONLAB', 'FISIK')
+ AND Group_ResultIsActive ='Y'";
+ $query = $this->db_onedev->query($sql, [$id]);
+ // echo $this->db_onedev->last_query();
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error_db("Error cek validasi 2" . $this->db_onedev->last_query());
+ exit;
+ }
+ $cekValidation = $query->row_array();
+ $expdCek = explode(',', $cekValidation['val']);
+ if (in_array('N', $expdCek) && $cekValidation['val'] != null && trim($cekValidation['val']) != '' && count($expdCek) > 0) {
+ $this->sys_error("Hasil Nonlab atau fisik belum di validasi .....");
+ exit;
+ }
+ //insert mcu_resume
+ $resumeID = 0;
+ $jsonBefore = "";
+ $jsonAfter = "";
+ $status = 'FITNESS NEW';
+ $sql = "SELECT *
+ FROM mcu_resume
+ WHERE Mcu_ResumeT_OrderHeaderID = ?
+ AND Mcu_ResumeIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [$id]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $dataCek = $query->result_array();
+ $jsonBefore = $dataCek;
+
+
+
+ $this->load->library('Etlfisik');
+ $rtn = $this->etlfisik->generate_kelainan_by_order($id, $userid);
+ $rtnStatus = $rtn['status'];
+ $rtnGenerateResult = $rtn['data'];
+ $fitnessID = $rtn['status']['id'] ?? '0';
+
+ $rekomendasi = $rtn['status']['name'];
+ $recomendation = $rtn['status']['name_eng'];
+ if (trim($rekomendasiPrm) == '') {
+ $rekomendasi = $rtn['status']['name'];
+ } else {
+ $rekomendasi = $rekomendasiPrm;
+ }
+ if (trim($recomendationPrm) == '') {
+ $recomendation = $rtn['status']['name_eng'];
+ } else {
+ $recomendation = $recomendationPrm;
+ }
+ $kesimpulan = '';
+ $saran = '';
+ $advice = '';
+ $conclusion = '';
+
+ if (count($dataCek) == 0) {
+ $generateKesimpulanSaran = $this->generateKesimpulanSaran($id);
+ $kesimpulan = $generateKesimpulanSaran['kesimpulan'];
+ $saran = $generateKesimpulanSaran['saran'];
+ $advice = $generateKesimpulanSaran['advice'];
+ $conclusion = $generateKesimpulanSaran['conclusion'];
+ $sql = "INSERT INTO mcu_resume
+ (Mcu_ResumeT_OrderHeaderID,
+ Mcu_ResumeStatus,
+ Mcu_ResumeMcu_FitnessCategoryID,
+ Mcu_ResumeCreated,
+ Mcu_ResumeUserID,
+ Mcu_ResumeKesimpulan,
+ Mcu_ResumeRekomendasi,
+ Mcu_ResumeSaran
+ )
+ VALUES(?,'NEW',?,NOW(),?,?,?,?)";
+ $query = $this->db_onedev->query($sql, [
+ $id,
+ $fitnessID,
+ $userid,
+ $kesimpulan,
+ $rekomendasi,
+ $saran
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $resumeID = $this->db_onedev->insert_id();
+ $sql = "INSERT INTO mcu_resume_eng
+ (Mcu_ResumeEngMcu_ResumeID,
+ Mcu_ResumeEngConlusion,
+ Mcu_ResumeEngRecomendation,
+ Mcu_ResumeEngAdvice,
+ Mcu_ResumeEngCreated,
+ Mcu_ResumeEngCreatedUserID
+ )
+ VALUES(?,?,?,?,NOW(),?)";
+ $query = $this->db_onedev->query($sql, [
+ $resumeID,
+ $conclusion,
+ $recomendation,
+ $advice,
+ $userid
+ ]);
+ } else {
+ if (trim($kesimpulanPrm) == "" || trim($saranPrm == '')) {
+ $generateKesimpulanSaran = $this->generateKesimpulanSaran($id);
+ if (trim($kesimpulanPrm) == '') {
+ $kesimpulan = $generateKesimpulanSaran['kesimpulan'];
+ $conclusion = $generateKesimpulanSaran['conclusion'];
+ } else {
+ $kesimpulan = $kesimpulanPrm;
+ }
+ if (trim($saranPrm) == '') {
+ $saran = $generateKesimpulanSaran['saran'];
+ $advice = $generateKesimpulanSaran['advice'];
+ } else {
+ $saran = $saranPrm;
+ }
+ } else {
+ $kesimpulan = $kesimpulanPrm;
+ $saran = $saranPrm;
+ $advice = $advicePrm;
+ $conclusion = $conclusionPrm;
+ $recomendation = $recomendationPrm;
+ }
+ $status = 'FITNESS UPDATE';
+ $resumeID = $dataCek[0]['Mcu_ResumeID'];
+ $sql = "UPDATE mcu_resume
+ SET Mcu_ResumeMcu_FitnessCategoryID = ?,
+ Mcu_ResumeUserID = ?,
+ Mcu_ResumeKesimpulan = ?,
+ Mcu_ResumeRekomendasi = ?,
+ Mcu_ResumeSaran = ?
+ WHERE Mcu_ResumeID = ?";
+ $query = $this->db_onedev->query($sql, [
+ $fitnessID,
+ $userid,
+ $kesimpulan,
+ $rekomendasi,
+ $saran,
+ $resumeID,
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+
+ $sql = "SELECT * FROM mcu_resume_eng
+ WHERE Mcu_ResumeEngMcu_ResumeID = ? AND Mcu_ResumeEngIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [$resumeID]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $dataCekEng = $query->result_array();
+ if (count($dataCekEng) == 0) {
+ $sql = "INSERT INTO mcu_resume_eng
+ (Mcu_ResumeEngMcu_ResumeID,
+ Mcu_ResumeEngConlusion,
+ Mcu_ResumeEngRecomendation,
+ Mcu_ResumeEngAdvice,
+ Mcu_ResumeEngCreated,
+ Mcu_ResumeEngCreatedUserID
+ )
+ VALUES(?,?,?,?,NOW(),?)";
+ $query = $this->db_onedev->query($sql, [
+ $resumeID,
+ $conclusion,
+ $recomendation,
+ $advice,
+ $userid
+ ]);
+ } else {
+ $sql = "UPDATE mcu_resume_eng
+ SET Mcu_ResumeEngConlusion = ?,
+ Mcu_ResumeEngRecomendation = ?,
+ Mcu_ResumeEngAdvice = ?
+ WHERE Mcu_ResumeEngMcu_ResumeID = ? AND Mcu_ResumeEngIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [
+ $conclusion,
+ $recomendation,
+ $advice,
+ $resumeID,
+ ]);
+ }
+ }
+ //insert log
+ $sql = "SELECT *
+ FROM mcu_resume
+ LEFT JOIN mcu_resume_eng ON Mcu_ResumeEngMcu_ResumeID = Mcu_ResumeID AND Mcu_ResumeEngIsActive = 'Y'
+ WHERE Mcu_ResumeT_OrderHeaderID = ?
+ AND Mcu_ResumeIsActive = 'Y'";
+ $query = $this->db_onedev->query($sql, [$id]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+
+ $dataCek = $query->result_array();
+ $jsonAfter = $dataCek;
+ $sql = "INSERT INTO cpone_log.log_mcu_resume
+ (log_Mcu_ResumeMcu_ResumeID,
+ log_Mcu_ResumeJsonBefore,
+ log_Mcu_ResumeJsonAfter,
+ log_Mcu_ResumeJsonPrm,
+ log_Mcu_ResumeType,
+ log_Mcu_ResumeUserID,
+ log_Mcu_ResumeCreated)
+ VALUES(?,?,?,?,?,?,NOW())";
+ $query = $this->db_onedev->query($sql, [
+ $resumeID,
+ json_encode($jsonBefore),
+ json_encode($jsonAfter),
+ json_encode($prm),
+ $status,
+ $userid
+ ]);
+ if (!$query) {
+ $message = $this->db_onedev->error();
+ $message['qry'] = $this->db_onedev->last_query();
+ $this->sys_error($message);
+ exit;
+ }
+ $this->sync_resume_status_dashboard($resumeID);
+
+ $query_sync_kelainan = $this->db_onedev->query("CALL cpone.sp_sync_kelainan_details_by_orderheader(?)", [$id]);
+ if (!$query_sync_kelainan) {
+ $this->insert_log_error($this->db_onedev->last_query(), ['SP_SYNC_KELAINAN_DETAILS', 'generateFitnessCategory'], [
+ 'orderid' => $id,
+ 'error' => $this->db_onedev->error()
+ ]);
+ }
+
+ for ($i = 0; $i < count($rtn['data']); $i++) {
+ $rtn['data'][$i]['Nat_TestName'] = str_replace("|", ", ", $rtn['data'][$i]['Nat_TestName']);
+ }
+ $this->sys_ok($rtn);
+ exit;
+ }
+}
diff --git a/scripts/sql/2026-06-25_update_sp_sync_kelainan_details_by_orderheader.sql b/scripts/sql/2026-06-25_update_sp_sync_kelainan_details_by_orderheader.sql
new file mode 100644
index 0000000..a170f74
--- /dev/null
+++ b/scripts/sql/2026-06-25_update_sp_sync_kelainan_details_by_orderheader.sql
@@ -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 ;
diff --git a/scripts/sql/2026-06-25_update_sp_sync_kelainan_details_by_orderheader_adminer.sql b/scripts/sql/2026-06-25_update_sp_sync_kelainan_details_by_orderheader_adminer.sql
new file mode 100644
index 0000000..f20b5f0
--- /dev/null
+++ b/scripts/sql/2026-06-25_update_sp_sync_kelainan_details_by_orderheader_adminer.sql
@@ -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 ;