177 lines
9.8 KiB
PHP
177 lines
9.8 KiB
PHP
<?php
|
|
class Antrianstationlocation extends MY_Controller
|
|
{
|
|
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);
|
|
}
|
|
|
|
function get_datas(){
|
|
try {
|
|
/*if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}*/
|
|
|
|
$this->db_onedev->trans_start();
|
|
$this->db_onedev->trans_strict(FALSE);
|
|
|
|
$sql = "SELECT * FROM (
|
|
SELECT 1 as countx, T_OrderHeaderIsCito,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_OrderHeaderQueue AS queue_number,
|
|
T_OrderHeaderM_PatientID AS patient_id,
|
|
M_PatientName AS patient_name,
|
|
T_OrderHeaderIsCito AS is_cito,
|
|
fn_sampling_queue_status_name(T_OrderHeaderID,T_SampleStationID) as status
|
|
FROM t_ordersample
|
|
JOIN t_samplestation ON T_OrderSampleT_SampleStationID = T_SampleStationID AND
|
|
T_SampleStationIsActive = 'Y' AND T_SampleStationIsNonLab = ''
|
|
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'
|
|
JOIN m_location ON T_OrderLocationM_LocationID = M_LocationID
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN t_orderheaderaddon ON T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID AND
|
|
T_OrderHeaderAddOnIsActive = 'Y'
|
|
JOIN last_status ON T_OrderHeaderID = Last_StatusT_OrderHeaderID AND ( Last_StatusM_StatusID > 3 OR Last_StatusM_StatusID NOT IN (4,6) )
|
|
WHERE T_OrderSampleIsActive = 'Y' AND T_OrderSampleReceive = 'N'
|
|
GROUP BY T_OrderHeaderID,T_samplestationID, M_LocationID
|
|
UNION
|
|
SELECT 1 as countx, T_OrderHeaderIsCito,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_OrderHeaderQueue AS queue_number,
|
|
T_OrderHeaderM_PatientID AS patient_id,
|
|
M_PatientName AS patient_name,
|
|
T_OrderHeaderIsCito AS is_cito,
|
|
fn_sampling_queue_status_name(T_OrderHeaderID,T_SampleStationID) as status
|
|
FROM t_orderdetail
|
|
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y'
|
|
JOIN t_orderheaderaddon ON T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID AND T_OrderHeaderAddOnIsActive = '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 <> ''
|
|
JOIN t_order_location ON T_OrderLocationT_OrderHeaderID = T_OrderHeaderID AND T_OrderLocationT_SampleStationID = T_SampleStationID AND T_OrderLocationIsActive = 'Y'
|
|
JOIN m_location ON T_OrderLocationM_LocationID = 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 T_OrderHeaderIsCito DESC, T_OrderHeaderDate ASC, T_OrderHeaderAddonIsComingDate ASC
|
|
|
|
|
|
";
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$arr_location_station = [];
|
|
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'],'details' => []);
|
|
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'],'details' => []);
|
|
}
|
|
}
|
|
|
|
|
|
foreach ($arr_location_station as $kx => $vx) {
|
|
$results = [];
|
|
foreach ($rows as $ky => $vy) {
|
|
if($vx['station_id'] == $vy['station_id'] && $vx['location_id'] == $vy['location_id']){
|
|
$results[] = $vy;
|
|
}
|
|
}
|
|
$arr_location_station[$kx]['details'] = $results;
|
|
}
|
|
|
|
/*foreach ($arr_location_station as $k_sl => $v_sl) {
|
|
$sql =" SELECT *
|
|
FROM t_orderlocationsampling
|
|
WHERE
|
|
T_OrderLocationSamplingM_LocationID = ? AND
|
|
T_OrderLocationSamplingT_SamplingStationID = ?";
|
|
$query = $this->db_onedev->query($sql,array($v_sl['location_id'],$v_sl['station_id']));
|
|
if($query){
|
|
$row_location_station = $query->row_array();
|
|
$time_last = date("Y-m-d H:i:s a", time() + 30);
|
|
if(datephp date_dif() > date($row_location_station['T_OrderLocationSamplingLastUpdated'],'Y-m-d H:i:s',time()+30)){
|
|
|
|
}
|
|
|
|
}
|
|
else {
|
|
$sql = "INSERT INTO t_orderlocationsampling (
|
|
T_OrderLocationSamplingM_LocationID,
|
|
T_OrderLocationSamplingT_SamplingStationID,
|
|
T_OrderLocationSamplingTotal,
|
|
T_OrderLocationSamplingJSON
|
|
)
|
|
VALUES(
|
|
?,?,?,?
|
|
)";
|
|
$query = $this->db_onedev->query($sql,array($v_sl['location_id'],$v_sl['station_id'],count($v_sl['details']),json_encode($v_sl['details'])));
|
|
if(!$query){
|
|
$this->sys_error_db("error insert t_orderlocationsampling",$this->db_onedev->last_query());
|
|
exit;
|
|
}
|
|
|
|
//$this->sys_error_db("error looping data, location : ".$v_sl['location_name']." station : ".$v_sl['station_name'],$this->db_onedev);
|
|
//exit;
|
|
}
|
|
|
|
}*/
|
|
|
|
$this->db_onedev->trans_complete();
|
|
//echo $this->db_onedev->last_query();
|
|
$this->sys_ok($arr_location_station);
|
|
}
|
|
else {
|
|
$this->sys_error_db("get data error",$this->db_onedev);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|