pbmc-cmod/app/Controllers/API_Dashboard.php

75 lines
3.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Controllers;
2024-11-21 15:38:56 +07:00
use CodeIgniter\RESTful\ResourceController;
2024-12-04 11:11:02 +07:00
class API_Dashboard extends ResourceController {
2024-11-21 15:38:56 +07:00
protected $format = 'json';
2024-11-21 15:38:56 +07:00
public function index() {
// Mengetahui Apakah User Login adalah Bali atau Surabaya
$cityid = session()->get('usercityid');
if ($cityid == 1) {
$filter_query = " AND (tr.REQNUMBER LIKE 'B%' OR tr.REQNUMBER LIKE 'Z%')";
} elseif ($cityid == 2) {
$filter_query = " AND (tr.REQNUMBER LIKE 'S%' OR tr.REQNUMBER LIKE 'X%')";
2025-01-21 13:24:39 +08:00
} else { $filter_query = " "; }
$db = \Config\Database::connect();
2024-12-07 09:25:13 +07:00
$date1 = $this->request->getPost('date1');
$date2 = $this->request->getPost('date2');
$sql = "SELECT
sr.COLLECTIONDATE, sr.SP_ACCESSNUMBER, tr.REQNUMBER as HOSTORDERNUMBER, p.PATNUMBER, concat(p.FIRSTNAMESK, ' ', p.NAME) as NAME,
TESTS=stuff(( select ', '+'('+T.SP_TESTCODE+')' from
( select T.SP_TESTCODE from SP_TESTS T
where T.SP_ACCESSNUMBER=sr.SP_ACCESSNUMBER
and T.DEPTH=0 AND T.SP_TESTCODE <> 'Q'
) as T
for xml path('')),1,1,''),
case
when exists (select 1 from AUDIT_TRAIL at where at.ATR_ACCESSNUMBER=sr.SP_ACCESSNUMBER and at.STEPTYPE=2 and at.LIS_SESSION='RFC' ) then
case
when exists (select 1 from SP_TUBES st where st.SP_ACCESSNUMBER=sr.SP_ACCESSNUMBER and st.TUBESTATUS=0 ) then 'PartRecv'
when exists (select 1 from TESTS T where T.REQUESTID=r.REQUESTID and T.RESTYPE IN (null,'0') ) then 'Inc'
--when exists (select 1 from TESTS T where T.REQUESTID=r.REQUESTID and T.RESTYPE IN (null,'0') and T.TESTID='1805' ) then 'Inc'
else 'Comp'
end
-- inc
when exists (select 1 from TESTS T where T.RESTYPE not in (0,4) and T.REQUESTID=r.REQUESTID ) then
case
when exists ( select 1 from cmod.dbo.CM_TUBES T where T.ACCESSNUMBER=sr.SP_ACCESSNUMBER and T.COLLSTATUS=0 ) then 'PartColl'
when exists (select 1 from SP_TUBES st where st.SP_ACCESSNUMBER=sr.SP_ACCESSNUMBER and st.TUBESTATUS=0 ) then 'PartRecv'
else 'Inc'
end
--rcv
when not exists (select 1 from SP_TUBES st where st.SP_ACCESSNUMBER=sr.SP_ACCESSNUMBER and st.TUBESTATUS=0 ) then
case
when exists (select 1 from cmod.dbo.CM_TUBES T where T.ACCESSNUMBER=sr.SP_ACCESSNUMBER and T.COLLSTATUS=0 ) then 'PartColl'
else 'Recv'
end
--coll
when exists (select 1 FROM cmod.dbo.CM_TUBES T where T.ACCESSNUMBER=sr.SP_ACCESSNUMBER ) then
case
when exists (select 1 from SP_TUBES st where st.SP_ACCESSNUMBER=sr.SP_ACCESSNUMBER and st.TUBESTATUS=4 ) then 'PartRecv'
when not exists (select 1 from cmod.dbo.CM_TUBES T where T.ACCESSNUMBER=sr.SP_ACCESSNUMBER and T.COLLSTATUS=0 ) then 'Coll'
when exists (select 1 from cmod.dbo.CM_TUBES T where T.ACCESSNUMBER=sr.SP_ACCESSNUMBER and T.COLLSTATUS=1 ) then 'PartColl'
else 'Pend'
end
else 'Pend'
end STATS
from SP_REQUESTS sr
left join PATIENTS p on p.PATID=sr.PATID
left join REQUESTS r on r.ACCESSNUMBER=sr.SP_ACCESSNUMBER
left join cmod.dbo.CM_TM_REQUESTS tr on tr.REFFID = sr.HOSTORDERNUMBER
where sr.COLLECTIONDATE between '$date1 00:00' and '$date2 23:59'"
.$filter_query.
"order by sr.COLLECTIONDATE desc";
$query = $db->query($sql);
$results = $query->getResultArray();
2024-11-21 15:38:56 +07:00
$data['data'] = $results;
2024-11-22 16:36:40 +07:00
$data['count'] = array_count_values(array_column($results, 'STATS'));
2024-11-21 15:38:56 +07:00
return $this->respond($data,200);
}
}