1211 lines
50 KiB
PHP
1211 lines
50 KiB
PHP
<?php
|
|
class Queuefov2 extends MY_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_antrione = $this->load->database("antrione", true);
|
|
$this->IP_SOCKET_IO = "devone.aplikasi.web.id";
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
echo "ini api queue fo v2\n";
|
|
echo "ipaddress: " . $this->input->ip_address();
|
|
}
|
|
|
|
public function coba()
|
|
{
|
|
echo file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/call");
|
|
}
|
|
|
|
// dari blok fo di routes.js
|
|
public function fo_url()
|
|
{
|
|
try {
|
|
// if (! $this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$sql_fo_url = "call sp_fo_url()";
|
|
$qry_fo_url = $this->db_antrione->query($sql_fo_url);
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_fo_url) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$result = $qry_fo_url->result_array();
|
|
|
|
// $this->sys_ok($result);
|
|
echo json_encode($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function list_service()
|
|
{
|
|
try {
|
|
// if (! $this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
// check IP ADDRESS
|
|
$sql_cek_counter_ip = "select counterIsDedicated, counterID
|
|
from counter
|
|
where counterIsActive = 'Y'
|
|
AND counterIP = ?";
|
|
|
|
$qry_cek_counter_ip = $this->db_antrione->query($sql_cek_counter_ip, [$this->input->ip_address()]);
|
|
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_cek_counter_ip) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$sql_data_service = "";
|
|
// $data_service = [];
|
|
|
|
$data_cek_counter_ip = $qry_cek_counter_ip->result_array();
|
|
|
|
if (count($data_cek_counter_ip) > 0) {
|
|
// dedicated N
|
|
if ($data_cek_counter_ip[0]['counterIsDedicated'] == 'N') {
|
|
$sql_data_service = "select
|
|
serviceID,
|
|
serviceDoctorName,
|
|
serviceName, servicePriority,serviceCode
|
|
from service
|
|
WHERE serviceIsActive = 'Y'";
|
|
} else {
|
|
if ($data_cek_counter_ip[0]['counterIsDedicated'] == 'Y') {
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
$sql_data_service = "select serviceID,
|
|
serviceDoctorName,
|
|
serviceName, servicePriority,serviceCode
|
|
from counter
|
|
join counter_service ON counterID = counterServiceCounterID
|
|
AND counterServiceIsActive = 'Y'
|
|
AND counterIsActive = 'Y'
|
|
join service ON counterServiceServiceID = ServiceID
|
|
AND serviceIsActive = 'Y'
|
|
where counterID = $counterID";
|
|
}
|
|
}
|
|
|
|
$qry_data_service = $this->db_antrione->query($sql_data_service);
|
|
$last_qry_data_service = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_data_service) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$result = $qry_data_service->result_array();
|
|
|
|
array_unshift($result, array(
|
|
"serviceID" => 0,
|
|
"serviceName" => "All Service",
|
|
"servicePriority" => 0,
|
|
"serviceCode" => "Code",
|
|
"serviceDoctorName" => ''
|
|
));
|
|
} else {
|
|
$result = [];
|
|
}
|
|
|
|
// $this->sys_ok($result);
|
|
echo json_encode($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function list_queue_today_oldv1()
|
|
{
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
// check IP ADDRESS
|
|
$sql_cek_counter_ip = "select counterIsDedicated, counterID
|
|
from counter
|
|
where counterIsActive = 'Y'
|
|
AND counterIP = ?";
|
|
// echo $sql_cek_counter_ip;
|
|
|
|
$qry_cek_counter_ip = $this->db_antrione->query($sql_cek_counter_ip, [$this->input->ip_address()]);
|
|
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_cek_counter_ip) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$result = [];
|
|
|
|
$data_cek_counter_ip = $qry_cek_counter_ip->result_array();
|
|
|
|
// get all service
|
|
$sql_get_all_service = "SELECT * FROM service
|
|
WHERE serviceIsActive = 'Y'";
|
|
$qry_get_all_service = $this->db_antrione->query($sql_get_all_service);
|
|
$last_qry_get_all_service = $this->db_antrione->last_query();
|
|
if (!$qry_get_all_service) {
|
|
// $error = array(
|
|
// "message" => $this->db_antrione->error()["message"],
|
|
// "sql" => $last_qry_get_all_service
|
|
// );
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$data_get_all_service = $qry_get_all_service->result_array();
|
|
|
|
$serviceIDs = "0";
|
|
if (count($data_cek_counter_ip) > 0) {
|
|
|
|
// dedicated N return all data service
|
|
if ($data_cek_counter_ip[0]['counterIsDedicated'] == 'N') {
|
|
// echo "9";
|
|
// loop serviceID
|
|
foreach ($data_get_all_service as $k => $val) {
|
|
$serviceIDs .= "," . $val['serviceID'];
|
|
}
|
|
}
|
|
|
|
// dedicated Y return only service in their counter
|
|
else {
|
|
|
|
// foreach($data_get_all_service as $k => $val){
|
|
// $serviceIDs .= ",".$val['serviceID'];
|
|
// }
|
|
// $serviceIDs .= ",".$val['serviceID'];
|
|
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
|
|
$sql_counter_service = "select serviceID,
|
|
serviceName, servicePriority,serviceCode
|
|
from counter
|
|
join counter_service ON counterID = counterServiceCounterID
|
|
AND counterServiceIsActive = 'Y'
|
|
AND counterIsActive = 'Y'
|
|
join service ON counterServiceServiceID = ServiceID
|
|
AND serviceIsActive = 'Y'
|
|
where counterID = $counterID";
|
|
|
|
$qry_counter_service = $this->db_antrione->query($sql_counter_service);
|
|
$last_qry_counter_service = $this->db_antrione->last_query();
|
|
if (!$qry_counter_service) {
|
|
// $error = array(
|
|
// "message" => $this->db_antrione->error()["message"],
|
|
// "sql" => $last_qry_counter_service
|
|
// );
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$data_counter_service = $qry_counter_service->result_array();
|
|
|
|
foreach ($data_counter_service as $k => $val) {
|
|
$serviceIDs .= "," . $val['serviceID'];
|
|
}
|
|
}
|
|
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
|
|
// uri segment not empty
|
|
$uri_segment_serviceID = $this->uri->segment('3');
|
|
if (!empty($uri_segment)) {
|
|
$serviceIDs = $uri_segment_serviceID;
|
|
}
|
|
|
|
$sql_data = "select serviceCode,serviceName,queueCreated,servicePriority, queueID,
|
|
queueNumber,statusName, queue.queueStatusID,
|
|
if ( queueStatusFirstCall is null and queueStatusTicket + interval 5 minute < now() , 'Y', 'N' )
|
|
queueIsRed,
|
|
serviceIsFoOrder,
|
|
serviceDoctorName
|
|
from
|
|
queue
|
|
join service on queueServiceID = serviceID
|
|
join status on queueStatusID = statusID
|
|
join queue_status on queueID = queueStatusQueueID
|
|
where
|
|
( queueServiceID IN ($serviceIDs) )
|
|
and
|
|
date(queueCreated) = date(now())
|
|
and (
|
|
queue.queueStatusID = 1
|
|
or ( queue.queueStatusID = 2 and queueCounterID = ? )
|
|
or ( queue.queueStatusID = 3 and queueCounterID = ? )
|
|
or ( queue.queueStatusID = 5 and queueCounterID = ? )
|
|
)
|
|
and queueIsActive = 'Y'
|
|
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
|
|
order by queue.queueStatusID desc, servicePriority, queueLastUpdated";
|
|
|
|
$qry_data = $this->db_antrione->query($sql_data, [$counterID, $counterID, $counterID]);
|
|
$last_data = $this->db_antrione->last_query();
|
|
if (!$qry_data) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$result = $qry_data->result_array();
|
|
|
|
// $this->sys_ok($result);
|
|
echo json_encode($result);
|
|
} else {
|
|
echo json_encode(
|
|
array(
|
|
array(
|
|
'status' => 'ERR',
|
|
'message' => 'Invalid IP address ' . $this->input->ip_address(),
|
|
'sql' => $last_data,
|
|
'uri' => $uri_segment_serviceID
|
|
)
|
|
)
|
|
);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function list_queue_today()
|
|
{
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
// check IP ADDRESS
|
|
$sql_cek_counter_ip = "select counterIsDedicated, counterID, counterLocationID
|
|
from counter
|
|
where counterIsActive = 'Y'
|
|
AND counterIP = ?";
|
|
// echo $sql_cek_counter_ip;
|
|
|
|
$qry_cek_counter_ip = $this->db_antrione->query($sql_cek_counter_ip, [$this->input->ip_address()]);
|
|
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_cek_counter_ip) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$result = [];
|
|
|
|
$data_cek_counter_ip = $qry_cek_counter_ip->result_array();
|
|
|
|
// get all service
|
|
$sql_get_all_service = "SELECT * FROM service
|
|
WHERE serviceIsActive = 'Y'";
|
|
$qry_get_all_service = $this->db_antrione->query($sql_get_all_service);
|
|
$last_qry_get_all_service = $this->db_antrione->last_query();
|
|
if (!$qry_get_all_service) {
|
|
// $error = array(
|
|
// "message" => $this->db_antrione->error()["message"],
|
|
// "sql" => $last_qry_get_all_service
|
|
// );
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$data_get_all_service = $qry_get_all_service->result_array();
|
|
|
|
$serviceIDs = "0";
|
|
if (count($data_cek_counter_ip) > 0) {
|
|
$locationID = $data_cek_counter_ip[0]['counterLocationID'];
|
|
|
|
// check uri segment
|
|
$id_service_uri_segment = $this->uri->segment('4');
|
|
|
|
if (empty($id_service_uri_segment)) {
|
|
// dedicated N return all data service
|
|
if ($data_cek_counter_ip[0]['counterIsDedicated'] == 'N') {
|
|
// echo "9";
|
|
// loop serviceID
|
|
foreach ($data_get_all_service as $k => $val) {
|
|
$serviceIDs .= "," . $val['serviceID'];
|
|
}
|
|
}
|
|
|
|
// dedicated Y return only service in their counter
|
|
else {
|
|
|
|
// foreach($data_get_all_service as $k => $val){
|
|
// $serviceIDs .= ",".$val['serviceID'];
|
|
// }
|
|
// $serviceIDs .= ",".$val['serviceID'];
|
|
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
|
|
$sql_counter_service = "select serviceID,
|
|
serviceName, servicePriority,serviceCode,
|
|
serviceDoctorName
|
|
from counter
|
|
join counter_service ON counterID = counterServiceCounterID
|
|
AND counterServiceIsActive = 'Y'
|
|
AND counterIsActive = 'Y'
|
|
join service ON counterServiceServiceID = ServiceID
|
|
AND serviceIsActive = 'Y'
|
|
where counterID = $counterID";
|
|
|
|
$qry_counter_service = $this->db_antrione->query($sql_counter_service);
|
|
$last_qry_counter_service = $this->db_antrione->last_query();
|
|
if (!$qry_counter_service) {
|
|
// $error = array(
|
|
// "message" => $this->db_antrione->error()["message"],
|
|
// "sql" => $last_qry_counter_service
|
|
// );
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$data_counter_service = $qry_counter_service->result_array();
|
|
|
|
foreach ($data_counter_service as $k => $val) {
|
|
$serviceIDs .= "," . $val['serviceID'];
|
|
}
|
|
}
|
|
} else {
|
|
if ($id_service_uri_segment == 0 || $id_service_uri_segment == "0") {
|
|
// dedicated N return all data service
|
|
if ($data_cek_counter_ip[0]['counterIsDedicated'] == 'N') {
|
|
// echo "9";
|
|
// loop serviceID
|
|
foreach ($data_get_all_service as $k => $val) {
|
|
$serviceIDs .= "," . $val['serviceID'];
|
|
}
|
|
}
|
|
|
|
// dedicated Y return only service in their counter
|
|
else {
|
|
|
|
// foreach($data_get_all_service as $k => $val){
|
|
// $serviceIDs .= ",".$val['serviceID'];
|
|
// }
|
|
// $serviceIDs .= ",".$val['serviceID'];
|
|
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
|
|
$sql_counter_service = "select serviceID,
|
|
serviceName, servicePriority,serviceCode,
|
|
serviceDoctorName
|
|
from counter
|
|
join counter_service ON counterID = counterServiceCounterID
|
|
AND counterServiceIsActive = 'Y'
|
|
AND counterIsActive = 'Y'
|
|
join service ON counterServiceServiceID = ServiceID
|
|
AND serviceIsActive = 'Y'
|
|
where counterID = $counterID";
|
|
|
|
$qry_counter_service = $this->db_antrione->query($sql_counter_service);
|
|
$last_qry_counter_service = $this->db_antrione->last_query();
|
|
if (!$qry_counter_service) {
|
|
// $error = array(
|
|
// "message" => $this->db_antrione->error()["message"],
|
|
// "sql" => $last_qry_counter_service
|
|
// );
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$data_counter_service = $qry_counter_service->result_array();
|
|
|
|
foreach ($data_counter_service as $k => $val) {
|
|
$serviceIDs .= "," . $val['serviceID'];
|
|
}
|
|
}
|
|
} else {
|
|
// only selected service from dropdown
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
|
|
$sql_counter_service = "select serviceID,
|
|
serviceName, servicePriority,serviceCode,
|
|
serviceDoctorName
|
|
from counter
|
|
join counter_service ON counterID = counterServiceCounterID
|
|
AND counterServiceIsActive = 'Y'
|
|
AND counterIsActive = 'Y'
|
|
join service ON counterServiceServiceID = ServiceID
|
|
AND serviceIsActive = 'Y'
|
|
where serviceID = $id_service_uri_segment";
|
|
|
|
// echo $sql_counter_service;
|
|
|
|
$qry_counter_service = $this->db_antrione->query($sql_counter_service);
|
|
$last_qry_counter_service = $this->db_antrione->last_query();
|
|
if (!$qry_counter_service) {
|
|
// $error = array(
|
|
// "message" => $this->db_antrione->error()["message"],
|
|
// "sql" => $last_qry_counter_service
|
|
// );
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$data_counter_service = $qry_counter_service->result_array();
|
|
|
|
foreach ($data_counter_service as $k => $val) {
|
|
$serviceIDs .= "," . $val['serviceID'];
|
|
}
|
|
}
|
|
}
|
|
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
|
|
$sql_data = "select serviceCode,serviceName,queueCreated,servicePriority, queueID,
|
|
queueNumber,statusName, queue.queueStatusID,
|
|
if ( queueStatusFirstCall is null and queueStatusTicket + interval 5 minute < now() , 'Y', 'N' )
|
|
queueIsRed,
|
|
serviceIsFoOrder,
|
|
serviceDoctorName
|
|
from
|
|
queue
|
|
join service on queueServiceID = serviceID
|
|
join status on queueStatusID = statusID
|
|
join queue_status on queueID = queueStatusQueueID
|
|
where
|
|
( queueServiceID IN ($serviceIDs) )
|
|
and
|
|
date(queueCreated) = date(now())
|
|
and (
|
|
queue.queueStatusID = 1
|
|
or ( queue.queueStatusID = 2 and queueCounterID = ? )
|
|
or ( queue.queueStatusID = 3 and queueCounterID = ? )
|
|
or ( queue.queueStatusID = 5 and queueCounterID = ? )
|
|
)
|
|
and queueIsActive = 'Y'
|
|
AND queueLocationID = $locationID
|
|
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
|
|
order by ifnull(queueSkipDate, queueCreated), servicePriority";
|
|
|
|
$qry_data = $this->db_antrione->query($sql_data, [$counterID, $counterID, $counterID]);
|
|
$last_data = $this->db_antrione->last_query();
|
|
if (!$qry_data) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$result = $qry_data->result_array();
|
|
|
|
// $this->sys_ok($result);
|
|
echo json_encode($result);
|
|
} else {
|
|
echo json_encode(
|
|
array(
|
|
array(
|
|
'status' => 'ERR',
|
|
'message' => 'Invalid IP address ' . $this->input->ip_address(),
|
|
'sql' => $last_data,
|
|
'uri' => $uri_segment_serviceID
|
|
)
|
|
)
|
|
);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function call_queue_today_by_queue_number()
|
|
{
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$prm = $this->sys_input;
|
|
$get_queue_number = $this->uri->segment('4');
|
|
|
|
// check IP ADDRESS
|
|
$sql_cek_counter_ip = "select counterIsDedicated, counterID, counterCode
|
|
from counter
|
|
where counterIsActive = 'Y'
|
|
AND counterIP = ?";
|
|
// echo $sql_cek_counter_ip;
|
|
|
|
$qry_cek_counter_ip = $this->db_antrione->query($sql_cek_counter_ip, [$this->input->ip_address()]);
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_cek_counter_ip) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$data_cek_counter_ip = $qry_cek_counter_ip->result_array();
|
|
|
|
if (count($data_cek_counter_ip) > 0) {
|
|
// call sp_call(?,?)
|
|
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
$counterCode = $data_cek_counter_ip[0]['counterCode'];
|
|
$sql_sp_call = "call sp_call(?,?)";
|
|
$qry_call_sp = $this->db_antrione->query($sql_sp_call, [$get_queue_number, $counterID]);
|
|
|
|
if (!$qry_call_sp) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
$this->clean_mysqli_connection($this->db_antrione->conn_id);
|
|
|
|
if ($qry_call_sp->result_array()[0]['status'] == "ERR") {
|
|
echo json_encode(array(
|
|
'status' => $qry_call_sp->result_array()[0]['status'],
|
|
'message' => $qry_call_sp->result_array()[0]['message']
|
|
));
|
|
} else {
|
|
// get serviceID
|
|
|
|
$sql_get_serviceID = "select queueServiceID, queueLocationID, serviceIsConsultDoctor
|
|
from queue
|
|
left join service
|
|
ON queueServiceID = ServiceID
|
|
AND ServiceIsActive = 'Y'
|
|
where queueIsActive = 'Y'
|
|
AND queueNumber = ?
|
|
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')";
|
|
// echo $sql_cek_counter_ip;
|
|
|
|
$qry_serviceID = $this->db_antrione->query($sql_get_serviceID, [$get_queue_number]);
|
|
// $last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_serviceID) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$data_serviceID = $qry_serviceID->result_array();
|
|
$get_serviceID_by_queueNumber = $data_serviceID[0]['queueServiceID'];
|
|
$get_locationID_by_queueNumber = $data_serviceID[0]['queueLocationID'];
|
|
$serviceIsConsultDoctor = $data_serviceID[0]['serviceIsConsultDoctor'];
|
|
|
|
// check serviceIsConsultDoctor Y atau bukan, klu Y berarti konsul dokter
|
|
|
|
// format status.jenisDisplay.serviceID.queueNumber.counter
|
|
if ($serviceIsConsultDoctor == 'Y') {
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/call.kd.$get_serviceID_by_queueNumber.$get_queue_number.$counterCode.$counterID");
|
|
} else {
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/call.fo.$get_serviceID_by_queueNumber.$get_queue_number.$counterCode.$counterID");
|
|
}
|
|
echo json_encode(array(
|
|
'status' => $qry_call_sp->result_array()[0]['status'],
|
|
'message' => $qry_call_sp->result_array()[0]['message'],
|
|
'counterCode' => $qry_call_sp->result_array()[0]['counterCode']
|
|
));
|
|
}
|
|
} else {
|
|
echo json_encode(
|
|
array(
|
|
array(
|
|
'status' => 'ERR',
|
|
'message' => 'Invalid IP address ' . $this->input->ip_address()
|
|
)
|
|
)
|
|
);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function call_skip_today_by_queue_number()
|
|
{
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$prm = $this->sys_input;
|
|
$get_queue_number = $this->uri->segment('4');
|
|
$queueID = $this->uri->segment('5');
|
|
|
|
// check IP ADDRESS
|
|
$sql_cek_counter_ip = "select counterIsDedicated, counterID
|
|
from counter
|
|
where counterIsActive = 'Y'
|
|
AND counterIP = ?";
|
|
// echo $sql_cek_counter_ip;
|
|
|
|
$qry_cek_counter_ip = $this->db_antrione->query($sql_cek_counter_ip, [$this->input->ip_address()]);
|
|
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_cek_counter_ip) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$data_cek_counter_ip = $qry_cek_counter_ip->result_array();
|
|
|
|
if (count($data_cek_counter_ip) > 0) {
|
|
// call sp_skip(?,?)
|
|
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
$sql_sp_skip = "call sp_skip(?,?)";
|
|
$qry_call_sp = $this->db_antrione->query($sql_sp_skip, [$get_queue_number, $counterID]);
|
|
|
|
if (!$qry_call_sp) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
$this->clean_mysqli_connection($this->db_antrione->conn_id);
|
|
|
|
if ($qry_call_sp->result_array()[0]['status'] == "ERR") {
|
|
echo json_encode(array(
|
|
'status' => $qry_call_sp->result_array()[0]['status'],
|
|
'message' => $qry_call_sp->result_array()[0]['message']
|
|
));
|
|
} else {
|
|
$sql_get_sID = "SELECT queueServiceID as serviceID,
|
|
queueCounterID as counterID,
|
|
serviceIsConsultDoctor
|
|
FROM queue
|
|
left join service
|
|
ON queueServiceID = ServiceID
|
|
AND ServiceIsActive = 'Y'
|
|
WHERE queueID = ?";
|
|
$qry_get_sID = $this->db_antrione->query($sql_get_sID, [$queueID]);
|
|
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_get_sID) {
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
$data = $qry_get_sID->row_array();
|
|
$serviceID = $data['serviceID'];
|
|
$counterID = $data['counterID'];
|
|
$serviceIsConsultDoctor = $data['serviceIsConsultDoctor'];
|
|
|
|
//update queueSkipDate where queueID next 2
|
|
|
|
$sql_all_antrian_by_service = "select queueID,
|
|
(ifnull(queueSkipDate,queueCreated) + INTERVAL 1 second) as skipdate,
|
|
queueSkipCounter
|
|
from queue
|
|
join service on queueServiceID = serviceID
|
|
where queueIsActive = 'Y'
|
|
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
|
|
AND queueServiceID = ?
|
|
order by ifnull(queueSkipDate, queueCreated), servicePriority ";
|
|
|
|
$qry_all = $this->db_antrione->query($sql_all_antrian_by_service,[
|
|
$serviceID
|
|
]);
|
|
if (!$qry_all) {
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$data_all = $qry_all->result_array();
|
|
$next_two_index = -1;
|
|
foreach($data_all as $key => $val)
|
|
{
|
|
if($val['queueID'] == $queueID){
|
|
$next_two_index = $key + 2;
|
|
}
|
|
}
|
|
|
|
$skipdate = "";
|
|
|
|
if($next_two_index < count($data_all) && $next_two_index > -1){
|
|
$skipdate = $data_all[$next_two_index]['skipdate'];
|
|
|
|
}
|
|
|
|
// update skipDate
|
|
if($skipdate != ""){
|
|
$sql_update = "UPDATE queue
|
|
SET queueSkipDate = ?,
|
|
queueSkipCounter = ifnull(queueSkipCounter,0)+1
|
|
WHERE queueID = ?";
|
|
|
|
$qry_update = $this->db_antrione->query($sql_update,[
|
|
$skipdate,
|
|
$queueID
|
|
]);
|
|
|
|
if (!$qry_update) {
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// check jk serviceIsConsultDoctor Y mk antrian konsul dokter
|
|
|
|
if ($serviceIsConsultDoctor == 'Y') {
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/skip.kd.$serviceID.$counterID");
|
|
} else {
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/skip.fo.$serviceID.$counterID");
|
|
}
|
|
echo json_encode(array(
|
|
'status' => $qry_call_sp->result_array()[0]['status'],
|
|
'message' => $qry_call_sp->result_array()[0]['message'],
|
|
));
|
|
}
|
|
} else {
|
|
echo json_encode(
|
|
array(
|
|
array(
|
|
'status' => 'ERR',
|
|
'message' => 'Invalid IP address ' . $this->input->ip_address()
|
|
)
|
|
)
|
|
);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function call_recall_today_by_queue_number()
|
|
{
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$prm = $this->sys_input;
|
|
$get_queue_number = $this->uri->segment('4');
|
|
$queueID = $this->uri->segment('5');
|
|
|
|
// check IP ADDRESS
|
|
$sql_cek_counter_ip = "select counterIsDedicated, counterID, counterCode
|
|
from counter
|
|
where counterIsActive = 'Y'
|
|
AND counterIP = ?";
|
|
// echo $sql_cek_counter_ip;
|
|
|
|
$qry_cek_counter_ip = $this->db_antrione->query($sql_cek_counter_ip, [$this->input->ip_address()]);
|
|
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_cek_counter_ip) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$data_cek_counter_ip = $qry_cek_counter_ip->result_array();
|
|
|
|
if (count($data_cek_counter_ip) > 0) {
|
|
// call sp_recall(?,?)
|
|
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
$counterCode = $data_cek_counter_ip[0]['counterCode'];
|
|
$sql_sp_recall = "call sp_recall(?,?)";
|
|
$qry_call_sp = $this->db_antrione->query($sql_sp_recall, [$get_queue_number, $counterID]);
|
|
|
|
if (!$qry_call_sp) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
$this->clean_mysqli_connection($this->db_antrione->conn_id);
|
|
|
|
if ($qry_call_sp->result_array()[0]['status'] == "ERR") {
|
|
echo json_encode(array(
|
|
'status' => $qry_call_sp->result_array()[0]['status'],
|
|
'message' => $qry_call_sp->result_array()[0]['message']
|
|
));
|
|
} else {
|
|
$sql_get_serviceID = "select queueServiceID, queueLocationID, serviceIsConsultDoctor
|
|
from queue
|
|
left join service
|
|
ON queueServiceID = ServiceID
|
|
AND ServiceIsActive = 'Y'
|
|
where queueIsActive = 'Y'
|
|
AND queueNumber = ?
|
|
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')";
|
|
// echo $sql_cek_counter_ip;
|
|
|
|
$qry_serviceID = $this->db_antrione->query($sql_get_serviceID, [$get_queue_number]);
|
|
// $last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_serviceID) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$data_serviceID = $qry_serviceID->result_array();
|
|
$get_serviceID_by_queueNumber = $data_serviceID[0]['queueServiceID'];
|
|
$get_locationID_by_queueNumber = $data_serviceID[0]['queueLocationID'];
|
|
$serviceIsConsultDoctor = $data_serviceID[0]['serviceIsConsultDoctor'];
|
|
// call fo
|
|
// check serviceIsConsultDoctor Y atau bukan, klu Y berarti konsul dokter
|
|
|
|
if ($serviceIsConsultDoctor == 'Y') {
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/call.kd.$get_serviceID_by_queueNumber.$get_queue_number.$counterCode.$counterID");
|
|
} else {
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/call.fo.$get_serviceID_by_queueNumber.$get_queue_number.$counterCode.$counterID");
|
|
}
|
|
echo json_encode(array(
|
|
'status' => $qry_call_sp->result_array()[0]['status'],
|
|
'message' => $qry_call_sp->result_array()[0]['message'],
|
|
));
|
|
}
|
|
} else {
|
|
echo json_encode(
|
|
array(
|
|
array(
|
|
'status' => 'ERR',
|
|
'message' => 'Invalid IP address ' . $this->input->ip_address()
|
|
)
|
|
)
|
|
);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function call_serve_today_by_queue_number()
|
|
{
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$prm = $this->sys_input;
|
|
$get_queue_number = $this->uri->segment('4');
|
|
$queueID = $this->uri->segment('5');
|
|
|
|
// check IP ADDRESS
|
|
$sql_cek_counter_ip = "select counterIsDedicated, counterID
|
|
from counter
|
|
where counterIsActive = 'Y'
|
|
AND counterIP = ?";
|
|
// echo $sql_cek_counter_ip;
|
|
|
|
$qry_cek_counter_ip = $this->db_antrione->query($sql_cek_counter_ip, [$this->input->ip_address()]);
|
|
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_cek_counter_ip) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$data_cek_counter_ip = $qry_cek_counter_ip->result_array();
|
|
|
|
if (count($data_cek_counter_ip) > 0) {
|
|
// call sp_serve(?,?)
|
|
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
$sql_sp_serve = "call sp_serve(?,?)";
|
|
$qry_call_sp = $this->db_antrione->query($sql_sp_serve, [$get_queue_number, $counterID]);
|
|
|
|
if (!$qry_call_sp) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
$this->clean_mysqli_connection($this->db_antrione->conn_id);
|
|
|
|
if ($qry_call_sp->result_array()[0]['status'] == "ERR") {
|
|
echo json_encode(array(
|
|
'status' => $qry_call_sp->result_array()[0]['status'],
|
|
'message' => $qry_call_sp->result_array()[0]['message']
|
|
));
|
|
} else {
|
|
|
|
$sql_get_sID = "SELECT queueServiceID as serviceID,
|
|
queueCounterID as counterID,
|
|
serviceIsConsultDoctor
|
|
FROM queue
|
|
left join service
|
|
ON queueServiceID = ServiceID
|
|
AND ServiceIsActive = 'Y'
|
|
WHERE queueID = ?";
|
|
$qry_get_sID = $this->db_antrione->query($sql_get_sID, [$queueID]);
|
|
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_get_sID) {
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$data = $qry_get_sID->row_array();
|
|
$serviceID = $data['serviceID'];
|
|
$counterID = $data['counterID'];
|
|
|
|
$serviceIsConsultDoctor = $data['serviceIsConsultDoctor'];
|
|
|
|
// check jk serviceIsConsultDoctor Y mk antrian konsul dokter
|
|
|
|
if ($serviceIsConsultDoctor == 'Y') {
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/serve.kd.$serviceID.$counterID");
|
|
} else {
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/serve.fo.$serviceID.$counterID");
|
|
}
|
|
|
|
|
|
echo json_encode(array(
|
|
'status' => $qry_call_sp->result_array()[0]['status'],
|
|
'message' => $qry_call_sp->result_array()[0]['message'],
|
|
));
|
|
}
|
|
} else {
|
|
echo json_encode(
|
|
array(
|
|
array(
|
|
'status' => 'ERR',
|
|
'message' => 'Invalid IP address ' . $this->input->ip_address()
|
|
)
|
|
)
|
|
);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function call_done_today_by_queue_number()
|
|
{
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$prm = $this->sys_input;
|
|
$get_queue_number = $this->uri->segment('4');
|
|
$queueID = $this->uri->segment('5');
|
|
|
|
// check IP ADDRESS
|
|
$sql_cek_counter_ip = "select counterIsDedicated, counterID
|
|
from counter
|
|
where counterIsActive = 'Y'
|
|
AND counterIP = ?";
|
|
// echo $sql_cek_counter_ip;
|
|
|
|
$qry_cek_counter_ip = $this->db_antrione->query($sql_cek_counter_ip, [$this->input->ip_address()]);
|
|
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_cek_counter_ip) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$data_cek_counter_ip = $qry_cek_counter_ip->result_array();
|
|
|
|
if (count($data_cek_counter_ip) > 0) {
|
|
// call sp_done(?,?)
|
|
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
$sql_sp_done = "call sp_done(?,?,?)";
|
|
$qry_call_sp = $this->db_antrione->query($sql_sp_done, [$get_queue_number, $counterID, '']);
|
|
|
|
if (!$qry_call_sp) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
$this->clean_mysqli_connection($this->db_antrione->conn_id);
|
|
|
|
if ($qry_call_sp->result_array()[0]['status'] == "ERR") {
|
|
echo json_encode(array(
|
|
'status' => $qry_call_sp->result_array()[0]['status'],
|
|
'message' => $qry_call_sp->result_array()[0]['message']
|
|
));
|
|
} else {
|
|
$sql_get_sID = "SELECT queueServiceID as serviceID,
|
|
queueCounterID as counterID,
|
|
serviceIsConsultDoctor
|
|
FROM queue
|
|
left join service
|
|
ON queueServiceID = ServiceID
|
|
AND ServiceIsActive = 'Y'
|
|
WHERE queueID = ?";
|
|
$qry_get_sID = $this->db_antrione->query($sql_get_sID, [$queueID]);
|
|
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_get_sID) {
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$data = $qry_get_sID->row_array();
|
|
$serviceID = $data['serviceID'];
|
|
$counterID = $data['counterID'];
|
|
$serviceIsConsultDoctor = $data['serviceIsConsultDoctor'];
|
|
|
|
// check jk serviceIsConsultDoctor Y mk antrian konsul dokter
|
|
|
|
if ($serviceIsConsultDoctor == 'Y') {
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/done.kd.$serviceID.$counterID");
|
|
} else {
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/done.fo.$serviceID.$counterID");
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'status' => $qry_call_sp->result_array()[0]['status'],
|
|
'message' => $qry_call_sp->result_array()[0]['message'],
|
|
));
|
|
}
|
|
} else {
|
|
echo json_encode(
|
|
array(
|
|
array(
|
|
'status' => 'ERR',
|
|
'message' => 'Invalid IP address ' . $this->input->ip_address()
|
|
)
|
|
)
|
|
);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// dari blok status di routes.js
|
|
public function call_info()
|
|
{
|
|
try {
|
|
// if (! $this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$sql_status_info = "call sp_status_info()";
|
|
$qry_status_info = $this->db_antrione->query($sql_status_info);
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_status_info) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$this->clean_mysqli_connection($this->db_antrione->conn_id);
|
|
|
|
$result = array(
|
|
'status' => 'OK',
|
|
'count' => count($qry_status_info->result_array()),
|
|
'data' => $qry_status_info->result_array()
|
|
);
|
|
|
|
// $this->sys_ok($result);
|
|
echo json_encode($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function call_onserve()
|
|
{
|
|
try {
|
|
// if (! $this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$sql_status_serve = "call sp_status_serve()";
|
|
$qry_status_serve = $this->db_antrione->query($sql_status_serve);
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_status_serve) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$this->clean_mysqli_connection($this->db_antrione->conn_id);
|
|
|
|
// 'status' : 'OK',
|
|
// 'count' : rs[0].length,
|
|
// 'data' : rs[0]
|
|
$result = array(
|
|
'status' => 'OK',
|
|
'count' => count($qry_status_info->result_array()),
|
|
'data' => $qry_status_info->result_array()
|
|
);
|
|
|
|
// $this->sys_ok($result);
|
|
echo json_encode($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|