Files
BE_CPONE/application/controllers/mockup/fo/antrian/AntrianByStationAndLocation.php
2026-04-27 10:31:17 +07:00

1189 lines
60 KiB
PHP

<?php
class AntrianByStationAndLocation extends MY_Controller
{
var $IP_SOCKET_IO = "127.0.0.1";
function __construct()
{
parent::__construct();
/*$this->db_inventory = $this->load->database("inventory", true);
$this->db_inventory_log = $this->load->database('inventory_log', true);
$this->db_onex = 'one_aditya';*/
$this->db_onedev = $this->load->database("onedev", true);
$this->IP_SOCKET_IO = "127.0.0.1";
}
public function cobaBroadcast()
{
print_r($this->IP_SOCKET_IO);
// file_get_contents("https://" . $this->IP_SOCKET_IO . ":9099/broadcast/call");
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9088/broadcast/call");
echo file_get_contents("http://" . $this->IP_SOCKET_IO . ":9088/broadcast/call");
}
function getAntrian()
{
try {
$prm = $this->sys_input;
$arrLocationID = array();
$time = 30;
if (isset($prm['time'])) {
$time = trim($prm["time"]);
}
if (isset($prm['arrLocationID'])) {
$arrLocationID = implode(",", $prm["arrLocationID"]);
}
$sqlCek = "SELECT M_LocationT_SampleStationID AS stationID,
M_LocationID AS locationID FROM m_location
WHERE M_LocationID IN ($arrLocationID)
AND M_LocationIsActive = 'Y'";
$qry = $this->db_onedev->query($sqlCek, array());
if (!$qry) {
$this->sys_error_db("Error get stationID ", $this->db_onedev);
exit;
}
$arrLocationStation = $qry->result_array();
$this->db_onedev->trans_start();
$this->db_onedev->trans_strict(FALSE);
$arrServed = array();
$arrNotServed = array();
$arrCall = array();
$Bagian = "";
foreach ($arrLocationStation as $key => $ls) {
$locationId = intval($ls['locationID']);
$stationId = intval($ls['stationID']);
//Cek snapshot
$sqlCek = "SELECT * FROM t_orderlocationsampling
WHERE T_OrderLocationSamplingM_LocationID = ?
AND T_OrderLocationSamplingT_SamplingStationID = ?";
$qry = $this->db_onedev->query($sqlCek, array(intval($locationId), intval($stationId)));
if (!$qry) {
$this->sys_error_db("cek snapshot error", $this->db_onedev);
exit;
}
$last_qry = "";
$result = $qry->row_array();
$arr_location_station = array();
// print_r($result);
// exit;
//apabila snapshot tidak ada
if (empty($result)) {
$sql = "SELECT * FROM (
SELECT 1 as countx,
T_OrderHeaderDate,
'N' is_cito,
'' T_OrderHeaderAddonIsComingDate,
T_OrderHeaderID AS order_header_id,
T_OrderHeaderLabNumber AS order_lab_number,
T_SampleStationID AS station_id,
T_SampleStationName as station_name,
M_LocationID as location_id,
M_LocatioNName as location_name,
T_OrderHeaderDate AS order_date,
T_OrderHeaderLabNumber AS queue_number,
T_OrderHeaderM_PatientID AS patient_id,
M_PatientName AS patient_name,
fn_sampling_queue_status_name(T_OrderHeaderID,T_SampleStationID) as status,
IF(ISNULL(AntrianSampleStationTime),T_OrderHeaderDate,AntrianSampleStationTime) as antri_time,
IF(ISNULL(AntrianSampleStationTime),T_OrderHeaderDate,AntrianSampleStationTime) as skip_time,
'N' AS is_clinic
FROM t_ordersample
JOIN t_samplestation ON T_OrderSampleT_SampleStationID = T_SampleStationID AND
T_SampleStationIsActive = 'Y' AND T_SampleStationIsNonLab = '' AND T_SampleStationID= ?
AND T_OrderSampleIsActive = 'Y' AND T_OrderSampleReceive = 'N'
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID AND
DATE(T_OrderHeaderDate) = DATE(Now()) AND T_OrderHeaderIsActive = 'Y'
JOIN t_order_location ON T_OrderLocationT_OrderHeaderID = T_OrderHeaderID AND
T_OrderLocationT_SampleStationID = T_SampleStationID AND T_OrderLocationIsActive = 'Y'
LEFT JOIN antrian_samplestation ON AntrianSampleStationT_OrderLocationID =T_OrderLocationID AND AntrianSampleStationIsActive = 'Y'
JOIN m_location ON T_OrderLocationM_LocationID = M_LocationID AND M_LocationID = ?
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
--- JOIN last_status ON T_OrderHeaderID = Last_StatusT_OrderHeaderID AND ( Last_StatusM_StatusID > 3 OR Last_StatusM_StatusID NOT IN (4,6) )
LEFT JOIN t_sampling_queue_last_status
ON T_OrderHeaderID = T_SamplingQueueLastStatusT_OrderHeaderID
AND T_SamplingQueueLastStatusT_SampleStationID = $stationId
GROUP BY T_OrderHeaderID,T_samplestationID, M_LocationID
UNION
SELECT 1 as countx,T_OrderHeaderDate,
'' T_OrderHeaderAddonIsComingDate,
T_OrderHeaderID AS order_header_id,
T_OrderHeaderLabNumber AS order_lab_number,
T_SampleStationID AS station_id,
T_SampleStationName as station_name,
M_LocationID as location_id,
M_LocationName as location_name,
T_OrderHeaderDate AS order_date,
T_OrderHeaderLabNumber AS queue_number,
T_OrderHeaderM_PatientID AS patient_id,
M_PatientName AS patient_name,
fn_sampling_queue_status_name(T_OrderHeaderID,T_SampleStationID) as status,
IF(ISNULL(AntrianSampleStationTime),T_OrderHeaderDate,AntrianSampleStationTime) as antri_time,
IF(ISNULL(AntrianSampleStationTime),T_OrderHeaderDate,AntrianSampleStationTime) as skip_time,
'N' AS is_clinic
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y'
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsActive = 'Y'
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID AND T_SampleTypeIsActive = 'Y'
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID AND T_BahanIsActive = 'Y'
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND
T_SampleStationIsActive = 'Y' AND
T_SampleStationIsNonLab <> '' AND T_SampleStationID = ?
JOIN t_order_location ON T_OrderLocationT_OrderHeaderID = T_OrderHeaderID AND T_OrderLocationT_SampleStationID = T_SampleStationID AND T_OrderLocationIsActive = 'Y'
LEFT JOIN antrian_samplestation ON AntrianSampleStationT_OrderLocationID =T_OrderLocationID AND AntrianSampleStationIsActive = 'Y'
JOIN m_location ON T_OrderLocationM_LocationID = M_LocationID AND M_LocationID = ?
LEFT JOIN t_samplingso ON T_OrderDetailT_OrderHeaderID = T_SamplingSoT_OrderHeaderID AND
T_OrderDetailT_TestID = T_SamplingSoT_TestID AND
T_SamplingSoT_SampleStationID = T_SampleStationID
WHERE DATE(T_OrderHeaderDate) = DATE(Now()) AND
T_OrderDetailIsActive = 'Y' AND
(ISNULL(T_SamplingSoID) OR T_SamplingSoFlag = 'P' OR T_SamplingSoFlag = 'X')
GROUP BY T_OrderHeaderID,T_samplestationID, M_LocationID
) tbl
ORDER BY antri_time ASC";
$query = $this->db_onedev->query($sql, array(
intval($stationId),
intval($locationId),
intval($stationId),
intval($locationId),
));
$last_qry = $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
foreach ($rows as $key => $value) {
if (count($arr_location_station) == 0)
$arr_location_station = array(
'station_id' => $value['station_id'],
'station_name' => $value['station_name'],
'location_id' => $value['location_id'],
'location_name' => $value['location_name'],
'antri_time' => $value['antri_time'],
'skip_time' => $value['skip_time'],
'Keterangan' => 'snapshow empty & get data & insert snapshot'
);
else {
$is_exist = false;
foreach ($arr_location_station as $k => $v) {
// if ($value['is_clinic'] == "Y") {
// if (100 == intval($value['station_id']) && $v['location_id'] == $value['location_id']) {
// $is_exist = true;
// }
// } else {
if ($v['station_id'] == $value['station_id'] && $v['location_id'] == $value['location_id']) {
$is_exist = true;
}
// }
}
if (!$is_exist)
$arr_location_station = array(
'station_id' => $value['station_id'],
'station_name' => $value['station_name'],
'location_id' => $value['location_id'],
'location_name' => $value['location_name'],
'antri_time' => $value['antri_time'],
'skip_time' => $value['skip_time'],
'Keterangan' => 'snapshow empty & get data & insert snapshot'
);
}
}
$results = [];
foreach ($rows as $ky => $vy) {
// if ($vy['is_clinic'] == "Y") {
// if (100 == $vy['station_id'] && intval($locationId) == $vy['location_id']) {
// $results[] = $vy;
// }
// } else {
if (intval($stationId) == $vy['station_id'] && intval($locationId) == $vy['location_id']) {
$results[] = $vy;
}
// }
}
$count_all_queue = count($results);
$arr_process_queue = [];
$arr_waiting_queue = [];
$arr_call_queue = [];
foreach ($results as $key => $value) {
if ($value['status'] == 'Process') {
$arr_process_queue[] = $value;
} else if ($value['status'] == 'Call') {
$arr_call_queue[] = $value;
} else {
$arr_waiting_queue[] = $value;
}
}
$count_process = count($arr_process_queue);
$count_waiting = count($arr_waiting_queue);
$arr_location_station['count_all_queue'] = $count_all_queue;
$arr_location_station['count_process'] = $count_process;
$arr_location_station['count_waiting'] = $count_waiting;
$arr_location_station['details_waiting'] = $arr_waiting_queue;
$arr_location_station['details_process'] = $arr_process_queue;
$arr_location_station['details_call'] = $arr_call_queue;
if (count($arrNotServed) > 0) {
$idCollect = array();
foreach ($arrNotServed as $key1 => $i) {
$idCollect[] = $i['order_header_id'];
}
foreach ($arr_waiting_queue as $key1 => $i) {
if (!in_array(
$i['order_header_id'],
$idCollect
)) {
$arrNotServed[] = $i;
}
}
} else {
$arrNotServed = $arr_waiting_queue;
}
if (count($arrCall) > 0) {
$idCollect = array();
foreach ($arrCall as $key1 => $i) {
$idCollect[] = $i['order_header_id'];
}
foreach ($arr_call_queue as $key1 => $i) {
if (!in_array(
$i['order_header_id'],
$idCollect
)) {
$arrCall[] = $i;
}
}
} else {
$arrCall = $arr_call_queue;
}
if (count($arrServed) > 0) {
$idCollect = array();
foreach ($arrServed as $key1 => $i) {
$idCollect[] = $i['order_header_id'];
}
foreach ($arr_process_queue as $key1 => $i) {
if (!in_array(
$i['order_header_id'],
$idCollect
)) {
$arrServed[] = $i;
}
}
} else {
$arrServed = $arr_process_queue;
}
$bagian = "snapshot tidak ada query data dan input snapshot lalu return";
//insert into snapshot
$sqlInsert = "INSERT INTO t_orderlocationsampling
(T_OrderLocationSamplingM_LocationID,
T_OrderLocationSamplingT_SamplingStationID,
T_OrderLocationSamplingTotal,
T_OrderLocationSamplingTotalProcess,
T_OrderLocationSamplingTotalWaiting,
T_OrderLocationSamplingJSON,
T_OrderLocationSamplingLastUpdated)
VALUES (?,?,?,?,?,?,NOW())";
$qry = $this->db_onedev->query($sqlInsert, array(
intval($locationId),
intval($stationId),
intval($count_all_queue),
intval($count_process),
intval($count_waiting),
json_encode($arr_location_station)
));
if (!$qry) {
$this->sys_error_db("Insert snapshot error", $this->db_onedev);
exit;
}
$this->db_onedev->trans_complete();
//echo $this->db_onedev->last_query();
} else {
$this->sys_error_db("get data error", $this->db_onedev);
exit;
}
//apabila snapshot tidak kosong
} elseif (!empty($result)) {
$last_update = $result['T_OrderLocationSamplingLastUpdated'];
$time_before = strtotime($last_update);
$time_now = strtotime(date("Y-m-d H:i:s"));
$gap = $time_now - $time_before;
//gap lebih besar dari time akan query ulang dan update snapshot
if ($gap > $time) {
$sql = "SELECT * FROM (
SELECT 1 as countx,T_OrderHeaderDate,
'' T_OrderHeaderAddonIsComingDate,
T_OrderHeaderID AS order_header_id,
T_OrderHeaderLabNumber AS order_lab_number,
T_SampleStationID AS station_id,
T_SampleStationName as station_name,
M_LocationID as location_id,
M_LocatioNName as location_name,
T_OrderHeaderDate AS order_date,
T_OrderHeaderLabNumber AS queue_number,
T_OrderHeaderM_PatientID AS patient_id,
M_PatientName AS patient_name,
fn_sampling_queue_status_name(T_OrderHeaderID,T_SampleStationID) as status,
IF(ISNULL(AntrianSampleStationTime),T_OrderHeaderDate,AntrianSampleStationTime) as antri_time,
IF(ISNULL(AntrianSampleStationTime),T_OrderHeaderDate,AntrianSampleStationTime) as skip_time,
'N' AS is_clinic
FROM t_ordersample
JOIN t_samplestation ON T_OrderSampleT_SampleStationID = T_SampleStationID AND
T_SampleStationIsActive = 'Y' AND T_SampleStationIsNonLab = '' AND T_SampleStationID= ?
AND T_OrderSampleIsActive = 'Y' AND T_OrderSampleReceive = 'N'
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID AND
DATE(T_OrderHeaderDate) = DATE(Now()) AND T_OrderHeaderIsActive = 'Y'
JOIN t_order_location ON T_OrderLocationT_OrderHeaderID = T_OrderHeaderID AND
T_OrderLocationT_SampleStationID = T_SampleStationID AND T_OrderLocationIsActive = 'Y'
LEFT JOIN antrian_samplestation ON AntrianSampleStationT_OrderLocationID =T_OrderLocationID AND AntrianSampleStationIsActive = 'Y'
JOIN m_location ON T_OrderLocationM_LocationID = M_LocationID AND M_LocationID = ?
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
-- JOIN last_status ON T_OrderHeaderID = Last_StatusT_OrderHeaderID AND ( Last_StatusM_StatusID > 3 OR Last_StatusM_StatusID NOT IN (4,6) )
LEFT JOIN t_sampling_queue_last_status
ON T_OrderHeaderID = T_SamplingQueueLastStatusT_OrderHeaderID
AND T_SamplingQueueLastStatusT_SampleStationID = $stationId
GROUP BY T_OrderHeaderID,T_samplestationID, M_LocationID
UNION
SELECT 1 as countx,T_OrderHeaderDate,
'' T_OrderHeaderAddonIsComingDate,
T_OrderHeaderID AS order_header_id,
T_OrderHeaderLabNumber AS order_lab_number,
T_SampleStationID AS station_id,
T_SampleStationName as station_name,
M_LocationID as location_id,
M_LocationName as location_name,
T_OrderHeaderDate AS order_date,
T_OrderHeaderLabNumber AS queue_number,
T_OrderHeaderM_PatientID AS patient_id,
M_PatientName AS patient_name,
fn_sampling_queue_status_name(T_OrderHeaderID,T_SampleStationID) as status,
IF(ISNULL(AntrianSampleStationTime),T_OrderHeaderDate,AntrianSampleStationTime) as antri_time,
IF(ISNULL(AntrianSampleStationTime),T_OrderHeaderDate,AntrianSampleStationTime) as skip_time,
'N' AS is_clinic
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y'
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsActive = 'Y'
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID AND T_SampleTypeIsActive = 'Y'
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID AND T_BahanIsActive = 'Y'
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND
T_SampleStationIsActive = 'Y' AND
T_SampleStationIsNonLab <> '' AND T_SampleStationID = ?
JOIN t_order_location ON T_OrderLocationT_OrderHeaderID = T_OrderHeaderID AND T_OrderLocationT_SampleStationID = T_SampleStationID AND T_OrderLocationIsActive = 'Y'
LEFT JOIN antrian_samplestation ON AntrianSampleStationT_OrderLocationID =T_OrderLocationID AND AntrianSampleStationIsActive = 'Y'
JOIN m_location ON T_OrderLocationM_LocationID = M_LocationID AND M_LocationID = ?
LEFT JOIN t_samplingso ON T_OrderDetailT_OrderHeaderID = T_SamplingSoT_OrderHeaderID AND
T_OrderDetailT_TestID = T_SamplingSoT_TestID AND
T_SamplingSoT_SampleStationID = T_SampleStationID
WHERE DATE(T_OrderHeaderDate) = DATE(Now()) AND
T_OrderDetailIsActive = 'Y' AND
(ISNULL(T_SamplingSoID) OR T_SamplingSoFlag = 'P' OR T_SamplingSoFlag = 'X')
GROUP BY T_OrderHeaderID,T_samplestationID, M_LocationID
) tbl
ORDER BY antri_time ASC";
$query = $this->db_onedev->query($sql, array(
intval($stationId),
intval($locationId),
intval($stationId),
intval($locationId),
));
$last_qry = $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
foreach ($rows as $key => $value) {
if (count($arr_location_station) == 0)
$arr_location_station = array(
'station_id' => $value['station_id'],
'station_name' => $value['station_name'],
'location_id' => $value['location_id'],
'location_name' => $value['location_name'],
'antri_time' => $value['antri_time'],
'skip_time' => $value['skip_time'],
);
else {
$is_exist = false;
foreach ($arr_location_station as $k => $v) {
if ($v['station_id'] == $value['station_id'] && $v['location_id'] == $value['location_id']) {
$is_exist = true;
}
}
if (!$is_exist)
$arr_location_station = array(
'station_id' => $value['station_id'],
'station_name' => $value['station_name'],
'location_id' => $value['location_id'],
'location_name' => $value['location_name'],
'antri_time' => $value['antri_time'],
'skip_time' => $value['skip_time'],
'Keterangan' => 'snapshot not empty & get data (more than' . $time . ') & update snapshot'
);
}
}
$results = [];
foreach ($rows as $ky => $vy) {
if (intval($stationId) == $vy['station_id'] && intval($locationId) == $vy['location_id']) {
$results[] = $vy;
}
}
$count_all_queue = count($results);
$arr_process_queue = [];
$arr_waiting_queue = [];
$arr_call_queue = [];
foreach ($results as $key => $value) {
if ($value['status'] == 'Process') {
$arr_process_queue[] = $value;
} else if ($value['status'] == 'Call') {
$arr_call_queue[] = $value;
} else {
$arr_waiting_queue[] = $value;
}
}
$count_process = count($arr_process_queue);
$count_waiting = count($arr_waiting_queue);
$arr_location_station['count_all_queue'] = $count_all_queue;
$arr_location_station['count_process'] = $count_process;
$arr_location_station['count_waiting'] = $count_waiting;
$arr_location_station['details_waiting'] = $arr_waiting_queue;
$arr_location_station['details_process'] = $arr_process_queue;
$arr_location_station['details_call'] = $arr_call_queue;
if (count($arrNotServed) > 0) {
$idCollect = array();
foreach ($arrNotServed as $key1 => $i) {
$idCollect[] = $i['order_header_id'];
}
foreach ($arr_waiting_queue as $key1 => $i) {
if (!in_array(
$i['order_header_id'],
$idCollect
)) {
$arrNotServed[] = $i;
}
}
} else {
$arrNotServed = $arr_waiting_queue;
}
if (count($arrCall) > 0) {
$idCollect = array();
foreach ($arrCall as $key1 => $i) {
$idCollect[] = $i['order_header_id'];
}
foreach ($arr_call_queue as $key1 => $i) {
if (!in_array(
$i['order_header_id'],
$idCollect
)) {
$arrCall[] = $i;
}
}
} else {
$arrCall = $arr_call_queue;
}
if (count($arrServed) > 0) {
$idCollect = array();
foreach ($arrServed as $key1 => $i) {
$idCollect[] = $i['order_header_id'];
}
foreach ($arr_process_queue as $key1 => $i) {
if (!in_array(
$i['order_header_id'],
$idCollect
)) {
$arrServed[] = $i;
}
}
} else {
$arrServed = $arr_process_queue;
}
$bagian = "snapshot ada gap > time query ulang dan update snapshoot";
$sqlInsert = "UPDATE t_orderlocationsampling
SET T_OrderLocationSamplingTotal = ?,
T_OrderLocationSamplingTotalProcess = ?,
T_OrderLocationSamplingTotalWaiting = ?,
T_OrderLocationSamplingJSON = ?,
T_OrderLocationSamplingLastUpdated = NOW()
WHERE T_OrderLocationSamplingM_LocationID = ?
AND T_OrderLocationSamplingT_SamplingStationID = ?";
$qry = $this->db_onedev->query($sqlInsert, array(
intval($count_all_queue),
intval($count_process),
intval($count_waiting),
json_encode($arr_location_station),
intval($locationId),
intval($stationId)
));
if (!$qry) {
$this->sys_error_db("Insert snapshot error", $this->db_onedev);
exit;
}
$this->db_onedev->trans_complete();
//echo $this->db_onedev->last_query();
} else {
$this->sys_error_db("get data error", $this->db_onedev);
exit;
}
//gap lebiih kecil dari time maka return adalah isi snapshot
} else {
$arr_location_station = (array)json_decode($result['T_OrderLocationSamplingJSON']);
$arr_waiting = (array)$arr_location_station['details_waiting'];
$arr_process = (array)$arr_location_station['details_process'];
$arr_call = (array)$arr_location_station['details_call'];
if (count($arrNotServed) > 0) {
$idCollect = array();
foreach ($arrNotServed as $key => $i) {
$arr = (array) $i;
$idCollect[] = $arr['order_header_id'];
}
foreach ($arr_waiting as $key1 => $i) {
$arr = (array) $i;
if (!in_array(
$arr['order_header_id'],
$idCollect
)) {
if ($arr['status'] == 'Call') {
$arrCall[] = $arr;
} else {
$arrNotServed[] = $arr;
}
}
}
} else {
foreach ($arr_waiting as $key => $value) {
$arr = (array)$value;
$arrNotServed[] = $arr;
}
}
if (count($arrServed) > 0) {
$idCollect = array();
foreach ($arrServed as $key => $i) {
$arr = (array) $i;
$idCollect[] = $arr['order_header_id'];
}
foreach ($arr_process as $key1 => $i) {
$arr = (array) $i;
if (!in_array(
$arr['order_header_id'],
$idCollect
)) {
$arrServed[] = $arr;
}
}
} else {
foreach ($arr_process as $key => $value) {
$arr = (array)$value;
$arrServed[] = $arr;
}
}
if (count($arrCall) > 0) {
$idCollect = array();
foreach ($arrCall as $key => $i) {
$arr = (array) $i;
$idCollect[] = $arr['order_header_id'];
}
foreach ($arr_call as $key1 => $i) {
$arr = (array) $i;
if (!in_array(
$arr['order_header_id'],
$idCollect
)) {
$arrCall[] = $arr;
}
}
} else {
foreach ($arr_call as $key => $value) {
$arr = (array)$value;
$arrCall[] = $arr;
}
}
$bagian = "snapshot ada gap < time tidak query ulang hanya ambil snapshoot";
// $arr_location_station->Keterangan = 'snapshot not empty & not get data (less than' . $time . ') & not update snapshot';
}
}
}
usort($arrServed, function ($item1, $item2) {
return $item1['order_date'] <=> $item2['order_date'];
});
usort($arrNotServed, function ($item1, $item2) {
$status1 = 0;
$status2 = 0;
if ($item1['status'] == 'Skip') {
$status1 = 1;
}
if ($item2['status'] == 'Skip') {
$status2 = 1;
}
return ($status1 <=> $status2) * 10 + ($item1['order_date'] <=> $item2['order_date']);
});
// usort($arrNotServed, function ($item1, $item2) {
// return $item1['order_date'] <=> $item2['order_date'];
// });
$data = array(
"bagian" => $bagian,
"call" => $arrCall,
"served" => $arrServed,
"notServed" => $arrNotServed,
"last_query" => $last_qry
);
$this->sys_ok($data);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function coba()
{
try {
$prm = $this->sys_input;
$arrStationID = array();
print_r($prm);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getAntrianV2()
{
try {
$prm = $this->sys_input;
$arrStationID = array();
// print_r($prm);
if (isset($prm['arrStationID'])) {
$arrStationID = explode(",", $prm["arrStationID"]);
}
$onSite = $prm['onSite'];
$branchID = $prm['branchID'];
$setupID = $prm['setupID'];
$qryMgmMcu = '';
if ($onSite == 'N') {
$qryMgmMcu = " AND T_OrderHeaderMgm_McuID IN (SELECT Mgm_McuID FROM mgm_mcu WHERE Mgm_McuM_BranchID = '100' AND Mgm_McuIsActive= 'Y')";
} else {
$qryMgmMcu = "AND T_OrderHeaderMgm_McuID = $setupID";
}
$result = array();
// print_r($setupID);
// print_r($arrStationID);
foreach ($arrStationID as $key => $stationID) {
$sql = "SELECT
T_SampleStationID stationID,
T_SampleStationIsAdditionalFisik stationIsAdditionalFisik,
T_SampleStationOrder stationOrder,
T_SampleStationCode stationCode,
T_SampleStationName stationName,
T_SampleStationNat_GroupID stationNatGroupID,
T_SampleStationIsNonLab stationIsNonLab
FROM t_samplestation
WHERE T_SampleStationIsActive = 'Y'
AND T_SampleStationID = $stationID
ORDER BY T_SampleStationOrder ";
$qry = $this->db_onedev->query(
$sql
);
if (!$qry) {
$this->sys_error_db("Error select branch", $this->db_onedev);
exit;
}
$station = $qry->row_array();
$sql = "SELECT * FROM (
SELECT 1 as countx,
T_OrderHeaderDate,
T_OrderHeaderID AS order_header_id,
PreregisterAntrianNumber AS order_lab_number,
T_SampleStationID AS station_id,
T_SampleStationName as station_name,
T_OrderHeaderDate AS order_date,
T_OrderHeaderMgm_McuID as mgmMcuID,
T_OrderHeaderM_BranchID as branchID,
PreregisterAntrianNumber AS queue_number,
T_OrderHeaderLabNumber AS queuelab_number,
T_OrderHeaderM_PatientID AS patient_id,
M_PatientName AS patient_name,
fn_sampling_queue_status_name(T_OrderHeaderID,T_SampleStationID) as status,
IF(ISNULL(AntrianSampleStationTime),T_OrderHeaderDate,AntrianSampleStationTime) as antri_time,
IF(ISNULL(AntrianSampleStationTime),T_OrderHeaderDate,AntrianSampleStationTime) as skip_time
FROM t_ordersample
JOIN t_samplestation ON T_OrderSampleT_SampleStationID = T_SampleStationID AND
T_SampleStationIsActive = 'Y' AND T_SampleStationIsNonLab = '' AND T_SampleStationID= $stationID
AND T_OrderSampleIsActive = 'Y' AND T_OrderSampleReceive = 'N'
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
AND DATE(T_OrderHeaderDate) = DATE(Now())
$qryMgmMcu
AND T_OrderHeaderM_BranchID = $branchID
AND T_OrderHeaderIsActive = 'Y'
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN t_sampling_queue_last_status
ON T_OrderHeaderID = T_SamplingQueueLastStatusT_OrderHeaderID
AND T_SamplingQueueLastStatusT_SampleStationID = $stationID
JOIN mcu_preregister_patients ON T_OrderHeaderID = Mcu_PreregisterPatientsT_OrderHeaderID
LEFT JOIN preregister_antrian ON Mcu_PreregisterPatientsID = PreregisterAntrianMcu_PreregisterPatientsID
LEFT JOIN antrian_samplestation ON T_OrderHeaderID = AntrianSampleStationOrderID
AND AntrianSampleStationIsActive = 'Y' AND AntrianSampleStationT_SampleStationID = $stationID
GROUP BY T_OrderHeaderID,T_samplestationID
UNION
SELECT 1 as countx,T_OrderHeaderDate,
T_OrderHeaderID AS order_header_id,
PreregisterAntrianNumber AS order_lab_number,
T_SampleStationID AS station_id,
T_SampleStationName as station_name,
T_OrderHeaderDate AS order_date,
T_OrderHeaderMgm_McuID as mgmMcuID,
T_OrderHeaderM_BranchID as branchID,
PreregisterAntrianNumber AS queue_number,
T_OrderHeaderLabNumber AS queuelab_number,
T_OrderHeaderM_PatientID AS patient_id,
M_PatientName AS patient_name,
fn_sampling_queue_status_name(T_OrderHeaderID,T_SampleStationID) as status,
IF(ISNULL(AntrianSampleStationTime),T_OrderHeaderDate,AntrianSampleStationTime) as antri_time,
IF(ISNULL(AntrianSampleStationTime),T_OrderHeaderDate,AntrianSampleStationTime) as skip_time
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y'
AND DATE(T_OrderHeaderDate) = DATE(Now())
$qryMgmMcu
AND T_OrderHeaderM_BranchID = $branchID
AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsActive = 'Y'
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID AND T_SampleTypeIsActive = 'Y'
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID AND T_BahanIsActive = 'Y'
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND
T_SampleStationIsActive = 'Y' AND
T_SampleStationIsNonLab <> '' AND T_SampleStationID = $stationID
JOIN m_patient
ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
LEFT JOIN t_samplingso ON T_OrderDetailT_OrderHeaderID = T_SamplingSoT_OrderHeaderID AND
T_OrderDetailT_TestID = T_SamplingSoT_TestID AND
T_SamplingSoT_SampleStationID = T_SampleStationID
AND(ISNULL(T_SamplingSoID) OR T_SamplingSoFlag = 'P' OR T_SamplingSoFlag = 'X')
JOIN mcu_preregister_patients ON T_OrderHeaderID = Mcu_PreregisterPatientsT_OrderHeaderID
LEFT JOIN preregister_antrian ON Mcu_PreregisterPatientsID = PreregisterAntrianMcu_PreregisterPatientsID
LEFT JOIN antrian_samplestation ON T_OrderHeaderID = AntrianSampleStationOrderID
AND AntrianSampleStationIsActive = 'Y' AND AntrianSampleStationT_SampleStationID = $stationID
GROUP BY T_OrderHeaderID,T_samplestationID
) tbl
ORDER BY antri_time ASC";
$qry = $this->db_onedev->query(
$sql
);
if (!$qry) {
$this->sys_error_db("Error get antrian", $this->db_onedev);
exit;
}
// print_r("qry");
// print_r($this->db_onedev->last_query());
$process = array();
$waiting = array();
$call = array();
$queue = $qry->result_array();
// print_r($queue);
foreach ($queue as $row) {
if ($row['status'] == 'New' || $row['status'] == 'Skip') {
$waiting[] = $row;
}
if ($row['status'] == 'Call') {
if (count($process) == 0) {
# code...
$process[] = $row;
} else {
$process[0]['order_lab_number'] = $process[0]['order_lab_number'] . ', ' . $row['order_lab_number'];
$process[0]['patient_name'] = $process[0]['patient_name'] . ', ' . $row['patient_name'];
}
}
if ($row['status'] == 'Process') {
if (count($process) == 0) {
# code...
$process[] = $row;
} else {
$process[0]['order_lab_number'] = $process[0]['order_lab_number'] . ', ' . $row['order_lab_number'];
$process[0]['patient_name'] = $process[0]['patient_name'] . ', ' . $row['patient_name'];
}
}
}
if (count($process) == 0) {
$data = array(
"countx" => "1",
"T_OrderHeaderDate" => "2025-01-02 08:33:27",
"order_header_id" => "20429",
"order_lab_number" => "-",
"station_id" => "7",
"station_name" => "Sample Station Pemeriksaan Fisik",
"order_date" => "2025-01-02 08:33:27",
"mgmMcuID" => "61",
"branchID" => "3",
"queue_number" => "-",
"patient_id" => "5776",
"patient_name" => "-",
"status" => "Process",
"antri_time" => "2025-01-02 08:33:27",
"skip_time" => "2025-01-02 08:33:27"
);
$process[] = $data;
}
$data = array(
'stationID' => $stationID,
'stationName' => $station['stationName'],
'process' => $process,
'waiting' => $waiting,
'call' => $call
);
$result[] = $data;
}
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getSampleStation()
{
try {
$sql = "SELECT * FROM t_samplestation WHERE T_SampleStationIsActive = 'Y'";
$qry = $this->db_onedev->query(
$sql
);
if (!$qry) {
$this->sys_error_db("Error select sample station", $this->db_onedev);
exit;
}
$data = array(
"records" => $qry->result_array()
);
$this->sys_ok($data);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getLocationName()
{
try {
$sql = "SELECT m_location.*, T_SampleStationName
FROM m_location
JOIN t_samplestation ON M_LocationT_SampleStationID = T_SampleStationID
AND T_SampleStationIsActive = 'Y'
WHERE M_LocationIsActive = 'Y'
ORDER BY M_LocationPriority DESC";
$qry = $this->db_onedev->query(
$sql
);
if (!$qry) {
$this->sys_error_db("Error select location", $this->db_onedev);
exit;
}
$data = array(
"records" => $qry->result_array()
);
$this->sys_ok($data);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getBranch()
{
try {
$sql = "SELECT
*
FROM m_branch
WHERE M_BranchIsActive = 'Y'";
$qry = $this->db_onedev->query(
$sql
);
if (!$qry) {
$this->sys_error_db("Error select branch", $this->db_onedev);
exit;
}
$data = array(
"records" => $qry->result_array()
);
$this->sys_ok($data);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getStation()
{
try {
$sql = "SELECT
T_SampleStationID stationID,
T_SampleStationIsAdditionalFisik stationIsAdditionalFisik,
T_SampleStationOrder stationOrder,
T_SampleStationCode stationCode,
T_SampleStationName stationName,
T_SampleStationNat_GroupID stationNatGroupID,
T_SampleStationIsNonLab stationIsNonLab
FROM t_samplestation
WHERE T_SampleStationIsActive = 'Y'
ORDER BY T_SampleStationOrder ";
$qry = $this->db_onedev->query(
$sql
);
if (!$qry) {
$this->sys_error_db("Error select branch", $this->db_onedev);
exit;
}
$data = array(
"records" => $qry->result_array()
);
$this->sys_ok($data);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function getsetup($branchID = 0)
{
try {
// if (!$this->isLogin) {
// $this->sys_error("Invalid Token");
// exit;
// }
$filterBranch = '';
if ($branchID != 0) {
$filterBranch = "AND Mgm_McuM_BranchID = $branchID";
}
$sql = "SELECT *
FROM mgm_mcu
WHERE Mgm_McuIsActive = 'Y' AND ( CURDATE() BETWEEN Mgm_McuStartDate AND Mgm_McuEndDate )
$filterBranch
ORDER BY Mgm_McuStartDate ASC, Mgm_McuEndDate ASC";
$qry = $this->db_onedev->query($sql, []);
$last_qry = $this->db_onedev->last_query();
if (!$qry) {
$message = $this->db_onedev->error();
$message['last_qry'] = $last_qry;
$this->sys_error($message);
exit;
}
$data = $qry->result_array();
$result = [
"records" => $data,
];
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function getsetuponsite()
{
try {
// if (!$this->isLogin) {
// $this->sys_error("Invalid Token");
// exit;
// }
$sql = "SELECT GROUP_CONCAT(Mgm_McuID) as mcuID FROM mgm_mcu WHERE Mgm_McuM_BranchID = '100' AND Mgm_McuIsActive= 'Y'";
$qry = $this->db_onedev->query($sql, []);
$last_qry = $this->db_onedev->last_query();
if (!$qry) {
$message = $this->db_onedev->error();
$message['last_qry'] = $last_qry;
$this->sys_error($message);
exit;
}
$data = $qry->row_array();
$result = [
"records" => $data,
];
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function getTicket($code = "")
{
try {
$sql = "SELECT
q.queueID,
q.queueNumber,
q.queueCode,
q.queueTicketBoothID,
q.queueStatusID,
M_BranchID,
M_BranchName,
serviceID,
serviceName,
ticketBoothName,
statusName,
DATE_FORMAT(queueStatusTicket, '%d-%m-%Y %H:%i') queueStatusTicket,
DATE_FORMAT(queueStatusTicket, '%H:%i') printed,
IFNULL(DATE_FORMAT(queueStatusLastCall, '%H:%i'), '-') queueStatusLastCall,
IFNULL(DATE_FORMAT(queueStatusServe, '%H:%i'), '-') queueStatusServe,
IFNULL(DATE_FORMAT(queueStatusDone, '%H:%i'),'-') queueStatusDone
FROM antrione.queue q
JOIN antrione.service
ON queueServiceID = serviceID
AND serviceIsActive = 'Y'
JOIN m_branch
ON queueBranchID = M_BranchID
AND M_BranchIsActive = 'Y'
JOIN antrione.ticket_booth
ON queueTicketBoothID = ticketBoothID
AND ticketBoothIsActive = 'Y'
JOIN antrione.queue_status
ON queueID = queueStatusQueueID
JOIN antrione.status
ON q.queueStatusID = statusID
WHERE queueCode = ?";
$qry = $this->db_onedev->query($sql, [$code]);
$last_qry = $this->db_onedev->last_query();
if (!$qry) {
$message = $this->db_onedev->error();
$message['last_qry'] = $last_qry;
$this->sys_error($message);
exit;
}
$data = $qry->row_array();
$statusFO = array();
if ($data) {
$statusFO[] = array(
"status" => "Ticket Printed",
"time" => $data["printed"],
);
$statusFO[] = array(
"status" => "Fo Call",
"time" => $data["queueStatusLastCall"],
);
$statusFO[] = array(
"status" => "Fo Serve",
"time" => $data["queueStatusServe"],
);
$statusFO[] = array(
"status" => "Fo Done",
"time" => $data["queueStatusDone"],
);
$data['statusFO'] = $statusFO;
}
$sql = "SELECT
T_OrderHeaderLabNumber,
T_OrderHeaderMgm_McuID,
M_PatientName,
queueID,
queueNumber ,
PreregisterAntrianID,
queueBranchID,
queueCreated,
Mcu_PreregisterPatientsT_OrderHeaderID,
T_OrderHeaderID,
T_OrderHeaderM_BranchID,
T_SampleStationName,
T_SampleStationID,
T_SamplingQueueLastStatusID,
T_SamplingQueueLastStatusT_SamplingQueueStatusID,
IFNULL(T_SamplingQueueStatusName, '') T_SamplingQueueStatusName
FROM antrione.queue q
JOIN preregister_antrian
ON queueNumber = PreregisterAntrianNumber
AND queueCode = ?
AND queueBranchID = ?
AND queueStatusID = 4
JOIN mcu_preregister_patients
ON PreregisterAntrianMcu_PreregisterPatientsID = Mcu_PreregisterPatientsID
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(PreregisterAntrianCreated, '%d-%m-%Y')
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
JOIN t_orderheader
ON Mcu_PreregisterPatientsT_OrderHeaderID = T_OrderHeaderID
AND T_OrderHeaderIsActive = 'Y'
JOIN m_patient
ON T_OrderHeaderM_PatientID = M_PatientID
JOIN t_order_location
ON T_OrderHeaderID = T_OrderLocationT_OrderHeaderID
JOIN t_samplestation
ON T_OrderLocationT_SampleStationID = T_SampleStationID
LEFT JOIN t_sampling_queue_last_status
ON T_SamplingQueueLastStatusT_SampleStationID = T_SampleStationID
AND T_SamplingQueueLastStatusT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN t_sampling_queue_status
ON T_SamplingQueueLastStatusT_SamplingQueueStatusID = T_SamplingQueueStatusID
GROUP BY T_OrderLocationID";
$qry = $this->db_onedev->query($sql, [$code, $data['M_BranchID']]);
$last_qry = $this->db_onedev->last_query();
if (!$qry) {
$message = $this->db_onedev->error();
$message['last_qry'] = $last_qry;
$this->sys_error($message);
exit;
}
$queueStation = $qry->result_array();
$data['statusStation'] = $queueStation;
$this->sys_ok($data);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}