Batch 6a: application controllers base
This commit is contained in:
976
application/controllers/qc-v2/Process.php
Normal file
976
application/controllers/qc-v2/Process.php
Normal file
@@ -0,0 +1,976 @@
|
||||
<?php
|
||||
|
||||
class Process extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Process API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$this->resp = array(
|
||||
"status" => "ERR",
|
||||
"message" => ""
|
||||
);
|
||||
}
|
||||
public function reply()
|
||||
{
|
||||
echo json_encode($this->resp);
|
||||
exit;
|
||||
}
|
||||
public function get_data(){
|
||||
$prm = $this->sys_input;
|
||||
$startdate = $prm['startdate'];
|
||||
$enddate = $prm['enddate'];
|
||||
$instrumentid = $prm['instrumentid'];
|
||||
$controlid = $prm['controlid'];
|
||||
$testid = $prm['testid'];
|
||||
$sql = "select
|
||||
Nat_QcControlName,
|
||||
Nat_QcControlLotNumber, Nat_QcControlExpired,
|
||||
Nat_QcLevelName, Nat_InstrumentName, Nat_TestName,
|
||||
M_QcResultDate, M_QcResultValue, ifnull(Nat_QcRuleCode,'') Marking,
|
||||
Nat_QcMean,Nat_QcSd,Nat_QcTea,
|
||||
M_QcIsStat, M_QcStatMean, M_QcStatSd
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
and M_QcResultDate >= ?
|
||||
and M_QcResultDate <= ?
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'
|
||||
join nat_qc_control on Nat_QcNat_QcControlID = Nat_QcControlID
|
||||
join nat_qc_level on Nat_QcControlNat_QcLevelID = Nat_QcLevelID
|
||||
join nat_instrument on Nat_QcNat_InstrumentID = Nat_InstrumentID
|
||||
join nat_test on Nat_QcNat_TestID = Nat_TestID
|
||||
left join nat_qc_rule
|
||||
on M_QcResultNat_QcRuleID = Nat_QcRuleID
|
||||
";
|
||||
|
||||
$qry = $this->db_onedev->query($sql, array($startdate, $enddate, $instrumentid,$controlid,$testid));
|
||||
//echo $this->db_onedev->last_query();
|
||||
if (!$qry) {
|
||||
$this->resp["message"] = "{$this->now()} ERR : " . $this->db_onedev->error()["message"] . "\n"
|
||||
. "|" . $this->db_onedev->last_query() . "\n";
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = array();
|
||||
foreach ($rows as $idx => $r) {
|
||||
if ($idx == 0) {
|
||||
$isStat = $r["M_QcIsStat"] == "Y";
|
||||
$result = array(
|
||||
"control" => $r["Nat_QcControlName"],
|
||||
"level" => $r["Nat_QcLevelName"],
|
||||
"lotNumber" => $r["Nat_QcControlLotNumber"],
|
||||
"instrument" => $r["Nat_InstrumentName"],
|
||||
"ed" => $r["Nat_QcControlExpired"],
|
||||
"test" => $r["Nat_TestName"],
|
||||
"mean" => $isStat ? $r["M_QcStatMean"] : $r["Nat_QcMean"],
|
||||
"sd" => $isStat ? $r["M_QcStatSd"] : $r["Nat_QcSd"],
|
||||
"tea" => $r["Nat_QcTea"],
|
||||
"value" => array(),
|
||||
"mark" => array(),
|
||||
"date" => array()
|
||||
);
|
||||
}
|
||||
$result["date"][] = $r["M_QcResultDate"];
|
||||
$result["value"][] = $r["M_QcResultValue"];
|
||||
$result["mark"][] = $r["Marking"];
|
||||
}
|
||||
$this->resp["status"] = "OK";
|
||||
$this->resp["data"] = array(
|
||||
"total" => 1,
|
||||
"records" => $result
|
||||
);
|
||||
$this->reply();
|
||||
}
|
||||
function get_detail(){
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$startdate = $prm['startdate'];
|
||||
$enddate = $prm['enddate'];
|
||||
$instrumentid = $prm['instrumentid'];
|
||||
$controlid = $prm['controlid'];
|
||||
$testid = $prm['testid'];
|
||||
$mean_group = $prm['group_mean'];
|
||||
$rows = [];
|
||||
|
||||
|
||||
|
||||
$sql ="SELECT
|
||||
round(avg(M_QcResultValue),2) as mean
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
and M_QcResultDate >= ?
|
||||
and M_QcResultDate <= ?
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'";
|
||||
$mean_actual = $this->db_onedev->query($sql, array($startdate, $enddate, $instrumentid,$controlid,$testid))->result_array()[0]["mean"];
|
||||
|
||||
$sql ="SELECT
|
||||
round(stddev(M_QcResultValue),2) as sd
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
and M_QcResultDate >= ?
|
||||
and M_QcResultDate <= ?
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'";
|
||||
$sd_actual = $this->db_onedev->query($sql, array($startdate, $enddate, $instrumentid,$controlid,$testid))->result_array()[0]["sd"];
|
||||
|
||||
$sql ="SELECT COUNT(*) as xnumber
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
and M_QcResultDate >= ?
|
||||
and M_QcResultDate <= ?
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'";
|
||||
$xnumber = $this->db_onedev->query($sql, array($startdate, $enddate, $instrumentid,$controlid,$testid))->result_array()[0]["xnumber"];
|
||||
|
||||
$sql ="SELECT MIN(M_QcResultValue) as min
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
and M_QcResultDate >= ?
|
||||
and M_QcResultDate <= ?
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'";
|
||||
$min = $this->db_onedev->query($sql, array($startdate, $enddate, $instrumentid,$controlid,$testid))->result_array()[0]["min"];
|
||||
|
||||
$sql ="SELECT MAX(M_QcResultValue) as max
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
and M_QcResultDate >= ?
|
||||
and M_QcResultDate <= ?
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'";
|
||||
$max = $this->db_onedev->query($sql, array($startdate, $enddate, $instrumentid,$controlid,$testid))->result_array()[0]["max"];
|
||||
|
||||
$sql ="SELECT
|
||||
IFNULL(M_QcStatMean,Nat_QcMean) as mean
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'";
|
||||
$mean_last = $this->db_onedev->query($sql, array($instrumentid,$controlid,$testid))->result_array()[0]["mean"];
|
||||
|
||||
$sql ="SELECT
|
||||
IFNULL(M_QcStatSd,Nat_QcSd) as sd
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'";
|
||||
$sd_last = $this->db_onedev->query($sql, array($instrumentid,$controlid,$testid))->result_array()[0]["sd"];
|
||||
|
||||
$sql ="SELECT
|
||||
IFNULL(M_QcStatTea,Nat_QcTea) as tea
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'";
|
||||
$tea = $this->db_onedev->query($sql, array($instrumentid,$controlid,$testid))->result_array()[0]["tea"];
|
||||
|
||||
|
||||
$sql ="SELECT round(($sd_last/$mean_last)*100,1) as cv";
|
||||
$cv = $this->db_onedev->query($sql)->result_array()[0]["cv"];
|
||||
|
||||
if($mean_group == 0){
|
||||
$bias = 0;
|
||||
$sql ="SELECT round(abs($bias)+(2*$cv),1) as te";
|
||||
$te = $this->db_onedev->query($sql)->result_array()[0]["te"];
|
||||
$sigma = 0;
|
||||
}else{
|
||||
$sql ="SELECT round((($mean_last-$mean_group)/$mean_group)*100,1)as bias";
|
||||
$bias = $this->db_onedev->query($sql)->result_array()[0]["bias"];
|
||||
|
||||
$sql ="SELECT round(abs($bias)+(2*$cv),1) as te";
|
||||
$te = $this->db_onedev->query($sql)->result_array()[0]["te"];
|
||||
|
||||
$sql ="SELECT ($tea-abs($bias))/$cv as sigma";
|
||||
$sigma = $this->db_onedev->query($sql)->result_array()[0]["sigma"];
|
||||
}
|
||||
|
||||
|
||||
//echo $this->db_onedev->last_query();
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"mean_actual" => $mean_actual,
|
||||
"sd_actual" => $sd_actual,
|
||||
"mean_last" => $mean_last,
|
||||
"sd_last" => $sd_last,
|
||||
"tea" => $tea,
|
||||
"cv" => $cv,
|
||||
"bias" => $bias,
|
||||
"te" => $te,
|
||||
"sigma"=> $sigma,
|
||||
"xnumber" => $xnumber,
|
||||
"xrange" => $min.' - '.$max
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getqcid(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$instrumentid = $prm['instrumentid'];
|
||||
$controlid = $prm['controlid'];
|
||||
$testid = $prm['testid'];
|
||||
$sql ="SELECT M_QcID, Nat_QcGroupMean, Nat_QcGroupSd
|
||||
FROM nat_qc
|
||||
JOIN m_qc ON M_QcNat_QcID = Nat_QcID AND M_QcIsActive = 'Y'
|
||||
WHERE
|
||||
Nat_QcNat_QcControlID = $controlid
|
||||
AND Nat_QcNat_InstrumentID = $instrumentid
|
||||
AND Nat_QcNat_TestID = $testid
|
||||
AND Nat_QcIsActive = 'Y'";
|
||||
//echo $query;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
// echo $this->db_onedev->last_query();
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("nat_qc select");
|
||||
exit;
|
||||
}
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
function get_data_graphic(){
|
||||
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$startdate = $prm['startdate'];
|
||||
$enddate = $prm['enddate'];
|
||||
$instrumentid = $prm['instrumentid'];
|
||||
$controlid = $prm['controlid'];
|
||||
$testid = $prm['testid'];
|
||||
$rows = [];
|
||||
$sql ="select
|
||||
Nat_QcControlName,
|
||||
Nat_QcControlLotNumber, Nat_QcControlExpired,
|
||||
Nat_QcLevelName, Nat_InstrumentName, Nat_TestName,
|
||||
M_QcResultDate, M_QcResultValue, ifnull(Nat_QcRuleCode,'') Marking,
|
||||
Nat_QcMean,Nat_QcSd,Nat_QcTea,
|
||||
M_QcIsStat, M_QcStatMean, M_QcStatSd
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
and M_QcResultDate >= ?
|
||||
and M_QcResultDate <= ?
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'
|
||||
join nat_qc_control on Nat_QcNat_QcControlID = Nat_QcControlID
|
||||
join nat_qc_level on Nat_QcControlNat_QcLevelID = Nat_QcLevelID
|
||||
join nat_instrument on Nat_QcNat_InstrumentID = Nat_InstrumentID
|
||||
join nat_test on Nat_QcNat_TestID = Nat_TestID
|
||||
left join nat_qc_rule
|
||||
on M_QcResultNat_QcRuleID = Nat_QcRuleID
|
||||
GROUP BY M_QcID";
|
||||
//echo $query;
|
||||
$rows['details'] = $this->db_onedev->query($sql, array($startdate, $enddate, $instrumentid,$controlid,$testid))->result_array();
|
||||
|
||||
$sql ="select DATE_FORMAT(M_QcResultDate, '%d') as x, CONCAT(M_QcResultValue, ' :',ifnull(Nat_QcRuleCode,'')) as y, ifnull(Nat_QcRuleCode,'') as rule
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
and M_QcResultDate >= ?
|
||||
and M_QcResultDate <= ?
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'
|
||||
join nat_qc_control on Nat_QcNat_QcControlID = Nat_QcControlID
|
||||
join nat_qc_level on Nat_QcControlNat_QcLevelID = Nat_QcLevelID
|
||||
join nat_instrument on Nat_QcNat_InstrumentID = Nat_InstrumentID
|
||||
join nat_test on Nat_QcNat_TestID = Nat_TestID
|
||||
left join nat_qc_rule
|
||||
on M_QcResultNat_QcRuleID = Nat_QcRuleID
|
||||
GROUP BY M_QcResultID
|
||||
ORDER BY M_QcResultDate ASC, M_QcResultID ASC";
|
||||
// echo $query;
|
||||
$rows['date'] = $this->db_onedev->query($sql, array($startdate, $enddate, $instrumentid,$controlid,$testid))->result_array();
|
||||
|
||||
$sql ="select M_QcResultValue
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
and M_QcResultDate >= ?
|
||||
and M_QcResultDate <= ?
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'
|
||||
join nat_qc_control on Nat_QcNat_QcControlID = Nat_QcControlID
|
||||
join nat_qc_level on Nat_QcControlNat_QcLevelID = Nat_QcLevelID
|
||||
join nat_instrument on Nat_QcNat_InstrumentID = Nat_InstrumentID
|
||||
join nat_test on Nat_QcNat_TestID = Nat_TestID
|
||||
left join nat_qc_rule
|
||||
on M_QcResultNat_QcRuleID = Nat_QcRuleID
|
||||
GROUP BY M_QcResultID
|
||||
ORDER BY M_QcResultDate ASC, M_QcResultID ASC";
|
||||
//echo $query;
|
||||
$rows['value'] = $this->db_onedev->query($sql, array($startdate, $enddate, $instrumentid,$controlid,$testid))->result_array();
|
||||
|
||||
$sql ="select ifnull(Nat_QcRuleCode,'') Marking
|
||||
from m_qc_result
|
||||
join m_qc on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultIsActive = 'Y'
|
||||
and M_QcResultDate >= ?
|
||||
and M_QcResultDate <= ?
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcNat_InstrumentID = ?
|
||||
and Nat_QcNat_QcControlID = ?
|
||||
and Nat_QcNat_TestID = ?
|
||||
and Nat_QcIsActive = 'Y'
|
||||
join nat_qc_control on Nat_QcNat_QcControlID = Nat_QcControlID
|
||||
join nat_qc_level on Nat_QcControlNat_QcLevelID = Nat_QcLevelID
|
||||
join nat_instrument on Nat_QcNat_InstrumentID = Nat_InstrumentID
|
||||
join nat_test on Nat_QcNat_TestID = Nat_TestID
|
||||
left join nat_qc_rule
|
||||
on M_QcResultNat_QcRuleID = Nat_QcRuleID
|
||||
GROUP BY M_QcResultID
|
||||
ORDER BY M_QcResultDate ASC, M_QcResultID ASC";
|
||||
//echo $query;
|
||||
$rows['mark'] = $this->db_onedev->query($sql, array($startdate, $enddate, $instrumentid,$controlid,$testid))->result_array();
|
||||
|
||||
//echo $this->db_onedev->last_query();
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
|
||||
}
|
||||
public function calc()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$qcresultID = $prm['qcresultid'];
|
||||
$sql = "select
|
||||
M_QcResultID,
|
||||
M_QcResultM_QcID,
|
||||
M_QcResultDate,
|
||||
M_QcResultValue,
|
||||
IFNULL(M_QcStatMean,Nat_QcMean) as Nat_QcMean,
|
||||
IFNULL(M_QcStatSd,Nat_QcSd) as Nat_QcSd,
|
||||
Nat_QcTea
|
||||
from
|
||||
m_qc_result
|
||||
join m_qc
|
||||
on M_QcResultM_QcID = M_QcID
|
||||
and M_QcIsActive = 'Y'
|
||||
join nat_qc
|
||||
on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcIsActive = 'Y'
|
||||
where M_QcResultID = ?";
|
||||
$qry = $this->db_onedev->query($sql, array($qcresultID));
|
||||
if (!$qry) {
|
||||
$this->resp["message"] = "{$this->now()} ERR : " . $this->db_onedev->error()["message"] . "\n"
|
||||
. "|" . $this->db_onedev->last_query() . "\n";
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
foreach ($rows as $idx => $r) {
|
||||
$mean = $r["Nat_QcMean"];
|
||||
$sd = $r["Nat_QcSd"];
|
||||
$TEa = $r["Nat_QcTea"];
|
||||
$value = $r["M_QcResultValue"];
|
||||
$id = $r["M_QcResultID"];
|
||||
$qcID = $r["M_QcResultM_QcID"];
|
||||
$ruleID = 0;
|
||||
$x12s= $this->is_1_2s($idx, $value, $mean, $sd);
|
||||
if($x12s > 0){
|
||||
$x1_3s = $this->is_1_3s($idx, $value, $mean, $sd);
|
||||
if($x1_3s == 0){
|
||||
$x2_2s= $this->is_2_2s($idx, $value, $mean, $sd, $id, $qcID);
|
||||
if($x2_2s == 0){
|
||||
$xR_4s = $this->is_R_4s($idx, $value, $mean, $sd, $id, $qcID);
|
||||
if($xR_4s == 0){
|
||||
$x4_1s = $this->is_4_1s($idx, $value, $mean, $sd, $id, $qcID);
|
||||
if($x4_1s == 0){
|
||||
$x10x = $this->is_10x($idx, $value, $mean, $sd, $id, $qcID);
|
||||
if($x10x == 0){
|
||||
$ruleID = $x12s;
|
||||
}else{
|
||||
$ruleID = $x10x;
|
||||
}
|
||||
}else{
|
||||
$ruleID = $x4_1s;
|
||||
}
|
||||
}else{
|
||||
$ruleID = $xR_4s;
|
||||
}
|
||||
}else{
|
||||
$ruleID = $x2_2s;
|
||||
}
|
||||
}else{
|
||||
$ruleID = $x1_3s;
|
||||
}
|
||||
}else{
|
||||
$ruleID = 0;
|
||||
}
|
||||
|
||||
|
||||
$sql = "update m_qc_result
|
||||
set M_QcResultNat_QcRuleID = ?
|
||||
where M_QcResultID = ?";
|
||||
$qry = $this->db_onedev->query($sql, array($ruleID,$id));
|
||||
//echo $this->db_onedev->last_query();
|
||||
if (!$qry) {
|
||||
$this->resp["message"] = "{$this->now()} ERR : " . $this->db_onedev->error()["message"] . "\n"
|
||||
. "|" . $this->db_onedev->last_query() . "\n";
|
||||
$this->reply();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
$this->resp["status"] = "OK";
|
||||
$this->reply();
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
// rule
|
||||
// 1 : 1 2s
|
||||
public function is_1_2s($idx, $value, $mean, $sd)
|
||||
{
|
||||
if ($value < $mean - 2 * $sd || $value > $mean + 2*$sd) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// 8 : 1 3s
|
||||
public function is_1_3s($idx, $value, $mean, $sd)
|
||||
{
|
||||
//echo "$value | $mean | $sd \n";
|
||||
if ($value < $mean - 3 * $sd || $value > $mean + 3*$sd) {
|
||||
return 8;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// 7 : 2 2s
|
||||
public function is_2_2s($idx, $value, $mean, $sd, $id, $qcID)
|
||||
{
|
||||
$x = $this->db_onedev->query("SELECT M_QcResultValue FROM
|
||||
m_qc_result
|
||||
WHERE M_QcResultID < $id AND M_QcResultM_QcID = $qcID
|
||||
ORDER BY M_QcResultID DESC LIMIT 1")->row();
|
||||
|
||||
$y = $this->db_onedev->query("SELECT count(*) as count
|
||||
FROM(SELECT M_QcResultValue FROM
|
||||
m_qc_result
|
||||
WHERE M_QcResultID < $id AND M_QcResultM_QcID = $qcID
|
||||
ORDER BY M_QcResultID DESC LIMIT 1)a")->row();
|
||||
$jml = $y->count;
|
||||
if($jml == 0){
|
||||
return 0;
|
||||
}else{
|
||||
$prev_value = $x->M_QcResultValue;
|
||||
if ($value < $mean - 2 * $sd && $prev_value < $mean - 2*$sd) {
|
||||
return 7;
|
||||
}
|
||||
if ($value > $mean + 2 * $sd && $prev_value > $mean + 2*$sd) {
|
||||
return 7;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// 2 : R 4s
|
||||
public function is_R_4s($idx, $value, $mean, $sd, $id, $qcID)
|
||||
{
|
||||
$x = $this->db_onedev->query("SELECT M_QcResultValue FROM
|
||||
m_qc_result
|
||||
WHERE M_QcResultID < $id AND M_QcResultM_QcID = $qcID
|
||||
ORDER BY M_QcResultID DESC LIMIT 1")->row();
|
||||
|
||||
$y = $this->db_onedev->query("SELECT count(*) as count
|
||||
FROM(SELECT M_QcResultValue FROM
|
||||
m_qc_result
|
||||
WHERE M_QcResultID < $id AND M_QcResultM_QcID = $qcID
|
||||
ORDER BY M_QcResultID DESC LIMIT 1)a")->row();
|
||||
$prev_value = $x->M_QcResultValue;
|
||||
$jml = $y->count;
|
||||
if($jml == 0){
|
||||
return 0;
|
||||
}else{
|
||||
if ($value < $mean - 2 * $sd && $prev_value > $mean + 2*$sd) {
|
||||
return 2;
|
||||
}
|
||||
if ($value > $mean + 2 * $sd && $prev_value < $mean - 2*$sd) {
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// 3 : 4 1s
|
||||
public function is_4_1s($idx, $value, $mean, $sd, $id, $qcID)
|
||||
{
|
||||
$x = $this->db_onedev->query("SELECT M_QcResultValue FROM
|
||||
m_qc_result
|
||||
WHERE M_QcResultID < $id AND M_QcResultM_QcID = $qcID
|
||||
ORDER BY M_QcResultID DESC LIMIT 3")->result_array();
|
||||
|
||||
$y = $this->db_onedev->query("SELECT count(*) as count
|
||||
FROM(SELECT M_QcResultValue FROM
|
||||
m_qc_result
|
||||
WHERE M_QcResultID < $id AND M_QcResultM_QcID = $qcID
|
||||
ORDER BY M_QcResultID DESC LIMIT 3)a")->row();
|
||||
|
||||
$jml = $y->count;
|
||||
if($jml < 3){
|
||||
return 0;
|
||||
}else{
|
||||
$value3 = $x[0]["M_QcResultValue"];
|
||||
$value2 = $x[1]["M_QcResultValue"];
|
||||
$value1 = $x[2]["M_QcResultValue"];
|
||||
$val_1sd = $mean + $sd;
|
||||
$val_1sd_neg = $mean - $sd;
|
||||
// echo "$value1 | $value2 | $value3 | $value | $val_1sd | $val_1sd_neg \n";
|
||||
if ($value1 > $val_1sd && $value2 > $val_1sd && $value3 > $val_1sd && $value > $val_1sd) {
|
||||
return 3;
|
||||
}
|
||||
if ($value1 < $val_1sd_neg && $value2 < $val_1sd_neg && $value3 < $val_1sd_neg && $value < $val_1sd_neg) {
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
// 4 : 10x
|
||||
public function is_10x($idx, $value, $mean, $sd, $id, $qcID)
|
||||
{
|
||||
$x = $this->db_onedev->query("SELECT M_QcResultValue FROM
|
||||
m_qc_result
|
||||
WHERE M_QcResultID < $id AND M_QcResultM_QcID = $qcID
|
||||
ORDER BY M_QcResultID DESC LIMIT 9")->result_array();
|
||||
|
||||
$y = $this->db_onedev->query("SELECT count(*) as count
|
||||
FROM(SELECT M_QcResultValue FROM
|
||||
m_qc_result
|
||||
WHERE M_QcResultID < $id AND M_QcResultM_QcID = $qcID
|
||||
ORDER BY M_QcResultID DESC LIMIT 9)a")->row();
|
||||
|
||||
$jml = $y->count;
|
||||
if($jml < 9){
|
||||
return 0;
|
||||
}else{
|
||||
$value9 = $x[0]["M_QcResultValue"];
|
||||
$value8 = $x[1]["M_QcResultValue"];
|
||||
$value7 = $x[2]["M_QcResultValue"];
|
||||
$value6 = $x[3]["M_QcResultValue"];
|
||||
$value5 = $x[4]["M_QcResultValue"];
|
||||
$value4 = $x[5]["M_QcResultValue"];
|
||||
$value3 = $x[6]["M_QcResultValue"];
|
||||
$value2 = $x[7]["M_QcResultValue"];
|
||||
$value1 = $x[8]["M_QcResultValue"];
|
||||
$val_1sd = $mean + $sd;
|
||||
$val_1sd_neg = $mean - $sd;
|
||||
if ($value1 < $mean && $value2 < $mean && $value3 < $mean && $value4 < $mean && $value5 < $mean &&
|
||||
$value6 < $mean && $value7 < $mean && $value8 < $mean && $value9 < $mean && $value < $mean) {
|
||||
return 4;
|
||||
}
|
||||
if ($value1 > $mean && $value2 > $mean && $value3 > $mean && $value4 > $mean && $value5 > $mean &&
|
||||
$value6 > $mean && $value7 > $mean && $value8 > $mean && $value9 > $mean && $value > $mean) {
|
||||
return 4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
function lookuprule(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$control = $prm['control'];
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM nat_qc_rule
|
||||
WHERE
|
||||
Nat_QcRuleIsActive = 'Y' AND Nat_QcRuleID IN(1,2,3,4,7,8)";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("nat_qc_rule count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
$sql = "
|
||||
SELECT Nat_QcRuleID,Nat_QcRuleCode, 'Y' as isactive
|
||||
FROM nat_qc_rule
|
||||
WHERE
|
||||
Nat_QcRuleIsActive = 'Y' AND Nat_QcRuleID IN(1,2,3,4,7,8)
|
||||
ORDER BY Nat_QcRuleID ASC
|
||||
";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
|
||||
|
||||
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
//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("nat_qc_rule rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
public function setfactory()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$natqcid = $prm['natqcid'];
|
||||
$mean = $prm['mean'];
|
||||
$sd = $prm['sd'];
|
||||
$tea = $prm['tea'];
|
||||
$startdate = $prm['startdate'];
|
||||
$enddate = $prm['enddate'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$query = "UPDATE m_qc SET M_QcIsStat = 'Y',
|
||||
M_QcStatMean = $mean,
|
||||
M_QcStatSd = $sd,
|
||||
M_QcUserID = $userid,
|
||||
M_QcLastUpdated = now()
|
||||
WHERE M_QcNat_QcID = $natqcid";
|
||||
$update_m_qc= $this->db_onedev->query($query);
|
||||
|
||||
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("m_qc update");
|
||||
exit;
|
||||
}
|
||||
$query = "INSERT INTO m_qc_log(
|
||||
M_QcLogNat_QcID,
|
||||
M_QcLogStartDate,
|
||||
M_QcLogEndDate,
|
||||
M_QcLogIsStat,
|
||||
M_QcLogStatMean,
|
||||
M_QcLogStatSd,
|
||||
M_QcLogStatTea,
|
||||
M_QcLogCreated,
|
||||
M_QcLogLastUpdated,
|
||||
M_QcLogUserID)
|
||||
VALUES
|
||||
($natqcid,
|
||||
'{$startdate}',
|
||||
'{$enddate}',
|
||||
'Y',
|
||||
$mean,
|
||||
$sd,
|
||||
$tea,
|
||||
now(),
|
||||
now(),
|
||||
$userid)";
|
||||
$insert_m_qc= $this->db_onedev->query($query);
|
||||
// echo $this->db_onedev->last_query();
|
||||
if (!$query) {
|
||||
$this->sys_error_db("m_qc_log insert");
|
||||
exit;
|
||||
}
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
|
||||
|
||||
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
public function qc_byidname(){
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$controlid = $prm['controlid'];
|
||||
$test = $prm['test'];
|
||||
$sdate = $prm['sdate'];
|
||||
$limit = ' LIMIT 10';
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['page'] - 1) * $number_limit ;
|
||||
$sql = "select COUNT(*) as total
|
||||
FROM(SELECT * from m_qc
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcIsActive = 'Y'
|
||||
join nat_qc_control on Nat_QcNat_QcControlID = Nat_QcControlID
|
||||
and Nat_QcControlIsActive = 'Y'
|
||||
and Nat_QcControlID = $controlid
|
||||
join nat_instrument on Nat_QcNat_InstrumentID = Nat_InstrumentID
|
||||
and Nat_InstrumentIsActive = 'Y'
|
||||
JOIN t_instrument_local ON T_InstrumentLocalNat_InstrumentID = Nat_InstrumentID
|
||||
AND T_InstrumentLocalIsActive = 'Y'
|
||||
join nat_test on Nat_QcNat_TestID = Nat_TestID
|
||||
and Nat_TestName like CONCAT('%','{$test}','%')
|
||||
and Nat_TestIsActive = 'Y'
|
||||
left join m_qc_result on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultDate = '{$sdate}'
|
||||
and M_QcResultIsActive ='Y'
|
||||
LEFT JOIN nat_qc_rule ON M_QcResultNat_QcRuleID = Nat_QcRuleID
|
||||
WHERE M_QcIsActive = 'Y') a";
|
||||
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$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("nat_qc count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "select distinct M_QcID, M_QcStatMean, M_QcStatSd, M_QcStatTea,
|
||||
M_QcResultID, M_QcResultValue, M_QcResultValue as M_QcResultValueOld, M_QcResultIsInstrument , M_QcResultDate,
|
||||
Nat_QcControlID , Nat_QcControlName , Nat_InstrumentID, Nat_InstrumentName, Nat_TestID , Nat_TestName, IFNULL(M_QcStatMean,Nat_QcMean) as Nat_QcMean, IFNULL(M_QcStatSd,Nat_QcSd) as Nat_QcSd, Nat_QcTea,
|
||||
Nat_QcRuleID,
|
||||
Nat_QcRuleCode,
|
||||
Nat_QcLevelID,
|
||||
Nat_QcLevelName
|
||||
from m_qc
|
||||
join nat_qc on M_QcNat_QcID = Nat_QcID
|
||||
and Nat_QcIsActive = 'Y'
|
||||
join nat_qc_control on Nat_QcNat_QcControlID = Nat_QcControlID
|
||||
and Nat_QcControlIsActive = 'Y'
|
||||
and Nat_QcControlID = $controlid
|
||||
join nat_instrument on Nat_QcNat_InstrumentID = Nat_InstrumentID
|
||||
and Nat_InstrumentIsActive = 'Y'
|
||||
JOIN t_instrument_local ON T_InstrumentLocalNat_InstrumentID = Nat_InstrumentID
|
||||
AND T_InstrumentLocalIsActive = 'Y'
|
||||
join nat_test on Nat_QcNat_TestID = Nat_TestID
|
||||
and Nat_TestName like CONCAT('%','{$test}','%')
|
||||
and Nat_TestIsActive = 'Y'
|
||||
left join m_qc_result on M_QcResultM_QcID = M_QcID
|
||||
and M_QcResultDate = '{$sdate}'
|
||||
and M_QcResultIsActive ='Y'
|
||||
LEFT JOIN nat_qc_rule ON M_QcResultNat_QcRuleID = Nat_QcRuleID
|
||||
join nat_qc_level ON Nat_QcLevelID = Nat_QcControlNat_QcLevelID
|
||||
WHERE M_QcIsActive = 'Y'
|
||||
order by Nat_InstrumentName ASC, Nat_QcControlName ASC, Nat_TestName ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
$sql_param = array($search);
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
|
||||
|
||||
} else {
|
||||
$this->sys_error_db("nat_qc select");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function control_byidname(){
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$instrumentid = $prm['instrumentid'];
|
||||
$control = $prm['control'];
|
||||
$limit = ' LIMIT 10';
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['page'] - 1) * $number_limit ;
|
||||
$sql = "select COUNT(*) as total
|
||||
FROM(SELECT * from nat_qc_control
|
||||
join nat_qc_level
|
||||
ON Nat_QcControlNat_QcLevelID = Nat_QcLevelID
|
||||
AND Nat_QcControlIsActive = 'Y'
|
||||
AND Nat_QcLevelIsActive = 'Y'
|
||||
AND Nat_QcControlName like CONCAT('%','{$control}','%')
|
||||
join nat_qc
|
||||
ON Nat_QcControlID = Nat_QcNat_QcControlID
|
||||
AND Nat_QcIsActive = 'Y'
|
||||
join nat_instrument
|
||||
ON Nat_QcNat_InstrumentID = Nat_InstrumentID
|
||||
AND Nat_InstrumentIsActive = 'Y'
|
||||
AND Nat_InstrumentID = $instrumentid
|
||||
JOIN t_instrument_local
|
||||
ON T_InstrumentLocalNat_InstrumentID = Nat_InstrumentID
|
||||
AND T_InstrumentLocalIsActive = 'Y'
|
||||
JOIN m_qc
|
||||
ON M_QcNat_QcID = Nat_QcID
|
||||
AND M_QcIsActive = 'Y'
|
||||
GROUP BY Nat_QcControlID) a";
|
||||
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$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("nat_qc count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT distinct Nat_QcControlID,
|
||||
Nat_QcControlName,
|
||||
Nat_QcControlLotNumber,
|
||||
DATE_FORMAT(Nat_QcControlExpired, '%d-%m-%Y') as Nat_QcControlExpired,
|
||||
Nat_InstrumentID,
|
||||
Nat_InstrumentName,
|
||||
Nat_QcLevelID,
|
||||
Nat_QcID,
|
||||
Nat_QcLevelName
|
||||
from nat_qc_control
|
||||
join nat_qc_level
|
||||
ON Nat_QcControlNat_QcLevelID = Nat_QcLevelID
|
||||
AND Nat_QcControlIsActive = 'Y'
|
||||
AND Nat_QcLevelIsActive = 'Y'
|
||||
AND Nat_QcControlName like CONCAT('%','{$control}','%')
|
||||
join nat_qc
|
||||
ON Nat_QcControlID = Nat_QcNat_QcControlID
|
||||
AND Nat_QcIsActive = 'Y'
|
||||
join nat_instrument
|
||||
ON Nat_QcNat_InstrumentID = Nat_InstrumentID
|
||||
AND Nat_InstrumentIsActive = 'Y'
|
||||
AND Nat_InstrumentID = $instrumentid
|
||||
JOIN t_instrument_local
|
||||
ON T_InstrumentLocalNat_InstrumentID = Nat_InstrumentID
|
||||
AND T_InstrumentLocalIsActive = 'Y'
|
||||
JOIN m_qc
|
||||
ON M_QcNat_QcID = Nat_QcID
|
||||
AND M_QcIsActive = 'Y'
|
||||
GROUP BY Nat_QcControlID
|
||||
order by Nat_InstrumentName ASC, Nat_QcControlName ASC, Nat_QcLevelID ASC
|
||||
|
||||
limit $number_limit offset $number_offset";
|
||||
$sql_param = array($search);
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
|
||||
|
||||
} else {
|
||||
$this->sys_error_db("nat_qc select");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user