Шаблон отчета дежурного врача
This commit is contained in:
41
app/Exports/DutyReportExport.php
Normal file
41
app/Exports/DutyReportExport.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\User;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
|
||||
class DutyReportExport implements FromArray, WithTitle
|
||||
{
|
||||
protected array $data;
|
||||
protected array $dateRange;
|
||||
protected User $user;
|
||||
protected Department $department;
|
||||
protected string $reportName;
|
||||
|
||||
public function __construct(
|
||||
array $data,
|
||||
array $dateRange,
|
||||
User $user,
|
||||
Department $department,
|
||||
string $reportName = 'Статистика по отделениям',
|
||||
) {
|
||||
$this->data = $data;
|
||||
$this->dateRange = $dateRange;
|
||||
$this->user = $user;
|
||||
$this->department = $department;
|
||||
$this->reportName = $reportName;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
// TODO: Implement array() method.
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return $this->sheetTitle;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Exports\DutyReportExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\MedicalHistoryResource;
|
||||
use App\Models\Department;
|
||||
@@ -15,11 +16,13 @@ use App\Services\DutyReportService;
|
||||
use App\Services\MedicalHistoryService;
|
||||
use App\Services\NurseMedicalHistoryService;
|
||||
use App\Services\NurseReportService;
|
||||
use App\Services\StatisticsService;
|
||||
use App\Services\UnifiedMedicalHistoryService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Inertia\Inertia;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class DutyReportController extends Controller
|
||||
{
|
||||
@@ -28,7 +31,8 @@ class DutyReportController extends Controller
|
||||
protected MedicalHistoryService $medicalHistoryService,
|
||||
protected DutyMedicalHistoryService $dutyMedicalHistoryService,
|
||||
protected DutyReportService $dutyReportService,
|
||||
protected NurseMedicalHistoryService $nurseMedicalHistoryService
|
||||
protected NurseMedicalHistoryService $nurseMedicalHistoryService,
|
||||
protected StatisticsService $statisticsService
|
||||
)
|
||||
{}
|
||||
|
||||
@@ -356,4 +360,24 @@ class DutyReportController extends Controller
|
||||
'out_reason' => 'Закрыто пользователем'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Формирование отчета дежурного в Excel
|
||||
*/
|
||||
public function generateReport(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$queryStartDate = $request->query('startAt');
|
||||
$queryEndDate = $request->query('endAt');
|
||||
$queryDepartmentId = $request->query('departmentId', $user->department->department_id);
|
||||
|
||||
[$startDate, $endDate] = $this->dateRangeService->getStatisticsDateRange($user, $queryStartDate, $queryEndDate);
|
||||
$isRangeOneDay = $this->dateRangeService->isRangeOneDay($startDate, $endDate);
|
||||
$department = Department::find($queryDepartmentId);
|
||||
|
||||
$finalData = $this->statisticsService->getStatisticsData($user, $startDate, $endDate, $isRangeOneDay, $department->department_id);
|
||||
|
||||
return Excel::download(new DutyReportExport($finalData['data'], [$startDate, $endDate], $user, $department), 'statistics.xlsx');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user