320 lines
12 KiB
PHP
320 lines
12 KiB
PHP
<?php
|
|
class Samplingcall extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "Samplingcall API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
function getsampletypes(){
|
|
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$orderid = $prm['orderid'];
|
|
$stationid = $prm['stationid'];
|
|
$statusid = $prm['statusid'];
|
|
|
|
$sql = "SELECT T_OrderDetailID,
|
|
T_OrderDetailT_TestCode,
|
|
T_OrderDetailT_TestName,
|
|
T_SampleTypeID,
|
|
T_SampleTypeName,
|
|
T_BahanName,
|
|
IF(ISNULL(T_SamplingSoID),'N',T_SamplingSoFlag) as status,
|
|
IF(ISNULL(T_SamplingSoID),DATE_FORMAT(CURDATE(),'%d-%m-%Y'),DATE_FORMAT(T_SamplingSoProcessDate,'%d-%m-%Y')) as process_date,
|
|
IF(ISNULL(T_SamplingSoID),DATE_FORMAT(CURTIME(),'%H:%i'),DATE_FORMAT(T_SamplingSoProcessTime,'%H:%i')) as process_time,
|
|
IF(ISNULL(T_SamplingSoID) OR T_SamplingSoFlag = 'P',DATE_FORMAT(CURDATE(),'%d-%m-%Y'),DATE_FORMAT(T_SamplingSoDoneDate,'%d-%m-%Y')) as done_date,
|
|
IF(ISNULL(T_SamplingSoID) OR T_SamplingSoFlag = 'P',DATE_FORMAT(CURTIME(),'%H:%i'),DATE_FORMAT(T_SamplingSoDoneTime,'%H:%i')) as done_time
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
|
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$stationid}
|
|
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND T_SamplingSoT_SampleTypeID = T_SampleTypeID AND T_SamplingSoIsActive = 'Y'
|
|
WHERE
|
|
T_OrderHeaderID = {$orderid} AND T_OrderHeaderIsActive = 'Y'
|
|
GROUP BY T_SampleTypeID";
|
|
//echo $sql;
|
|
$rows = $this->db_onedev->query($sql)->result_array();
|
|
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$name = $prm["name"];
|
|
$nolab = $prm["nolab"];
|
|
$stationid = $prm["stationid"];
|
|
$statusid = $prm["statusid"];
|
|
|
|
// echo $norm;
|
|
$where_status = " AND T_SamplingQueueLastStatusT_SamplingQueueStatusID = {$statusid}";
|
|
if($statusid == 0)
|
|
$where_status = " AND ISNULL(T_SamplingQueueLastStatusID)";
|
|
|
|
$sql_where = "WHERE T_OrderHeaderIsActive = 'Y' {$where_status}";
|
|
|
|
//$sql_param = array();
|
|
if ($name != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .=" and ";
|
|
}
|
|
$sql_where .= " M_PatientName like '%$name%' ";
|
|
//$sql_param[] = "%$nama%";
|
|
}
|
|
|
|
if ($nolab != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .=" and ";
|
|
}
|
|
$sql_where .= " T_OrderHeaderLabNumber like '%$nolab%' ";
|
|
//$sql_param[] = "%$nama%";
|
|
}
|
|
|
|
$sql = " SELECT count(*) as total
|
|
FROM (
|
|
SELECT *
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
|
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$stationid} AND T_SampleStationIsNonLab = 'Y'
|
|
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID AND ( Last_StatusM_StatusID = 3 OR Last_StatusM_StatusID = 5 )
|
|
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
|
|
$sql_where
|
|
GROUP BY T_OrderHeaderID
|
|
) a
|
|
";
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
$tot_count = 0;
|
|
//$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
//$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("m_doctor count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT t_orderheader.*,m_patient.*, IFNULL(M_PatientPhotoThumb,'https://www.sgm-inc.com/wp-content/uploads/2014/06/no-profile-male-img.gif') as M_PatientPhotoThumb,
|
|
M_SexName, M_TitleName, CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
|
|
IF(ISNULL(T_SamplingQueueLastStatusID), 'Baru',T_SamplingQueueStatusName) as status, DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as patient_dob,
|
|
IF(ISNULL(T_SamplingQueueLastStatusID), 0,T_SamplingQueueLastStatusT_SamplingQueueStatusID) as statusid, T_SampleStationID
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
|
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$stationid} AND T_SampleStationIsNonLab = 'Y'
|
|
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID AND ( Last_StatusM_StatusID = 3 OR Last_StatusM_StatusID = 5 )
|
|
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
|
|
$sql_where
|
|
GROUP BY T_OrderHeaderID
|
|
ORDER BY T_OrderHeaderID DESC
|
|
limit 0,20";
|
|
echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
$rows = $query->result_array();
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getstationstatus(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT T_SampleStationID as id, T_SampleStationName as name
|
|
FROM t_samplestation
|
|
WHERE
|
|
T_SampleStationIsActive = 'Y' AND T_SampleStationIsNonLab = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['stations'] = $this->db_onedev->query($query)->result_array();
|
|
$rows['statuses'] = array(array('id'=>0,'name'=>'Baru'));
|
|
$query =" SELECT T_SamplingQueueStatusID as id, T_SamplingQueueStatusName as name
|
|
FROM t_sampling_queue_status
|
|
WHERE
|
|
T_SamplingCallStatusIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$statuses = $this->db_onedev->query($query)->result_array();
|
|
//print_r($statuses);
|
|
foreach($statuses as $k=>$v){
|
|
array_push($rows['statuses'],$v);
|
|
}
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function doaction(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$next_status = $prm['statusnextid'];
|
|
if($prm['act'] == 'samplingprocess'){
|
|
|
|
$sql = "INSERT INTO t_samplingso (
|
|
T_SamplingSoT_OrderHeaderID,
|
|
T_SamplingSoT_SampleTypeID,
|
|
T_SamplingSoProcessDate,
|
|
T_SamplingSoProcessTime,
|
|
T_SamplingSoProcessUserID,
|
|
T_SamplingSoCreated,
|
|
T_SamplingSoUserID
|
|
)
|
|
VALUES(
|
|
{$prm['id']},
|
|
{$prm['sample']['T_SampleTypeID']},
|
|
CURDATE(),
|
|
CURTIME(),
|
|
{$userid},
|
|
NOW(),
|
|
{$userid}
|
|
) ON DUPLICATE KEY UPDATE
|
|
T_SamplingSoProcessDate = CURDATE(),
|
|
T_SamplingSoProcessTime = CURTIME(),
|
|
T_SamplingSoFlag = 'P',
|
|
T_SamplingSoIsActive = 'Y',
|
|
T_SamplingSoProcessUserID = {$userid},
|
|
T_SamplingSoUserID = {$userid}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
|
|
if($prm['act'] == 'samplingdone'){
|
|
$sql = "INSERT INTO t_samplingso (
|
|
T_SamplingSoT_OrderHeaderID,
|
|
T_SamplingSoT_SampleTypeID,
|
|
T_SamplingSoDoneDate,
|
|
T_SamplingSoDoneTime,
|
|
T_SamplingSoDoneUserID,
|
|
T_SamplingSoCreated,
|
|
T_SamplingSoUserID
|
|
)
|
|
VALUES(
|
|
{$prm['id']},
|
|
{$prm['sample']['T_SampleTypeID']},
|
|
CURDATE(),
|
|
CURTIME(),
|
|
{$userid},
|
|
NOW(),
|
|
{$userid}
|
|
) ON DUPLICATE KEY UPDATE
|
|
T_SamplingSoDoneDate = CURDATE(),
|
|
T_SamplingSoDoneTime = CURTIME(),
|
|
T_SamplingSoFlag = 'D',
|
|
T_SamplingSoIsActive = 'Y',
|
|
T_SamplingSoDoneUserID = {$userid},
|
|
T_SamplingSoUserID = {$userid}";
|
|
$this->db_onedev->query($sql);
|
|
|
|
$sql = "SELECT count(*) as xcount
|
|
FROM (SELECT *
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
|
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID
|
|
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_SamplingSoT_SampleTypeID = T_SampleTypeID AND
|
|
T_SamplingSoIsActive = 'Y'
|
|
WHERE
|
|
T_OrderHeaderID = {$prm['id']} AND T_SamplingSoT_SampleTypeID <> {$prm['sample']['T_SampleTypeID']} AND
|
|
(ISNULL(T_SamplingSoID) OR T_SamplingSoFlag = 'P') AND T_OrderHeaderIsActive = 'Y'
|
|
GROUP BY T_SampleTypeID ) xx";
|
|
//echo $sql;
|
|
$xcount = $this->db_onedev->query($sql)->row()->xcount;
|
|
if($xcount == 0){
|
|
$next_status = 5;
|
|
}
|
|
}
|
|
|
|
if($prm['act'] !== 'samplingprocess'){
|
|
$dt_json = json_encode(array('T_SampleStationID'=>$prm['stationid'],'T_OrderHeaderID'=>$prm['id'],'T_SamplingQueueStatusID'=>$next_status));
|
|
$query = "INSERT INTO one_log.log_sampling_queue (Log_SamplingQueueDate,Log_SamplingQueueJSON,Log_SamplingQueueUserID)
|
|
VALUES(NOW(),'{$dt_json}',{$userid})";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
$sql = "SELECT *
|
|
FROM t_sampling_queue_last_status
|
|
WHERE
|
|
T_SamplingQueueLastStatusT_SampleStationID = {$prm['stationid']} AND
|
|
T_SamplingQueueLastStatusT_OrderHeaderID = {$prm['id']} AND
|
|
T_SamplingQueueLastStatusIsActive = 'Y'";
|
|
$data_last = $this->db_onedev->query($sql)->row();
|
|
|
|
$query = "INSERT INTO t_sampling_queue_last_status (
|
|
T_SamplingQueueLastStatusT_SampleStationID,
|
|
T_SamplingQueueLastStatusT_OrderHeaderID,
|
|
T_SamplingQueueLastStatusT_SamplingQueueStatusID,
|
|
T_SamplingQueueLastStatusUserID)
|
|
VALUES(
|
|
{$prm['stationid']},
|
|
{$prm['id']},
|
|
{$next_status},
|
|
{$userid}) ON DUPLICATE KEY UPDATE T_SamplingQueueLastStatusT_SamplingQueueStatusID = {$next_status}";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
exit;
|
|
}
|
|
|
|
} |