893 lines
30 KiB
PHP
893 lines
30 KiB
PHP
<?php
|
|
class Promisenotok 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 search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$search = $prm["nolab"];
|
|
$sql_where = "WHERE ( T_OrderHeaderLabNumber LIKE CONCAT('%','{$search}','%') OR M_PatientName LIKE CONCAT('%','{$search}','%')) AND T_OrderHeaderIsActive = 'Y'";
|
|
|
|
$sql = " SELECT count(*) as total
|
|
FROM (
|
|
SELECT T_OrderHeaderID as orderid,
|
|
T_OrderHeaderLabNumber as labnumber,
|
|
CONCAT(M_TitleName,'. ',M_PatientName) as patient_fullname,
|
|
fn_fo_promise_not_ok(T_OrderHeaderID) as status
|
|
FROM t_orderheader
|
|
JOIN t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
$sql_where
|
|
HAVING status = 'Y'
|
|
|
|
) 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("m_doctor count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT T_OrderHeaderID as orderid,
|
|
T_OrderHeaderLabNumber as labnumber,
|
|
CONCAT(M_TitleName,'. ',M_PatientName) as patient_fullname,
|
|
fn_fo_promise_not_ok(T_OrderHeaderID) as status
|
|
FROM t_orderheader
|
|
JOIN t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
$sql_where
|
|
HAVING status = 'Y'
|
|
ORDER BY T_OrderHeaderID ASC";
|
|
//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 searchcompany(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM m_company
|
|
WHERE
|
|
M_CompanyName like ?
|
|
AND M_CompanyIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city count",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$rows = array('id'=>0,'name'=>'Semua');
|
|
$sql = "
|
|
SELECT M_CompanyID as id, M_CompanyName as name
|
|
FROM m_company
|
|
WHERE
|
|
M_CompanyName like ?
|
|
AND M_CompanyIsActive = 'Y'
|
|
ORDER BY M_CompanyName DESC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows,array('id'=>0,'name'=>'Semua'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_company rows",$this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function fajribagus(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
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 = ''
|
|
";
|
|
//echo $query;
|
|
$rows['stations'] = $this->db_onedev->query($query)->result_array();
|
|
$rows['statuses'] = array(array('id'=>'NEW','name'=>'New'),array('id'=>'DONE','name'=>'Done'));
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function search_staff(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$rows = [];
|
|
$query =" SELECT M_StaffID as id, M_StaffName as name, M_StaffCode as code, M_UserID as userid
|
|
FROM m_staff
|
|
JOIN m_user ON M_UserM_StaffID = M_StaffID AND M_UserIsActive = 'Y'
|
|
WHERE
|
|
M_StaffIsActive = 'Y' AND M_StaffCode = '{$prm['search']}' LIMIT 1
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->row_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function gettests(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$query =" SELECT T_OrderDetailID as id,
|
|
T_OrderDetailT_TestName as testname,
|
|
T_OrderDetailT_TestCode as testcode,
|
|
T_OrderDetailT_TestSasCode as sascode
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_OrderDetailIsActive = 'Y' AND
|
|
LENGTH(T_OrderDetailT_TestSasCode) = 8
|
|
WHERE
|
|
T_OrderHeaderID = {$prm['orderid']}
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function savenewpromise(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
|
|
$prm = $this->sys_input;
|
|
$newpromise = $prm['newpromise'];
|
|
$xuserid = $this->sys_user['M_UserID'];
|
|
//print_r($newpromise);
|
|
foreach($newpromise as $k => $v){
|
|
$xdatetime = date('Y-m-d H:i',strtotime($v['promisedate'].' '.$v['promisetime']));
|
|
$xid = 0;
|
|
$sql = "SELECT * FROM t_orderpromise WHERE T_OrderPromiseT_OrderHeaderID = {$prm['orderid']} AND DATE_FORMAT(T_OrderPromiseDateTime,'%Y-%m-%d %H:%i') = '{$xdatetime}' AND T_OrderPromiseIsActive = 'Y' LIMIT 1";
|
|
//echo $sql;
|
|
$sql_xid = $this->db_onedev->query($sql)->row();
|
|
if($sql_xid){
|
|
$xid = $sql_xid->T_OrderPromiseID;
|
|
}
|
|
//echo $xid;
|
|
if($xid == 0){
|
|
$sql = "INSERT INTO t_orderpromise (
|
|
T_OrderPromiseT_OrderHeaderID,
|
|
T_OrderPromiseDateTime
|
|
)VALUES(
|
|
{$prm['orderid']},
|
|
'{$xdatetime}'
|
|
)";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
$xid = $this->db_onedev->insert_id();
|
|
}
|
|
$sql = "UPDATE t_orderdetail SET T_OrderDetailT_OrderPromiseID = {$xid} WHERE T_OrderDetailID = '{$v['id']}' ";
|
|
$this->db_onedev->query($sql);
|
|
//echo $sql;
|
|
}
|
|
$fologcode = 'FO.P3KPROMISE';
|
|
$data_log = array();
|
|
$data_log['orderid'] = $prm['orderid'];
|
|
$data_log['new_promise'] = $newpromise;
|
|
|
|
$json_dt_log = json_encode($data_log);
|
|
$sql = "insert into one_log.log_fo(
|
|
Log_FoDate,
|
|
Log_FoCode,
|
|
Log_FoJson,
|
|
Log_FoUserID)
|
|
values( now(), ?, ?, ?)";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$fologcode,
|
|
$json_dt_log,
|
|
$xuserid
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("one_log.fo_log insert");
|
|
exit;
|
|
}
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => $prm
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
|
|
function getdatapromises(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
$prm = $this->sys_input;
|
|
$rows = array();
|
|
if(isset($prm['act']) && $prm['act'] == 'save'){
|
|
$newpromise = $prm['newpromise'];
|
|
foreach($newpromise as $k => $v){
|
|
$xdatetime = date('Y-m-d H:i:s',strtotime($v['promisedate'].' '.$v['promisetime']));
|
|
$xid = 0;
|
|
$sql_xid = $this->db_onedev->query("SELECT * FROM t_orderpromise WHERE T_OrderPromiseT_OrderHeaderID = {$prm['orderid']} AND T_OrderPromiseDateTime = '{$xdatetime}' AND T_OrderPromiseIsActive = 'Y'")->row();
|
|
if($sql_xid){
|
|
$xid = $sql_xid->T_OrderPromiseID;
|
|
}
|
|
if($xid == 0){
|
|
$sql = "INSERT INTO t_orderpromise (
|
|
T_OrderPromiseT_OrderHeaderID,
|
|
T_OrderPromiseDateTime
|
|
)VALUES(
|
|
{$prm['orderid']},
|
|
'{$xdatetime}'
|
|
)";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
else{
|
|
$sql = "UPDATE t_orderpromise SET T_OrderPromiseT_OrderHeaderID = {$prm['orderid']}, T_OrderPromiseDateTime = '{$xdatetime}' ";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
|
|
}
|
|
}else{
|
|
$rows = array();
|
|
$query =" SELECT 0 as id,
|
|
GROUP_CONCAT(CONCAT(T_OrderDetailID,'-',T_OrderDetailT_TestName) separator ',') as testname,
|
|
'' as arr_test,
|
|
DATE_FORMAT(T_OrderPromiseDateTime,'%d%m%Y %H%i') as promisedatetime,
|
|
DATE_FORMAT(T_OrderPromiseDateTime,'%d%m%Y') as promisedate,
|
|
DATE_FORMAT(T_OrderPromiseDateTime,'%H%i') as promisetime
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_OrderDetailIsActive = 'Y' and T_OrderDetailT_TestIsResult = 'Y'
|
|
JOIN t_orderpromise ON T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseIsActive = 'Y'
|
|
WHERE
|
|
T_OrderHeaderID = {$prm['orderid']}
|
|
GROUP BY T_OrderPromiseID
|
|
";
|
|
//echo $query;
|
|
$rows['ok'] = $this->db_onedev->query($query)->result_array();
|
|
if($rows['ok']){
|
|
foreach($rows['ok'] as $k => $v){
|
|
//echo $v{'testname'};
|
|
$arr_x = array();
|
|
$expl_x_1 = explode(",",$v['testname']);
|
|
//print_r($exp_x_1);
|
|
foreach($expl_x_1 as $i=>$j){
|
|
$expl_x_2 = explode("-",$j);
|
|
//print_r($expl_x_2);
|
|
array_push($arr_x,array('id'=>$expl_x_2[0],'name'=>$expl_x_2[1]));
|
|
}
|
|
$rows['ok'][$k]['arr_test'] = $arr_x;
|
|
}
|
|
}
|
|
|
|
|
|
$query ="
|
|
SELECT
|
|
T_OrderDetailID as id,
|
|
CONCAT(T_OrderDetailID,'-',T_OrderDetailT_TestName) as testname,
|
|
'' as arr_test,
|
|
DATE_FORMAT(fn_fo_p3k_promise(T_OrderHeaderID),'%d%m%Y %H%i') as promisedatetime,
|
|
DATE_FORMAT(fn_fo_p3k_promise(T_OrderHeaderID),'%d%m%Y') as promisedate,
|
|
DATE_FORMAT(fn_fo_p3k_promise(T_OrderHeaderID),'%H%i') as promisetime
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_OrderDetailIsActive = 'Y' and T_OrderDetailT_TestIsResult = 'Y' AND T_OrderDetailT_OrderPromiseID = 0
|
|
WHERE
|
|
T_OrderHeaderID = {$prm['orderid']}
|
|
GROUP BY T_OrderDetailID
|
|
";
|
|
//echo $query;
|
|
$rows['notok'] = $this->db_onedev->query($query)->result_array();
|
|
if($rows['notok']){
|
|
foreach($rows['notok'] as $k => $v){
|
|
//echo $v{'testname'};
|
|
$arr_x = array();
|
|
$expl_x_1 = explode(",",$v['testname']);
|
|
//print_r($exp_x_1);
|
|
foreach($expl_x_1 as $i=>$j){
|
|
$expl_x_2 = explode("-",$j);
|
|
//print_r($expl_x_2);
|
|
array_push($arr_x,array('id'=>$expl_x_2[0],'name'=>$expl_x_2[1]));
|
|
}
|
|
$rows['notok'][$k]['arr_test'] = $arr_x;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function search_patient(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$search = '%'.$prm["search"].'%';
|
|
$stationid = $prm["stationid"];
|
|
$statusid = $prm["statusid"];
|
|
$patients = $prm["patients"];
|
|
$where_status = '';
|
|
if($statusid === 'NEW'){
|
|
$where_status = "AND (ISNULL(T_SamplingQueueLastStatusID) OR T_SamplingQueueLastStatusT_SamplingQueueStatusID <> 5 )";
|
|
}
|
|
else{
|
|
$where_status = "AND T_SamplingQueueLastStatusT_SamplingQueueStatusID = 5";
|
|
}
|
|
|
|
// echo $norm;
|
|
//$where_status = " AND {$where_status}";
|
|
|
|
$sql_where = "WHERE T_OrderHeaderLabNumber LIKE '{$search}' AND T_OrderHeaderIsActive = 'Y' {$where_status}";
|
|
$rows = [];
|
|
$query = "SELECT t_orderheader.*,m_patient.*, IFNULL(M_PatientPhoto,'') as M_PatientPhotoThumb,
|
|
M_SexName, M_TitleName, CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname, M_CompanyName,
|
|
IF(ISNULL(T_SamplingQueueLastStatusID), 'New',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, T_SampleTypeID,
|
|
{$stationid} as stationid,
|
|
fn_global_check_is_cito(T_OrderHeaderID) as iscito
|
|
FROM t_orderheader
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
|
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 = ''
|
|
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
|
|
LEFT JOIN t_ordersamplereq ON T_OrderSampleReqT_SampleStationID = T_SampleStationID AND T_OrderSampleReqT_OrderSampleID
|
|
$sql_where
|
|
GROUP BY T_OrderHeaderID
|
|
ORDER BY T_OrderHeaderID DESC
|
|
limit 1";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->row();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
/*function getrequirements($prm){
|
|
|
|
|
|
$query =" SELECT Nat_RequirementID as id,
|
|
Nat_RequirementName as name, '{$prm['status']}' as status,
|
|
if(ISNULL(T_SamplingSoRequirementID),'N', if(json_contains(T_SamplingSoRequirementRequirements,Nat_RequirementID),'Y','N') ) as chex,
|
|
Nat_RequirementPositionNat_PositionID as positionid
|
|
FROM nat_requirement
|
|
JOIN nat_testrequirement ON Nat_TestRequirementNat_RequirementID = Nat_RequirementID
|
|
JOIN nat_requirementposition ON Nat_RequirementPositionNat_RequirementID = Nat_RequirementID AND Nat_RequirementPositionNat_PositionID = 8 AND
|
|
Nat_RequirementPositionIsActive = 'Y'
|
|
JOIN t_test ON T_TestNat_TestID = Nat_TestRequirementNat_TestID
|
|
LEFT JOIN t_samplingso_requirement ON T_SamplingSoRequirementT_OrderHeaderID = {$prm['orderid']} AND
|
|
T_SamplingSoRequirementT_SampletypeID = {$prm['sampletypeid']} AND T_SamplingSoRequirementNat_PositionID = Nat_RequirementPositionNat_PositionID
|
|
WHERE
|
|
Nat_TestRequirementIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
return $rows;
|
|
}*/
|
|
|
|
function getrequirements($prm){
|
|
|
|
$rows = array();
|
|
$query = "
|
|
SELECT Nat_RequirementID as id,
|
|
Nat_RequirementName as name, 'P' as status,
|
|
if(ISNULL(T_OrderSampleReqID),'N', if(json_contains(T_OrderSampleReqs,Nat_RequirementID),'Y','N') ) as chex,
|
|
Nat_RequirementPositionNat_PositionID as positionid
|
|
FROM nat_requirement
|
|
JOIN nat_testrequirement ON Nat_TestRequirementNat_RequirementID = Nat_RequirementID
|
|
JOIN nat_requirementposition ON Nat_RequirementPositionNat_RequirementID = Nat_RequirementID AND Nat_RequirementPositionNat_PositionID = 2 AND
|
|
Nat_RequirementPositionIsActive = 'Y'
|
|
JOIN t_test ON T_TestNat_TestID = Nat_TestRequirementNat_TestID
|
|
JOIN t_barcodelab ON T_barcodeLabT_OrderHeaderID = {$prm['orderid']} AND T_BarcodeLabT_SampleTypeID = {$prm['sampletypeid']}
|
|
JOIN t_ordersample ON T_OrderSampleT_OrderHeaderID = {$prm['orderid']} AND T_OrderSampleT_SampleTypeID = {$prm['sampletypeid']} AND
|
|
T_OrderSampleT_BarcodeLabID = T_BarcodeLabID AND T_OrderSampleIsActive = 'Y'
|
|
LEFT JOIN t_ordersamplereq ON T_OrderSampleReqT_OrderSampleID = T_OrderSampleID AND T_OrderSampleReqT_OrderHeaderID = {$prm['orderid']} AND
|
|
T_OrderSampleReqNat_PositionID = Nat_RequirementPositionNat_PositionID
|
|
WHERE
|
|
Nat_TestRequirementIsActive = 'Y'
|
|
GROUP BY nat_requirementID
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
return $rows;
|
|
}
|
|
|
|
function saverequirement(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$query = " INSERT INTO t_samplingso_requirement (
|
|
T_SamplingSoRequirementT_OrderHeaderID,
|
|
T_SamplingSoRequirementT_SampleStationID,
|
|
T_SamplingSoRequirementT_SampletypeID,
|
|
T_SamplingSoRequirementStatus,
|
|
T_SamplingSoRequirementRequirements,
|
|
T_SamplingSoRequirementNote,
|
|
T_SamplingSoRequirementNat_PositionID,
|
|
T_SamplingSoRequirementUserID,
|
|
T_SamplingSoRequirementCreated
|
|
)VALUES(
|
|
{$prm['T_OrderHeaderID']},
|
|
{$prm['stationid']},
|
|
{$prm['sample']['T_SampleTypeID']},
|
|
'N',
|
|
|
|
)";
|
|
//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;
|
|
}
|
|
$rst_data = array('status'=>'OK');
|
|
$status_call = array('status'=>'OK','data'=>array());
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
if($prm['staff']['id'] != 0 || $prm['staff']['id'] != '0' ){
|
|
$userid = $prm['staff']['userid'];
|
|
}
|
|
|
|
if($prm['act'] == 'call'){
|
|
$sql = "SELECT if(fn_sampling_available_call({$prm['id']},{$prm['stationid']})=0,'Y','N') as status_call";
|
|
$sql = "SELECT T_SamplingQueueLastStatusID, T_SamplingQueueStatusName, T_SampleStationName
|
|
FROM t_sampling_queue_last_status
|
|
JOIN t_sampling_queue_status ON T_SamplingQueueLastStatusT_SamplingQueueStatusID = T_SamplingQueueStatusID
|
|
JOIN t_samplestation ON T_SampleStationID = T_SamplingQueueLastStatusT_SampleStationID
|
|
WHERE
|
|
T_SamplingQueueLastStatusT_OrderHeaderID = {$prm['id']} AND
|
|
T_SamplingQueueLastStatusT_SampleStationID <> {$prm['stationid']} AND
|
|
T_SamplingQueueLastStatusT_SamplingQueueStatusID IN (1,3) LIMIT 1";
|
|
$data_status_call = $this->db_onedev->query($sql)->row_array();
|
|
if($data_status_call){
|
|
$status_call = array('status'=>'NOTCALL','data'=>$data_status_call);
|
|
}
|
|
|
|
}
|
|
|
|
$next_status = $prm['statusnextid'];
|
|
if($prm['act'] == 'process'){
|
|
$sql = "SELECT T_OrderDetailID, T_OrderHeaderID,T_OrderDetailID as id,
|
|
T_BarcodeLabID,
|
|
T_BarcodeLabBarcode,
|
|
T_OrderDetailT_TestCode,
|
|
T_OrderDetailT_TestName,
|
|
T_SampleTypeID,
|
|
T_SampleTypeName,
|
|
T_BahanName
|
|
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_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderHeaderID AND T_BarcodeLabT_SampleTypeID = T_SampleTypeID
|
|
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
|
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$prm['stationid']}
|
|
LEFT JOIN t_ordersample ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID AND T_OrderSampleT_BarcodeLabID = T_BarcodeLabID AND
|
|
T_OrderSampleT_SampleTypeID = T_SampleTypeID AND
|
|
T_OrderSampleReceive = 'N' AND T_OrderSampleIsActive = 'Y'
|
|
LEFT JOIN t_ordersamplereq ON T_OrderSampleReqT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_OrderSampleReqT_OrderSampleID = T_OrderSampleID AND
|
|
T_OrderSampleReqNat_PositionID = 2 AND
|
|
T_OrderSampleReqT_SampleStationID = T_SampleStationID AND
|
|
T_OrderSampleReqIsActive = 'Y'
|
|
WHERE
|
|
T_OrderHeaderID = {$prm['id']} AND T_OrderHeaderIsActive = 'Y'
|
|
GROUP BY T_SampleTypeID";
|
|
//echo $sql;
|
|
$rows_all_sample = $this->db_onedev->query($sql)->result();
|
|
if($rows_all_sample){
|
|
foreach($rows_all_sample as $k => $v){
|
|
$sql = "INSERT INTO t_ordersample (
|
|
T_OrderSampleT_OrderHeaderID,
|
|
T_OrderSampleT_SampleTypeID,
|
|
T_OrderSampleT_BarcodeLabID,
|
|
T_OrderSampleCreated,
|
|
T_OrderSampleUserID
|
|
)
|
|
VALUES(
|
|
{$prm['id']},
|
|
{$v->T_SampleTypeID},
|
|
{$v->T_BarcodeLabID},
|
|
NOW(),
|
|
{$userid}
|
|
) ON DUPLICATE KEY UPDATE
|
|
T_OrderSampleSampling = 'Y',
|
|
T_OrderSampleSamplingDate = CURDATE(),
|
|
T_OrderSampleSamplingTime = CURTIME(),
|
|
T_OrderSampleSamplingUserID = {$userid},
|
|
T_OrderSampleIsActive = 'Y',
|
|
T_OrderSampleUserID = {$userid}";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
}
|
|
}
|
|
|
|
if($prm['act'] == 'samplingdone'){
|
|
|
|
$sql = "INSERT INTO t_ordersample (
|
|
T_OrderSampleT_OrderHeaderID,
|
|
T_OrderSampleT_SampleTypeID,
|
|
T_OrderSampleT_BarcodeLabID,
|
|
T_OrderSampleCreated,
|
|
T_OrderSampleUserID
|
|
)
|
|
VALUES(
|
|
{$prm['sample']['T_OrderHeaderID']},
|
|
{$prm['sample']['T_SampleTypeID']},
|
|
{$prm['sample']['T_BarcodeLabID']},
|
|
NOW(),
|
|
{$userid}
|
|
) ON DUPLICATE KEY UPDATE
|
|
T_OrderSampleReceiveDate = CURDATE(),
|
|
T_OrderSampleReceiveTime = CURTIME(),
|
|
T_OrderSampleReceiveUserID = {$userid},
|
|
T_OrderSampleReceive = 'Y',
|
|
T_OrderSampleIsActive = 'Y',
|
|
T_OrderSampleUserID = {$userid}";
|
|
$this->db_onedev->query($sql);
|
|
|
|
$sql = "SELECT * FROM t_ordersample
|
|
WHERE T_OrderSampleT_BarcodeLabID = {$prm['sample']['T_BarcodeLabID']} AND T_OrderSampleIsActive = 'Y'
|
|
ORDER BY T_OrderSampleID DESC LIMIT 1";
|
|
$dt_sampleorder = $this->db_onedev->query($sql)->row();
|
|
|
|
$sql = "SELECT * FROM t_sampletype WHERE T_SampleTypeID = {$prm['sample']['T_SampleTypeID']}";
|
|
$dt_sampletype = $this->db_onedev->query($sql)->row();
|
|
//echo $dt_sampleorder->T_OrderSampleReceiveDate;
|
|
//echo $dt_sampleorder->T_OrderSampleReceiveTime;
|
|
$readytime = date('Y-m-d H:i:s',strtotime($dt_sampleorder->T_OrderSampleReceiveDate.' '.$dt_sampleorder->T_OrderSampleReceiveTime));
|
|
//echo $readytime;
|
|
if($dt_sampletype->T_SampleTypeAgingOnHold == 'Y'){
|
|
$readytime = date('Y-m-d H:i:s',strtotime("+{$dt_sampletype->T_SampleTypeAgingOnHoldTime} minutes",strtotime($dt_sampleorder->T_OrderSampleReceiveDate.' '.$dt_sampleorder->T_OrderSampleReceiveTime)));
|
|
//echo $readytime;
|
|
}
|
|
//echo $readytime;
|
|
$sql = "UPDATE t_ordersample
|
|
SET T_OrderSampleReadyToProcessDateTime = '{$readytime}'
|
|
WHERE
|
|
T_OrderSampleT_BarcodeLabID = {$prm['sample']['T_BarcodeLabID']} AND T_OrderSampleIsActive = 'Y' ";
|
|
$this->db_onedev->query($sql);
|
|
//echo $sql;
|
|
$xreq = $prm['sample']['requirements'];
|
|
$arr_requirements = array();
|
|
foreach($xreq as $k=>$v){
|
|
if($v['chex'] == 'Y')
|
|
array_push($arr_requirements,$v['id']);
|
|
}
|
|
$requirements = '['.join(',',$arr_requirements).']';
|
|
|
|
$sql = "INSERT INTO t_ordersamplereq(
|
|
T_OrderSampleReqT_OrderHeaderID,
|
|
T_OrderSampleReqT_SampleStationID,
|
|
T_OrderSampleReqT_OrderSampleID,
|
|
T_OrderSampleReqNat_PositionID,
|
|
T_OrderSampleReqStatus,
|
|
T_OrderSampleReqs,
|
|
T_OrderSampleReqUserID,
|
|
T_OrderSampleReqCreated
|
|
)
|
|
VALUES(
|
|
{$prm['sample']['T_OrderHeaderID']},
|
|
{$prm['stationid']},
|
|
{$prm['sample']['T_OrderSampleID']},
|
|
{$prm['sample']['requirements'][0]['positionid']},
|
|
'{$prm['sample']['requirement_status']}',
|
|
'{$requirements}',
|
|
{$userid},
|
|
NOW()
|
|
)ON DUPLICATE KEY UPDATE
|
|
T_OrderSampleReqStatus = '{$prm['sample']['requirement_status']}',
|
|
T_OrderSampleReqs = '{$requirements}',
|
|
T_OrderSampleReqUserID = {$userid}";
|
|
//echo $sql;
|
|
$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_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderHeaderID AND T_BarcodeLabT_SampleTypeID = T_SampleTypeID
|
|
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
|
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$prm['stationid']}
|
|
LEFT JOIN t_ordersample ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_OrderSampleT_SampleTypeID = T_SampleTypeID AND
|
|
T_OrderSampleT_BarcodeLabID = T_BarcodeLabID AND
|
|
T_OrderSampleIsActive = 'Y'
|
|
WHERE
|
|
T_OrderHeaderID = {$prm['id']} AND T_OrderSampleT_SampleTypeID <> {$prm['sample']['T_SampleTypeID']} AND
|
|
T_OrderSampleReceive = 'N' AND T_OrderHeaderIsActive = 'Y'
|
|
GROUP BY T_BarcodeLabID ) xx";
|
|
//echo $sql;
|
|
$xcount = $this->db_onedev->query($sql)->row()->xcount;
|
|
$rst_data = array('status'=>'PARTIAL');
|
|
if($xcount == 0){
|
|
$next_status = 5;
|
|
$rst_data = array('status'=>'OK');
|
|
}
|
|
}
|
|
|
|
if($prm['act'] !== 'samplingprocess' && $status_call['status'] == 'OK'){
|
|
$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);
|
|
}
|
|
|
|
if($status_call['status'] == 'NOTCALL'){
|
|
$rst_data = $status_call;
|
|
}
|
|
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => $rst_data
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
exit;
|
|
}
|
|
|
|
function addnewlabel(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rst_data = array('status'=>'OK');
|
|
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$exp_barcode = explode(".",$prm["sample"]["T_BarcodeLabBarcode"]);
|
|
$new_counter = intval($exp_barcode[2])+1;
|
|
$new_label = $exp_barcode[0].".".$exp_barcode[1].".".$new_counter ;
|
|
$sql = "INSERT INTO t_barcodelab (
|
|
T_BarcodeLabT_OrderHeaderID ,
|
|
T_BarcodeLabBarcode,
|
|
T_BarcodeLabT_SampleTypeID,
|
|
T_BarcodeLabUserID
|
|
)
|
|
VALUES(
|
|
{$prm['sample']['T_OrderHeaderID']},
|
|
'{$new_label}',
|
|
{$prm['sample']['T_SampleTypeID']},
|
|
{$userid}
|
|
)";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => $rst_data
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
exit;
|
|
}
|
|
|
|
function getdatanoterequirement(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rst_data = array();
|
|
$prm = $this->sys_input;
|
|
|
|
|
|
|
|
$sql = "SELECT 'fo registration' as position,GROUP_CONCAT(DISTINCT Nat_RequirementName separator ',') as requirements
|
|
FROM t_orderheader
|
|
JOIN t_orderreq ON T_OrderReqT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN nat_requirement ON json_contains(T_OrderReqs,Nat_RequirementID)
|
|
WHERE T_OrderHeaderID = {$prm['T_OrderHeaderID']}
|
|
GROUP BY T_OrderHeaderID";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql)->row_array();
|
|
if($query){
|
|
array_push($rst_data,$query);
|
|
}
|
|
|
|
$sql = "SELECT 'fo verifikasi' as position, GROUP_CONCAT(DISTINCT Fo_VerificationsLabelName separator ',') as requirements
|
|
FROM fo_verificationsvalue
|
|
JOIN fo_verificationslabel ON Fo_VerificationsValueFo_VerificationsLabelID = Fo_VerificationsLabelID
|
|
WHERE
|
|
Fo_VerificationsValueCheck = 'N' AND
|
|
Fo_VerificationsValueT_OrderHeaderID = {$prm['T_OrderHeaderID']}
|
|
GROUP BY Fo_VerificationsValueT_OrderHeaderID
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql)->row_array();
|
|
if($query){
|
|
array_push($rst_data,$query);
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => $rst_data
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
exit;
|
|
}
|
|
|
|
function savenotesampling(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rst_data = array();
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "UPDATE t_orderheader SET T_OrderHeaderSamplingNote = '{$prm['sampling_note']}' WHERE T_OrderHeaderID = {$prm['T_OrderHeaderID']}";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => $rst_data
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
exit;
|
|
}
|
|
|
|
} |