80 lines
2.9 KiB
PHP
80 lines
2.9 KiB
PHP
<?php
|
|
|
|
|
|
class Ri_detail extends MY_Controller
|
|
{
|
|
var $db_smartone;
|
|
|
|
public function index()
|
|
{
|
|
echo "RI Detail API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_smartone = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 10;
|
|
|
|
$order_id = $prm["order_id"];
|
|
$search = '%'.$prm["query"].'%';
|
|
$page = $prm['page'];
|
|
|
|
if ($page == null)
|
|
$page = 1;
|
|
|
|
$offset = ($page - 1) * $max_rst;
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT COUNT(*)
|
|
FROM t_orderrefintdetail
|
|
JOIN t_orderheader ON T_OrderRefIntDetailT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN t_orderdetail ON T_OrderRefIntDetailT_OrderDetailID = T_OrderDetailID
|
|
JOIN t_test ON T_OrderRefIntDetailT_TestID = T_TestID
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_statusref ON T_OrderRefIntDetailM_StatusRefID = M_StatusRefID
|
|
WHERE T_OrderRefIntDetailIsActive = 'Y'
|
|
AND T_OrderRefIntDetailT_OrderRefIntID = ?
|
|
AND (M_PatientName LIKE ? OR T_OrderHeaderLabNumber LIKE ?)";
|
|
$query = $this->db_smartone->query($sql, [$order_id, $search, $search]);
|
|
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("re count", $this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT T_OrderHeaderLabNumber, fn_global_patient_name(T_OrderHeaderM_PatientID) patient_name,
|
|
T_TestName, T_OrderRefIntDetailResult, T_OrderRefIntDetailPromise,
|
|
M_StatusRefName
|
|
FROM t_orderrefintdetail
|
|
JOIN t_orderheader ON T_OrderRefIntDetailT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN t_orderdetail ON T_OrderRefIntDetailT_OrderDetailID = T_OrderDetailID
|
|
JOIN t_test ON T_OrderRefIntDetailT_TestID = T_TestID
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_statusref ON T_OrderRefIntDetailM_StatusRefID = M_StatusRefID
|
|
WHERE T_OrderRefIntDetailIsActive = 'Y'
|
|
AND T_OrderRefIntDetailT_OrderRefIntID = ?
|
|
AND (M_PatientName LIKE ? OR T_OrderHeaderLabNumber LIKE ?)
|
|
limit {$offset}, {$max_rst}";
|
|
$query = $this->db_smartone->query($sql, [$order_id, $search, $search]);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("total" => $tot_count, "total_page" => ceil($tot_count/$max_rst), "cur_page" => $page, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("RI Detail rows", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
} |