This commit adds comprehensive audit logging for specimen requests and sample collection activities across all roles. Changes Summary: New Features: - Added AUDIT_EVENTS table schema for tracking validation and sample collection events - Created ApiRequestsAuditController with /api/requests/(:any)/audit endpoint to retrieve audit history - Added dialog_audit.php view component for displaying audit trails in UI - Integrated audit logging into validation workflow (VAL1, VAL2, UNVAL events) Database: - Created AUDIT_EVENTS table with columns: ACCESSNUMBER, EVENT_TYPE, USERID, EVENT_AT, REASON - Supports tracking validation events and sample collection actions Controllers: - RequestsController: Now inserts audit records for all validation operations - ApiRequestsAuditController: New API controller returning validation and sample collection history Routes: - Added GET /api/requests/(:any)/audit endpoint for retrieving audit trail - Removed DELETE /api/samples/collect/(:any) endpoint (uncollect functionality) Views Refactoring: - Consolidated dashboard layouts into shared components: - layout.php (from layout_dashboard.php) - script_requests.php (from script_dashboard.php) - script_validation.php (from script_validate.php) - content_requests.php (from dashboard_table.php) - content_validation.php (from dashboard_validate.php) - Added content_validation_new.php for enhanced validation interface
53 lines
1.9 KiB
PHP
53 lines
1.9 KiB
PHP
<?php
|
|
namespace App\Controllers;
|
|
use App\Controllers\BaseController;
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
class ApiRequestsAuditController extends BaseController {
|
|
use ResponseTrait;
|
|
|
|
public function show($accessnumber) {
|
|
$db = \Config\Database::connect();
|
|
|
|
$result = [
|
|
'accessnumber' => $accessnumber,
|
|
'validation' => [],
|
|
'sample_collection' => []
|
|
];
|
|
|
|
$sqlAudit = "SELECT EVENT_TYPE, USERID, EVENT_AT, REASON
|
|
FROM GDC_CMOD.dbo.AUDIT_EVENTS
|
|
WHERE ACCESSNUMBER = ?
|
|
ORDER BY EVENT_AT ASC";
|
|
$auditRows = $db->query($sqlAudit, [$accessnumber])->getResultArray();
|
|
|
|
foreach ($auditRows as $row) {
|
|
$isUnval = $row['EVENT_TYPE'] === 'UNVAL';
|
|
$result['validation'][] = [
|
|
'type' => $row['EVENT_TYPE'],
|
|
'user' => trim($row['USERID']),
|
|
'datetime' => $row['EVENT_AT'] ? date('Y-m-d H:i:s', strtotime($row['EVENT_AT'])) : null,
|
|
'reason' => $isUnval ? trim($row['REASON']) : null
|
|
];
|
|
}
|
|
|
|
$sqlTube = "SELECT TUBENUMBER, USERID, STATUS, LOGDATE
|
|
FROM GDC_CMOD.dbo.AUDIT_TUBES
|
|
WHERE ACCESSNUMBER = ?
|
|
ORDER BY LOGDATE ASC";
|
|
$tubeRows = $db->query($sqlTube, [$accessnumber])->getResultArray();
|
|
|
|
foreach ($tubeRows as $row) {
|
|
$action = $row['STATUS'] == 1 ? 'COLLECTED' : 'UNRECEIVED';
|
|
$result['sample_collection'][] = [
|
|
'tubenumber' => trim($row['TUBENUMBER']),
|
|
'user' => trim($row['USERID']),
|
|
'datetime' => $row['LOGDATE'] ? date('Y-m-d H:i:s', strtotime($row['LOGDATE'])) : null,
|
|
'action' => $action
|
|
];
|
|
}
|
|
|
|
return $this->respond(['status' => 'success', 'data' => $result]);
|
|
}
|
|
}
|