284 lines
10 KiB
PHP
284 lines
10 KiB
PHP
<?php
|
|
class Patient extends MY_Controller
|
|
{
|
|
var $db;
|
|
var $load;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db = $this->load->database("onedev", true);
|
|
}
|
|
|
|
function index()
|
|
{
|
|
// $cek = $this->db->query("select database() as current_db")->result();
|
|
// print_r($cek);
|
|
echo "LIST PATIENT ORDER";
|
|
}
|
|
|
|
function search()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$search = "";
|
|
if (isset($prm["search"])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = "%" . $prm["search"] . "%";
|
|
} else {
|
|
$search = "%%";
|
|
}
|
|
}
|
|
$start_date = $prm['start_date'];
|
|
$end_date = $prm['end_date'];
|
|
|
|
$filter_date = " AND (DATE(orderDate) BETWEEN '{$start_date}' AND '{$end_date}')";
|
|
|
|
$where = " orderIsActive = 'Y' $filter_date";
|
|
|
|
if ($search != "") {
|
|
$where .= " AND (orderNumber LIKE '{$search}' OR M_PatientName LIKE '{$search}')";
|
|
}
|
|
|
|
$sql_total = "SELECT COUNT(*) as total FROM (
|
|
SELECT `order`.*,S_MenuUrl,
|
|
DATE_FORMAT(orderDate, '%d-%m-%Y %H:%i') as order_date,
|
|
CONCAT(M_TitleName,'. ',M_PatientName) as patient_fullname,
|
|
IFNULL(T_OrderHeaderLabNumber,'-') as labnumber
|
|
FROM one_klinik.order
|
|
JOIN m_patient ON orderM_PatientID = M_PatientID
|
|
AND M_PatientIsActive = 'Y'
|
|
JOIN s_menu ON S_MenuName = 'Registration' AND S_MenuIsActive = 'Y'
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
AND M_TitleIsActive = 'Y'
|
|
LEFT JOIN t_orderheader ON orderT_OrderHeaderID = T_OrderHeaderID
|
|
WHERE $where
|
|
GROUP BY orderID) x";
|
|
$qry_total = $this->db->query($sql_total);
|
|
$last_query = $this->db->last_query();
|
|
//echo $last_query;
|
|
// exit;
|
|
|
|
$tot_count = 0;
|
|
if ($qry_total) {
|
|
$tot_count = $qry_total->result_array()[0]["total"];
|
|
} else {
|
|
$this->sys_error_db("count order error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT * FROM (
|
|
SELECT `order`.*,S_MenuUrl,
|
|
DATE_FORMAT(orderDate, '%d-%m-%Y %H:%i') as order_date,
|
|
CONCAT(M_TitleName,'. ',M_PatientName) as patient_fullname,
|
|
IFNULL(T_OrderHeaderLabNumber,'-') as labnumber
|
|
FROM one_klinik.order
|
|
JOIN m_patient ON orderM_PatientID = M_PatientID
|
|
AND M_PatientIsActive = 'Y'
|
|
JOIN s_menu ON S_MenuName = 'Registration' AND S_MenuIsActive = 'Y'
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
AND M_TitleIsActive = 'Y'
|
|
LEFT JOIN t_orderheader ON orderT_OrderHeaderID = T_OrderHeaderID
|
|
WHERE $where
|
|
GROUP BY orderID) x
|
|
ORDER BY orderID ASC
|
|
limit 0, $tot_count";
|
|
|
|
$qry = $this->db->query($sql);
|
|
$last_query = $this->db->last_query();
|
|
// echo $last_query;
|
|
// exit;
|
|
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("Select order error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total_filter" => $tot_count,
|
|
"records" => $rows,
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function searchcompany()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$search = "";
|
|
$number_limit = 10;
|
|
|
|
if (isset($prm['search'])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = '%' . $prm['search'] . '%';
|
|
} else {
|
|
$search = '%%';
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT M_CompanyID,
|
|
M_CompanyName, '' as mous
|
|
FROM m_company
|
|
WHERE M_CompanyIsActive = 'Y'
|
|
AND M_CompanyName LIKE ?
|
|
LIMIT ?";
|
|
$qry = $this->db->query($sql, [$search, $number_limit]);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
if($rows){
|
|
foreach ($rows as $key => $value) {
|
|
$mous = [];
|
|
$sql = "SELECT M_MouID, M_MouName
|
|
FROM m_mou
|
|
WHERE M_MouIsActive = 'Y' AND M_MouIsApproved = 'Y' AND M_MouIsReleased = 'Y'
|
|
AND M_MouStartDate <= date(now()) AND M_MouEndDate >= date(now()) AND M_MouM_CompanyID = ?";
|
|
$mous = $this->db->query($sql,array($value['M_CompanyID']))->result_array();
|
|
$rows[$key]['mous'] = $mous;
|
|
|
|
}
|
|
}
|
|
} else {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("company select error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total_display" => sizeof($rows),
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function savesetting()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$mouid = "";
|
|
if (isset($prm["mouid"])) {
|
|
$mouid = trim($prm["mouid"]);
|
|
}
|
|
|
|
|
|
$sql = "UPDATE one_klinik.order SET
|
|
orderM_MouID = {$mouid},
|
|
orderUserID = {$userid},
|
|
orderLastUpdated = NOW()
|
|
WHERE
|
|
orderID = {$prm['orderid']}";
|
|
// echo $sql;
|
|
$qry = $this->db->query($sql);
|
|
|
|
if (!$qry) {
|
|
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db_oneklinik);
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function getdefaultmou()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$row_results = [];
|
|
$rtn_mou = [];
|
|
$sql = "SELECT M_CompanyID,
|
|
M_CompanyName, '' as mous, settingM_MouID
|
|
FROM m_company
|
|
JOIN one_klinik.setting ON settingIsActive = 'Y'
|
|
JOIN m_mou ON M_MouID = settingM_MouID AND M_MouM_CompanyID = M_CompanyID AND
|
|
M_MouIsActive = 'Y' AND M_MouIsApproved = 'Y' AND M_MouIsReleased = 'Y'
|
|
AND M_MouStartDate <= date(now()) AND M_MouEndDate >= date(now())
|
|
WHERE M_CompanyIsActive = 'Y'
|
|
LIMIT 1";
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
if($rows){
|
|
foreach ($rows as $key => $value) {
|
|
$mous = [];
|
|
$sql = "SELECT M_MouID, M_MouName
|
|
FROM m_mou
|
|
WHERE M_MouIsActive = 'Y' AND M_MouIsApproved = 'Y' AND M_MouIsReleased = 'Y'
|
|
AND M_MouStartDate <= date(now()) AND M_MouEndDate >= date(now()) AND M_MouM_CompanyID = ?";
|
|
$mous = $this->db->query($sql,array($value['M_CompanyID']))->result_array();
|
|
$data_result = [];
|
|
$data_result['M_CompanyID'] = $value['M_CompanyID'];
|
|
$data_result['M_CompanyName'] = $value['M_CompanyName'];
|
|
$data_result['mous'] = $mous;
|
|
$row_results[] = $data_result;
|
|
foreach ($mous as $k => $v) {
|
|
if($v['M_MouID'] == $value['settingM_MouID']){
|
|
$rtn_mou = $v;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$this->sys_error_db("company select error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total_display" => sizeof($rows),
|
|
"records" => $row_results,
|
|
"mou" => $rtn_mou
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|