Batch 6a: application controllers base
This commit is contained in:
402
application/controllers/tools/Outgoingref_lab.php
Normal file
402
application/controllers/tools/Outgoingref_lab.php
Normal file
@@ -0,0 +1,402 @@
|
||||
<?php
|
||||
class OutgoingRef_lab extends MY_Controller
|
||||
{
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->db = $this->load->database("onedev", true);
|
||||
}
|
||||
function get_nonlab($type,$xid) {
|
||||
//mikro
|
||||
if ($type == "mikro") {
|
||||
$sql = "select * from other_mikro where Other_MikroID=? ";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
$result = array() ;
|
||||
if ($qry ) {
|
||||
$result["type"] = "mikro";
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
$result["header"]= $rows[0];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
$sql = "select * from other_mikrodetails where Other_MikroDetailsOther_MikroID=? and
|
||||
Other_MikroDetailsIsActive = 'Y' ";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
if ($qry) {
|
||||
$result["detail"] = $qry->result_array();
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//cytologi
|
||||
if ($type == "cytologi") {
|
||||
$sql = "select * from other_cytologi where Other_CytologiID=? ";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
$result = array() ;
|
||||
if ($qry ) {
|
||||
$result["type"] = "cytologi";
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
$result["header"]= $rows[0];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
$sql = "select * from other_cytologidetails where Other_CytologiDetailsOther_CytologiID=? and
|
||||
Other_CytologiDetailsIsActive = 'Y' ";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
if ($qry) {
|
||||
$result["detail"] = $qry->result_array();
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//fna
|
||||
if ($type == "fna") {
|
||||
$sql = "select * from other_fna where Other_FnaID=? ";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
$result = array() ;
|
||||
if ($qry ) {
|
||||
$result["type"] = "fna";
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
$result["header"]= $rows[0];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
$sql = "select * from other_fnadetails where Other_FnaDetailsOther_FnaID=? and
|
||||
Other_FnaDetailsIsActive = 'Y' ";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
if ($qry) {
|
||||
$result["detail"] = $qry->result_array();
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//papsmear
|
||||
//
|
||||
if ($type == "papsmear") {
|
||||
$sql = "select * from other_papsmear where Other_PapSmearID=? ";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
$result = array() ;
|
||||
if ($qry ) {
|
||||
$result["type"] = "papsmear";
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
$result["header"]= $rows[0];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
$result["detail"] = array();
|
||||
//bahan
|
||||
$sql = "select * from other_papsmearbahan where Other_PapSmearBahanOther_PapSmearID = ?
|
||||
and Other_PapSmearBahanIsActive='Y'";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
if ($qry) {
|
||||
$result["detail"]["bahan"] = $qry->result_array();
|
||||
}
|
||||
//category
|
||||
$sql = "select * from other_papsmearcategory
|
||||
where Other_PapsmearCategoryOther_PapSmearID = ?
|
||||
and Other_PapsmearCategoryIsActive='Y'";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
if ($qry) {
|
||||
$result["detail"]["category"] = $qry->result_array();
|
||||
}
|
||||
// check
|
||||
$sql = "select * from other_papsmearcheck
|
||||
where Other_PapSmearCheckOther_PapSmearID= ?
|
||||
and Other_PapSmearCheckIsActive='Y'";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
if ($qry) {
|
||||
$result["detail"]["check"] = $qry->result_array();
|
||||
}
|
||||
// details
|
||||
$sql = "select * from other_papsmeardetails
|
||||
where Other_PapSmearDetailsOther_PapSmearID= ?
|
||||
and Other_PapSmearDetailsIsActive='Y'";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
if ($qry) {
|
||||
$result["detail"]["details"] = $qry->result_array();
|
||||
}
|
||||
// maturasi
|
||||
$sql = "select * from other_papsmearmaturasi
|
||||
where Other_PapSmearMaturasiOther_PapSmearID = ?
|
||||
and Other_PapSmearMaturasiIsActive='Y'";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
if ($qry) {
|
||||
$result["detail"]["maturasi"] = $qry->result_array();
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//lcprep
|
||||
//
|
||||
if ($type == "lcprep") {
|
||||
$sql = "select * from other_lcprep where Other_LcprepID=? ";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
$result = array() ;
|
||||
if ($qry ) {
|
||||
$result["type"] = "lcprep";
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
$result["header"]= $rows[0];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
$result["detail"] = array();
|
||||
//adekuasi
|
||||
$sql = "select * from other_lcprepadekuasi where Other_LcprepAdekuasiOther_LcprepID = ?
|
||||
and Other_LcprepAdekuasiIsActive='Y'";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
if ($qry) {
|
||||
$result["detail"]["adekuasi"] = $qry->result_array();
|
||||
}
|
||||
//interpretasi
|
||||
$sql = "select * from other_lcprepinterpretasi
|
||||
where Other_PapsmearInterpretasiOther_LcprepID = ?
|
||||
and Other_PapsmearInterpretasiIsActive='Y'";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
if ($qry) {
|
||||
$result["detail"]["interpretasi"] = $qry->result_array();
|
||||
}
|
||||
// details
|
||||
$sql = "select * from other_lcprepdetails
|
||||
where Other_LcprepDetailsOther_LcprepID= ?
|
||||
and Other_LcprepDetailsIsActive='Y'";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
if ($qry) {
|
||||
$result["detail"]["details"] = $qry->result_array();
|
||||
}
|
||||
// kategoriumum
|
||||
$sql = "select * from other_lcprepkategoriumum
|
||||
where Other_LcprepKategoriUmumOther_LcprepID = ?
|
||||
and Other_LcprepKategoriUmumIsActive='Y'";
|
||||
$qry = $this->db->query($sql, array($xid));
|
||||
if ($qry) {
|
||||
$result["detail"]["kategoriumum"] = $qry->result_array();
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
function process_nonlab($incomingRefDetailID) {
|
||||
//mikro
|
||||
$sql = "select ifnull(Other_MikroID,0) mikroID
|
||||
from incoming_ref_detail
|
||||
join t_orderdetail on T_OrderDetailT_OrderHeaderID = incomingRefDetailNewT_OrderHeaderID
|
||||
and T_OrderDetailT_TestID = incomingRefDetailT_TestID and T_OrderDetailIsActive = 'Y'
|
||||
left join other_mikro on T_OrderDetailID = Other_MikroT_OrderDetailID and
|
||||
Other_MikroIsActive = 'Y'
|
||||
where incomingRefDetailID = ? ";
|
||||
$qry = $this->db->query($sql,array($incomingRefDetailID));
|
||||
if ( ! $qry ) {
|
||||
echo "ERR : process_nonlab : $incomingRefDetailID : " . print_r($this->db->error(),true) . "\n";
|
||||
return "";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if ( count($rows) > 0 ) {
|
||||
$mikroID = $rows[0]["mikroID"];
|
||||
$nl = "";
|
||||
if ($mikroID > 0 ) {
|
||||
$nl = $this->get_nonlab("mikro", $mikroID);
|
||||
return $nl;
|
||||
}
|
||||
}
|
||||
|
||||
//papsmear
|
||||
$sql = "select ifnull(Other_PapSmearID,0) papsmearID
|
||||
from incoming_ref_detail
|
||||
join t_orderdetail on T_OrderDetailT_OrderHeaderID = incomingRefDetailNewT_OrderHeaderID
|
||||
and T_OrderDetailT_TestID = incomingRefDetailT_TestID and T_OrderDetailIsActive = 'Y'
|
||||
left join other_papsmear on T_OrderDetailID = Other_PapSmearT_OrderDetailID and
|
||||
Other_PapSmearIsActive = 'Y'
|
||||
where incomingRefDetailID = ? ";
|
||||
$qry = $this->db->query($sql,array($incomingRefDetailID));
|
||||
if ( ! $qry ) {
|
||||
echo "ERR : process_nonlab : $incomingRefDetailID : " . print_r($this->db->error(),true) . "\n";
|
||||
return "";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if ( count($rows) > 0 ) {
|
||||
$papsmearID = $rows[0]["papsmearID"];
|
||||
$nl = "";
|
||||
if ($papsmear> 0 ) {
|
||||
$nl = $this->get_nonlab("papsmear", $papsmearID);
|
||||
return $nl;
|
||||
}
|
||||
}
|
||||
|
||||
//lcprep
|
||||
$sql = "select ifnull(Other_LcprepID,0) lcprepID
|
||||
from incoming_ref_detail
|
||||
join t_orderdetail on T_OrderDetailT_OrderHeaderID = incomingRefDetailNewT_OrderHeaderID
|
||||
and T_OrderDetailT_TestID = incomingRefDetailT_TestID and T_OrderDetailIsActive = 'Y'
|
||||
left join other_lcprep on T_OrderDetailID = Other_LcprepT_OrderDetailID and
|
||||
Other_LcprepIsActive = 'Y'
|
||||
where incomingRefDetailID = ? ";
|
||||
$qry = $this->db->query($sql,array($incomingRefDetailID));
|
||||
if ( ! $qry ) {
|
||||
echo "ERR : process_nonlab : $incomingRefDetailID : " . print_r($this->db->error(),true) . "\n";
|
||||
return "";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if ( count($rows) > 0 ) {
|
||||
$lcprepID = $rows[0]["lcprepID"];
|
||||
$nl = "";
|
||||
if ($lcprepID > 0 ) {
|
||||
$nl = $this->get_nonlab("lcprep", $lcprepID);
|
||||
return $nl;
|
||||
}
|
||||
}
|
||||
|
||||
//fna
|
||||
$sql = "select ifnull(Other_FnaID,0) fnaID
|
||||
from incoming_ref_detail
|
||||
join t_orderdetail on T_OrderDetailT_OrderHeaderID = incomingRefDetailNewT_OrderHeaderID
|
||||
and T_OrderDetailT_TestID = incomingRefDetailT_TestID and T_OrderDetailIsActive = 'Y'
|
||||
left join other_fna on T_OrderDetailID = Other_FnaT_OrderDetailID and
|
||||
Other_FnaIsActive = 'Y'
|
||||
where incomingRefDetailID = ? ";
|
||||
$qry = $this->db->query($sql,array($incomingRefDetailID));
|
||||
if ( ! $qry ) {
|
||||
echo "ERR : process_nonlab : $incomingRefDetailID : " . print_r($this->db->error(),true) . "\n";
|
||||
return "";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if ( count($rows) > 0 ) {
|
||||
$fnaID = $rows[0]["fnaID"];
|
||||
$nl = "";
|
||||
if ($fnaID > 0 ) {
|
||||
$nl = $this->get_nonlab("fna", $fnaID);
|
||||
return $nl;
|
||||
}
|
||||
}
|
||||
//
|
||||
//cytology
|
||||
$sql = "select ifnull(Other_CytologiID,0) cytologiID
|
||||
from incoming_ref_detail
|
||||
join t_orderdetail on T_OrderDetailT_OrderHeaderID = incomingRefDetailNewT_OrderHeaderID
|
||||
and T_OrderDetailT_TestID = incomingRefDetailT_TestID and T_OrderDetailIsActive = 'Y'
|
||||
left join other_cytologi on T_OrderDetailID = Other_CytologiT_OrderDetailID and
|
||||
Other_CytologiIsActive = 'Y'
|
||||
where incomingRefDetailID = ? ";
|
||||
$qry = $this->db->query($sql,array($incomingRefDetailID));
|
||||
if ( ! $qry ) {
|
||||
echo "ERR : process_nonlab : $incomingRefDetailID : " . print_r($this->db->error(),true) . "\n";
|
||||
return "";
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if ( count($rows) > 0 ) {
|
||||
$cytologiID = $rows[0]["cytologiID"];
|
||||
$nl = "";
|
||||
if ($cytologiID > 0 ) {
|
||||
$nl = $this->get_nonlab("cytologi", $cytologiID);
|
||||
return $nl;
|
||||
}
|
||||
}
|
||||
}
|
||||
function cek() {
|
||||
$sql = "select tx_branch_status.*, M_BranchName
|
||||
from tx_branch_status
|
||||
join m_branch on TxBranchStatusM_BranchID = M_BranchID
|
||||
where TxBranchStatusIsSent = 'N' and TxBranchStatusRetry < 20
|
||||
|
||||
order by TxBranchStatusRetry, TxBranchStatusID
|
||||
limit 0,30";
|
||||
$qry = $this->db->query($sql);
|
||||
$sql_update = "update tx_branch_status set TxBranchStatusIsSent=?,
|
||||
TxBranchStatusRetry = TxBranchStatusRetry + 1
|
||||
where TxBranchStatusID = ?";
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
print_r($rows);
|
||||
}
|
||||
}
|
||||
function process() {
|
||||
$sql = "select tx_branch_status.*, M_BranchName
|
||||
from tx_branch_status
|
||||
join m_branch on TxBranchStatusM_BranchID = M_BranchID
|
||||
where TxBranchStatusIsSent = 'N' and TxBranchStatusRetry < 20
|
||||
|
||||
order by TxBranchStatusRetry, TxBranchStatusID
|
||||
limit 0,30";
|
||||
// $sql = "select tx_branch_status.*, M_BranchName
|
||||
// from tx_branch_status
|
||||
// join m_branch on TxBranchStatusM_BranchID = M_BranchID
|
||||
// where TxBranchStatusID = 234623
|
||||
// order by TxBranchStatusRetry, TxBranchStatusID
|
||||
// limit 0,30";
|
||||
$qry = $this->db->query($sql);
|
||||
$sql_update = "update tx_branch_status set TxBranchStatusIsSent=?,
|
||||
TxBranchStatusRetry = TxBranchStatusRetry + 1
|
||||
where TxBranchStatusID = ?";
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
foreach($rows as $r) {
|
||||
$param = $r["TxBranchStatusJson"];
|
||||
$stage = $r["TxBranchStatusStage"];
|
||||
$ipAddress = $r["TxBranchStatusM_BranchIP"];
|
||||
$branchName = $r["M_BranchName"];
|
||||
$txID = $r["TxBranchStatusID"];
|
||||
if ($stage == "VALIDATION") {
|
||||
//cek nonlab
|
||||
$j_param = json_decode($param,true);
|
||||
foreach($j_param as $idx => $j ) {
|
||||
if (isset($j["incomingRefDetailID"])) {
|
||||
$nonlab_result = $this->process_nonlab( $j["incomingRefDetailID"] );
|
||||
if ($nonlab_result != array() ) {
|
||||
$j_param[$idx]["nonlab_result"] = $nonlab_result;
|
||||
$param = json_encode($j_param);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$url = "http://$ipAddress/one-api-lab/tools/xstatusbranch_lab/update";
|
||||
$rst = $this->post($url,$param);
|
||||
|
||||
if ($rst["status"] == "OK" ) {
|
||||
$this->xlog("Update status $stage to $branchName @ $ipAddress [OK]");
|
||||
$this->db->query($sql_update, array('Y',$txID));
|
||||
} else {
|
||||
$err_msg = print_r($rst,true);
|
||||
$this->xlog("Update status $stage to $branchName @ $ipAddress [ERR] : $err_msg");
|
||||
$this->db->query($sql_update, array('N',$txID));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->xlog("Err: " . print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
|
||||
function xlog($message) {
|
||||
$dt = date("Y-m-d H:i:s");
|
||||
echo "$dt $message\n";
|
||||
}
|
||||
function post($url,$data) {
|
||||
$zdata = gzdeflate($data,9);
|
||||
$ch = curl_init($url);
|
||||
$this->xlog("Post to : " . $url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $zdata);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($zdata))
|
||||
);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
if ($result === false ) {
|
||||
return array("status" => "ERR" ,
|
||||
"message" => curl_error($ch)
|
||||
);
|
||||
}
|
||||
$rst = json_decode($result,true);
|
||||
return $rst;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user