1311 lines
56 KiB
PHP
1311 lines
56 KiB
PHP
<?php
|
|
class Tat extends CI_Controller
|
|
{
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->db = $this->load->database("onedev", true);
|
|
}
|
|
function lab($prm_date) {
|
|
$sql = "select T_OrderHeaderID, M_StatusName, Fo_StatusDate, Fo_StatusM_UserID,
|
|
T_TestID
|
|
from t_orderheader
|
|
join fo_status on Fo_StatusT_OrderHeaderID = T_OrderHeaderID
|
|
and Fo_StatusM_StatusID in ( 1,3,5 )
|
|
join m_status on Fo_StatusM_StatusID = M_StatusID
|
|
join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID and
|
|
T_OrderHeaderIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_test_tat on T_OrderDetailT_TestID = T_TestTatT_TestID and T_TestTatIsActive = 'Y'
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
and T_TestIsNonLab = ''
|
|
group by T_OrderHeaderID,T_TestID,M_StatusID";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
$data = array();
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_TestID"];
|
|
$testID= $r["T_TestID"];
|
|
$status = $r["M_StatusName"];
|
|
$date = $r["Fo_StatusDate"];
|
|
$userID = $r["Fo_StatusM_UserID"];
|
|
if ($date == "") continue;
|
|
if(! isset($data[$idx]) && $date != "" ) {
|
|
$data[$idx] = array();
|
|
}
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
$tot = count($rows);
|
|
echo "FO : $tot records\n";
|
|
//payment
|
|
$sql = "select T_OrderHeaderID , F_PaymentM_UserID, F_PaymentCreated, T_TestID
|
|
from t_orderheader
|
|
join f_payment on F_PaymentT_OrderHeaderID= T_OrderHeaderID and F_PaymentIsActive = 'Y'
|
|
and date(T_OrderHeaderDate) = ? and T_OrderHeaderIsActive = 'Y'
|
|
join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID and
|
|
T_OrderHeaderIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
join t_test_tat on T_OrderDetailT_TestID = T_TestTatT_TestID and T_TestTatIsActive = 'Y'
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
group by T_OrderHeaderID,T_TestID";
|
|
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_TestID"];
|
|
$status = "Payment";
|
|
$date = $r["F_PaymentCreated"];
|
|
if ($date == "") continue;
|
|
if ($date == "0000-00-00 00:00:00") continue;
|
|
$userID = $r["F_PaymentM_UserID"];
|
|
if (isset($data[$idx])) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
$tot = count($rows);
|
|
echo "Payment : $tot records\n";
|
|
//call time
|
|
$sql = "select * from t_sampling_queue_by_action
|
|
where date(T_SamplingQueueByActionCreated) = ? and T_SamplingQueueByActionT_SampleStationID =1
|
|
and T_SamplingQueueByActionT_SamplingQueueStatusID=1";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$orderHeaderID = $r["T_SamplingQueueByActionT_OrderHeaderID"];
|
|
$userID = $r["T_SamplingQueueByActionUserID"];
|
|
$date = $r["T_SamplingQueueByActionCreated"];
|
|
foreach($data as $idx => $v) {
|
|
$xid = explode("-",$idx)[0];
|
|
if ($xid == $orderHeaderID ) {
|
|
$data[$idx]["Call"] = array("date" => $date , "userID" => $userID );
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
$tot = count($rows);
|
|
echo "Calling : $tot records\n";
|
|
//sampling status
|
|
$sql = "select
|
|
T_OrderHeaderID,T_OrderDetailT_TestID,T_OrderSampleSamplingUserID,T_TestID,
|
|
ifnull(concat(T_OrderSampleSamplingDate,' ', T_OrderSampleSamplingTime),'') as Tanggal
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_test_tat on T_TestTatT_TestID = T_OrderDetailT_TestID
|
|
join t_test on T_TestTatT_TestID = T_TestID and
|
|
T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y' and T_TestIsResult = 'Y'
|
|
join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID
|
|
join t_ordersample on T_OrderSampleT_OrderHeaderID = T_OrderHeaderID and T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_TestID"];
|
|
$status = "Sampling";
|
|
$date = $r["Tanggal"];
|
|
if ($date == "") continue;
|
|
$userID = $r["T_OrderSampleSamplingUserID"];
|
|
if (isset($data[$idx])) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
$tot = count($rows);
|
|
echo "Sampling : $tot records\n";
|
|
//receive
|
|
$sql = "select T_OrderHeaderID , T_OrderDetailT_TestID,T_TestID
|
|
T_OrderSampleReceiveUserID,
|
|
ifnull(concat(T_OrderSampleReceiveDate,' ', T_OrderSampleReceiveTime),'') as Tanggal
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_test_tat on T_TestTatT_TestID = T_OrderDetailT_TestID
|
|
join t_test on T_TestTatT_TestID = T_TestID and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y' and T_TestIsResult = 'Y'
|
|
join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID
|
|
join t_ordersample on T_OrderSampleT_OrderHeaderID = T_OrderHeaderID and T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $testID;
|
|
$status = "Receive";
|
|
$date = $r["Tanggal"];
|
|
if ($date == "") continue;
|
|
$userID = $r["T_OrderSampleReceiveUserID"];
|
|
if (isset($data[$idx])) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
$tot = count($rows);
|
|
echo "Receive : $tot records\n";
|
|
//verification
|
|
$sql = "select
|
|
T_OrderHeaderID , T_OrderDetailT_TestID, T_OrderSampleVerificationUserID,T_TestID,
|
|
ifnull(concat(T_OrderSampleVerificationDate,' ', T_OrderSampleVerificationTime),'') as Tanggal
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_test_tat on T_TestTatT_TestID = T_OrderDetailT_TestID
|
|
join t_test on T_TestTatT_TestID = T_TestID and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y' and T_TestIsResult = 'Y'
|
|
join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID
|
|
join t_ordersample on T_OrderSampleT_OrderHeaderID = T_OrderHeaderID and T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_TestID"];
|
|
$status = "Verification";
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$date = $r["Tanggal"];
|
|
if ($date == "") continue;
|
|
$userID = $r["T_OrderSampleVerificationUserID"];
|
|
if (isset($data[$idx])) {
|
|
if(!isset($data[$idx])) continue;
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
$tot = count($rows);
|
|
echo "Verification : $tot records\n";
|
|
|
|
//send handling
|
|
$sql="select T_OrderHeaderID , T_OrderDetailT_TestID, T_OrderSampleSendHandlingUserID,T_TestID,
|
|
ifnull(concat(T_OrderSampleSendHandlingDate,' ', T_OrderSampleSendHandlingTime),'') as Tanggal
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_test_tat on T_TestTatT_TestID = T_OrderDetailT_TestID
|
|
join t_test on T_TestTatT_TestID = T_TestID and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y' and T_TestIsResult = 'Y'
|
|
join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID
|
|
join t_ordersample on T_OrderSampleT_OrderHeaderID = T_OrderHeaderID and T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_TestID"];
|
|
$status = "SendHandling";
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$date = $r["Tanggal"];
|
|
if ($date == "") continue;
|
|
$userID = $r["T_OrderSampleSendHandlingUserID"];
|
|
if (isset($data[$idx])) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
$tot = count($rows);
|
|
echo "Send Handling : $tot records\n";
|
|
|
|
//receive handling
|
|
$sql="select
|
|
T_OrderHeaderID , T_OrderDetailT_TestID, T_OrderSampleReceiveHandlingUserID,
|
|
ifnull(concat(T_OrderSampleReceiveHandlingDate,' ', T_OrderSampleReceiveHandlingTime),'') as Tanggal
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_test_tat on T_TestTatT_TestID = T_OrderDetailT_TestID
|
|
join t_test on T_TestTatT_TestID = T_TestID and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y' and T_TestIsResult = 'Y'
|
|
join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID
|
|
join t_ordersample on T_OrderSampleT_OrderHeaderID = T_OrderHeaderID and T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$idx = $r["T_OrderHeaderID"] . "-$testID";
|
|
$status = "ReceiveHandling";
|
|
$date = $r["Tanggal"];
|
|
if ($date == "") continue;
|
|
$userID = $r["T_OrderSampleReceiveHandlingUserID"];
|
|
if (isset($data[$idx])) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
|
|
$tot = count($rows);
|
|
echo "ReceiveHandling : $tot records\n";
|
|
|
|
//handling
|
|
$sql="select T_OrderHeaderID , T_OrderDetailT_TestID, T_OrderSampleHandlingUserID,
|
|
ifnull(concat(T_OrderSampleHandlingDate,' ', T_OrderSampleHandlingTime),'') as Tanggal
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_test_tat on T_TestTatT_TestID = T_OrderDetailT_TestID
|
|
join t_test on T_TestTatT_TestID = T_TestID and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y' and T_TestIsResult = 'Y'
|
|
join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID
|
|
join t_ordersample on T_OrderSampleT_OrderHeaderID = T_OrderHeaderID and T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$idx = $r["T_OrderHeaderID"] ."-$testID";
|
|
$status = "Handling";
|
|
$date = $r["Tanggal"];
|
|
if ($date == "") continue;
|
|
$userID = $r["T_OrderSampleHandlingUserID"];
|
|
if (isset($data[$idx])) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
|
|
$tot = count($rows);
|
|
echo "Handling : $tot records\n";
|
|
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,T_OrderSampleProcessingUserID,
|
|
ifnull(concat(T_OrderSampleProcessingDate,' ', T_OrderSampleProcessingTime),'') as Tanggal
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_test_tat on T_TestTatT_TestID = T_OrderDetailT_TestID
|
|
join t_test on T_TestTatT_TestID = T_TestID and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y' and T_TestIsResult = 'Y'
|
|
join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID
|
|
join t_ordersample on T_OrderSampleT_OrderHeaderID = T_OrderHeaderID and T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$idx = $r["T_OrderHeaderID"] ."-$testID";
|
|
$status = "Processing";
|
|
$date = $r["Tanggal"];
|
|
if ($date == "") continue;
|
|
$userID = $r["T_OrderSampleProcessingUserID"];
|
|
if (isset($data[$idx])) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
|
|
$tot = count($rows);
|
|
echo "Processing : $tot records\n";
|
|
|
|
//worklist
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,T_OrderSampleWorklistReceiveUserID,
|
|
T_OrderSampleWorklistReceiveDatetime Tanggal
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_orderdetailaddon on T_OrderDetailID = T_OrderDetailAddonT_OrderDetailID
|
|
join t_test_tat on T_TestTatT_TestID = T_OrderDetailT_TestID
|
|
join t_test on T_TestTatT_TestID = T_TestID and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y' and T_TestIsResult = 'Y'
|
|
join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID
|
|
join t_ordersample on T_OrderSampleT_OrderHeaderID = T_OrderHeaderID and T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$idx = $r["T_OrderHeaderID"] ."-$testID";
|
|
$status = "Worklist";
|
|
$date = $r["Tanggal"];
|
|
if ($date == "") continue;
|
|
$userID = $r["T_OrderSampleWorklistReceiveUserID"];
|
|
if (isset($data[$idx])) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
|
|
$tot = count($rows);
|
|
echo "Worklist : $tot records\n";
|
|
//PreAnalytic
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID, T_TestNat_TestID,
|
|
ifnull(PreAnalyticCreated,'') PreAnalyticDate,
|
|
PreAnalyticUserID,
|
|
-- ifnull(PreAnalyticCreated,'') PreAnalyticDate,
|
|
-- ifnull(Log_WorklistUserID,0) PreAnalyticUserID,
|
|
PreAnalyticT_WorklistID
|
|
-- , Log_WorklistJson
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_test_tat on T_TestTatT_TestID = T_OrderDetailT_TestID
|
|
join t_test on T_TestTatT_TestID = T_TestID and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
|
join pre_analytic on T_TestNat_TestID = PreAnalyticNat_TestID and
|
|
date(PreAnalyticCreated) = ?
|
|
-- join one_log.log_worklist on Log_WorklistCode = 'PRE.ANALYTIC'
|
|
-- and date(Log_WorklistDate) = ?
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date,$prm_date,$prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$idx = $r["T_OrderHeaderID"] . "-$testID";
|
|
$status = "PreAnalytic";
|
|
$worklistID = $r["PreAnalyticT_WorklistID"];
|
|
$natTestID = $r["T_TestNat_TestID"];
|
|
if (isset($data[$idx])) {
|
|
$data[$idx]["PreAnalytic"] = array("date"=>$r["PreAnalyticDate"],
|
|
"userID" => $r["PreAnalyticUserID"]);
|
|
} else {
|
|
//$data[$idx] = array();
|
|
//$data[$idx]["PreAnalytic"] = array("date"=>$r["PreAnalyticDate"],
|
|
// "userID" => $r["PreAnalyticUserID"]);
|
|
}
|
|
/*
|
|
$json = json_decode($r["Log_WorklistJson"], true);
|
|
if (isset($data[$idx])) {
|
|
$j_testID = $json["T_TestID"];
|
|
$j_worklistID = $json["T_WorklistID"];
|
|
if($worklistID != $j_worklistID ) continue;
|
|
if($natTestID != $j_testID ) continue;
|
|
//if ( $r["PreAnalyticDate"] != '' ) {
|
|
$data[$idx]["PreAnalytic"] = array("date"=>$r["PreAnalyticDate"],
|
|
"userID" => $r["PreAnalyticUserID"]);
|
|
//}
|
|
}
|
|
*/
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
|
|
$tot = count($rows);
|
|
echo "Pre Analytic : $tot records\n";
|
|
//ResultEntry
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,Log_ProcessCode,
|
|
Log_ProcessDate, Log_ProcessUserID, Log_ProcessJson
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join one_log.log_process on T_OrderHeaderID = Log_ProcessOrderID
|
|
and Log_ProcessCode='PROCESS.Result.Entry'
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$idx = $r["T_OrderHeaderID"] . "-$testID";
|
|
$date = $r["Log_ProcessDate"];
|
|
if ($date == "") continue;
|
|
$status = $r["Log_ProcessCode"];
|
|
$userID = $r["Log_ProcessUserID"];
|
|
if (isset($data[$idx])) {
|
|
$json = json_decode($r["Log_ProcessJson"], true);
|
|
foreach($json as $j) {
|
|
if ($testID == $j["test_id"]) {
|
|
if(!isset($data[$idx])) continue;
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
|
|
//verif
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,
|
|
T_OrderDetailVerification, T_OrderDetailVerDate, T_OrderDetailVerUserID,
|
|
T_OrderDetailValidation, T_OrderDetailValDate, T_OrderDetailValUserID
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$idx = $r["T_OrderHeaderID"] . "-$testID";
|
|
if($r["T_OrderDetailVerification"] == "Y") {
|
|
if (isset($data[$idx])) {
|
|
$date = $r["T_OrderDetailVerDate"];
|
|
$status = "R.Verification";
|
|
$userID = $r["T_OrderDetailVerUserID"];
|
|
if ($date != "" ) $data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
if($r["T_OrderDetailValidation"] == "Y") {
|
|
if (isset($data[$idx])) {
|
|
$date = $r["T_OrderDetailValDate"];
|
|
$status = "R.Validation";
|
|
$userID = $r["T_OrderDetailValUserID"];
|
|
if ($date != "" ) $data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
|
|
// send to adm
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join one_log.log_printlab on T_OrderHeaderID = Log_PrintLabT_OrderHeaderID
|
|
and Log_PrintLabCode = 'SEND.TO.ADM'
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "_" . $r["T_OrderDetailT_TestID"];
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$date = $r["Log_PrintlabDate"];
|
|
$status = "SendAdm";
|
|
$userID = $r["Log_ProcessUserID"];
|
|
if (isset($data[$idx])) {
|
|
$json = json_decode($r["Log_ProcessJson"], true);
|
|
foreach($json as $j) {
|
|
if ($testID == $j["test_id"]) {
|
|
if(!isset($data[$idx])) continue;
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//sent from back office
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,
|
|
Result_ProcessToOfficeSendTime, ifnull(Result_ProcessToOfficeSendBy,0) Result_ProcessToOfficeSendBy,
|
|
Result_ProcessToOfficeReceiveTime, ifnull(Result_ProcessToOfficeReceivedBy,0) Result_ProcessToOfficeReceivedBy
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderHeaderIsActive = 'Y'
|
|
and T_OrderDetailIsActive = 'Y' and date(T_OrderHeaderDate) = ?
|
|
join result_processtooffice on Result_ProcessToOfficeT_OrderHeaderID = T_OrderHeaderID
|
|
and Result_ProcessToOfficeIsActive = 'Y'
|
|
join group_result on Result_ProcessToOfficeGroup_ResultID = Group_ResultID
|
|
and Group_ResultFlagPerTest = 'N'
|
|
join group_resultdetail on Group_ResultID = Group_ResultDetailGroup_ResultID
|
|
and T_OrderDetailT_TestID = Group_ResultDetailT_TestID
|
|
";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_OrderDetailT_TestID"];
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
if (isset($data[$idx])) {
|
|
$date = $r["Result_ProcessToOfficeSendTime"];
|
|
$status = "ADM.Send";
|
|
$userID = $r["Result_ProcessToOfficeSendBy"];
|
|
if($userID > 0 ) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
$date = $r["Result_ProcessToOfficeReceiveTime"];
|
|
$status = "FO.Receive";
|
|
$userID = $r["Result_ProcessToOfficeReceivedBy"];
|
|
if($userID > 0 ) {
|
|
if(!isset($data[$idx])) continue;
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//pasien
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,
|
|
Result_HandOverPatientUserID, Result_HandOverPatientCreated
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderHeaderIsActive = 'Y'
|
|
and T_OrderDetailIsActive = 'Y' and date(T_OrderHeaderDate) = ?
|
|
join result_handoverpatient on Result_HandOverPatientT_OrderHeaderID = T_OrderHeaderID
|
|
and Result_HandOverPatientIsActive = 'Y' and Result_HandOverPatientT_OrderPromiseID = T_OrderDetailT_OrderPromiseID
|
|
";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_OrderDetailT_TestID"];
|
|
if (isset($data[$idx])) {
|
|
$date = $r["Result_HandOverPatientCreated"];
|
|
$status = "Patient.Receive";
|
|
$userID = $r["Result_HandOverPatientUserID"];
|
|
if($userID > 0 ) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//kurir berangkat
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,
|
|
Result_CourierDetailStepByStepUserID,Result_CourierDetailStepByStepLastUpdated,
|
|
Result_CourierDetailStepByStepStatus Status
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderHeaderIsActive = 'Y'
|
|
and T_OrderDetailIsActive = 'Y' and date(T_OrderHeaderDate) = ?
|
|
join result_courierspk_detail on Result_CourierSPKDetailT_OrderPromiseID = T_OrderDetailT_OrderPromiseID
|
|
and Result_CourierSPKDetailIsActive = 'Y'
|
|
join result_courierspk_detail_step_by_step on Result_CourierDetailStepByStepResult_CourierSPKDetailID =
|
|
Result_CourierSPKDetailID and (Result_CourierDetailStepByStepStatus = 'S' or Result_CourierDetailStepByStepStatus ='D')
|
|
group by T_OrderHeaderID,T_OrderDetailT_TestID,Status ";
|
|
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_OrderDetailT_TestID"];
|
|
if (isset($data[$idx])) {
|
|
$date = $r["Result_CourierDetailStepByStepLastUpdated"];
|
|
$status = "Courier.Done";
|
|
if ($r["Status"] == 'S' ) $status = "Courier.Go";
|
|
$userID = $r["Result_CourierDetailStepByStepUserID"];
|
|
if($userID > 0 ) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$sql = "delete from ss_tat_lab where ss_TatLabDate = ?";
|
|
$this->db->query($sql,array($prm_date));
|
|
|
|
foreach($data as $idx => $d ) {
|
|
$arr = explode("-",$idx);
|
|
$orderHeaderID = $arr[0];
|
|
$testID = $arr[1];
|
|
$param = array();
|
|
$param[] = $prm_date;
|
|
$param[] = $orderHeaderID;
|
|
$param[] = $testID;
|
|
$sql = "insert into ss_tat_lab(ss_TatLabDate, ss_TatLabT_OrderHeaderID, ss_TatLabT_TestID ";
|
|
$vals = "values(?,?,?";
|
|
|
|
$reg = $d["FO.Registration"];
|
|
$sql .= ",ss_TatLabFO_RegUserID,ss_TatLabFO_RegDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
|
|
if (isset($d["Payment"]) ) {
|
|
$reg = $d["Payment"];
|
|
$sql .= ",ss_TatLabFO_PaymentUserID,ss_TatLabFO_PaymentDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
|
|
if (isset($d["Call"]) ) {
|
|
$reg = $d["Call"];
|
|
$sql .= ",ss_TatLabCallUserID,ss_TatLabCallDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["FO.Verification.Confirm"]) ) {
|
|
$reg = $d["FO.Verification.Confirm"];
|
|
$sql .= ",ss_TatLabFO_VerifUserID,ss_TatLabFO_VerifDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
|
|
if (isset($d["FO.Verification.SPV.Confirm"]) ) {
|
|
$reg = $d["FO.Verification.SPV.Confirm"];
|
|
$sql .= ",ss_TatLabFO_VerifUserID,ss_TatLabFO_VerifDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
|
|
if (isset($d["Sampling"]) ) {
|
|
$reg = $d["Sampling"];
|
|
$sql .= ",ss_TatLabSamplingUserID,ss_TatLabSamplingDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Receive"]) ) {
|
|
$reg = $d["Receive"];
|
|
$sql .= ",ss_TatLabReceiveUserID,ss_TatLabReceiveDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Verification"]) ) {
|
|
$reg = $d["Verification"];
|
|
$sql .= ",ss_TatLabVerificationUserID,ss_TatLabVerificationDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["SendHandling"]) ) {
|
|
$reg = $d["SendHandling"];
|
|
$sql .= ",ss_TatLabSendHandlingUserID,ss_TatLabSendHandlingDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["ReceiveHandling"]) ) {
|
|
$reg = $d["ReceiveHandling"];
|
|
$sql .= ",ss_TatLabReceiveHandlingUserID,ss_TatLabReceiveHandlingDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Handling"]) ) {
|
|
$reg = $d["Handling"];
|
|
$sql .= ",ss_TatLabHandlingUserID,ss_TatLabHandlingDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Processing"]) ) {
|
|
$reg = $d["Processing"];
|
|
$sql .= ",ss_TatLabProcessingUserID,ss_TatLabProcessingDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["PreAnalytic"]) ) {
|
|
$reg = $d["PreAnalytic"];
|
|
$sql .= ",ss_TatLabPreAnalyticUserID,ss_TatLabPreAnalyticDate";
|
|
$vals .= ",?,?";
|
|
if ($reg["userID"] == "" ) $reg["userID"] = 0;
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Worklist"]) ) {
|
|
$reg = $d["Worklist"];
|
|
$sql .= ",ss_TatLabWorklistUserID,ss_TatLabWorklistDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
|
|
if (isset($d["PROCESS.Result.Entry"]) ) {
|
|
$reg = $d["PROCESS.Result.Entry"];
|
|
$sql .= ",ss_TatLabResultEntryUserID,ss_TatLabResultEntryDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["R.Verification"]) ) {
|
|
$reg = $d["R.Verification"];
|
|
$sql .= ",ss_TatLabVerificationLabUserID,ss_TatLabVerificationLabDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["R.Validation"]) ) {
|
|
$reg = $d["R.Validation"];
|
|
$sql .= ",ss_TatLabValidationLabUserID,ss_TatLabValidationLabDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["ADM.Send"]) ) {
|
|
$reg = $d["ADM.Send"];
|
|
$sql .= ",ss_TatLabCetakUserID,ss_TatLabCetakDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["FO.Receive"]) ) {
|
|
$reg = $d["FO.Receive"];
|
|
$sql .= ",ss_TatLabTerimaFOUserID,ss_TatLabTerimaFODate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Courier.Go"]) ) {
|
|
$reg = $d["Courier.Go"];
|
|
$sql .= ",ss_TatLabSendKurirUserID,ss_TatLabSendKurirDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Courier.Done"]) ) {
|
|
$reg = $d["Courier.Done"];
|
|
$sql .= ",ss_TatLabTerimaPasienUserID,ss_TatLabTerimaPasienDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Patient.Receive"]) ) {
|
|
$reg = $d["Patient.Receive"];
|
|
$sql .= ",ss_TatLabTerimaPasienUserID,ss_TatLabTerimaPasienDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
$sql .= ") $vals )";
|
|
$qry = $this->db->query($sql,$param);
|
|
if (! $qry ) {
|
|
echo "ERR : " . print_r( $this->db->error(), true) . "\n";
|
|
exit;
|
|
}
|
|
echo "inserting ... " . $orderHeaderID . " : $testID \n";
|
|
}
|
|
|
|
}
|
|
function nonlab($prm_date) {
|
|
$sql = "select T_OrderHeaderID, M_StatusName, Fo_StatusDate, Fo_StatusM_UserID,
|
|
T_TestID
|
|
from t_orderheader
|
|
join fo_status on Fo_StatusT_OrderHeaderID = T_OrderHeaderID
|
|
and Fo_StatusM_StatusID in ( 1,3,5 )
|
|
join m_status on Fo_StatusM_StatusID = M_StatusID
|
|
join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID and
|
|
T_OrderHeaderIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_test_tat on T_OrderDetailT_TestID = T_TestTatT_TestID and T_TestTatIsActive = 'Y'
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
and T_TestIsNonLab <> ''
|
|
group by T_OrderHeaderID,T_TestID,M_StatusID";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
$data = array();
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_TestID"];
|
|
$testID= $r["T_TestID"];
|
|
$status = $r["M_StatusName"];
|
|
$date = $r["Fo_StatusDate"];
|
|
$userID = $r["Fo_StatusM_UserID"];
|
|
if ($date == "") continue;
|
|
if(! isset($data[$idx]) && $date != "" ) {
|
|
$data[$idx] = array();
|
|
}
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
$tot = count($rows);
|
|
echo "FO : $tot records\n";
|
|
//payment
|
|
$sql = "select T_OrderHeaderID , F_PaymentM_UserID, F_PaymentCreated, T_TestID
|
|
from t_orderheader
|
|
join f_payment on F_PaymentT_OrderHeaderID= T_OrderHeaderID and F_PaymentIsActive = 'Y'
|
|
and date(T_OrderHeaderDate) = ? and T_OrderHeaderIsActive = 'Y'
|
|
join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID and
|
|
T_OrderHeaderIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
join t_test_tat on T_OrderDetailT_TestID = T_TestTatT_TestID and T_TestTatIsActive = 'Y'
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
group by T_OrderHeaderID,T_TestID";
|
|
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_TestID"];
|
|
$status = "Payment";
|
|
$date = $r["F_PaymentCreated"];
|
|
if ($date == "") continue;
|
|
if ($date == "0000-00-00 00:00:00") continue;
|
|
$userID = $r["F_PaymentM_UserID"];
|
|
if (isset($data[$idx])) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
$tot = count($rows);
|
|
echo "Payment : $tot records\n";
|
|
//call time
|
|
$sql = "select * from t_sampling_queue_by_action
|
|
where date(T_SamplingQueueByActionCreated) = ? and T_SamplingQueueByActionT_SampleStationID >1
|
|
and T_SamplingQueueByActionT_SamplingQueueStatusID=1";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$orderHeaderID = $r["T_SamplingQueueByActionT_OrderHeaderID"];
|
|
$userID = $r["T_SamplingQueueByActionUserID"];
|
|
$date = $r["T_SamplingQueueByActionCreated"];
|
|
foreach($data as $idx => $v) {
|
|
$xid = explode("-",$idx)[0];
|
|
if ($xid == $orderHeaderID ) {
|
|
$data[$idx]["Call"] = array("date" => $date , "userID" => $userID );
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
$tot = count($rows);
|
|
echo "Calling : $tot records\n";
|
|
|
|
|
|
//sampling status
|
|
$sql = "select
|
|
T_OrderHeaderID,T_OrderDetailT_TestID,T_TestID,
|
|
concat(T_SamplingSoProcessDate,' ',T_SamplingSoProcessTime) ProcessDate,
|
|
ifnull(T_SamplingSoProcessUserID,0) ProcessUserID,
|
|
concat(T_SamplingSoDoneDate,' ',T_SamplingSoDoneTime) DoneDate,
|
|
ifnull(T_SamplingSoDoneUserID,0) DoneUserID,
|
|
concat(T_SamplingSoVerifyDate,' ',T_SamplingSoVerifyTime) VerifyDate,
|
|
ifnull(T_SamplingSoVerifyUserID,0) VerifyUserID,
|
|
concat(T_SamplingSoSendAdmDate,' ',T_SamplingSoSendAdmTime) SendAdmDate,
|
|
ifnull(T_SamplingSoSendAdmUserID,0) SendAdmUserID,
|
|
concat(T_SamplingSoReceiveAdmDate,' ',T_SamplingSoReceiveAdmTime) ReceiveAdmDate,
|
|
ifnull(T_SamplingSoReceiveAdmUserID,0) ReceiveAdmUserID,
|
|
T_OrderDetailVerification, T_OrderDetailVerDate, T_OrderDetailVerUserID,
|
|
T_OrderDetailValidation, T_OrderDetailValDate, T_OrderDetailValUserID,
|
|
T_TestID
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_test_tat on T_TestTatT_TestID = T_OrderDetailT_TestID
|
|
and T_OrderHeaderIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
join t_test on T_TestTatT_TestID = T_TestID and
|
|
T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y' and T_TestIsResult = 'Y'
|
|
join t_samplingso on T_SamplingSoT_OrderHeaderID = T_OrderHeaderID and
|
|
T_SamplingSoT_TestID = T_TestID and T_SamplingSoIsActive = 'Y'
|
|
where T_OrderHeaderIsActive = 'Y'
|
|
group by T_OrderHeaderID, T_TestID";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_TestID"];
|
|
if (! isset($data[$idx])) continue;
|
|
if ($r["ProcessUserID"] > 0 ) {
|
|
$status = "Process";
|
|
$date = $r["ProcessDate"];
|
|
if ($date != "") {
|
|
$userID = $r["ProcessUserID"];
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
if ($r["DoneUserID"] > 0 ) {
|
|
$status = "Done";
|
|
$date = $r["DoneDate"];
|
|
if ($date != "") {
|
|
$userID = $r["DoneUserID"];
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
if ($r["VerifyUserID"] > 0 ) {
|
|
$status = "Verify";
|
|
$date = $r["VerifyDate"];
|
|
if ($date != "") {
|
|
$userID = $r["VerifyUserID"];
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
|
|
if ($r["SendAdmUserID"] > 0 ) {
|
|
$status = "SendAdm";
|
|
$date = $r["SendAdmDate"];
|
|
if ($date != "") {
|
|
$userID = $r["SendAdmUserID"];
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
if ($r["ReceiveAdmUserID"] > 0 ) {
|
|
$status = "ReceiveAdm";
|
|
$date = $r["ReceiveAdmDate"];
|
|
if ($date != "") {
|
|
$userID = $r["ReceiveAdmUserID"];
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
if(isset($r["Verification"]) && $r["Verification"] == "Y" ) {
|
|
$status = "Verification";
|
|
$date = $r["T_OrderDetailVerDate"];
|
|
if ($date != "") {
|
|
$userID = $r["T_OrderDetailVerUserID"];
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
if (isset($r["Validation"]) && $r["Validation"] == "Y" ) {
|
|
$status = "Validation";
|
|
$date = $r["T_OrderDetailValDate"];
|
|
if ($date != "") {
|
|
$userID = $r["T_OrderDetailValUserID"];
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$tot = count($rows);
|
|
echo "Sampling : $tot records\n";
|
|
|
|
//ResultEntry
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,Log_ProcessCode,
|
|
Log_ProcessDate, Log_ProcessUserID, Log_ProcessJson
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join one_log.log_process on T_OrderHeaderID = Log_ProcessOrderID
|
|
and Log_ProcessCode='PROCESS.Result.Entry'
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$idx = $r["T_OrderHeaderID"] . "-$testID";
|
|
$date = $r["Log_ProcessDate"];
|
|
if ($date == "") continue;
|
|
$status = $r["Log_ProcessCode"];
|
|
$userID = $r["Log_ProcessUserID"];
|
|
if (isset($data[$idx])) {
|
|
$json = json_decode($r["Log_ProcessJson"], true);
|
|
foreach($json as $j) {
|
|
if ($testID == $j["test_id"]) {
|
|
if(!isset($data[$idx])) continue;
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//verif
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,
|
|
T_OrderDetailVerification, T_OrderDetailVerDate, T_OrderDetailVerUserID,
|
|
T_OrderDetailValidation, T_OrderDetailValDate, T_OrderDetailValUserID
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsNonLab <> ''
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$idx = $r["T_OrderHeaderID"] . "-$testID";
|
|
if($r["T_OrderDetailVerification"] == "Y") {
|
|
if (isset($data[$idx])) {
|
|
$date = $r["T_OrderDetailVerDate"];
|
|
$status = "R.Verification";
|
|
$userID = $r["T_OrderDetailVerUserID"];
|
|
if ($date != "" ) $data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
if($r["T_OrderDetailValidation"] == "Y") {
|
|
if (isset($data[$idx])) {
|
|
$date = $r["T_OrderDetailValDate"];
|
|
$status = "R.Validation";
|
|
$userID = $r["T_OrderDetailValUserID"];
|
|
if ($date != "" ) $data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// send to adm
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and date(T_OrderHeaderDate) = ?
|
|
join one_log.log_printlab on T_OrderHeaderID = Log_PrintLabT_OrderHeaderID
|
|
and Log_PrintLabCode = 'SEND.TO.ADM'
|
|
where T_OrderHeaderIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "_" . $r["T_OrderDetailT_TestID"];
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$date = $r["Log_PrintlabDate"];
|
|
$status = "SendAdm";
|
|
$userID = $r["Log_ProcessUserID"];
|
|
if (isset($data[$idx])) {
|
|
$json = json_decode($r["Log_ProcessJson"], true);
|
|
foreach($json as $j) {
|
|
if ($testID == $j["test_id"]) {
|
|
if(!isset($data[$idx])) continue;
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//sent from back office
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,
|
|
Result_ProcessToOfficeSendTime, ifnull(Result_ProcessToOfficeSendBy,0) Result_ProcessToOfficeSendBy,
|
|
Result_ProcessToOfficeReceiveTime, ifnull(Result_ProcessToOfficeReceivedBy,0) Result_ProcessToOfficeReceivedBy
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderHeaderIsActive = 'Y'
|
|
and T_OrderDetailIsActive = 'Y' and date(T_OrderHeaderDate) = ?
|
|
join result_processtooffice on Result_ProcessToOfficeT_OrderHeaderID = T_OrderHeaderID
|
|
and Result_ProcessToOfficeIsActive = 'Y'
|
|
join group_result on Result_ProcessToOfficeGroup_ResultID = Group_ResultID
|
|
and Group_ResultFlagPerTest = 'N'
|
|
join group_resultdetail on Group_ResultID = Group_ResultDetailGroup_ResultID
|
|
and T_OrderDetailT_TestID = Group_ResultDetailT_TestID
|
|
";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_OrderDetailT_TestID"];
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
if (isset($data[$idx])) {
|
|
$date = $r["Result_ProcessToOfficeSendTime"];
|
|
$status = "ADM.Send";
|
|
$userID = $r["Result_ProcessToOfficeSendBy"];
|
|
if($userID > 0 ) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
$date = $r["Result_ProcessToOfficeReceiveTime"];
|
|
$status = "FO.Receive";
|
|
$userID = $r["Result_ProcessToOfficeReceivedBy"];
|
|
if($userID > 0 ) {
|
|
if(!isset($data[$idx])) continue;
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//pasien
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,
|
|
Result_HandOverPatientUserID, Result_HandOverPatientCreated
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderHeaderIsActive = 'Y'
|
|
and T_OrderDetailIsActive = 'Y' and date(T_OrderHeaderDate) = ?
|
|
join result_handoverpatient on Result_HandOverPatientT_OrderHeaderID = T_OrderHeaderID
|
|
and Result_HandOverPatientIsActive = 'Y' and Result_HandOverPatientT_OrderPromiseID = T_OrderDetailT_OrderPromiseID
|
|
";
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_OrderDetailT_TestID"];
|
|
if (isset($data[$idx])) {
|
|
$date = $r["Result_HandOverPatientCreated"];
|
|
$status = "Patient.Receive";
|
|
$userID = $r["Result_HandOverPatientUserID"];
|
|
if($userID > 0 ) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//kurir berangkat
|
|
$sql = "select T_OrderHeaderID, T_OrderDetailT_TestID,
|
|
Result_CourierDetailStepByStepUserID,Result_CourierDetailStepByStepLastUpdated,
|
|
Result_CourierDetailStepByStepStatus Status
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderHeaderIsActive = 'Y'
|
|
and T_OrderDetailIsActive = 'Y' and date(T_OrderHeaderDate) = ?
|
|
join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsNonLab <> ''
|
|
join result_courierspk_detail on Result_CourierSPKDetailT_OrderPromiseID = T_OrderDetailT_OrderPromiseID
|
|
and Result_CourierSPKDetailIsActive = 'Y'
|
|
join result_courierspk_detail_step_by_step on Result_CourierDetailStepByStepResult_CourierSPKDetailID =
|
|
Result_CourierSPKDetailID and (Result_CourierDetailStepByStepStatus = 'S' or Result_CourierDetailStepByStepStatus ='D')
|
|
group by T_OrderHeaderID,T_OrderDetailT_TestID,Status ";
|
|
|
|
$qry = $this->db->query($sql,array($prm_date));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r ) {
|
|
$idx = $r["T_OrderHeaderID"] . "-" . $r["T_OrderDetailT_TestID"];
|
|
if (isset($data[$idx])) {
|
|
$date = $r["Result_CourierDetailStepByStepLastUpdated"];
|
|
$status = "Courier.Done";
|
|
if ($r["Status"] == 'S' ) $status = "Courier.Go";
|
|
$userID = $r["Result_CourierDetailStepByStepUserID"];
|
|
if($userID > 0 ) {
|
|
$data[$idx][$status] = array("date"=>$date, "userID" => $userID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$sql = "delete from ss_tat_nonlab where ss_TatNonLabDate = ?";
|
|
$this->db->query($sql,array($prm_date));
|
|
|
|
|
|
foreach($data as $idx => $d ) {
|
|
$arr = explode("-",$idx);
|
|
$orderHeaderID = $arr[0];
|
|
$testID = $arr[1];
|
|
$param = array();
|
|
$param[] = $prm_date;
|
|
$param[] = $orderHeaderID;
|
|
$param[] = $testID;
|
|
$sql = "insert into ss_tat_nonlab(Ss_TatNonLabDate, Ss_TatNonLabT_OrderHeaderID, Ss_TatNonLabT_TestID ";
|
|
$vals = "values(?,?,?";
|
|
|
|
$reg = $d["FO.Registration"];
|
|
$sql .= ",Ss_TatNonLabFO_RegUserID,Ss_TatNonLabFO_RegDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
|
|
if (isset($d["Payment"]) ) {
|
|
$reg = $d["Payment"];
|
|
$sql .= ",Ss_TatNonLabFO_PaymentUserID,Ss_TatNonLabFO_PaymentDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Call"]) ) {
|
|
$reg = $d["Call"];
|
|
$sql .= ",ss_TatNonLabCallUserID,ss_TatNonLabCallDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["FO.Verification.Confirm"]) ) {
|
|
$reg = $d["FO.Verification.Confirm"];
|
|
$sql .= ",Ss_TatNonLabFO_VerifUserID,Ss_TatNonLabFO_VerifDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
|
|
if (isset($d["FO.Verification.SPV.Confirm"]) ) {
|
|
$reg = $d["FO.Verification.SPV.Confirm"];
|
|
$sql .= ",Ss_TatNonLabFO_VerifUserID,Ss_TatNonLabFO_VerifDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
|
|
if (isset($d["Process"]) ) {
|
|
$reg = $d["Process"];
|
|
$sql .= ",Ss_TatNonLabSoProcessUserID,Ss_TatNonLabSoProcessDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Done"]) ) {
|
|
$reg = $d["Done"];
|
|
$sql .= ",Ss_TatNonLabSoDoneUserID,Ss_TatNonLabSoDoneDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Verify"]) ) {
|
|
$reg = $d["Verify"];
|
|
$sql .= ",Ss_TatNonLabSoVerifyUserID,Ss_TatNonLabSoVerifyDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["SendAdm"]) ) {
|
|
$reg = $d["SendAdm"];
|
|
$sql .= ",Ss_TatNonLabSoSendAdmUserID,Ss_TatNonLabSoSendAdmDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["ReceiveAdm"]) ) {
|
|
$reg = $d["ReceiveAdm"];
|
|
$sql .= ",Ss_TatNonLabSoReceiveAdmUserID,Ss_TatNonLabSoReceiveAdmDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["PROCESS.Result.Entry"]) ) {
|
|
$reg = $d["PROCESS.Result.Entry"];
|
|
$sql .= ",Ss_TatNonLabResultEntryUserID,Ss_TatNonLabResultEntryDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["R.Verification"]) ) {
|
|
$reg = $d["R.Verification"];
|
|
$sql .= ",Ss_TatNonLabSoVerificationUserID,Ss_TatNonLabSoVerificationDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["R.Validation"]) ) {
|
|
$reg = $d["R.Validation"];
|
|
$sql .= ",Ss_TatNonLabSoValidationUserID,Ss_TatNonLabSoValidationDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["ADM.Send"]) ) {
|
|
$reg = $d["ADM.Send"];
|
|
$sql .= ",Ss_TatNonLabSoCetakUserID,Ss_TatNonLabSoCetakDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["FO.Receive"]) ) {
|
|
$reg = $d["FO.Receive"];
|
|
$sql .= ",Ss_TatNonLabSoTerimaFOUserID,Ss_TatNonLabSoTerimaFODate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Courier.Go"]) ) {
|
|
$reg = $d["Courier.Go"];
|
|
$sql .= ",Ss_TatNonLabSendKurirUserID,Ss_TatNonLabSendKurirDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Courier.Done"]) ) {
|
|
$reg = $d["Courier.Done"];
|
|
$sql .= ",Ss_TatNonLabTerimaPasienUserID,Ss_TatNonLabTerimaPasienDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
if (isset($d["Patient.Receive"]) ) {
|
|
$reg = $d["Patient.Receive"];
|
|
$sql .= ",Ss_TatNonLabTerimaPasienUserID,Ss_TatNonLabTerimaPasienDate";
|
|
$vals .= ",?,?";
|
|
$param[] = $reg["userID"];
|
|
$param[] = $reg["date"];
|
|
}
|
|
$sql .= ") $vals )";
|
|
$qry = $this->db->query($sql,$param);
|
|
if (!$qry ) {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
exit;
|
|
}
|
|
echo "inserting ... " . $orderHeaderID . " : $testID \n";
|
|
}
|
|
|
|
}
|
|
}
|