226 lines
7.5 KiB
Plaintext
226 lines
7.5 KiB
Plaintext
<?php
|
|
class Patient extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "Patient API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function add_notes($orderid){
|
|
$sql = " SELECT F_PaymentT_OrderHeaderID as note_order_id,
|
|
F_PaymentID as note_id,
|
|
F_PaymentDate as note_date,
|
|
F_PaymentNumber as note_number,
|
|
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
|
|
MAX(F_PaymentTotal) as note_amount,
|
|
M_StaffName as note_user,
|
|
F_PaymentDetailIsActive as note_active
|
|
FROM f_payment
|
|
JOIN f_paymentdetail ON F_PaymentDetailF_PaymentID = F_PaymentID
|
|
JOIN m_paymenttype ON F_PaymentDetailM_PaymentTypeID = M_PaymentTypeID
|
|
LEFT JOIN m_user ON F_PaymentDetailUserID = M_UserID
|
|
LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID
|
|
WHERE
|
|
F_PaymentT_OrderHeaderID = {$orderid}
|
|
GROUP BY F_PaymentID";
|
|
$query = $this->db_onedev->query($sql);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
return $rows;
|
|
|
|
} else {
|
|
$this->sys_error_db("get notes", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$startdate = $prm['startdate'];
|
|
$enddate = $prm['enddate'] . " 23:59:59";
|
|
$search = $prm["search"];
|
|
$status = $prm["status"];
|
|
$company = $prm["company"];
|
|
$filter_company = '';
|
|
if($company != '0' || $company != 0)
|
|
$filter_company = " AND CorporateID = {$company}";
|
|
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
$where = " ( DATE(T_OrderHeaderDate) = '{$startdate}' ) AND ";
|
|
if($search != ''){
|
|
$where = "( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' ) AND ";
|
|
if(strlen($search) == 10){
|
|
$where = "T_OrderHeaderLabNumber = '{$search}' AND ";
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT count(*) as total
|
|
FROM t_orderheader
|
|
left join f_bill_detail on F_BillDetailT_OrderHeaderID = T_OrderHeaderID and F_BillDetailIsActive = 'Y'
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
JOIN corporate ON T_OrderHeaderCorporateID = CorporateID $filter_company
|
|
LEFT JOIN mgm_mcu ON T_OrderHeaderMgm_McuID = Mgm_McuID
|
|
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
|
|
LEFT JOIN x_wa_outbox
|
|
ON T_OrderHeaderID = XWaOutboxRefID
|
|
AND XWaOutboxIsActive = 'Y'
|
|
WHERE T_OrderHeaderIsActive = 'Y' AND
|
|
$where
|
|
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y') ) and F_BillDetailID is null";
|
|
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
|
|
$sql = "SELECT t_orderheader.*,
|
|
M_PatientNoReg,
|
|
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y %H:%i') as order_date,
|
|
CONCAT(M_TitleName,'. ',M_PatientName) as M_PatientName,
|
|
M_PatientName as M_PatientName_eng,
|
|
M_TitleName,
|
|
CorporateName as M_CompanyName,
|
|
CorporateName as CorporateName,
|
|
Mgm_McuLabel as M_MouName,
|
|
Mgm_McuLabel,
|
|
IFNULL(Last_StatusPaymentBillTotal, T_OrderHeaderTotal) as totalbill,
|
|
IFNULL(Last_StatusPaymentPaid,0) as paid,
|
|
(IFNULL(Last_StatusPaymentBillTotal, T_OrderHeaderTotal) - IFNULL(Last_StatusPaymentPaid,0)) as unpaid,
|
|
Last_StatusPaymentIsLunas as flaglunas,
|
|
'' as notes,
|
|
0 as mindp_percent,
|
|
0 as mindp_amount,
|
|
F_BillDetailID,
|
|
IFNULL(M_PatientHp,'') as M_PatientHp,
|
|
IFNULL(M_PatientID,0) as M_PatientID,
|
|
IFNULL(XWaOutboxIsSent,'') as XWaOutboxIsSent,
|
|
IFNULL(XWaOutboxRetry,0) as XWaOutboxRetry
|
|
FROM t_orderheader
|
|
left join f_bill_detail on F_BillDetailT_OrderHeaderID = T_OrderHeaderID and F_BillDetailIsActive = 'Y'
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
JOIN corporate ON T_OrderHeaderCorporateID = CorporateID $filter_company
|
|
LEFT JOIN mgm_mcu ON T_OrderHeaderMgm_McuID = Mgm_McuID
|
|
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
|
|
LEFT JOIN x_wa_outbox
|
|
ON T_OrderHeaderID = XWaOutboxRefID
|
|
AND XWaOutboxIsActive = 'Y'
|
|
AND XWaOutboxType = 'KWITANSI'
|
|
WHERE T_OrderHeaderIsActive = 'Y' AND
|
|
$where
|
|
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y') ) and F_BillDetailID is null
|
|
ORDER BY T_OrderHeaderID ASC
|
|
limit $number_limit offset $number_offset";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
$rows[$k]['notes'] = $this->add_notes($v['T_OrderHeaderID']);
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT * FROM `s_menu` WHERE `S_MenuName` = 'Registration (Walk In)' AND `S_MenuIsActive` = 'Y' ORDER BY `S_MenuID` DESC LIMIT 1";
|
|
$query = $this->db_onedev->query($sql);
|
|
$menu = $query->row_array();
|
|
if($menu){
|
|
$menu_url = $menu['S_MenuUrl'];
|
|
}
|
|
|
|
|
|
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query(), "menu_url" => $menu_url);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
function searchcompany(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
$filter_date = '';
|
|
if(isset($prm['xdate']))
|
|
$filter_date = " JOIN t_orderheader ON T_OrderHeaderCorporateID = CorporateID AND DATE(T_OrderHeaderDate) = '{$prm['xdate']}' AND T_OrderHeaderIsActive = 'Y' ";
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '' )
|
|
{
|
|
if($prm['search'] == 'Semua')
|
|
$prm['search'] = "";
|
|
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM corporate
|
|
WHERE
|
|
CorporateName like ?
|
|
AND CorporateIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city count",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$rows = array('id'=>0,'name'=>'Semua');
|
|
$sql = "
|
|
SELECT CorporateID as id, CorporateName as name
|
|
FROM corporate
|
|
$filter_date
|
|
WHERE
|
|
CorporateName like ?
|
|
AND CorporateIsActive = 'Y'
|
|
ORDER BY CorporateName DESC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
// echo $this->db_onedev->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows,array('id'=>0,'name'=>'Semua'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("corporate rows",$this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
}
|