Files
BE_IBL/application/controllers/v1/su/Portserver_kd.php
2026-04-15 15:23:57 +07:00

190 lines
5.6 KiB
PHP

<?php
class Portserver_kd extends MY_Controller
{
public function __construct()
{
parent::__construct();
$this->db_one = $this->load->database("onedev", true);
}
function fpp($fppNo)
{
$sql = "call sp_itf_result_brn(?)";
$qry = $this->db->query($sql, [$fppNo]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => "sp_itf_result_brn |" . $this->db->error()["message"]]);
exit;
}
echo json_encode(["status" => "OK", "message" => ""]);
}
function get_orderdetail_id($orderID, $instrumentID, $assay)
{
$sql = "select T_OrderDetailID, m_instrumentassay.*
from t_orderdetail
join t_test on T_OrderDetailT_OrderHeaderID = ?
and T_OrderDetailIsActive = 'Y'
and T_TestID = T_OrderDetailT_TestID
join m_instrumentassay on M_InstrumentAssayNat_instrumentID = ?
and M_InstrumentAssayNat_TestID = T_TestNat_TestID
and M_InstrumentAssayIsActive = 'Y'
and M_InstrumentAssayCode = ?";
$qry = $this->db->query($sql, [$orderID, $instrumentID, $assay]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => "Get itf_result |" . $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
return $rows;
}
function raw()
{
$param = $this->sys_input;
try {
$instrumentID = $param["instrumentID"];
$data = $param["data"];
$sql = "insert into itf_raw(itf_RawNat_InstrumentID,itf_RawData)
values(?,?)";
$this->db_one->query($sql, array($instrumentID, base64_decode($data)));
echo json_encode(
array("status" => "OK", "id" => $this->db_one->insert_id(), "message" => "")
);
} catch (exception $e) {
echo json_encode(
array("status" => "ERR", "id" => 0, "message" => $e . message())
);
}
}
function result()
{
$param = $this->sys_input;
try {
$instrumentID = $param["instrumentID"];
$rawID = $param["rawID"];
$result = $param["result"];
$noreg = $result["nolab"];
$len_noreg = 10;
if (strlen($noreg) > $len_noreg) {
$noreg = substr($noreg, 0, 10);
}
$sql = "insert into itf_result(itf_ResultNat_InstrumentID, itf_ResultItf_RawID,
Itf_ResultNoreg, Itf_ResultInstrumentDate, itf_ResultKode, itf_ResultResult, itf_ResultFlag)
values(?,?,?,?,?,?,?)";
foreach ($result["result"] as $r) {
$tgl = $r["date"];
$px = $r["px"];
$result = $r["result"];
$this->db_one->query(
$sql,
array(
$instrumentID, $rawID, $noreg, $tgl, $px,
$result, $r["flag"]
)
);
}
if ($instrumentID == 1) {
$sql = "call sp_itf_result_alinity(?)";
} else {
$sql = "call sp_itf_result(?)";
}
$this->db->query($sql, array($rawID));
// auto calc
$s_noreg = substr($noreg, 0, 10);
$sql = "select T_OrderHeaderID from t_orderheader where T_OrderHeaderLabNumber = ? ";
$qry = $this->db->query($sql, array($s_noreg));
$order_id = 0;
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0) {
$order_id = $rows[0]["T_OrderHeaderID"];
$this->load->library("Resultcalc");
$this->resultcalc->auto($order_id);
//file_put_contents("/xtmp/re-query.sql",$order_id);
}
}
echo json_encode(
array("status" => "OK", "message" => "")
);
} catch (exception $e) {
echo json_encode(
array("status" => "ERR", "message" => $e->message())
);
}
}
function order()
{
$param = $this->sys_input;
$sampleID = $param["sampleID"];
$instrumentID = $param["instrumentID"];
$sql = "call sp_itf_order_v2(?,?)";
try {
$qry = $this->db->query($sql, array($instrumentID, $sampleID));
if (isset($qry->result_id->num_rows)) {
$rows = $qry->result_array();
echo json_encode(
array("status" => "OK", "order" => $rows)
);
} else {
echo json_encode(
array("status" => "OK", "order" => array())
);
}
} catch (exception $e) {
echo json_encode(
array("status" => "ERR", "message" => $e->message())
);
}
}
function update_order()
{
$param = $this->sys_input;
$sampleID = $param["sampleID"];
$instrumentID = $param["instrumentID"];
$status = $param["status"];
$sql = "call sp_itf_order_update(?,?,?)";
try {
$qry = $this->db->query($sql, array($instrumentID, $sampleID, $status));
if ($qry) {
echo json_encode(
array("status" => "OK", "message" => "")
);
} else {
$msg = print_r($this->db->error(), true);
echo json_encode(
array("status" => "OK", "message" => $msg)
);
}
} catch (exception $e) {
echo json_encode(
array("status" => "ERR", "message" => $e->message())
);
}
}
function reset_order()
{
$param = $this->sys_input;
$sampleID = $param["sampleID"];
$instrumentID = $param["instrumentID"];
$status = $param["status"];
$sql = "call sp_itf_order_reset(?,?,?)";
try {
$qry = $this->db->query($sql, array($instrumentID, $sampleID, $status));
if ($qry) {
echo json_encode(
array("status" => "OK", "message" => "")
);
} else {
$msg = print_r($this->db->error(), true);
echo json_encode(
array("status" => "OK", "message" => $msg)
);
}
} catch (exception $e) {
echo json_encode(
array("status" => "ERR", "message" => $e->message())
);
}
}
}