Files
BE_IBL/application/controllers/mockup/antrian-online/Antrianonlinemonitoring.php
2026-04-15 15:24:12 +07:00

240 lines
8.5 KiB
PHP

<?php
class Antrianonlinemonitoring extends MY_Controller
{
var $db;
var $load;
public function index()
{
echo "Antrian Online Monitoring";
}
public function __construct()
{
parent::__construct();
// $this->db = $this->load->database("antrian_online", true);
}
public function search()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$page = $prm['page'];
$rowPerPage = 10;
$keyword = '%%';
$startDate = $prm['start_date'];
$subService = $prm['subService'];
$status = $prm['status'];
if (!isset($prm['subService'])) {
$subService = 0;
}
$endDate = $prm['end_date'];
if (isset($prm['keyword'])) {
$keyword = '%' . $prm['keyword'] . '%';
}
$start_offset = 0;
if (isset($prm['page'])) {
if (is_numeric((int)$prm['page']) && $prm['page'] > 0) {
$start_offset = ($page - 1) * intval($rowPerPage);
}
}
$filter_subservice = "";
if ($subService != 0) {
$filter_subservice = "AND queueSubServiceID = {$subService}";
}
$filter_status = "";
if ($status == 'X') {
$filter_status = "WHERE IFNULL(Queue_FollowUpID, 'X') = 'X'";
} else if ($status == "Y") {
$filter_status = "WHERE IFNULL(Queue_FollowUpID, 'X') != 'X'";
}
$page = $prm['page'];
$sql_total = "SELECT
COUNT(queueID) AS total
FROM antrian_online.queue
JOIN antrian_online.m_patient
ON queueM_PatientID = M_PatientID
AND queueIsActive = 'Y'
AND M_PatientIsActive = 'Y'
AND queueDate BETWEEN ? AND ?
$filter_subservice
AND (M_PatientName LIKE ? OR M_PatientNoreg LIKE ?)
JOIN subservice
ON queueSubServiceID = subServiceID
AND subServiceIsActive = 'Y'
LEFT JOIN antrian_online.queue_followup
ON queueID = Queue_FollowUpQueueID
AND Queue_FollowUpIsActive = 'Y'
$filter_status
ORDER BY queueDate DESC
";
$qry_total = $this->db->query($sql_total, [
$startDate,
$endDate,
$keyword,
$keyword
]);
$totals = $qry_total->result_array()[0]['total'];
if (!$qry_total) {
$error = array(
"message" => $this->db->error()["message"],
);
$this->sys_error_db($error);
exit;
}
$sql = "SELECT
queueID,
queueM_PatientID,
queueSubServiceID,
subServiceName,
DATE_FORMAT(queueDate, '%d-%m-%Y') AS queueDate,
TIME_FORMAT(queueTimeStart, '%H:%i') AS queueTimeStart,
CONCAT(M_TitleName , ' ',M_PatientName) AS M_PatientName,
M_PatientNoreg,
Queue_FollowUpID,
Queue_FollowUpMessage,
Queue_FollowUpUserID,
M_PatientHp,
M_PatientEmail,
DATE_FORMAT(Queue_FollowUpDate, '%d-%m-%Y %H:%i') AS Queue_FollowUpDate,
M_UserUsername,
IFNULL(Queue_FollowUpID, 'X') AS status
FROM antrian_online.queue
JOIN antrian_online.m_patient
ON queueM_PatientID = M_PatientID
AND queueIsActive = 'Y'
AND M_PatientIsActive = 'Y'
AND queueDate BETWEEN ? AND ?
$filter_subservice
AND (M_PatientName LIKE ? OR M_PatientNoreg LIKE ?)
JOIN subservice
ON queueSubServiceID = subServiceID
AND subServiceIsActive = 'Y'
LEFT JOIN antrian_online.queue_followup
ON queueID = Queue_FollowUpQueueID
AND Queue_FollowUpIsActive = 'Y'
JOIN m_title
ON M_PatientM_TitleID = M_TitleID
AND M_TitleIsActive = 'Y'
LEFT JOIN m_user
ON Queue_FollowUpUserID = M_UserID
AND M_UserIsActive = 'Y'
$filter_status
ORDER BY queueDate DESC
LIMIT ? OFFSET ?";
$qry = $this->db->query($sql, [
$startDate,
$endDate,
$keyword,
$keyword,
intval($rowPerPage),
intval($start_offset),
]);
$last_qry = $this->db->last_query();
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
$result = [
"data" => $qry->result_array(),
"total" => $totals,
"total_page" => ceil($totals / $rowPerPage),
"last_qry" => $last_qry
];
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function getsubservice()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT
subServiceID AS id,
subServiceName AS name
FROM subservice
WHERE subServiceIsActive = 'Y'";
$qry = $this->db->query($sql, []);
$last_qry = $this->db->last_query();
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
$data = $qry->result_array();
array_unshift($data, ["id" => "0", "name" => "All"]);
$this->sys_ok($data);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function followup()
{
try {
$prm = $this->sys_input;
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$queueID = $prm['queue_id'];
$msg = $prm['msg'];
$userID = $this->sys_user['M_UserID'];
if (!(isset($prm['queue_id']) && (strlen(trim($queueID)) > 0))) {
$this->sys_error("queue id mandatory");
exit;
}
if (!(isset($prm['msg']) && (strlen(trim($msg)) > 0))) {
$this->sys_error("note mandatory");
exit;
}
$sql = "INSERT INTO antrian_online.queue_followup(
Queue_FollowUpQueueID,
Queue_FollowUpMessage,
Queue_FollowUpUserID,
Queue_FollowUpDate
)VALUES(?,?,?,NOW())";
$qry = $this->db->query($sql, [$queueID, $msg, $userID]);
$last_qry = $this->db->last_query();
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
$this->sys_ok("Berhasil");
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}