225 lines
6.5 KiB
PHP
225 lines
6.5 KiB
PHP
<?php
|
|
class Itf extends MY_Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db->query("use one_bb");
|
|
}
|
|
function raw()
|
|
{
|
|
$param = $this->sys_input;
|
|
try {
|
|
$instrumentID = $param["instrumentID"];
|
|
$data = $param["data"];
|
|
$sql = "insert into bb_raw(bb_RawInstrumentID,bb_RawData)
|
|
values(?,?)";
|
|
$this->db->query($sql, array($instrumentID, base64_decode($data)));
|
|
echo json_encode(
|
|
array("status" => "OK", "id" => $this->db->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"];
|
|
$sql = "insert into bb_result(Bb_ResultNat_InstrumentID, Bb_ResultBb_RawID,
|
|
Bb_ResultNoreg, Bb_ResultInstrumentDate, Bb_ResultKode, Bb_ResultResult, Bb_ResultFlag)
|
|
values(?,?,?,?,?,?,?)";
|
|
foreach ($result["result"] as $r) {
|
|
$tgl = $r["date"];
|
|
$px = $r["px"];
|
|
$result = $r["result"];
|
|
$qry = $this->db->query(
|
|
$sql,
|
|
array(
|
|
$instrumentID, $rawID, $noreg, $tgl, $px,
|
|
$result, $r["flag"]
|
|
)
|
|
);
|
|
if (!$qry) {
|
|
echo json_encode(
|
|
array("status" => "ERR", "message" => $this->db->error()["message"])
|
|
);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
//TODO
|
|
//insert into bb_instrumentresult
|
|
$sql = "insert into bb_resultinstrument(
|
|
Bb_ResultInstrumentTd_OrderImltdDetaiID,
|
|
Bb_ResultInstrumentResult,
|
|
Bb_ResultInstrumentInstrumentDate,
|
|
Bb_ResultInstrumentIncomingDate,
|
|
Bb_ResultInstrumentBb_RawID,
|
|
Bb_ResultInstrumentNat_InstrumentID
|
|
)
|
|
select
|
|
Td_OrderImltdDetailID,
|
|
Bb_ResultResult,
|
|
ifnull(Bb_ResultInstrumentDate,Bb_ResultDate),
|
|
Bb_ResultDate,
|
|
Bb_ResultBb_RawID,
|
|
Bb_ResultNat_InstrumentID
|
|
from
|
|
bb_result br
|
|
join td_order
|
|
on Td_OrderNumber = Bb_ResultNoreg
|
|
and Bb_ResultIsSent = 'N'
|
|
and Td_OrderNumber = ?
|
|
and Bb_ResultBb_RawID = ?
|
|
join td_orderimltd on Td_OrderID = Td_OrderImltdTd_OrderID
|
|
join td_orderimltd_detail on Td_OrderImltdID = Td_OrderImltdDetailTd_OrderImltdId
|
|
join td_test on Td_OrderImltdDetailTd_TestID = Td_TestID
|
|
and Td_TestAssay = Bb_ResultKode";
|
|
$qry = $this->db->query($sql, [$noreg, $rawID]);
|
|
|
|
if (!$qry) {
|
|
echo json_encode(
|
|
array("status" => "ERR", "message" => $this->db->error()["message"])
|
|
);
|
|
exit;
|
|
}
|
|
|
|
$sql = "update
|
|
bb_result br
|
|
join td_order
|
|
on Td_OrderNumber = Bb_ResultNoreg
|
|
and Td_OrderNumber = ?
|
|
and Bb_ResultBb_RawID = ?
|
|
join td_orderimltd on Td_OrderID = Td_OrderImltdTd_OrderID
|
|
join td_orderimltd_detail on Td_OrderImltdID = Td_OrderImltdDetailTd_OrderImltdId
|
|
join td_test on Td_OrderImltdDetailTd_TestID = Td_TestID
|
|
and Td_TestAssay = Bb_ResultKode
|
|
set Bb_ResultIsSent = 'Y'";
|
|
|
|
$qry = $this->db->query($sql, [$noreg, $rawID]);
|
|
if (!$qry) {
|
|
echo json_encode(
|
|
array("status" => "ERR", "message" => $this->db->error()["message"])
|
|
);
|
|
exit;
|
|
}
|
|
|
|
$sql = "update
|
|
bb_result br
|
|
set Bb_ResultIsSent = 'O'
|
|
where Bb_ResultBb_RawID = ?
|
|
and Bb_ResultIsSent = 'N'";
|
|
|
|
$qry = $this->db->query($sql, [$rawID]);
|
|
if (!$qry) {
|
|
echo json_encode(
|
|
array("status" => "ERR", "message" => $this->db->error()["message"])
|
|
);
|
|
exit;
|
|
}
|
|
// Proses ke result
|
|
$sql = "update td_orderimltd_detail
|
|
join bb_resultinstrument on Bb_ResultInstrumentBb_RawID = ?
|
|
and Td_OrderImltdDetailID = Bb_ResultInstrumentTd_OrderImltdDetaiID
|
|
and Td_OrderImltdDetailResult = ''
|
|
set Td_OrderImltdDetailResult = Bb_ResultInstrumentResult
|
|
";
|
|
$qry = $this->db->query($sql, [$rawID]);
|
|
if (!$qry) {
|
|
echo json_encode(
|
|
array("status" => "ERR", "message" => $this->db->error()["message"])
|
|
);
|
|
exit;
|
|
}
|
|
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_bb_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_v2(?,?,?)";
|
|
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())
|
|
);
|
|
}
|
|
}
|
|
}
|