120 lines
5.5 KiB
PHP
120 lines
5.5 KiB
PHP
<?php
|
|
class StationQueue extends MY_Controller
|
|
{
|
|
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
function getQueueLab()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$station_id = "station_id";
|
|
if (isset($prm['station_id'])) {
|
|
$station_id = trim($prm["station_id"]);
|
|
}
|
|
$sql = "SELECT T_OrderSampleT_OrderHeaderID AS order_header_id,
|
|
T_OrderHeaderLabNumber AS order_lab_number,
|
|
T_OrderSampleT_SampleStationID AS station_id,
|
|
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_SampleStationID = ?
|
|
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
|
AND DATE_FORMAT(T_OrderHeaderDate, '%M %d %Y') =
|
|
DATE_FORMAT(Now(), '%M %d %Y') AND T_OrderHeaderIsActive = 'Y'
|
|
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
|
|
ORDER BY T_OrderHeaderIsCito DESC, T_OrderHeaderDate ASC, T_OrderHeaderAddonIsComingDate ASC";
|
|
$qry = $this->db->query($sql, array($station_id));
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
} else {
|
|
$value = $qry->result_array();
|
|
$result = array(
|
|
"data" => $value,
|
|
"query" => $last_qry,
|
|
);
|
|
$this->sys_ok($result);
|
|
}
|
|
}
|
|
function getQueueNonLab()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$station_id = "station_id";
|
|
if (isset($prm['station_id'])) {
|
|
$station_id = trim($prm["station_id"]);
|
|
}
|
|
$sql = "SELECT T_OrderHeaderID AS order_id,
|
|
T_OrderHeaderDate AS order_date,
|
|
T_OrderHeaderLabNumber AS order_lab_number,
|
|
T_OrderHeaderM_PatientID AS patient_id,
|
|
M_PatientName AS patient_name,
|
|
T_OrderHeaderIsCito AS is_cito,
|
|
T_BahanT_SampleStationID AS station_id,
|
|
fn_sampling_queue_status_name(T_OrderHeaderID,T_SampleStationID) as statusid,
|
|
T_SampleStationIsNonLab AS is_non_lab
|
|
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 <> ''
|
|
AND T_SampleStationID = ?
|
|
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_FORMAT(T_OrderHeaderDate, '%M %d %Y') =
|
|
DATE_FORMAT(Now(), '%M %d %Y')
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
AND (ISNULL(T_SamplingSoID) OR T_SamplingSoFlag = 'P' OR T_SamplingSoFlag = 'X')
|
|
ORDER BY T_OrderHeaderIsCito DESC, T_OrderHeaderDate ASC, T_OrderHeaderAddonIsComingDate ASC";
|
|
$qry = $this->db->query($sql, array($station_id));
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
} else {
|
|
$value = $qry->result_array();
|
|
$result = array(
|
|
"data" => $value,
|
|
"query" => $last_qry,
|
|
);
|
|
$this->sys_ok($result);
|
|
}
|
|
}
|
|
}
|