Files
2026-04-27 10:31:17 +07:00

185 lines
6.7 KiB
PHP

<?php
class Receive_patient extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Handling.To.Process'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, '' status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Handling.To.Process'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
public function search_sent()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'PROCESS.Process.From.Handling')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, m_statussamplecode status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'PROCESS.Process.From.Handling')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
function receive()
{
$prm = $this->sys_input;
$sql = "CALL sp_process_worklist_01_receive_remove('RCV', '0', '{$prm['ids']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("handling receive", $this->db_smartone);
exit;
}
}
function remove()
{
$prm = $this->sys_input;
$sql = "CALL sp_process_worklist_01_receive_remove('RMV', '{$prm['id']}', '')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("worklist receive remove", $this->db_smartone);
exit;
}
}
}