863 lines
34 KiB
PHP
863 lines
34 KiB
PHP
<?php
|
|
class Mcu_offline_uploader extends MY_Controller {
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->debug = true;
|
|
$this->response = array("status" => "ERR",
|
|
"message" => "" );
|
|
}
|
|
function reply() {
|
|
if($this->debug) {
|
|
echo json_encode($this->response);
|
|
} else {
|
|
echo gzdeflate(json_encode($this->response),9);
|
|
}
|
|
exit;
|
|
}
|
|
function get_one_result($qry,$info = "",$allow_no_result = true) {
|
|
if (!$qry) {
|
|
$this->response["message"] = "Err $info : " . $this->db->error()["message"] . "\n" .
|
|
$this->db->last_query();
|
|
$this->reply();
|
|
}
|
|
$rows = $qry->result_array();
|
|
if(count($rows) == 0 && ! $allow_no_result) {
|
|
$this->response["message"] = "Err $info : No Record " . "\n" .
|
|
$this->db->last_query();
|
|
$this->reply();
|
|
}
|
|
return $rows[0];
|
|
}
|
|
function get_all_result($qry,$info = "",$allow_no_result = true) {
|
|
if (!$qry) {
|
|
$this->response["message"] = "Err $info : " . $this->db->error()["message"] . "\n" .
|
|
$this->db->last_query();
|
|
$this->reply();
|
|
}
|
|
$rows = $qry->result_array();
|
|
if(count($rows) == 0 && ! $allow_no_result) {
|
|
$this->response["message"] = "Err $info : No Record " . "\n" .
|
|
$this->db->last_query();
|
|
$this->reply();
|
|
}
|
|
return $rows;
|
|
}
|
|
function add_unique($target,$source,$id) {
|
|
$arr_target = array();
|
|
foreach($target as $t) {
|
|
$arr_target[] = $t[$id];
|
|
}
|
|
foreach($source as $s) {
|
|
if (! in_array($s[$id], $arr_target)) {
|
|
$target[] = $s;
|
|
}
|
|
}
|
|
return $target;
|
|
}
|
|
//---
|
|
function get_orderheader($orderID) {
|
|
$sql = "select *
|
|
from t_orderheader
|
|
where T_OrderHeaderID = ?";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_one_result($qry,"t_orderheader",false);
|
|
}
|
|
function get_doctor($order) {
|
|
$pjID = $order["T_OrderHeaderPjM_DoctorID"];
|
|
$senderID = $order["T_OrderHeaderSenderM_DoctorID"];
|
|
$senderAddressID = $order["T_OrderHeaderSenderM_DoctorAddressID"];
|
|
|
|
$sql = "select * from m_doctor where M_DoctorID = ?";
|
|
$qry = $this->db->query($sql, array($pjID));
|
|
$doctor_pj = $this->get_one_result($qry,"doctor PJ",false);
|
|
|
|
$sql = "select * from m_doctor where M_DoctorID = ?";
|
|
$qry = $this->db->query($sql, array($senderID));
|
|
$doctor_sender = $this->get_one_result($qry,"Doctor Sender",false);
|
|
|
|
$sql = "select * from m_doctoraddress where M_DoctorAddressID = ?";
|
|
$qry = $this->db->query($sql, array($senderAddressID));
|
|
$address_sender = $this->get_one_result($qry,"Sender Address",false);
|
|
|
|
$sql = "select * from m_doctoraddress where M_DoctorAddressM_DoctorID = ?
|
|
and M_DoctorAddressIsActive='Y' order by M_DoctorAddressID limit 0,1";
|
|
$qry = $this->db->query($sql, array($pjID));
|
|
$address_pj = $this->get_one_result($qry,"PJ Address",false);
|
|
|
|
return array(
|
|
"sender" => $doctor_sender,
|
|
"sender_address" => $address_sender,
|
|
"pj" => $doctor_sender,
|
|
"pj_address" => $address_pj
|
|
);
|
|
}
|
|
function get_patient($order) {
|
|
$patientID = $order["T_OrderHeaderM_PatientID"];
|
|
|
|
$sql = "select * from m_patient where M_PatientID = ?";
|
|
$qry = $this->db->query($sql, array($patientID));
|
|
$patient = $this->get_one_result($qry,"m_patient",false);
|
|
return $patient;
|
|
}
|
|
function last_statuspayment($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
// log -5 menit | orderdate | 5 menit
|
|
$sql = "select *
|
|
from last_statuspayment
|
|
where Last_StatusPaymentT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"last_statuspayment");
|
|
}
|
|
function fo_status($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
// log -5 menit | orderdate | 5 menit
|
|
$sql = "select *
|
|
from fo_status
|
|
where Fo_StatusT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"fo_status");
|
|
}
|
|
function last_status($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
// log -5 menit | orderdate | 5 menit
|
|
$sql = "select *
|
|
from last_status
|
|
where Last_StatusT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"last_status");
|
|
}
|
|
function t_orderheaderaddon($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from t_orderheaderaddon
|
|
where T_OrderHeaderAddOnT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_one_result($qry,"t_orderheaderaddon",false);
|
|
}
|
|
function t_orderdelivery($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from t_orderdelivery
|
|
where T_OrderDeliveryT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_orderdelivery");
|
|
}
|
|
function t_orderdetail($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from t_orderdetail
|
|
where T_OrderDetailT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_orderdetail");
|
|
}
|
|
function t_orderdetailaddon($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select t_orderdetailaddon.*
|
|
from t_orderdetailaddon
|
|
join t_orderdetail on T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID
|
|
where T_OrderDetailT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_orderdetailaddon");
|
|
}
|
|
function t_orderreq($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select t_orderreq.*
|
|
from t_orderreq
|
|
where T_OrderReqT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_orderreq");
|
|
}
|
|
function t_orderpromise($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select t_orderpromise.*
|
|
from t_orderpromise
|
|
where T_OrderPromiseT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_orderpromise");
|
|
}
|
|
function order_log($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from order_log
|
|
where OrderLogT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"order_log");
|
|
}
|
|
function f_payment($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from f_payment
|
|
where F_PaymentT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"f_payment");
|
|
}
|
|
function f_payment_test($payments) {
|
|
$res = array();
|
|
foreach($payments as $payment) {
|
|
$paymentID = $payment["F_PaymentID"];
|
|
$sql = "select *
|
|
from f_payment_test
|
|
where F_Payment_TestF_PaymentID=? ";
|
|
$qry = $this->db->query($sql, array($paymentID));
|
|
$rows = $this->get_all_result($qry,"f_payment_test");
|
|
$res = array_merge($res,$rows);
|
|
}
|
|
return $res;
|
|
}
|
|
function f_payment_orderheader($payments) {
|
|
$res = array();
|
|
foreach($payments as $payment) {
|
|
$paymentID = $payment["F_PaymentID"];
|
|
$sql = "select *
|
|
from f_payment_orderheader
|
|
where F_Payment_OrderHeaderF_PaymentID=? ";
|
|
$qry = $this->db->query($sql, array($paymentID));
|
|
$rows = $this->get_all_result($qry,"f_payment_orderheader");
|
|
$res = array_merge($res,$rows);
|
|
}
|
|
return $res;
|
|
}
|
|
function f_payment_detail($payments) {
|
|
$res = array();
|
|
foreach($payments as $payment) {
|
|
$paymentID = $payment["F_PaymentID"];
|
|
$sql = "select *
|
|
from f_paymentdetail
|
|
where F_PaymentDetailF_PaymentID=? ";
|
|
$qry = $this->db->query($sql, array($paymentID));
|
|
$rows = $this->get_all_result($qry,"f_paymentdetail");
|
|
|
|
$res = array_merge($res,$rows);
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
// ---------- FO VERIFY
|
|
function fo_verificationsvalue($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from fo_verificationsvalue
|
|
where Fo_VerificationsValueT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"fo_verificationsvalue");
|
|
}
|
|
function t_ordermessage($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from t_ordermessage
|
|
where T_OrderMessageT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_ordermessage");
|
|
}
|
|
|
|
function cr_order($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from cr_order
|
|
where crOrderT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"cr_order");
|
|
}
|
|
function t_barcodelab($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from t_barcodelab
|
|
where T_BarcodeLabT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_barcodelab");
|
|
}
|
|
function t_ordersample($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from t_ordersample
|
|
where T_OrderSampleT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_ordersample");
|
|
}
|
|
function last_statussample($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from last_statussample
|
|
where Last_StatusSampleT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"last_statussample");
|
|
}
|
|
function sample_by_step($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from sample_by_step
|
|
where SampleByStepT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"sample_by_step");
|
|
}
|
|
function helper_sst($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from helper_sst
|
|
where Helper_SstT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"helper_sst");
|
|
}
|
|
function t_sampling_queue_last_status($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from t_sampling_queue_last_status
|
|
where T_SamplingQueueLastStatusT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_sampling_queue_last_status");
|
|
}
|
|
function t_sampling_queue_by_action($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from t_sampling_queue_by_action
|
|
where T_SamplingQueueByActionT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_sampling_queue_by_action");
|
|
}
|
|
function helper_bahan($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from helper_bahan
|
|
where Helper_BahanT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"helper_bahan");
|
|
}
|
|
function t_ordersamplereq($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from t_ordersamplereq
|
|
where T_OrderSampleReqT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_ordersamplereq");
|
|
}
|
|
function t_samplingso($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from t_samplingso
|
|
where T_SamplingSoT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_samplingso");
|
|
}
|
|
function sample_so_by_step($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from sample_so_by_step
|
|
where SampleSoByStepT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"sample_so_by_step");
|
|
}
|
|
function so_resultentry($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from so_resultentry
|
|
where So_ResultEntryT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"so_resultentry");
|
|
}
|
|
function so_resultentrydetail($so_result_entry) {
|
|
$ids = "-1";
|
|
foreach($so_result_entry as $s) {
|
|
$ids .= ", " . $s["So_ResultEntryID"];
|
|
}
|
|
$sql = "select *
|
|
from so_resultentrydetail
|
|
where So_ResultEntryDetailSo_ResultEntryID in ($ids) ";
|
|
$qry = $this->db->query($sql);
|
|
return $this->get_all_result($qry,"so_resultentrydetail");
|
|
}
|
|
function t_samplingso_requirement($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from t_samplingso_requirement
|
|
where T_SamplingSoRequirementT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_samplingso_requirement");
|
|
}
|
|
function t_samplingso_form($sampling_so) {
|
|
$ids = "-1";
|
|
foreach($sampling_so as $s) {
|
|
$ids .= ", " . $s["T_SamplingSoID"];
|
|
}
|
|
$sql = "select *
|
|
from t_samplingso_form
|
|
where T_SamplingSoFormT_SamplingSOID in ($ids) ";
|
|
$qry = $this->db->query($sql);
|
|
return $this->get_all_result($qry,"t_samplingso_form");
|
|
}
|
|
function t_samplingso_film($sampling_so) {
|
|
$ids = "-1";
|
|
foreach($sampling_so as $s) {
|
|
$ids .= ", " . $s["T_SamplingSoID"];
|
|
}
|
|
$sql = "select *
|
|
from t_samplingso_film
|
|
where T_SamplingSoFilmT_SamplingSoID in ($ids) ";
|
|
$qry = $this->db->query($sql);
|
|
return $this->get_all_result($qry,"t_samplingso_film");
|
|
}
|
|
function snap_doctor_fee($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from snap_doctor_fee
|
|
where SnapDoctorFeeT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"snap_doctor_fee");
|
|
}
|
|
function result_verifications_value($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from result_verifications_value
|
|
where Result_VerificationsValueT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"result_verifications_value");
|
|
}
|
|
function result_verification_by_step($result_verification) {
|
|
$ids = "-1";
|
|
foreach($result_verification as $s) {
|
|
$ids .= ", " . $s["Result_VerificationsValueID"];
|
|
}
|
|
$sql = "select *
|
|
from result_verification_by_step
|
|
where Result_VerificationByStepResult_VerificationsValueID in ($ids) ";
|
|
$qry = $this->db->query($sql);
|
|
return $this->get_all_result($qry,"result_verification_by_step");
|
|
}
|
|
function pre_analytic($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$orderDate = substr($order["T_OrderHeaderDate"],0,10); // yyyy-mm-dd
|
|
$sql = "select pre_analytic.*
|
|
from t_orderdetail
|
|
join t_test
|
|
on T_OrderDetailT_OrderHeaderID = ?
|
|
and T_TestID = T_OrderDetailT_TestID
|
|
join pre_analytic
|
|
on PreAnalyticDate=?
|
|
and PreAnalyticNat_TestID = T_TestNat_TestID
|
|
";
|
|
$qry = $this->db->query($sql, array($orderID,$orderDate));
|
|
return $this->get_all_result($qry,"pre_analytic");
|
|
}
|
|
function t_worklist_confirm($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from t_worklist_confirm
|
|
where T_WorklistConfirmT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"t_worklist_confirm");
|
|
}
|
|
|
|
// ---------- ONE LOG
|
|
function get_log_patient($order) {
|
|
$patientID = $order["T_OrderHeaderM_PatientID"];
|
|
$date = $order["T_OrderHeaderDate"];
|
|
$sql = "select *
|
|
from one_log.log_patient
|
|
where Log_PatientDate >= ? - interval 35 minute and Log_PatientDate <= ? + interval 35 minute ";
|
|
$qry = $this->db->query($sql, array($date, $date));
|
|
$rows = $this->get_all_result($qry,"one_log.log_patient");
|
|
$res = array();
|
|
|
|
foreach($rows as $r) {
|
|
$jpas = json_decode($r["Log_PatientJson"],true);
|
|
if ($jpas["M_PatientID"] == $patientID) {
|
|
$res[] = $r;
|
|
}
|
|
}
|
|
return $res;
|
|
}
|
|
function log_fo_status($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from one_log.log_fostatus
|
|
where Log_FoStatusT_OrderHeaderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"log_fo_status");
|
|
}
|
|
function log_px($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from one_log.log_px
|
|
where Log_PxOrderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"log_px");
|
|
}
|
|
function log_fo($orderID,$date) {
|
|
$sql = "select *
|
|
from one_log.log_fo
|
|
where Log_FoDate >= ? - interval 35 minute and Log_FoDate <= ? + interval 35 minute ";
|
|
$qry = $this->db->query($sql, array($date, $date));
|
|
$rows = $this->get_all_result($qry,"one_log.log_fo");
|
|
$res = array();
|
|
foreach($rows as $r) {
|
|
$jpas = json_decode($r["Log_FoJson"],true);
|
|
if ($jpas["order_id"] == $orderID) {
|
|
$res[] = $r;
|
|
}
|
|
}
|
|
return $res;
|
|
}
|
|
function log_payment($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from one_log.log_payment
|
|
where Log_PaymentOrderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"log_payment");
|
|
}
|
|
function log_sample($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from one_log.log_sample
|
|
where Log_SampleOrderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"log_sample");
|
|
}
|
|
function log_sample_order($samples) {
|
|
$barcodes = array();
|
|
$minDate = "";
|
|
$maxDate = "";
|
|
foreach($samples as $sample) {
|
|
if ($minDate == "") {
|
|
$minDate = $sample["Log_SampleDate"];
|
|
} else {
|
|
if ($minDate > $sample["Log_SampleDate"]) $minDate = $sample["Log_SampleDate"];
|
|
}
|
|
if ($maxDate == "") {
|
|
$maxDate = $sample["Log_SampleDate"];
|
|
} else {
|
|
if ($maxDate < $sample["Log_SampleDate"]) $maxDate = $sample["Log_SampleDate"];
|
|
}
|
|
$barcodes[] = $sample["Log_SampleBarcode"];
|
|
}
|
|
|
|
if (count($barcodes) > 0) {
|
|
$sql = "select *
|
|
from one_log.log_sample_order
|
|
where Log_sampleOrderDate >= ? - interval 30 minute and Log_sampleOrderDate <= ? + interval 30 minute ";
|
|
$qry = $this->db->query($sql, array($minDate,$maxDate));
|
|
$rows = $this->get_all_result($qry,"log_sample_order");
|
|
$result = array();
|
|
foreach($rows as $r) {
|
|
$json = json_decode($r["Log_sampleOrderJson"],true);
|
|
if (in_array($json["barcode_number"],$barcodes)) {
|
|
$result[] = $r;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
return [];
|
|
}
|
|
function log_sampling_queue($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from one_log.log_sampling_queue
|
|
where Log_SamplingQueueOrderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"log_sampling_queue");
|
|
}
|
|
function log_sample_req($orderID, $samples) {
|
|
$barcodes = array();
|
|
$minDate = "";
|
|
$maxDate = "";
|
|
foreach($samples as $sample) {
|
|
if ($minDate == "") {
|
|
$minDate = $sample["Log_SampleDate"];
|
|
} else {
|
|
if ($minDate > $sample["Log_SampleDate"]) $minDate = $sample["Log_SampleDate"];
|
|
}
|
|
if ($maxDate == "") {
|
|
$maxDate = $sample["Log_SampleDate"];
|
|
} else {
|
|
if ($maxDate < $sample["Log_SampleDate"]) $maxDate = $sample["Log_SampleDate"];
|
|
}
|
|
|
|
}
|
|
|
|
if ($minDate != "" && $maxDate != "") {
|
|
$sql = "select *
|
|
from one_log.log_sample_req
|
|
where Log_SampleReqDate >= ? - interval 30 minute and Log_SampleReqDate <= ? + interval 30 minute ";
|
|
$qry = $this->db->query($sql, array($minDate,$maxDate));
|
|
$rows = $this->get_all_result($qry,"log_sample_req");
|
|
$result = array();
|
|
foreach($rows as $r) {
|
|
$json = json_decode($r["Log_SampleReqJson"],true);
|
|
if ($orderID == $json["order_id"]) {
|
|
$result[] = $r;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
return [];
|
|
}
|
|
function log_resultentry_so($so_result_entry) {
|
|
$barcodes = array();
|
|
$minDate = "";
|
|
$maxDate = "";
|
|
$so_ids = array();
|
|
foreach($so_result_entry as $so) {
|
|
if ($minDate == "") {
|
|
$minDate = $so["So_ResultEntryCreated"];
|
|
} else {
|
|
if ($minDate > $so["So_ResultEntryCreated"]) $minDate = $so["So_ResultEntryCreated"];
|
|
}
|
|
if ($maxDate == "") {
|
|
$maxDate = $so["So_ResultEntryCreated"];
|
|
} else {
|
|
if ($maxDate < $so["So_ResultEntryCreated"]) $maxDate = $so["So_ResultEntryCreated"];
|
|
}
|
|
$so_ids[] = $so["So_ResultEntryID"];
|
|
}
|
|
|
|
if ($minDate != "" && $maxDate != "") {
|
|
$sql = "select *
|
|
from one_log.log_resultentry_so
|
|
where Log_ResultEntrySoDate >= ? - interval 30 minute
|
|
and Log_ResultEntrySoDate <= ? + interval 30 minute ";
|
|
$qry = $this->db->query($sql, array($minDate,$maxDate));
|
|
$rows = $this->get_all_result($qry,"log_resultentry_so");
|
|
$result = array();
|
|
foreach($rows as $r) {
|
|
$json = json_decode($r["Log_ResultEntrySoJSON"],true);
|
|
if ( in_array($json["order_id"],$so_ids)) {
|
|
$result[] = $r;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
return [];
|
|
}
|
|
function log_result_verifications_value($orderID, $result_verification) {
|
|
$barcodes = array();
|
|
$minDate = "";
|
|
$maxDate = "";
|
|
foreach($result_verification as $sample) {
|
|
if ($minDate == "") {
|
|
$minDate = $sample["Result_VerificationByStepDateTime"];
|
|
} else {
|
|
if ($minDate > $sample["Result_VerificationByStepDateTime"]) $minDate = $sample["Result_VerificationByStepDateTime"];
|
|
}
|
|
if ($maxDate == "") {
|
|
$maxDate = $sample["Result_VerificationByStepDateTime"];
|
|
} else {
|
|
if ($maxDate < $sample["Result_VerificationByStepDateTime"]) $maxDate = $sample["Result_VerificationByStepDateTime"];
|
|
}
|
|
|
|
}
|
|
|
|
if ($minDate != "" && $maxDate != "") {
|
|
$sql = "select *
|
|
from one_log.log_result_verifications_value
|
|
where Result_VerificationByStepDateTime >= ? - interval 30 minute and Result_VerificationByStepDateTime <= ? + interval 30 minute ";
|
|
$qry = $this->db->query($sql, array($minDate,$maxDate));
|
|
$rows = $this->get_all_result($qry,"log_result_verifications_value");
|
|
$result = array();
|
|
foreach($rows as $r) {
|
|
$json = json_decode($r["Log_ResultVerificationsValueJson"],true);
|
|
if ($orderID == $json["Result_VerificationsValueT_OrderHeaderID"]) {
|
|
$result[] = $r;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
return [];
|
|
}
|
|
function log_worklist($pre_analytic) {
|
|
$preDate = "";
|
|
foreach($pre_analytic as $pre) {
|
|
$preDate = $pre["PreAnalyticDate"];
|
|
|
|
}
|
|
|
|
if ($preDate != "") {
|
|
$sql = "select *
|
|
from one_log.log_worklist
|
|
where
|
|
date(Log_WorklistDate) =?
|
|
and Log_WorklistCode = 'PRE.ANALYTIC' ";
|
|
$qry = $this->db->query($sql, array($preDate));
|
|
$rows = $this->get_all_result($qry,"log_worklist");
|
|
$result = array();
|
|
$natTestID = $pre["PreAnalyticNat_TestID"];
|
|
foreach($rows as $r) {
|
|
$json = json_decode($r["Log_WorklistJson"],true);
|
|
if ($natTestID == $json["T_TestID"]) {
|
|
$result[] = $r;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
return [];
|
|
}
|
|
function log_worklist_conf($t_worklistconf) {
|
|
$preDate = "";
|
|
foreach($t_worklistconf as $pre) {
|
|
$preDate = substr($pre["T_WorklistConfirmCreated"],0,10);
|
|
|
|
}
|
|
|
|
if ($preDate != "") {
|
|
$sql = "select *
|
|
from one_log.log_worklist
|
|
where
|
|
date(Log_WorklistDate) = ?
|
|
and Log_WorklistCode = 'PRE.ANALYTIC.CONF' ";
|
|
$qry = $this->db->query($sql, array($preDate));
|
|
$rows = $this->get_all_result($qry,"log_worklist");
|
|
$result = array();
|
|
$orderID = $pre["T_WorklistConfirmT_OrderHeaderID"];
|
|
foreach($rows as $r) {
|
|
$json = json_decode($r["Log_WorklistJson"],true);
|
|
if ($orderID == $json["T_OrderHeaderID"]) {
|
|
$result[] = $r;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
return [];
|
|
}
|
|
function log_worklist_rcv($t_worklistconf) {
|
|
$preDate = "";
|
|
foreach($t_worklistconf as $pre) {
|
|
$preDate = substr($pre["T_WorklistConfirmCreated"],0,10);
|
|
|
|
}
|
|
|
|
if ($preDate != "") {
|
|
$sql = "select *
|
|
from one_log.log_worklist
|
|
where
|
|
date(Log_WorklistDate) = ?
|
|
and Log_WorklistCode = 'RECEIVE' ";
|
|
$qry = $this->db->query($sql, array($preDate));
|
|
$rows = $this->get_all_result($qry,"log_worklist");
|
|
$result = array();
|
|
$orderID = $pre["T_WorklistConfirmT_OrderHeaderID"];
|
|
foreach($rows as $r) {
|
|
$json = json_decode($r["Log_WorklistJson"],true);
|
|
if ($orderID == $json["T_OrderHeaderID"]) {
|
|
$result[] = $r;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
return [];
|
|
}
|
|
function log_process($order) {
|
|
$orderID = $order["T_OrderHeaderID"];
|
|
$sql = "select *
|
|
from one_log.log_process
|
|
where Log_ProcessOrderID=? ";
|
|
$qry = $this->db->query($sql, array($orderID));
|
|
return $this->get_all_result($qry,"log_process");
|
|
}
|
|
|
|
function get_order($headerID) {
|
|
//t_orderheader
|
|
$this->db->trans_begin();
|
|
|
|
$result = array();
|
|
//--- FO
|
|
$order_header = $this->get_orderheader($headerID);
|
|
$result["order_header"] = $order_header;
|
|
$result["dokter"] = $this->get_doctor($order_header);
|
|
$result["patient"] = $this->get_patient($order_header);
|
|
$result["log_patient"] = $this->get_log_patient($order_header);
|
|
$result["last_status_payment"] = $this->last_statuspayment($order_header);
|
|
$result["fo_status"] = $this->fo_status($order_header);
|
|
$result["last_status"] = $this->last_status($order_header);
|
|
$result["log_fo_status"] = $this->log_fo_status($order_header);
|
|
$result["log_fo"] = $this->log_fo($headerID, $order_header["T_OrderHeaderDate"]);
|
|
$result["t_orderheaderaddon"] = $this->t_orderheaderaddon($order_header);
|
|
$result["t_orderdelivery"] = $this->t_orderdelivery($order_header);
|
|
$result["t_orderdetail"] = $this->t_orderdetail($order_header);
|
|
$result["t_orderdetailaddon"] = $this->t_orderdetailaddon($order_header);
|
|
$result["t_orderreq"] = $this->t_orderreq($order_header);
|
|
$result["t_orderpromise"] = $this->t_orderpromise($order_header);
|
|
$result["log_px"] = $this->log_px($order_header);
|
|
$result["order_log"] = $this->order_log($order_header);
|
|
|
|
//--- Payment
|
|
$result["f_payment"] = $this->f_payment($order_header);
|
|
$payments = $result["f_payment"];
|
|
$result["f_payment_test"] = $this->f_payment_test($payments);
|
|
$result["f_payment_orderheader"] = $this->f_payment_orderheader($payments);
|
|
$result["f_payment_detail"] = $this->f_payment_detail($payments);
|
|
if (count($payments) > 0 ) {
|
|
$paymentDate = $payments[0]["F_PaymentDate"];
|
|
$rows = $this->log_fo($headerID,$paymentDate);
|
|
$this->add_unique($result["log_fo"],$rows,"Log_FoID");
|
|
}
|
|
$result["log_payment"] = $this->log_payment($order_header);
|
|
|
|
//-- FO Verify
|
|
$result["fo_verificationsvalue"] = $this->fo_verificationsvalue($order_header);
|
|
$result["t_ordermessage"] = $this->t_ordermessage($order_header);
|
|
|
|
//-- Specimen Collection
|
|
$result["cr_order"] = $this->cr_order($order_header);
|
|
$result["t_barcodelab"] = $this->t_barcodelab($order_header);
|
|
$result["t_ordersample"] = $this->t_ordersample($order_header);
|
|
$result["log_sample"] = $this->log_sample($order_header);
|
|
$result["log_sample_order"] = $this->log_sample_order($result["log_sample"]);
|
|
$result["last_statussample"] = $this->last_statussample($order_header);
|
|
$result["sample_by_step"] = $this->sample_by_step($order_header);
|
|
$result["helper_sst"] = $this->helper_sst($order_header);
|
|
$result["t_sampling_queue_last_status"] = $this->t_sampling_queue_last_status($order_header);
|
|
$result["t_sampling_queue_by_action"] = $this->t_sampling_queue_by_action($order_header);
|
|
$result["helper_bahan"] = $this->helper_bahan($order_header);
|
|
$result["last_statussample"] = $this->last_statussample($order_header);
|
|
$result["t_ordersamplereq"] = $this->t_ordersamplereq($order_header);
|
|
$result["log_sampling_queue"] = $this->log_sampling_queue($order_header);
|
|
|
|
//-- Spec Verif
|
|
$result["log_sample_req"] = $this->log_sample_req($headerID,$result["log_sample"]);
|
|
|
|
//-- Spec Handling
|
|
//-- Rad Patient Handling
|
|
$result["t_samplingso"] = $this->t_samplingso($order_header);
|
|
$result["sample_so_by_step"] = $this->sample_so_by_step($order_header);
|
|
$result["so_resultentry"] = $this->so_resultentry($order_header);
|
|
$so_result_entry = $result["so_resultentry"];
|
|
$result["so_resultentrydetail"] = $this->so_resultentrydetail($so_result_entry);
|
|
$result["t_samplingso_requirement"] = $this->t_samplingso_requirement($order_header);
|
|
|
|
$sampling_so = $result["t_samplingso"];
|
|
$result["t_samplingso_form"] = $this->t_samplingso_form($sampling_so);
|
|
$result["t_samplingso_film"] = $this->t_samplingso_film($sampling_so);
|
|
|
|
//-- Rad Image Verify
|
|
//-- Rad Image Handling
|
|
$result["snap_doctor_fee"] = $this->snap_doctor_fee($order_header);
|
|
|
|
//-- Rad Dokumentasi Hasil
|
|
$result["log_resultentry_so"] = $this->log_resultentry_so($so_result_entry);
|
|
|
|
//-- RAD Verifikasi Hasil
|
|
$result["result_verifications_value"] = $this->result_verifications_value($order_header);
|
|
$result_verification = $result["result_verifications_value"] ;
|
|
$result["result_verification_by_step"] = $this->result_verification_by_step($result_verification);
|
|
$result["log_result_verifications_value"] = $this->log_result_verifications_value($headerID,$result_verification);
|
|
|
|
//-- Worklist
|
|
$result["pre_analytic"] = $this->pre_analytic($order_header);
|
|
$pre_analytic = $result["pre_analytic"];
|
|
$result["log_worklist"] = $this->log_worklist($pre_analytic);
|
|
$result["t_worklist_confirm"] = $this->t_worklist_confirm($order_header);
|
|
|
|
$worklist_conf = $this->log_worklist_conf($result["t_worklist_confirm"]);
|
|
$result["log_worklist"] = array_merge($result["log_worklist"], $worklist_conf);
|
|
|
|
$worklist_rcv = $this->log_worklist_rcv($result["t_worklist_confirm"]);
|
|
$result["log_worklist"] = array_merge($result["log_worklist"], $worklist_rcv);
|
|
|
|
//result entry
|
|
$result["log_process"] = $this->log_process($order_header);
|
|
|
|
|
|
$this->response["status"] = "OK";
|
|
$this->response["result"] = $result;
|
|
$this->reply();
|
|
}
|
|
} |