diff --git a/application/controllers/mockup/process/refreceivesample-v11/Sample.php b/application/controllers/mockup/process/refreceivesample-v11/Sample.php index 5be2432f..948ede86 100644 --- a/application/controllers/mockup/process/refreceivesample-v11/Sample.php +++ b/application/controllers/mockup/process/refreceivesample-v11/Sample.php @@ -26,16 +26,16 @@ class Sample extends MY_Controller $barcode = $prm['barcode']; $sql = $this->db_onedev->query("SELECT COUNT(*) as semua FROM incoming_ref_detail - WHERE incomingRefDetailIncomingRefID = '{$id}'")->row(); + WHERE incomingRefDetailIncomingRefID = '{$id}'")->row(); $semua = $sql->semua; $sql = $this->db_onedev->query("SELECT COUNT(*) as terima FROM incoming_ref_detail - WHERE incomingRefDetailIncomingRefID = '{$id}' AND incomingRefDetailStatus <> 'N'")->row(); + WHERE incomingRefDetailIncomingRefID = '{$id}' AND incomingRefDetailStatus <> 'N'")->row(); $terima = $sql->terima; $sql = $this->db_onedev->query("SELECT incomingRefIsConfirm as konfirmasi FROM incoming_ref - WHERE incomingRefID = '{$id}'")->row(); - $konfirmasi = $sql->konfirmasi; + WHERE incomingRefID = '{$id}'")->row(); + $konfirmasi = $sql->konfirmasi; $sql = "SELECT *, IF(incomingRefDetailStatus = 'N' AND nosample = '{$barcode}', 'R', incomingRefDetailStatus) as ischoose FROM (SELECT incoming_ref_detail.*, incomingRefDetailStatus as ischoose, @@ -51,18 +51,18 @@ class Sample extends MY_Controller if ($query) { $rows = $query->result_array(); } else { - $this->sys_error_db( $this->db_onedev->last_query() ); + $this->sys_error_db($this->db_onedev->last_query()); exit; } - $result = array ("total" => count($rows), "records" => $rows, "semua" => $semua, "terima" => $terima, "konfirmasi" => $konfirmasi); + $result = array("total" => count($rows), "records" => $rows, "semua" => $semua, "terima" => $terima, "konfirmasi" => $konfirmasi); $this->sys_ok($result); - - } catch(Exception $exc) { + } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } - function tolak_all(){ + function tolak_all() + { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; @@ -72,69 +72,70 @@ class Sample extends MY_Controller $incomingRefID = $prm["id"]; $sql = $this->db_onedev->query("SELECT incomingRefIsConfirm as konfirmasi FROM incoming_ref - WHERE incomingRefID = '{$incomingRefID}'")->row(); - $konfirmasi = $sql->konfirmasi; - if($konfirmasi == 'N'){ - $sql = "select M_BranchID, M_BranchIPAddress + WHERE incomingRefID = '{$incomingRefID}'")->row(); + $konfirmasi = $sql->konfirmasi; + if ($konfirmasi == 'N') { + $sql = "select M_BranchID, M_BranchIPAddress from m_branch join incoming_ref on M_BranchID = incomingRefM_BranchID where incomingRefID = ?"; - $qry = $this->db_onedev->query($sql, array($incomingRefID)); - $branchID = 0; - if ($qry) { - $rows = $qry->result_array(); - if(count($rows)>0) { - $branchID = $rows[0]["M_BranchID"]; - $branchIPAddress = $rows[0]["M_BranchIPAddress"]; + $qry = $this->db_onedev->query($sql, array($incomingRefID)); + $branchID = 0; + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) { + $branchID = $rows[0]["M_BranchID"]; + $branchIPAddress = $rows[0]["M_BranchIPAddress"]; + } + } + if ($branchID == 0) { + $this->sys_errror("Invalid Branch ID"); + //file_put_contents("/xtmp/log-confirmdeliveryorder.log","Invalid Branch ID\n", FILE_APPEND); + exit; } - } - if ($branchID == 0 ) { - $this->sys_errror("Invalid Branch ID"); - //file_put_contents("/xtmp/log-confirmdeliveryorder.log","Invalid Branch ID\n", FILE_APPEND); - exit; - } - $sql = "update incoming_ref_detail + $sql = "update incoming_ref_detail set incomingRefDetailStatus = 'N' - where incomingRefDetailIncomingRefID = $incomingRefID"; - $qry = $this->db_onedev->query($sql); - $sql = "select + where incomingRefDetailIncomingRefID = $incomingRefID"; + $qry = $this->db_onedev->query($sql); + $sql = "select incomingRefT_RefDeliveryOrderID, incomingRefDetailT_OrderDetailID, incomingRefDetailStatus from incoming_ref_detail join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID and incomingRefID = ?"; - $qry = $this->db->query($sql, array($incomingRefID)); + $qry = $this->db->query($sql, array($incomingRefID)); - if ($qry) { - $rows = $qry->result_array(); - $param = json_encode($rows); - $note = $rst["message"]; - //insert to - $sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID, + if ($qry) { + $rows = $qry->result_array(); + $param = json_encode($rows); + $note = $rst["message"]; + //insert to + $sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID, TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote ) values ('CONFIRM',?,?,?,?)"; - $qry = $this->db_onedev->query($sql, array($branchID, $branchIPAddress, $param, $note)); - } - - $this->clean_mysqli_connection($this->db_onedev->conn_id); - $sql = "update incoming_ref set incomingRefIsConfirm = 'Y' + $qry = $this->db_onedev->query($sql, array($branchID, $branchIPAddress, $param, $note)); + } + + $this->clean_mysqli_connection($this->db_onedev->conn_id); + $sql = "update incoming_ref set incomingRefIsConfirm = 'Y' where incomingRefID = ?"; - $qry = $this->db_onedev->query($sql, array($incomingRefID)); - $this->sys_ok($rst["message"]); - exit; -}else{ - $result = array( - "total" => 1 , - "records" => array('status'=>'OK') - ); + $qry = $this->db_onedev->query($sql, array($incomingRefID)); + $this->sys_ok($rst["message"]); + exit; + } else { + $result = array( + "total" => 1, + "records" => array('status' => 'OK') + ); $this->sys_ok($result); exit; -} + } } - function confirmdeliveryorder(){ + function confirmdeliveryorder() + { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; @@ -144,116 +145,116 @@ class Sample extends MY_Controller $incomingRefID = $prm["id"]; $sql = $this->db_onedev->query("SELECT incomingRefIsConfirm as konfirmasi FROM incoming_ref - WHERE incomingRefID = '{$incomingRefID}'")->row(); - $konfirmasi = $sql->konfirmasi; - if($konfirmasi == 'N'){ - $sql = "select M_BranchID, M_BranchIPAddress + WHERE incomingRefID = '{$incomingRefID}'")->row(); + $konfirmasi = $sql->konfirmasi; + if ($konfirmasi == 'N') { + $sql = "select M_BranchID, M_BranchIPAddress from m_branch join incoming_ref on M_BranchID = incomingRefM_BranchID where incomingRefID = ?"; - $qry = $this->db_onedev->query($sql, array($incomingRefID)); - $branchID = 0; - if ($qry) { - $rows = $qry->result_array(); - if(count($rows)>0) { - $branchID = $rows[0]["M_BranchID"]; - $branchIPAddress = $rows[0]["M_BranchIPAddress"]; + $qry = $this->db_onedev->query($sql, array($incomingRefID)); + $branchID = 0; + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0) { + $branchID = $rows[0]["M_BranchID"]; + $branchIPAddress = $rows[0]["M_BranchIPAddress"]; + } } - } - if ($branchID == 0 ) { - $this->sys_errror("Invalid Branch ID"); - //file_put_contents("/xtmp/log-confirmdeliveryorder.log","Invalid Branch ID\n", FILE_APPEND); - exit; - } - $a_accept = array(); - $a_reject = array(); - $s_ids = "0"; - $s_nosamples = "''"; - foreach($prm["dodetail"] as $idx => $detail) { - $orderHeaderID = $detail["incomingRefDetailT_OrderHeaderID"]; - if (! isset($a_accept[$orderHeaderID]) ) { - $a_accept[$orderHeaderID] = array(); - $a_reject[$orderHeaderID] = array(); + if ($branchID == 0) { + $this->sys_errror("Invalid Branch ID"); + //file_put_contents("/xtmp/log-confirmdeliveryorder.log","Invalid Branch ID\n", FILE_APPEND); + exit; } - if ($detail["ischoose"] == "N" ) { - $a_reject[$orderHeaderID][] = $detail["incomingRefDetailID"]; - } else { - $a_accept[$orderHeaderID][] = $detail["incomingRefDetailID"]; - $s_ids .= "," . $detail["incomingRefDetailID"]; - $s_nosamples .= "," . "'".$detail["nosample"]."'"; + $a_accept = array(); + $a_reject = array(); + $s_ids = "0"; + $s_nosamples = "''"; + foreach ($prm["dodetail"] as $idx => $detail) { + $orderHeaderID = $detail["incomingRefDetailT_OrderHeaderID"]; + if (! isset($a_accept[$orderHeaderID])) { + $a_accept[$orderHeaderID] = array(); + $a_reject[$orderHeaderID] = array(); + } + if ($detail["ischoose"] == "N") { + $a_reject[$orderHeaderID][] = $detail["incomingRefDetailID"]; + } else { + $a_accept[$orderHeaderID][] = $detail["incomingRefDetailID"]; + $s_ids .= "," . $detail["incomingRefDetailID"]; + $s_nosamples .= "," . "'" . $detail["nosample"] . "'"; + } } - } - $hid = ""; - $sql = $this->db_onedev->query("SELECT GROUP_CONCAT(DISTINCT incomingRefDetailT_OrderHeaderID SEPARATOR ',') as hid FROM incoming_ref_detail - WHERE incomingRefDetailID in ( $s_ids )")->row(); - $hid = $sql->hid; - //all px yg di terima - $sql="select distinct incomingRefDetailID from incoming_ref_detail + $hid = ""; + $sql = $this->db_onedev->query("SELECT GROUP_CONCAT(DISTINCT incomingRefDetailT_OrderHeaderID SEPARATOR ',') as hid FROM incoming_ref_detail + WHERE incomingRefDetailID in ( $s_ids )")->row(); + $hid = $sql->hid; + //all px yg di terima + $sql = "select distinct incomingRefDetailID from incoming_ref_detail where incomingRefDetailIncomingRefID = ? AND incomingRefDetailT_OrderHeaderID in ($hid) AND LEFT(incomingRefDetailT_BarcodeLabBarcode,12) in ($s_nosamples)"; - $qry = $this->db_onedev->query($sql, array($incomingRefID)); - //echo $this->db_onedev->last_query(); - $s_ids = "0"; - if ($qry) { - $rows = $qry->result_array(); - foreach($rows as $r) { - $s_ids .= "," . $r["incomingRefDetailID"]; + $qry = $this->db_onedev->query($sql, array($incomingRefID)); + //echo $this->db_onedev->last_query(); + $s_ids = "0"; + if ($qry) { + $rows = $qry->result_array(); + foreach ($rows as $r) { + $s_ids .= "," . $r["incomingRefDetailID"]; + } } - } - // CEK KELENGKAPAN SETTINGAN - $sql = $this->db_onedev->query("SELECT incomingRefM_BranchID as branchid FROM incoming_ref - WHERE incomingRefID = '{$incomingRefID}'")->row(); - $branchid = $sql->branchid; + // CEK KELENGKAPAN SETTINGAN + $sql = $this->db_onedev->query("SELECT incomingRefM_BranchID as branchid FROM incoming_ref + WHERE incomingRefID = '{$incomingRefID}'")->row(); + $branchid = $sql->branchid; - $sql = $this->db_onedev->query("SELECT M_BranchM_CompanyID as companyid FROM m_branch - WHERE M_BranchID = '{$branchid}'")->row(); - $companyid = $sql->companyid; - - $sql = $this->db_onedev->query("SELECT M_BranchM_MouID as mouid FROM m_branch - WHERE M_BranchID = '{$branchid}'")->row(); - $mouid = $sql->mouid; - - $sql = $this->db_onedev->query("SELECT M_BranchM_DoctorID as doctorid FROM m_branch - WHERE M_BranchID = '{$branchid}'")->row(); - $doctorid = $sql->doctorid; - - $sql = $this->db_onedev->query("SELECT M_BranchM_DoctorAddressID as doctoraddressid FROM m_branch - WHERE M_BranchID = '{$branchid}'")->row(); - $doctoraddressid = $sql->doctoraddressid; + $sql = $this->db_onedev->query("SELECT M_BranchM_CompanyID as companyid FROM m_branch + WHERE M_BranchID = '{$branchid}'")->row(); + $companyid = $sql->companyid; - if($companyid > 0 && $mouid > 0 && $doctorid > 0 && $doctoraddressid > 0){ - $noprice = "0"; - $sql = $this->db_onedev->query("SELECT count(IFNULL(Ss_PriceMouID,0)) as noprice, + $sql = $this->db_onedev->query("SELECT M_BranchM_MouID as mouid FROM m_branch + WHERE M_BranchID = '{$branchid}'")->row(); + $mouid = $sql->mouid; + + $sql = $this->db_onedev->query("SELECT M_BranchM_DoctorID as doctorid FROM m_branch + WHERE M_BranchID = '{$branchid}'")->row(); + $doctorid = $sql->doctorid; + + $sql = $this->db_onedev->query("SELECT M_BranchM_DoctorAddressID as doctoraddressid FROM m_branch + WHERE M_BranchID = '{$branchid}'")->row(); + $doctoraddressid = $sql->doctoraddressid; + + if ($companyid > 0 && $mouid > 0 && $doctorid > 0 && $doctoraddressid > 0) { + $noprice = "0"; + $sql = $this->db_onedev->query("SELECT count(IFNULL(Ss_PriceMouID,0)) as noprice, GROUP_CONCAT(DISTINCT CONCAT(a.T_TestSasCode,' | ', a.T_TestName) SEPARATOR '\n') as tes FROM incoming_ref_detail JOIN t_test a ON a.T_TestID = incomingRefDetailT_TestID AND a.T_TestIsPrice = 'Y' LEFT JOIN ss_price_mou ON Ss_PriceMouM_MouID = '{$mouid}' AND T_PriceT_TestID = a.T_TestID WHERE - incomingRefDetailID in ($s_ids) AND Ss_PriceMouID IS NULL")->row(); - $noprice = $sql->noprice; - $tes = $sql->tes; + incomingRefDetailID in ($s_ids) AND Ss_PriceMouID IS NULL")->row(); + $noprice = $sql->noprice; + $tes = $sql->tes; - if($noprice != "0"){ - $this->sys_error("Cek kelengkapan harga pemeriksaan : " .$tes); - exit; - }else{ - if($s_ids != "0" ) { + if ($noprice != "0") { + $this->sys_error("Cek kelengkapan harga pemeriksaan : " . $tes); + exit; + } else { + if ($s_ids != "0") { $sql = "update incoming_ref_detail set incomingRefDetailStatus = 'Y' - where incomingRefDetailID in ( $s_ids ) "; - $qry = $this->db_onedev->query($sql); - //generate order - $rst = $this->ref_order($incomingRefID); - if ($rst["status"] != "OK" ) { - $this->sys_error($rst["message"]); - //file_put_contents("/xtmp/log-confirmdeliveryorder.log","Ref Order:" . $rst["message"] . "\n", FILE_APPEND); - exit; - } - $sql = "select + where incomingRefDetailID in ( $s_ids ) "; + $qry = $this->db_onedev->query($sql); + //generate order + $rst = $this->ref_order($incomingRefID); + if ($rst["status"] != "OK") { + $this->sys_error($rst["message"]); + //file_put_contents("/xtmp/log-confirmdeliveryorder.log","Ref Order:" . $rst["message"] . "\n", FILE_APPEND); + exit; + } + $sql = "select incomingRefT_RefDeliveryOrderID, incomingRefDetailT_OrderDetailID, incomingRefDetailStatus, @@ -266,81 +267,80 @@ class Sample extends MY_Controller and incomingRefID = ? left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID"; - $qry = $this->db->query($sql, array($incomingRefID)); + $qry = $this->db->query($sql, array($incomingRefID)); - if ($qry) { - $rows = $qry->result_array(); - $param = json_encode($rows); - $note = $rst["message"]; - //insert to - $sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID, + if ($qry) { + $rows = $qry->result_array(); + $param = json_encode($rows); + $note = $rst["message"]; + //insert to + $sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID, TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote ) values ('CONFIRM',?,?,?,?)"; - $qry = $this->db_onedev->query($sql, array($branchID, $branchIPAddress, $param, $note)); - } - - $this->clean_mysqli_connection($this->db_onedev->conn_id); - $sql = "update incoming_ref set incomingRefIsConfirm = 'Y' + $qry = $this->db_onedev->query($sql, array($branchID, $branchIPAddress, $param, $note)); + } + + $this->clean_mysqli_connection($this->db_onedev->conn_id); + $sql = "update incoming_ref set incomingRefIsConfirm = 'Y' where incomingRefID = ?"; - $qry = $this->db_onedev->query($sql, array($incomingRefID)); - $this->sys_ok($rst["message"]); - exit; + $qry = $this->db_onedev->query($sql, array($incomingRefID)); + $this->sys_ok($rst["message"]); + exit; + } } - } - - - }else{ + } else { $this->sys_error("Belum Ada Settingan Agremeent / Dokternya"); - exit; - } - - -}else{ - $result = array( - "total" => 1 , - "records" => array('status'=>'OK') - ); + exit; + } + } else { + $result = array( + "total" => 1, + "records" => array('status' => 'OK') + ); $this->sys_ok($result); exit; -} + } } - function ref_order($incomingRefID) { + function ref_order($incomingRefID) + { //$adminUserID = 3; - $adminUserID = $this->sys_user["M_UserID"] ; + $adminUserID = $this->sys_user["M_UserID"]; $sql = "select * from incoming_ref where incomingRefID = ?"; - $qry = $this->db_onedev->query($sql, array($incomingRefID) ); + $qry = $this->db_onedev->query($sql, array($incomingRefID)); $rows = array(); $branchID = 0; if ($qry) { $rows = $qry->result_array(); - if ( count($rows) > 0 ) $branchID = $rows[0]["incomingRefM_BranchID"]; + if (count($rows) > 0) $branchID = $rows[0]["incomingRefM_BranchID"]; } - if ($branchID == 0 ) { + if ($branchID == 0) { return array( "status" => "ERR", - "message" => "Branch belum di set"); + "message" => "Branch belum di set" + ); } $companyID = 0; - if ($branchID > 0 ) { + if ($branchID > 0) { $sql = "select * from m_branch where M_BranchID = ?"; - $qry = $this->db_onedev->query($sql, array($branchID) ); + $qry = $this->db_onedev->query($sql, array($branchID)); if ($qry) { $rows = $qry->result_array(); $companyID = $rows[0]["M_BranchM_CompanyID"]; $mouID = $rows[0]["M_BranchM_MouID"]; $doctorID = $rows[0]["M_BranchM_DoctorID"]; $doctorAddressID = $rows[0]["M_BranchM_DoctorAddressID"]; - $branchKelurahanID= $rows[0]["M_BranchM_KelurahanID"]; + $branchKelurahanID = $rows[0]["M_BranchM_KelurahanID"]; $branchAddresss = $rows[0]["M_BranchAddress"]; } } - if ($companyID == 0 ) { + if ($companyID == 0) { return array( "status" => "ERR", - "message" => "Branch / Company/MOU belum di set"); + "message" => "Branch / Company/MOU belum di set" + ); } //create order yg di confirm saja $sql = "select * @@ -348,7 +348,7 @@ class Sample extends MY_Controller where incomingRefDetailIncomingRefID = ? and incomingRefDetailStatus = 'Y' order by incomingRefDetailT_OrderHeaderID"; - $qry = $this->db_onedev->query($sql, array($incomingRefID) ); + $qry = $this->db_onedev->query($sql, array($incomingRefID)); $orders = array(); $ax_test = array(); $a_promise = array(); @@ -356,39 +356,39 @@ class Sample extends MY_Controller if ($qry) { $rows = $qry->result_array(); $prev_oh_id = 0; - foreach($rows as $r) { + foreach ($rows as $r) { $oh_id = $r["incomingRefDetailT_OrderHeaderID"]; - $incomingRefDetailFoNote = str_replace("'","", $r["incomingRefDetailFoNote"]); - $incomingRefDetailVefificationNote = str_replace("'","",$r["incomingRefDetailVefificationNote"]); - if ( ! isset($orders[$oh_id]) ) { - $orders[$oh_id]["patient"] = json_decode($r["incomingRefDetailPatient"],true); + $incomingRefDetailFoNote = str_replace("'", "", $r["incomingRefDetailFoNote"]); + $incomingRefDetailVefificationNote = str_replace("'", "", $r["incomingRefDetailVefificationNote"]); + if (! isset($orders[$oh_id])) { + $orders[$oh_id]["patient"] = json_decode($r["incomingRefDetailPatient"], true); $orders[$oh_id]["foNote"] = $incomingRefDetailFoNote; $orders[$oh_id]["verificationNote"] = $incomingRefDetailVefificationNote; $orders[$oh_id]["samplingNote"] = $r["incomingRefDetailSamplingNote"]; $orders[$oh_id]["LabNumber"] = $r["incomingRefDetailT_OrderHeaderLabNumber"]; $orders[$oh_id]["test"] = array(); - } - $orders[$oh_id]["test"][] = array ( + } + $orders[$oh_id]["test"][] = array( "T_TestID" => $r["incomingRefDetailT_TestID"], "Promise" => $r["incomingRefDetailT_OrderPromiseDateTime"], "T_OrderDetailID" => $r["incomingRefDetailT_OrderDetailID"], "T_BarcodeLabBarcode" => $r["incomingRefDetailT_BarcodeLabBarcode"], - "Requirements" => json_decode($r["incomingRefDetailRequirements"],true) + "Requirements" => json_decode($r["incomingRefDetailRequirements"], true) ); $ax_test[] = $r["incomingRefDetailT_TestID"]; $a_promise[$oh_id][$r["incomingRefDetailT_TestID"]] = $r["incomingRefDetailT_OrderPromiseDateTime"]; $a_barcode[$oh_id][$r["incomingRefDetailT_TestID"]] = $r["incomingRefDetailT_BarcodeLabBarcode"]; } } - $s_test = "0," . join(",",$ax_test); + $s_test = "0," . join(",", $ax_test); $sql = "select * from ss_price_mou where Ss_PriceMouM_MouID = ? and T_TestID in ( $s_test ) "; - $qry = $this->db_onedev->query($sql, array($mouID) ); + $qry = $this->db_onedev->query($sql, array($mouID)); //test primer sama dengan T_TestID $a_test = array(); - if ($qry ) { + if ($qry) { $rows = $qry->result_array(); - foreach($rows as $r) { + foreach ($rows as $r) { $testID = $r["T_TestID"]; $a_test[$testID] = array( "T_PriceAmount" => $r["T_PriceAmount"], @@ -396,7 +396,7 @@ class Sample extends MY_Controller "T_PriceDisc" => $r["T_PriceDisc"] ); } - } + } //test sekunder dari Nat_Test $a_test_v2 = array(); $sql = "select ss_price_mou.* @@ -408,11 +408,11 @@ class Sample extends MY_Controller join t_test p on s.T_TestNat_TestID = p.T_TestNat_TestID and p.T_TestID in ( $s_test ) ) "; - $qry = $this->db_onedev->query($sql, array($mouID) ); + $qry = $this->db_onedev->query($sql, array($mouID)); //test primer sama dengan T_TestID - if ($qry ) { + if ($qry) { $rows = $qry->result_array(); - foreach($rows as $r) { + foreach ($rows as $r) { $testID = $r["T_TestID"]; $a_test_v2[$testID] = array( "T_PriceAmount" => $r["T_PriceAmount"], @@ -420,37 +420,37 @@ class Sample extends MY_Controller "T_PriceDisc" => $r["T_PriceDisc"] ); } - } + } $message = ""; - foreach($orders as $oh_id => $o){ + foreach ($orders as $oh_id => $o) { $noreg = $o["patient"]["M_PatientNoReg"]; - $lab_number= $o["LabNumber"]; + $lab_number = $o["LabNumber"]; //if noreg not exists create patient $sql = "select count(*) tot from m_patient where M_PatientNoReg=? and M_PatientIsActive = 'Y'"; $qry = $this->db_onedev->query($sql, array($noreg)); $patientID = 0; - if($qry) { + if ($qry) { $rows = $qry->result_array(); - if ($rows[0]["tot"] == 0 ) { + if ($rows[0]["tot"] == 0) { $patientID = $this->create_patient($orders[$oh_id]["patient"], $adminUserID); } else { - $patientID = $orders[$oh_id]["patient"]["M_PatientID"]; - } + $patientID = $orders[$oh_id]["patient"]["M_PatientID"]; + } } - if ($patientID == 0 ) { - if ($message != "" ) $message .= ","; + if ($patientID == 0) { + if ($message != "") $message .= ","; $message .= "[ $lab_number, gagal buat pasien $noreg ]"; continue; - } + } $sql = "select fn_global_age_count(M_PatientDOB,now()) age from m_patient where M_PatientID = ? "; - $qry = $this->db_onedev->query($sql, array($patientID) ); + $qry = $this->db_onedev->query($sql, array($patientID)); $patientAge = ""; if ($qry) { $rows = $qry->result_array(); - if (count($rows) > 0 ) { + if (count($rows) > 0) { $patientAge = $rows[0]["age"]; } } @@ -464,49 +464,65 @@ class Sample extends MY_Controller 'company_id' => $companyID, 'mou_id' => $mouID, 'lang_id' => '1', - 'lang_si' => 'N', + 'lang_si' => 'N', 'doctor_note' => '', 'fo_note' => $orders[$oh_id]["foNote"], 'queue' => '', - 'received_sample' => 'Y', + 'received_sample' => array('flag' => 'Y', 'time' => date("Y-m-d H:i:s")), 'lang_id_2' => '2', 'lang_si_2' => 'N', + 'pj_doctor_id' => $doctorID, + 'diagnose' => '', + 'is_cito' => 'N', + 'cito_id' => '0', + 'alias_doctor_name' => '', + 'alias_doctor_address' => '', + 'patient_note' => '', + 'reference' => array(), + 'fpp_id' => '0', + 'mcu_pre_id' => -1, ); $xdel = array( array( 'address_id' => $branchID, 'delivery_id' => '10', + 'delivery_code' => '', 'delivery_type_id' => '2', 'senderdoctorid' => $doctorID, 'senderaddressid' => $doctorAddressID, 'note' => $branchAddresss, - 'kelurahan' => $branchKelurahanID - )); + 'noteplus' => '', + 'kelurahan' => $branchKelurahanID, + 'regional_cd' => $branchKelurahanID + ) + ); $xdet = array(); $reqs = array(); - foreach($orders[$oh_id]["test"] as $t ) { - if ( isset($a_test[$t["T_TestID"]]) ) { - $v=$a_test[$t["T_TestID"]]; + foreach ($orders[$oh_id]["test"] as $t) { + if (isset($a_test[$t["T_TestID"]])) { + $v = $a_test[$t["T_TestID"]]; $xdet[] = array( 't_id' => $t['T_TestID'], 't_cito' => 'N', 't_price' => $v['T_PriceAmount'], 't_disc' => $v['T_PriceDisc'], 't_discrp' => $v['T_PriceDiscRp'], + 't_disc_rp' => $v['T_PriceDiscRp'], 't_req' => 'Y', 't_reqnote' => '', 't_ispacket' => "N", 't_packettype' => "PX", 't_packetid' => '0' ); - } elseif ( isset($a_test_v2["T_TestID"] ) ) { - $v=$a_test_v2[$t["T_TestID"]]; + } elseif (isset($a_test_v2["T_TestID"])) { + $v = $a_test_v2[$t["T_TestID"]]; $xdet[] = array( 't_id' => $t['T_TestID'], 't_cito' => 'N', 't_price' => $v['T_PriceAmount'], 't_disc' => $v['T_PriceDisc'], 't_discrp' => $v['T_PriceDiscRp'], + 't_disc_rp' => $v['T_PriceDiscRp'], 't_req' => 'Y', 't_reqnote' => '', 't_ispacket' => "N", @@ -520,6 +536,7 @@ class Sample extends MY_Controller 't_price' => 0, 't_disc' => 0, 't_discrp' => 0, + 't_disc_rp' => 0, 't_req' => 'Y', 't_reqnote' => '', 't_ispacket' => "N", @@ -527,7 +544,7 @@ class Sample extends MY_Controller 't_packetid' => '0' ); } - if (count($t["Requirements"]) > 0 ) { + if (count($t["Requirements"]) > 0) { $reqs = array_merge($reqs, $t["Requirements"]); } } @@ -536,31 +553,18 @@ class Sample extends MY_Controller 'status' => 'Y', 'reqs' => '[]' ); - $header_json = addslashes(str_replace('\n', '\\\n', json_encode($xheader))); - $delivery_json = addslashes(str_replace('\n', '\\\n', json_encode($xdel))); - $detail_json = addslashes(str_replace('\n', '\\\n', json_encode($xdet))); - $req_json = json_encode($xreq); - $sql = "CALL `sp_fo_register_save_v5`( - 0, - '{$header_json}', - '{$delivery_json}', - '{$detail_json}', - '{$req_json}', - '{$adminUserID}' - );"; - $r = $this->db_onedev->query($sql)->row(); - $this->clean_mysqli_connection($this->db_onedev->conn_id); - if ($r->status != "OK" ) { - if ($message != "" ) $message .= ","; - $xmsg = print_r($r, true); - $message .= "[ $lab_number, gagal sp_fo_register_save_v5 : $xmsg ]"; + $r = $this->save_ref_order_by_registration($xheader, $xdel, $xdet, $xreq, $adminUserID); + if ($r["status"] != "OK") { + if ($message != "") $message .= ","; + $xmsg = isset($r["message"]) ? $r["message"] : print_r($r, true); + $message .= "[ $lab_number, gagal order/save : $xmsg ]"; $g_date = date("Y-m-d H:i:s"); - file_put_contents("/xtmp/gagal-order.log","$g_date $message\n", FILE_APPEND); + file_put_contents("/xtmp/gagal-order.log", "$g_date $message\n", FILE_APPEND); continue; } - $data = json_decode($r->data,true); + $data = $r["data"]; $new_oh_id = $data["id"]; - $new_lab_number= $data["number"]; + $new_lab_number = $data["number"]; //echo "2. $new_oh_id : $lab_number => $new_lab_number \n"; //update incoming_ref @@ -568,22 +572,22 @@ class Sample extends MY_Controller incomingRefDetailNewM_PatientID = ? where incomingRefDetailIncomingRefID = ? and incomingRefDetailT_OrderHeaderID=?"; - $this->db_onedev->query($sql,array($new_oh_id, $patientID, $incomingRefID, $oh_id)); + $this->db_onedev->query($sql, array($new_oh_id, $patientID, $incomingRefID, $oh_id)); $sql = "update t_orderheaderaddon set T_OrderHeaderAddOnLabNumberOrigin=? where T_OrderHeaderAddOnT_OrderHeaderID = ?"; - $this->db_onedev->query($sql,array($lab_number,$new_oh_id)); - + $this->db_onedev->query($sql, array($lab_number, $new_oh_id)); + //update promise $a_promise_test = array(); - $a_promise_date= array(); - $a_promise_id= array(); - foreach($a_promise[$oh_id] as $testID => $promise ) { - if(!isset($a_promise_date[$promise])) { + $a_promise_date = array(); + $a_promise_id = array(); + foreach ($a_promise[$oh_id] as $testID => $promise) { + if (!isset($a_promise_date[$promise])) { $sql = "insert into t_orderpromise(T_OrderPromiseT_OrderHeaderID, T_OrderPromiseDateTime) values(?,?)"; - $this->db_onedev->query($sql, array($new_oh_id,$promise)); + $this->db_onedev->query($sql, array($new_oh_id, $promise)); $promise_id = $this->db_onedev->insert_id(); $a_promise_test[$testID] = $promise_id; $a_promise_date["$promise"] = $promise_id; @@ -591,7 +595,7 @@ class Sample extends MY_Controller $a_promise_test[$testID] = $a_promise_date["$promise"]; } } - if ( count($a_promise_test) > 0 ) { + if (count($a_promise_test) > 0) { $s_test = join(",", array_keys($a_promise_test)); $sql = "update t_orderpromise,t_orderdetail set T_OrderPromiseIsActive = 'N' @@ -600,20 +604,25 @@ class Sample extends MY_Controller and T_OrderDetailT_TestID in ($s_test) "; $this->db_onedev->query($sql, array($new_oh_id)); } - foreach($a_promise_test as $testID => $promiseID ) { + foreach ($a_promise_test as $testID => $promiseID) { $sql = "update t_orderdetail set T_OrderDetailT_OrderPromiseID= ? where T_OrderDetailT_OrderHeaderID = ? and T_OrderDetailT_TestID = ? "; - $this->db_onedev->query($sql, array($promiseID , $new_oh_id, $testID) ); + $this->db_onedev->query($sql, array($promiseID, $new_oh_id, $testID)); } //insert requirements - foreach($reqs as $r) { - $sql ="insert into t_orderreq(T_OrderReqT_OrderHeaderID,T_OrderReqNat_PositionID, + foreach ($reqs as $r) { + $sql = "insert into t_orderreq(T_OrderReqT_OrderHeaderID,T_OrderReqNat_PositionID, T_OrderReqStatus, T_OrderReqT_TestID, T_OrderReqs) values(?,?, ?,?,?)"; - $this->db_onedev->query($sql, array($new_oh_id, $r["T_OrderReqNat_PositionID"], - $r["T_OrderReqStatus"], $r["T_OrderReqT_TestID"], $r["T_OrderReqs"] )); + $this->db_onedev->query($sql, array( + $new_oh_id, + $r["T_OrderReqNat_PositionID"], + $r["T_OrderReqStatus"], + $r["T_OrderReqT_TestID"], + $r["T_OrderReqs"] + )); } //update note $sql = "update t_orderheader @@ -621,20 +630,26 @@ class Sample extends MY_Controller T_OrderHeaderSamplingNote = ?, T_OrderHeaderSamplingNoteM_UserID = ?, T_OrderHeaderVerificationNote = ?, T_OrderHeaderVerificationNoteM_UserID = ? where T_OrderHeaderID = ? "; - $this->db_onedev->query($sql, array( $o["foNote"],$adminUserID, - $o["samplingNote"], $adminUserID, $o["verificationNote"], $adminUserID, - $new_oh_id)); - $result = $this->fo_verify($new_oh_id,$adminUserID); + $this->db_onedev->query($sql, array( + $o["foNote"], + $adminUserID, + $o["samplingNote"], + $adminUserID, + $o["verificationNote"], + $adminUserID, + $new_oh_id + )); + $result = $this->fo_verify($new_oh_id, $adminUserID); //update t_barcodelab - foreach($a_barcode[$oh_id] as $testID => $barcode) { + foreach ($a_barcode[$oh_id] as $testID => $barcode) { $sql = "update t_barcodelab,t_test set T_BarcodeLabBarcodeOrigin =? where T_BarcodeLabT_OrderHeaderID = ? and T_TestID = ? and T_TestIsActive = 'Y' and T_BarcodeLabT_SampleTypeID = T_TestT_SampleTypeID"; $this->db_onedev->query($sql, array($barcode, $new_oh_id, $testID)); - } + } // update nilai normal $sql = "select distinct T_OrderDetailT_OrderHeaderID id, @@ -647,12 +662,12 @@ class Sample extends MY_Controller $qry = $this->db_onedev->query($sql, array($new_oh_id)); if ($qry) { $rows = $qry->result_array(); - foreach($rows as $r) { + foreach ($rows as $r) { $sql = "call sp_sampling_set_normal(?,?)"; - $this->db_onedev->query($sql,array($r["id"],$r["sid"])); + $this->db_onedev->query($sql, array($r["id"], $r["sid"])); } } - if ($message != "" ) $message .= ","; + if ($message != "") $message .= ","; $message .= "[ $lab_number -> $new_lab_number Fo Verify : $result ]"; } try { @@ -663,8 +678,8 @@ class Sample extends MY_Controller and incomingRefChildT_OrderHeaderID = incomingRefDetailT_OrderHeaderID and incomingRefChildNewT_OrderHeaderID is null and incomingRefChildIncomingRefID = ? "; - $this->db_onedev->query($sql,array($incomingRefID)); - } catch(Exception $e) { + $this->db_onedev->query($sql, array($incomingRefID)); + } catch (Exception $e) { } try { //update barcode @@ -678,13 +693,67 @@ class Sample extends MY_Controller and incomingRefDetailIncomingRefID = ? and T_TestT_SampleTypeID = 0 and T_BarcodeLabBarcodeOrigin is null"; - $this->db_onedev->query($sql,array($incomingRefID)); - } catch(Exception $e) { + $this->db_onedev->query($sql, array($incomingRefID)); + } catch (Exception $e) { } - return array( "status" => "OK", - "message" => $message ); + return array( + "status" => "OK", + "message" => $message + ); } - function create_patient($p, $userID) { + function save_ref_order_by_registration($header, $delivery, $detail, $req, $userID) + { + if (!class_exists('CI_Jwt', false)) { + if (!class_exists('JWT', false)) { + require_once APPPATH . 'libraries/Jwt.php'; + } + if (class_exists('JWT', false)) { + class_alias('JWT', 'CI_Jwt'); + } + } + + require_once APPPATH . 'controllers/mockup/fo/ibl_registration/Order.php'; + $order_ctrl = new Order(); + $order_ctrl->sys_input = array( + '_internal' => true, + 'mcuid' => null, + 'preid' => null, + 'order_id' => -1, + 'header' => $header, + 'delivery' => $delivery, + 'delivery_note' => array(), + 'detail' => $detail, + 'req' => $req, + 'preregister_promise' => '', + 'tests' => array(), + ); + $order_ctrl->sys_user = array( + 'M_UserID' => $userID, + 'M_UserUsername' => isset($this->sys_user["M_UserUsername"]) ? $this->sys_user["M_UserUsername"] : 'ref_receive_sample' + ); + $order_ctrl->isLogin = true; + + $result = $order_ctrl->save(); + if (!is_array($result)) { + return array("status" => "ERR", "message" => "Order->save() tidak mengembalikan array"); + } + if (isset($result["status"]) && $result["status"] == "ERR") { + return array("status" => "ERR", "message" => isset($result["message"]) ? $result["message"] : "Order/save error"); + } + if (isset($result["status"]) && $result["status"] == "OK" && !empty($result["data"]["data"]["id"]) && !empty($result["data"]["data"]["number"])) { + return array( + "status" => "OK", + "data" => array( + "id" => $result["data"]["data"]["id"], + "number" => $result["data"]["data"]["number"] + ) + ); + } + + return array("status" => "ERR", "message" => "Order/save response tanpa data.id/number"); + } + function create_patient($p, $userID) + { $sql = "insert into m_patient"; //check title $sql = "select M_TitleID from m_title where M_TitleName = ? and M_TitleIsActive = 'Y'"; @@ -692,7 +761,7 @@ class Sample extends MY_Controller $titleID = 0; if ($qry) { $rows = $qry->result_array(); - if (count($rows) > 0 ) $titleID = $rows[0]["M_TitleID"]; + if (count($rows) > 0) $titleID = $rows[0]["M_TitleID"]; } if ($titleID == 0) { $sql = "insert into m_title(M_TitleName, M_TitleM_SexID) values ( ? , ? )"; @@ -701,17 +770,17 @@ class Sample extends MY_Controller $titleID = $this->db_onedev->insert_id(); } } - if ($titleID == 0 ) { + if ($titleID == 0) { return 0; } $p_name = stripslashes($p['M_PatientName']); $p_name2 = stripslashes($p_name); $patient_name = str_replace("'", "\\'", $p_name2); $pnote = str_replace("'", "\\'", $p['M_PatientNote']); - $pdob = date('Y-m-d',strtotime($p['M_PatientDOB'])); + $pdob = date('Y-m-d', strtotime($p['M_PatientDOB'])); $pob = str_replace("'", "", $p['M_PatientPOB']); - $hp = str_replace("'", "",$p['M_PatientHP']); - $query ="INSERT INTO m_patient ( + $hp = str_replace("'", "", $p['M_PatientHP']); + $query = "INSERT INTO m_patient ( M_PatientM_TitleID, M_PatientName, M_PatientDOB, @@ -743,23 +812,31 @@ class Sample extends MY_Controller )"; $qry = $this->db_onedev->query($query); $patientID = 0; - if ($qry ) { + if ($qry) { $patientID = $this->db_onedev->insert_id(); } - // echo $this->db_onedev->last_query(); + // echo $this->db_onedev->last_query(); // $sql = "insert into m_patientaddress(M_PatientAddressM_PatientID, M_PatientAddressNote, M_PatientAddressDescription,M_PatientAddressLocation,M_PatientAddressM_KelurahanID, M_PatientAddressOldCityID, M_PatientAddressPostCodeID, M_PatientAddressFax, M_PatientAddressEmail, M_PatientAddressPhone) values(?,?, ?,?,?, ?,?,?, ?,?) "; - foreach($p["address"] as $adr) { - $address_description = str_replace("'", "\\'", $adr['M_PatientAddressDescription']); - $prm = array($patientID , $adr["M_PatientAddressNote"], - $address_description,$adr["M_PatientAddressLocation"],$adr["M_PatientAddressM_KelurahanID"], - $adr["M_PatientAddressOldCityID"], $adr["M_PatientAddressPostCodeID"], $adr["M_PatientAddressFax"], - $adr["M_PatientAddressEmail"], $adr["M_PatientAddressPhone"] ); - $this->db_onedev->query($sql,$prm); + foreach ($p["address"] as $adr) { + $address_description = str_replace("'", "\\'", $adr['M_PatientAddressDescription']); + $prm = array( + $patientID, + $adr["M_PatientAddressNote"], + $address_description, + $adr["M_PatientAddressLocation"], + $adr["M_PatientAddressM_KelurahanID"], + $adr["M_PatientAddressOldCityID"], + $adr["M_PatientAddressPostCodeID"], + $adr["M_PatientAddressFax"], + $adr["M_PatientAddressEmail"], + $adr["M_PatientAddressPhone"] + ); + $this->db_onedev->query($sql, $prm); } return $patientID; @@ -768,8 +845,9 @@ class Sample extends MY_Controller - function fo_verify($orderID,$userID) { - $sql="INSERT INTO fo_verificationsvalue ( + function fo_verify($orderID, $userID) + { + $sql = "INSERT INTO fo_verificationsvalue ( Fo_VerificationsValueT_OrderHeaderID, Fo_VerificationsValueFo_VerificationsLabelID, Fo_VerificationsValueCheck, @@ -801,16 +879,18 @@ class Sample extends MY_Controller Fo_StatusUpdated) values( now(), ?, ?, ?, now(),now())"; - $query = $this->db_onedev->query($sql, + $query = $this->db_onedev->query( + $sql, array( $orderID, - $fostatusid, $userID + $fostatusid, + $userID ) ); if (!$query) { return "Error Fo Status"; - } + } $sql = "SELECT * FROM fo_verificationsvalue WHERE Fo_VerificationsValueT_OrderHeaderID = {$orderID}"; @@ -826,7 +906,8 @@ class Sample extends MY_Controller Log_FoJson, Log_FoUserID) values( now(), ?, ?, ?)"; - $query = $this->db_onedev->query($sql, + $query = $this->db_onedev->query( + $sql, array( $fologcode, $json_dt_log, @@ -859,13 +940,10 @@ class Sample extends MY_Controller where T_OrderSampleT_OrderHeaderID = ?"; - $qry = $this->db_onedev->query($sql, array($orderID) ); + $qry = $this->db_onedev->query($sql, array($orderID)); if (!$qry) { return "Error T_OrderSample : " . $this->db_onedev->last_query(); } return "OK"; } - - - } diff --git a/application/controllers/tools/Outgoingref_v4.php b/application/controllers/tools/Outgoingref_v4.php index 3a2dcf9c..ead46a38 100644 --- a/application/controllers/tools/Outgoingref_v4.php +++ b/application/controllers/tools/Outgoingref_v4.php @@ -1,21 +1,23 @@ db = $this->load->database("onedev", true); } - function get_nonlab($type,$xid) { + 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 = array(); + if ($qry) { $result["type"] = "mikro"; - $rows = $qry->result_array(); - if (count($rows) > 0 ) { - $result["header"]= $rows[0]; + $rows = $qry->result_array(); + if (count($rows) > 0) { + $result["header"] = $rows[0]; } else { return array(); } @@ -23,8 +25,8 @@ class OutgoingRef_v4 extends MY_Controller Other_MikroDetailsIsActive = 'Y' "; $qry = $this->db->query($sql, array($xid)); if ($qry) { - $result["detail"] = $qry->result_array(); - } + $result["detail"] = $qry->result_array(); + } } return $result; } @@ -33,12 +35,12 @@ class OutgoingRef_v4 extends MY_Controller if ($type == "cytologi") { $sql = "select * from other_cytologi where Other_CytologiID=? "; $qry = $this->db->query($sql, array($xid)); - $result = array() ; - if ($qry ) { + $result = array(); + if ($qry) { $result["type"] = "cytologi"; - $rows = $qry->result_array(); - if (count($rows) > 0 ) { - $result["header"]= $rows[0]; + $rows = $qry->result_array(); + if (count($rows) > 0) { + $result["header"] = $rows[0]; } else { return array(); } @@ -46,8 +48,8 @@ class OutgoingRef_v4 extends MY_Controller Other_CytologiDetailsIsActive = 'Y' "; $qry = $this->db->query($sql, array($xid)); if ($qry) { - $result["detail"] = $qry->result_array(); - } + $result["detail"] = $qry->result_array(); + } } return $result; } @@ -56,12 +58,12 @@ class OutgoingRef_v4 extends MY_Controller if ($type == "fna") { $sql = "select * from other_fna where Other_FnaID=? "; $qry = $this->db->query($sql, array($xid)); - $result = array() ; - if ($qry ) { + $result = array(); + if ($qry) { $result["type"] = "fna"; - $rows = $qry->result_array(); - if (count($rows) > 0 ) { - $result["header"]= $rows[0]; + $rows = $qry->result_array(); + if (count($rows) > 0) { + $result["header"] = $rows[0]; } else { return array(); } @@ -69,8 +71,8 @@ class OutgoingRef_v4 extends MY_Controller Other_FnaDetailsIsActive = 'Y' "; $qry = $this->db->query($sql, array($xid)); if ($qry) { - $result["detail"] = $qry->result_array(); - } + $result["detail"] = $qry->result_array(); + } } return $result; } @@ -80,12 +82,12 @@ class OutgoingRef_v4 extends MY_Controller if ($type == "papsmear") { $sql = "select * from other_papsmear where Other_PapSmearID=? "; $qry = $this->db->query($sql, array($xid)); - $result = array() ; - if ($qry ) { + $result = array(); + if ($qry) { $result["type"] = "papsmear"; - $rows = $qry->result_array(); - if (count($rows) > 0 ) { - $result["header"]= $rows[0]; + $rows = $qry->result_array(); + if (count($rows) > 0) { + $result["header"] = $rows[0]; } else { return array(); } @@ -95,40 +97,40 @@ class OutgoingRef_v4 extends MY_Controller and Other_PapSmearBahanIsActive='Y'"; $qry = $this->db->query($sql, array($xid)); if ($qry) { - $result["detail"]["bahan"] = $qry->result_array(); - } + $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(); + $result["detail"]["category"] = $qry->result_array(); } - // check + // 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(); - } + $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(); - } + $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(); - } + $result["detail"]["maturasi"] = $qry->result_array(); + } } return $result; } @@ -138,12 +140,12 @@ class OutgoingRef_v4 extends MY_Controller if ($type == "lcprep") { $sql = "select * from other_lcprep where Other_LcprepID=? "; $qry = $this->db->query($sql, array($xid)); - $result = array() ; - if ($qry ) { + $result = array(); + if ($qry) { $result["type"] = "lcprep"; - $rows = $qry->result_array(); - if (count($rows) > 0 ) { - $result["header"]= $rows[0]; + $rows = $qry->result_array(); + if (count($rows) > 0) { + $result["header"] = $rows[0]; } else { return array(); } @@ -153,15 +155,15 @@ class OutgoingRef_v4 extends MY_Controller and Other_LcprepAdekuasiIsActive='Y'"; $qry = $this->db->query($sql, array($xid)); if ($qry) { - $result["detail"]["adekuasi"] = $qry->result_array(); - } + $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(); + $result["detail"]["interpretasi"] = $qry->result_array(); } // details $sql = "select * from other_lcprepdetails @@ -169,23 +171,24 @@ class OutgoingRef_v4 extends MY_Controller and Other_LcprepDetailsIsActive='Y'"; $qry = $this->db->query($sql, array($xid)); if ($qry) { - $result["detail"]["details"] = $qry->result_array(); - } + $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(); - } + $result["detail"]["kategoriumum"] = $qry->result_array(); + } } return $result; } return array(); } - function process_nonlab($incomingRefDetailID) { + function process_nonlab($incomingRefDetailID) + { //mikro $sql = "select ifnull(Other_MikroID,0) mikroID from incoming_ref_detail @@ -194,19 +197,19 @@ class OutgoingRef_v4 extends MY_Controller 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"; + $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 ) { + if (count($rows) > 0) { $mikroID = $rows[0]["mikroID"]; $nl = ""; - if ($mikroID > 0 ) { + if ($mikroID > 0) { $nl = $this->get_nonlab("mikro", $mikroID); return $nl; - } + } } //papsmear @@ -217,19 +220,19 @@ class OutgoingRef_v4 extends MY_Controller 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"; + $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 ) { + if (count($rows) > 0) { $papsmearID = $rows[0]["papsmearID"]; $nl = ""; - if ($papsmear> 0 ) { + if ($papsmear > 0) { $nl = $this->get_nonlab("papsmear", $papsmearID); return $nl; - } + } } //lcprep @@ -240,19 +243,19 @@ class OutgoingRef_v4 extends MY_Controller 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"; + $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 ) { + if (count($rows) > 0) { $lcprepID = $rows[0]["lcprepID"]; $nl = ""; - if ($lcprepID > 0 ) { + if ($lcprepID > 0) { $nl = $this->get_nonlab("lcprep", $lcprepID); return $nl; - } + } } //fna @@ -263,19 +266,19 @@ class OutgoingRef_v4 extends MY_Controller 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"; + $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 ) { + if (count($rows) > 0) { $fnaID = $rows[0]["fnaID"]; $nl = ""; - if ($fnaID > 0 ) { + if ($fnaID > 0) { $nl = $this->get_nonlab("fna", $fnaID); return $nl; - } + } } // //cytology @@ -286,22 +289,23 @@ class OutgoingRef_v4 extends MY_Controller 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"; + $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 ) { + if (count($rows) > 0) { $cytologiID = $rows[0]["cytologiID"]; $nl = ""; - if ($cytologiID > 0 ) { + if ($cytologiID > 0) { $nl = $this->get_nonlab("cytologi", $cytologiID); return $nl; - } + } } } - function cek() { + function cek() + { $sql = "select tx_branch_status.*, M_BranchName from tx_branch_status join m_branch on TxBranchStatusM_BranchID = M_BranchID @@ -318,7 +322,8 @@ class OutgoingRef_v4 extends MY_Controller print_r($rows); } } - function process() { + function process() + { $sql = "select tx_branch_status.*, M_BranchName from tx_branch_status join m_branch on TxBranchStatusM_BranchID = M_BranchID @@ -338,7 +343,7 @@ class OutgoingRef_v4 extends MY_Controller where TxBranchStatusID = ?"; if ($qry) { $rows = $qry->result_array(); - foreach($rows as $r) { + foreach ($rows as $r) { $param = $r["TxBranchStatusJson"]; $stage = $r["TxBranchStatusStage"]; $ipAddress = $r["TxBranchStatusM_BranchIP"]; @@ -346,57 +351,69 @@ class OutgoingRef_v4 extends MY_Controller $txID = $r["TxBranchStatusID"]; if ($stage == "VALIDATION") { //cek nonlab - $j_param = json_decode($param,true); - foreach($j_param as $idx => $j ) { + $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() ) { + $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/tools/xstatusbranch_v4/update"; - $rst = $this->post($url,$param); - - if ($rst["status"] == "OK" ) { + $url = "http://$ipAddress/one-api-lab/tools/xstatusbranch_v4/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)); + $this->db->query($sql_update, array('Y', $txID)); } else { - $err_msg = print_r($rst,true); + $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)); - } + $this->db->query($sql_update, array('N', $txID)); + } } } else { - $this->xlog("Err: " . print_r($this->db->error(),true)); + $this->xlog("Err: " . print_r($this->db->error(), true)); } } - function xlog($message) { + 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)) - ); + 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_CONNECTTIMEOUT, 10); + curl_setopt($ch, CURLOPT_TIMEOUT, 60); + curl_setopt( + $ch, + CURLOPT_HTTPHEADER, + array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($zdata) + ) + ); $result = curl_exec($ch); + $curl_error = curl_error($ch); + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); - if ($result === false ) { - return array("status" => "ERR" , - "message" => curl_error($ch) + if ($result === false) { + return array( + "status" => "ERR", + "message" => $curl_error, + "http_code" => $http_code ); } - $rst = json_decode($result,true); - return $rst; - } -} \ No newline at end of file + $rst = json_decode($result, true); + return $rst; + } +} diff --git a/application/controllers/tools/Xstatusbranch_v3.php b/application/controllers/tools/Xstatusbranch_v3.php new file mode 100644 index 00000000..90f90c61 --- /dev/null +++ b/application/controllers/tools/Xstatusbranch_v3.php @@ -0,0 +1,639 @@ +db = $this->load->database("onedev", true); + } + function index() { + echo "API"; + } + //mikro + function update_mikro($detailID, $header, $detail ) { + $sql = "select * from t_orderdetail where T_OrderDetailID = ? "; + $qry = $this->db->query($sql, array($detailID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Mikro cek Validation " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + if ($rows[0]["T_OrderDetailValidation"] == "Y" ) return; + $sql = "select Other_MikroID from other_mikro where Other_MikroT_OrderDetailID = ? and Other_MikroIsActive = 'Y'"; + $qry = $this->db->query($sql, array($detailID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Mikro cek Existence " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $rows = $qry->result_array(); + $mikroID = 0; + if (count($rows) > 0 ) $mikroID = $rows[0]["Other_MikroID"]; + if ( $mikroID > 0 ) { + $sql = "update other_mikro set Other_MikroIsActive = 'N' where Other_MikroID = ? "; + $qry = $this->db->query($sql, array($mikroID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Mikro set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $sql = "update other_mikrodetails set Other_MikroDetailsIsActive = 'N' where Other_MikroDetailsOther_MikroID= ? "; + $qry = $this->db->query($sql, array($mikroID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Mikro Details set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + unset($header["Other_MikroID"]); + $header["Other_MikroCreated"] = date("Y-m-d h:i:s"); + $header["Other_MikroLastUpdated"] =date("Y-m-d h:i:s"); + $header["Other_MikroUserID"] = 3; + $header["Other_MikroIsActive"] = "Y"; + $header["Other_MikroT_OrderDetailID"] = $detailID; + $qry = $this->db->insert("other_mikro",$header); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Mikro Add Header" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $mikroID = $this->db->insert_id(); + if ($mikroID == 0 ) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Mikro ID Header" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + foreach($detail as $idx => $d ) { + $detail[$idx]["Other_MikroDetailsOther_MikroID"] = $mikroID ; + $detail[$idx]["Other_MikroDetailsUserID"] = 3; + $detail[$idx]["Other_MikroDetailsIsActive"] = "Y"; + unset($detail[$idx]["Other_MikroDetailsID"]); + unset($detail[$idx]["Other_MikroDetailsCreated"]); + unset($detail[$idx]["Other_MikroDetailsLastUpdated"]); + } + $qry = $this->db->insert_batch("other_mikrodetails",$detail); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Mikro Add Detail" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + + //cytologi + function update_cytologi($detailID, $header, $detail ) { + $sql = "select * from t_orderdetail where T_OrderDetailID = ? "; + $qry = $this->db->query($sql, array($detailID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Cytologi cek Validation " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + if ($rows[0]["T_OrderDetailValidation"] == "Y" ) return; + $sql = "select Other_CytologiID from other_cytologi where Other_CytologiT_OrderDetailID = ? and Other_CytologiIsActive = 'Y'"; + $qry = $this->db->query($sql, array($detailID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Cytologi cek Existence " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $rows = $qry->result_array(); + $cytologiID = 0; + if (count($rows) > 0 ) $cytologiID = $rows[0]["Other_CytologiID"]; + if ( $cytologiID > 0 ) { + $sql = "update other_cytologi set Other_CytologiIsActive = 'N' where Other_CytologiID = ? "; + $qry = $this->db->query($sql, array($cytologiID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Cytologi set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $sql = "update other_cytologidetails set Other_CytologiDetailsIsActive = 'N' where Other_CytologiDetailsOther_CytologiID= ? "; + $qry = $this->db->query($sql, array($cytologiID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Cytologi Details set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + unset($header["Other_CytologiID"]); + $header["Other_CytologiCreated"] = date("Y-m-d h:i:s"); + $header["Other_CytologiLastUpdated"] =date("Y-m-d h:i:s"); + $header["Other_CytologiUserID"] = 3; + $header["Other_CytologiIsActive"] = "Y"; + $header["Other_CytologiT_OrderDetailID"] = $detailID; + $qry = $this->db->insert("other_cytologi",$header); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Cytologi Add Header" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $cytologiID = $this->db->insert_id(); + if ($cytologiID == 0 ) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Cytologi ID Header" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + foreach($detail as $idx => $d ) { + $detail[$idx]["Other_CytologiDetailsOther_CytologiID"] = $cytologiID ; + $detail[$idx]["Other_CytologiDetailsUserID"] = 3; + $detail[$idx]["Other_CytologiDetailsIsActive"] = "Y"; + unset($detail[$idx]["Other_CytologiDetailsID"]); + unset($detail[$idx]["Other_CytologiDetailsCreated"]); + unset($detail[$idx]["Other_CytologiDetailsLastUpdated"]); + } + $qry = $this->db->insert_batch("other_cytologidetails",$detail); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Cytologi Add Detail" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + + //fna + function update_fna($detailID, $header, $detail ) { + $sql = "select * from t_orderdetail where T_OrderDetailID = ? "; + $qry = $this->db->query($sql, array($detailID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError FNA cek Validation " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + if ($rows[0]["T_OrderDetailValidation"] == "Y" ) return; + $sql = "select Other_FNAID from other_fna where Other_FNAT_OrderDetailID = ? and Other_FNAIsActive = 'Y'"; + $qry = $this->db->query($sql, array($detailID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError FNA cek Existence " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $rows = $qry->result_array(); + $fnaID = 0; + if (count($rows) > 0 ) $fnaID = $rows[0]["Other_FNAID"]; + if ( $fnaID > 0 ) { + $sql = "update other_fna set Other_FNAIsActive = 'N' where Other_FNAID = ? "; + $qry = $this->db->query($sql, array($fnaID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError FNA set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $sql = "update other_fnadetails set Other_FNADetailsIsActive = 'N' where Other_FNADetailsOther_FNAID= ? "; + $qry = $this->db->query($sql, array($fnaID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError FNA Details set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + unset($header["Other_FNAID"]); + $header["Other_FNACreated"] = date("Y-m-d h:i:s"); + $header["Other_FNALastUpdated"] =date("Y-m-d h:i:s"); + $header["Other_FNAUserID"] = 3; + $header["Other_FNAIsActive"] = "Y"; + $header["Other_FNAT_OrderDetailID"] = $detailID; + $qry = $this->db->insert("other_fna",$header); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError FNA Add Header" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $fnaID = $this->db->insert_id(); + if ($fnaID == 0 ) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError FNA ID Header" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + foreach($detail as $idx => $d ) { + $detail[$idx]["Other_FNADetailsOther_FNAID"] = $fnaID ; + $detail[$idx]["Other_FNADetailsUserID"] = 3; + $detail[$idx]["Other_FNADetailsIsActive"] = "Y"; + unset($detail[$idx]["Other_FNADetailsID"]); + unset($detail[$idx]["Other_FNADetailsCreated"]); + unset($detail[$idx]["Other_FNADetailsLastUpdated"]); + } + $qry = $this->db->insert_batch("other_fnadetails",$detail); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError FNA Add Detail" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + + + // update papsmear + function update_papsmear ($detailID, $header, $detail ) { + $sql = "select * from t_orderdetail where T_OrderDetailID = ? "; + $qry = $this->db->query($sql, array($detailID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear cek Validation " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + if ($rows[0]["T_OrderDetailValidation"] == "Y" ) return; + $sql = "select Other_PapSmearID from other_papsmear where Other_PapSmearT_OrderDetailID = ? and Other_PapSmearIsActive = 'Y'"; + $qry = $this->db->query($sql, array($detailID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear cek Existence " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $rows = $qry->result_array(); + $papsmearID = 0; + if (count($rows) > 0 ) $papsmearID = $rows[0]["Other_PapSmearID"]; + if ( $papsmearID > 0 ) { + $sql = "update other_papsmear set Other_PapSmearIsActive = 'N' where Other_PapSmearID = ? "; + $qry = $this->db->query($sql, array($papsmearID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $sql = "update other_papsmearbahan set Other_PapSmearBahanIsActive = 'N' where Other_PapSmearBahanOther_PapSmearID= ? "; + $qry = $this->db->query($sql, array($papsmearID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear Details set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + + $sql = "update other_papsmearcategory set Other_PapSmearCategoryIsActive = 'N' where Other_PapSmearCategoryOther_PapSmearID= ? "; + $qry = $this->db->query($sql, array($papsmearID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear Category set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + + $sql = "update other_papsmearcheck set Other_PapSmearCheckIsActive = 'N' where Other_PapSmearCheckOther_PapSmearID= ? "; + $qry = $this->db->query($sql, array($papsmearID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear Check set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + + $sql = "update other_papsmeardetails set Other_PapSmearDetailsIsActive = 'N' where Other_PapSmearDetailsOther_PapSmearID= ? "; + $qry = $this->db->query($sql, array($papsmearID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear Details set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + + $sql = "update other_papsmearmaturasi set Other_PapSmearMaturasiIsActive = 'N' where Other_PapSmearMaturasiOther_PapSmearID= ? "; + $qry = $this->db->query($sql, array($papsmearID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear Details set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + unset($header["Other_PapSmearID"]); + $header["Other_PapSmearCreated"] = date("Y-m-d h:i:s"); + $header["Other_PapSmearLastUpdated"] =date("Y-m-d h:i:s"); + $header["Other_PapSmearUserID"] = 3; + $header["Other_PapSmearIsActive"] = "Y"; + $header["Other_PapSmearT_OrderDetailID"] = $detailID; + $qry = $this->db->insert("other_papsmear",$header); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear Add Header" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $papsmearID= $this->db->insert_id(); + if ($papsmearID == 0 ) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear ID Header" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + foreach($detail as $key => $d ) { + if ($key == "bahan") { + foreach($d as $idx => $xd) { + $detail[$key][$idx]["Other_PapSmearBahanOther_PapSmearID"] = $papsmearID ; + $detail[$key][$idx]["Other_PapSmearBahanUserID"] = 3; + $detail[$key][$idx]["Other_PapSmearBahanIsActive"] = "Y"; + unset($detail[$key][$idx]["Other_PapSmearBahanID"]); + unset($detail[$key][$idx]["Other_PapSmearBahanCreated"]); + unset($detail[$key][$idx]["Other_PapSmearBahanLastUpdated"]); + } + $qry = $this->db->insert_batch("other_papsmearbahan",$detail[$key]); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear Add Bahan " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + if ($key == "category") { + foreach($d as $idx => $xd) { + $detail[$key][$idx]["Other_PapSmearCategoryOther_PapSmearID"] = $papsmearID ; + $detail[$key][$idx]["Other_PapSmearCategoryUserID"] = 3; + $detail[$key][$idx]["Other_PapSmearCategoryIsActive"] = "Y"; + unset($detail[$key][$idx]["Other_PapSmearCategoryID"]); + unset($detail[$key][$idx]["Other_PapSmearCategoryCreated"]); + unset($detail[$key][$idx]["Other_PapSmearCategoryLastUpdated"]); + } + $qry = $this->db->insert_batch("other_papsmearcategory",$detail[$key]); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear Add Category " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + if ($key == "check") { + foreach($d as $idx => $xd) { + $detail[$key][$idx]["Other_PapSmearCheckOther_PapSmearID"] = $papsmearID ; + $detail[$key][$idx]["Other_PapSmearCheckUserID"] = 3; + $detail[$key][$idx]["Other_PapSmearCheckIsActive"] = "Y"; + unset($detail[$key][$idx]["Other_PapSmearCheckID"]); + unset($detail[$key][$idx]["Other_PapSmearCheckCreated"]); + unset($detail[$key][$idx]["Other_PapSmearCheckLastUpdated"]); + } + $qry = $this->db->insert_batch("other_papsmearcheck",$detail[$key]); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear Add Check " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + if ($key == "details") { + foreach($d as $idx => $xd) { + $detail[$key][$idx]["Other_PapSmearDetailsOther_PapSmearID"] = $papsmearID ; + $detail[$key][$idx]["Other_PapSmearDetailsUserID"] = 3; + $detail[$key][$idx]["Other_PapSmearDetailsIsActive"] = "Y"; + unset($detail[$key][$idx]["Other_PapSmearDetailsID"]); + unset($detail[$key][$idx]["Other_PapSmearDetailsCreated"]); + unset($detail[$key][$idx]["Other_PapSmearDetailsLastUpdated"]); + } + $qry = $this->db->insert_batch("other_papsmeardetails",$detail[$key]); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear Add Details " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + if ($key == "maturasi") { + foreach($d as $idx => $xd) { + $detail[$key][$idx]["Other_PapSmearMaturasiOther_PapSmearID"] = $papsmearID ; + $detail[$key][$idx]["Other_PapSmearMaturasiUserID"] = 3; + $detail[$key][$idx]["Other_PapSmearMaturasiIsActive"] = "Y"; + unset($detail[$key][$idx]["Other_PapSmearMaturasiID"]); + unset($detail[$key][$idx]["Other_PapSmearMaturasiCreated"]); + unset($detail[$key][$idx]["Other_PapSmearMaturasiLastUpdated"]); + } + $qry = $this->db->insert_batch("other_papsmearmaturasi",$detail[$key]); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError PapSmear Add Maturasi " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + } + } + + function update_lcprep($detailID, $header, $detail ) { + $sql = "select * from t_orderdetail where T_OrderDetailID = ? "; + $qry = $this->db->query($sql, array($detailID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep cek Validation " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $rows = $qry->result_array(); + if (count($rows) == 0 ) return; + if ($rows[0]["T_OrderDetailValidation"] == "Y" ) return; + $sql = "select Other_LcprepID from other_lcprep where Other_LcprepT_orderDetailID = ? and Other_LcprepIsActive = 'Y'"; + $qry = $this->db->query($sql, array($detailID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep cek Existence " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $rows = $qry->result_array(); + $lcprepID = 0; + if (count($rows) > 0 ) $lcprepID = $rows[0]["Other_LcprepID"]; + if ( $lcprepID > 0 ) { + $sql = "update other_lcprep set Other_LcprepIsActive = 'N' where Other_LcprepID = ? "; + $qry = $this->db->query($sql, array($lcprepID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $sql = "update other_lcprepadekuasi set Other_LcprepAdekuasiIsActive = 'N' where Other_LcprepAdekuasiOther_LcprepID= ? "; + $qry = $this->db->query($sql, array($lcprepID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep Adekuasi set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + + $sql = "update other_lcprepinterpretasi set Other_LcprepInterpretasiIsActive = 'N' where Other_LcprepInterpretasiOther_LcprepID= ? "; + $qry = $this->db->query($sql, array($lcprepID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep Interpretasi set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + + $sql = "update other_lcprepdetails set Other_LcprepDetailsIsActive = 'N' where Other_LcprepDetailsOther_LcprepID= ? "; + $qry = $this->db->query($sql, array($lcprepID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep Details set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + + $sql = "update other_lcprepkategoriumum set Other_LcprepKategoriUmumIsActive = 'N' where Other_LcprepKategoriUmumOther_LcprepID= ? "; + $qry = $this->db->query($sql, array($lcprepID)); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep KategoriUmum set Inactive" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + unset($header["Other_LcprepID"]); + $header["Other_LcprepCreated"] = date("Y-m-d h:i:s"); + $header["Other_LcprepLastUpdated"] =date("Y-m-d h:i:s"); + $header["Other_LcprepUserID"] = 3; + $header["Other_LcprepIsActive"] = "Y"; + $header["Other_LcprepT_orderDetailID"] = $detailID; + $qry = $this->db->insert("other_lcprep",$header); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep Add Header" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + $lcprepID= $this->db->insert_id(); + if ($lcprepID == 0 ) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep ID Header" . print_r($this->db->error(),true),FILE_APPEND); + return; + } + foreach($detail as $key => $d ) { + if ($key == "adekuasi") { + foreach($d as $idx => $xd) { + $detail[$key][$idx]["Other_LcprepAdekuasiOther_LcprepID"] = $lcprepID ; + $detail[$key][$idx]["Other_LcprepAdekuasiUserID"] = 3; + $detail[$key][$idx]["Other_LcprepAdekuasiIsActive"] = "Y"; + unset($detail[$key][$idx]["Other_LcprepAdekuasiID"]); + unset($detail[$key][$idx]["Other_LcprepAdekuasiCreated"]); + unset($detail[$key][$idx]["Other_LcprepAdekuasiLastUpdated"]); + } + $qry = $this->db->insert_batch("other_lcprepadekuasi",$detail[$key]); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep Add Adekuasi " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + if ($key == "interpretasi") { + foreach($d as $idx => $xd) { + $detail[$key][$idx]["Other_LcprepInterpretasiOther_LcprepID"] = $lcprepID ; + $detail[$key][$idx]["Other_LcprepInterpretasiUserID"] = 3; + $detail[$key][$idx]["Other_LcprepInterpretasiIsActive"] = "Y"; + unset($detail[$key][$idx]["Other_LcprepInterpretasiID"]); + unset($detail[$key][$idx]["Other_LcprepInterpretasiCreated"]); + unset($detail[$key][$idx]["Other_LcprepInterpretasiLastUpdated"]); + } + $qry = $this->db->insert_batch("other_lcprepinterpretasi",$detail[$key]); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep Add Interpretasi " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + if ($key == "details") { + foreach($d as $idx => $xd) { + $detail[$key][$idx]["Other_LcprepDetailsOther_LcprepID"] = $lcprepID ; + $detail[$key][$idx]["Other_LcprepDetailsUserID"] = 3; + $detail[$key][$idx]["Other_LcprepDetailsIsActive"] = "Y"; + unset($detail[$key][$idx]["Other_LcprepDetailsID"]); + unset($detail[$key][$idx]["Other_LcprepDetailsCreated"]); + unset($detail[$key][$idx]["Other_LcprepDetailsLastUpdated"]); + } + $qry = $this->db->insert_batch("other_lcprepdetails",$detail[$key]); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep Add Details " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + if ($key == "kategoriumum") { + foreach($d as $idx => $xd) { + $detail[$key][$idx]["Other_LcprepKategoriUmumOther_LcprepID"] = $lcprepID ; + $detail[$key][$idx]["Other_LcprepKategoriUmumUserID"] = 3; + $detail[$key][$idx]["Other_LcprepKategoriUmumIsActive"] = "Y"; + unset($detail[$key][$idx]["Other_LcprepKategoriUmumID"]); + unset($detail[$key][$idx]["Other_LcprepKategoriUmumCreated"]); + unset($detail[$key][$idx]["Other_LcprepKategoriUmumLastUpdated"]); + } + $qry = $this->db->insert_batch("other_lcprepkategoriumum",$detail[$key]); + if(!$qry) { + file_put_contents("/xtmp/dbg-xstatus_branch-v3.log", "\nError Lcprep Add KategoriUmum " . print_r($this->db->error(),true),FILE_APPEND); + return; + } + } + } + } + + function update() { + $prm = $this->sys_input; + foreach($prm as $p) { + $deliveryOrderID = $p["incomingRefT_RefDeliveryOrderID"]; + $detailID = $p["incomingRefDetailT_OrderDetailID"]; + $normalValueID = $p["T_OrderDetailNat_NormalValueID"]; + $result = $p["T_OrderDetailResult"]; + $resultnote = $p["T_OrderDetailNote"]; + $validation = $p["T_OrderDetailValidation"]; + $verification = $p["T_OrderDetailVerification"]; + $status = $p["incomingRefDetailStatus"]; + $note = ''; + if (isset($p["note"])) $note = $p["note"]; + if ($validation == "Y") { + $ret = $this->update_delivery($deliveryOrderID,$detailID,"$result","VALIDATION",$note); + if ($ret) $ret = $this->update_order($detailID,$result,$resultnote,$normalValueID); + if (isset($p["nonlab_result"])) { + $type = $p["nonlab_result"]["type"]; + $header = $p["nonlab_result"]["header"]; + $detail = $p["nonlab_result"]["detail"]; + + if ($type == "mikro" ) { + $this->update_mikro($detailID,$header,$detail); + } + if ($type == "papsmear" ) { + $this->update_papsmear($detailID,$header,$detail); + } + if ($type == "lcprep" ) { + $this->update_lcprep($detailID,$header,$detail); + } + if ($type == "fna" ) { + $this->update_fna($detailID,$header,$detail); + } + if ($type == "cytologi" ) { + $this->update_cytologi($detailID,$header,$detail); + } + } + } elseif($verification == "Y") { + $ret = $this->update_delivery($deliveryOrderID,$detailID,"$result","VERIFICATION",$note); + } elseif($status != "N") { + $ret = $this->update_delivery($deliveryOrderID,$detailID,"Diterima"); + } else { + $ret = $this->update_delivery($deliveryOrderID,$detailID,"Ditolak"); + } + if (! $ret ) { + echo json_encode( array("status"=>"ERR", "message"=> print_r($this->db->error(),true) )); + exit; + } + } + echo json_encode( array("status"=>"OK", "message"=>"")); + } + function update_delivery($deliveryOrderID,$detailID,$value,$stage = "", $note = "" ) { + $sql = "select T_RefDeliveryOrderDetailT_OrderDetailID , + T_RefDeliveryOrderDetailID, + T_RefDeliveryOrderChildID + from t_ref_deliveryorder_child + join t_ref_deliveryorder_detail on + T_RefDeliveryOrderChildT_RefDeliveryOrderDetailID = T_RefDeliveryOrderDetailID + where T_RefDeliveryOrderDetailT_RefDeliveryOrderID = ? + and T_RefDeliveryOrderChildT_OrderDetailID = ?"; + $qry = $this->db->query($sql, array($deliveryOrderID, $detailID)); + $flag_child = false; + $child_id = 0; + $refDeliveryOrderDetailID = 0; + if ($qry) { + $rows = $qry->result_array(); + if (count($rows) > 0 ) { + $flag_child = true; + $child_id = $rows[0]["T_RefDeliveryOrderChildID"]; + $parentDetailID = $rows[0]["T_RefDeliveryOrderDetailID"]; + } + } + if ($flag_child) { + $sql = "update t_ref_deliveryorder_child + set T_RefDeliveryOrderChildResult = ?, + T_RefDeliveryOrderChildStage= ? , + T_RefDeliveryOrderChildNote = ? + where T_RefDeliveryOrderChildID=?"; + + $qry = $this->db->query($sql, array($value, $state, $note, $child_id)); + $value = "..."; + $detailID = $parentDetailID; + } + + if ($flag_child) { + $sql = "update t_ref_deliveryorder_detail + set T_RefDeliveryOrderDetailResult = ?, + T_RefDeliveryOrderDetailStage = ?, + T_RefDeliveryOrderDetailNote = ? + where T_RefDeliveryOrderDetailT_RefDeliveryOrderID = ? + and T_RefDeliveryOrderDetailID = ?"; + } else { + $sql = "update t_ref_deliveryorder_detail + set T_RefDeliveryOrderDetailResult = ?, + T_RefDeliveryOrderDetailStage = ?, + T_RefDeliveryOrderDetailNote = ? + where T_RefDeliveryOrderDetailT_RefDeliveryOrderID = ? + and T_RefDeliveryOrderDetailT_OrderDetailID = ?"; + } + + $qry = $this->db->query($sql, array($value, $stage, $note, $deliveryOrderID, $detailID)); + + return $qry; + } + function update_order($detailID,$value,$resultnote,$normalValueID) { + $verUserID = 3; + + $sql = "update t_orderdetail + set T_OrderDetailResult = ?, + T_OrderDetailNote = ?, + T_OrderDetailNat_NormalValueID = ?, + T_OrderDetailVerification = 'Y', + T_OrderDetailVerDate = now(), + T_OrderDetailVerUserID = $verUserID + where T_OrderDetailID = ?"; + $qry = $this->db->query($sql, array($value,$resultnote, $normalValueID, $detailID)); + + if ( $qry) { + $sql = "update t_orderdetail, nat_normalvalue, nat_methode + set T_OrderDetailNat_MethodeID = Nat_NormalValueNat_MethodeID , + T_OrderDetailNat_MethodeName = Nat_MethodeName, + T_OrderDetailNormalValueNote = Nat_NormalValueNote, + T_OrderDetailNormalValueDescription = Nat_NormalValueDescription, + T_OrderDetailMinValue = Nat_NormalValueMinValue, + T_OrderDetailMaxValue = Nat_NormalValueMaxValue, + T_OrderDetailMinValueInclusive = Nat_NormalValueMinValueInclusive, + T_OrderDetailMaxValueInclusive = Nat_NormalValueMaxValueInclusive + where T_OrderDetailID = ? + and T_OrderDetailNat_NormalValueID = Nat_NormalValueID + and Nat_NormalValueNat_MethodeID = Nat_MethodeID"; + $qryn = $this->db->query($sql, array($detailID)); + //if (! $qryn ) print_r($this->db->error()); + if (! $qryn ) return false; + $sql = "call sp_set_normal_value_flag(?)"; + $qryu = $this->db->query($sql, array($detailID)); + //if (! $qryu ) print_r($this->db->error()); + if (! $qryu ) return false; + $this->clean_mysqli_connection($this->db->conn_id); + } + return $qry; + } +}