Files
BE_IBL/application/controllers/mockup/process/resultunvalidation/Rv_patient.php
2026-04-15 15:24:21 +07:00

102 lines
4.0 KiB
PHP
Executable File

<?php
class Rv_patient extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "RE 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;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
$page = $prm['page'];
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
if ($page == null)
$page = 1;
$offset = ($page - 1) * $max_rst;
// QUERY TOTAL
$sql = "select count(*) total
from t_orderheader
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join m_doctor da on T_OrderHeaderPJM_DoctorID = da.M_DoctorID
JOIN m_company on T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou on T_OrderHeaderM_MouID = M_MouID
JOIN helper_order ON Helper_OrderT_OrderHeaderID = T_OrderHeaderID
AND Helper_OrderIsLAB = 'Y'
where T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderLabNumber like ?
and
( M_PatientName LIKE ?
or ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL))
or ((M_PatientDOB LIKE ? and M_PatientDOB IS NOT NULL))
)
order by T_OrderHeaderLabNumber DESC";
$query = $this->db_smartone->query($sql, [$nolab, $search, $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_OrderHeaderID, T_OrderHeaderLabNumber, T_OrderHeaderDate,
M_PatientID, M_PatientNoReg, fn_global_patient_name(M_PatientID) M_PatientName,
M_PatientDOB, T_OrderHeaderM_PatientAge, M_PatientHP, M_SexName,
da.M_DoctorID doctor_pj_id, fn_global_doctor_name(da.M_DoctorID) doctor_pj_name,
M_MouID, M_MouName, M_CompanyID, M_CompanyName,
T_OrderHeaderFoNote, T_OrderHeaderSamplingNote, T_OrderHeaderResultNote, M_LangCode,
T_OrderHeaderLangIsSI is_si
from t_orderheader
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join m_doctor da on T_OrderHeaderPJM_DoctorID = da.M_DoctorID
JOIN m_company on T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou on T_OrderHeaderM_MouID = M_MouID
JOIN m_sex on M_PatientM_SexID = M_SexID
JOIN helper_order ON Helper_OrderT_OrderHeaderID = T_OrderHeaderID
AND Helper_OrderIsLAB = 'Y'
JOIN m_lang ON T_OrderHeaderM_LangID = M_LangID
where T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderLabNumber like ?
and
( M_PatientName LIKE ?
or ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL))
or ((M_PatientDOB LIKE ? and M_PatientDOB IS NOT NULL))
)
order by T_OrderHeaderLabNumber DESC
limit {$offset}, {$max_rst}";
$query = $this->db_smartone->query($sql, [$nolab, $search, $search, $search ]);
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['data'] = json_decode($v['data']);
$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;
}
}
}