Initial import

This commit is contained in:
sas.fajri
2026-05-25 20:01:37 +07:00
commit 710d7c1b97
10371 changed files with 2381698 additions and 0 deletions

View File

@@ -0,0 +1,320 @@
<?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;
}
}

View File

@@ -0,0 +1,180 @@
<?php
class SamplingUpload extends MY_Controller {
function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->load->helper(array('form', 'url'));
}
function get_userdatadir()
{
$r = $this->db_onedev->query('select S_SystemsUserdataUrl from s_systems where S_SystemsIsActive = "Y"')->row();
$q = preg_replace('/(smartlab\_)[a-zA-Z0-9]+/', $r->S_SystemsUserdataUrl, getcwd());
return $q;
}
function uploadimage(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$data = [];
//print_r($_SERVER);
$labnumber = $this->input->post('ordernumber');
$orderid = $this->input->post('orderid');
$sampletype = $this->input->post('sampletype');
//$config['upload_path'] = 'assets/';
$path = '/home/one/project/one/one-media/one-image-nonlab/';
//echo $path;
$config['upload_path'] = $path;
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['max_size'] = '10000';
$count = count($_FILES['photos']['name']);
$this->load->library('upload',$config);
$error = [];
for($i=0;$i<$count;$i++){
if(!empty($_FILES['photos']['name'][$i])){
$_FILES['file']['name'] = $_FILES['photos']['name'][$i];
$_FILES['file']['type'] = $_FILES['photos']['type'][$i];
$_FILES['file']['tmp_name'] = $_FILES['photos']['tmp_name'][$i];
$_FILES['file']['error'] = $_FILES['photos']['error'][$i];
$_FILES['file']['size'] = $_FILES['photos']['size'][$i];
$namex = $labnumber.'-'.$sampletype.'-'.$this->generateRandomString(5);
//echo $namex;
$config['file_name'] = $namex;
$this->upload->initialize($config);
//echo $config['file_name'] ;
if($this->upload->do_upload('file')){
$uploadData = $this->upload->data();
$filename = $uploadData['file_name'];
//echo $filename;
$sql = "INSERT INTO so_imageupload (
So_ImageUploadT_SampleTypeID,
So_ImageUploadT_OrderHeaderID,
So_ImageUploadT_OrderHeaderLabNumber,
So_ImageUploadOldName,
So_ImageUploadNewName,
So_ImageUploadCreated,
So_ImageUploadUserID
)
VALUES(
{$sampletype},
{$orderid},
'{$labnumber}',
'{$_FILES['photos']['name'][$i]}',
'{$filename}',
NOW(),
{$userid}
)";
//echo $sql;
$this->db_onedev->query($sql);
$doctorid = $this->input->post('doctorid');
$doctoraddressid = $this->input->post('doctoraddressid');
$sql = "UPDATE t_samplingso SET T_SamplingSoM_DoctorID = {$doctorid}, T_SamplingSoM_DoctorAddressID = {$doctoraddressid}
WHERE T_SamplingSoT_OrderHeaderID = {$orderid} AND T_SamplingSoT_SampleTypeID = {$sampletype} AND T_SamplingSoIsActive = 'Y'";
$this->db_onedev->query($sql);
$data['totalFiles'][] = $filename;
}
else{
$error = array('error' => $this->upload->display_errors());
}
}
}
$result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error);
$this->sys_ok($result);
}
function xdo_upload()
{
$config['upload_path'] = 'assets/';
$config['allowed_types'] = 'pdf|rar|jpg|png';
$config['max_size'] = '5000';
$config['file_name'] = date('YmdHis');
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('photos'))
{
$error = array('error' => $this->upload->display_errors());
echo json_encode(array('status'=>$error));
}
else
{
print_r($this->upload->data());
/*$lastUpdated = date('Y-m-d H:i:s');
$sql ="UPDATE file_attachment SET File_AattachmentIsActive = 'N' WHERE File_AattachmentReffNumber = '{$this->input->post('trxnumber')}'";
$this->db->query($sql);
$sql = "INSERT INTO file_attachment (
File_AattachmentReffNumber,
File_AattachmentUrl,
File_AattachmentIsActive,
File_AattachmentLastUpdated
)
VALUES (
'{$this->input->post('trxnumber')}',
'{$this->upload->data('file_name')}',
'Y',
'{$lastUpdated}'
)";
//echo $sql;
$r = $this->db->query($sql);
$data = $this->upload->data();
print_r($this->upload->data();
echo json_encode('Upload Success');*/
}
}
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
}
?>

View File

@@ -0,0 +1,418 @@
<?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;
}
}
}