url_renderer = "http://devkedungdoro.aplikasi.web.id:3000/chart"; $this->url_renderer = "http://192.168.250.42:3000/chart"; } function render($type, $id) { switch ($type) { case "mcu001": $this->mcu001($id); break; case "mcu002": $this->mcu002($id); break; } } // --> MCU001 function mcu001($id) { // 1. prepare the data using sql // SQL belum tau dari tabel dan field apa saja // 1. prepare the data using sql $sql = "SELECT count(Mcu_OrderT_OrderHeaderID) as peserta,Mgm_McuTotalParticipant as total FROM one_etl.mgm_mcu join one_etl.mcu_order on Mcu_OrderMgm_McuID = Mgm_McuID AND Mgm_McuID = ?"; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { // $this->chart_error("No data found"); } $total = $rows[0]["total"]; $peserta = $rows[0]["peserta"]; $belum_mcu = $total - $peserta; // 2. generate parameter for the chart $param = array( 'tooltip' => array( 'trigger' => 'item', 'formatter' => '{b}: {c} ({d}%)' ), 'legend' => array( 'top' => 'bottom', // 'right' => 'right', 'orient' => 'horizontal', 'itemGap' => 20 ), 'series' => array( array( 'name' => 'Access From', 'type' => 'pie', 'radius' => '50%', 'avoidLabelOverlap' => true, 'labelLine' => array( 'show' => true ), 'label' => array( 'show' => true, 'position' => 'outside', 'formatter' => '{d}% | {c} peserta {b}', ), 'itemStyle' => array( 'normal' => array( 'shadowBlur' => 20, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.5)' ) ), 'emphasis' => array( 'itemStyle' => array( 'shadowBlur' => 30, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.7)' ) ), 'data' => array( array('value' => $peserta, 'name' => 'Hadir'), array('value' => $belum_mcu, 'name' => 'Tidak Hadir') ) ) ) ); // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // MCU002 Kepesertaan berdasarkan Umur function mcu002($id) { $sql_data = "SELECT CASE WHEN CAST(LEFT(Mgm_HeaderT_OrderHeaderM_PatientAge, 2) AS UNSIGNED) < 30 THEN '< 30 th' WHEN CAST(LEFT(Mgm_HeaderT_OrderHeaderM_PatientAge, 2) AS UNSIGNED) >= 30 AND CAST(LEFT(Mgm_HeaderT_OrderHeaderM_PatientAge, 2) AS UNSIGNED) < 40 THEN '30 - < 40 th' WHEN CAST(LEFT(Mgm_HeaderT_OrderHeaderM_PatientAge, 2) AS UNSIGNED) >= 40 AND CAST(LEFT(Mgm_HeaderT_OrderHeaderM_PatientAge, 2) AS UNSIGNED) < 50 THEN '40 - < 50 th' WHEN CAST(LEFT(Mgm_HeaderT_OrderHeaderM_PatientAge, 2) AS UNSIGNED) >= 50 THEN '> 50 th' ELSE '' END AS umur, COUNT(Distinct Mcu_OrderT_OrderHeaderID) AS total FROM one_etl.mcu_order JOIN one_etl.mgm_mcu ON Mgm_McuID = Mcu_OrderMgm_McuID AND Mgm_McuIsActive = 'Y' AND Mgm_McuID = ? LEFT JOIN one_etl.mgm_header ON Mgm_McuID = Mgm_HeaderMgm_McuID AND Mcu_OrderT_OrderHeaderID = Mgm_HeaderT_OrderHeaderID AND Mgm_HeaderIsActive = 'Y' GROUP BY CASE WHEN CAST(LEFT(Mgm_HeaderT_OrderHeaderM_PatientAge, 2) AS UNSIGNED) < 30 THEN 1 WHEN CAST(LEFT(Mgm_HeaderT_OrderHeaderM_PatientAge, 2) AS UNSIGNED) >= 30 AND CAST(LEFT(Mgm_HeaderT_OrderHeaderM_PatientAge, 2) AS UNSIGNED) < 40 THEN 2 WHEN CAST(LEFT(Mgm_HeaderT_OrderHeaderM_PatientAge, 2) AS UNSIGNED) >= 40 AND CAST(LEFT(Mgm_HeaderT_OrderHeaderM_PatientAge, 2) AS UNSIGNED) < 50 THEN 3 WHEN CAST(LEFT(Mgm_HeaderT_OrderHeaderM_PatientAge, 2) AS UNSIGNED) >= 50 THEN 4 ELSE '' END"; $qry_data = $this->db->query($sql_data, [$id]); $this->check_error($qry_data, 'get xData mcu'); $rows_data = $qry_data->result_array(); // 2. generate parameter for the chart $param = array( 'title' => array( 'text' => 'Sebaran Peserta Menurut Kelompok Umur', 'left' => 'center' ), 'tooltip' => array( 'trigger' => 'item' ), "dataset" => array( "dimensions" => array('umur', 'total'), "source" => array() // Nanti diisi dengan data $result ), 'legend' => array( 'top' => 'bottom', // 'right' => 'right', 'orient' => 'horizontal', 'itemGap' => 20 ), 'series' => array( array( 'width' => "100%", 'labelLine' => array( 'show' => true ), 'label' => array( 'position' => 'outside', // Gunakan format string untuk formatter di ECharts 'formatter' => '{d}% | {@[1]} peserta' ), 'name' => 'Access From', 'type' => 'pie', 'radius' => array('20%', '50%'), 'itemStyle' => array( 'borderRadius' => 10, 'borderColor' => '#fff', 'borderWidth' => 2 ), 'emphasis' => array( 'itemStyle' => array( 'shadowBlur' => 10, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.5)' ) ) ) ) ); $param['dataset']['source'] = $rows_data; // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // sindhu // mcu keluhan klinik (Non Lab) mcu003 function mcu003($id) { $color = [ 200, 150, 125, 100, 90, 80, 75, 70, 60, 50, ]; // Calculate the maximum amount $maxAmount = 0.0; // ECharts option in PHP $option = array( 'title' => array( // 'text' => '% Keluhan Saat ini', 'left' => 'center' ), 'dataset' => array( array( "dimensions" => ['score', 'amount', 'product', 'percentage'], 'source' => array(), ), array( "transform" => array( "type" => 'sort', "config" => array( "dimension" => 'percentage', "order" => 'asc' ) ) ) ), 'grid' => array( 'containLabel' => true, 'width' => 'auto', 'height' => 'auto', ), 'xAxis' => array( 'name' => '', 'position' => 'top', 'max' => 100, 'axisLabel' => array( 'formatter' => '{value}%' // Menambahkan tanda persen di setiap label sumbu Y ) ), 'yAxis' => array( 'type' => 'category' ), 'visualMap' => array( 'orient' => 'horizontal', 'left' => 'center', 'min' => 0, 'max' => 100, 'show' => false, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'label' => array( 'position' => 'right', 'show' => true, "formatter" => "{@[3]}% {@[4]}" ), 'type' => 'bar', 'encode' => array( 'x' => 'percentage', 'y' => 'product' ), "datasetIndex" => 1 ) ) ); // total order yang non lab saja $sql_total_all = "SELECT COUNT(*) as xTotalAll, Mcu_OrderMgm_McuID FROM one_etl.mcu_order WHERE Mcu_OrderMgm_McuID =? "; $qry_total_all = $this->db->query($sql_total_all, [$id]); $this->check_error($qry_total_all, "get xTotalAll mcu"); $rows_total = $qry_total_all->result_array(); if (count($rows_total) == 0) { // $this->chart_error("No data found"); } $maxAmount += $rows_total[0]['xTotalAll']; // Data $sql_data = "SELECT COUNT(*) as xTotalPerItem, Mcu_RiwayatName as Mcu_KelainanGroupName, Mgm_HeaderMgm_McuID ,concat(COUNT(*) , ' Peserta' ) as pasien FROM one_etl.mgm_header JOIN one_etl.mgm_riwayat ON Mgm_HeaderID = Mgm_RiwayatMgm_HeaderID AND Mgm_HeaderIsActive = 'Y' AND Mgm_RiwayatIsActive = 'Y' AND Mgm_HeaderType = 'R' AND Mgm_HeaderMgm_McuID = ? JOIN one_etl.mcu_riwayatgroup ON Mgm_RiwayatMcu_RiwayatGroupID = Mcu_RiwayatGroupID AND Mcu_RiwayatGroupIsActive = 'Y' AND Mcu_RiwayatGroupID = 2 JOIN one_etl.mcu_riwayat ON Mgm_RiwayatMcu_RiwayatID = Mcu_RiwayatID and Mcu_RiwayatIsActive = 'Y' GROUP BY Mcu_RiwayatID ORDER BY xTotalPerItem DESC LIMIT 0, 10"; $qry_total_data = $this->db->query($sql_data, [$id]); $this->check_error($qry_total_data, "get xTotalPerItem mcu"); $rows_total_data = $qry_total_data->result_array(); if (count($rows_total_data) == 0) { // $this->chart_error("No data found"); } for ($i = 0; $i < count($rows_total_data); $i++) { if ($i < count($color)) { $percentage = (($rows_total_data[$i]['xTotalPerItem'] / $maxAmount) * 100); $pasien = $rows_total_data[$i]['pasien']; $formattedPercentage = number_format($percentage, 2); $option['dataset'][0]['source'][] = [ $color[$i], $rows_total_data[$i]['xTotalPerItem'], $rows_total_data[$i]['Mcu_KelainanGroupName'], $formattedPercentage, $pasien ]; } else { break; } } // Encapsulate in config attribute and JSON encode $config = ["config" => $option]; $j_param = json_encode($config); // Set content type to image/png header("Content-Type: image/png"); // Post to chart renderer echo $this->post($this->url_renderer, $j_param); } function mcu004($id) { $sql_total_all = "SELECT COUNT(*) as xTotalAll, Mcu_OrderMgm_McuID FROM one_etl.mcu_order WHERE Mcu_OrderMgm_McuID =? "; $qry_total_all = $this->db->query($sql_total_all, [$id]); $this->check_error($qry_total_all, "get xTotalAll mcu"); $rows_total = $qry_total_all->result_array(); $maxAmount = 0.0; $maxAmount += $rows_total[0]['xTotalAll']; $color = [ 200, 150, 125, 100, 90, 80, 75, 70, 60, 50, ]; // ECharts option in PHP $option = array( 'title' => array( // 'text' => '% Keluhan Saat ini', 'left' => 'center' ), 'dataset' => array( array( "dimensions" => ['score', 'amount', 'product', 'percentage'], 'source' => array(), ), array( "transform" => array( "type" => 'sort', "config" => array( "dimension" => 'percentage', "order" => 'asc' ) ) ) ), 'grid' => array( 'containLabel' => true, 'width' => 'auto', 'height' => 'auto', ), 'xAxis' => array( 'name' => '', 'position' => 'top', 'max' => 100, 'axisLabel' => array( 'formatter' => '{value}%' // Menambahkan tanda persen di setiap label sumbu Y ) ), 'yAxis' => array( 'type' => 'category' ), 'visualMap' => array( 'orient' => 'horizontal', 'left' => 'center', 'min' => 0, 'max' => 100, 'show' => false, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'label' => array( 'position' => 'right', 'show' => true, "formatter" => "{@[3]}% {@[4]}" ), 'type' => 'bar', 'encode' => array( 'x' => 'percentage', 'y' => 'product' ), "datasetIndex" => 1 ) ) ); $sql_data = "SELECT count(*) as xTotalPerItem, Mcu_RiwayatName, Mgm_HeaderMgm_McuID, concat(COUNT(*) , ' Peserta' ) as pasien FROM one_etl.mgm_header JOIN one_etl.mgm_riwayat ON Mgm_HeaderID = Mgm_RiwayatMgm_HeaderID AND Mgm_HeaderIsActive = 'Y' AND Mgm_RiwayatIsActive = 'Y' JOIN one_etl.mcu_riwayat ON Mgm_RiwayatMcu_RiwayatID = Mcu_RiwayatID AND Mcu_RiwayatIsActive = 'Y' AND Mcu_RiwayatMcu_RiwayatGroupID = 4 AND Mgm_HeaderMgm_McuID = ? GROUP BY Mcu_RiwayatID ORDER BY xTotalPerItem DESC LIMIT 0, 10"; $qry_total_data = $this->db->query($sql_data, [$id]); $this->check_error($qry_total_data, "get xTotalPerItem mgm_header"); $rows_total_data = $qry_total_data->result_array(); for ($i = 0; $i < count($rows_total_data); $i++) { if ($i < count($color)) { $percentage = (($rows_total_data[$i]['xTotalPerItem'] / $maxAmount) * 100); $pasien = $rows_total_data[$i]['pasien']; $formattedPercentage = number_format($percentage, 2); $option['dataset'][0]['source'][] = [ $color[$i], $rows_total_data[$i]['xTotalPerItem'], $rows_total_data[$i]['Mcu_RiwayatName'], $formattedPercentage, $pasien ]; } else { break; } } // Encapsulate in config attribute and JSON encode $config = ["config" => $option]; $j_param = json_encode($config); // echo $j_param; // Set content type to image/png header("Content-Type: image/png"); // Post to chart renderer echo $this->post($this->url_renderer, $j_param); } // pola kebiasaan mcu005 // --> MCU020 Pola Kebiasaan chart batang (merokok, minum alkohol, olahraga) function mcu005($id) { $rows_all_data = []; // 1. prepare the data using sql $sql = "WITH na_data AS ( SELECT COUNT(Mcu_OrderT_OrderHeaderID) AS peserta FROM one_etl.mgm_mcu JOIN one_etl.mcu_order ON Mcu_OrderMgm_McuID = Mgm_McuID AND Mgm_McuID = ? ) SELECT COUNT(DISTINCT Mgm_HeaderT_OrderHeaderID) AS total, '2' as kode, 'YA' AS test, Mcu_RiwayatSegmentName AS location FROM one_etl.mcu_riwayat JOIN one_etl.mgm_riwayat ON Mcu_RiwayatID = Mgm_RiwayatMcu_RiwayatID AND Mcu_RiwayatMcu_RiwayatGroupID = 6 AND Mcu_RiwayatIsActive = 'Y' AND Mcu_RiwayatCode IN ( 'fisik_kebiasaanhidup_2', 'fisik_kebiasaanhidup_3', 'fisik_kebiasaanhidup_14', 'fisik_kebiasaanhidup_5', 'fisik_kebiasaanhidup_6', 'fisik_kebiasaanhidup_7', 'fisik_kebiasaanhidup_9', 'fisik_kebiasaanhidup_10', 'fisik_kebiasaanhidup_11','fisik_kebiasaanhidup_12' ) LEFT JOIN one_etl.mgm_header ON Mgm_RiwayatMgm_HeaderID = Mgm_HeaderID AND Mgm_RiwayatIsActive = 'Y' AND Mgm_HeaderIsActive = 'Y' AND Mgm_HeaderMgm_McuID = ? GROUP BY Mcu_RiwayatSegmentName UNION SELECT COUNT(DISTINCT Mgm_HeaderT_OrderHeaderID) AS total, '1' as kode, 'TIDAK' AS test, Mcu_RiwayatSegmentName AS location FROM one_etl.mcu_riwayat JOIN one_etl.mgm_riwayat ON Mcu_RiwayatID = Mgm_RiwayatMcu_RiwayatID AND Mcu_RiwayatMcu_RiwayatGroupID = 6 AND Mcu_RiwayatIsActive = 'Y' AND Mcu_RiwayatCode IN ('fisik_kebiasaanhidup_1','fisik_kebiasaanhidup_4','fisik_kebiasaanhidup_8') LEFT JOIN one_etl.mgm_header ON Mgm_RiwayatMgm_HeaderID = Mgm_HeaderID AND Mgm_RiwayatIsActive = 'Y' AND Mgm_HeaderIsActive = 'Y' AND Mgm_HeaderMgm_McuID = ? GROUP BY Mcu_RiwayatSegmentName UNION SELECT na_data.peserta - COUNT(DISTINCT Mgm_HeaderT_OrderHeaderID) AS total, '3' as kode, 'N/A' AS test, Mcu_RiwayatSegmentName AS location FROM na_data, one_etl.mcu_riwayat JOIN one_etl.mgm_riwayat ON Mcu_RiwayatID = Mgm_RiwayatMcu_RiwayatID AND Mcu_RiwayatMcu_RiwayatGroupID = 6 AND Mcu_RiwayatIsActive = 'Y' AND Mcu_RiwayatCode IN ( 'fisik_kebiasaanhidup_2', 'fisik_kebiasaanhidup_3', 'fisik_kebiasaanhidup_14', 'fisik_kebiasaanhidup_5', 'fisik_kebiasaanhidup_6', 'fisik_kebiasaanhidup_7', 'fisik_kebiasaanhidup_9', 'fisik_kebiasaanhidup_10', 'fisik_kebiasaanhidup_11','fisik_kebiasaanhidup_12', 'fisik_kebiasaanhidup_1','fisik_kebiasaanhidup_4','fisik_kebiasaanhidup_8' ) LEFT JOIN one_etl.mgm_header ON Mgm_RiwayatMgm_HeaderID = Mgm_HeaderID AND Mgm_RiwayatIsActive = 'Y' AND Mgm_HeaderIsActive = 'Y' AND Mgm_HeaderMgm_McuID = ? GROUP BY Mcu_RiwayatSegmentName ORDER BY location,kode"; $qry_total_data = $this->db->query($sql, [$id, $id, $id, $id]); $this->check_error($qry_total_data, "get xTotalAll mcu"); $rows = $qry_total_data->result_array(); if (count($rows) == 0) { // $this->chart_error("No data found"); } //fungsi mengatur pembagian label / text function wrapText($text, $maxLength) { return wordwrap($text, $maxLength, "\n", true); // Memecah teks menjadi beberapa baris dengan panjang maksimum dan menggunakan newline sebagai pemisah } // 2. generate parameter for the chart $color = ['#36A2EB', '#FF5733', '#FFC300', '#4BC0C0', '#9966FF']; // Mendapatkan nilai unik dari 'test' dan 'location' serta mengatur ulang indeks array $uniqueTests = array_values(array_unique(array_column($rows, 'test'))); $uniqueLocations = array_values(array_unique(array_column($rows, 'location'))); $param = array( 'title' => array( 'text' => 'Pola Kebiasaan', 'left' => 'center', // Menempatkan legend di tengah secara horizontal, 'top' => 'top', 'orient' => 'vertical' ), 'dataset' => array( 'source' => array( array('score', 'amount', 'product'), ) ), //menampilkan nama bagian tiap-tiap chart 'legend' => array( 'data' => $uniqueTests, 'left' => 'center', 'bottom' => 'bottom', 'orient' => 'horizontal' ), 'grid' => array('containLabel' => true), 'yAxis' => array('type' => 'value', 'name' => 'peserta', ), 'xAxis' => array( 'type' => 'category', 'axisTick' => array('show' => false), 'data' => $uniqueLocations, ), 'visualMap' => array( 'orient' => 'horizontal', 'show' => false, 'left' => 'center', 'min' => 0, 'max' => 100, 'dimension' => 0, 'inRange' => array( // 'color' => array('#0000FF', '#00eaf2', '#035bff') ) ), 'series' => array() ); // Memetakan warna tiap bar sesuai dengan kategori test $colorMapping = array(); foreach ($uniqueTests as $index => $test) { $colorMapping[$test] = $color[$index % count($color)]; // Menggunakan modulus untuk memastikan palet warna diulang jika jumlah kategori lebih banyak daripada warna yang tersedia } foreach ($uniqueTests as $test) { $data = array_fill(0, count($uniqueLocations), null); // Inisialisasi data untuk setiap lokasi foreach ($rows as $row) { if ($row['test'] == $test) { // Menemukan indeks lokasi dalam $uniqueLocations $locationIndex = array_search($row['location'], $uniqueLocations); if ($locationIndex !== false) { $data[$locationIndex] = $row['total'] ?? 0; // Handling null values } } } $param['series'][] = array( 'name' => $test, 'type' => 'bar', 'barGap' => 0.5, 'avoidLabelOverlap' => true, 'label' => array( 'show' => true, 'position' => 'top', 'distance' => 5, 'fontSize' => 11, // Menyesuaikan ukuran font 'formatter' => '{c}', // Menggunakan formatter untuk memisahkan baris ), 'itemStyle' => array( // Menentukan gaya item untuk bar, termasuk warnanya 'color' => $colorMapping[$test] ), 'data' => $data ); } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // bmi pie mcu006 function mcu006($id) { // 1. prepare the data using sql // SQL belum tau dari tabel dan field apa saja $maxAmount = 0.0; $color = ['#FF5733', '#FFC300', '#36A2EB', '#4BC0C0', '#9966FF']; $sql = "SELECT COUNT(*) AS xTotal FROM one_etl.mgm_header JOIN one_etl.mgm_detail ON Mgm_DetailMgm_HeaderID = Mgm_HeaderID AND Mgm_DetailIsActive = 'Y' AND Mgm_HeaderIsActive = 'Y' AND Mgm_DetailMcu_KelainanGroupID = 1 AND Mgm_HeaderMgm_McuID = ? JOIN one_etl.mcu_kelainan ON Mgm_DetailMcu_KelainanID = Mcu_KelainanID AND Mcu_KelainanClasification = 'asia_pacific' AND Mcu_KelainanIsActive = 'Y'"; $qry_total = $this->db->query($sql, [$id]); $this->check_error($qry_total, "get total item"); $rows_total = $qry_total->result_array(); if (count($rows_total) == 0) { // $this->chart_error("No data found"); } $sql = "SELECT COUNT(*) AS xTotalPerItem, CASE WHEN Mcu_KelainanName = 'Underweight' THEN 'Underweight' WHEN Mcu_KelainanName = 'Normal' THEN 'Normal' WHEN Mcu_KelainanName = 'Overweight' THEN 'Overweight' WHEN Mcu_KelainanName = 'Obese I' THEN 'Obese I' WHEN Mcu_KelainanName = 'Obese II' THEN 'Obese II' ELSE Mcu_KelainanName END AS test FROM one_etl.mgm_header JOIN one_etl.mgm_detail ON Mgm_DetailMgm_HeaderID = Mgm_HeaderID AND Mgm_DetailIsActive = 'Y' AND Mgm_HeaderIsActive = 'Y' AND Mgm_DetailMcu_KelainanGroupID = 1 AND Mgm_HeaderMgm_McuID = ? JOIN one_etl.mcu_kelainan ON Mgm_DetailMcu_KelainanID = Mcu_KelainanID AND Mcu_KelainanIsActive = 'Y' GROUP BY test ORDER BY CASE WHEN test = 'Kurus Berat' THEN 0 WHEN test = 'Underweight' THEN 1 WHEN test = 'Normal' THEN 2 WHEN test = 'Overweight' THEN 3 WHEN test = 'Obese' THEN 4 WHEN test = 'Obese I' THEN 5 WHEN test = 'Obese II' THEN 6 END "; $qry_total_data = $this->db->query($sql, [$id]); $this->check_error($qry_total_data, "get total item"); $rows = $qry_total_data->result_array(); if (count($rows) == 0) { // $this->chart_error("No data found"); } $maxAmount = $rows_total[0]['xTotal']; // 2. generate parameter for the chart $param = array( 'title' => array( 'text' => 'Body Mass Index (BMI)', 'left' => 'center' ), 'tooltip' => array( 'trigger' => 'item' ), 'legend' => array( 'show' => false, 'top' => 'bottom', 'left' => 'center', 'orient' => 'vertical' ), 'series' => array( array( 'avoidoverlap' => true, 'label' => array( 'formatter' => '{b} ' . chr(10) . '{d}%, {c} peserta' ), 'name' => 'Access From', 'type' => 'pie', 'radius' => '50%', 'labelLayout' => array( 'hideOverlap' => false, // Mengatur agar label yang bertabrakan disembunyikan 'color' => 'black', ), 'itemStyle' => array( 'borderRadius' => 1, 'borderColor' => '#fff', 'borderWidth' => 1 ), 'data' => array() ) ) ); for ($i = 0; $i < count($rows); $i++) { $percentage = (($rows[$i]['xTotalPerItem'] / $maxAmount) * 100); $formattedPercentage = number_format($percentage, 2); $param['series'][0]['data'][] = array( // 'value' => $formattedPercentage, 'value' => $rows[$i]['xTotalPerItem'], 'name' => $rows[$i]['test'], 'itemStyle' => array( 'color' => $color[$i] // Warna untuk potongan ini ) ); } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // sebaran BMI site perusahaan perusahaan (chart batang) mcu007 function mcu007($id) { $sql = "SELECT COUNT(DISTINCT Mgm_HeaderT_OrderHeaderID) AS total, CASE WHEN Mcu_KelainanName = 'Underweight' THEN 'Underweight' WHEN Mcu_KelainanName = 'Normal' THEN 'Normal' WHEN Mcu_KelainanName = 'Overweight' THEN 'Overweight' WHEN Mcu_KelainanName = 'Obese I' THEN 'Obese I' WHEN Mcu_KelainanName = 'Obese II' THEN 'Obese II' ELSE Mcu_KelainanName END AS test, if(Mgm_HeaderM_PatientLocation = '' or Mgm_HeaderM_PatientLocation is null ,'Departement', Mgm_HeaderM_PatientLocation ) AS location FROM one_etl.mgm_header JOIN one_etl.mgm_detail ON Mgm_DetailMgm_HeaderID = Mgm_HeaderID AND Mgm_HeaderIsActive = 'Y' AND Mgm_HeaderNat_TestCode = 'STATUS GIZI' AND Mgm_HeaderMgm_McuID =? AND Mgm_DetailIsActive = 'Y' AND Mgm_DetailMcu_KelainanGroupID = 1 JOIN one_etl.mcu_kelainan ON Mgm_DetailMcu_KelainanID = Mcu_KelainanID AND Mcu_KelainanIsActive = 'Y' GROUP BY Mcu_KelainanName, location ORDER BY CASE WHEN test = 'Kurus Berat' THEN 0 WHEN test = 'Underweight' THEN 1 WHEN test = 'Normal' THEN 2 WHEN test = 'Overweight' THEN 3 WHEN test = 'Obese' THEN 4 WHEN test = 'Obese I' THEN 5 WHEN test = 'Obese II' THEN 6 END "; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { // $this->chart_error("No data found"); } // 2. generate parameter for the chart // Palet warna yang ingin Anda gunakan $color = ['#FF5733', '#FFC300', '#36A2EB', '#4BC0C0', '#9966FF']; function wrapText($text, $maxLength) { return wordwrap($text, $maxLength, "\n", true); // Memecah teks menjadi beberapa baris dengan panjang maksimum dan menggunakan newline sebagai pemisah } // Mendapatkan nilai unik dari 'test' dan 'location' serta mengatur ulang indeks array $uniqueTests = array_values(array_unique(array_column($rows, 'test'))); $uniqueLocations = array_values(array_unique(array_column($rows, 'location'))); $param = array( 'title' => array( ), 'dataset' => array( 'source' => array( array('score', 'amount', 'product'), ), ), //menampilkan nama bagian tiap-tiap chart 'legend' => array( 'data' => $uniqueTests, 'left' => 'center', 'bottom' => 'bottom', 'orient' => 'horizontal' ), 'grid' => array( 'containLabel' => true, 'width' => 'auto', 'height' => 'auto', ), 'yAxis' => array( 'type' => 'value', 'name' => 'peserta', ), 'xAxis' => array( 'type' => 'category', 'axisTick' => array('show' => false), // 'data' => $uniqueLocations, $maxWidth = 13, 'data' => array_map(function ($location) use ($maxWidth) { return wrapText($location, $maxWidth); // Memecah nama lokasi menjadi beberapa baris jika terlalu panjang }, $uniqueLocations), ), 'labelLayout' => array( 'hideOverlap' => false // Mengatur agar label yang bertabrakan disembunyikan ), 'visualMap' => array( 'orient' => 'horizontal', // 'show' => true, // 'left' => 'center', // 'min' => 0, // 'dimension' => 0, 'inRange' => array( // 'color' => array('#0000FF', '#00eaf2', '#035bff') ) ), 'series' => array() ); // Memetakan warna tiap bar sesuai dengan kategori test $colorMapping = array(); foreach ($uniqueTests as $index => $test) { $colorMapping[$test] = $color[$index % count($color)]; // Menggunakan modulus untuk memastikan palet warna diulang jika jumlah kategori lebih banyak daripada warna yang tersedia } foreach ($uniqueTests as $test) { $data = array_fill(0, count($uniqueLocations), null); // Inisialisasi data untuk setiap lokasi foreach ($rows as $row) { if ($row['test'] == $test) { // Menemukan indeks lokasi dalam $uniqueLocations $locationIndex = array_search($row['location'], $uniqueLocations); if ($locationIndex !== false) { $data[$locationIndex] = $row['total'] ?? 0; // Handling null values } } } $param['series'][] = array( 'name' => $test, 'type' => 'bar', 'barGap' => 0.5, 'avoidLabelOverlap' => true, 'label' => array( 'show' => true, 'position' => 'top', 'fontSize' => 10, // Menyesuaikan ukuran font 'formatter' => '{c}', // Menggunakan formatter untuk memisahkan baris ), 'itemStyle' => array( // Menentukan gaya item untuk bar, termasuk warnanya 'color' => $colorMapping[$test] ), 'labelLayout' => array( 'hideOverlap' => false, // Tidak menyembunyikan label 'moveOverlap' => 'shiftY', // Menggeser label untuk menghindari tumpang tindih ), 'data' => $data ); } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo($j_param); header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // pola kelainan penyakit mcu008 function mcu008($id) { $color = [ 200, 150, 125, 100, 90, 80, 75, 70, 60, 50, ]; // Calculate the maximum amount $maxAmount = 0.0; // ECharts option in PHP $option = array( 'title' => array( 'text' => 'Pola Kelainan Penyakit' ), 'dataset' => array( array( "dimensions" => ['score', 'amount', 'product', 'percentage'], 'source' => array(), ), array( "transform" => array( "type" => 'sort', "config" => array( "dimension" => 'percentage', "order" => 'asc' ) ) ) ), 'grid' => array( 'containLabel' => true, 'width' => 'auto', 'height' => 'auto', ), 'xAxis' => array( 'position' => 'top', 'axisLabel' => array( 'formatter' => '{value}%' // Menambahkan tanda persen di setiap label sumbu Y ) ), 'yAxis' => array( 'type' => 'category', 'axisLabel' => [ 'fontSize' => 9, 'formarter' => '{@[2]}%' ] ), 'visualMap' => array( 'orient' => 'horizontal', 'left' => 'center', 'show' => false, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'label' => array( 'position' => 'right', 'show' => true, "formatter" => "{@[3]}%" . chr(10) . "{@[1]} peserta", 'fontSize' => 9, ), 'type' => 'bar', 'encode' => array( 'x' => 'percentage', 'y' => 'product' ), "datasetIndex" => 1 ) ) ); // total order yang non lab saja $sql_total_all = "SELECT COUNT(distinct Mgm_HeaderT_OrderHeaderID) as xTotalAll, Mgm_HeaderMgm_McuID FROM one_etl.mgm_header WHERE Mgm_HeaderIsActive = 'Y' AND Mgm_HeaderMgm_McuID = ?"; $qry_total_all = $this->db->query($sql_total_all, [$id]); $this->check_error($qry_total_all, "get xTotalAll mcu"); $rows_total = $qry_total_all->result_array(); if (count($rows_total) == 0) { // $this->chart_error("No data found"); } $maxAmount += $rows_total[0]['xTotalAll']; // Data $sql_data = "select count(xTotalPerItem) as xTotalPerItem, Mcu_KelainanGroupName, Mgm_HeaderMgm_McuID from ( SELECT distinct Mgm_HeaderT_OrderHeaderID AS xTotalPerItem , if (Mcu_KelainanGroupID IN (2,3,16,22,17,18,19,20,28,29) , Mcu_KelainanGroupName, Mcu_KelainanName) as Mcu_KelainanGroupName , Mgm_HeaderMgm_McuID FROM one_etl.mgm_header JOIN one_etl.mgm_detail ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID AND Mgm_HeaderIsActive = 'Y' AND Mgm_DetailIsActive = 'Y' JOIN one_etl.mcu_kelainangroup ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID AND Mcu_KelainanGroupIsActive = 'Y' join one_etl.mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID and Mcu_KelainanIsActive = 'Y' WHERE Mgm_HeaderMgm_McuID = ? and Mcu_KelainanName <> 'Normal' and Mcu_KelainanGroupID not in (1,5) and Mcu_KelainanID not in (63,12) ) as orderid group by Mcu_KelainanGroupName order by xTotalPerItem DESC limit 0,10"; $qry_total_data = $this->db->query($sql_data, [$id]); $this->check_error($qry_total_data, "get xTotalPerItem mcu"); $rows_total_data = $qry_total_data->result_array(); if (count($rows_total_data) == 0) { // $this->chart_error("No data found"); } for ($i = 0; $i < count($rows_total_data); $i++) { if ($i < count($color)) { $percentage = (($rows_total_data[$i]['xTotalPerItem'] / $maxAmount) * 100); $formattedPercentage = number_format($percentage, 2); $option['dataset'][0]['source'][] = [ $color[$i], $rows_total_data[$i]['xTotalPerItem'], $rows_total_data[$i]['Mcu_KelainanGroupName'], $formattedPercentage ]; } else { break; } } // Encapsulate in config attribute and JSON encode $config = ["config" => $option]; $j_param = json_encode($config); // Set content type to image/png header("Content-Type: image/png"); // Post to chart renderer echo $this->post($this->url_renderer, $j_param); } // gangguan lemak persite mcu009 function mcu009($id) { $maxAmount = 0.0; $maxwidth = 40; $title_value = "Sebaran Gangguan Metabolisme Lemak Per Departement (Prosentase)"; // Palet warna yang ingin Anda gunakan $color = [ 200, 150, 125, 100, 90, 80, 75, 70, 60, 50, ]; function wrapText($text, $maxLength) { return wordwrap($text, $maxLength, "\n", true); // Memecah teks menjadi beberapa baris dengan panjang maksimum dan menggunakan newline sebagai pemisah } $option = array( 'title' => array( 'text' => wrapText($title_value, $maxwidth), 'left' => 'center', // Menempatkan legend di tengah secara horizontal, 'top' => 'top', 'orient' => 'vertical' ), 'dataset' => array( array( "dimensions" => ['score', 'amount', 'product', 'percentage'], 'source' => array() ), array( 'transform' => array( 'type' => 'sort', 'config' => array( 'dimension' => 'percentage', 'order' => 'desc' ) ) ) ), 'grid' => array( 'containLabel' => true ), 'xAxis' => array( 'type' => 'category', // 'axisLabel' => array('interval' => 0, 'rotate' => 330) ), 'yAxis' => array( 'type' => 'value', 'show' => true, 'min' => 0, 'max' => 100, 'axisLabel' => array('formatter' => '{value}%') ), 'visualMap' => array( 'orient' => 'horizontal', 'show' => false, 'left' => 'center', 'min' => 0, 'max' => 100, 'dimension' => 0, 'inRange' => array( // 'color' => array('#0000FF', '#00eaf2', '#035bff') ) ), 'series' => array( 'type' => 'bar', 'encode' => array( 'x' => 'product', 'y' => 'percentage' ), 'datasetIndex' => 1, 'label' => array( 'show' => true, 'position' => 'top', 'formatter' => "{@[3]}%" . chr(10) . '{@[1]} peserta', ) ) ); $sql_total_all = "SELECT COUNT(DISTINCT Mgm_HeaderT_OrderHeaderID) as xTotalAll, Mgm_HeaderMgm_McuID FROM one_etl.mgm_header WHERE Mgm_HeaderMgm_McuID = ? AND Mgm_HeaderIsActive = 'Y' "; $qry_total_all = $this->db->query($sql_total_all, [$id]); $this->check_error($qry_total_all, "get xTotalAll mcu"); $rows_total = $qry_total_all->result_array(); if (count($rows_total) == 0) { // $this->chart_error("No data found"); } $maxAmount += $rows_total[0]['xTotalAll']; $sql_data = "SELECT if(Mgm_HeaderM_PatientLocation = '' or Mgm_HeaderM_PatientLocation is null ,'Departement', Mgm_HeaderM_PatientLocation) as location, IFNULL(Mcu_KelainanGroupName, '-') as test, COUNT(DISTINCT Mgm_HeaderT_OrderHeaderID) as xTotalPerItem FROM one_etl.mgm_header JOIN one_etl.mgm_detail ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID AND Mgm_HeaderMgm_McuID = ? AND Mgm_DetailIsActive = 'Y' AND Mgm_DetailMcu_KelainanGroupID = 17 JOIN one_etl.mcu_kelainangroup ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID GROUP BY location"; $qry_total_data = $this->db->query($sql_data, [$id]); $this->check_error($qry_total_data, "get xTotalPerItem mcu"); $rows_total_data = $qry_total_data->result_array(); if (count($rows_total_data) == 0) { // $this->chart_error("No data found"); } // var_dump($rows_total_data); // exit; for ($i = 0; $i < count($rows_total_data); $i++) { $percentage = (($rows_total_data[$i]['xTotalPerItem'] / $maxAmount) * 100); $formattedPercentage = number_format($percentage, 2); $option['dataset'][0]['source'][] = [ $color[$i], $rows_total_data[$i]['xTotalPerItem'], $rows_total_data[$i]['location'], $formattedPercentage ]; } // 3. encapsulate in config attribute and json encode $config = ["config" => $option]; $j_param = json_encode($config); // echo $j_param; // exit; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // gangguan lemak mcu010 function mcu010($id) { $maxwidth = 40; $title_value = "Sebaran Gangguan Metabolisme Lemak"; function wrapText($text, $maxLength) { return wordwrap($text, $maxLength, "\n", true); // Memecah teks menjadi beberapa baris dengan panjang maksimum dan menggunakan newline sebagai pemisah } $option = array( "title" => array( "text" => wrapText($title_value, $maxwidth), "left" => 'center', "orient" => 'vertical' ), "legend" => array( "bottom" => 'bottom' ), "tooltip" => array(), "dataset" => array( "dimensions" => array('product', 'laki-laki', 'perempuan'), "source" => array() ), "grid" => array( "containLabel" => true ), "xAxis" => array( "type" => 'category' ), 'yAxis' => array('type' => 'value', 'name' => 'peserta', ), "series" => array( array( "type" => 'bar', "label" => array( "show" => true, "position" => 'top', 'formatter' => '{@[1]}', ), ), array( "type" => 'bar', "label" => array( "show" => true, "position" => 'top', 'formatter' => '{@[2]}', ), "itemStyle" => array( "color" => 'orange' ) ) ) ); $sql_data = "SELECT distinct Mgm_HeaderT_OrderHeaderID, Mgm_HeaderM_SexCode as M_SexCode, instr(Mgm_HeaderT_OrderHeaderM_PatientAge,'tahun') as instr_thn, replace(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge,'(\\\\d+) tahun'),'tahun','') as xTahun, CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED) as xUmurTahunNew from one_etl.mgm_header join one_etl.mgm_detail ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID AND Mgm_DetailIsActive = 'Y' AND Mgm_DetailMcu_KelainanGroupID = 17 AND Mgm_HeaderMgm_McuID = ? AND Mgm_HeaderIsActive = 'Y' "; $qry_data = $this->db->query($sql_data, [$id]); $this->check_error($qry_data, 'get xData mcu'); $rows_data = $qry_data->result_array(); $result = [ ["<30", 0, 0], ["30 - <40", 0, 0], ["40 - <50", 0, 0], [">= 50", 0, 0] ]; $age_groups = [ 'before_30' => [], 'between_30_40' => [], 'between_40_50' => [], 'after_50' => [] ]; $l_counts = [ 'before_30' => 0, 'between_30_40' => 0, 'between_40_50' => 0, 'after_50' => 0 ]; $p_counts = [ 'before_30' => 0, 'between_30_40' => 0, 'between_40_50' => 0, 'after_50' => 0 ]; foreach ($rows_data as $vx) { if ($vx['M_SexCode'] == 'L') { if ((int) $vx['xUmurTahunNew'] < 30) { $age_groups['before_30'][] = (int) $vx['xUmurTahunNew']; $l_counts['before_30']++; } elseif ((int) $vx['xUmurTahunNew'] >= 30 && (int) $vx['xUmurTahunNew'] < 40) { $age_groups['between_30_40'][] = (int) $vx['xUmurTahunNew']; $l_counts['between_30_40']++; } elseif ((int) $vx['xUmurTahunNew'] >= 40 && (int) $vx['xUmurTahunNew'] < 50) { $age_groups['between_40_50'][] = (int) $vx['xUmurTahunNew']; $l_counts['between_40_50']++; } elseif ((int) $vx['xUmurTahunNew'] >= 50) { $age_groups['after_50'][] = (int) $vx['xUmurTahunNew']; $l_counts['after_50']++; } } else { // M_SexCode == 'P' if ((int) $vx['xUmurTahunNew'] < 30) { $age_groups['before_30'][] = (int) $vx['xUmurTahunNew']; $p_counts['before_30']++; } elseif ((int) $vx['xUmurTahunNew'] >= 30 && (int) $vx['xUmurTahunNew'] < 40) { $age_groups['between_30_40'][] = (int) $vx['xUmurTahunNew']; $p_counts['between_30_40']++; } elseif ((int) $vx['xUmurTahunNew'] >= 40 && (int) $vx['xUmurTahunNew'] < 50) { $age_groups['between_40_50'][] = (int) $vx['xUmurTahunNew']; $p_counts['between_40_50']++; } elseif ((int) $vx['xUmurTahunNew'] >= 50) { $age_groups['after_50'][] = (int) $vx['xUmurTahunNew']; $p_counts['after_50']++; } } } $age_ranges = ['before_30', 'between_30_40', 'between_40_50', 'after_50']; for ($i = 0; $i < count($age_ranges); $i++) { $result[$i][1] = $l_counts[$age_ranges[$i]]; $result[$i][2] = $p_counts[$age_ranges[$i]]; } // print_r($result); $option['dataset']['source'] = $result; // 3. encapsulate in config attribute and json encode $config = ["config" => $option]; $j_param = json_encode($config); // echo $j_param; // exit; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // hypertensi persite mcu011 function mcu011($id) { $maxAmount = 0.0; $maxwidth = 40; $title_value = "Sebaran Gangguan Hypertensi Per Departement (Prosentase)"; // Palet warna yang ingin Anda gunakan $color = [ 200, 150, 125, 100, 90, 80, 75, 70, 60, 50, ]; function wrapText($text, $maxLength) { return wordwrap($text, $maxLength, "\n", true); // Memecah teks menjadi beberapa baris dengan panjang maksimum dan menggunakan newline sebagai pemisah } $option = array( 'title' => array( 'text' => wrapText($title_value, $maxwidth), 'left' => 'center', // Menempatkan legend di tengah secara horizontal, 'top' => 'top', 'orient' => 'vertical' ), 'dataset' => array( array( "dimensions" => ['score', 'amount', 'product', 'percentage'], 'source' => array() ), array( 'transform' => array( 'type' => 'sort', 'config' => array( 'dimension' => 'percentage', 'order' => 'desc' ) ) ) ), 'grid' => array( 'containLabel' => true ), 'xAxis' => array( 'type' => 'category', // 'axisLabel' => array('interval' => 0, 'rotate' => 330) ), 'yAxis' => array( 'type' => 'value', 'min' => 0, 'max' => 100, 'axisLabel' => array('formatter' => '{value}%') ), 'visualMap' => array( 'orient' => 'horizontal', 'show' => false, 'left' => 'center', 'min' => 0, 'max' => 100, 'dimension' => 0, 'inRange' => array( // 'color' => array('#0000FF', '#00eaf2', '#035bff') ) ), 'series' => array( 'type' => 'bar', 'encode' => array( 'x' => 'product', 'y' => 'percentage' ), 'datasetIndex' => 1, 'label' => array( 'show' => true, 'position' => 'top', 'formatter' => "{@[3]}%" . chr(10) . "{@[1]}peserta", ) ) ); // total order hypertensi $sql_total_all = "SELECT COUNT(DISTINCT Mgm_HeaderT_OrderHeaderID) as xTotalAll, Mgm_HeaderMgm_McuID FROM one_etl.mgm_header WHERE Mgm_HeaderMgm_McuID = ? AND Mgm_HeaderIsActive = 'Y' "; $qry_total_all = $this->db->query($sql_total_all, [$id]); $this->check_error($qry_total_all, "get xTotalAll mcu"); $rows_total = $qry_total_all->result_array(); if (count($rows_total) == 0) { // $this->chart_error("No data found"); } $maxAmount += $rows_total[0]['xTotalAll']; $sql_data = "SELECT if(Mgm_HeaderM_PatientLocation = '' or Mgm_HeaderM_PatientLocation is null ,'Departement', Mgm_HeaderM_PatientLocation) as location, IFNULL(Mcu_KelainanGroupName, '-') as test, COUNT(DISTINCT Mgm_HeaderT_OrderHeaderID) as xTotalPerItem FROM one_etl.mgm_header JOIN one_etl.mgm_detail ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID AND Mgm_DetailIsActive = 'Y' AND Mgm_DetailMcu_KelainanGroupID = 2 AND Mgm_HeaderMgm_McuID = ? JOIN one_etl.mcu_kelainangroup ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID GROUP BY location "; $qry_total_data = $this->db->query($sql_data, [$id]); $this->check_error($qry_total_data, "get xTotalPerItem mcu"); $rows_total_data = $qry_total_data->result_array(); if (count($rows_total_data) == 0) { // $this->chart_error("No data found"); } // var_dump($rows_total_data); // exit; for ($i = 0; $i < count($rows_total_data); $i++) { $percentage = (($rows_total_data[$i]['xTotalPerItem'] / $maxAmount) * 100); $formattedPercentage = number_format($percentage, 2); $option['dataset'][0]['source'][] = [ $color[$i], $rows_total_data[$i]['xTotalPerItem'], $rows_total_data[$i]['location'], $formattedPercentage ]; } // 3. encapsulate in config attribute and json encode $config = ["config" => $option]; $j_param = json_encode($config); // echo $j_param; // exit; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // hypertensi mcu012 function mcu012($id) { $maxwidth = 40; $title_value = "Sebaran Gangguan Hypertensi"; function wrapText($text, $maxLength) { return wordwrap($text, $maxLength, "\n", true); // Memecah teks menjadi beberapa baris dengan panjang maksimum dan menggunakan newline sebagai pemisah } $option = array( "title" => array( "text" => wrapText($title_value, $maxwidth), "left" => 'center', "orient" => 'vertical' ), "legend" => array( "bottom" => 'bottom' ), "tooltip" => array(), "dataset" => array( "dimensions" => array('product', 'laki-laki', 'perempuan'), "source" => array() ), "grid" => array( "containLabel" => true ), "xAxis" => array( "type" => 'category' ), 'yAxis' => array('type' => 'value', 'name' => 'peserta', ), "series" => array( array( "type" => 'bar', "label" => array( "show" => true, "position" => 'top', 'formatter' => "{@[1]}", ), ), array( "type" => 'bar', "label" => array( "show" => true, "position" => 'top', 'formatter' => "{@[2]}", ), "itemStyle" => array( "color" => 'orange' ) ) ) ); $sql_data = "SELECT distinct Mgm_HeaderT_OrderHeaderID, Mgm_HeaderM_SexCode as M_SexCode, instr(Mgm_HeaderT_OrderHeaderM_PatientAge,'tahun') as instr_thn, replace(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge,'(\\\\d+) tahun'),'tahun','') as xTahun, replace(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge,' (\\\\d+) bulan'),'bulan','') as xBulan, CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED) AS xUmurTahunNew from one_etl.mgm_header join one_etl.mgm_detail ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID AND Mgm_DetailIsActive = 'Y' AND Mgm_DetailMcu_KelainanGroupID = 2 AND Mgm_HeaderMgm_McuID = ? AND Mgm_HeaderIsActive = 'Y'"; $qry_data = $this->db->query($sql_data, [$id]); $this->check_error($qry_data, 'get xData mcu'); $rows_data = $qry_data->result_array(); $result = [ ["<30", 0, 0], ["30 - <40", 0, 0], ["40 - <50", 0, 0], [">= 50", 0, 0] ]; $age_groups = [ 'before_30' => [], 'between_30_40' => [], 'between_40_50' => [], 'after_50' => [] ]; $l_counts = [ 'before_30' => 0, 'between_30_40' => 0, 'between_40_50' => 0, 'after_50' => 0 ]; $p_counts = [ 'before_30' => 0, 'between_30_40' => 0, 'between_40_50' => 0, 'after_50' => 0 ]; foreach ($rows_data as $vx) { if ($vx['M_SexCode'] == 'L') { if ((int) $vx['xUmurTahunNew'] < 30) { $age_groups['before_30'][] = (int) $vx['xUmurTahunNew']; $l_counts['before_30']++; } elseif ((int) $vx['xUmurTahunNew'] >= 30 && (int) $vx['xUmurTahunNew'] < 40) { $age_groups['between_30_40'][] = (int) $vx['xUmurTahunNew']; $l_counts['between_30_40']++; } elseif ((int) $vx['xUmurTahunNew'] >= 40 && (int) $vx['xUmurTahunNew'] < 50) { $age_groups['between_40_50'][] = (int) $vx['xUmurTahunNew']; $l_counts['between_40_50']++; } elseif ((int) $vx['xUmurTahunNew'] >= 50) { $age_groups['after_50'][] = (int) $vx['xUmurTahunNew']; $l_counts['after_50']++; } } else { // M_SexCode == 'P' if ((int) $vx['xUmurTahunNew'] < 30) { $age_groups['before_30'][] = (int) $vx['xUmurTahunNew']; $p_counts['before_30']++; } elseif ((int) $vx['xUmurTahunNew'] >= 30 && (int) $vx['xUmurTahunNew'] < 40) { $age_groups['between_30_40'][] = (int) $vx['xUmurTahunNew']; $p_counts['between_30_40']++; } elseif ((int) $vx['xUmurTahunNew'] >= 40 && (int) $vx['xUmurTahunNew'] < 50) { $age_groups['between_40_50'][] = (int) $vx['xUmurTahunNew']; $p_counts['between_40_50']++; } elseif ((int) $vx['xUmurTahunNew'] >= 50) { $age_groups['after_50'][] = (int) $vx['xUmurTahunNew']; $p_counts['after_50']++; } } } $age_ranges = ['before_30', 'between_30_40', 'between_40_50', 'after_50']; for ($i = 0; $i < count($age_ranges); $i++) { $result[$i][1] = $l_counts[$age_ranges[$i]]; $result[$i][2] = $p_counts[$age_ranges[$i]]; } // print_r($result); $option['dataset']['source'] = $result; // 3. encapsulate in config attribute and json encode $config = ["config" => $option]; $j_param = json_encode($config); // echo $j_param; // exit; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // refraksi persite mcu013 function mcu013($id) { $maxAmount = 0.0; $maxwidth = 40; $title_value = "Sebaran Gangguan Refraksi Per Departement Perusahaan (Prosentase)"; // Palet warna yang ingin Anda gunakan $color = [ 200, 150, 125, 100, 90, 80, 75, 70, 60, 50, ]; function wrapText($text, $maxLength) { return wordwrap($text, $maxLength, "\n", true); // Memecah teks menjadi beberapa baris dengan panjang maksimum dan menggunakan newline sebagai pemisah } $option = array( 'title' => array( 'text' => wrapText($title_value, $maxwidth), 'left' => 'center', // Menempatkan legend di tengah secara horizontal, 'top' => 'top', 'orient' => 'vertical' ), 'dataset' => array( array( "dimensions" => ['score', 'amount', 'product', 'percentage'], 'source' => array() ), array( 'transform' => array( 'type' => 'sort', 'config' => array( 'dimension' => 'percentage', 'order' => 'desc' ) ) ) ), 'grid' => array( 'containLabel' => true ), 'xAxis' => array( 'type' => 'category', // 'axisLabel' => array('interval' => 0, 'rotate' => 330) ), 'yAxis' => array( 'type' => 'value', 'min' => 0, 'max' => 100, 'axisLabel' => array('formatter' => '{value}%') ), 'visualMap' => array( 'orient' => 'horizontal', 'show' => false, 'left' => 'center', 'min' => 0, 'max' => 100, 'dimension' => 0, 'inRange' => array( // 'color' => array('#0000FF', '#00eaf2', '#035bff') ) ), 'series' => array( 'type' => 'bar', 'encode' => array( 'x' => 'product', 'y' => 'percentage' ), 'datasetIndex' => 1, 'label' => array( 'show' => true, 'position' => 'top', 'formatter' => "{@[3]}%" . chr(10) . "{@[1]} peserta", ) ) ); // total order hypertensi $sql_total_all = "SELECT COUNT(DISTINCT Mgm_HeaderT_OrderHeaderID) as xTotalAll, Mgm_HeaderMgm_McuID FROM one_etl.mgm_header WHERE Mgm_HeaderMgm_McuID = ? AND Mgm_HeaderIsActive = 'Y' "; $qry_total_all = $this->db->query($sql_total_all, [$id]); $this->check_error($qry_total_all, "get xTotalAll mcu"); $rows_total = $qry_total_all->result_array(); if (count($rows_total) == 0) { // $this->chart_error("No data found"); } $maxAmount += $rows_total[0]['xTotalAll']; // Data $sql_data = "SELECT IFNULL(Mgm_HeaderM_PatientLocation,'-') as location, IFNULL(Mcu_KelainanGroupName, '-') as test, COUNT(*) as xTotalPerItem FROM one_etl.mgm_header JOIN one_etl.mgm_detail ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID AND Mgm_DetailIsActive = 'Y' AND Mgm_DetailMcu_KelainanGroupID = 3 AND Mgm_HeaderMgm_McuID = ? JOIN one_etl.mcu_kelainangroup ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID GROUP BY Mgm_HeaderM_PatientLocation"; $sql_data = "SELECT if(Mgm_HeaderM_PatientLocation = '' or Mgm_HeaderM_PatientLocation is null ,'Departement', Mgm_HeaderM_PatientLocation) as location, IFNULL(Mcu_KelainanGroupName, '-') as test, COUNT(DISTINCT Mgm_HeaderT_OrderHeaderID) as xTotalPerItem FROM one_etl.mgm_header JOIN one_etl.mgm_detail ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID AND Mgm_DetailIsActive = 'Y' AND Mgm_DetailMcu_KelainanGroupID = 3 AND Mgm_HeaderMgm_McuID = ? JOIN one_etl.mcu_kelainangroup ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID GROUP BY location"; $qry_total_data = $this->db->query($sql_data, [$id]); $this->check_error($qry_total_data, "get xTotalPerItem mcu"); $rows_total_data = $qry_total_data->result_array(); if (count($rows_total_data) == 0) { // $this->chart_error("No data found"); } // var_dump($rows_total_data); // exit; for ($i = 0; $i < count($rows_total_data); $i++) { $percentage = (($rows_total_data[$i]['xTotalPerItem'] / $maxAmount) * 100); $formattedPercentage = number_format($percentage, 2); $option['dataset'][0]['source'][] = [ $color[$i], $rows_total_data[$i]['xTotalPerItem'], $rows_total_data[$i]['location'], $formattedPercentage ]; } // 3. encapsulate in config attribute and json encode $config = ["config" => $option]; $j_param = json_encode($config); // echo $j_param; // exit; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // refraksi mcu014 function mcu014($id) { $maxwidth = 40; $title_value = "Sebaran Gangguan Refraksi"; function wrapText($text, $maxLength) { return wordwrap($text, $maxLength, "\n", true); // Memecah teks menjadi beberapa baris dengan panjang maksimum dan menggunakan newline sebagai pemisah } $option = array( "title" => array( "text" => wrapText($title_value, $maxwidth), "left" => 'center', "orient" => 'vertical' ), "legend" => array( "bottom" => 'bottom' ), "tooltip" => array(), "dataset" => array( "dimensions" => array('product', 'laki-laki', 'perempuan'), "source" => array() ), "grid" => array( "containLabel" => true ), "xAxis" => array( "type" => 'category' ), 'yAxis' => array('type' => 'value', 'name' => 'peserta', ), "series" => array( array( "type" => 'bar', "label" => array( "show" => true, "position" => 'top', 'formatter' => "{@[1]}", ), ), array( "type" => 'bar', "label" => array( "show" => true, "position" => 'top', 'formatter' => "{@[2]}", ), "itemStyle" => array( "color" => 'orange' ) ) ) ); $sql_data = "SELECT distinct Mgm_HeaderT_OrderHeaderID, Mgm_HeaderM_SexCode as M_SexCode, instr(Mgm_HeaderT_OrderHeaderM_PatientAge,'tahun') as instr_thn, replace(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge,'(\\\\d+) tahun'),'tahun','') as xTahun, replace(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge,' (\\\\d+) bulan'),'bulan','') as xBulan, CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED) AS xUmurTahunNew from one_etl.mgm_header join one_etl.mgm_detail ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID AND Mgm_DetailIsActive = 'Y' AND Mgm_DetailMcu_KelainanGroupID = 3 AND Mgm_HeaderMgm_McuID = ? AND Mgm_HeaderIsActive = 'Y'"; $qry_data = $this->db->query($sql_data, [$id]); $this->check_error($qry_data, 'get xData mcu'); $rows_data = $qry_data->result_array(); $result = [ ["<30", 0, 0], ["30 - <40", 0, 0], ["40 - <50", 0, 0], [">= 50", 0, 0] ]; $age_groups = [ 'before_30' => [], 'between_30_40' => [], 'between_40_50' => [], 'after_50' => [] ]; $l_counts = [ 'before_30' => 0, 'between_30_40' => 0, 'between_40_50' => 0, 'after_50' => 0 ]; $p_counts = [ 'before_30' => 0, 'between_30_40' => 0, 'between_40_50' => 0, 'after_50' => 0 ]; foreach ($rows_data as $vx) { if ($vx['M_SexCode'] == 'L') { if ((int) $vx['xUmurTahunNew'] < 30) { $age_groups['before_30'][] = (int) $vx['xUmurTahunNew']; $l_counts['before_30']++; } elseif ((int) $vx['xUmurTahunNew'] >= 30 && (int) $vx['xUmurTahunNew'] < 40) { $age_groups['between_30_40'][] = (int) $vx['xUmurTahunNew']; $l_counts['between_30_40']++; } elseif ((int) $vx['xUmurTahunNew'] >= 40 && (int) $vx['xUmurTahunNew'] < 50) { $age_groups['between_40_50'][] = (int) $vx['xUmurTahunNew']; $l_counts['between_40_50']++; } elseif ((int) $vx['xUmurTahunNew'] >= 50) { $age_groups['after_50'][] = (int) $vx['xUmurTahunNew']; $l_counts['after_50']++; } } else { // M_SexCode == 'P' if ((int) $vx['xUmurTahunNew'] < 30) { $age_groups['before_30'][] = (int) $vx['xUmurTahunNew']; $p_counts['before_30']++; } elseif ((int) $vx['xUmurTahunNew'] >= 30 && (int) $vx['xUmurTahunNew'] < 40) { $age_groups['between_30_40'][] = (int) $vx['xUmurTahunNew']; $p_counts['between_30_40']++; } elseif ((int) $vx['xUmurTahunNew'] >= 40 && (int) $vx['xUmurTahunNew'] < 50) { $age_groups['between_40_50'][] = (int) $vx['xUmurTahunNew']; $p_counts['between_40_50']++; } elseif ((int) $vx['xUmurTahunNew'] >= 50) { $age_groups['after_50'][] = (int) $vx['xUmurTahunNew']; $p_counts['after_50']++; } } } $age_ranges = ['before_30', 'between_30_40', 'between_40_50', 'after_50']; for ($i = 0; $i < count($age_ranges); $i++) { $result[$i][1] = $l_counts[$age_ranges[$i]]; $result[$i][2] = $p_counts[$age_ranges[$i]]; } // print_r($result); $option['dataset']['source'] = $result; // 3. encapsulate in config attribute and json encode $config = ["config" => $option]; $j_param = json_encode($config); // echo $j_param; // exit; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU001 function mcu015($id) { // 1. prepare the data using sql // SQL belum tau dari tabel dan field apa saja // 1. prepare the data using sql $sql = "SELECT Mcu_OrderMcu_FitnessName AS name, count(Mcu_OrderT_OrderHeaderID) AS total FROM one_etl.mcu_order WHERE Mcu_OrderMgm_McuID = ? GROUP BY Mcu_OrderMcu_FitnessID "; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total Status Fitness"); $rows = $qry->result_array(); // 2. generate parameter for the chart $param = array( 'title' => array( 'text' => 'Fitness Status', 'left' => 'center' ), 'tooltip' => array( 'trigger' => 'item', ), "dataset" => array( "dimensions" => array('name', 'total'), "source" => array() // Nanti diisi dengan data $result ), 'series' => array( array( 'width' => "100%", 'name' => 'Access From', 'type' => 'pie', 'radius' => '50%', 'avoidLabelOverlap' => true, 'labelLine' => array( 'show' => true ), 'label' => array( 'show' => true, 'position' => 'outside', 'formatter' => '{@[0]}' . chr(10) . '{d}% | {@[1]} peserta', ), 'itemStyle' => array( 'normal' => array( 'shadowBlur' => 5, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.5)' ) ), // 'emphasis' => array( // 'itemStyle' => array( // 'shadowBlur' => 30, // 'shadowOffsetX' => 0, // 'shadowColor' => 'rgba(0, 0, 0, 0.7)' // ) // ), ) ) ); // 3. encapsulate in config attribute and json encode $param['dataset']['source'] = $rows; $config = ["config" => $param]; $j_param = json_encode($config); header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // top 3 pola kelainan function mcu016($id, $mcu_kelainan_group_id, $mcu_kelainan_id) { $maxwidth = 40; function wrapText($text, $maxLength) { return wordwrap($text, $maxLength, "\n", true); // Memecah teks menjadi beberapa baris dengan panjang maksimum dan menggunakan newline sebagai pemisah } $rows_data = []; if ($mcu_kelainan_group_id != 0) { $sql_data = "SELECT distinct Mgm_HeaderT_OrderHeaderID, Mgm_HeaderM_SexCode as M_SexCode, instr(Mgm_HeaderT_OrderHeaderM_PatientAge,'tahun') as instr_thn, replace(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge,'(\\\\d+) tahun'),'tahun','') as xTahun, replace(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge,' (\\\\d+) bulan'),'bulan','') as xBulan, CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED) AS xUmurTahunNew, Mcu_KelainanGroupName AS kelainan_name from one_etl.mgm_header join one_etl.mgm_detail ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID AND Mgm_DetailIsActive = 'Y' AND Mgm_HeaderMgm_McuID = ? AND Mgm_DetailMcu_KelainanGroupID = ? AND Mgm_HeaderIsActive = 'Y' JOIN one_etl.mcu_kelainangroup ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID AND Mcu_KelainanGroupIsActive = 'Y' "; $qry_data = $this->db->query($sql_data, [$id, $mcu_kelainan_group_id]); $this->check_error($qry_data, 'get xData mcu'); $rows_data = $qry_data->result_array(); } else { $sql_data = "SELECT distinct Mgm_HeaderT_OrderHeaderID, Mgm_HeaderM_SexCode as M_SexCode, instr(Mgm_HeaderT_OrderHeaderM_PatientAge,'tahun') as instr_thn, replace(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge,'(\\\\d+) tahun'),'tahun','') as xTahun, replace(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge,' (\\\\d+) bulan'),'bulan','') as xBulan, CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED) AS xUmurTahunNew, Mcu_KelainanName AS kelainan_name from one_etl.mgm_header join one_etl.mgm_detail ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID AND Mgm_DetailIsActive = 'Y' AND Mgm_HeaderMgm_McuID = ? AND Mgm_DetailMcu_KelainanID = ? AND Mgm_HeaderIsActive = 'Y' JOIN one_etl.mcu_kelainan ON Mgm_DetailMcu_KelainanID = Mcu_KelainanID AND Mcu_KelainanIsActive = 'Y' "; $qry_data = $this->db->query($sql_data, [$id, $mcu_kelainan_id]); $this->check_error($qry_data, 'get xData mcu'); $rows_data = $qry_data->result_array(); } $kelainan_name = (count($rows_data) > 0 && isset($rows_data[0]['kelainan_name'])) ? $rows_data[0]['kelainan_name'] : 'Tidak Ada Nama Pola Kelainan'; $result = [ ["<30", 0, 0], ["30 - <40", 0, 0], ["40 - <50", 0, 0], [">= 50", 0, 0] ]; $age_groups = [ 'before_30' => [], 'between_30_40' => [], 'between_40_50' => [], 'after_50' => [] ]; $l_counts = [ 'before_30' => 0, 'between_30_40' => 0, 'between_40_50' => 0, 'after_50' => 0 ]; $p_counts = [ 'before_30' => 0, 'between_30_40' => 0, 'between_40_50' => 0, 'after_50' => 0 ]; $option = array( "title" => array( "text" => wrapText($kelainan_name, $maxwidth), "left" => 'center', "orient" => 'vertical' ), "legend" => array( "bottom" => 'bottom' ), "tooltip" => array(), "dataset" => array( "dimensions" => array('product', 'laki-laki', 'perempuan'), "source" => array() ), "grid" => array( "containLabel" => true ), "xAxis" => array( "type" => 'category' ), 'yAxis' => array('type' => 'value', 'name' => 'peserta', ), "series" => array( array( "type" => 'bar', "label" => array( "show" => true, "position" => 'top', 'formatter' => "{@[1]}", ), ), array( "type" => 'bar', "label" => array( "show" => true, "position" => 'top', 'formatter' => "{@[2]}", ), "itemStyle" => array( "color" => 'orange' ) ) ) ); foreach ($rows_data as $vx) { if ($vx['M_SexCode'] == 'L') { if ((int) $vx['xUmurTahunNew'] < 30) { $age_groups['before_30'][] = (int) $vx['xUmurTahunNew']; $l_counts['before_30']++; } elseif ((int) $vx['xUmurTahunNew'] >= 30 && (int) $vx['xUmurTahunNew'] < 40) { $age_groups['between_30_40'][] = (int) $vx['xUmurTahunNew']; $l_counts['between_30_40']++; } elseif ((int) $vx['xUmurTahunNew'] >= 40 && (int) $vx['xUmurTahunNew'] < 50) { $age_groups['between_40_50'][] = (int) $vx['xUmurTahunNew']; $l_counts['between_40_50']++; } elseif ((int) $vx['xUmurTahunNew'] >= 50) { $age_groups['after_50'][] = (int) $vx['xUmurTahunNew']; $l_counts['after_50']++; } } else { // M_SexCode == 'P' if ((int) $vx['xUmurTahunNew'] < 30) { $age_groups['before_30'][] = (int) $vx['xUmurTahunNew']; $p_counts['before_30']++; } elseif ((int) $vx['xUmurTahunNew'] >= 30 && (int) $vx['xUmurTahunNew'] < 40) { $age_groups['between_30_40'][] = (int) $vx['xUmurTahunNew']; $p_counts['between_30_40']++; } elseif ((int) $vx['xUmurTahunNew'] >= 40 && (int) $vx['xUmurTahunNew'] < 50) { $age_groups['between_40_50'][] = (int) $vx['xUmurTahunNew']; $p_counts['between_40_50']++; } elseif ((int) $vx['xUmurTahunNew'] >= 50) { $age_groups['after_50'][] = (int) $vx['xUmurTahunNew']; $p_counts['after_50']++; } } } $age_ranges = ['before_30', 'between_30_40', 'between_40_50', 'after_50']; for ($i = 0; $i < count($age_ranges); $i++) { $result[$i][1] = $l_counts[$age_ranges[$i]]; $result[$i][2] = $p_counts[$age_ranges[$i]]; } // print_r($result); $option['dataset']['source'] = $result; // 3. encapsulate in config attribute and json encode $config = ["config" => $option]; $j_param = json_encode($config); // echo $j_param; // exit; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } function mcu017($id, $mcu_kelainan_group_id, $mcu_kelainan_id) { $maxwidth = 40; function wrapText($text, $maxLength) { return wordwrap($text, $maxLength, "\n", true); } $rows_data = []; if ($mcu_kelainan_group_id != 0) { $sql_data = "SELECT DISTINCT Mgm_HeaderT_OrderHeaderID, IF(Mgm_HeaderM_PatientLocation = '' OR Mgm_HeaderM_PatientLocation IS NULL, 'Departement', Mgm_HeaderM_PatientLocation) AS location, COUNT(Mgm_HeaderT_OrderHeaderID) AS total, Mcu_KelainanGroupName AS kelainan_name FROM one_etl.mgm_header JOIN one_etl.mgm_detail ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID AND Mgm_DetailIsActive = 'Y' AND Mgm_HeaderMgm_McuID = ? AND Mgm_DetailMcu_KelainanGroupID = ? AND Mgm_HeaderIsActive = 'Y' JOIN one_etl.mcu_kelainangroup ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID AND Mcu_KelainanGroupIsActive = 'Y' GROUP BY location"; $qry_data = $this->db->query($sql_data, [$id, $mcu_kelainan_group_id]); $this->check_error($qry_data, 'get xData mcu'); $rows_data = $qry_data->result_array(); } else { $sql_data = "SELECT DISTINCT Mgm_HeaderT_OrderHeaderID, IF(Mgm_HeaderM_PatientLocation = '' OR Mgm_HeaderM_PatientLocation IS NULL, 'Departement', Mgm_HeaderM_PatientLocation) AS location, COUNT(Mgm_HeaderT_OrderHeaderID) AS total, Mcu_KelainanName AS kelainan_name FROM one_etl.mgm_header JOIN one_etl.mgm_detail ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID AND Mgm_DetailIsActive = 'Y' AND Mgm_HeaderMgm_McuID = ? AND Mgm_DetailMcu_KelainanID = ? AND Mgm_HeaderIsActive = 'Y' JOIN one_etl.mcu_kelainan ON Mgm_DetailMcu_KelainanID = Mcu_KelainanID AND Mcu_KelainanIsActive = 'Y' GROUP BY location"; $qry_data = $this->db->query($sql_data, [$id, $mcu_kelainan_id]); $this->check_error($qry_data, 'get xData mcu'); $rows_data = $qry_data->result_array(); } $kelainan_name = (count($rows_data) > 0 && isset($rows_data[0]['kelainan_name'])) ? $rows_data[0]['kelainan_name'] : 'Tidak Ada Nama Pola Kelainan'; $result = []; $location = []; $total = []; for ($i = 0; $i < count($rows_data); $i++) { $location[$i] = $rows_data[$i]['location']; $total[$i] = $rows_data[$i]['total']; } $option['dataset']['source'] = $result; $option = array( "title" => array( "text" => wrapText($kelainan_name, $maxwidth), "left" => 'center', "orient" => 'vertical' ), "legend" => array( "bottom" => 'bottom' ), "tooltip" => array(), "grid" => array( "containLabel" => true ), "xAxis" => array( "type" => 'category', "data" => $location ), 'yAxis' => array( 'type' => 'value', 'name' => 'peserta', ), "series" => array( array( "type" => 'bar', "label" => array( "show" => true, "position" => 'top', 'formatter' => "{@[1]}", ), 'data' => $total, ), ) ); $config = ["config" => $option]; $j_param = json_encode($config); header("Content-Type: image/png"); echo $this->post($this->url_renderer, $j_param); } function check_error($qry, $stage) { if (!$qry) { $errMsg = $stage . "
" . $this->db->error()["messge"]; print_r($errMsg); $this->chart_error($errMsg); } } function chart_error($msg) { $param = array( 'title' => array( 'show' => true, 'textStyle' => array( 'color' => 'grey', 'fontSize' => 20 ), 'text' => $msg, 'left' => 'center', 'top' => 'center' ), 'xAxis' => array( 'show' => false ), 'yAxis' => array( 'show' => false ), 'series' => array() ); header("Content-Type: image/png"); $config = ["config" => $param]; $j_param = json_encode($config); echo $this->post($this->url_renderer, $j_param); exit; } function post($url, $data) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, j120); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "Content-Length: " . strlen($data), ]); $result = curl_exec($ch); if (curl_errno($ch) > 0) { return [ "status" => "ERR", "message" => curl_error($ch), ]; } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpCode != 200) { return [ "status" => "ERR", "message" => "Http Response : $httpCode", ]; } return $result; } }