707 lines
34 KiB
PHP
707 lines
34 KiB
PHP
<?php
|
|
|
|
class Check_result_v2 extends MY_Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
echo '<pre>';
|
|
echo "cek [NomorLab]\n Untuk menampilkan sample dari T_OrderHeaderID yang terkait termasuk yg IsActive N\n\n";
|
|
echo "fix_sample [NomorLab] [SampleTypeID] \n Untuk copy status worklist receive dari worklist receive sampletype yg sama yg paling akhir\n\n";
|
|
echo "update_order_sample [T_OrderSampleID targetNya] [T_OrderSampleID sumbernya]\n Copy status T_OrderSample dari sumber ke target \n\n";
|
|
}
|
|
|
|
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 fix_verif_valid($ids) {
|
|
$arr_id = explode("-",$ids);
|
|
$str_ids = implode(",",$arr_id);
|
|
$sql = "update t_orderdetail set T_OrderDetailValidation ='N' where T_OrderDetailID in ($str_ids)";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]);
|
|
exit;
|
|
}
|
|
echo "Updated OK";
|
|
}
|
|
public function cek_valid($nolab) {
|
|
$sql = "select T_OrderDetailID,T_OrderDetailT_TestName, T_OrderDetailVerification,
|
|
T_OrderDetailValidation
|
|
from t_orderheader
|
|
join t_orderdetail
|
|
on T_OrderHeaderLabNumber = ?
|
|
and T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
|
and T_OrderDetailT_TestIsResult = 'Y'
|
|
and T_OrderDetailIsActive = 'Y'
|
|
where
|
|
T_OrderDetailValidation = 'Y' and T_OrderDetailVerification <> 'Y'";
|
|
$qry = $this->db->query($sql,[$nolab]);
|
|
if (!$qry) {
|
|
echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo $this->db->last_query();
|
|
echo "No record";
|
|
exit;
|
|
}
|
|
$this->print_table_style();
|
|
$ids = "0";
|
|
foreach($rows as $r) {
|
|
$ids .= "-" . $r["T_OrderDetailID"];
|
|
}
|
|
$this->print_table($rows,array_keys($rows[0]));
|
|
$url_fix = "/one-api/fix/check_result_v2/fix_verif_valid/$ids";
|
|
echo "<br/><button onClick=\"document.location.href='$url_fix'\">Fix Verif Valid Race</button>";
|
|
}
|
|
|
|
public function get_detail($r)
|
|
{
|
|
$result = "<tr>";
|
|
$result .= "<td> </td>";
|
|
$result .= "<td>Sample Handling</td>";
|
|
$result .= "<td>" . $r["T_OrderSampleHandling"] . "</td>";
|
|
$result .= "<td>" . $r["T_OrderSampleHandlingDate"];
|
|
$result .= " " . $r["T_OrderSampleHandlingTime"] . "</td>";
|
|
$result .= "<td>" . $r["T_OrderSampleHandlingUserID"] . "</td>";
|
|
$result .= "<td colspan=3> </td>";
|
|
$result .= "<tr>";
|
|
return $result;
|
|
}
|
|
public function cek_result($labNo) {
|
|
$sql = "select T_OrderDetailID, T_OrderDetailT_TestSasCode SasCode,
|
|
T_OrderDetailT_TestName T_TestName,T_OrderDetailT_TestIsResult IsResult, T_OrderDetailIsActive IsActive,
|
|
'' Action
|
|
from t_orderdetail
|
|
join t_orderheader on T_OrderHeaderLabNumber = '$labNo' and T_OrderDetailT_OrderHeaderID = T_OrderHeaderID";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
echo "Err : " . $this->db->error()["message"] . "\n";
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $idx => $r) {
|
|
if ($r["IsResult"] == "") {
|
|
$fix_url = "<a href='/one-api/fix/check_result_v2/fix_is_result/" . $r["T_OrderDetailID"] . "/" . $labNo . "'>Fix IsResult to Y </a>";
|
|
$rows[$idx]["Action"] = $fix_url;
|
|
} else {
|
|
$rows[$idx]["Action"] = " ";
|
|
}
|
|
}
|
|
$this->print_table_style();
|
|
echo "<H5> Detail $labNo Px </h5>";
|
|
$this->print_table($rows,array_keys($rows[0]));
|
|
|
|
}
|
|
public function fix_is_result($detailID,$labNo) {
|
|
$sql = "update t_orderdetail set T_OrderDetailT_TestIsResult = 'Y' where T_OrderDetailID = ?";
|
|
$qry = $this->db->query($sql,[$detailID]);
|
|
if(!$qry) {
|
|
echo "Err : " . $this->db->error()["message"] . "\n";
|
|
exit;
|
|
}
|
|
header("Location: /one-api/fix/check_result_v2/cek_result/$labNo");
|
|
}
|
|
public function cek($labNo, $all = false)
|
|
{
|
|
$sql = "select *
|
|
from t_ordersample
|
|
join t_sampletype on T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
join t_orderheader on T_OrderHeaderID = T_OrderSampleT_OrderHeaderID
|
|
where T_OrderSampleIsActive = 'Y' and T_OrderHeaderLabNumber=? order by T_OrderSampleID";
|
|
if ($all) {
|
|
$sql = 'select *
|
|
from t_ordersample
|
|
join t_orderheader on T_OrderHeaderID = T_OrderSampleT_OrderHeaderID
|
|
left join t_sampletype on T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
where T_OrderHeaderLabNumber=? order by T_OrderSampleID';
|
|
}
|
|
$qry = $this->db->query($sql, [$labNo]);
|
|
if (!$qry) {
|
|
echo "ERR : \n";
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
echo '<style>
|
|
th, td {
|
|
padding: 15px;
|
|
text-align: left;
|
|
}
|
|
tr:nth-child(even) {background-color: #f2f2f2;}
|
|
table {
|
|
border: solid 1px ;
|
|
min-width:600px;
|
|
}
|
|
</style>
|
|
';
|
|
echo '<table>';
|
|
echo '<tr>';
|
|
echo "<td>T_OrderSampleID</td> <td>T_OrderSampleBarcode</td> <td>T_SampleTypeName</td> <td>T_SampleTypeID</td> <td>T_OrderSampleWorklistReceive</td> <td>Wl RcvDate</td> <td>Wl RcvTime</td> <td>IsActive</td><td> </td>
|
|
</tr>\n";
|
|
$lastWlReceive = "";
|
|
$lastRecord = array();
|
|
$flagOnlySingle = false;
|
|
if (count($rows) == 1) {
|
|
$flagOnlySingle = true;
|
|
}
|
|
$flagNoReceiveYet = true;
|
|
foreach ($rows as $r) {
|
|
if ($r["T_OrderSampleWorklistReceive"] == "Y") $flagNoReceiveYet = false;
|
|
}
|
|
|
|
foreach ($rows as $r) {
|
|
echo '<tr>';
|
|
echo "<td>{$r['T_OrderSampleID']} </td> <td>{$r['T_OrderSampleBarcode']}</td> <td>{$r['T_SampleTypeName']}</td> <td>{$r['T_SampleTypeID']}</td> <td>{$r['T_OrderSampleWorklistReceive']}</td> <td>" .
|
|
"{$r['T_OrderSampleWorklistReceiveDatetime']}</td> <td>{$r['T_OrderSampleWorklistReceiveUserID']}</td> <td>{$r['T_OrderSampleIsActive']}</td>";
|
|
|
|
if ($r['T_OrderSampleWorklistReceiveDatetime'] != '') {
|
|
$url_target = '/one-api/fix/check_result_v2/fix_sample/' . $r['T_OrderHeaderLabNumber'] . '/' . $r['T_SampleTypeID'];
|
|
echo '<td>';
|
|
echo "<a type='button' target=\"_blank\" href=\"$url_target\"> Fix " . $r['T_SampleTypeName'] . ' lainnya </a>';
|
|
echo '</td>';
|
|
if ($lastWlReceive < $r["T_OrderSampleWorklistReceiveDatetime"]) {
|
|
$lastWlReceive = $r["T_OrderSampleWorklistReceiveDatetime"];
|
|
$lastRecord = $r;
|
|
}
|
|
} else {
|
|
//echo '<td> </td>';
|
|
if ($lastWlReceive == "") {
|
|
if ((true || $flagOnlySingle) && $r["T_OrderSampleHandling"] == "Y") {
|
|
$url_target = '/one-api/fix/check_result_v2/fix_from_sampling/' . $r['T_OrderSampleID'];
|
|
echo '<td>';
|
|
echo "<a type='button' target=\"_blank\" href=\"$url_target\"> Fix from samplingtime </a>";
|
|
|
|
echo "</td>";
|
|
} else {
|
|
echo "<td> </td>";
|
|
}
|
|
} else {
|
|
$url_target = '/one-api/fix/check_result_v2/fix_sample_one/' . $r['T_OrderSampleID'] . '/' . $lastRecord['T_SampleTypeID'];
|
|
echo '<td>';
|
|
echo "<a type='button' target=\"_blank\" href=\"$url_target\"> Fix copy dari " . $lastRecord['T_SampleTypeName'] . ' </a>';
|
|
echo "</td>";
|
|
}
|
|
}
|
|
// $x_note = "<pre>" . print_r($r, true) . "</pre>";
|
|
// echo "<td>$x_note</td>";
|
|
echo '</tr>';
|
|
$detail_info = $this->get_detail($r);
|
|
echo $detail_info;
|
|
}
|
|
}
|
|
|
|
public function fix_from_sampling($targetID)
|
|
{
|
|
$sql = "update t_ordersample target
|
|
join t_ordersample source on
|
|
target.T_OrderSampleID = $targetID
|
|
and target.T_OrderSampleWorklistReceive = 'N'
|
|
and source.T_OrderSampleID = $targetID
|
|
set
|
|
|
|
target.T_OrderSampleWorklistReceive = source.T_OrderSampleHandling,
|
|
target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleHandlingTime,
|
|
target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleHandlingUserID
|
|
";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select T_OrderSampleT_OrderHeaderID, T_OrderSampleT_SampleTypeID
|
|
from t_ordersample where T_OrderSampleID=?";
|
|
$qry = $this->db->query($sql, array($targetID));
|
|
if (!$qry) {
|
|
echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo $this->db->last_query();
|
|
echo "No record";
|
|
exit;
|
|
}
|
|
$headerID = $rows[0]["T_OrderSampleT_OrderHeaderID"];
|
|
$sampleTypeID = $targetID;
|
|
$sql = "
|
|
update t_orderdetailaddon
|
|
join t_orderdetail on T_OrderDetailT_OrderHeaderID = ?
|
|
and T_OrderDetailAddOnT_OrderDetailID = T_OrderDetailID
|
|
and T_OrderDetailAddOnPreAnalytic <> 'Y'
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
and T_TestT_SampleTypeID = ?
|
|
set T_OrderDetailAddOnPreAnalytic = 'Y'
|
|
, T_OrderDetailAddOnPreAnalyticDate=now()";
|
|
$qry = $this->db->query($sql, array($headerID, $sampleTypeID));
|
|
if (!$qry) {
|
|
echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]);
|
|
exit;
|
|
}
|
|
echo 'update OK';
|
|
}
|
|
|
|
public function confirm_fix_sample_one($targetID, $sourceID)
|
|
{
|
|
$target_ids = " $targetID ";
|
|
$sql = "update t_ordersample target
|
|
join t_ordersample source on
|
|
target.T_OrderSampleID in ($target_ids)
|
|
and target.T_OrderSampleWorklistReceive = 'N'
|
|
and source.T_OrderSampleID = ?
|
|
set
|
|
target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling),
|
|
target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate),
|
|
target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime),
|
|
target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID),
|
|
|
|
target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive),
|
|
target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate),
|
|
target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime),
|
|
target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID),
|
|
|
|
target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification),
|
|
target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate),
|
|
target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime),
|
|
target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID),
|
|
|
|
target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing),
|
|
target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate),
|
|
target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime),
|
|
target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID),
|
|
|
|
target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ),
|
|
target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate),
|
|
target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime),
|
|
target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID),
|
|
|
|
target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling),
|
|
target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate),
|
|
target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime),
|
|
target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID),
|
|
|
|
target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive,
|
|
target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime,
|
|
target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID
|
|
";
|
|
$qry = $this->db->query($sql, [$sourceID]);
|
|
if (!$qry) {
|
|
echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select T_OrderSampleT_OrderHeaderID, T_OrderSampleT_SampleTypeID
|
|
from t_ordersample where T_OrderSampleID=?";
|
|
$qry = $this->db->query($sql, array($sourceID));
|
|
if (!$qry) {
|
|
echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo $this->db->last_query();
|
|
echo "No record";
|
|
exit;
|
|
}
|
|
$headerID = $rows[0]["T_OrderSampleT_OrderHeaderID"];
|
|
$sampleTypeID = $targetID;
|
|
$sql = "
|
|
update t_orderdetailaddon
|
|
join t_orderdetail on T_OrderDetailT_OrderHeaderID = ?
|
|
and T_OrderDetailAddOnT_OrderDetailID = T_OrderDetailID
|
|
and T_OrderDetailAddOnPreAnalytic <> 'Y'
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
and T_TestT_SampleTypeID = ?
|
|
set T_OrderDetailAddOnPreAnalytic = 'Y'
|
|
, T_OrderDetailAddOnPreAnalyticDate=now()";
|
|
$qry = $this->db->query($sql, array($headerID, $sampleTypeID));
|
|
if (!$qry) {
|
|
echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]);
|
|
exit;
|
|
}
|
|
echo 'update OK';
|
|
}
|
|
|
|
|
|
public function confirm_fix_sample($labNo, $sampleTypeID, $sourceID)
|
|
{
|
|
$sql = "select *
|
|
from t_ordersample
|
|
join t_sampletype on T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
join t_orderheader on T_OrderHeaderID = T_OrderSampleT_OrderHeaderID
|
|
where T_OrderSampleIsActive = 'Y'
|
|
and T_OrderHeaderLabNumber=?
|
|
and T_SampleTypeID = ?
|
|
and T_OrderSampleWorklistReceive <> 'Y'
|
|
and T_OrderSampleID <> ?
|
|
";
|
|
$qry = $this->db->query($sql, [$labNo, $sampleTypeID, $sourceID]);
|
|
if (!$qry) {
|
|
echo 'Error ' . $this->db->error()['message'] . ' | ' . $this->db->last_query();
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$target_ids = '0';
|
|
foreach ($rows as $r) {
|
|
$target_ids .= ',' . $r['T_OrderSampleID'];
|
|
}
|
|
$sql = "update t_ordersample target
|
|
join t_ordersample source on
|
|
target.T_OrderSampleID in ($target_ids)
|
|
and target.T_OrderSampleWorklistReceive = 'N'
|
|
and source.T_OrderSampleID = ?
|
|
set
|
|
target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling),
|
|
target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate),
|
|
target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime),
|
|
target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID),
|
|
|
|
target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive),
|
|
target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate),
|
|
target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime),
|
|
target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID),
|
|
|
|
target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification),
|
|
target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate),
|
|
target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime),
|
|
target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID),
|
|
|
|
target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing),
|
|
target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate),
|
|
target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime),
|
|
target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID),
|
|
|
|
target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ),
|
|
target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate),
|
|
target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime),
|
|
target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID),
|
|
|
|
target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling),
|
|
target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate),
|
|
target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime),
|
|
target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID),
|
|
|
|
target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive,
|
|
target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime,
|
|
target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID
|
|
";
|
|
$qry = $this->db->query($sql, [$sourceID]);
|
|
if (!$qry) {
|
|
echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select *
|
|
from t_ordersample
|
|
join t_sampletype on T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
join t_orderheader on T_OrderHeaderID = T_OrderSampleT_OrderHeaderID
|
|
where T_OrderSampleIsActive = 'Y'
|
|
and T_OrderHeaderLabNumber= ?
|
|
and T_SampleTypeID = ?
|
|
";
|
|
$qry = $this->db->query($sql, [$labNo, $sampleTypeID]);
|
|
if (!$qry) {
|
|
echo 'Error ' . $this->db->error()['message'] . ' | ' . $this->db->last_query();
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$target_header_ids = "0";
|
|
// echo "<pre>" . $this->db->last_query() . "</pre>";
|
|
foreach ($rows as $r) {
|
|
$target_header_ids .= ',' . $r['T_OrderSampleT_OrderHeaderID'];
|
|
}
|
|
|
|
$sql = "
|
|
update t_orderdetailaddon
|
|
join t_orderdetail on T_OrderDetailT_OrderHeaderID in ( $target_header_ids )
|
|
and T_OrderDetailAddOnT_OrderDetailID = T_OrderDetailID
|
|
and T_OrderDetailAddOnPreAnalytic <> 'Y'
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
and T_TestT_SampleTypeID = ?
|
|
set T_OrderDetailAddOnPreAnalytic = 'Y'
|
|
, T_OrderDetailAddOnPreAnalyticDate=now()";
|
|
$qry = $this->db->query($sql, array($sampleTypeID));
|
|
// echo "<pre>" . $this->db->last_query() . "</pre>";
|
|
if (!$qry) {
|
|
echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]);
|
|
exit;
|
|
}
|
|
|
|
echo 'update OK';
|
|
}
|
|
|
|
public function fix_sample_one($targetID, $sampleTypeID)
|
|
{
|
|
//get worklist receive terakhir
|
|
//one target
|
|
$sql = "select *
|
|
from t_ordersample
|
|
join t_sampletype on T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
join t_orderheader on T_OrderHeaderID = T_OrderSampleT_OrderHeaderID
|
|
where T_OrderSampleIsActive = 'Y'
|
|
and T_OrderSampleID = ?
|
|
order by T_OrderSampleWorklistReceiveDatetime desc
|
|
limit 0,1";
|
|
|
|
$qry = $this->db->query($sql, [$targetID]);
|
|
if (!$qry) {
|
|
echo 'Error : ' . $this->db->error()['message'] . ' | ' . $this->db->last_query();
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo "Target Sample tidak ketemu : $targetID";
|
|
exit;
|
|
}
|
|
$labNo = $rows[0]["T_OrderHeaderLabNumber"];
|
|
$targetSampleType = $rows[0]["T_SampleTypeName"];
|
|
|
|
$sql = "select *
|
|
from t_ordersample
|
|
join t_sampletype on T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
join t_orderheader on T_OrderHeaderID = T_OrderSampleT_OrderHeaderID
|
|
where T_OrderSampleIsActive = 'Y'
|
|
and T_OrderHeaderLabNumber=?
|
|
and T_SampleTypeID = ?
|
|
and T_OrderSampleWorklistReceive = 'Y'
|
|
order by T_OrderSampleWorklistReceiveDatetime desc
|
|
limit 0,1";
|
|
$qry = $this->db->query($sql, [$labNo, $sampleTypeID]);
|
|
if (!$qry) {
|
|
echo 'Error : ' . $this->db->error()['message'] . ' | ' . $this->db->last_query();
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo "Belum ada worklist receive utk sample type id $sampleTypeID";
|
|
exit;
|
|
}
|
|
$r = $rows[0];
|
|
$sourceID = $r['T_OrderSampleID'];
|
|
echo '<pre>';
|
|
echo "Update Status utk sample {$targetSampleType} - {$labNo}: \n";
|
|
echo "dari : " . $r["T_SampleTypeName"] . "\n";
|
|
echo "Worklist Receive : {$r['T_OrderSampleWorklistReceiveDatetime']}\n";
|
|
echo '</pre>';
|
|
|
|
echo "<button onClick=\"location.href='/one-api/fix/check_result_v2/confirm_fix_sample_one/$targetID/$sourceID'\">Confirm</button>";
|
|
}
|
|
|
|
public function fix_sample($labNo, $sampleTypeID)
|
|
{
|
|
//get worklist receive terakhir
|
|
$sql = "select *
|
|
from t_ordersample
|
|
join t_sampletype on T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
join t_orderheader on T_OrderHeaderID = T_OrderSampleT_OrderHeaderID
|
|
where T_OrderSampleIsActive = 'Y'
|
|
and T_OrderHeaderLabNumber=?
|
|
and T_SampleTypeID = ?
|
|
and T_OrderSampleWorklistReceive = 'Y'
|
|
order by T_OrderSampleWorklistReceiveDatetime desc
|
|
limit 0,1";
|
|
$qry = $this->db->query($sql, [$labNo, $sampleTypeID]);
|
|
if (!$qry) {
|
|
echo 'Error : ' . $this->db->error()['message'] . ' | ' . $this->db->last_query();
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo "Belum ada worklist receive utk sample type id $sampleTypeID";
|
|
exit;
|
|
}
|
|
$r = $rows[0];
|
|
$sourceID = $r['T_OrderSampleID'];
|
|
echo '<pre>';
|
|
echo "Update Status utk sample {$r['T_SampleTypeName']} - {$labNo}: \n";
|
|
echo "Worklist Receive : {$r['T_OrderSampleWorklistReceiveDatetime']}\n";
|
|
echo '</pre>';
|
|
|
|
echo "<button onClick=\"location.href='/one-api/fix/check_result_v2/confirm_fix_sample/$labNo/$sampleTypeID/$sourceID'\">Confirm</button>";
|
|
}
|
|
|
|
public function update_order_sample($targetID, $sourceID)
|
|
{
|
|
$sql = "update t_ordersample target
|
|
join t_ordersample source on
|
|
target.T_OrderSampleID = ?
|
|
and target.T_OrderSampleWorklistReceive = 'N'
|
|
and source.T_OrderSampleID = ?
|
|
set
|
|
target.T_OrderSampleSampling = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSampling, source.T_OrderSampleSampling),
|
|
target.T_OrderSampleSamplingDate = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingDate, source.T_OrderSampleSamplingDate),
|
|
target.T_OrderSampleSamplingTime = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingTime, source.T_OrderSampleSamplingTime),
|
|
target.T_OrderSampleSamplingUserID = if(target.T_OrderSampleSampling='Y',target.T_OrderSampleSamplingUserID, source.T_OrderSampleSamplingUserID),
|
|
|
|
target.T_OrderSampleReceive = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceive, source.T_OrderSampleReceive),
|
|
target.T_OrderSampleReceiveDate = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveDate, source.T_OrderSampleReceiveDate),
|
|
target.T_OrderSampleReceiveTime = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveTime, source.T_OrderSampleReceiveTime),
|
|
target.T_OrderSampleReceiveUserID = if(target.T_OrderSampleReceive='Y',target.T_OrderSampleReceiveUserID, source.T_OrderSampleReceiveUserID),
|
|
|
|
target.T_OrderSampleVerification = if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerification, source.T_OrderSampleVerification),
|
|
target.T_OrderSampleVerificationDate =if(target.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationDate, source.T_OrderSampleVerificationDate),
|
|
target.T_OrderSampleVerificationTime =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationTime, source.T_OrderSampleVerificationTime),
|
|
target.T_OrderSampleVerificationUserID =if(source.T_OrderSampleVerification='Y',target.T_OrderSampleVerificationUserID, source.T_OrderSampleVerificationUserID),
|
|
|
|
target.T_OrderSampleProcessing = if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessing, source.T_OrderSampleProcessing),
|
|
target.T_OrderSampleProcessingDate= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingDate, source.T_OrderSampleProcessingDate),
|
|
target.T_OrderSampleProcessingTime= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingTime, source.T_OrderSampleProcessingTime),
|
|
target.T_OrderSampleProcessingUserID= if(target.T_OrderSampleProcessing='Y',target.T_OrderSampleProcessingUserID, source.T_OrderSampleProcessingUserID),
|
|
|
|
target.T_OrderSampleReceiveHandling =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandling, source.T_OrderSampleReceiveHandling ),
|
|
target.T_OrderSampleReceiveHandlingDate =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingDate, source.T_OrderSampleReceiveHandlingDate),
|
|
target.T_OrderSampleReceiveHandlingTime =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingTime, source.T_OrderSampleReceiveHandlingTime),
|
|
target.T_OrderSampleReceiveHandlingUserID =if(target.T_OrderSampleReceiveHandling='Y',target.T_OrderSampleReceiveHandlingUserID, source.T_OrderSampleReceiveHandlingUserID),
|
|
|
|
target.T_OrderSampleHandling = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandling, source.T_OrderSampleHandling),
|
|
target.T_OrderSampleHandlingDate = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingDate, source.T_OrderSampleHandlingDate),
|
|
target.T_OrderSampleHandlingTime = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingTime, source.T_OrderSampleHandlingTime),
|
|
target.T_OrderSampleHandlingUserID = if(target.T_OrderSampleHandling='Y',target.T_OrderSampleHandlingUserID, source.T_OrderSampleHandlingUserID),
|
|
|
|
target.T_OrderSampleWorklistReceive = source.T_OrderSampleWorklistReceive,
|
|
target.T_OrderSampleWorklistReceiveDatetime = source.T_OrderSampleWorklistReceiveDateTime,
|
|
target.T_OrderSampleWorklistReceiveUserID = source.T_OrderSampleWorklistReceiveUserID
|
|
";
|
|
$qry = $this->db->query($sql, [$targetID, $sourceID]);
|
|
if (!$qry) {
|
|
echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function id($order)
|
|
{
|
|
echo '<pre>';
|
|
$sql = 'select t_orderheader.* from t_orderheader join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
|
|
where T_OrderHeaderLabNumber like ? or T_OrderHeaderAddonLabNumberOrigin like ?';
|
|
$qry = $this->db->query($sql, ['%' . $order . '%', "%{$order}%"]);
|
|
if (!$qry) {
|
|
echo "ERR : \n";
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
foreach ($rows as $r) {
|
|
echo "{$r['T_OrderHeaderID']}\t{$r['T_OrderHeaderDate']}\t{$r['T_OrderHeaderLabNumber']}\n";
|
|
}
|
|
}
|
|
|
|
public function preanalytic($headerID)
|
|
{
|
|
$sql = "select *
|
|
from t_orderdetailaddon
|
|
join t_orderdetail on T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID and T_OrderDetailIsActive = 'Y'
|
|
and T_OrderDetailAddOnIsActive = 'Y' and T_OrderDetailT_OrderHeaderID = ?";
|
|
$qry = $this->db->query($sql, [$headerID]);
|
|
if (!$qry) {
|
|
echo "ERR : \n";
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
echo "<pre>";
|
|
$rows = $qry->result_array();
|
|
echo "T_OrderDetailID\tT_OrderDetailT_TestName\tT_OrderDetailAddOnPreAnalytic\tT_OrderDetailAddOnPreAnalyticDate\n";
|
|
foreach ($rows as $r) {
|
|
echo "{$r['T_OrderDetailID']}\t{$r['T_OrderDetailT_TestName']}\t{$r['T_OrderDetailAddOnPreAnalytic']}\t{$r['T_OrderDetailAddOnPreAnalyticDate']}\n";
|
|
}
|
|
}
|
|
|
|
public function pre_copy_from_to($fromID, $toID)
|
|
{
|
|
$sql = 'update
|
|
t_orderdetailaddon a
|
|
join t_orderdetailaddon b on a.T_OrderDetailAddOnT_OrderDetailID = ?
|
|
and b.T_OrderDetailAddOnT_OrderDetailID = ?
|
|
set b.T_OrderDetailAddOnPreAnalytic = a.T_OrderDetailAddOnPreAnalytic ,
|
|
b.T_OrderDetailAddOnPreAnalyticDate = a.T_OrderDetailAddOnPreAnalyticDate
|
|
';
|
|
$qry = $this->db->query($sql, [$fromID, $toID]);
|
|
echo $this->db->last_query() . "\n";
|
|
if (!$qry) {
|
|
echo "ERR : \n";
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
echo 'Pre Analytic Update';
|
|
}
|
|
|
|
public function cek_kuning($headerID)
|
|
{
|
|
$sql = "select a.T_OrderSampleWorklistReceive , b.T_OrderSampleWorklistReceive bRcv,
|
|
a.T_OrderSampleWorklistReceiveDatetime, b.T_OrderSampleWorklistReceiveDatetime bDate,
|
|
a.T_OrderSampleWorklistReceiveUserID, b.T_OrderSampleWorklistReceiveUserID bUser
|
|
from t_ordersample a
|
|
join t_ordersample b on a.T_OrderSampleT_OrderHeaderID = b.T_OrderSampleT_OrderHeaderID
|
|
and a.T_OrderSampleBarcode like '%SK%' and b.T_OrderSampleBarcode like '%SP%' and b.T_OrderSampleWorklistReceive = 'Y'
|
|
and a.T_OrderSampleIsActive = 'Y' and b.T_OrderSampleIsActive = 'Y'
|
|
and a.T_OrderSampleT_OrderHeaderID = ?";
|
|
$qry = $this->db->query($sql, [$headerID]);
|
|
if (!$qry) {
|
|
echo "ERR : \n";
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
print_r($rows);
|
|
}
|
|
|
|
public function update_kuning($headerID)
|
|
{
|
|
$sql = "update t_ordersample a
|
|
join t_ordersample b on a.T_OrderSampleT_OrderHeaderID = b.T_OrderSampleT_OrderHeaderID
|
|
and a.T_OrderSampleBarcode like '%SK%' and b.T_OrderSampleBarcode like '%SP%' and b.T_OrderSampleWorklistReceive = 'Y'
|
|
and a.T_OrderSampleIsActive = 'Y' and b.T_OrderSampleIsActive = 'Y'
|
|
and a.T_OrderSampleT_OrderHeaderID = ?
|
|
set
|
|
a.T_OrderSampleWorklistReceive = b.T_OrderSampleWorklistReceive ,
|
|
a.T_OrderSampleWorklistReceiveDatetime = b.T_OrderSampleWorklistReceiveDatetime ,
|
|
a.T_OrderSampleWorklistReceiveUserID = b.T_OrderSampleWorklistReceiveUserID
|
|
";
|
|
$qry = $this->db->query($sql, [$headerID]);
|
|
if (!$qry) {
|
|
echo "ERR : \n";
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
echo 'Serum Kuning di update';
|
|
}
|
|
}
|