Добавлена страница штаба
Добавлены графики Добавлены события отчетов
This commit is contained in:
42
app/Events/PatientDataChanged.php
Normal file
42
app/Events/PatientDataChanged.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\DepartmentPatient;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class PatientDataChanged implements ShouldBroadcast
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public DepartmentPatient $patient,
|
||||
public string $action
|
||||
) {}
|
||||
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PrivateChannel('headquarters')];
|
||||
}
|
||||
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'patient.changed';
|
||||
}
|
||||
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->patient->department_patient_id,
|
||||
'department_id' => $this->patient->rf_department_id,
|
||||
'full_name' => $this->patient->full_name,
|
||||
'action' => $this->action,
|
||||
'is_current' => $this->patient->is_current,
|
||||
'changed_at' => now()->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
43
app/Events/ReportDutyUpdated.php
Normal file
43
app/Events/ReportDutyUpdated.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\ReportDuty;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ReportDutyUpdated implements ShouldBroadcast
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public ReportDuty $reportDuty,
|
||||
public string $action
|
||||
) {}
|
||||
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PrivateChannel('headquarters')];
|
||||
}
|
||||
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'report-duty.updated';
|
||||
}
|
||||
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->reportDuty->id,
|
||||
'department_id' => $this->reportDuty->rf_department_id,
|
||||
'department' => $this->reportDuty->department?->name_short,
|
||||
'action' => $this->action,
|
||||
'period_start' => $this->reportDuty->period_start?->toISOString(),
|
||||
'period_end' => $this->reportDuty->period_end?->toISOString(),
|
||||
'sent_at' => now()->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
44
app/Events/ReportNurseUpdated.php
Normal file
44
app/Events/ReportNurseUpdated.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\ReportNurse;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ReportNurseUpdated implements ShouldBroadcast
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public ReportNurse $reportNurse,
|
||||
public string $action
|
||||
) {}
|
||||
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PrivateChannel('headquarters')];
|
||||
}
|
||||
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'report-nurse.updated';
|
||||
}
|
||||
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->reportNurse->id,
|
||||
'department_id' => $this->reportNurse->rf_department_id,
|
||||
'department' => $this->reportNurse->department?->name_short,
|
||||
'action' => $this->action,
|
||||
'period_start' => $this->reportNurse->period_start?->toISOString(),
|
||||
'period_end' => $this->reportNurse->period_end?->toISOString(),
|
||||
'sent_at' => now()->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
36
app/Http/Controllers/Api/HeadquartersController.php
Normal file
36
app/Http/Controllers/Api/HeadquartersController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\DateRangeService;
|
||||
use App\Services\StatisticsService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HeadquartersController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected DateRangeService $dateService,
|
||||
protected StatisticsService $statisticsService
|
||||
) {}
|
||||
|
||||
public function stats(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
$dateRange = $this->dateService->getDateRangeFromRequest($request, $user);
|
||||
$isRangeOneDay = $this->dateService->isRangeOneDay($dateRange->startDate, $dateRange->endDate);
|
||||
|
||||
$finalData = $this->statisticsService->getStatisticsData(
|
||||
$user,
|
||||
$dateRange->startDate,
|
||||
$dateRange->endDate,
|
||||
$isRangeOneDay
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'data' => $finalData['data'],
|
||||
'grandTotals' => $finalData['grandTotals'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
42
app/Http/Controllers/Web/HeadquartersController.php
Normal file
42
app/Http/Controllers/Web/HeadquartersController.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\DateRangeService;
|
||||
use App\Services\StatisticsService;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class HeadquartersController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected DateRangeService $dateService,
|
||||
protected StatisticsService $statisticsService
|
||||
) {}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
$dateRange = $this->dateService->getDateRangeFromRequest($request, $user);
|
||||
$isRangeOneDay = $this->dateService->isRangeOneDay($dateRange->startDate, $dateRange->endDate);
|
||||
|
||||
$finalData = $this->statisticsService->getStatisticsData(
|
||||
$user,
|
||||
$dateRange->startDate,
|
||||
$dateRange->endDate,
|
||||
$isRangeOneDay
|
||||
);
|
||||
|
||||
return Inertia::render('Statistic/Headquarters', [
|
||||
'data' => $finalData['data'],
|
||||
'grandTotals' => $finalData['grandTotals'],
|
||||
'isHeadOrAdmin' => $user->isSeniorStaff(),
|
||||
'date' => [
|
||||
$dateRange->startDate->getTimestampMs(),
|
||||
$dateRange->endDate->getTimestampMs(),
|
||||
],
|
||||
'isOneDay' => $isRangeOneDay,
|
||||
]);
|
||||
}
|
||||
}
|
||||
19
app/Observers/DepartmentPatientObserver.php
Normal file
19
app/Observers/DepartmentPatientObserver.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\PatientDataChanged;
|
||||
use App\Models\DepartmentPatient;
|
||||
|
||||
class DepartmentPatientObserver
|
||||
{
|
||||
public function created(DepartmentPatient $patient): void
|
||||
{
|
||||
PatientDataChanged::dispatch($patient, 'created');
|
||||
}
|
||||
|
||||
public function updated(DepartmentPatient $patient): void
|
||||
{
|
||||
PatientDataChanged::dispatch($patient, 'updated');
|
||||
}
|
||||
}
|
||||
19
app/Observers/ReportDutyObserver.php
Normal file
19
app/Observers/ReportDutyObserver.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\ReportDutyUpdated;
|
||||
use App\Models\ReportDuty;
|
||||
|
||||
class ReportDutyObserver
|
||||
{
|
||||
public function created(ReportDuty $reportDuty): void
|
||||
{
|
||||
ReportDutyUpdated::dispatch($reportDuty, 'created');
|
||||
}
|
||||
|
||||
public function updated(ReportDuty $reportDuty): void
|
||||
{
|
||||
ReportDutyUpdated::dispatch($reportDuty, 'updated');
|
||||
}
|
||||
}
|
||||
19
app/Observers/ReportNurseObserver.php
Normal file
19
app/Observers/ReportNurseObserver.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\ReportNurseUpdated;
|
||||
use App\Models\ReportNurse;
|
||||
|
||||
class ReportNurseObserver
|
||||
{
|
||||
public function created(ReportNurse $reportNurse): void
|
||||
{
|
||||
ReportNurseUpdated::dispatch($reportNurse, 'created');
|
||||
}
|
||||
|
||||
public function updated(ReportNurse $reportNurse): void
|
||||
{
|
||||
ReportNurseUpdated::dispatch($reportNurse, 'updated');
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\DepartmentPatient;
|
||||
use App\Models\ReportDuty;
|
||||
use App\Models\ReportNurse;
|
||||
use App\Observers\DepartmentPatientObserver;
|
||||
use App\Observers\ReportDutyObserver;
|
||||
use App\Observers\ReportNurseObserver;
|
||||
use App\Services\Cache\CacheInvalidator;
|
||||
use App\Services\Cache\CacheKeyBuilder;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
@@ -25,6 +31,8 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
ReportNurse::observe(ReportNurseObserver::class);
|
||||
ReportDuty::observe(ReportDutyObserver::class);
|
||||
DepartmentPatient::observe(DepartmentPatientObserver::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user