265 lines
9.2 KiB
PHP
265 lines
9.2 KiB
PHP
<?php
|
|
|
|
class Rv_verification extends MY_Controller
|
|
{
|
|
var $db_smartone;
|
|
|
|
public function index()
|
|
{
|
|
echo "RV Px API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_smartone = $this->load->database("onedev", true);
|
|
$this->db_one= $this->load->database("onedev", true);
|
|
}
|
|
|
|
function requirement($id) {
|
|
$sql = "call sp_result_verify_requirement(?)";
|
|
$query = $this->db_one->query($sql, array($id));
|
|
$this->clean_mysqli_connection($this->db_one);
|
|
$rows = $query->result_array() ;
|
|
$result = array();
|
|
foreach( $rows as $r ) {
|
|
$jdata = json_decode( $r["jdata"] );
|
|
$a_pos = array();
|
|
foreach($jdata as $req ) {
|
|
$xreq = json_decode($req,true);
|
|
foreach($xreq as $position => $req) {
|
|
$a_req = explode("^",$req);
|
|
$a_pos[$position] = $a_req;
|
|
}
|
|
}
|
|
$result = $a_pos;
|
|
}
|
|
return $this->req_html($result);
|
|
}
|
|
function req_html($result) {
|
|
$a_pos = $result;
|
|
if (count($a_pos) == 0 ) return "";
|
|
$html = "<table >\n";
|
|
$html .= "<tr><th style='text-align:left;padding:5px;'>Position</th>
|
|
<th style='text-align:left;padding:5px;' >Requirements</th></tr>\n";
|
|
foreach($a_pos as $pos => $reqs) {
|
|
$html .= "<tr valign='top' >\n";
|
|
$html .= "<td style='text-align:left;padding:5px;'>$pos</td>";
|
|
$html .= "<td style='text-align:left;padding:5px;'>";
|
|
foreach($reqs as $r) {
|
|
$html .= "$r<br/>";
|
|
}
|
|
$html .= "</td>";
|
|
$html .= "</tr>";
|
|
}
|
|
$html .= "</table>";
|
|
return $html;
|
|
}
|
|
|
|
public function pre_analytic()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$id = $prm["order_id"];
|
|
$image = "";
|
|
$note = "";
|
|
try {
|
|
$sql = "select date(T_OrderDetailAddOnPreAnalyticDate) pDate,
|
|
T_OrderDetailAddOnPreAnalyticDate fDate,
|
|
T_TestNat_TestID Nat_TestID, T_TestName
|
|
from t_orderdetail
|
|
join t_orderdetailaddon on T_OrderDetailID = ? and T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
limit 0,1";
|
|
$qry = $this->db_one->query($sql,array($id));
|
|
$fdate = "";
|
|
if ($qry) {
|
|
$row = $qry->row();
|
|
$date = $row->pDate;
|
|
$fdate = $row->fDate;
|
|
$testName = $row->T_TestName;
|
|
$natTestID = $row->Nat_TestID;
|
|
}
|
|
$reqs = "";
|
|
if ( $fdate != "" ) {
|
|
$sql = "select PreAnalyticRequirements reqs
|
|
from pre_analytic
|
|
where PreAnalyticDate =? and PreAnalyticNat_TestID = ?
|
|
and PreAnalyticCreated <=?
|
|
order by PreAnalyticID desc limit 0,1";
|
|
$qry = $this->db_one->query($sql,array($date, $natTestID,$fdate));
|
|
if ($qry) {
|
|
$row = $qry->row();
|
|
$jreqs = json_decode($row->reqs);
|
|
foreach($jreqs as $id) {
|
|
if ($reqs != "" ) $reqs .= ", ";
|
|
$reqs .= $id;
|
|
}
|
|
}
|
|
}
|
|
if ($reqs != "" ) {
|
|
$sql = "select * from nat_requirement where Nat_RequirementID in ( $reqs )";
|
|
$qry = $this->db_one->query($sql);
|
|
$rows = $qry->result_array();
|
|
$s_req = "";
|
|
foreach($rows as $r) {
|
|
if ($s_req != "" ) $s_req .= "<br/>";
|
|
$s_req .= $r["Nat_RequirementName"];
|
|
}
|
|
}
|
|
$note = "Pre Analytic tidak terpenuhi";
|
|
if ($s_req != "") $note = $s_req;
|
|
$data = array("title" => "Pre Analytic $testName",
|
|
"note" => $note,
|
|
"red" => true,
|
|
"load" => false
|
|
);
|
|
} catch(Exception $e) {
|
|
$note = "Pre Analytic tidak terpenuhi";
|
|
if ($s_req != "") $note = $s_req;
|
|
$data = array("title" => "Pre Analytic $testName",
|
|
"note" => $note,
|
|
"red" => true,
|
|
"load" => false
|
|
);
|
|
}
|
|
$this->sys_ok($data);
|
|
}
|
|
public function trend_analysis()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$id = $prm["order_id"];
|
|
$image = "";
|
|
$note = "";
|
|
try {
|
|
$sql = "select fn_process_re_trendanalysis_v2(?) ta";
|
|
$qry = $this->db_one->query($sql,array($id));
|
|
if ($qry) {
|
|
$row = $qry->row();
|
|
$j_tmp = json_decode($row->ta);
|
|
if ($j_tmp->image != "") {
|
|
$i_url = $j_tmp->image . "&ts=" . date("Ymdhnis") ;
|
|
$image = file_get_contents("http://localhost/$i_url");
|
|
$image = str_replace("src=\"","src=\"/charts/",$image);
|
|
}
|
|
$note = $j_tmp->note;
|
|
}
|
|
} catch(Exception $e) {
|
|
}
|
|
$req_note =$this->requirement($id);
|
|
if ($req_note != "" ) {
|
|
$note = $req_note;
|
|
$image = "";
|
|
}
|
|
$data = ["image"=>$image,
|
|
"note"=> $note,
|
|
"title"=>"Trend Analisis"];
|
|
$this->sys_ok($data);
|
|
}
|
|
|
|
public function delta_check()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$id = $prm["order_id"];
|
|
|
|
$note = "";
|
|
try {
|
|
$sql = "select fn_process_re_deltacheck(?) ta";
|
|
$qry = $this->db_one->query($sql,array($id));
|
|
if ($qry) {
|
|
$row = $qry->row();
|
|
$j_tmp = json_decode($row->ta);
|
|
$note = $j_tmp->note;
|
|
}
|
|
} catch(Exception $e) {
|
|
}
|
|
$req_note =$this->requirement($id);
|
|
if ($req_note != "" ) {
|
|
$note = $req_note;
|
|
$image = "";
|
|
}
|
|
$data = [ "note"=> $note,
|
|
"image" => "",
|
|
"title"=>"Delta Check"];
|
|
$this->sys_ok($data);
|
|
}
|
|
|
|
public function confirm()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$data = json_decode($prm["data"]);
|
|
|
|
if (sizeof($data) < 1)
|
|
{
|
|
$this->sys_error_db("RE Verification Confirmation", $this->db_smartone);
|
|
exit;
|
|
}
|
|
else
|
|
{
|
|
$ids = [];
|
|
foreach ($data as $k => $v)
|
|
{
|
|
$this->db_smartone->set('T_OrderDetailVerDeltaCheck', $v->delta)
|
|
->set('T_OrderDetailVerTrendAnalysis', $v->trend)
|
|
->set('T_OrderDetailVerification', $v->verification)
|
|
->set('T_OrderDetailVerDate', $v->verification == "Y" ? date('Y-m-d H:i:s') : null)
|
|
->set('T_OrderDetailVerUserID', $this->sys_user['M_UserID'])
|
|
->where('T_OrderDetailID', $v->id)
|
|
->update('t_orderdetail');
|
|
$ids[] = $v->id;
|
|
}
|
|
|
|
// LOG Process
|
|
$order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false)
|
|
->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID')
|
|
->where('T_OrderDetailID', $data[0]->id)
|
|
->get('t_orderdetail')
|
|
->row();
|
|
|
|
$dblog = $this->load->database("onelog", true);
|
|
$dblog->set('Log_ProcessCode', 'PROCESS.Result.Verification')
|
|
->set('Log_ProcessOrderID', $order->id)
|
|
->set('Log_ProcessOrderNumber', $order->lab_number)
|
|
->set('Log_ProcessJson', json_encode($data))
|
|
->set('Log_ProcessUserID', $this->sys_user['M_UserID'])
|
|
->insert('log_process');
|
|
// END OF Log Process
|
|
//sipe : verifikasi Y t_orderdetail IsParent Y T_OrderDetailVerification X IsResult N
|
|
|
|
// Heri, 2020-01-02
|
|
$tcode = $this->db_smartone->where('T_OrderDetailID', $v->id)
|
|
->get('t_orderdetail')
|
|
->row();
|
|
|
|
$sql = "update t_orderdetail,t_test
|
|
set T_OrderDetailVerification='Y',
|
|
T_OrderDetailVerDate = now(),
|
|
T_OrderDetailVerUserID = ?
|
|
where T_OrderDetailT_OrderHeaderID = ? and T_OrderDetailT_TestID = T_TestID
|
|
and T_TestIsParent = 'Y' and T_TestIsResult = 'N'
|
|
and T_OrderDetailVerification='X'
|
|
and ? LIKE CONCAT(T_OrderDetailT_TestSasCode, '%')";
|
|
$this->db_smartone->query($sql,array($this->sys_user['M_UserID'],$order->id, $tcode->T_OrderDetailT_TestSasCode));
|
|
//file_put_contents("/xtmp/pe-debug.sql",$this->db_smartone->last_query());
|
|
$this->sys_ok($ids);
|
|
}
|
|
}
|
|
|
|
public function reject()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
// QUERY TOTAL
|
|
$sql = "CALL sp_process_result_validation_reject(?, ?)";
|
|
$query = $this->db_smartone->query($sql, [$prm['id'], $prm['action']]);
|
|
|
|
if ($query) {
|
|
$row = $query->row();
|
|
$this->sys_ok($row);
|
|
}
|
|
else {
|
|
$this->sys_error_db("REJECT VERIFICATION", $this->db_smartone);
|
|
}
|
|
}
|
|
}
|
|
|