805 lines
31 KiB
PHP
805 lines
31 KiB
PHP
<?php
|
|
|
|
class Sample extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "REF RECEIVE SAMPLE API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
function fix_barcodelab($refID) {
|
|
$sql = "select incomingRefDetailNewT_OrderHeaderID,
|
|
incomingRefDetailT_TestID,
|
|
incomingRefDetailT_BarcodeLabBarcode,
|
|
T_TestSasCode
|
|
from incoming_ref_detail
|
|
join t_test on T_TestID = incomingRefDetailT_TestID
|
|
where incomingRefDetailID = ?";
|
|
$qry = $this->db->query($sql, array($refID));
|
|
if (! $qry) {
|
|
return;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if( count($rows) == 0 ) return;
|
|
$orgBarcode = $rows[0]["incomingRefDetailT_BarcodeLabBarcode"];
|
|
$orgSasCode = $rows[0]["T_TestSasCode"];
|
|
$orgT_OrderHeaderID = $rows[0]["incomingRefDetailNewT_OrderHeaderID"];
|
|
// echo 'Barcode : '.$orgBarcode.' Sas Code :'.$orgSasCode. ' Header ID : '. $orgT_OrderHeaderID;
|
|
|
|
$sql = "select distinct left(T_SampleTypeCode,3) as T_SampleTypeCode
|
|
from
|
|
t_test
|
|
join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID
|
|
and T_TestSasCode like '$orgSasCode%' and T_SampleTypeIsActive = 'Y' and T_TestIsActive = 'Y' ";
|
|
// echo $sql;
|
|
$qry = $this->db->query($sql);
|
|
if (! $qry) {
|
|
return;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
if( count($rows) == 0 ) return;
|
|
foreach($rows as $r) {
|
|
$sampleTypeCode = $r["T_SampleTypeCode"];
|
|
$sql = "update
|
|
t_barcodelab
|
|
join t_sampletype on T_BarcodeLabT_SampleTypeID = T_SampleTypeID
|
|
and T_BarcodeLabT_OrderHeaderID = $orgT_OrderHeaderID
|
|
and T_BarcodeLabBarcodeOrigin is null
|
|
and T_SampleTypeCode like '$sampleTypeCode%'
|
|
set T_BarcodeLabBarcodeOrigin = '{$orgBarcode}'";
|
|
$qry = $this->db->query($sql);
|
|
// echo $sql;
|
|
// echo $this->db_onedev->last_query();
|
|
}
|
|
}
|
|
function selected_sample()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $prm['id'];
|
|
// $barcode = $prm['barcode'];
|
|
|
|
$sql = $this->db_onedev->query("SELECT COUNT(*) as semua FROM one_mitra.t_orderdetaildelivery
|
|
JOIN one_mitra.t_order ON T_OrderID = T_OrderDetailDeliveryT_OrderID AND T_OrderIsActive = 'Y'
|
|
JOIN one_mitra.m_patient ON M_PatientID = T_OrderM_PatientID
|
|
WHERE T_OrderDetailDeliveryT_OrderDeliveryID = '{$id}'")->row();
|
|
$semua = $sql->semua;
|
|
|
|
$sql = $this->db_onedev->query("SELECT COUNT(*) as terima FROM one_mitra.t_orderdetaildelivery
|
|
JOIN one_mitra.t_order ON T_OrderID = T_OrderDetailDeliveryT_OrderID AND T_OrderIsActive = 'Y'
|
|
JOIN one_mitra.m_patient ON M_PatientID = T_OrderM_PatientID
|
|
|
|
WHERE T_OrderDetailDeliveryT_OrderDeliveryID = '{$id}' AND T_OrderStatus = 'R'")->row();
|
|
$terima = $sql->terima;
|
|
|
|
$sql = $this->db_onedev->query("SELECT IF(T_OrderStatus = 'S','N',T_OrderStatus) as konfirmasi FROM one_mitra.t_orderdetaildelivery
|
|
JOIN one_mitra.t_order ON T_OrderID = T_OrderDetailDeliveryT_OrderID AND T_OrderIsActive = 'Y'
|
|
WHERE T_OrderDetailDeliveryT_OrderDeliveryID = '{$id}'")->row();
|
|
$konfirmasi = $sql->konfirmasi;
|
|
|
|
$sql = "SELECT *, ischoose FROM (SELECT t_orderdetaildelivery.*,
|
|
T_OrderDetailSampleStatus as ischoose,
|
|
CONCAT(T_OrderDetailSampleName , ' | ',T_OrderNumber) as nosample,
|
|
'{$semua}' as semua,
|
|
'{$terima}' as terima,
|
|
T_OrderStatus,
|
|
'sample' as tipe,
|
|
T_OrderDetailSampleID as id
|
|
|
|
from one_mitra.t_orderdetaildelivery
|
|
JOIN one_mitra.t_order ON T_OrderID = T_OrderDetailDeliveryT_OrderID AND T_OrderIsActive = 'Y'
|
|
JOIN one_mitra.m_patient ON M_PatientID = T_OrderM_PatientID
|
|
JOIN one_mitra.t_orderdetailsample ON T_OrderDetailSampleT_OrderID = T_OrderID AND T_OrderDetailSampleIsActive = 'Y'
|
|
where
|
|
T_OrderDetailDeliveryT_OrderDeliveryID = '{$id}'
|
|
|
|
UNION SELECT t_orderdetaildelivery.*,
|
|
T_OrderDetailBahanStatus as ischoose,
|
|
CONCAT(T_OrderDetailBahanName , ' | ',T_OrderNumber) as nosample,
|
|
'{$semua}' as semua,
|
|
'{$terima}' as terima,
|
|
T_OrderStatus,
|
|
'bahan' as tipe,
|
|
T_OrderDetailBahanID as id
|
|
|
|
from one_mitra.t_orderdetaildelivery
|
|
JOIN one_mitra.t_order ON T_OrderID = T_OrderDetailDeliveryT_OrderID AND T_OrderIsActive = 'Y'
|
|
JOIN one_mitra.m_patient ON M_PatientID = T_OrderM_PatientID
|
|
JOIN one_mitra.t_orderdetailbahan ON T_OrderDetailBahanT_OrderID = T_OrderID AND T_OrderDetailBahanIsActive = 'Y'
|
|
where
|
|
T_OrderDetailDeliveryT_OrderDeliveryID = '{$id}') a
|
|
";
|
|
// echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
$this->sys_error_db( $this->db_onedev->last_query() );
|
|
exit;
|
|
}
|
|
$result = array ("total" => count($rows), "records" => $rows, "semua" => $semua, "terima" => $terima, "konfirmasi" => $konfirmasi);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function tolak_all(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$incomingRefID = $prm["id"];
|
|
foreach($prm["dodetail"] as $idx => $detail) {
|
|
$orderHeaderID = $detail["T_OrderDetailDeliveryT_OrderID"];
|
|
if($detail["tipe"] == "sample"){
|
|
$sql = "UPDATE one_mitra.t_orderdetailsample
|
|
SET T_OrderDetailSampleStatus = 'X'
|
|
WHERE T_OrderDetailSampleID = {$detail["id"]}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
|
|
if($detail["tipe"] == "bahan"){
|
|
$sql = "UPDATE one_mitra.t_orderdetailbahan
|
|
SET T_OrderDetailBahanStatus = 'X'
|
|
WHERE T_OrderDetailBahanID = {$detail["id"]}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
|
|
}
|
|
|
|
$sql = "SELECT T_OrderDetailDeliveryT_OrderID FROM one_mitra.t_orderdetaildelivery
|
|
WHERE T_OrderDetailDeliveryT_OrderDeliveryID = '{$incomingRefID}'";
|
|
$qry = $this->db_onedev->query($sql);
|
|
$branchID = 0;
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r) {
|
|
$ID = $r["T_OrderDetailDeliveryT_OrderID"];
|
|
|
|
$sql = "UPDATE one_mitra.t_order
|
|
SET T_OrderStatus = 'X'
|
|
WHERE T_OrderID = {$ID}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
|
|
}
|
|
|
|
$sql = "UPDATE one_mitra.t_orderdelivery
|
|
SET T_OrderDeliveryStatus = 'X'
|
|
WHERE T_OrderDeliveryID = {$incomingRefID}";
|
|
$this->db_onedev->query($sql);
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function confirmdeliveryorder(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$incomingRefID = $prm["id"];
|
|
foreach($prm["dodetail"] as $idx => $detail) {
|
|
$orderHeaderID = $detail["T_OrderDetailDeliveryT_OrderID"];
|
|
if($detail["tipe"] == "sample"){
|
|
if ($detail["ischoose"] == "N") {
|
|
$sql = "UPDATE one_mitra.t_orderdetailsample
|
|
SET T_OrderDetailSampleStatus = 'X'
|
|
WHERE T_OrderDetailSampleID = {$detail["id"]}";
|
|
$this->db_onedev->query($sql);
|
|
} else {
|
|
$sql = "UPDATE one_mitra.t_orderdetailsample
|
|
SET T_OrderDetailSampleStatus = 'Y'
|
|
WHERE T_OrderDetailSampleID = {$detail["id"]}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
}
|
|
|
|
if($detail["tipe"] == "bahan"){
|
|
if ($detail["ischoose"] == "N") {
|
|
$sql = "UPDATE one_mitra.t_orderdetailbahan
|
|
SET T_OrderDetailBahanStatus = 'X'
|
|
WHERE T_OrderDetailBahanID = {$detail["id"]}";
|
|
$this->db_onedev->query($sql);
|
|
} else {
|
|
$sql = "UPDATE one_mitra.t_orderdetailbahan
|
|
SET T_OrderDetailBahanStatus = 'Y'
|
|
WHERE T_OrderDetailBahanID = {$detail["id"]}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$sql = "SELECT T_OrderDetailDeliveryT_OrderID FROM one_mitra.t_orderdetaildelivery
|
|
WHERE T_OrderDetailDeliveryT_OrderDeliveryID = '{$incomingRefID}'";
|
|
$qry = $this->db_onedev->query($sql);
|
|
$branchID = 0;
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r) {
|
|
$ID = $r["T_OrderDetailDeliveryT_OrderID"];
|
|
$sql = $this->db_onedev->query("SELECT COUNT(*) as semua FROM
|
|
(SELECT T_OrderDetailSampleID as id
|
|
FROM one_mitra.t_orderdetaildelivery
|
|
JOIN one_mitra.t_orderdetailsample ON T_OrderDetailSampleT_OrderID = T_OrderDetailDeliveryT_OrderID AND T_OrderDetailSampleIsActive = 'Y'
|
|
WHERE T_OrderDetailDeliveryT_OrderID = {$ID}
|
|
UNION
|
|
SELECT T_OrderDetailBahanID as id
|
|
FROM one_mitra.t_orderdetaildelivery
|
|
JOIN one_mitra.t_orderdetailbahan ON T_OrderDetailBahanT_OrderID = T_OrderDetailDeliveryT_OrderID AND T_OrderDetailBahanIsActive = 'Y'
|
|
WHERE T_OrderDetailDeliveryT_OrderID = {$ID}
|
|
)a")->row();
|
|
$semua = $sql->semua;
|
|
|
|
$sql = $this->db_onedev->query("SELECT COUNT(*) as terima FROM
|
|
(SELECT T_OrderDetailSampleID as id
|
|
FROM one_mitra.t_orderdetaildelivery
|
|
JOIN one_mitra.t_orderdetailsample ON T_OrderDetailSampleT_OrderID = T_OrderDetailDeliveryT_OrderID AND T_OrderDetailSampleIsActive = 'Y' AND T_OrderDetailSampleStatus = 'Y'
|
|
WHERE T_OrderDetailDeliveryT_OrderID = {$ID}
|
|
UNION
|
|
SELECT T_OrderDetailBahanID as id
|
|
FROM one_mitra.t_orderdetaildelivery
|
|
JOIN one_mitra.t_orderdetailbahan ON T_OrderDetailBahanT_OrderID = T_OrderDetailDeliveryT_OrderID AND T_OrderDetailBahanIsActive = 'Y' AND T_OrderDetailBahanStatus = 'Y'
|
|
WHERE T_OrderDetailDeliveryT_OrderID = {$ID}
|
|
)a")->row();
|
|
$terima = $sql->terima;
|
|
|
|
if($semua == $terima){
|
|
$sql = "UPDATE one_mitra.t_order
|
|
SET T_OrderStatus = 'R'
|
|
WHERE T_OrderID = {$ID}";
|
|
$this->db_onedev->query($sql);
|
|
}elseif($semua > $terima && $terima == 0){
|
|
$sql = "UPDATE one_mitra.t_order
|
|
SET T_OrderStatus = 'X'
|
|
WHERE T_OrderID = {$ID}";
|
|
$this->db_onedev->query($sql);
|
|
}elseif($semua > $terima && $terima > 0){
|
|
$sql = "UPDATE one_mitra.t_order
|
|
SET T_OrderStatus = 'T'
|
|
WHERE T_OrderID = {$ID}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$sql = "UPDATE one_mitra.t_orderdelivery
|
|
SET T_OrderDeliveryStatus = 'R'
|
|
WHERE T_OrderDeliveryID = {$incomingRefID}";
|
|
$this->db_onedev->query($sql);
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function ref_order($incomingRefID,$doctorID,$doctorAddressID) {
|
|
//$adminUserID = 3;
|
|
$adminUserID = $this->sys_user["M_UserID"] ;
|
|
|
|
//create order yg di confirm saja
|
|
$sql = "select *
|
|
from one_mitra.t_orderdetaildelivery
|
|
JOIN one_mitra.t_order ON T_OrderID = T_OrderDetailDeliveryT_OrderID
|
|
-- AND T_OrderStatus = 'R'
|
|
JOIN one_mitra.t_orderdetail ON T_OrderDetailOrderID = T_OrderID AND T_OrderDetailIsActive = 'Y'
|
|
where T_OrderDetailDeliveryT_OrderDeliveryID = ?
|
|
order by T_OrderID ASC, T_OrderDetailID ASC";
|
|
$qry = $this->db_onedev->query($sql, array($incomingRefID) );
|
|
$orders = array();
|
|
$ax_test = array();
|
|
$a_promise = array();
|
|
$a_barcode = array();
|
|
$a_ref_detail = array();
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
$prev_oh_id = 0;
|
|
foreach($rows as $r) {
|
|
$mouID = $r["T_OrderM_MouID"];
|
|
$companyID = $r["T_OrderM_CompanyID"];
|
|
$oh_id = $r["T_OrderDetailDeliveryT_OrderID"];
|
|
$incomingRefDetailFoNote = $r["T_OrderNote"];
|
|
$incomingRefDetailVefificationNote = $r["T_OrderDiagnosis"];
|
|
if ( ! isset($orders[$oh_id]) ) {
|
|
$orders[$oh_id]["patient"] = $r["T_OrderM_PatientID"];
|
|
$orders[$oh_id]["foNote"] = $incomingRefDetailFoNote;
|
|
$orders[$oh_id]["verificationNote"] = $incomingRefDetailVefificationNote;
|
|
$orders[$oh_id]["samplingNote"] = '';
|
|
$orders[$oh_id]["LabNumber"] = '';
|
|
$orders[$oh_id]["test"] = array();
|
|
}
|
|
$orders[$oh_id]["test"][] = array (
|
|
"T_TestID" => $r["T_OrderDetailTestID"],
|
|
"Promise" => '',
|
|
"T_OrderDetailID" => '',
|
|
"T_BarcodeLabBarcode" => '',
|
|
"Requirements" => ''
|
|
);
|
|
$ax_test[] = $r["T_OrderDetailTestID"];
|
|
$a_promise[$oh_id][$r["T_OrderDetailTestID"]] = '';
|
|
$a_barcode[$oh_id][$r["T_OrderDetailTestID"]] = '';
|
|
$a_ref_detail[] = $r["T_OrderDetailID"];
|
|
}
|
|
}
|
|
$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) );
|
|
//test primer sama dengan T_TestID
|
|
$a_test = array();
|
|
if ($qry ) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r) {
|
|
$testID = $r["T_TestID"];
|
|
$a_test[$testID] = array(
|
|
"T_PriceAmount" => $r["T_PriceAmount"],
|
|
"T_PriceDiscRp" => $r["T_PriceDiscRp"],
|
|
"T_PriceDisc" => $r["T_PriceDisc"]
|
|
);
|
|
}
|
|
}
|
|
//test sekunder dari Nat_Test
|
|
$a_test_v2 = array();
|
|
$sql = "select ss_price_mou.*
|
|
from ss_price_mou
|
|
where Ss_PriceMouM_MouID = ? and
|
|
ss_price_mou.T_TestID in (
|
|
select s.T_TestID
|
|
from t_test s
|
|
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) );
|
|
//test primer sama dengan T_TestID
|
|
if ($qry ) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r) {
|
|
$testID = $r["T_TestID"];
|
|
$a_test_v2[$testID] = array(
|
|
"T_PriceAmount" => $r["T_PriceAmount"],
|
|
"T_PriceDiscRp" => $r["T_PriceDiscRp"],
|
|
"T_PriceDisc" => $r["T_PriceDisc"]
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
$message = "";
|
|
foreach($orders as $oh_id => $o){
|
|
|
|
$patientID = $this->create_patient($orders[$oh_id]["patient"],$companyID,$adminUserID);
|
|
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) );
|
|
$patientAge = "";
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0 ) {
|
|
$patientAge = $rows[0]["age"];
|
|
}
|
|
}
|
|
//echo "1. $lab_number : $patientID \n";
|
|
//register order
|
|
$xheader = array(
|
|
'patient_id' => $patientID,
|
|
'age' => $patientAge,
|
|
'sender_doctor_id' => $doctorID,
|
|
'sender_address_id' => $doctorAddressID,
|
|
'company_id' => $companyID,
|
|
'mou_id' => $mouID,
|
|
'lang_id' => '1',
|
|
'lang_si' => 'N',
|
|
'doctor_note' => '',
|
|
'fo_note' => $orders[$oh_id]["foNote"],
|
|
'queue' => '',
|
|
'received_sample' => 'Y',
|
|
'lang_id_2' => '2',
|
|
'lang_si_2' => 'N',
|
|
);
|
|
$sql = "select M_CompanyAddress, M_CompanyM_KelurahanID
|
|
from m_company where M_CompanyID = ?";
|
|
$qry = $this->db->query($sql, array($companyID));
|
|
$rows = $qry->result_array();
|
|
|
|
$xdel = array(
|
|
array(
|
|
'address_id' => $companyID,
|
|
'delivery_id' => '10',
|
|
'delivery_type_id' => '2',
|
|
'senderdoctorid' => $doctorID,
|
|
'senderaddressid' => $doctorAddressID,
|
|
'note' => $rows[0]['M_CompanyAddress'],
|
|
'kelurahan' => $rows[0]['M_CompanyM_KelurahanID']
|
|
));
|
|
$xdet = array();
|
|
$reqs = array();
|
|
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_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"]];
|
|
$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_req' => 'Y',
|
|
't_reqnote' => '',
|
|
't_ispacket' => "N",
|
|
't_packettype' => "PX",
|
|
't_packetid' => '0'
|
|
);
|
|
} else {
|
|
$xdet[] = array(
|
|
't_id' => $t['T_TestID'],
|
|
't_cito' => 'N',
|
|
't_price' => 0,
|
|
't_disc' => 0,
|
|
't_discrp' => 0,
|
|
't_req' => 'Y',
|
|
't_reqnote' => '',
|
|
't_ispacket' => "N",
|
|
't_packettype' => "PX",
|
|
't_packetid' => '0'
|
|
);
|
|
}
|
|
if (count($t["Requirements"]) > 0 ) {
|
|
$reqs = array_merge($reqs, $t["Requirements"]);
|
|
}
|
|
}
|
|
//requirements
|
|
$xreq = array(
|
|
'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();
|
|
echo $this->db_onedev->last_query();
|
|
$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 ]";
|
|
$g_date = date("Y-m-d H:i:s");
|
|
file_put_contents("/xtmp/gagal-order.log","$g_date $message\n", FILE_APPEND);
|
|
continue;
|
|
}
|
|
$data = json_decode($r->data,true);
|
|
$new_oh_id = $data["id"];
|
|
$new_lab_number= $data["number"];
|
|
|
|
//echo "2. $new_oh_id : $lab_number => $new_lab_number \n";
|
|
//update incoming_ref
|
|
$sql = "update one_mitra.t_order set T_OrderT_OrderHeaderID=?,
|
|
T_OrderM_PatientNewID = ?
|
|
where T_OrderDetailDeliveryT_OrderDeliveryID = ?
|
|
and T_OrderDetailDeliveryT_OrderID=?";
|
|
$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));
|
|
|
|
*/
|
|
|
|
|
|
//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])) {
|
|
$sql = "insert into t_orderpromise(T_OrderPromiseT_OrderHeaderID, T_OrderPromiseDateTime)
|
|
values(?,?)";
|
|
$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;
|
|
} else {
|
|
$a_promise_test[$testID] = $a_promise_date["$promise"];
|
|
}
|
|
}
|
|
if ( count($a_promise_test) > 0 ) {
|
|
$s_test = join(",", array_keys($a_promise_test));
|
|
$sql = "update t_orderpromise,t_orderdetail
|
|
set T_OrderPromiseIsActive = 'N'
|
|
where T_OrderPromiseID = T_OrderDetailT_OrderPromiseID
|
|
and T_OrderDetailT_OrderHeaderID = ?
|
|
and T_OrderDetailT_TestID in ($s_test) ";
|
|
$this->db_onedev->query($sql, array($new_oh_id));
|
|
}
|
|
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) );
|
|
}
|
|
//insert requirements
|
|
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"] ));
|
|
}
|
|
//update note
|
|
$sql = "update t_orderheader
|
|
set T_OrderHeaderFoNote = ? , T_OrderHeaderFoNoteM_UserID = ?,
|
|
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);
|
|
/*
|
|
//update t_barcodelab
|
|
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));
|
|
}
|
|
//fix t_barcodelab
|
|
foreach($a_ref_detail as $rd) {
|
|
$this->fix_barcodelab($rd);
|
|
//echo 'fix barcodelab' . $rd;
|
|
}
|
|
// update nilai normal
|
|
$sql = "select distinct T_OrderDetailT_OrderHeaderID id,
|
|
T_TestT_SampleTypeID sid
|
|
from t_orderdetail
|
|
join t_test on T_OrderDetailT_OrderHeaderID = ?
|
|
and T_OrderDetailIsActive = 'Y' and
|
|
T_OrderDetailT_TestID = T_TestID
|
|
and T_TestIsActive = 'Y' ";
|
|
$qry = $this->db_onedev->query($sql, array($new_oh_id));
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r) {
|
|
$sql = "call sp_sampling_set_normal(?,?)";
|
|
$this->db_onedev->query($sql,array($r["id"],$r["sid"]));
|
|
}
|
|
}
|
|
|
|
*/
|
|
if ($message != "" ) $message .= ",";
|
|
$message .= "[ $lab_number -> $new_lab_number Fo Verify : $result ]";
|
|
}
|
|
return array( "status" => "OK",
|
|
"message" => $message );
|
|
}
|
|
function create_patient($pat_id,$com_id, $userID) {
|
|
|
|
$sql = "select *
|
|
from one_mitra.m_patient
|
|
where M_PatientID = ?";
|
|
$qry = $this->db->query($sql, array($pat_id));
|
|
$rows = $qry->result_array();
|
|
|
|
|
|
|
|
$p_name = stripslashes($rows[0]['M_PatientName']);
|
|
$p_name2 = stripslashes($p_name);
|
|
$patient_name = str_replace("'", "\\'", $p_name2);
|
|
$pnote = '';
|
|
$pdob = date('Y-m-d',strtotime($rows[0]['M_PatientDOB']));
|
|
$pob = str_replace("'", "", $rows[0]['M_PatientPOB']);
|
|
$hp = str_replace("'", "",$rows[0]['M_PatientHP']);
|
|
$query ="INSERT INTO m_patient (
|
|
M_PatientM_TitleID,
|
|
M_PatientName,
|
|
M_PatientDOB,
|
|
M_PatientM_SexID,
|
|
M_PatientM_ReligionID,
|
|
M_PatientEmail,
|
|
M_PatientPOB,
|
|
M_PatientHP,
|
|
M_PatientPhone,
|
|
M_PatientM_IdTypeID,
|
|
M_PatientIDNumber,
|
|
M_PatientNote,
|
|
M_PatientUserID
|
|
)
|
|
VALUES(
|
|
'{$rows[0]['M_PatientTitleID']}',
|
|
'{$patient_name}',
|
|
'{$pdob}',
|
|
'{$rows[0]['M_PatientM_SexID']}',
|
|
'0',
|
|
'0',
|
|
'{$pob}',
|
|
'{$hp}',
|
|
'',
|
|
'1',
|
|
'{$rows[0]['M_PatientNIK']}',
|
|
'{$pnote}',
|
|
$userID
|
|
)";
|
|
$qry = $this->db_onedev->query($query);
|
|
$patientID = 0;
|
|
if ($qry ) {
|
|
$patientID = $this->db_onedev->insert_id();
|
|
}
|
|
// echo $this->db_onedev->last_query();
|
|
//
|
|
$sql = "select M_CompanyAddress,
|
|
M_CompanyM_KelurahanID
|
|
from m_company
|
|
where M_CompanyID = ?";
|
|
$qry = $this->db->query($sql, array($com_id));
|
|
$rows = $qry->result_array();
|
|
$sql = "insert into m_patientaddress(M_PatientAddressM_PatientID, M_PatientAddressNote,
|
|
M_PatientAddressDescription,M_PatientAddressLocation,M_PatientAddressM_KelurahanID)
|
|
values(?,?, ?,?,?) ";
|
|
$this->db_onedev->query($sql,array($patientID,'KANTOR',$rows[0]['M_CompanyAddress'],$rows[0]['M_CompanyAddress'],
|
|
$rows[0]['M_CompanyM_KelurahanID']));
|
|
return $patientID;
|
|
}
|
|
|
|
|
|
|
|
|
|
function fo_verify($orderID,$userID) {
|
|
$sql="INSERT INTO fo_verificationsvalue (
|
|
Fo_VerificationsValueT_OrderHeaderID,
|
|
Fo_VerificationsValueFo_VerificationsLabelID,
|
|
Fo_VerificationsValueCheck,
|
|
Fo_VerificationsValueNote,
|
|
Fo_VerificationsValueUserID,
|
|
Fo_VerificationsValueCreated )
|
|
SELECT {$orderID},
|
|
Fo_VerificationsLabelID,
|
|
'Y',
|
|
'', {$userID},
|
|
NOW()
|
|
FROM fo_verificationslabel
|
|
WHERE
|
|
Fo_VerificationsLabelIsActive = 'Y' ";
|
|
$this->db_onedev->query($sql);
|
|
|
|
$sql = "call sp_fo_barcode_generate({$orderID})";
|
|
$this->db_onedev->query($sql);
|
|
|
|
$fostatusid = 3;
|
|
$fologcode = 'FO.VERIFICATION.CONFIRM';
|
|
|
|
$sql = "insert into fo_status(
|
|
Fo_StatusDate,
|
|
Fo_StatusT_OrderHeaderID,
|
|
Fo_StatusM_StatusID,
|
|
Fo_StatusM_UserID,
|
|
Fo_StatusCreated,
|
|
Fo_StatusUpdated)
|
|
values( now(), ?, ?, ?, now(),now())";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$orderID,
|
|
$fostatusid, $userID
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
return "Error Fo Status";
|
|
}
|
|
|
|
$sql = "SELECT * FROM fo_verificationsvalue WHERE Fo_VerificationsValueT_OrderHeaderID = {$orderID}";
|
|
|
|
$data_log = array();
|
|
$data_log['orderid'] = $orderID;
|
|
$data_log['values'] = $this->db_onedev->query($sql)->result_array();
|
|
$data_log['note'] = '';
|
|
|
|
$json_dt_log = json_encode($data_log);
|
|
$sql = "insert into one_log.log_fo(
|
|
Log_FoDate,
|
|
Log_FoCode,
|
|
Log_FoJson,
|
|
Log_FoUserID)
|
|
values( now(), ?, ?, ?)";
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$fologcode,
|
|
$json_dt_log,
|
|
$userID
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
return "Error Fo Log";
|
|
}
|
|
|
|
/* T_OrderSample */
|
|
$adminUserID = $userID;
|
|
$sql = "update t_ordersample
|
|
set T_OrderSampleSampling='Y', T_OrderSampleSamplingDate = now(),
|
|
T_OrderSampleSamplingTime = now(),T_OrderSampleSamplingUserID = $adminUserID,
|
|
T_OrderSampleReceive='Y', T_OrderSampleReceiveDate = now() , T_OrderSampleReceiveTime = now(),
|
|
T_OrderSampleReceiveUserID = $adminUserID,
|
|
T_OrderSampleVerification='Y', T_OrderSampleVerificationDate=now(), T_OrderSampleVerificationTime=now(),
|
|
T_OrderSampleVerificationUserID = $adminUserID,
|
|
T_OrderSampleSendHandling = 'Y', T_OrderSampleSendHandlingDate =now(), T_OrderSampleSendHandlingTime=now(),
|
|
T_OrderSampleSendHandlingUserID = $adminUserID,
|
|
T_OrderSampleReceiveHandling = 'Y', T_OrderSampleReceiveHandlingDate=now(), T_OrderSampleReceiveHandlingTime=now(),
|
|
T_OrderSampleReceiveHandlingUserID=$adminUserID,
|
|
T_OrderSampleHandling='Y', T_OrderSampleHandlingDate=now(), T_OrderSampleHandlingTime=now(),
|
|
T_OrderSampleHandlingUserID=$adminUserID,
|
|
T_OrderSampleProcessing='Y', T_OrderSampleReadyToProcessDateTime=now(), T_OrderSampleProcessingDate=now(),
|
|
T_OrderSampleProcessingTime=now(), T_OrderSampleProcessingUserID=$adminUserID,
|
|
T_OrderSampleUserID=$adminUserID
|
|
where T_OrderSampleT_OrderHeaderID = ?";
|
|
|
|
|
|
$qry = $this->db_onedev->query($sql, array($orderID) );
|
|
if (!$qry) {
|
|
return "Error T_OrderSample : " . $this->db_onedev->last_query();
|
|
}
|
|
return "OK";
|
|
}
|
|
|
|
|
|
|
|
}
|