Files
BE_CPONE/application/controllers/tools/monitoring/Specimenlocal.php
2026-04-27 10:26:26 +07:00

85 lines
3.0 KiB
PHP

<?php
class Specimenlocal extends MY_Controller
{
function __construct() {
parent::__construct();
$this->db = $this->load->database("onedev", true);
}
function index() {
$this->cek(true);
}
function clean_up_message($msg) {
$msg = str_replace("-","\-",$msg);
$msg = str_replace("(","\(",$msg);
$msg = str_replace(")","\)",$msg);
$msg = str_replace(".","\.",$msg);
$msg = str_replace("[","\[",$msg);
$msg = str_replace("]","\]",$msg);
$msg = str_replace("|","\|",$msg);
return $msg;
}
function cek($do_send=false,$date = "") {
if ($date == "" ) $date = Date("Y-m-d");
$sql = "select
distinct T_OrderHeaderID, T_OrderHeaderLabNumber, concat(T_TestName) testName
from
t_orderheader
join t_orderdetail on T_OrderHeaderIsActive = 'Y' and date(T_OrderHeaderDate) = ?
and T_OrderDetailIsActive = 'Y' and T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
and T_OrderDetailIsActive = 'Y'
join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsActive = 'Y' and T_TestT_SampleTypeID > 0
join t_specimenlocal on T_TestNat_TestID = T_SpecimenLocalNat_TestID and T_SpecimenLocalIsActive = 'Y'
and T_TestT_SampleTypeID <> T_SpecimenLocalT_SampletypeID
group by T_OrderHeaderLabNumber";
$qry = $this->db->query($sql,array($date));
if ($qry) {
$rows = $qry->result_array();
$msg = "";
foreach($rows as $r) {
$id = $r["T_OrderHeaderID"];
if ( ! $this->is_worklist_receive($id) ) {
$msg .= $r["T_OrderHeaderLabNumber"] . " : " . $r["testName"] . "\n";
}
}
if($msg != "" ) {
$msg = "Order Specimen Local:\n$msg";
if ($do_send === true ) {
$msg = $this->clean_up_message($msg);
$this->sasone($msg);
} else {
echo $msg;
}
}
} else {
print_r($this->db->error());
}
}
function is_worklist_receive($id) {
$sql = "select count(*) total from t_ordersample where T_OrderSampleT_OrderHeaderID = ? and T_OrderSampleIsActive = 'Y'
and T_OrderSampleWorklistReceive = 'Y'";
$qry = $this->db->query($sql,array($id));
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0 ) {
if ( $rows[0]["total"] > 0 ) return true;
}
}
return false;
}
function sasone($msg) {
$url = "http://bandungraya.aplikasi.web.id/one-api/tgram/xone/sasone";
$data = json_encode( array("text" => $msg ));
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
echo $result;
}
}