136 lines
5.1 KiB
PHP
Executable File
136 lines
5.1 KiB
PHP
Executable File
<?php
|
|
|
|
|
|
class Ro_patient extends MY_Controller
|
|
{
|
|
var $db_smartone;
|
|
|
|
public function index()
|
|
{
|
|
echo "RO Patient API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_smartone = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 10;
|
|
|
|
$sdate = $prm["sdate"];
|
|
$edate = $prm["edate"];
|
|
$nolab = '%' . $prm["nolab"] . '%';
|
|
$search = '%' . $prm["search"] . '%';
|
|
$page = $prm['page'];
|
|
|
|
if ($page == null)
|
|
$page = 1;
|
|
|
|
$offset = ($page - 1) * $max_rst;
|
|
|
|
// QUERY TOTAL
|
|
$sql = "select count(DISTINCT T_OrderHeaderID) total
|
|
from t_orderheader
|
|
join t_orderdetail on t_orderheaderid = t_orderdetailt_orderheaderid
|
|
and t_orderdetailisactive = 'Y' and T_OrderDetailVerification <> 'Y'
|
|
join t_orderrefmaster on t_orderrefmastert_testid = t_orderdetailt_testid
|
|
and t_orderrefmasterisactive = 'Y'
|
|
|
|
left join t_orderrefout ON T_OrderRefOutT_OrderHeaderID = t_orderheaderid
|
|
AND T_OrderRefOutT_TestID = t_orderdetailt_testid
|
|
AND T_OrderRefOutIsActive = 'Y'
|
|
|
|
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_company on T_OrderRefMasterToM_CompanyID = M_CompanyID
|
|
where T_OrderheaderIsActive = 'Y'
|
|
and T_OrderheaderDate BETWEEN '{$sdate} 00:00:00' and '{$edate} 23:59:59'
|
|
and T_OrderHeaderLabNumber LIKE ?
|
|
and M_PatientName LIKE ?
|
|
order by T_OrderHeaderLabNumber DESC";
|
|
$query = $this->db_smartone->query($sql, [$nolab, $search]);
|
|
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("re count", $this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber, T_OrderHeaderDate,
|
|
M_PatientID, M_PatientNoReg, fn_global_patient_name(M_PatientID) M_PatientName,
|
|
M_PatientDOB, T_OrderHeaderM_PatientAge, M_PatientHP,
|
|
T_OrderHeaderFoNote, T_OrderHeaderSamplingNote, T_OrderHeaderResultNote,
|
|
|
|
concat('[',
|
|
group_concat(JSON_OBJECT('T_TestID', T_TestID, 'T_TestCode', T_TestCode, 'T_TestName', T_TestName,
|
|
'M_CompanyID', M_CompanyID, 'M_CompanyName', M_CompanyName,
|
|
'M_BranchID', T_OrderRefMasterToM_BranchID, 'is_internal', T_OrderRefMasterIsInternal,
|
|
'sent', IFNULL(T_OrderRefOutIsSent, 'N'))
|
|
order by T_TestName SEPARATOR ','),
|
|
']') T_TestName
|
|
|
|
from t_orderheader
|
|
join t_orderdetail on t_orderheaderid = t_orderdetailt_orderheaderid
|
|
and t_orderdetailisactive = 'Y' and T_OrderDetailVerification <> 'Y'
|
|
join t_orderrefmaster on t_orderrefmastert_testid = t_orderdetailt_testid
|
|
and t_orderrefmasterisactive = 'Y'
|
|
join t_test on t_orderdetailt_testid = t_testid
|
|
|
|
left join t_orderrefout ON T_OrderRefOutT_OrderHeaderID = t_orderheaderid
|
|
AND T_OrderRefOutT_TestID = t_orderdetailt_testid
|
|
AND T_OrderRefOutIsActive = 'Y'
|
|
|
|
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_company on T_OrderRefMasterToM_CompanyID = M_CompanyID
|
|
where T_OrderheaderIsActive = 'Y'
|
|
and T_OrderheaderDate BETWEEN '{$sdate} 00:00:00' and '{$edate} 23:59:59'
|
|
and T_OrderHeaderLabNumber LIKE ?
|
|
and M_PatientName LIKE ?
|
|
group by T_OrderHeaderID
|
|
order by T_OrderHeaderLabNumber DESC
|
|
limit {$offset}, {$max_rst}";
|
|
$query = $this->db_smartone->query($sql, [$nolab, $search]);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
foreach ($rows as $k => $v)
|
|
$rows[$k]['T_TestName'] = json_decode($v['T_TestName']);
|
|
$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("worklist rows", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function send()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
$data = $prm['data'];
|
|
$sql = "CALL sp_process_ref_send('{$data}', '{$this->sys_input['M_UserID']}')";
|
|
$query = $this->db_smartone->query($sql);
|
|
|
|
if ($query)
|
|
{
|
|
$r = $query->row();
|
|
if ($r->status == "OK")
|
|
$this->sys_ok($r);
|
|
|
|
else
|
|
{
|
|
$this->sys_error($r->message);
|
|
exit;
|
|
}
|
|
}
|
|
else
|
|
$this->sys_error("ERROR");
|
|
}
|
|
} |