Files
BE_IBL/application/controllers/fix/Itf.php
2026-04-15 15:23:57 +07:00

399 lines
12 KiB
PHP

<?php
class Itf extends MY_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
echo "<pre>";
echo "order [instrumentID] [Nomor Reg]:\n Untuk melihat Status Order\n\n";
echo "reset_order [instrumentID] [Nomor Reg]:\n Untuk Mereset Order\n\n";
}
function cek($nolab, $test = "ALL")
{
$sql = "select * from t_orderheader where T_OrderHeaderLabNumber = ?";
$qry = $this->db->query($sql, [$nolab]);
if (!$qry) {
$this->query_error();
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo "<pre>No Order found.\n";
exit;
}
$orderID = $rows[0]["T_OrderHeaderID"];
$sql = "select T_OrderDetailID, T_OrderDetailT_TestName, T_OrderDetailNat_InstrumentID ,
Nat_InstrumentName, T_OrderDetailResult
from t_orderdetail
left join nat_instrument on
T_OrderDetailIsActive = 'Y'
and T_OrderDetailNat_InstrumentID = Nat_InstrumentID
where T_OrderDetailT_OrderHeaderID = ?
";
$qry = $this->db->query($sql, [$orderID]);
if (!$qry) {
$this->query_error();
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo "<pre>No Order Detail found.\n";
exit;
}
$fields = array_keys($rows[0]);
$this->print_table($rows, $fields);
}
function raw($rawID)
{
$sql = "select Nat_InstrumentName, itf_RawDate, concat('<PRE>', Itf_RawData, '</PRE>') RawData
from itf_raw
join nat_instrument on Nat_InstrumentID = Itf_RawNat_InstrumentID
where itf_RawID=?";
$qry = $this->db->query($sql, [$rawID]);
if (!$qry) {
$this->query_error();
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo "<pre>No Parsing Record found.\n";
exit();
}
$fields = array_keys($rows[0]);
$this->print_table($rows, $fields);
$sql = "select
Itf_ResultInstrumentDate, Itf_ResultNoreg, Itf_ResultKode, Itf_ResultResult, Itf_ResultIsSent, itf_ResultBacteri, itf_ResultAnti
from itf_result where Itf_ResultItf_RawID = ?";
$qry = $this->db->query($sql, [$rawID]);
if (!$qry) {
$this->query_error();
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo "<pre>No Record found.\n";
echo $this->db->last_query();
exit();
}
$fields = array_keys($rows[0]);
$this->print_table($rows, $fields);
}
function incoming($instrumentID, $nolab)
{
$sample = $nolab . "%";
$sql = "select
Itf_ResultInstrumentDate, Itf_ResultNoreg, Itf_ResultAssay, Itf_ResultResult, ItfResultRawID
from itf_result
where Itf_ResultNoreg like ?
and Itf_ResultNat_InstrumentID=?";
$qry = $this->db->query($sql, [$sample, $instrumentID]);
if (!$qry) {
$this->query_error();
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo "<pre>No Record found.\n";
echo $this->db->last_query();
exit();
}
$fields = array_keys($rows[0]);
$this->print_table($rows, $fields);
}
public function print_table_style()
{
echo "
<style>
th, td {
padding: 15px;
text-align: left;
}
tr:nth-child(even) {background-color: #f2f2f2;}
table {
border: solid 1px ;
min-width:600px;
}
</style>
";
}
public function print_table($rows, $keys)
{
$this->print_table_style();
echo "<table>";
echo "<tr>";
foreach ($keys as $k) {
echo "<td>$k</td>";
}
echo "</tr>\n";
foreach ($rows as $r) {
echo "<tr>";
foreach ($keys as $k) {
echo "<td>" . $r[$k] . "</td>";
}
echo "</tr>";
}
echo "</table>";
}
public function instrument($query = "")
{
$query = "%$query%";
$sql = "select Nat_InstrumentID,Nat_InstrumentName, Nat_InstrumentIsActive
from nat_instrument
join t_instrument_local on T_InstrumentLocalNat_InstrumentID = Nat_InstrumentID
and T_InstrumentLocalIsActive = 'Y'
and Nat_InstrumentName like ?";
$qry = $this->db->query($sql, [$query]);
if (!$qry) {
$this->query_error();
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo "<pre>No Record found.\n";
echo $this->db->last_query();
exit();
}
$fields = array_keys($rows[0]);
$this->print_table($rows, $fields);
}
public function query_error()
{
echo "<pre>Erro Query : " . $this->db->error()["message"] . "\n";
echo $this->db->last_query();
exit();
}
public function reset_order($instrumentID, $nolab, $status = "N")
{
echo "<pre>";
$sql = "call sp_itf_order_reset(?,?,?)";
try {
$qry = $this->db->query($sql, [$instrumentID, $nolab, $status]);
if ($qry) {
echo json_encode(["status" => "OK", "message" => ""]);
} else {
$msg = print_r($this->db->error(), true);
echo json_encode(["status" => "OK", "message" => $msg]);
}
} catch (exception $e) {
echo json_encode(["status" => "ERR", "message" => $e->message()]);
}
}
public function order_api_v2($instrumentID, $sampleID)
{
$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())
);
}
}
public function order_api($instrumentID, $sampleID)
{
$sql = "call sp_itf_order(?,?)";
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())
);
}
}
public function order($instrumentID, $nolab)
{
$sql = " select
T_BarcodeLabT_OrderHeaderID, T_BarcodeLabT_SampleTypeID ,
T_BarcodeLabBarcode
from t_barcodelab
where T_BarcodeLabBarcode like concat(?,'%')
and T_BarcodeLabIsActive ='Y'
order by T_BarcodeLabID desc
limit 0,1; ";
$qry = $this->db->query($sql, [$nolab]);
if (!$qry) {
echo "ERR select order :\n";
print_r($this->db->error());
exit();
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo "Checking Order from rujukan</p>";
$sql = " select
T_BarcodeLabT_OrderHeaderID, T_BarcodeLabT_SampleTypeID ,
T_BarcodeLabBarcodeOrigin
from t_barcodelab
where T_BarcodeLabBarcodeOrigin like concat(?,'%')
and T_BarcodeLabIsActive ='Y'
limit 0,1";
$qry = $this->db->query($sql, [$nolab]);
if (!$qry) {
echo "ERR select order :\n";
print_r($this->db->error());
exit();
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo "Checking Order from rujukan WorkAround</p>";
//02208301DCSK
$nolab_only = substr($nolab, 0, 10);
$sample = substr($nolab, 10, 2);
$sql = "select concat(T_OrderHeaderLabNumber,?) Nolab
from t_orderheaderaddon
join t_orderheader on T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
and T_OrderHeaderIsActive = 'Y'
where T_OrderHeaderAddOnLabNumberOrigin= ?
and T_OrderHeaderAddOnIsActive = 'Y'";
$qry = $this->db->query($sql, [$sample, $nolab_only]);
if (!$qry) {
echo "ERR select order WorkAround :\n";
print_r($this->db->error());
exit();
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo "ERR order not found : noreg $nolab\n";
exit();
}
$new_nolab = $rows[0]["Nolab"];
$sql = " select
T_BarcodeLabT_OrderHeaderID, T_BarcodeLabT_SampleTypeID ,
T_BarcodeLabBarcode
from t_barcodelab
where T_BarcodeLabBarcode like concat(?,'%')
and T_BarcodeLabIsActive ='Y'
order by T_BarcodeLabID desc
";
$qry = $this->db->query($sql, [$new_nolab]);
if (!$qry) {
echo "ERR select order :\n";
print_r($this->db->error());
exit();
}
$rows = $qry->result_array();
print_r($rows);
if (count($rows) == 0) {
echo "ERR order not found : noreg $nolab\n";
exit();
}
$r = $rows[0];
$barcode = $r["T_BarcodeLabBarcode"];
} else {
$r = $rows[0];
$barcode = $r["T_BarcodeLabBarcode"];
}
} else {
$r = $rows[0];
$barcode = $r["T_BarcodeLabBarcode"];
}
$orderHeaderID = $r["T_BarcodeLabT_OrderHeaderID"];
$sampleTypeID = $r["T_BarcodeLabT_SampleTypeID"];
$sql = "select if(@flagOrigin, T_OrderHeaderAddOnLabNumberOrigin,
T_OrderHeaderLabNumber) T_OrderHeaderLabNumber,
concat(M_TitleName,' ', M_PatientName)
M_PatientName,
concat(M_DoctorPrefix, if(M_DoctorPrefix <> '' , ' ','') ,
M_DoctorPrefix2,if(M_DoctorPrefix2 <> '' , ' ',''),
M_DoctorName,
M_DoctorSufix) M_DoctorName,
replace(M_PatientDob,'-','') M_PatientDob,
T_OrderHeaderM_PatientAge, T_OrderHeaderDate ,
M_PatientNoReg,
case
when M_SexCode = 'P' then 'F'
when M_SexCode = 'L' then 'M'
else M_SexCode
end Sex
from t_orderheader
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
join m_patient on T_OrderHeaderID =?
and M_PatientID = T_OrderHeaderM_PatientID
and T_OrderHeaderIsActive = 'Y'
and M_PatientIsActive = 'Y'
join m_sex on M_PatientM_SexID = M_SexID
join m_title on M_PatientM_TitleID = M_TitleID
join m_doctor on T_OrderHeaderSenderM_DoctorID = M_DoctorID ";
$qry = $this->db->query($sql, [$orderHeaderID]);
if (!$qry) {
echo "ERR select order :\n";
$this->query_error();
}
$rows = $qry->result_array();
$r = $rows[0];
$noreg = $r["T_OrderHeaderLabNumber"];
$pasien = $r["M_PatientName"];
$dokter = $r["M_DoctorName"];
$dob = $r["M_PatientDob"];
$orderDate = $r["T_OrderHeaderDate"];
$sex = $r["M_SexCode"];
$pid = $r["pid"];
$this->print_table([$r], array_keys($r));
echo "<p>Assay</p>";
$sql = "select
T_OrderDetailAddOnID,T_OrderDetailT_TestName, M_InstrumentAssayCode,T_OrderDetailAddOnFlagIsRunning,
if(T_OrderDetailAddOnFlagIsRunning='N','-',T_OrderDetailAddOnRunDate)
T_OrderDetailAddOnRunDate,
Nat_InstrumentName
from
m_instrumentassay
join t_test on M_InstrumentAssayNat_TestID = T_TestNat_TestID
and M_InstrumentAssayNat_InstrumentID = ?
and M_InstrumentAssayIsActive = 'Y'
and M_InstrumentAssaySentToInstrument ='Y'
and (
T_TestT_SampleTypeID = ? or
fn_sampletype_from_local(T_TestNat_TestID) = ?
)
join t_orderdetail on T_OrderDetailT_OrderHeaderID = ?
and T_OrderDetailT_TestID = T_TestID and T_OrderDetailIsActive = 'Y'
join t_orderdetailaddon on T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID
left join nat_instrument on T_OrderDetailAddOnRunNat_InstrumentID = Nat_InstrumentID
";
$qry = $this->db->query($sql, [
$instrumentID,
$sampleTypeID,
$sampleTypeID,
$orderHeaderID,
]);
if (!$qry) {
echo "ERR select Assay :\n";
$this->query_error();
exit();
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo "No Assay.";
echo "<pre>" . $this->db->last_query() . "</pre>";
exit();
}
$f = array_keys($rows[0]);
$this->print_table($rows, $f);
}
}