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

244 lines
9.0 KiB
PHP

<?php
class Layanandokter extends MY_Controller
{
var $db_antrione;
var $load;
function __construct()
{
parent::__construct();
$this->db_antrione = $this->load->database("antrione", true);
}
function index()
{
echo ('API SERVICE');
}
function list_layanan_dokter()
{
try {
// if (!$this->isLogin) {
// $this->sys_error("Invalid Token");
// exit;
// }
$prm = $this->sys_input;
$serviceId = "0";
if (isset($prm['serviceId'])) {
// $serviceId = trim(str_replace("[]","",$prm["serviceId"]));
$serviceId = implode(",", $prm['serviceId']);
}
// $serviceIdfix = "1,15";
// belum dilayani
$sql_belum_dilayani = "SELECT queueID,
statusID,
IFNULL(queueNumber,'') as queueNumber,
IFNULL(serviceDoctorName,'') as serviceDoctorName,
CONCAT(queueNumber,'-',serviceDoctorName) as antrian_selanjutnya,
( CASE
WHEN statusID = 1 THEN 1
END ) as order_status
FROM queue
JOIN service
ON serviceID = queueServiceID
AND serviceIsActive = 'Y'
JOIN status
ON statusID = queueStatusID
WHERE queueIsActive = 'Y'
AND statusID IN (1)
AND serviceIsConsultDoctor = 'Y'
AND serviceId IN ($serviceId)
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
ORDER BY IFNULL(queueSkipDate, queueCreated)";
$qry_belum_dilayani = $this->db_antrione->query($sql_belum_dilayani);
$last_qry_belum_dilayani = $this->db_antrione->last_query();
if (!$qry_belum_dilayani) {
// $error = array(
// "message" => $this->db_antrione->error()["message"],
// "sql" => $last_qry
// );
// $this->sys_error_db($error);
// exit;
$this->db_antrione->trans_rollback();
echo json_encode(
array("status" => "ERR", "message" => $last_qry_belum_dilayani)
);
exit;
}
$belum_dilayani = $qry_belum_dilayani->result_array();
$arr_serviceName = [];
$result = [];
foreach ($belum_dilayani as $key => $val) {
$serviceName = $val['serviceDoctorName'];
if (in_array($serviceName, $arr_serviceName)) {
continue;
}
$result[] = $val;
$arr_serviceName[] = $serviceName;
}
$belum_dilayani = $result;
$sql_call = "SELECT queueID,
statusID,
queueServiceID as serviceID,
IFNULL(queueNumber,'') as queueNumber,
IFNULL(serviceDoctorName,'') as serviceDoctorName,
CONCAT(queueNumber,'-',serviceDoctorName) as antrian_selanjutnya,
( CASE
WHEN statusID = 2 THEN 1
WHEN statusID = 5 THEN 3
END ) as order_status
FROM queue
JOIN service
ON serviceID = queueServiceID
AND serviceIsActive = 'Y'
JOIN status
ON statusID = queueStatusID
WHERE queueIsActive = 'Y'
AND statusID IN (2,5)
AND serviceIsConsultDoctor = 'Y'
AND serviceId IN ($serviceId)
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
ORDER BY order_status, queueCreated asc";
$qry_call = $this->db_antrione->query($sql_call);
$last_qry_call = $this->db_antrione->last_query();
if (!$qry_call) {
$this->db_antrione->trans_rollback();
echo json_encode(
array("status" => "ERR", "message" => $last_qry_call)
);
exit;
}
$call = $qry_call->result_array();
$arr_serviceName = [];
$result = [];
foreach ($call as $key => $val) {
$serviceName = $val['serviceDoctorName'];
if (in_array($serviceName, $arr_serviceName)) {
continue;
}
$result[] = $val;
$arr_serviceName[] = $serviceName;
}
$call = $result;
// sedang dilayani
$sql_sedang_dilayani = "SELECT queueID,
queueServiceID as serviceID,
IFNULL(queueNumber,'') as queueNumber,
IFNULL(serviceDoctorName,'') as serviceDoctorName,
CONCAT(queueNumber,'-',serviceDoctorName) as antrian_selanjutnya,
( CASE
WHEN statusID = 3 THEN 1
END ) as order_status
FROM queue
JOIN service
ON serviceID = queueServiceID
AND serviceIsActive = 'Y'
JOIN status
ON statusID = queueStatusID
WHERE queueIsActive = 'Y'
AND statusID IN (3)
AND serviceIsConsultDoctor = 'Y'
AND serviceId IN ($serviceId)
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
ORDER BY order_status, queueCreated asc";
$qry_sedang_dilayani = $this->db_antrione->query($sql_sedang_dilayani);
$last_qry_sedang_dilayani = $this->db_antrione->last_query();
if (!$qry_sedang_dilayani) {
// $error = array(
// "message" => $this->db_antrione->error()["message"],
// "sql" => $last_qry
// );
// $this->sys_error_db($error);
// exit;
$this->db_antrione->trans_rollback();
echo json_encode(
array("status" => "ERR", "message" => $last_qry_sedang_dilayani)
);
exit;
}
$sedang_dilayani = $qry_sedang_dilayani->result_array();
$data = [];
$data['call'] = $call;
$data['belumDilayani'] = $belum_dilayani;
$data['sedangDilayani'] = $sedang_dilayani;
$result = array(
$data
);
$this->sys_ok($result);
exit;
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function list_service()
{
try {
$sql = "SELECT * FROM service WHERE serviceIsActive = 'Y'
and serviceIsConsultDoctor = 'Y'";
$qry = $this->db_antrione->query($sql, []);
$last_qry = $this->db_antrione->last_query();
if (!$qry) {
$error = array(
"message" => $this->db_antrione->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
$data = $qry->result_array();
$result = array(
"records" => $data,
"qry" => $last_qry
);
$this->sys_ok($result);
exit;
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function list_service_not_consult()
{
try {
$sql = "SELECT * FROM service
WHERE serviceIsActive = 'Y'";
$qry = $this->db_antrione->query($sql, []);
$last_qry = $this->db_antrione->last_query();
if (!$qry) {
$error = array(
"message" => $this->db_antrione->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
$data = $qry->result_array();
$result = array(
"records" => $data,
"qry" => $last_qry
);
$this->sys_ok($result);
exit;
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}