Files
BE_CPONE/application/controllers/mockup/cpone-supervisor/Patient.php
2026-04-27 10:31:17 +07:00

181 lines
5.3 KiB
PHP

<?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);
}
function add_notes_bckp($orderid){
$rst = array();
$sql = "SELECT Fo_VerificationTypeLabelCorrection as label,
Fo_VerificationReason as reason,
Fo_VerificationTypeGroup as xgroup,
Fo_VerificationTypeName as xname,
'N' as chex
FROM fo_verification
JOIN fo_verificationtype ON Fo_VerificationFo_VericationTypeID = Fo_VericationTypeID
WHERE
Fo_VerificationIsOK = 'N' AND Fo_VerificationT_OrderHeaderID = {$orderid}";
$other = $this->db_onedev->query($sql)->result_array();
if($other){
foreach($other as $k => $v){
array_push($rst,$v);
}
}
$sql = "
SELECT
IF(SUM(label) > 0, 'Perubahan pemeriksaan','') as label,
GROUP_CONCAT(reason separator ',') as reason,
'TEST' as xgroup,
'ORDER.TEST' as xname,
'N' as chex
FROM (
SELECT COUNT(*) as label,
GROUP_CONCAT(CONCAT(T_OrderDetailT_TestName,'(-)') separator ',') as reason,
Fo_VerificationTestT_OrderHeaderID as orderid
FROM fo_verification_test
JOIN t_orderdetail ON Fo_VerificationTestT_OrderDetailID = T_OrderDetailID
WHERE
Fo_VerificationTestT_OrderHeaderID = {$orderid} AND Fo_VerificationTestIsOK = 'N'
GROUP BY Fo_VerificationTestT_OrderHeaderID
UNION
SELECT COUNT(*) as label,
GROUP_CONCAT(CONCAT(T_TestName,'(+)') separator ',') as reason,
Fo_VerificationTestAddT_OrderHeaderID as orderid
FROM fo_verification_test_add
JOIN t_test ON Fo_VerificationTestAddT_TestID = T_TestID
WHERE
Fo_VerificationTestAddT_OrderHeaderID = {$orderid} AND Fo_VerificationTestAddIsActive = 'Y'
GROUP BY Fo_VerificationTestAddT_OrderHeaderID
) a GROUP BY orderid
";
$tests = $this->db_onedev->query($sql)->result_array();
if($tests){
foreach($tests as $k => $v){
array_push($rst,$v);
}
}
$sql = "SELECT COUNT(*) as xc
FROM fo_verification_delivery_add
WHERE
Fo_VerificationDeliveryAddIsActive = 'Y' AND Fo_VerificationDeliveryAddT_OrderHeaderID = {$orderid} ";
$delivery = $this->db_onedev->query($sql)->row();
if($delivery->xc > 0){
$xv = array('label'=>'Perubahan pengiriman hasil','reason'=>'Silahkan check perubahan pengiriman hasil','xgroup'=>'DELIVERY','xname'=>'ORDER.DELIVERY','chex'=>'N');
array_push($rst,$xv);
}
return $rst;
}
function add_notes($orderid){
$rst = array();
$sql = "SELECT Fo_VerificationsLabelName as label,
Fo_VerificationsValueNote as reason,
Fo_VerificationsLabelButton as button
FROM fo_verificationsvalue
JOIN fo_verificationslabel ON Fo_VerificationsValueFo_VerificationsLabelID = Fo_VerificationsLabelID
WHERE
Fo_VerificationsValueCheck = 'N' AND Fo_VerificationsValueT_OrderHeaderID = {$orderid}";
$other = $this->db_onedev->query($sql)->result_array();
if($other){
foreach($other as $k => $v){
array_push($rst,$v);
}
}
return $rst;
}
function getdataselected(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = " SELECT t_orderheaderaddon.*,IFNULL(T_OrderHeaderAddOnAliasDoctorName,'') as T_OrderHeaderAddOnAliasDoctorName
FROM t_orderheaderaddon
WHERE
T_OrderHeaderAddOnT_OrderHeaderID = {$prm['orderid']} AND
T_OrderHeaderAddOnIsActive = 'Y' LIMIT 1";
$query = $this->db_onedev->query($sql);
$rows = $query->row_array();
$result = array("total" => 1, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm["search"];
$status = $prm["status"];
$sql = "SELECT -1 as xid,
T_OrderHeaderID as orderid,
'' as alias,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y %H:%i') as orderdate,
T_OrderHeaderLabNumber as labnumber,
'' as labnumber_ext,
M_PatientNoReg as patient_noreg,
'' as status_fo,
'adhoc' as message_type,
'' as message,
0 as message_id,
'' as donedelivery,
CONCAT(M_TitleName,' ',M_PatientName) as patientname,
'adhoc' as type,
'' as patient_mcu
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
WHERE
( T_OrderHeaderLabNumber LIKE '%{$search}%' OR M_PatientName LIKE '%{$search}%' ) AND T_OrderHeaderIsActive = 'Y'
ORDER BY T_OrderHeaderID DESC LIMIT 30";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
/*if($status == 'N' || $status == 'Y'){
$rows[$k]['notes'] = $this->add_notes($v['orderid']);
}
else{
$rows[$k]['notes'] = array();
}
*/
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
}