49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Web;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Department;
|
|
use App\Services\DateRangeService;
|
|
use App\Services\ReportPageService;
|
|
use App\Services\ReportService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Inertia\Inertia;
|
|
|
|
class ReportController extends Controller
|
|
{
|
|
public function __construct(
|
|
protected ReportPageService $reportPageService,
|
|
protected ReportService $reportService,
|
|
protected DateRangeService $dateRangeService
|
|
) {}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$user = Auth::user();
|
|
$departmentId = $request->query('departmentId', $user->department->department_id);
|
|
$department = Department::where('department_id', $departmentId)->firstOrFail();
|
|
$dateRange = $this->dateRangeService->getDateRangeFromRequest($request, $user);
|
|
|
|
return Inertia::render('Report/Index', $this->reportPageService->build($department, $user, $dateRange));
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
'metrics' => 'required|array',
|
|
'observationPatients' => 'nullable|array',
|
|
'departmentId' => 'required|integer',
|
|
'unwantedEvents' => 'nullable|array',
|
|
'dates' => 'required|array',
|
|
'userId' => 'required|integer',
|
|
'reportId' => 'nullable|integer'
|
|
]);
|
|
|
|
$this->reportService->storeReport($validated, Auth::user(), false);
|
|
|
|
return redirect()->route('start');
|
|
}
|
|
}
|