189 lines
7.0 KiB
PHP
Executable File
189 lines
7.0 KiB
PHP
Executable File
<?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.Verification.To.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, '' 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.Verification.To.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;
|
|
}
|
|
}
|
|
|
|
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 = 'SAMPLING.Handling.From.Verification' OR
|
|
m_statussamplecode = 'SAMPLING.Handling.Process' OR
|
|
m_statussamplecode = 'SAMPLING.Handling.Reject')
|
|
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 = 'SAMPLING.Handling.From.Verification' OR
|
|
m_statussamplecode = 'SAMPLING.Handling.Process' OR
|
|
m_statussamplecode = 'SAMPLING.Handling.Reject')
|
|
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_sampling_handling_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_sampling_handling_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("handling receive remove", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
}
|