Files
BE_IBL/application/controllers/mockup/resultentry_verification_so/Patient.php
2026-04-15 15:24:12 +07:00

330 lines
11 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_verifications_label($orderid,$type){
$query = " SELECT Result_VerificationsID as id,
IFNULL(Result_VerificationsValueID,0) as xid,
IFNULL(Result_VerificationsValueCheck,'N') as chex,
IF(ISNULL(Result_VerificationsValueID),'',Result_VerificationsValueNote) as note,
Result_VerificationsLabel as label
FROM result_verifications
LEFT JOIN result_verifications_value ON
Result_VerificationsValueT_OrderHeaderID = {$orderid} AND Result_VerificationsValueType = '{$type}'
WHERE
Result_VerificationIsActive = 'Y'
GROUP BY Result_VerificationsID
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
return $rows;
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nolab = $prm["nolab"];
$nama = $prm["name"];
//$startdate = $prm["startdate"];
//$enddate = $prm["enddate"];
$groupid = 3;
$subgroupid = $prm["subgroupid"];
$join_group = '';
if($groupid != 0){
$join_group = "JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID AND Nat_GroupID = {$groupid}";
}
$join_subgroup = '';
if($subgroupid != 0){
$join_group = "JOIN nat_subgroup ON T_TestNat_SubgroupID = Nat_SubgroupID AND Nat_SubgroupID = {$subgroupid}";
}
if(!isset($prm['current_page']))
$prm['current_page'] = 1;
$sql_where = "WHERE So_ResultEntryValidation1 = 'Y' AND So_ResultEntryValidation2 = 'N' AND So_ResultEntryIsActive = 'Y'";
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
//$sql_param = array();
if ($nolab != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " T_OrderHeaderLabNumber like '%$nolab%' ";
}
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_PatientName like '%$nama%' ";
}
$sql = "SELECT T_OrderHeaderID as orderid,
GROUP_CONCAT(T_OrderDetailID separator ',') as ids,
fn_result_so_check_verification_status(T_OrderHeaderID,'xray') as status,
T_OrderHeaderLabNumber as ordernumber,
UPPER(CONCAT(M_TitleName,' ',M_PatientName)) as patient_fullname,
UPPER(M_SexName) as sexname,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as orderdate,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob,
UPPER(T_OrderHeaderM_PatientAge) as umur,
M_LangName as languange_name,
GROUP_CONCAT(T_TestName separator ',') as test_name,
'' as details,
'' as verifications,
T_OrderHeaderIsCito as iscito,
'xray' as type
FROM so_resultentry
JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestNat_SubgroupID IN (17,18,19)
JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_lang ON So_ResultEntryM_LangID = M_LangID
$join_group
$join_subgroup
$sql_where
GROUP BY T_OrderHeaderID
HAVING fn_result_verification_check_ready_xray(T_OrderHeaderID) = 'Y'
UNION
SELECT T_OrderHeaderID as orderid,
GROUP_CONCAT(T_OrderDetailID separator ',') as ids,
fn_result_so_check_verification_status(T_OrderHeaderID,'usg') as status,
T_OrderHeaderLabNumber as ordernumber,
UPPER(CONCAT(M_TitleName,' ',M_PatientName)) as patient_fullname,
UPPER(M_SexName) as sexname,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as orderdate,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob,
UPPER(T_OrderHeaderM_PatientAge) as umur,
M_LangName as languange_name,
GROUP_CONCAT(T_TestName separator ',') as test_name,
'' as details,
'' as verifications,
T_OrderHeaderIsCito as iscito,
'usg' as type
FROM so_resultentry
JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestNat_SubgroupID = 22
JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_lang ON So_ResultEntryM_LangID = M_LangID
$join_group
$join_subgroup
$sql_where
GROUP BY T_OrderHeaderID
HAVING fn_result_verification_check_ready_usg(T_OrderHeaderID) = 'Y'
UNION
SELECT T_OrderHeaderID as orderid,
GROUP_CONCAT(T_OrderDetailID separator ',') as ids,
fn_result_so_check_verification_status(T_OrderHeaderID,'bdm') as status,
T_OrderHeaderLabNumber as ordernumber,
UPPER(CONCAT(M_TitleName,' ',M_PatientName)) as patient_fullname,
UPPER(M_SexName) as sexname,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as orderdate,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob,
UPPER(T_OrderHeaderM_PatientAge) as umur,
M_LangName as languange_name,
GROUP_CONCAT(T_TestName separator ',') as test_name,
'' as details,
'' as verifications,
T_OrderHeaderIsCito as iscito,
'bdm' as type
FROM so_resultentry
JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestNat_SubgroupID = 20
JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_lang ON So_ResultEntryM_LangID = M_LangID
$join_group
$join_subgroup
$sql_where
GROUP BY T_OrderHeaderID
HAVING fn_result_verification_check_ready_bdm(T_OrderHeaderID) = 'Y'
UNION
SELECT T_OrderHeaderID as orderid,
GROUP_CONCAT(T_OrderDetailID separator ',') as ids,
fn_result_so_check_verification_status(T_OrderHeaderID,'scan') as status,
T_OrderHeaderLabNumber as ordernumber,
UPPER(CONCAT(M_TitleName,' ',M_PatientName)) as patient_fullname,
UPPER(M_SexName) as sexname,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as orderdate,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob,
UPPER(T_OrderHeaderM_PatientAge) as umur,
M_LangName as languange_name,
GROUP_CONCAT(T_TestName separator ',') as test_name,
'' as details,
'' as verifications,
T_OrderHeaderIsCito as iscito,
'scan' as type
FROM so_resultentry
JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestNat_SubgroupID IN (21,23)
JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_lang ON So_ResultEntryM_LangID = M_LangID
$join_group
$join_subgroup
$sql_where
GROUP BY T_OrderHeaderID
HAVING fn_result_verification_check_ready_scan(T_OrderHeaderID) = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['verifications'] = $this->add_verifications_label($v['orderid'],$v['type']);
}
}
$result = array("total" => count($rst), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function verify(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$xstatus = $prm['act'];
$ids = '['.$prm['ids'].']';
if($xstatus == 'Y'){
$msg = "Berhasil melakukan verifikasi";
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueT_OrderHeaderID,
Result_VerificationsValueType,
Result_VerificationsValueIds,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
SELECT
{$prm['orderid']},
'{$prm['type']}',
'{$ids}',
'Y',
'',
{$userid},
NOW()
FROM result_verifications
WHERE
Result_VerificationIsActive = 'Y'
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = 'Y',
Result_VerificationsValueNote = '',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
$sql = "
INSERT INTO result_frontoffice(
Result_FrontOfficeT_OrderHeaderID,
Result_FrontOfficeIds,
Result_FrontOfficeStatus,
Result_FrontOfficeType,
Result_FrontOfficeTestName,
Result_FrontOfficeCreated,
Result_FrontOfficeUserID
)
VALUES(
{$prm['orderid']},
'{$ids}',
'P',
'{$prm['type']}',
'{$prm['test_name']}',
NOW(),
{$userid}
) ON DUPLICATE KEY UPDATE
Result_FrontOfficeStatus = 'P',
Result_FrontOfficeType = '{$prm['type']}',
Result_FrontOfficeUserID = {$userid}
";
//echo $sql;
$this->db_onedev->query($sql);
$sql = "UPDATE so_resultentry SET So_ResultEntryStatus = 'VAL2' , So_ResultEntryValidation2 = 'Y' WHERE JSON_CONTAINS('{$ids}',So_ResultEntryT_OrderDetailID) ";
//echo $sql;
$this->db_onedev->query($sql);
}
else{
$msg = "Tolak untuk perbaikan";
$verifications = $prm['verifications'];
foreach($verifications as $k => $v){
$chx = $v['chex'] == true ?'Y':'N';
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueT_OrderHeaderID,
Result_VerificationsValueType,
Result_VerificationsValueIds,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
values( {$prm['orderid']},
'{$prm['type']}',
'{$ids}',
{$v['id']},
'{$chx}',
'{$v['note']}',
{$userid},
NOW()
)
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = '{$chx}',
Result_VerificationsValueNote = '{$v['note']}',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
}
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>$msg));
$this->sys_ok($result);
}
}