418 lines
14 KiB
PHP
418 lines
14 KiB
PHP
<?php
|
|
class Samplingverify extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "Samplingverify API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->load->helper(array('form', 'url'));
|
|
}
|
|
|
|
|
|
function getphotos($orderid,$sampletypeid){
|
|
$rows = [];
|
|
//print_r($_SERVER);
|
|
$urlbase = 'http://'.$_SERVER['SERVER_NAME']."/one-media/one-image-nonlab/";
|
|
$sql = "SELECT So_ImageUploadID as id,
|
|
So_ImageUploadOldName as oldname,
|
|
CONCAT('{$urlbase}',So_ImageUploadNewName) as newname
|
|
FROM so_imageupload
|
|
WHERE
|
|
So_ImageUploadT_OrderHeaderID = {$orderid} AND So_ImageUploadT_SampleTypeID = {$sampletypeid} AND So_ImageUploadIsActive = 'Y'";
|
|
//echo $sql;
|
|
$rows = $this->db_onedev->query($sql)->result_array();
|
|
return $rows;
|
|
|
|
}
|
|
|
|
function getdoctors($sampletypeid){
|
|
$rows = [];
|
|
|
|
$sql = "SELECT M_DoctorID as id,
|
|
CONCAT(M_DoctorPrefix,' ',M_DoctorName,' ',M_DoctorSufix) as name
|
|
FROM m_doctorso
|
|
JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID
|
|
JOIN t_test ON T_TestT_SampleTypeID = {$sampletypeid} AND M_DoctorSONat_SubGroupID = T_TestNat_SubgroupID
|
|
WHERE
|
|
M_DoctorSOIsActive = 'Y'";
|
|
//echo $sql;
|
|
$rows = $this->db_onedev->query($sql)->result_array();
|
|
return $rows;
|
|
|
|
}
|
|
|
|
function getsetdoctoraddress($doctorid){
|
|
$rows = [];
|
|
|
|
$sql = "SELECT M_DoctorAddressID as id, M_DoctorAddressDescription as name
|
|
FROM m_doctoraddress
|
|
WHERE
|
|
M_DoctorAddressM_DoctorID = {$doctorid} AND M_DoctorAddressIsActive = 'Y'";
|
|
//echo $sql;
|
|
$rows = $this->db_onedev->query($sql)->result_array();
|
|
return $rows;
|
|
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$namelab = $prm["namelab"];
|
|
$nolab = $prm["nolab"];
|
|
$stationid = $prm["stationid"];
|
|
$startdate = $prm["startdate"];
|
|
$enddate = $prm["enddate"];
|
|
|
|
$sql_where = "WHERE ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' ) AND T_OrderHeaderIsActive = 'Y'";
|
|
|
|
//$sql_param = array();
|
|
if ($namelab != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .=" and ";
|
|
}
|
|
$sql_where .= " ( M_PatientName like '%$namelab%' OR T_OrderHeaderLabNumber like '%$namelab%' ) ";
|
|
//$sql_param[] = "%$nama%";
|
|
}
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
|
|
$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 t_sampling_queue_last_status ON
|
|
T_SamplingQueueLastStatusT_SampleStationID = T_SampleStationID AND
|
|
T_SamplingQueueLastStatusT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_SamplingQueueLastStatusT_SamplingQueueStatusID = 5
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_SamplingSoT_SampleTypeID = T_SampleTypeID AND
|
|
( T_SamplingSoFlag = 'D' OR T_SamplingSoFlag = 'V' )
|
|
LEFT JOIN m_doctor ON T_SamplingSoM_DoctorID = M_DoctorID
|
|
LEFT JOIN m_doctoraddress ON T_SamplingSoM_DoctorAddressID = M_DoctorAddressID
|
|
$sql_where
|
|
GROUP BY T_OrderHeaderID , T_SampleTypeID
|
|
) a
|
|
";
|
|
//echo $sql;
|
|
$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("t_orderheader count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT T_SamplingSoID as trx_id, t_orderheader.*,m_patient.*, M_SexName, M_TitleName, CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
|
|
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as patient_dob,IFNULL(M_PatientPhotoThumb,'https://www.sgm-inc.com/wp-content/uploads/2014/06/no-profile-male-img.gif') as M_PatientPhotoThumb,
|
|
T_SampleStationID, T_SampleTypeName,T_SampleTypeID,
|
|
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,
|
|
IF(ISNULL(T_SamplingSoID),DATE_FORMAT(CURDATE(),'%d-%m-%Y'),DATE_FORMAT(T_SamplingSoVerifyDate,'%d-%m-%Y')) as verify_date,
|
|
IF(ISNULL(T_SamplingSoID),DATE_FORMAT(CURTIME(),'%H:%i'),DATE_FORMAT(T_SamplingSoVerifyTime,'%H:%i')) as verify_time,
|
|
'' as photos,
|
|
T_SamplingSoFlag as status,
|
|
T_SamplingSoM_DoctorID,
|
|
T_SamplingSoM_DoctorAddressID,
|
|
CONCAT(M_DoctorPrefix,' ',M_DoctorName,' ',M_DoctorSufix) as doctor_fullname,
|
|
M_DoctorAddressDescription as doctor_address,
|
|
'' as doctors,
|
|
'' as doctoraddress
|
|
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 t_sampling_queue_last_status ON
|
|
T_SamplingQueueLastStatusT_SampleStationID = T_SampleStationID AND
|
|
T_SamplingQueueLastStatusT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_SamplingQueueLastStatusT_SamplingQueueStatusID = 5
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_SamplingSoT_SampleTypeID = T_SampleTypeID AND
|
|
( T_SamplingSoFlag = 'D' OR T_SamplingSoFlag = 'V' )
|
|
LEFT JOIN m_doctor ON T_SamplingSoM_DoctorID = M_DoctorID
|
|
LEFT JOIN m_doctoraddress ON T_SamplingSoM_DoctorAddressID = M_DoctorAddressID
|
|
$sql_where
|
|
GROUP BY T_OrderHeaderID , T_SampleTypeID
|
|
ORDER BY T_OrderHeaderID DESC
|
|
limit $number_limit offset $number_offset";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
$rows[$k]['photos'] = $this->getphotos($v['T_OrderHeaderID'],$v['T_SampleTypeID']);
|
|
$rows[$k]['doctors'] = $this->getdoctors($v['T_SampleTypeID']);
|
|
$rows[$k]['doctoraddress'] = $this->getsetdoctoraddress($v['T_SamplingSoM_DoctorID']);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getstation(){
|
|
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();
|
|
//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 getdoctoraddress(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$query =" SELECT M_DoctorAddressID as id, M_DoctorAddressDescription as name
|
|
FROM m_doctoraddress
|
|
WHERE
|
|
M_DoctorAddressM_DoctorID = {$prm['id']} AND M_DoctorAddressIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
$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'] == 'reject'){
|
|
$sql = "INSERT INTO t_samplingso (
|
|
T_SamplingSoT_OrderHeaderID,
|
|
T_SamplingSoT_SampleTypeID,
|
|
T_SamplingSoUserID
|
|
)
|
|
VALUES(
|
|
{$prm['orderid']},
|
|
{$prm['sampleid']},
|
|
{$userid}
|
|
) ON DUPLICATE KEY UPDATE
|
|
T_SamplingSoDoneDate = NULL,
|
|
T_SamplingSoDoneTime = NULL,
|
|
T_SamplingSoDoneUserID = NULL,
|
|
T_SamplingSoProcessDate = NULL,
|
|
T_SamplingSoProcessTime = NULL,
|
|
T_SamplingSoProcessUserID = NULL,
|
|
T_SamplingSoFlag = 'X',
|
|
T_SamplingSoIsActive = 'N',
|
|
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
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND T_SamplingSoT_SampleTypeID = T_SampleTypeID AND T_SamplingSoIsActive = 'Y'
|
|
WHERE
|
|
T_OrderHeaderID = {$prm['orderid']} AND T_SamplingSoT_SampleTypeID <> {$prm['sampleid']} AND
|
|
(T_SamplingSoFlag = 'D' OR T_SamplingSoFlag = 'V') AND T_OrderHeaderIsActive = 'Y'
|
|
GROUP BY T_SampleTypeID ) xx";
|
|
//echo $sql;
|
|
$xcount = $this->db_onedev->query($sql)->row()->xcount;
|
|
if($xcount == 0){
|
|
$next_status = 2;
|
|
}
|
|
|
|
$dt_json = json_encode(array('T_SampleStationID'=>$prm['stationid'],'T_OrderHeaderID'=>$prm['orderid'],'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['orderid']} 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['orderid']},
|
|
{$next_status},
|
|
{$userid}) ON DUPLICATE KEY UPDATE T_SamplingQueueLastStatusT_SamplingQueueStatusID = {$next_status}";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
|
|
}
|
|
|
|
if($prm['act'] == 'verify'){
|
|
$sql = "INSERT INTO t_samplingso (
|
|
T_SamplingSoT_OrderHeaderID,
|
|
T_SamplingSoT_SampleTypeID,
|
|
T_SamplingSoUserID
|
|
)
|
|
VALUES(
|
|
{$prm['orderid']},
|
|
{$prm['sampleid']},
|
|
{$userid}
|
|
) ON DUPLICATE KEY UPDATE
|
|
T_SamplingSoVerifyDate = CURDATE(),
|
|
T_SamplingSoVerifyTime = CURTIME(),
|
|
T_SamplingSoVerifyUserID = {$userid},
|
|
T_SamplingSoFlag = 'V',
|
|
T_SamplingSoM_DoctorID = {$prm['doctor']['id']},
|
|
T_SamplingSoM_DoctorAddressID = {$prm['doctoraddress']['id']},
|
|
T_SamplingSoIsActive = 'Y',
|
|
T_SamplingSoUserID = {$userid}";
|
|
$this->db_onedev->query($sql);
|
|
|
|
}
|
|
|
|
if($prm['act'] == 'updatedoctor'){
|
|
$sql = "INSERT INTO t_samplingso (
|
|
T_SamplingSoT_OrderHeaderID,
|
|
T_SamplingSoT_SampleTypeID,
|
|
T_SamplingSoUserID
|
|
)
|
|
VALUES(
|
|
{$prm['orderid']},
|
|
{$prm['sampleid']},
|
|
{$userid}
|
|
) ON DUPLICATE KEY UPDATE
|
|
T_SamplingSoM_DoctorID = {$prm['doctor']['id']},
|
|
T_SamplingSoM_DoctorAddressID = {$prm['doctoraddress']['id']},
|
|
T_SamplingSoIsActive = 'Y',
|
|
T_SamplingSoUserID = {$userid}";
|
|
$this->db_onedev->query($sql);
|
|
|
|
}
|
|
|
|
if($prm['act'] == 'unverify'){
|
|
$sql = "INSERT INTO t_samplingso (
|
|
T_SamplingSoT_OrderHeaderID,
|
|
T_SamplingSoT_SampleTypeID,
|
|
T_SamplingSoUserID
|
|
)
|
|
VALUES(
|
|
{$prm['orderid']},
|
|
{$prm['sampleid']},
|
|
{$userid}
|
|
) ON DUPLICATE KEY UPDATE
|
|
T_SamplingSoVerifyDate = NULL,
|
|
T_SamplingSoVerifyTime = NULL,
|
|
T_SamplingSoVerifyUserID = NULL,
|
|
T_SamplingSoFlag = 'D',
|
|
T_SamplingSoIsActive = 'Y',
|
|
T_SamplingSoUserID = {$userid}";
|
|
$this->db_onedev->query($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
exit;
|
|
}
|
|
|
|
function deletephoto(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$query =" UPDATE so_imageupload SET So_ImageUploadIsActive = 'N', So_ImageUploadUserID = {$userid} WHERE So_ImageUploadID = {$prm['id']}";
|
|
//echo $query;
|
|
$actdelete = $this->db_onedev->query($query);
|
|
|
|
if($actdelete){
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array(),
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
else{
|
|
$this->sys_error_db("so_imageupload delete", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} |