235 lines
9.4 KiB
PHP
235 lines
9.4 KiB
PHP
<?php
|
|
class Getorder extends MY_Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
// db wilayah contoh surabaya
|
|
// $this->db = $this->load->database("regional", true);
|
|
|
|
// string database
|
|
$this->db_str_doctor = 'one_doctor';
|
|
$this->M_MouM_CompanyID = "1235";
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
echo "GET RESULT";
|
|
}
|
|
|
|
public function getdata()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
$limit = 10;
|
|
if (isset($prm['limit'])) {
|
|
$limit = trim($prm["limit"]);
|
|
$limit = $prm['limit'];
|
|
}
|
|
$sql = "SELECT
|
|
T_OrderHeaderID,
|
|
T_OrderHeaderLabNumber as no_reg,
|
|
T_OrderHeaderDate,
|
|
concat(M_TitleName, ' ',
|
|
ifnull(M_PatientPrefix,' '),
|
|
M_PatientName,
|
|
ifnull(M_PatientSuffix,'')
|
|
) as nama_pasien,
|
|
'' as test,
|
|
M_PatientIDNumber,
|
|
M_PatientHP,
|
|
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
|
OneResultConfirmRetry
|
|
from t_orderheader
|
|
join t_orderdetail
|
|
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
AND T_OrderHeaderIsActive = 'Y'
|
|
join m_mou
|
|
ON T_OrderHeaderM_MouID = M_MouID
|
|
AND M_MouIsActive = 'Y'
|
|
-- AND M_MouIsReleased = 'Y'
|
|
AND M_MouIsBill = 'Y'
|
|
left join one_result_confirm
|
|
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
|
AND OneResultConfirmIsActive = 'Y'
|
|
join m_patient
|
|
ON T_OrderHeaderM_PatientID = M_PatientID
|
|
AND (M_PatientIDNumber <> '' AND M_PatientIDNumber IS NOT NULL)
|
|
AND (M_PatientHP <> '' AND M_PatientHP IS NOT NULL AND M_PatientHP <> '-')
|
|
join m_title
|
|
on M_PatientM_TitleID = M_TitleID
|
|
join t_orderdelivery on T_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID and T_OrderDeliveryIsActive = 'Y'
|
|
join m_deliverytype
|
|
ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID
|
|
AND M_DeliveryTypeCode = 'ERESULT'
|
|
WHERE (OneResultConfirmStatus = 'C' OR OneResultConfirmStatus = 'R' OR OneResultConfirmStatus = 'E') AND OneResultConfirmRetry <= 5
|
|
group by T_OrderHeaderID
|
|
|
|
UNION
|
|
|
|
select
|
|
T_OrderHeaderID,
|
|
T_OrderHeaderLabNumber as no_reg,
|
|
T_OrderHeaderDate,
|
|
concat(M_TitleName, ' ',
|
|
ifnull(M_PatientPrefix,' '),
|
|
M_PatientName,
|
|
ifnull(M_PatientSuffix,'')
|
|
) as nama_pasien,
|
|
'' as test,
|
|
M_PatientIDNumber,
|
|
M_PatientHP,
|
|
IFNULL(OneResultConfirmStatus,'-') as OneResultConfirmStatus,
|
|
OneResultConfirmRetry
|
|
from t_orderheader
|
|
join t_orderdetail
|
|
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
AND T_OrderHeaderIsActive = 'Y'
|
|
join m_mou
|
|
ON T_OrderHeaderM_MouID = M_MouID
|
|
AND M_MouIsActive = 'Y'
|
|
-- AND M_MouIsReleased = 'Y'
|
|
left join one_result_confirm
|
|
ON T_OrderHeaderID = OneResultConfirmT_OrderHeaderID
|
|
AND OneResultConfirmIsActive = 'Y'
|
|
join m_patient
|
|
ON T_OrderHeaderM_PatientID = M_PatientID
|
|
AND (M_PatientIDNumber <> '' AND M_PatientIDNumber IS NOT NULL)
|
|
AND (M_PatientHP <> '' AND M_PatientHP IS NOT NULL AND M_PatientHP <> '-')
|
|
join m_title
|
|
on M_PatientM_TitleID = M_TitleID
|
|
join f_payment
|
|
ON t_orderheader.T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
|
AND F_PaymentIsActive = 'Y'
|
|
join f_payment_orderheader
|
|
ON F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
|
AND F_Payment_OrderHeaderIsLunas = 'Y'
|
|
join t_orderdelivery on T_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID and T_OrderDeliveryIsActive = 'Y'
|
|
join m_deliverytype
|
|
ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID
|
|
AND M_DeliveryTypeCode = 'ERESULT'
|
|
WHERE (OneResultConfirmStatus = 'C' OR OneResultConfirmStatus = 'R' OR OneResultConfirmStatus = 'E') AND OneResultConfirmRetry <= 5
|
|
group by T_OrderHeaderID
|
|
limit $limit";
|
|
|
|
$query = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$query) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
$this->sys_ok($rows);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function update_status()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
$id = 0;
|
|
if (isset($prm['id'])) {
|
|
$id = trim($prm["id"]);
|
|
$id = $prm['id'];
|
|
}
|
|
$status = "A";
|
|
if (isset($prm['status'])) {
|
|
$status = trim($prm["status"]);
|
|
$status = $prm['status'];
|
|
}
|
|
|
|
// print_r("$status & $id");
|
|
// exit;
|
|
|
|
if ($id == 0) {
|
|
$this->sys_error("ID mandatory !");
|
|
exit;
|
|
}
|
|
if ($status == "A") {
|
|
$this->sys_error("status mandatory !");
|
|
exit;
|
|
}
|
|
|
|
$sql_retry = "SELECT OneResultConfirmRetry
|
|
FROM one_result_confirm
|
|
WHERE OneResultConfirmT_OrderHeaderID = ?";
|
|
$query_retry = $this->db->query($sql_retry, [$id]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$query_retry) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$retry = intval($query_retry->result_array()[0]['OneResultConfirmRetry']) + 1;
|
|
// print_r(
|
|
// array(
|
|
// "retrydb" => $query_retry->result_array()[0]['OneResultConfirmRetry'],
|
|
// "retry + 1" => $query_retry->result_array()[0]['OneResultConfirmRetry'] + 1,
|
|
// "resp" => $query_retry->result_array(),
|
|
// "last_qry" => $this->db->last_query(),
|
|
// "retry_var" => $retry
|
|
// )
|
|
|
|
// );
|
|
// exit;
|
|
|
|
if (count($query_retry->result_array()) > 0) {
|
|
if ($status == "E") {
|
|
|
|
$sql = "UPDATE one_result_confirm SET
|
|
OneResultConfirmStatus = 'E'
|
|
,OneResultConfirmRetry = ?
|
|
,OneResultConfirmLastUpdated = ?
|
|
WHERE OneResultConfirmT_OrderHeaderID = ?";
|
|
$query = $this->db->query($sql, [$retry, date("Y-m-d H:i:s"), $id]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$query) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
} else if ($status == "S") {
|
|
$sql = "UPDATE one_result_confirm SET
|
|
OneResultConfirmStatus = 'S'
|
|
WHERE OneResultConfirmT_OrderHeaderID = ?";
|
|
$query = $this->db->query($sql, [$id]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$query) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
}
|
|
} else {
|
|
$error = array(
|
|
"message" => "ID not found",
|
|
);
|
|
$this->sys_error($error);
|
|
exit;
|
|
}
|
|
|
|
$this->sys_ok("OK");
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|