339 lines
13 KiB
PHP
339 lines
13 KiB
PHP
<?php
|
|
class Patient extends MY_Controller
|
|
{
|
|
var $db;
|
|
var $load;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db = $this->load->database("onedev", true);
|
|
$this->load->library('ibl_encryptor');
|
|
}
|
|
|
|
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";
|
|
|
|
$bidx_where = '';
|
|
if ($search != "") {
|
|
$raw_search = trim($prm['search']);
|
|
$tokens = $this->ibl_encryptor->query_tokens($raw_search);
|
|
if ($tokens) {
|
|
$bidx_conds = implode(' AND ', array_map(function($h) {
|
|
return "JSON_CONTAINS(M_PatientName_bidx, '\"$h\"')";
|
|
}, $tokens));
|
|
$bidx_where = " AND (orderNumber LIKE '{$search}' OR ({$bidx_conds}))";
|
|
} else {
|
|
$bidx_where = " AND orderNumber LIKE '{$search}'";
|
|
}
|
|
$where .= $bidx_where;
|
|
}
|
|
|
|
$sql_total = "SELECT COUNT(*) as total FROM (
|
|
SELECT `order`.*,S_MenuUrl,
|
|
DATE_FORMAT(orderDate, '%d-%m-%Y %H:%i') as order_date,
|
|
M_PatientName_enc as patient_name_enc,
|
|
M_PatientName as patient_name_masked,
|
|
M_PatientPrefix, M_PatientSuffix, M_TitleName,
|
|
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,
|
|
M_PatientName_enc as patient_name_enc,
|
|
M_PatientName as patient_name_masked,
|
|
M_PatientPrefix, M_PatientSuffix, M_TitleName,
|
|
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);
|
|
if ($qry) {
|
|
$enc = $this->ibl_encryptor;
|
|
$rows = array_map(function($row) use ($enc) {
|
|
$name = $enc->decrypt($row['patient_name_enc'] ?? '') ?: $row['patient_name_masked'];
|
|
$title = $row['M_TitleName'] ? $row['M_TitleName'] . '. ' : '';
|
|
$prefix = $row['M_PatientPrefix'] ? $row['M_PatientPrefix'] . ' ' : '';
|
|
$suffix = $row['M_PatientSuffix'] ? ' ' . $row['M_PatientSuffix'] : '';
|
|
$row['patient_fullname'] = trim($title . $prefix . $name . $suffix);
|
|
unset($row['patient_name_enc'], $row['patient_name_masked']);
|
|
return $row;
|
|
}, $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 = [];
|
|
$orderid = intval($prm['orderid'] ?? 0);
|
|
|
|
if ($orderid) {
|
|
$sql = "SELECT M_CompanyID, M_CompanyName, m.M_MouID as settingM_MouID
|
|
FROM one_klinik.`order` o
|
|
JOIN m_mou m ON o.orderM_MouID = m.M_MouID
|
|
JOIN m_company ON m.M_MouM_CompanyID = M_CompanyID
|
|
WHERE o.orderID = ?
|
|
LIMIT 1";
|
|
$qry_order = $this->db->query($sql, [$orderid]);
|
|
if ($qry_order && $qry_order->num_rows() > 0) {
|
|
$order_row = $qry_order->row_array();
|
|
$mous = $this->db->query(
|
|
"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 = ?",
|
|
[$order_row['M_CompanyID']]
|
|
)->result_array();
|
|
$row_results[] = [
|
|
'M_CompanyID' => $order_row['M_CompanyID'],
|
|
'M_CompanyName' => $order_row['M_CompanyName'],
|
|
'mous' => $mous,
|
|
];
|
|
foreach ($mous as $v) {
|
|
if ($v['M_MouID'] == $order_row['settingM_MouID']) {
|
|
$rtn_mou = $v;
|
|
}
|
|
}
|
|
$this->sys_ok(['total_display' => 1, 'records' => $row_results, 'mou' => $rtn_mou]);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$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);
|
|
}
|
|
}
|
|
}
|