Files
BE_CPONE/application/controllers/tools/Mcu_chart_gan.php
2026-04-27 10:26:26 +07:00

2954 lines
113 KiB
PHP

<?php
class Mcu_chart_gan extends MY_Controller
{
var $url_renderer;
function __construct()
{
parent::__construct();
$this->url_renderer = "http://devkedungdoro.aplikasi.web.id:3000/chart";
}
function render($type, $id)
{
switch ($type) {
case "mcu001":
$this->mcu001($id);
break;
case "mcu002":
$this->mcu002($id);
break;
}
}
// --> MCU020 Konsumsi Alkohol
function mcu020($id)
{
// Data
$sql = "SELECT
Mcu_KelainanName as test,
COUNT( distinct T_OrderHeaderID) as total
FROM mcu_kelainan
JOIN mcu_summaryfisik ON Mcu_SummaryFisikMcu_KelainanID = Mcu_KelainanID AND
Mcu_KelainanIsActive = 'Y' AND Mcu_KelainanID IN (117,118,119)
LEFT JOIN t_kelainan_fisik ON T_KelainanFiskMcu_SummaryFisikID = Mcu_SummaryFisikID AND
T_KelainanFiskIsActive = 'Y'
LEFT JOIN so_resultentry ON T_KelainanFiskSo_ResultEntryID = So_ResultEntryID AND
So_ResultEntryIsActive = 'Y'
LEFT JOIN so_resultentry_fisik_umum ON So_ResultEntryFisikUmumSo_ResultEntryID = So_ResultEntryID AND
So_ResultEntryFisikUmumIsActive = 'Y'
LEFT JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderHeaderMgm_McuID = ?
group by Mcu_KelainanID";
$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");
}
$data = [];
if (count($rows) > 0) {
foreach ($rows as $key => $vx) {
$data[] = array(
"value" => $vx["total"],
"name" => $vx["test"] . ":" . $vx['total'] . " Peserta"
);
}
}
$param = array(
'title' => array(
'text' => 'Minum Alkohol',
'subtext' => '',
'left' => 'center'
),
'tooltip' => array(
'trigger' => 'item'
),
'legend' => array(
'top' => 'bottom',
'left' => 'center',
'orient' => 'vertical'
),
'series' => array(
array(
'label' => array(
'position' => 'inner',
'formatter' => '{d}%'
),
'name' => 'Access From',
'type' => 'pie',
'radius' => array('20%', '50%'),
'itemStyle' => array(
'borderRadius' => 10,
'borderColor' => '#fff',
'borderWidth' => 2
),
'data' => $data,
'emphasis' => array(
'itemStyle' => array(
'shadowBlur' => 10,
'shadowOffsetX' => 0,
'shadowColor' => 'rgba(0, 0, 0, 0.5)'
)
)
)
)
);
// Encapsulate in config attribute and JSON encode
$config = ["config" => $param];
$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);
}
// --> MCU021 Merokok
function mcu021($id)
{
// Data
$sql = "SELECT Mcu_KelainanName as test, COUNT( distinct T_OrderHeaderID) as total
FROM mcu_kelainan
JOIN mcu_summaryfisik ON Mcu_SummaryFisikMcu_KelainanID = Mcu_KelainanID AND
Mcu_KelainanIsActive = 'Y' AND Mcu_KelainanID IN (120,121,122)
LEFT JOIN t_kelainan_fisik ON T_KelainanFiskMcu_SummaryFisikID = Mcu_SummaryFisikID AND
T_KelainanFiskIsActive = 'Y'
LEFT JOIN so_resultentry ON T_KelainanFiskSo_ResultEntryID = So_ResultEntryID AND
So_ResultEntryIsActive = 'Y'
LEFT JOIN so_resultentry_fisik_umum ON So_ResultEntryFisikUmumSo_ResultEntryID = So_ResultEntryID AND
So_ResultEntryFisikUmumIsActive = 'Y'
LEFT JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderHeaderMgm_McuID = ?
group by Mcu_KelainanID";
$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");
}
$data = [];
if (count($rows) > 0) {
foreach ($rows as $key => $vx) {
$data[] = array(
"value" => $vx["total"],
"name" => $vx["test"] . ":" . $vx['total'] . " Peserta"
);
}
}
$param = array(
'title' => array(
'text' => 'Merokok',
'subtext' => '',
'left' => 'center'
),
'tooltip' => array(
'trigger' => 'item'
),
'legend' => array(
'top' => 'bottom',
'left' => 'center',
'orient' => 'vertical'
),
'series' => array(
array(
'label' => array(
'position' => 'inner',
'formatter' => '{d}%'
),
'name' => 'Access From',
'type' => 'pie',
'radius' => array('20%', '50%'),
'itemStyle' => array(
'borderRadius' => 10,
'borderColor' => '#fff',
'borderWidth' => 2
),
'data' => $data,
'emphasis' => array(
'itemStyle' => array(
'shadowBlur' => 10,
'shadowOffsetX' => 0,
'shadowColor' => 'rgba(0, 0, 0, 0.5)'
)
)
)
)
);
// Encapsulate in config attribute and JSON encode
$config = ["config" => $param];
$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 mcu001($id)
{
// Data
$sql = "SELECT
COUNT(distinct(T_OrderHeaderID)) as peserta,
COUNT( distinct(Mcu_PreregisterPatientsM_PatientID)) as total
FROM mcu_preregister_patients
LEFT JOIN t_orderheader ON Mcu_PreregisterPatientsT_OrderHeaderID = T_OrderHeaderID AND
T_OrderHeaderIsActive = 'Y'
WHERE
Mcu_PreregisterPatientsMgm_McuID = ? AND
Mcu_PreregisterPatientsIsActive = 'Y'";
$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(
'title' => array(
'text' => 'Peserta MCU',
'subtext' => 'Total Peserta ' . $total,
'left' => 'center'
),
'tooltip' => array(
'trigger' => 'item'
),
'legend' => array(
'top' => 'bottom',
'left' => 'center',
'orient' => 'vertical'
),
'series' => array(
array(
'label' => array(
'position' => 'inner',
'formatter' => '{d}%'
),
'name' => 'Access From',
'type' => 'pie',
'radius' => array('20%', '50%'),
'itemStyle' => array(
'borderRadius' => 10,
'borderColor' => '#fff',
'borderWidth' => 2
),
'data' => array(
array("value" => $peserta, "name" => "Sudah MCU : $peserta Peserta"),
array("value" => $belum_mcu, "name" => "Belum MCU : $belum_mcu Peserta")
),
'emphasis' => array(
'itemStyle' => array(
'shadowBlur' => 10,
'shadowOffsetX' => 0,
'shadowColor' => 'rgba(0, 0, 0, 0.5)'
)
)
)
)
);
// 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);
}
function mcu002($id)
{
// Data
$sql = "SELECT IF(M_PatientGender = 'male','Laki-laki','Perempuan') as M_PatientGender,
COUNT(T_OrderHeaderID) as Jumlah
FROM t_orderheader
LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
WHERE T_OrderHeaderMgm_McuID = ? AND T_OrderHeaderIsActive = 'Y'
GROUP BY M_PatientGender";
$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");
}
$data = [];
if (count($rows) > 0) {
foreach ($rows as $key => $vx) {
$data[] = array(
"value" => $vx["Jumlah"],
"name" => $vx["M_PatientGender"] . ":" . $vx['Jumlah'] . " Peserta"
);
}
}
$param = array(
'title' => array(
'text' => 'Peserta MCU',
'subtext' => 'berdasarkan jenis kelamin',
'left' => 'center'
),
'tooltip' => array(
'trigger' => 'item'
),
'legend' => array(
'top' => 'bottom',
'left' => 'center',
'orient' => 'vertical'
),
'series' => array(
array(
'label' => array(
'position' => 'inner',
'formatter' => '{d}%'
),
'name' => 'Access From',
'type' => 'pie',
'radius' => array('20%', '50%'),
'itemStyle' => array(
'borderRadius' => 10,
'borderColor' => '#fff',
'borderWidth' => 2
),
'data' => $data,
'emphasis' => array(
'itemStyle' => array(
'shadowBlur' => 10,
'shadowOffsetX' => 0,
'shadowColor' => 'rgba(0, 0, 0, 0.5)'
)
)
)
)
);
// Encapsulate in config attribute and JSON encode
$config = ["config" => $param];
$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 mcu003($id)
{
// Data
$sql = "SELECT
CASE
WHEN LEFT(T_OrderHeaderM_PatientAge,2) < '30' THEN '1. < 30 tahun'
WHEN LEFT(T_OrderHeaderM_PatientAge,2) >= '30' AND left(T_OrderHeaderM_PatientAge,2) < '40' THEN '2. 30 -< 40 tahun'
WHEN LEFT(T_OrderHeaderM_PatientAge,2) >= '40' AND left(T_OrderHeaderM_PatientAge,2) < '50' THEN '3. 40 - < 50 tahun'
WHEN LEFT(T_OrderHeaderM_PatientAge,2) >= '50' THEN '4. > 50 tahun' ELSE ''
END AS umur,
COUNT(T_OrderHeaderID) as total
FROM t_orderheader
LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
WHERE t_orderheaderMgm_McuID = ? AND T_OrderHeaderIsActive = 'Y'
GROUP BY
CASE
WHEN LEFT(T_OrderHeaderM_PatientAge,2) < '30' THEN '1. < 30 tahun'
WHEN LEFT(T_OrderHeaderM_PatientAge,2) >= '30' AND left(T_OrderHeaderM_PatientAge,2) < '40' THEN '2. 30 -< 40 tahun'
WHEN LEFT(T_OrderHeaderM_PatientAge,2) >= '40' AND left(T_OrderHeaderM_PatientAge,2) < '50' THEN '3. 40 - < 50 tahun'
WHEN LEFT(T_OrderHeaderM_PatientAge,2) >= '50' THEN '4. > 50 tahun' ELSE ''
END
ORDER BY umur";
$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");
}
$data = [];
if (count($rows) > 0) {
foreach ($rows as $key => $vx) {
$data[] = array(
"value" => $vx["total"],
"name" => $vx["umur"] . ":" . $vx['total'] . " Peserta"
);
}
}
$param = array(
'title' => array(
'text' => 'Peserta MCU',
'subtext' => 'berdasarkan umur',
'left' => 'center'
),
'tooltip' => array(
'trigger' => 'item'
),
'legend' => array(
'top' => 'bottom',
'left' => 'center',
'orient' => 'vertical'
),
'series' => array(
array(
'label' => array(
'position' => 'inner',
'formatter' => '{d}%'
),
'name' => 'Access From',
'type' => 'pie',
'radius' => array('20%', '50%'),
'itemStyle' => array(
'borderRadius' => 10,
'borderColor' => '#fff',
'borderWidth' => 2
),
'data' => $data,
'emphasis' => array(
'itemStyle' => array(
'shadowBlur' => 10,
'shadowOffsetX' => 0,
'shadowColor' => 'rgba(0, 0, 0, 0.5)'
)
)
)
)
);
// Encapsulate in config attribute and JSON encode
$config = ["config" => $param];
$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 mcu017($id)
{
// Data
$sql = "SELECT Mcu_KelainanName as test,
Mcu_KelainanClasification,
count(distinct orderkel.T_OrderHeaderID) as total
FROM mcu_kelainan
JOIN mcu_summaryfisik ON Mcu_SummaryFisikMcu_KelainanID = Mcu_KelainanID AND
Mcu_SummaryFisikIsActive = 'Y'
LEFT JOIN t_kelainan_fisik ON T_KelainanFiskMcu_SummaryFisikID = Mcu_SummaryFisikID AND
T_KelainanFiskIsActive= 'Y'
LEFT JOIN t_orderheader orderkel ON T_KelainanFiskT_OrderHeaderID = orderkel.T_OrderHeaderID AND
orderkel.T_OrderHeaderIsActive = 'Y' AND orderkel.T_OrderHeaderMgm_McuID = ?
WHERE
Mcu_KelainanIsActive = 'Y' AND Mcu_KelainanClasification = 'asia_pacific'
group by Mcu_KelainanID
UNION
SELECT 'Normal' as test,
'asia_pacific' as Mcu_KelainanClasification,
ifnull(count(distinct T_OrderHeaderID) - summary_total_kelainan_bmi(?), 0) as total
FROM t_orderheader
WHERE
T_OrderHeaderMgm_McuID = ? AND T_OrderHeaderIsActive = 'Y'
group by T_OrderHeaderMgm_McuID ";
$qry = $this->db->query($sql, [$id,$id,$id]);
$this->check_error($qry, "get total bmi");
$rows = $qry->result_array();
if (count($rows) == 0) {
$this->chart_error("No data found");
}
$data = [];
if (count($rows) > 0) {
foreach ($rows as $key => $vx) {
$data[] = array(
"value" => $vx["total"],
"name" => $vx["test"] . ":" . $vx['total'] . " Peserta"
);
}
}
$param = array(
'title' => array(
'text' => 'Status Index Masa Tubuh(BMI)',
'subtext' => '',
'left' => 'center'
),
'tooltip' => array(
'trigger' => 'item'
),
'legend' => array(
'top' => 'center',
'right' => '15%',
'orient' => 'vertical'
),
'series' => array(
array(
'label' => array(
'position' => 'inner',
'formatter' => '{d}%'
),
'left' => -150,
'name' => 'Access From',
'type' => 'pie',
'radius' => array('20%', '50%'),
'itemStyle' => array(
'borderRadius' => 10,
'borderColor' => '#fff',
'borderWidth' => 2
),
'data' => $data,
'emphasis' => array(
'itemStyle' => array(
'shadowBlur' => 10,
'shadowOffsetX' => 0,
'shadowColor' => 'rgba(0, 0, 0, 0.5)'
)
)
)
)
);
// Encapsulate in config attribute and JSON encode
$config = ["config" => $param];
$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 mcu018($id)
{
// Data
$sql = "SELECT Mcu_KelainanName as test,
Mcu_KelainanClasification,
count(distinct orderkel.T_OrderHeaderID) as total
FROM mcu_kelainan
JOIN mcu_summaryfisik ON Mcu_SummaryFisikMcu_KelainanID = Mcu_KelainanID AND
Mcu_SummaryFisikIsActive = 'Y'
LEFT JOIN t_kelainan_fisik ON T_KelainanFiskMcu_SummaryFisikID = Mcu_SummaryFisikID AND
T_KelainanFiskIsActive= 'Y'
LEFT JOIN t_orderheader orderkel ON T_KelainanFiskT_OrderHeaderID = orderkel.T_OrderHeaderID AND
orderkel.T_OrderHeaderIsActive = 'Y' AND orderkel.T_OrderHeaderMgm_McuID = ?
WHERE
Mcu_KelainanIsActive = 'Y' AND Mcu_KelainanClasification = 'JNC-VII'
group by Mcu_KelainanID
UNION
SELECT 'Normal' as test,
'JNC-VII' as Mcu_KelainanClasification,
IFNULL(COUNT(T_OrderHeaderID) - summary_total_kelainan_hipertensi(?), 0) as total
FROM t_orderheader
WHERE
T_OrderHeaderMgm_McuID = ? AND T_OrderHeaderIsActive = 'Y'
group by T_OrderHeaderMgm_McuID ";
$qry = $this->db->query($sql, [$id,$id,$id]);
$this->check_error($qry, "get total bmi");
$rows = $qry->result_array();
if (count($rows) == 0) {
$this->chart_error("No data found");
}
$data = [];
if (count($rows) > 0) {
foreach ($rows as $key => $vx) {
$data[] = array(
"value" => $vx["total"],
"name" => $vx["test"] . ":" . $vx['total'] . " Peserta"
);
}
}
$param = array(
'title' => array(
'text' => 'Kriteria Hipertensi',
'subtext' => '',
'left' => 'center'
),
'tooltip' => array(
'trigger' => 'item'
),
'legend' => array(
'top' => 'center',
'right' => '12.5%',
'orient' => 'vertical'
),
'series' => array(
array(
'label' => array(
'position' => 'inner',
'formatter' => '{d}%'
),
'left' => -200,
'name' => 'Access From',
'type' => 'pie',
'radius' => array('20%', '50%'),
'itemStyle' => array(
'borderRadius' => 10,
'borderColor' => '#fff',
'borderWidth' => 2
),
'data' => $data,
'emphasis' => array(
'itemStyle' => array(
'shadowBlur' => 10,
'shadowOffsetX' => 0,
'shadowColor' => 'rgba(0, 0, 0, 0.5)'
)
)
)
)
);
// Encapsulate in config attribute and JSON encode
$config = ["config" => $param];
$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 mcu019($id)
{
// Data
$sql = "SELECT Mcu_KelainanName as test,
count(distinct orderkel.T_OrderHeaderID) as total
FROM mcu_kelainan
JOIN mcu_summaryfisik ON Mcu_SummaryFisikMcu_KelainanID = Mcu_KelainanID AND
Mcu_SummaryFisikIsActive = 'Y'
LEFT JOIN t_kelainan_fisik ON T_KelainanFiskMcu_SummaryFisikID = Mcu_SummaryFisikID AND
T_KelainanFiskIsActive= 'Y'
LEFT JOIN t_orderheader orderkel ON T_KelainanFiskT_OrderHeaderID = orderkel.T_OrderHeaderID AND
orderkel.T_OrderHeaderIsActive = 'Y' AND orderkel.T_OrderHeaderMgm_McuID = ?
WHERE
Mcu_KelainanIsActive = 'Y' AND Mcu_KelainanID IN (24,25)
group by Mcu_KelainanID
UNION
SELECT 'Normal' as test,
IFNULL(count(distinct T_OrderHeaderID) - summary_total_kelainan_visus(?), 0) as total
FROM t_orderheader
WHERE
T_OrderHeaderMgm_McuID = ? AND T_OrderHeaderIsActive = 'Y'
group by T_OrderHeaderMgm_McuID ";
$qry = $this->db->query($sql, [$id,$id,$id]);
$this->check_error($qry, "get total bmi");
$rows = $qry->result_array();
if (count($rows) == 0) {
$this->chart_error("No data found");
}
$data = [];
if (count($rows) > 0) {
foreach ($rows as $key => $vx) {
$data[] = array(
"value" => $vx["total"],
"name" => $vx["test"] . ":" . $vx['total'] . " Peserta"
);
}
}
$param = array(
'title' => array(
'text' => 'Refraksi',
'subtext' => '',
'left' => 'center'
),
'tooltip' => array(
'trigger' => 'item'
),
'legend' => array(
'bottom' => '5%',
'left' => 'center',
'orient' => 'vertical'
),
'series' => array(
array(
'label' => array(
'position' => 'inner',
'formatter' => '{d}%'
),
'top' => -50,
'name' => 'Access From',
'type' => 'pie',
'radius' => array('20%', '50%'),
'itemStyle' => array(
'borderRadius' => 10,
'borderColor' => '#fff',
'borderWidth' => 2
),
'data' => $data,
'emphasis' => array(
'itemStyle' => array(
'shadowBlur' => 10,
'shadowOffsetX' => 0,
'shadowColor' => 'rgba(0, 0, 0, 0.5)'
)
)
)
)
);
// Encapsulate in config attribute and JSON encode
$config = ["config" => $param];
$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 mcu022($id)
{
// Data
$sql = "SELECT Mcu_KelainanName as test, COUNT( distinct T_OrderHeaderID) as total
FROM mcu_kelainan
JOIN mcu_summaryfisik ON Mcu_SummaryFisikMcu_KelainanID = Mcu_KelainanID AND
Mcu_KelainanIsActive = 'Y' AND Mcu_KelainanID IN (123,124)
LEFT JOIN t_kelainan_fisik ON T_KelainanFiskMcu_SummaryFisikID = Mcu_SummaryFisikID AND
T_KelainanFiskIsActive = 'Y'
LEFT JOIN so_resultentry ON T_KelainanFiskSo_ResultEntryID = So_ResultEntryID AND
So_ResultEntryIsActive = 'Y'
LEFT JOIN so_resultentry_fisik_umum ON So_ResultEntryFisikUmumSo_ResultEntryID = So_ResultEntryID AND
So_ResultEntryFisikUmumIsActive = 'Y'
LEFT JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderHeaderMgm_McuID = ?
group by Mcu_KelainanID";
$qry = $this->db->query($sql, [$id]);
$this->check_error($qry, "get total bmi");
$rows = $qry->result_array();
if (count($rows) == 0) {
$this->chart_error("No data found");
}
$data = [];
if (count($rows) > 0) {
foreach ($rows as $key => $vx) {
$data[] = array(
"value" => $vx["total"],
"name" => $vx["test"] . ":" . $vx['total'] . " Peserta"
);
}
}
$param = array(
'title' => array(
'text' => 'Olahraga',
'subtext' => '',
'left' => 'center'
),
'tooltip' => array(
'trigger' => 'item'
),
'legend' => array(
'bottom' => '5%',
'left' => 'center',
'orient' => 'vertical'
),
'series' => array(
array(
'label' => array(
'position' => 'inner',
'formatter' => '{d}%'
),
'top' => -50,
'name' => 'Access From',
'type' => 'pie',
'radius' => array('20%', '50%'),
'itemStyle' => array(
'borderRadius' => 10,
'borderColor' => '#fff',
'borderWidth' => 2
),
'data' => $data,
'emphasis' => array(
'itemStyle' => array(
'shadowBlur' => 10,
'shadowOffsetX' => 0,
'shadowColor' => 'rgba(0, 0, 0, 0.5)'
)
)
)
)
);
// Encapsulate in config attribute and JSON encode
$config = ["config" => $param];
$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 mcu005V2($id)
{
// 1. prepare the data using sql
$sql = "SELECT COUNT(*) AS total, Mcu_RiwayatCode as code,
Mcu_RiwayatName AS test, Mcu_RiwayatSegmentName as location
FROM one_etl.mgm_header
JOIN one_etl.mgm_riwayat ON Mgm_RiwayatMgm_HeaderID = Mgm_HeaderID
AND Mgm_RiwayatIsActive = 'Y'
AND Mgm_HeaderIsActive = 'Y'
AND Mgm_HeaderMgm_McuID = ?
JOIN one_etl.mcu_riwayat ON Mgm_RiwayatMcu_RiwayatID = Mcu_RiwayatID
AND Mcu_RiwayatIsActive = 'Y'
AND Mcu_RiwayatMcu_RiwayatGroupID = 6
GROUP BY Mcu_RiwayatName, Mcu_RiwayatSegmentName
";
$qry_total_data = $this->db->query($sql, [$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");
}
// $rows = array(
//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'),
'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,
'label' => array(
'show' => true,
'position' => 'top',
'distance' => 25,
'fontSize' => 12, // Menyesuaikan ukuran font
'formatter' => '', // Menggunakan formatter untuk memisahkan baris
'rich' => array('name' => array()),
),
'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);
}
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
WHERE
Mgm_McuID = ?
)
SELECT
COUNT(DISTINCT Mgm_HeaderT_OrderHeaderID) AS total,
'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,
'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,
'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";
$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'),
'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,
'label' => array(
'show' => true,
'position' => 'top',
'distance' => 25,
'fontSize' => 12, // Menyesuaikan ukuran font
'formatter' => '', // Menggunakan formatter untuk memisahkan baris
'rich' => array('name' => array()),
),
'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,
Mcu_KelainanName 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_KelainanClasification = 'asia_pacific'
AND Mcu_KelainanIsActive = 'Y'
GROUP BY Mcu_KelainanName";
$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");
}
$sql_normal = "SELECT
COUNT(DISTINCT a.Mgm_HeaderT_OrderHeaderID) AS xTotalNormal,
'Normal' AS test,
IFNULL(a.Mgm_HeaderM_PatientLocation, '-') AS location
FROM one_etl.mgm_header a
LEFT JOIN
(SELECT DISTINCT Mgm_HeaderT_OrderHeaderID
FROM one_etl.mgm_header
JOIN one_etl.mgm_detail ON Mgm_DetailMgm_HeaderID = Mgm_HeaderID
JOIN one_etl.mcu_kelainan ON Mgm_DetailMcu_KelainanID = Mcu_KelainanID
WHERE Mgm_HeaderIsActive = 'Y'
AND Mgm_HeaderMgm_McuID = ?
AND Mgm_DetailIsActive = 'Y'
AND Mgm_DetailMcu_KelainanGroupID = 1
AND Mcu_KelainanClasification = 'asia_pacific'
AND Mcu_KelainanIsActive = 'Y') b
ON a.Mgm_HeaderT_OrderHeaderID = b.Mgm_HeaderT_OrderHeaderID
WHERE a.Mgm_HeaderIsActive = 'Y'
AND a.Mgm_HeaderIsNormal = 'Y'
AND a.Mgm_HeaderMgm_McuID = ?
AND b.Mgm_HeaderT_OrderHeaderID IS NULL
GROUP BY a.Mgm_HeaderM_PatientLocation";
$qry_total_normal = $this->db->query($sql_normal, [$id, $id]);
$this->check_error($qry_total_normal, "get total item");
$rows_normal = $qry_total_normal->result_array();
if (count($rows_normal) == 0) {
$this->chart_error("No data found");
}
foreach ($rows_normal as $normal) {
$rows[] = [
'xTotalPerItem' => $normal['xTotalNormal'],
'test' => $normal['test'],
'location' => $normal['location']
// Menambahkan setiap baris hasil normal ke dalam array $rows
];
}
$maxAmount += $rows_total[0]['xTotal'] + $rows_normal[0]['xTotalNormal'];
// 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(
'label' => array(
'formatter' => '{b} ' . chr(10) . '{d}%'
),
'name' => 'Access From',
'type' => 'pie',
'radius' => '50%',
'labelLayout' => array(
'hideOverlap' => false, // Mengatur agar label yang bertabrakan disembunyikan
'color' => 'black',
),
'itemStyle' => array(
'borderRadius' => 10,
'borderColor' => '#fff',
'borderWidth' => 2
),
'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,
'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 mcu007V2($id)
{
$sql = "SELECT COUNT(*) AS total, Mcu_KelainanName as test,
ifnull(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_HeaderMgm_McuID = ?
AND Mgm_DetailIsActive = 'Y'
AND Mgm_DetailMcu_KelainanGroupID = 1
JOIN one_etl.mcu_kelainan ON Mgm_DetailMcu_KelainanID = Mcu_KelainanID
AND Mcu_KelainanClasification = 'asia_pacific'
AND Mcu_KelainanIsActive = 'Y'
GROUP BY Mcu_KelainanName, Mgm_HeaderM_PatientLocation
";
$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");
}
$sql_normal = "SELECT COUNT(distinct Mgm_HeaderT_OrderHeaderID) AS total, 'Normal' as test,
ifnull(Mgm_HeaderM_PatientLocation, '-') as location
from one_etl.mgm_header
WHERE Mgm_HeaderIsActive = 'Y'
AND Mgm_HeaderMgm_McuID = ?
AND Mgm_HeaderIsNormal = 'Y'
GROUP BY Mgm_HeaderM_PatientLocation
";
$qry_normal = $this->db->query($sql_normal, [$id]);
$this->check_error($qry_normal, "get total mcu");
$rows_normal = $qry_normal->result_array();
if (count($rows_normal) == 0) {
$this->chart_error("No data found");
}
// Menggabungkan hasil query normal ke dalam array $rows
foreach ($rows_normal as $normal) {
$rows[] = $normal; // Menambahkan setiap baris hasil normal ke dalam array $rows
}
// 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(
//tidak menggunakan title
// 'text' => '',
),
'dataset' => array(
'source' => array(
array('score', 'amount', 'product'),
),
),
//menampilkan nama bagian tiap-tiap chart
'legend' => array(
'data' => $uniqueTests
),
'grid' => array('containLabel' => true),
'yAxis' => array('type' => 'value'),
'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(
// 'overlap' => false,
'hideOverlap' => false // Mengatur agar label yang bertabrakan disembunyikan
),
'visualMap' => array(
'orient' => 'horizontal',
'show' => false,
'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,
'label' => array(
'show' => true,
'position' => 'top',
'distance' => 25,
'fontSize' => 12, // Menyesuaikan ukuran font
'formatter' => '{c}', // Menggunakan formatter untuk memisahkan baris
'rich' => array('name' => array())
),
'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);
}
function mcu007($id)
{
$sql = "SELECT
COUNT(DISTINCT Mgm_HeaderT_OrderHeaderID) AS total,
Mcu_KelainanName AS test,
IFNULL(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_KelainanClasification = 'asia_pacific'
AND Mcu_KelainanIsActive = 'Y'
GROUP BY Mcu_KelainanName, Mgm_HeaderM_PatientLocation
";
$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");
}
$sql_normal = "SELECT
COUNT(DISTINCT a.Mgm_HeaderT_OrderHeaderID) AS total,
'Normal' AS test,
IFNULL(a.Mgm_HeaderM_PatientLocation, '-') AS location
FROM one_etl.mgm_header a
LEFT JOIN
(SELECT DISTINCT Mgm_HeaderT_OrderHeaderID
FROM one_etl.mgm_header
JOIN one_etl.mgm_detail ON Mgm_DetailMgm_HeaderID = Mgm_HeaderID
JOIN one_etl.mcu_kelainan ON Mgm_DetailMcu_KelainanID = Mcu_KelainanID
WHERE Mgm_HeaderIsActive = 'Y'
AND Mgm_HeaderMgm_McuID = ?
AND Mgm_DetailIsActive = 'Y'
AND Mgm_DetailMcu_KelainanGroupID = 1
AND Mcu_KelainanClasification = 'asia_pacific'
AND Mcu_KelainanIsActive = 'Y') b
ON a.Mgm_HeaderT_OrderHeaderID = b.Mgm_HeaderT_OrderHeaderID
WHERE a.Mgm_HeaderIsActive = 'Y'
AND a.Mgm_HeaderIsNormal = 'Y'
AND a.Mgm_HeaderMgm_McuID = ?
AND b.Mgm_HeaderT_OrderHeaderID IS NULL
GROUP BY a.Mgm_HeaderM_PatientLocation";
$qry_normal = $this->db->query($sql_normal, [$id, $id]);
$this->check_error($qry_normal, "get total mcu");
$rows_normal = $qry_normal->result_array();
if (count($rows_normal) == 0) {
$this->chart_error("No data found");
}
// Menggabungkan hasil query normal ke dalam array $rows
foreach ($rows_normal as $normal) {
$rows[] = $normal; // Menambahkan setiap baris hasil normal ke dalam array $rows
}
// 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(
//tidak menggunakan title
// 'text' => '',
),
'dataset' => array(
'source' => array(
array('score', 'amount', 'product'),
),
),
//menampilkan nama bagian tiap-tiap chart
'legend' => array(
'data' => $uniqueTests
),
'grid' => array('containLabel' => true),
'yAxis' => array('type' => 'value'),
'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(
// 'overlap' => false,
'hideOverlap' => false // Mengatur agar label yang bertabrakan disembunyikan
),
'visualMap' => array(
'orient' => 'horizontal',
'show' => false,
'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,
'label' => array(
'show' => true,
'position' => 'top',
'distance' => 25,
'fontSize' => 12, // Menyesuaikan ukuran font
'formatter' => '{c}', // Menggunakan formatter untuk memisahkan baris
'rich' => array('name' => array())
),
'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);
}
// 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
),
'xAxis' => array(
'name' => 'amount(%)',
'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]}%"
),
'type' => 'bar',
'encode' => array(
'x' => 'percentage',
'y' => 'product'
),
"datasetIndex" => 1
)
)
);
// total order yang non lab saja
$sql_total_all = "SELECT COUNT(*) as xTotalAll, Mgm_HeaderMgm_McuID
FROM one_etl.mgm_header
WHERE Mgm_HeaderIsActive = 'Y'
AND Mgm_HeaderType = 'L'
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(*) as xTotalPerItem,
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'
WHERE Mgm_HeaderType = 'L'
AND Mgm_HeaderMgm_McuID = ?
GROUP BY Mgm_DetailMcu_KelainanGroupID
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-Site 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',
'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,
'formatter' => "{@[3]}%",
)
)
);
// 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
// JOIN one_etl.mgm_detail
// ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID
// AND Mgm_DetailIsActive = 'Y'
// AND Mgm_HeaderMgm_McuID = ?
// AND Mgm_DetailMcu_KelainanGroupID = 17
// AND Mgm_HeaderIsActive = 'Y'
// ";
$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(M_PatientLocation,'-') as location,
// IFNULL(Mcu_KelainanGroupName, '-') as test,
// COUNT(*) as xTotalPerItem
// FROM
// one_etl.mgm_header
// JOIN one.t_orderheader
// ON Mgm_HeaderT_OrderHeaderID = T_OrderHeaderID
// AND T_OrderHeaderIsActive = 'Y'
// AND Mgm_HeaderIsActive = 'Y'
// AND Mgm_HeaderMgm_McuID = ?
// JOIN one_etl.mgm_detail
// ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID
// AND Mgm_DetailIsActive = 'Y'
// AND Mgm_DetailMcu_KelainanGroupID = 17
// JOIN one_etl.mcu_kelainangroup
// ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID
// JOIN one.m_patient
// ON T_OrderHeaderM_PatientID = M_PatientID
// AND M_PatientIsActive ='Y'
// GROUP BY M_PatientLocation";
$sql_data = "SELECT
IFNULL(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 = 17
JOIN one_etl.mcu_kelainangroup
ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID
WHERE Mgm_HeaderMgm_McuID = ?
GROUP BY Mgm_HeaderM_PatientLocation";
$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', ),
"series" => array(
array(
"type" => 'bar',
"label" => array(
"show" => true,
"position" => 'top'
),
),
array(
"type" => 'bar',
"label" => array(
"show" => true,
"position" => 'top'
),
"itemStyle" => array(
"color" => 'orange'
)
)
)
);
// $sql_data = "SELECT
// distinct T_OrderHeaderM_PatientAge,
// T_OrderHeaderID,
// M_SexCode,
// instr(T_OrderHeaderM_PatientAge,'tahun') as instr_thn,
// replace(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge,'(\\\\d+) tahun'),'tahun','') as xTahun,
// replace(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge,' (\\\\d+) bulan'),'bulan','') as xBulan,
// CASE
// WHEN CAST(REPLACE(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge, ' (\\\\d+) bulan'), 'bulan', '') AS UNSIGNED) > 6
// THEN CAST(REPLACE(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED) + 1
// ELSE CAST(REPLACE(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED)
// END AS xUmurTahunNew
// from t_orderheader
// join m_patient
// ON T_OrderHeaderM_PatientID = M_PatientID
// AND T_OrderHeaderIsActive = 'Y'
// AND M_PatientIsActive = 'Y'
// join m_sex
// ON M_PatientM_SexID = M_SexID
// AND M_SexIsActive = 'Y'
// join one_etl.mgm_header
// ON T_OrderHeaderID = Mgm_HeaderT_OrderHeaderID
// AND Mgm_HeaderIsActive = 'Y'
// join one_etl.mgm_detail
// ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID
// AND Mgm_DetailIsActive = 'Y'
// WHERE Mgm_DetailMcu_KelainanGroupID = 17
// AND Mgm_HeaderMgm_McuID = ?
// -- group by xUmurTahunNew
// ";
$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,
CASE
WHEN CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, ' (\\\\d+) bulan'), 'bulan', '') AS UNSIGNED) > 6
THEN CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED) + 1
ELSE CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED)
END AS xUmurTahunNew
from one_etl.mgm_header
join one_etl.mgm_detail
ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID
AND Mgm_DetailIsActive = 'Y'
WHERE 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();
if (count($rows_data) == 0) {
$this->chart_error('No data found');
} else {
$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-Site 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',
'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,
'formatter' => "{@[3]}%",
)
)
);
// 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'
";
// $sql_total_all = "SELECT COUNT(*) as xTotalAll, Mgm_HeaderMgm_McuID
// 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 = 2
// 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(M_PatientLocation,'-') as location,
// IFNULL(Mcu_KelainanGroupName, '-') as test,
// COUNT(*) as xTotalPerItem
// FROM
// one_etl.mgm_header
// JOIN one.t_orderheader
// ON Mgm_HeaderT_OrderHeaderID = T_OrderHeaderID
// AND T_OrderHeaderIsActive = 'Y'
// AND Mgm_HeaderIsActive = 'Y'
// AND Mgm_HeaderMgm_McuID = ?
// JOIN one_etl.mgm_detail
// ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID
// AND Mgm_DetailIsActive = 'Y'
// AND Mgm_DetailMcu_KelainanGroupID = 2
// JOIN one_etl.mcu_kelainangroup
// ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID
// JOIN one.m_patient
// ON T_OrderHeaderM_PatientID = M_PatientID
// AND M_PatientIsActive ='Y'
// GROUP BY M_PatientLocation";
$sql_data = "SELECT
IFNULL(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
JOIN one_etl.mcu_kelainangroup
ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID
WHERE Mgm_HeaderMgm_McuID = ?
GROUP BY Mgm_HeaderM_PatientLocation";
$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', ),
"series" => array(
array(
"type" => 'bar',
"label" => array(
"show" => true,
"position" => 'top'
),
),
array(
"type" => 'bar',
"label" => array(
"show" => true,
"position" => 'top'
),
"itemStyle" => array(
"color" => 'orange'
)
)
)
);
// $sql_data = "SELECT
// distinct T_OrderHeaderM_PatientAge,
// T_OrderHeaderID,
// M_SexCode,
// instr(T_OrderHeaderM_PatientAge,'tahun') as instr_thn,
// replace(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge,'(\\\\d+) tahun'),'tahun','') as xTahun,
// replace(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge,' (\\\\d+) bulan'),'bulan','') as xBulan,
// CASE
// WHEN CAST(REPLACE(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge, ' (\\\\d+) bulan'), 'bulan', '') AS UNSIGNED) > 6
// THEN CAST(REPLACE(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED) + 1
// ELSE CAST(REPLACE(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED)
// END AS xUmurTahunNew
// from t_orderheader
// join m_patient
// ON T_OrderHeaderM_PatientID = M_PatientID
// AND T_OrderHeaderIsActive = 'Y'
// AND M_PatientIsActive = 'Y'
// join m_sex
// ON M_PatientM_SexID = M_SexID
// AND M_SexIsActive = 'Y'
// join one_etl.mgm_header
// ON T_OrderHeaderID = Mgm_HeaderT_OrderHeaderID
// AND Mgm_HeaderIsActive = 'Y'
// join one_etl.mgm_detail
// ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID
// AND Mgm_DetailIsActive = 'Y'
// WHERE Mgm_DetailMcu_KelainanGroupID = 2
// AND Mgm_HeaderMgm_McuID = ?
// -- group by xUmurTahunNew
// ";
$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,
CASE
WHEN CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, ' (\\\\d+) bulan'), 'bulan', '') AS UNSIGNED) > 6
THEN CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED) + 1
ELSE CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED)
END AS xUmurTahunNew
from one_etl.mgm_header
join one_etl.mgm_detail
ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID
AND Mgm_DetailIsActive = 'Y'
WHERE Mgm_DetailMcu_KelainanGroupID = 2
AND Mgm_HeaderMgm_McuID = ?
AND Mgm_HeaderIsActive = 'Y'";
// $sql_data = "SELECT
// distinct Mgm_HeaderT_OrderHeaderM_PatientAge,
// 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,
// CASE
// WHEN CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, ' (\\\\d+) bulan'), 'bulan', '') AS UNSIGNED) > 6
// THEN CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED) + 1
// ELSE CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED)
// END AS xUmurTahunNew
// from one_etl.mgm_header
// join one_etl.mgm_detail
// ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID
// AND Mgm_DetailIsActive = 'Y'
// WHERE 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();
if (count($rows_data) == 0) {
$this->chart_error('No data found');
} else {
$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-Site 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',
'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,
'formatter' => "{@[3]}%",
)
)
);
// 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(M_PatientLocation,'-') as location,
// IFNULL(Mcu_KelainanGroupName, '-') as test,
// COUNT(*) as xTotalPerItem
// FROM
// one_etl.mgm_header
// JOIN one.t_orderheader
// ON Mgm_HeaderT_OrderHeaderID = T_OrderHeaderID
// AND T_OrderHeaderIsActive = 'Y'
// AND Mgm_HeaderIsActive = 'Y'
// AND Mgm_HeaderMgm_McuID = ?
// JOIN one_etl.mgm_detail
// ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID
// AND Mgm_DetailIsActive = 'Y'
// AND Mgm_DetailMcu_KelainanGroupID = 3
// JOIN one_etl.mcu_kelainangroup
// ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID
// JOIN one.m_patient
// ON T_OrderHeaderM_PatientID = M_PatientID
// AND M_PatientIsActive ='Y'
// GROUP BY M_PatientLocation";
$sql_data = "SELECT
IFNULL(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
JOIN one_etl.mcu_kelainangroup
ON Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID
WHERE Mgm_HeaderMgm_McuID = ?
GROUP BY Mgm_HeaderM_PatientLocation";
$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 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', ),
"series" => array(
array(
"type" => 'bar',
"label" => array(
"show" => true,
"position" => 'top'
),
),
array(
"type" => 'bar',
"label" => array(
"show" => true,
"position" => 'top'
),
"itemStyle" => array(
"color" => 'orange'
)
)
)
);
// $sql_data = "SELECT
// distinct T_OrderHeaderM_PatientAge,
// T_OrderHeaderID,
// M_SexCode,
// instr(T_OrderHeaderM_PatientAge,'tahun') as instr_thn,
// replace(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge,'(\\\\d+) tahun'),'tahun','') as xTahun,
// replace(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge,' (\\\\d+) bulan'),'bulan','') as xBulan,
// CASE
// WHEN CAST(REPLACE(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge, ' (\\\\d+) bulan'), 'bulan', '') AS UNSIGNED) > 6
// THEN CAST(REPLACE(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED) + 1
// ELSE CAST(REPLACE(REGEXP_SUBSTR(T_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED)
// END AS xUmurTahunNew
// from t_orderheader
// join m_patient
// ON T_OrderHeaderM_PatientID = M_PatientID
// AND T_OrderHeaderIsActive = 'Y'
// AND M_PatientIsActive = 'Y'
// join m_sex
// ON M_PatientM_SexID = M_SexID
// AND M_SexIsActive = 'Y'
// join one_etl.mgm_header
// ON T_OrderHeaderID = Mgm_HeaderT_OrderHeaderID
// AND Mgm_HeaderIsActive = 'Y'
// join one_etl.mgm_detail
// ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID
// AND Mgm_DetailIsActive = 'Y'
// WHERE Mgm_DetailMcu_KelainanGroupID = 3
// AND Mgm_HeaderMgm_McuID = ?
// -- group by xUmurTahunNew
// ";
$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,
CASE
WHEN CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, ' (\\\\d+) bulan'), 'bulan', '') AS UNSIGNED) > 6
THEN CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED) + 1
ELSE CAST(REPLACE(REGEXP_SUBSTR(Mgm_HeaderT_OrderHeaderM_PatientAge, '(\\\\d+) tahun'), 'tahun', '') AS UNSIGNED)
END AS xUmurTahunNew
from one_etl.mgm_header
join one_etl.mgm_detail
ON Mgm_HeaderID = Mgm_DetailMgm_HeaderID
AND Mgm_DetailIsActive = 'Y'
WHERE 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();
if (count($rows_data) == 0) {
$this->chart_error('No data found');
} else {
$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);
}
}
function check_error($qry, $stage)
{
if (!$qry) {
$errMsg = $stage . "<br/>" . $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;
}
}