Initial import
This commit is contained in:
216
application/controllers/tools/Xferbranch_v2-devone.php
Normal file
216
application/controllers/tools/Xferbranch_v2-devone.php
Normal file
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
class Xferbranch_v2 extends CI_Controller
|
||||
{
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->db = $this->load->database("onedev", true);
|
||||
}
|
||||
function index() {
|
||||
echo "Xfer Branch API";
|
||||
}
|
||||
function batch() {
|
||||
$sql = "select T_RefDeliveryOrderID, T_RefDeliveryOrderNumber,
|
||||
M_BranchName, M_BranchIPAddress
|
||||
from t_ref_deliveryorder
|
||||
join m_branch on T_RefDeliveryOrderM_DestinationID = M_BranchID
|
||||
where T_RefDeliveryOrderIsConfirm = 'Y' or T_RefDeliveryOrderIsConfirm = 'P'
|
||||
limit 0,10
|
||||
";
|
||||
$qry = $this->db->query($sql);
|
||||
$tot_upload = 0;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
foreach($rows as $r) {
|
||||
$date = date("Y-m-d H:i:s ");
|
||||
$branch = $r["M_BranchName"];
|
||||
$ip_address = $r["M_BranchIPAddress"];
|
||||
$number = $r["T_RefDeliveryOrderNumber"];
|
||||
|
||||
if ( $this->do($r["T_RefDeliveryOrderID"])) {
|
||||
echo "$date [OK] uploaded {$number} to {$branch} @ $ip_address\n";
|
||||
} else {
|
||||
echo "$date [ERR] uploaded {$number} to {$branch} @ $ip_address\n";
|
||||
}
|
||||
$tot_upload++;
|
||||
}
|
||||
}
|
||||
if ($tot_upload == 0 ) {
|
||||
$date = date("Y-m-d H:i:s ");
|
||||
echo "$date [OK] No upload data\n";
|
||||
}
|
||||
}
|
||||
function do($deliveryID) {
|
||||
$sql = "select distinct
|
||||
T_RefDeliveryOrderID,
|
||||
T_RefDeliveryOrderDate,
|
||||
T_RefDeliveryOrderNumber,
|
||||
T_RefDeliveryOrderDetailID,
|
||||
T_RefDeliveryOrderDetailT_OrderDetailID T_OrderDetailID,
|
||||
ob.M_BranchCode OriginM_BranchCode,
|
||||
db.M_BranchCode DestinationM_BranchCode, db.M_BranchIPAddress DestinationIPAddress,
|
||||
T_OrderHeaderID, T_OrderHeaderLabNumber,
|
||||
T_OrderHeaderM_PatientID,
|
||||
Concat(M_TitleName, ' ',M_PatientName) M_PatientName,
|
||||
if( T_OrderHeaderFoNote <> '' or T_OrderHeaderFoNote is null,
|
||||
concat(T_OrderHeaderFoNote,' (', sfo.M_StaffName , ')' ), '') FoNote,
|
||||
if( T_OrderHeaderVerificationNote <> '' or T_OrderHeaderVerificationNote is null,
|
||||
concat(T_OrderHeaderVerificationNote,' (', sver.M_StaffName , ')' ), '' ) VerificationNote,
|
||||
if( T_OrderHeaderSamplingNote <> '' or T_OrderHeaderSamplingNote is null ,
|
||||
concat(T_OrderHeaderSamplingNote,' (', ssam.M_StaffName , ')' ), '') SamplingNote
|
||||
from
|
||||
t_ref_deliveryorder_detail
|
||||
join t_ref_deliveryorder on T_RefDeliveryOrderDetailT_RefDeliveryOrderID = T_RefDeliveryOrderID
|
||||
and T_RefDeliveryOrderIsConfirm <> 'N'
|
||||
join m_branch ob on T_RefDeliveryOrderM_BranchID = ob.M_BranchID
|
||||
join m_branch db on T_RefDeliveryOrderM_DestinationID = db.M_BranchID
|
||||
join t_orderheader on T_RefDeliveryOrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title on M_PatientM_TitleID = M_TitleID
|
||||
left join m_user ufo on T_OrderHeaderFoNoteM_UserID = ufo.M_UserID
|
||||
left join m_staff sfo on ufo.M_UserM_StaffID = sfo.M_StaffID
|
||||
left join m_user uver on T_OrderHeaderVerificationNoteM_UserID = uver.M_UserID
|
||||
left join m_staff sver on uver.M_UserM_StaffID = sver.M_StaffID
|
||||
left join m_user usam on T_OrderHeaderVerificationNoteM_UserID = usam.M_UserID
|
||||
left join m_staff ssam on usam.M_UserM_StaffID = ssam.M_StaffID
|
||||
where T_RefDeliveryOrderID = ?
|
||||
and T_RefDeliveryOrderDetailIsConfirm = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql, array($deliveryID) );
|
||||
$rows = array();
|
||||
$branch_ip_address = "";
|
||||
if($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return false;
|
||||
}
|
||||
$sqlp = "select * from m_patient where M_PatientID = ?";
|
||||
$sqlpa = "select * from m_patientaddress where M_PatientAddressM_PatientID = ?";
|
||||
$sqlpt = "select * from m_title where M_TitleID = ?";
|
||||
|
||||
$sqlt = "select
|
||||
T_OrderDetailT_TestID T_TestID,
|
||||
T_OrderDetailT_TestName T_TestName,
|
||||
T_OrderDetailT_TestSasCode T_TestSasCode,
|
||||
T_OrderPromiseDateTime,
|
||||
T_RefDeliveryOrderDetailT_BarcodeLabBarcode T_BarcodeLabBarcode,
|
||||
T_OrderDetailID
|
||||
from
|
||||
t_ref_deliveryorder_detail
|
||||
join t_orderdetail on T_RefDeliveryOrderDetailT_OrderDetailID = T_OrderDetailID
|
||||
and T_RefDeliveryOrderDetailT_OrderDetailID = ?
|
||||
and T_RefDeliveryOrderDetailIsActive = 'Y'
|
||||
and T_RefDeliveryOrderDetailIsConfirm = 'Y'
|
||||
left join t_orderpromise on T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
|
||||
";
|
||||
$sqlct = "select
|
||||
T_OrderDetailT_OrderHeaderID T_OrderHeaderID,
|
||||
T_OrderDetailT_TestID T_TestID,
|
||||
T_OrderDetailT_TestName T_TestName,
|
||||
T_OrderPromiseDateTime,
|
||||
T_OrderDetailID
|
||||
from
|
||||
t_ref_deliveryorder_child
|
||||
join t_orderdetail on T_RefDeliveryOrderChildT_OrderDetailID = T_OrderDetailID
|
||||
and T_RefDeliveryOrderChildT_RefDeliveryOrderDetailID= ?
|
||||
left join t_orderpromise on T_OrderDetailT_OrderPromiseID = T_OrderPromiseID";
|
||||
|
||||
$arr_price_test = array();
|
||||
foreach($rows as $idx => $r) {
|
||||
//patient & address
|
||||
$branch_ip_address = $r["DestinationIPAddress"];
|
||||
$patientID = $r["T_OrderHeaderM_PatientID"];
|
||||
$headerID = $r["T_OrderHeaderID"];
|
||||
$detailID= $r["T_OrderDetailID"];
|
||||
$deliveryDetailID = $r["T_RefDeliveryOrderDetailID"];
|
||||
$qryp = $this->db->query($sqlp, array($patientID));
|
||||
$patient = array();
|
||||
if ($qryp) {
|
||||
$rowsp = $qryp->result_array();
|
||||
if( count($rowsp) > 0 ) {
|
||||
$patient = $rowsp[0];
|
||||
$titleID = $patient["M_PatientM_TitleID"];
|
||||
$qrypa = $this->db->query($sqlpa, array($patientID));
|
||||
if ($qrypa) {
|
||||
$patient["address"] = $qrypa->result_array();
|
||||
}
|
||||
$qrypt = $this->db->query($sqlpt, array($titleID));
|
||||
if ($qrypt) {
|
||||
$rowspt = $qrypt->result_array();
|
||||
if (count($rowspt) > 0 ) $patient["title"] = $rowspt[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
$rows[$idx]["patient"] = $patient;
|
||||
// test
|
||||
$qryt = $this->db->query($sqlt,array($detailID));
|
||||
$arr_test = array();
|
||||
if ($qryt) {
|
||||
$rowst = $qryt->result_array();
|
||||
foreach($rowst as $r ) {
|
||||
$sasCode = substr($r["T_TestSasCode"],0,8);
|
||||
if ( ! isset($arr_price_test[$sasCode]) ) {
|
||||
$arr_price_test[$sasCode] = true;
|
||||
$rows[$idx]["test"][] = $r;
|
||||
$arr_test[]=$r["T_TestID"];
|
||||
}
|
||||
}
|
||||
}
|
||||
// $child_test
|
||||
$qryct = $this->db->query($sqlct,array($deliveryDetailID));
|
||||
if ($qryct) {
|
||||
$rowsct = $qryct->result_array();
|
||||
$rows[$idx]["child_test"] = $rowsct;
|
||||
}
|
||||
|
||||
$reqs = array();
|
||||
if (count($arr_test) > 0 ) {
|
||||
$sqlr = "select * from t_orderreq where T_OrderReqT_OrderHeaderID = ?";
|
||||
$qryr = $this->db->query($sqlr, array($headerID));
|
||||
if ($qryr) {
|
||||
$rowsr = $qryr->result_array();
|
||||
foreach($rowsr as $r) {
|
||||
$a_test_r = json_decode($r["T_OrderReqT_TestID"]);
|
||||
$a_x = array_intersect($arr_test,$a_test_r);
|
||||
if( count($a_x) > 0 ) $reqs[] = $r;
|
||||
}
|
||||
}
|
||||
}
|
||||
$rows[$idx]["requirements"] = $reqs;
|
||||
}
|
||||
$o_rows=$rows;
|
||||
$rows = array();
|
||||
foreach($o_rows as $r) {
|
||||
if (isset($r["test"]) ) {
|
||||
$rows[] = $r;
|
||||
}
|
||||
}
|
||||
$param = json_encode($rows);
|
||||
$url = "http://$branch_ip_address/one-api/tools/incomingref_v2/receive";
|
||||
$result = $this->post($url,$param);
|
||||
$result = json_decode($result,true);
|
||||
if ($result["status"] == "OK" ) {
|
||||
$sqlu = "update t_ref_deliveryorder set T_RefDeliveryOrderIsConfirm = 'S'
|
||||
where T_RefDeliveryOrderID = ?";
|
||||
$this->db->query($sqlu, array($deliveryID));
|
||||
return true;
|
||||
} else {
|
||||
print_r($result);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
//echo "RST : $result ";
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user