diff --git a/app/Http/Controllers/Staff/AuditLogController.php b/app/Http/Controllers/Staff/AuditLogController.php new file mode 100644 index 0000000..8d59403 --- /dev/null +++ b/app/Http/Controllers/Staff/AuditLogController.php @@ -0,0 +1,51 @@ +getStudy(); + $sql = <<<'SQL' +SELECT + aud.user_id, + usr.display_name AS user_name, + aud.category, + aud.activity, + aud.ip_addr, + aud.user_agent, + aud.orthanc_uuid, + aud.url, + aud.notes, + aud.created_at +FROM + audit_logs AS aud + INNER JOIN users AS usr ON aud.user_id = usr."id" +WHERE + aud.study_id = :id +ORDER BY + aud."id" DESC +SQL; + // $logs = DB::select($sql, ['id' => $study->id]); + $logs = DB::table('audit_logs') + ->leftjoin('users', 'users.id', '=', 'audit_logs.user_id') + ->selectRaw('users.display_name as user_name, audit_logs.*') + ->orderBy('audit_logs.id') + ->where('audit_logs.study_id', $study->id) + ->get(); + + $logs->each(function ($log) { + $log->category_name = Category::from($log->category)->name; + $log->activity_name = Str::slug(Activity::from($log->activity)->name); + }); + + return view('staff.audit.popup', compact('study', 'logs')); + } +} diff --git a/app/Services/AuditTrail/Activity.php b/app/Services/AuditTrail/Activity.php index ad47fbb..a9677ca 100644 --- a/app/Services/AuditTrail/Activity.php +++ b/app/Services/AuditTrail/Activity.php @@ -2,47 +2,48 @@ namespace App\Services\AuditTrail; -final class Activity +enum Activity: int { // studies - public const int Study_Open = 101; + case Study_Open = 101; - public const int Study_Metadata_View = 102; + case Study_Metadata_View = 102; - public const int Study_Metadata_Edit = 103; + case Study_Metadata_Edit = 103; - public const int Study_History_View = 104; + case Study_History_View = 104; - public const int Study_History_Update = 105; + case Study_History_Update = 105; - public const int Study_Create = 106; + case Study_Create = 106; - public const int Study_Update = 107; + case Study_Update = 107; - public const int Study_Archive = 108; + case Study_Archive = 108; - public const int Study_Delete = 109; - public const int Study_Lock = 110; - public const int Study_Unlock = 111; + case Study_Delete = 109; + case Study_Lock = 110; + case Study_Unlock = 111; - public const int Attachment_Upload = 112; - public const int Attachment_Download = 113; - public const int Attachment_Delete = 114; + case Attachment_Upload = 112; + case Attachment_Download = 113; + case Attachment_Delete = 114; // report - public const int Report_Save = 201; + case Report_Save = 201; - public const int Report_Delete = 202; + case Report_Delete = 202; - public const int Report_Finalize = 203; + case Report_Finalize = 203; - public const int User_Login = 301; + case User_Login = 301; - public const int User_Failed_Login = 302; + case User_Failed_Login = 302; - public const int User_Logout = 303; + case User_Logout = 303; + + case Assign_Physician = 401; + case Unassign_Physician = 402; - public const int Assign_Physician = 401; - public const int Unassign_Physician = 402; } diff --git a/app/Services/AuditTrail/Category.php b/app/Services/AuditTrail/Category.php index 7bbaad1..caf69b7 100644 --- a/app/Services/AuditTrail/Category.php +++ b/app/Services/AuditTrail/Category.php @@ -2,13 +2,13 @@ namespace App\Services\AuditTrail; -final class Category +enum Category: int { - public const int GENERAL = 10; + case GENERAL = 10; - public const int SYSTEM = 20; + case SYSTEM = 20; - public const int PACS = 30; + case PACS = 30; - public const int AUTH = 40; + case AUTH = 40; } diff --git a/resources/views/staff/audit/popup.blade.php b/resources/views/staff/audit/popup.blade.php new file mode 100644 index 0000000..48d3ae1 --- /dev/null +++ b/resources/views/staff/audit/popup.blade.php @@ -0,0 +1,14 @@ +
{{ $log->created_at }} | +{{ $log->user_name }} | +{{ $log->category_name }} | +{{ $log->activity_name }} | +{{ $log->ip_addr }} | +{{ Illuminate\Support\Str::limit($log->user_agent, 20) }} | +{{ $log->notes }} | +{{ $log->url }} | +