276 lines
11 KiB
PHP
276 lines
11 KiB
PHP
<?php
|
|
class Qc extends MY_Controller
|
|
{
|
|
var $db;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db = $this->load->database("onedev", true);
|
|
}
|
|
function index()
|
|
{
|
|
echo "API QC";
|
|
}
|
|
function get_rule()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$sql = 'SELECT * FROM `nat_qc_rule`';
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
$count = 'SELECT count(Nat_QcRuleID) as total FROM `nat_qc_rule`';
|
|
$qry_total_filter = $this->db->query($count);
|
|
$last_qry_total_filter = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
if (!$qry_total_filter) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry_total_filter
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$total_filter = (int)$qry_total_filter->result_array()[0]["total"];
|
|
$result = array(
|
|
"total" => $total_filter,
|
|
"records" => $rows,
|
|
"sql" => $last_qry,
|
|
"count" => $last_qry_total_filter
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function get_qc_value()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$param = $this->sys_input;
|
|
$instrumentid = 0;
|
|
if (isset($param['instrumentid'])) {
|
|
if (is_numeric($param['instrumentid'])) {
|
|
$instrumentid = $param['instrumentid'];
|
|
}
|
|
} else {
|
|
$this->sys_error("Instrument id, control id, test id, startdate, enddate is mandatory");
|
|
exit;
|
|
}
|
|
$controlid = 0;
|
|
if (isset($param['controlid'])) {
|
|
if (is_numeric($param['controlid'])) {
|
|
$controlid = $param['controlid'];
|
|
}
|
|
} else {
|
|
$this->sys_error("Instrument id, control id, test id, startdate, enddate is mandatory");
|
|
exit;
|
|
}
|
|
$testid = 0;
|
|
if (isset($param['testid'])) {
|
|
if (is_numeric($param['testid'])) {
|
|
$testid = $param['testid'];
|
|
}
|
|
} else {
|
|
$this->sys_error("Instrument id, control id, test id, startdate, enddate is mandatory");
|
|
exit;
|
|
}
|
|
$startdate = 0;
|
|
if (isset($param['startdate'])) {
|
|
$startdate = $param['startdate'];
|
|
} else {
|
|
$this->sys_error("Instrument id, control id, test id, startdate, enddate is mandatory");
|
|
exit;
|
|
}
|
|
$enddate = 0;
|
|
if (isset($param['enddate'])) {
|
|
$enddate = $param['enddate'];
|
|
} else {
|
|
$this->sys_error("Instrument id, control id, test id, startdate, enddate is mandatory");
|
|
exit;
|
|
}
|
|
$sql = "select distinct M_QcResultID,
|
|
DATE_FORMAT(M_QcResultDate , '%d-%m-%Y') as M_QcResultDate
|
|
,M_QcResultValue
|
|
,Nat_QcRuleID,
|
|
Nat_QcRuleCode,
|
|
round((M_QcResultValue-IFNULL(M_QcStatMean,Nat_QcMean))/IFNULL(M_QcStatSd,Nat_QcSd),1) as zscore
|
|
from m_qc_result
|
|
join m_qc on M_QcResultM_QcID = M_QcID
|
|
and M_QcResultIsActive = 'Y' and M_QcIsActive='Y'
|
|
join nat_qc on M_QcNat_QcID
|
|
and Nat_QcIsActive ='Y'
|
|
and Nat_QcNat_InstrumentID = ?
|
|
and Nat_QcNat_QcControlID = ?
|
|
and Nat_QcNat_TestID = ?
|
|
left join nat_qc_rule on M_QcResultNat_QcRuleID = Nat_QcRuleID
|
|
and Nat_QcRuleIsActive ='Y'
|
|
where M_QcResultDate >= ? and M_QcResultDate <= ?
|
|
ORDER BY M_QcResultDate ASC";
|
|
$qry = $this->db->query($sql, [$instrumentid, $controlid, $testid, $startdate, $enddate]);
|
|
$last_qry = $this->db->last_query();
|
|
$count = "select count(distinct M_QcResultID,
|
|
M_QcResultDate
|
|
,M_QcResultValue
|
|
,Nat_QcRuleID,
|
|
Nat_QcRuleCode) as total
|
|
from m_qc_result
|
|
join m_qc on M_QcResultM_QcID = M_QcID
|
|
and M_QcResultIsActive = 'Y' and M_QcIsActive='Y'
|
|
join nat_qc on M_QcNat_QcID
|
|
and Nat_QcIsActive ='Y'
|
|
and Nat_QcNat_InstrumentID = ?
|
|
and Nat_QcNat_QcControlID = ?
|
|
and Nat_QcNat_TestID = ?
|
|
left join nat_qc_rule on M_QcResultNat_QcRuleID = Nat_QcRuleID
|
|
and Nat_QcRuleIsActive ='Y'
|
|
where M_QcResultDate >= ? and M_QcResultDate <= ?
|
|
ORDER BY M_QcResultDate ASC";
|
|
$qry_total_filter = $this->db->query($count, [$instrumentid, $controlid, $testid, $startdate, $enddate]);
|
|
$last_qry_total = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
if (!$qry_total_filter) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry_total
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$total_filter = (int)$qry_total_filter->result_array()[0]["total"];
|
|
$result = array(
|
|
"total" => $total_filter,
|
|
"records" => $rows,
|
|
"sql" => $last_qry,
|
|
"count" => $last_qry_total
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function get_actual_mean_sd()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$param = $this->sys_input;
|
|
$instrumentid = 0;
|
|
if (isset($param['instrumentid'])) {
|
|
if (is_numeric($param['instrumentid'])) {
|
|
$instrumentid = $param['instrumentid'];
|
|
}
|
|
} else {
|
|
$this->sys_error("Instrument id, control id, test id, startdate, enddate is mandatory");
|
|
exit;
|
|
}
|
|
$controlid = 0;
|
|
if (isset($param['controlid'])) {
|
|
if (is_numeric($param['controlid'])) {
|
|
$controlid = $param['controlid'];
|
|
}
|
|
} else {
|
|
$this->sys_error("Instrument id, control id, test id, startdate, enddate is mandatory");
|
|
exit;
|
|
}
|
|
$testid = 0;
|
|
if (isset($param['testid'])) {
|
|
if (is_numeric($param['testid'])) {
|
|
$testid = $param['testid'];
|
|
}
|
|
} else {
|
|
$this->sys_error("Instrument id, control id, test id, startdate, enddate is mandatory");
|
|
exit;
|
|
}
|
|
$sql = "SELECT
|
|
avg(M_QcResultValue) mean,
|
|
stddev(M_QcResultValue) sd
|
|
FROM m_qc_result
|
|
JOIN m_qc ON M_QcID = M_QcResultM_QcID
|
|
AND M_QcIsActive = 'Y'
|
|
JOIN nat_qc ON Nat_QcID = M_QcNat_QcID
|
|
AND Nat_QcNat_QcControlID = ?
|
|
AND Nat_QcNat_InstrumentID = ?
|
|
AND Nat_QcNat_TestID = ?
|
|
WHERE M_QcResultIsActive = 'Y'
|
|
AND date(M_QcResultDate) + INTERVAL 1 YEAR > date(now())";
|
|
$qry = $this->db->query($sql, [$controlid, $instrumentid, $testid]);
|
|
$last_qry = $this->db->last_query();
|
|
$count = "SELECT
|
|
avg(M_QcResultValue) mean,
|
|
stddev(M_QcResultValue) sd
|
|
FROM m_qc_result
|
|
JOIN m_qc ON M_QcID = M_QcResultM_QcID
|
|
AND M_QcIsActive = 'Y'
|
|
JOIN nat_qc ON Nat_QcID = M_QcNat_QcID
|
|
AND Nat_QcNat_QcControlID = ?
|
|
AND Nat_QcNat_InstrumentID = ?
|
|
AND Nat_QcNat_TestID = ?
|
|
WHERE M_QcResultIsActive = 'Y'
|
|
AND date(M_QcResultDate) + INTERVAL 1 YEAR > date(now())";
|
|
$qry_total_filter = $this->db->query($count, [$controlid, $instrumentid, $testid]);
|
|
$last_qry_total = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
if (!$qry_total_filter) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry_total
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$total_filter = (int)$qry_total_filter->result_array()[0]["total"];
|
|
$result = array(
|
|
"total" => $total_filter,
|
|
"records" => $rows,
|
|
"sql" => $last_qry,
|
|
"count" => $last_qry_total
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|