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

244 lines
7.3 KiB
PHP

<?php
class Audiometry_chart_old extends MY_Controller
{
var $url_renderer;
var $db_onedev;
var $load;
function __construct()
{
parent::__construct();
$this->url_renderer = "http://localhost:3030/chart";
$this->db_onedev = $this->load->database("onedev", true);
}
function v01($id)
{
$sql = "SELECT
So_ResultEntryDetailID as trx_id,
NonlabTemplateDetailCode as code,
So_ResultEntryDetailNonlab_TemplateDetailID as template_detail_id,
So_ResultEntryDetailNonlab_TemplateDetailName as result_label,
IFNULL(fn_get_old_result_audiometri(M_PatientOldPID,NonlabTemplateDetailID), 0) as result_value,
So_ResultEntryDetailFlagPrint as flag_print,
fn_get_old_result_audiometri(M_PatientOldPID,NonlabTemplateDetailID) as result_value_before,
NonlabTemplateDetailIsResult as isResult,
CASE
WHEN NonlabTemplateDetailCode LIKE '%AR%' AND NonlabTemplateDetailIsResult='Y' THEN 'AR'
WHEN NonlabTemplateDetailCode LIKE '%AL%' AND NonlabTemplateDetailIsResult='Y' THEN 'AL'
WHEN NonlabTemplateDetailCode LIKE '%BR%' AND NonlabTemplateDetailIsResult='Y' THEN 'BR'
WHEN NonlabTemplateDetailCode LIKE '%BL%' AND NonlabTemplateDetailIsResult='Y' THEN 'BL'
ELSE 'N'
END as type,
GROUP_CONCAT(CASE
WHEN fn_get_old_result_audiometri(M_PatientOldPID,NonlabTemplateDetailID) IS NULL THEN 0
WHEN TRIM(fn_get_old_result_audiometri(M_PatientOldPID,NonlabTemplateDetailID)) = '' THEN 0
WHEN fn_get_old_result_audiometri(M_PatientOldPID,NonlabTemplateDetailID) REGEXP '^[0-9]+$' THEN So_ResultEntryDetailResult
ELSE 0
END ORDER BY So_ResultEntryDetailNonlab_TemplateDetailID) as value
FROM so_resultentrydetail
JOIN so_resultentry ON So_ResultEntryDetailSo_ResultEntryID = So_ResultEntryID
JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID
JOIN m_patient ON M_PatientID = T_OrderHeaderM_PatientID
JOIN nonlab_template_detail ON So_ResultEntryDetailNonlab_TemplateDetailID = NonlabTemplateDetailID
AND NonlabTemplateDetaiM_LangID = 1
WHERE
So_ResultEntryDetailSo_ResultEntryID = '{$id}' AND So_ResultEntryDetailisActive = 'Y'
GROUP BY type
ORDER BY So_ResultEntryDetailNonlab_TemplateDetailID
";
//echo $sql;
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$acR = array();
$acL = array();
$bcR = array();
$bcL = array();
$dtls = $qry->result_array();
foreach ($dtls as $key => $v) {
if ($v['type'] == 'AR') {
$acR = explode(',', $v['value']);
$cek = array();
for ($i = 0; $i < count($acR); $i++) {
if (intval($acR[$i]) == 0) {
array_push($cek, 1);
}
}
if (count($cek) == count($acR)) {
$acR = [];
}
}
if ($v['type'] == 'AL') {
$acL = explode(',', $v['value']);
$cek = array();
for ($i = 0; $i < count($acL); $i++) {
if (intval($acL[$i]) == 0) {
array_push($cek, 1);
}
}
if (count($cek) == count($acL)) {
$acL = [];
}
}
if ($v['type'] == 'BR') {
$bcR = explode(',', $v['value']);
$cek = array();
for ($i = 0; $i < count($bcR); $i++) {
if (intval($bcR[$i]) == 0) {
array_push($cek, 1);
}
}
if (count($cek) == count($bcR)) {
$bcR = [];
}
}
if ($v['type'] == 'BL') {
$bcL = explode(',', $v['value']);
$cek = array();
for ($i = 0; $i < count($bcL); $i++) {
if (intval($bcL[$i]) == 0) {
array_push($cek, 1);
}
}
if (count($cek) == count($bcL)) {
$bcL = [];
}
}
}
$param = array(
'tooltip' => array(
"show" => true,
'trigger' => 'item'
),
'color' => [
"#ff0000",
"#00ff00",
"#0000ff",
"#00ffff",
],
'xAxis' => [
"name"=>"Frequency in hertz (Hz)",
"nameLocation" => "center",
"nameGap" => 30,
"showGrid" => true,
"type" => "category",
"data" => [250, 500, 1000, 2000, 3000, 4000, 6000, 8000],
"forceLabelIsEnabled" => true,
"labelCount" => 8,
"splitLine" => [
"show" => true,
"lineStyle" => [
"color" => "#bbbbbb"
]
]
],
'yAxis' => [
"name" =>"Hearing treshold level (dB)",
"nameLocation" => "middle",
"nameGap" => 30,
"type" => "value",
"inverse" => true,
"min" => 0,
"max" => 120,
"interval" => 10,
"splitLine" => [
"interval" => 0,
"lineStyle" => [
"color" => "#bbbbbb"
]
]
],
'legend' => array(
'top' => 'bottom',
'left' => 'center',
'orient' => 'horizontal'
),
'series' => array(
[
"name" => "1 Right Ear",
"symbol" => "none",
// "symbolSize" => 200,
// "data" => [25, 25, 20, 25, 20, 15, 20, 25],
"data" => $acR,
"type" => "line",
],
[
"name" => "2 BC Right",
"symbol" => "none",
// "symbol" => "circle",
// "showSymbol" => true,
// "data" => [],
"data" => $bcR,
"type" => "line",
],
[
"name" => "3 Left Ear",
"symbol" => "none",
// "symbol" => "plus",
// "showSymbol" => true,
// "data" => [30, 30, 25, 25, 30, 20, 30, 30],
"data" => $acL,
"type" => "line",
],
[
"name" => "4 BC Left ",
"symbol" => "none",
// "symbol" => "triangle",
// "showSymbol" => true,
"data" => $bcL,
// "data" => [],
"type" => "line",
]
)
);
// 3. encapsulate in config attribute and json encode
// print_r($param);
$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 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, 20);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Content-Length: " . strlen($data),
]);
$result = curl_exec($ch);
print_r($result);
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;
}
}