213 lines
8.7 KiB
PHP
213 lines
8.7 KiB
PHP
<?php
|
|
class Outgoingref_other extends MY_Controller
|
|
{
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->db = $this->load->database("onedev", true);
|
|
}
|
|
function get_origin_detail($type,$xid) {
|
|
if ($type == "mikro") {
|
|
$sql = "select * from other_mikro where Other_MikroID=? ";
|
|
$qry = $this->db->query($sql, array($xid));
|
|
$result = array();
|
|
if ($qry ) {
|
|
$result["header"] = $qry->result_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;
|
|
}
|
|
return array();
|
|
}
|
|
function get_origin($orderHeaderID,$testID) {
|
|
$sql = "select
|
|
incomingRefDetailT_OrderHeaderID T_OrderHeaderID,
|
|
incomingRefDetailT_OrderDetailID T_OrderDetailID,
|
|
M_BranchID, M_BranchCode, M_BranchIPAddress
|
|
from incoming_ref_detail
|
|
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
|
|
join m_branch on M_BranchID = incomingRefM_BranchID
|
|
where incomingRefDetailNewT_OrderHeaderID = ?
|
|
and incomingRefDetailT_TestID = ?";
|
|
$qry = $this->db->query($sql, array($orderHeaderID, $testID));
|
|
if ( ! $qry ) {
|
|
print_r($this->db->error());
|
|
return false;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if ( count($rows) > 0 ) {
|
|
$result = $rows[0];
|
|
return $result;
|
|
}
|
|
$sql = "select
|
|
incomingRefChildT_OrderHeaderID T_OrderHeaderID,
|
|
M_BranchID, M_BranchCode, M_BranchIPAddress
|
|
from incoming_ref_child
|
|
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
|
|
join m_branch on M_BranchID = incomingRefM_BranchID
|
|
where incomingRefChildNewT_OrderHeaderID = ?
|
|
and incomingRefChildT_TestID = ?";
|
|
$qry = $this->db->query($sql, array($orderHeaderID, $testID));
|
|
if ( ! $qry ) {
|
|
print_r($this->db->error());
|
|
return false;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if ( count($rows) > 0 ) {
|
|
$result = $rows[0];
|
|
return $result;
|
|
}
|
|
return false;
|
|
}
|
|
function gen($date) {
|
|
$type = "cytologi";
|
|
$sql = "select
|
|
other_cytologi.*
|
|
from other_cytologi
|
|
join t_orderdetail on Other_CytologiT_OrderDetailID = T_OrderDetailID
|
|
and Other_CytologiIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
and T_OrderDetailVerification = 'Y'
|
|
join t_orderheaderaddon on T_OrderHeaderAddOnT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and T_OrderHeaderAddOnIsActive = 'Y' and T_OrderHeaderAddOnLabNumberOrigin is not null
|
|
join t_orderheader on T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
|
and T_OrderHeaderIsActive='Y' and date(T_OrderHeaderDate) = ?";
|
|
$qry = $this->db->query($sql,array($date)) ;
|
|
if ( ! $qry ) {
|
|
$this->xlog("$type Err : " . print_r($this->db->error(),true));
|
|
}
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0 ) {
|
|
$this->xlog("Proccessing $type");
|
|
print_r($rows);
|
|
}
|
|
}
|
|
$type = "fna";
|
|
$sql = "select
|
|
other_fna.*
|
|
from other_fna
|
|
join t_orderdetail on Other_FnaT_OrderDetailID = T_OrderDetailID
|
|
and Other_FnaIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
and T_OrderDetailVerification = 'Y'
|
|
join t_orderheaderaddon on T_OrderHeaderAddOnT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and T_OrderHeaderAddOnIsActive = 'Y' and T_OrderHeaderAddOnLabNumberOrigin is not null
|
|
join t_orderheader on T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
|
and T_OrderHeaderIsActive='Y' and date(T_OrderHeaderDate) = ?";
|
|
$qry = $this->db->query($sql,array($date)) ;
|
|
if ( ! $qry ) {
|
|
$this->xlog("$type Err : " . print_r($this->db->error(),true));
|
|
}
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0 ) {
|
|
$this->xlog("Proccessing $type");
|
|
print_r($rows);
|
|
}
|
|
}
|
|
$type = "lcprep";
|
|
$sql = "select
|
|
other_lcprep.*
|
|
from other_lcprep
|
|
join t_orderdetail on Other_LcprepT_OrderDetailID = T_OrderDetailID
|
|
and Other_LcprepIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
and T_OrderDetailVerification = 'Y'
|
|
join t_orderheaderaddon on T_OrderHeaderAddOnT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and T_OrderHeaderAddOnIsActive = 'Y' and T_OrderHeaderAddOnLabNumberOrigin is not null
|
|
join t_orderheader on T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
|
and T_OrderHeaderIsActive='Y' and date(T_OrderHeaderDate) = ?";
|
|
$qry = $this->db->query($sql,array($date)) ;
|
|
if ( ! $qry ) {
|
|
$this->xlog("$type Err : " . print_r($this->db->error(),true));
|
|
}
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0 ) {
|
|
$this->xlog("Proccessing $type");
|
|
print_r($rows);
|
|
}
|
|
}
|
|
$type = "mikro";
|
|
$sql = "select T_OrderHeaderID,T_OrderDetailT_TestID,
|
|
other_mikro.*
|
|
from other_mikro
|
|
join t_orderdetail on Other_MikroT_OrderDetailID = T_OrderDetailID
|
|
and Other_MikroIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
and T_OrderDetailVerification = 'Y'
|
|
join t_orderheaderaddon on T_OrderHeaderAddOnT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and T_OrderHeaderAddOnIsActive = 'Y' and T_OrderHeaderAddOnLabNumberOrigin is not null
|
|
join t_orderheader on T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
|
and T_OrderHeaderIsActive='Y' and date(T_OrderHeaderDate) = ?";
|
|
$qry = $this->db->query($sql,array($date)) ;
|
|
if ( ! $qry ) {
|
|
$this->xlog("$type Err : " . print_r($this->db->error(),true));
|
|
}
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0 ) {
|
|
$this->xlog("Proccessing $type");
|
|
foreach($rows as $idx => $r) {
|
|
$orderHeaderID = $r["T_OrderHeaderID"];
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$xid = $r["Other_MikroID"];
|
|
$result = $this->get_origin($orderHeaderID, $testID);
|
|
$rows[$idx] = array_merge($rows[$idx],$result);
|
|
$rows[$idx] = array_merge($rows[$idx],$result);
|
|
$rows[$idx]["other_detail"] = $this->get_origin_detail($type,$xid);
|
|
}
|
|
}
|
|
print_r($rows);
|
|
}
|
|
$type = "papsmear";
|
|
$sql = "select
|
|
other_papsmear.*
|
|
from other_papsmear
|
|
join t_orderdetail on Other_PapsmearT_OrderDetailID = T_OrderDetailID
|
|
and Other_PapsmearIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
and T_OrderDetailVerification = 'Y'
|
|
join t_orderheaderaddon on T_OrderHeaderAddOnT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and T_OrderHeaderAddOnIsActive = 'Y' and T_OrderHeaderAddOnLabNumberOrigin is not null
|
|
join t_orderheader on T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
|
and T_OrderHeaderIsActive='Y' and date(T_OrderHeaderDate) = ?";
|
|
$qry = $this->db->query($sql,array($date)) ;
|
|
if ( ! $qry ) {
|
|
$this->xlog("$type Err : " . print_r($this->db->error(),true));
|
|
}
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0 ) {
|
|
$this->xlog("Proccessing $type");
|
|
print_r($rows);
|
|
}
|
|
}
|
|
}
|
|
function xlog($message) {
|
|
$dt = date("Y-m-d H:i:s");
|
|
echo "$dt $message\n";
|
|
}
|
|
function post($url,$data) {
|
|
$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_VERBOSE, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
'Content-Type: application/json',
|
|
'Content-Length: ' . strlen($data))
|
|
);
|
|
$result = curl_exec($ch);
|
|
if ($result === false ) {
|
|
$msg = json_encode( array("status"=>"ERR", "message" => curl_error($ch)));
|
|
curl_close($ch);
|
|
return $msg;
|
|
}
|
|
$msg = json_decode($result,true);
|
|
curl_close($ch);
|
|
return $msg;
|
|
}
|
|
}
|
|
|