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

190 lines
6.6 KiB
PHP

<?php
class Hs_check extends MY_Controller
{
function __construct()
{
parent::__construct();
}
function sex() {
$sql = "select T_OrderHeaderLabNumber,M_TitleName, M_PatientName, M_PatientM_SexID,
' ' Action, M_PatientID
from one_hs.t_order
join t_orderheader on T_OrderT_OrderHeaderID = T_OrderHeaderID
and T_OrderCreated + interval 2 day > now()
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
and ( M_PatientM_SexID = 0 or M_PatientM_SexID is null )
join m_title on M_PatientM_TitleID = M_TitleID
order by T_OrderHeaderID desc ";
$qry = $this->db->query($sql);
if (!$qry) {
echo "Error : " . $this->db->error()["message"];
exit();
}
$rows = $qry->result_array();
foreach ($rows as $idx => $r) {
$url_fix_laki =
"/one-api/tools/hs_check/fix_patient/" .
$r["M_PatientID"] .
"/1" ;
$url_fix_wanita =
"/one-api/tools/hs_check/fix_patient/" .
$r["M_PatientID"] .
"/2" ;
$rows[$idx]["Action"] = "<button onClick=\"document.location.href='{$url_fix_laki}'\"
style='padding:5px; color:white; border: solid 0px; border-radius: 5px;
background-color:blue; margin-top:20px; display:block;' >FIX Laki Laki</button>";
$rows[$idx]["Action"] .= "<button onClick=\"document.location.href='{$url_fix_wanita}'\"
style='padding:5px; color:white; border: solid 0px; border-radius: 5px;
background-color:blue; margin-top:20px; display:block;' >FIX Perempuan</button>";
unset($rows[$idx]["M_PatientID"]);
}
$this->print_table_style();
$this->print_table($rows, array_keys($rows[0]));
}
function aging_fix($id, $aging)
{
$this->db->trans_begin();
$sql = "update t_ordersample set T_OrderSampleReadyToProcessDateTime =
concat(T_OrderSampleReceiveDate, ' ', T_OrderSampleReceiveTime) + interval ? minute
where T_OrderSampleID = ? and T_OrderSampleReadyToProcessDateTime is null ";
$qry = $this->db->query($sql, [$aging, $id]);
if (!$qry) {
echo "Error : " . $this->db->error()["message"];
$this->db->trans_rollback();
exit();
}
$sql = "select * from t_ordersample where T_OrderSampleID = ?";
$qry = $this->db->query($sql, [$id]);
if (!$qry) {
echo "Error : " . $this->db->error()["message"];
$this->db->trans_rollback();
exit();
}
$rows = $qry->result_array();
$this->print_table_style();
$this->print_table($rows, array_keys($rows[0]));
$this->db->trans_commit();
header("Location: /one-api/tools/hs_check/sample_aging");
}
function sample_aging_non_hs() {
$sql = "select T_OrderHeaderLabNumber, T_OrderSampleT_SampleTypeID,
T_SampleTypeName, T_SampleTypeAgingOnHold, T_SampleTypeAgingOnHoldTime,
concat(T_OrderSampleReceiveDate, ' ',T_OrderSampleReceiveTime) ReceiveDate,
T_OrderSampleReadyToProcessDateTime,T_OrderSampleID,
' ' Action
from t_orderheader
join t_ordersample on T_OrderHeaderID = T_OrderSampleT_OrderHeaderID
and T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderDate + interval 1 day > now()
join t_sampletype on T_OrderSampleT_SampleTypeID = T_SampleTypeID
and T_SampleTypeAgingOnHold = 'Y'
and T_OrderHeaderID not in ( select T_OrderHeaderID from one_hs.t_order)
order by T_OrderHeaderID desc ";
$qry = $this->db->query($sql);
if (!$qry) {
echo "Error : " . $this->db->error()["message"];
exit();
}
$rows = $qry->result_array();
foreach ($rows as $idx => $r) {
if (trim($r["T_OrderSampleReadyToProcessDateTime"]) == "") {
$url_fix =
"/one-api/tools/hs_check/aging_fix/" .
$r["T_OrderSampleID"] .
"/" .
$r["T_SampleTypeAgingOnHoldTime"];
$rows[$idx]["Action"] = "<button onClick=\"document.location.href='{$url_fix}'\"
style='padding:5px; color:white; border: solid 0px; border-radius: 5px;
background-color:blue; margin-top:20px; display:block;' >FIX</button>";
}
unset($rows[$idx]["T_OrderSampleID"]);
}
$this->print_table_style();
$this->print_table($rows, array_keys($rows[0]));
}
function sample_aging()
{
$sql = "select T_OrderHeaderLabNumber, T_OrderSampleT_SampleTypeID,
T_SampleTypeName, T_SampleTypeAgingOnHold, T_SampleTypeAgingOnHoldTime,
concat(T_OrderSampleReceiveDate, ' ',T_OrderSampleReceiveTime) ReceiveDate,
T_OrderSampleReadyToProcessDateTime,T_OrderSampleID,
' ' Action
from one_hs.t_order
join t_orderheader on T_OrderT_OrderHeaderID = T_OrderHeaderID
join t_ordersample on T_OrderT_OrderHeaderID = T_OrderSampleT_OrderHeaderID
and T_OrderIsActive = 'Y'
and T_OrderCreated + interval 2 day > now()
join t_sampletype on T_OrderSampleT_SampleTypeID = T_SampleTypeID
and T_SampleTypeAgingOnHold = 'Y'
order by T_OrderHeaderID desc ";
$qry = $this->db->query($sql);
if (!$qry) {
echo "Error : " . $this->db->error()["message"];
exit();
}
$rows = $qry->result_array();
foreach ($rows as $idx => $r) {
if (trim($r["T_OrderSampleReadyToProcessDateTime"]) == "") {
$url_fix =
"/one-api/tools/hs_check/aging_fix/" .
$r["T_OrderSampleID"] .
"/" .
$r["T_SampleTypeAgingOnHoldTime"];
$rows[$idx]["Action"] = "<button onClick=\"document.location.href='{$url_fix}'\"
style='padding:5px; color:white; border: solid 0px; border-radius: 5px;
background-color:blue; margin-top:20px; display:block;' >FIX</button>";
}
unset($rows[$idx]["T_OrderSampleID"]);
}
$this->print_table_style();
$this->print_table($rows, array_keys($rows[0]));
}
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;
margin-left:auto;
margin-right:auto;
}
</style>
";
}
public function print_table_one_column($rows)
{
$rst = "<table>";
foreach ($rows as $r) {
$rst .= "<tr>";
$rst .= "<td>" . $r . "</td>";
$rst .= "</tr>";
}
$rst .= "</table>";
return $rst;
}
public function print_table($rows, $keys)
{
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>";
}
}