126 lines
4.6 KiB
PHP
126 lines
4.6 KiB
PHP
<?php
|
|
|
|
|
|
class Ri_new extends MY_Controller
|
|
{
|
|
var $db_smartone;
|
|
|
|
public function index()
|
|
{
|
|
echo "RI New API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_smartone = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function search_branch()
|
|
{
|
|
$sql = "SELECT M_BranchID, M_BranchName, IFNULL(S_SystemsID, 0) `default`
|
|
FROM m_branch
|
|
LEFT JOIN conf_systems ON M_BranchID = S_SystemsM_BranchID
|
|
WHERE M_BranchIsActive = 'Y'
|
|
ORDER BY M_BranchName";
|
|
$query = $this->db_smartone->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("records" => $rows, "q" => $this->db_smartone->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("Branch rows", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search_worklist()
|
|
{
|
|
$sql = "SELECT T_WorklistID, T_WorklistName,
|
|
CONCAT('[', GROUP_CONCAT(JSON_OBJECT('test_id', T_TestID, 'test_name', T_TestName) SEPARATOR ','), ']') tests
|
|
FROM t_worklist
|
|
JOIN t_worklistdetail ON T_WorklistDetailT_WorklistID = T_WorklistID
|
|
AND T_WorklistDetailIsActive = 'Y'
|
|
JOIN t_test ON T_WorklistDetailT_TestID = T_TestID
|
|
WHERE T_WorklistIsActive = 'Y'
|
|
AND T_WorklistIsRujukan = 'Y'
|
|
AND `fn_process_refinternal_hasorder`(T_TestID) > 0
|
|
GROUP BY T_WorklistID
|
|
ORDER BY T_WorklistName, T_TestName";
|
|
$query = $this->db_smartone->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
foreach($rows as $k => $v)
|
|
$rows[$k]['tests'] = json_decode($v['tests']);
|
|
|
|
$result = array("records" => $rows, "q" => $this->db_smartone->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("Branch rows", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search_patient()
|
|
{
|
|
// print_r($this->sys_user);
|
|
$prm = $this->sys_input;
|
|
$ids = $prm['ids'];
|
|
|
|
$sql = "SELECT b.T_OrderDetailID, T_OrderHeaderID, T_OrderHeaderLabNumber, b.T_OrderDetailT_TestName,
|
|
T_OrderHeaderDate, fn_global_patient_name(T_OrderHeaderM_PatientID) patient_name
|
|
FROM t_ordersample
|
|
JOIN t_test ON T_OrderSampleT_SampleTypeID = T_TestT_SampleTypeID
|
|
AND FIND_IN_SET(T_TestID, ?)
|
|
JOIN t_orderdetail a ON a.T_OrderDetailT_OrderHeaderID = T_OrderSampleT_OrderHeaderID
|
|
AND a.T_OrderDetailT_TestID = T_TestID
|
|
AND a.T_OrderDetailIsActive = 'Y'
|
|
JOIN t_orderdetail b ON a.T_OrderDetailT_OrderHeaderID = b.T_OrderDetailT_OrderHeaderID
|
|
AND b.T_OrderdetailIsActive = 'Y'
|
|
AND b.T_OrderDetailT_TestSasCode LIKE CONCAT(a.T_OrderDetailT_TestSasCode, '%')
|
|
AND b.T_OrderDetailT_TestIsResult = 'Y'
|
|
LEFT JOIN t_orderrefintdetail ON b.T_OrderDetailID = T_OrderRefIntDetailT_OrderDetailID
|
|
AND T_ORderRefIntDetailIsActive = 'Y'
|
|
JOIN t_orderheader ON a.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
|
WHERE T_OrderSampleWorklistReceive = 'Y'
|
|
AND T_OrderSampleIsActive = 'Y'
|
|
AND T_OrderRefIntDetailID IS NULL";
|
|
|
|
$query = $this->db_smartone->query($sql, [$ids]);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("records" => $rows, "q" => $this->db_smartone->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("Patient rows", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$ids = json_encode(explode(',', $prm['ids']));
|
|
$branch_id = $prm['branch_id'];
|
|
|
|
$sql = "CALL sp_process_refinternal_save(?, ?)";
|
|
$query = $this->db_smartone->query($sql, [$branch_id, $ids]);
|
|
|
|
if ($query) {
|
|
$rows = $query->row();
|
|
$this->sys_ok($rows);
|
|
}
|
|
else {
|
|
$this->sys_error_db("Patient rows", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
} |