Initial import

This commit is contained in:
sas.fajri
2026-04-27 10:26:26 +07:00
commit bf9b9097ee
2388 changed files with 3002242 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,356 @@
<?php
class Interface_qc extends MY_Controller
{
function __construct()
{
parent::__construct();
}
function get_rows($sql, $param = false)
{
if ($param) {
$qry = $this->db->query($sql, $param);
} else {
$qry = $this->db->query($sql);
}
if (!$qry) {
return array("status" => false, "message" => $this->db->error()["message"] . "|"
. $this->db->last_query());
}
return array("status" => true, "rows" => $qry->result_array());
}
function get_one_row($sql, $param = false)
{
$rs = $this->get_rows($sql, $param);
if ($rs["status"] == false) {
return
array("status" => false, "notfound" => false, "message" => $rs["message"]);
}
if (count($rs["rows"]) == 0) {
return array("status" => false, "notfound" => true, "row" => array());
}
return array("status" => true, "row" => $rs["rows"][0]);
}
function log($msg)
{
echo date("Y-m-d H:i:s") . " " . $msg . "\n";
}
function get_last_rawID($instrumentID, $date)
{
$sql = "select max(itfQcLastItfRawID) maxRawID
from itf_qc
where itfQcNat_InstrumentID = ?
and itfQcDate = ?";
$rs = $this->get_one_row($sql, array($instrumentID, $date));
if ($rs["status"] === false && $rs["notfound"] === false) {
$this->log("Error Get Max RawID : [{$instrumentID}] [{$date}]" . $rs["message"]);
exit;
}
if ($rs["status"] == false) return 0;
if ($rs["row"]["maxRawID"] == "") return 0;
return $rs["row"]["maxRawID"];
}
function parse_qc_alinity($result)
{
if (strpos($result, "\n") > 0 && strpos($result, "\r") > 0) {
$result = str_replace("\n", "", $result);
$lines = explode("\r", $result);
} else if (strpos($result, "\n") > 0) {
$lines = explode("\n", $result);
} else {
$lines = explode("\r", $result);
}
$lines = array_map(function ($r) {
return explode("|", $r);
}, $lines);
$lines = array_filter($lines, function ($r) {
if ($r[0] == "O" || $r[0] == "R") return true;
return false;
});
$o_qc = array_filter($lines, function ($l) {
if ($l[0] == "O") {
if ($l[11] == "Q") {
return true;
}
}
});
if (count($o_qc) == 0) {
return false;
}
$number = "";
$result = "";
$arr_result = array();
foreach ($lines as $l) {
if ($l[0] == "O") {
$number = $l[2];
} else if ($l[0] == "R") {
$a_test = explode("^", $l[2]);
if (count($a_test) >= 6) {
$test = $a_test[3];
if ($a_test[6] == "F") {
$result = $l[3];
if ($result == "" || $number == "" || $test == "") {
continue;
}
$arr_result[] = array(
"no" => $number,
"assay" => $test,
"result" => $result
);
$number = "";
$test = "";
$result = "";
}
}
}
}
return $arr_result;
}
function parse_qc_cobas_c8000($result)
{
if (strpos($result, "\n") > 0 && strpos($result, "\r") > 0) {
$result = str_replace("\n", "", $result);
$lines = explode("\r", $result);
} else if (strpos($result, "\n") > 0) {
$lines = explode("\n", $result);
} else {
$lines = explode("\r", $result);
}
$lines = array_map(function ($r) {
return explode("|", $r);
}, $lines);
$lines = array_filter($lines, function ($r) {
if ($r[0] == "O" || $r[0] == "R") return true;
return false;
});
$o_qc = array_filter($lines, function ($l) {
if ($l[0] == "O") {
if ($l[11] == "Q") {
return true;
}
}
});
if (count($o_qc) == 0) {
return false;
}
$number = "";
$result = "";
$arr_result = array();
foreach ($lines as $l) {
if ($l[0] == "O") {
$a_number = explode("^",$l[2]);
if (count($a_number) >= 1) {
$number = $a_number[1];
}
} else if ($l[0] == "R") {
$a_test = explode("^", $l[2]);
if (count($a_test) >= 3) {
$test = $a_test[3];
if(strpos($a_test[3],"/") > 0) {
$a_test = explode("/",$a_test[3]);
$test = $a_test[0];
}
$result = $l[3];
if ($result == "" || $number == "" || $test == "") {
continue;
}
$arr_result[] = array(
"no" => $number,
"assay" => $test,
"result" => $result
);
$number = "";
$test = "";
$result = "";
}
}
}
return $arr_result;
}
function parse_qc_xn_1000($result)
{
if (strpos($result, "\n") > 0 && strpos($result, "\r") > 0) {
$result = str_replace("\n", "", $result);
$lines = explode("\r", $result);
} else if (strpos($result, "\n") > 0) {
$lines = explode("\n", $result);
} else {
$lines = explode("\r", $result);
}
$lines = array_map(function ($r) {
return explode("|", $r);
}, $lines);
$lines = array_filter($lines, function ($r) {
if ($r[0] == "O" || $r[0] == "R") return true;
return false;
});
$o_qc = array_filter($lines, function ($l) {
if ($l[0] == "O") {
if ( strpos($l[3],"QC-") > 0) {
return true;
}
}
});
if (count($o_qc) == 0) {
return false;
}
print_r($o_qc);
exit;
$number = "";
$result = "";
$arr_result = array();
foreach ($lines as $l) {
if ($l[0] == "O") {
$a_number = explode("^",$l[2]);
if (count($a_number) >= 1) {
$number = $a_number[1];
}
} else if ($l[0] == "R") {
$a_test = explode("^", $l[2]);
if (count($a_test) >= 3) {
$test = $a_test[3];
if(strpos($a_test[3],"/") > 0) {
$a_test = explode("/",$a_test[3]);
$test = $a_test[0];
}
$result = $l[3];
if ($result == "" || $number == "" || $test == "") {
continue;
}
$arr_result[] = array(
"no" => $number,
"assay" => $test,
"result" => $result
);
$number = "";
$test = "";
$result = "";
}
}
}
return $arr_result;
}
function parse($instrumentID, $date = "")
{
//2021-05-27
if ($date == "") $date = date("Y-m-d");
$this->log("Start Parce Qc InstrumentID : {$instrumentID} Date {$date}");
// get 50 rawID
$lastRawID = $this->get_last_rawID($instrumentID, $date);
//get rawID
$sql = "select * from itf_raw
where Itf_RawNat_InstrumentID = ?
and Itf_RawID > ?
and date(Itf_RawDate) = ?
limit 0,100";
$rs = $this->get_rows($sql, array($instrumentID, $lastRawID, $date));
if ($rs["status"] === false) {
$this->log("Err get Raw Data : " . $rs["message"]);
exit;
}
$rawID = $lastRawID;
$this->db->trans_begin();
$arr_qc_ids = array();
$last_qc_id = 0;
foreach ($rs["rows"] as $r) {
$rawID = $r["Itf_RawID"];
$instrumentID = $r["Itf_RawNat_InstrumentID"];
$qcData = array();
switch ($instrumentID) {
case 1:
$qcData = $this->parse_qc_alinity($r["Itf_RawData"]);
break;
case 2:
$qcData = $this->parse_qc_cobas_c8000($r["Itf_RawData"]);
break;
case 5:
$qcData = $this->parse_qc_xn_1000($r["Itf_RawData"]);
break;
}
if ($qcData != array()) {
//
foreach($qcData as $dt) {
$data = array(
"itfQcNat_InstrumentID" => $instrumentID,
"itfQcDate" => $date,
"itfQcNumber" => $dt["no"],
"itfQcAssay" => $dt["assay"],
"itfQcResult" => $dt["result"],
"itfQcNat_TestID" => 0,
"itfQcLastItfRawID" => $rawID
);
$qry = $this->db->insert("itf_qc", $data);
if (!$qry) {
$this->log("Error save itf_qc : " . $this->db->error()["message"] . "|" .
$this->db->last_query());
$this->db->trans_rollback();
exit;
}
$last_qc_id = $this->db->insert_id();
$arr_qc_ids[] = $last_qc_id;
}
}
}
if ($rawID > $lastRawID) {
if ($last_qc_id > 0 ) {
$sql = "update itf_qc set itfQcLastItfRawID=? where itfQcID=?";
$qry = $this->db->query($sql, array($rawID, $last_qc_id));
} else {
$sql = "select max(itfQcID) maxID
from itf_qc where itfQcIsActive='Y'
and itfQcDate = '$date'
and itfQcNat_InstrumentID = $instrumentID";
$res = $this->get_one_row($sql);
if (! $res["status"]) {
$this->log("Error get max itf_qc : " . $res["message"]);
$this->db->trans_rollback();
exit;
}
if (! $res["notfound"]) {
$last_qc_id = 0;
} else {
$last_qc_id = $res["row"]["maxID"];
if ($last_qc_id == "") $last_qc_id = 0;
}
if ( $last_qc_id == 0) {
$sql = "insert into itf_qc(itfQcNat_InstrumentID,itfQcDate,itfQcNumber,itfQcLastItfRawID) values($instrumentID,'$date','dummy',$rawID)";
$qry = $this->db->query($sql);
} else {
$sql = "update itf_qc set itfQcLastItfRawID=? where itfQcID=?";
$qry = $this->db->query($sql, array($rawID, $last_qc_id));
}
}
if (!$qry) {
$this->log("Error save itf_qc : " . $this->db->error()["message"] . "|" .
$this->db->last_query());
$this->db->trans_rollback();
exit;
}
}
if (count($arr_qc_ids) > 0 ) {
$str_qc_id = implode(",",$arr_qc_ids);
//update nat_id
$sql = "update
itf_qc
join m_instrumentassay
on itfQcID in ($str_qc_id)
and itfQcNat_InstrumentID = '$instrumentID'
and M_InstrumentAssayNat_InstrumentID = itfQcNat_InstrumentID
and M_InstrumentAssayCode = itfQcAssay
and M_InstrumentAssayIsActive='Y'
set itfQcNat_TestID = M_InstrumentAssayNat_TestID";
$qry = $this->db->query($sql);
if (!$qry) {
$this->log("Error update itf_qc nat test : " . $this->db->error()["message"] . "|" .
$this->db->last_query());
$this->db->trans_rollback();
exit;
}
}
$this->log("Done up to $rawID");
$this->db->trans_commit();
}
}

View File

@@ -0,0 +1,70 @@
<?php
class Template extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Template API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function searchbyname()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm['search']; // parameter
$number_limit = 10;
$number_offset = ($prm['page'] - 1) * $number_limit ;
$sql = "SELECT COUNT(*) as total
from m_sex
where
M_SexIsActive = 'Y' AND
m_sexname LIKE CONCAT('%','{$search}','%')";
$query = $this->db_onedev->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("m_sex count", $this->db_onedev);
exit;
}
$sql = "select M_SexID, m_sexname
FROM m_sex
where
M_SexIsActive = 'Y' AND
m_sexname LIKE CONCAT('%','{$search}','%')
ORDER BY m_sexname ASC
limit $number_limit offset $number_offset";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("m_sex 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);
}
}
}