Перевод на DDD
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Infrastructure\Http\Controllers\Web;
|
||||
|
||||
use App\Domain\ReportDuty\Actions\CreateReportDutyAction;
|
||||
use App\Domain\ReportDuty\Actions\GenerateAndSaveReportSnapshotAction;
|
||||
use App\Domain\ReportDuty\Actions\SaveObservablePatientsAction;
|
||||
use App\Domain\ReportDuty\DTO\CreateReportDutyDto;
|
||||
use App\Infrastructure\Http\Requests\CreateDutyReportRequest;
|
||||
use App\Services\DateRange;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class DutyReportController
|
||||
{
|
||||
public function store(
|
||||
CreateDutyReportRequest $request,
|
||||
CreateReportDutyAction $createAction,
|
||||
GenerateAndSaveReportSnapshotAction $snapshotAction
|
||||
) {
|
||||
// Валидация уже выполнена в FormRequest
|
||||
$validated = $request->validated();
|
||||
|
||||
// Создаём DTO и DateRange
|
||||
$dateRange = new DateRange(
|
||||
$validated['period_start'],
|
||||
$validated['period_end']
|
||||
);
|
||||
|
||||
$dto = new CreateReportDutyDto(
|
||||
reportDate: $dateRange->endSql(),
|
||||
periodStart: $dateRange->startSql(),
|
||||
periodEnd: $dateRange->endSql(),
|
||||
periodType: $validated['period_type'] ?? 'day',
|
||||
statusId: $validated['status_id'] ?? 2,
|
||||
rfLpuDoctorId: $request->user()->rf_lpudoctor_id,
|
||||
rfDepartmentId: $request->user()->rf_department_id,
|
||||
rfUserId: $request->user()->id,
|
||||
);
|
||||
|
||||
// Вызов Use Case для создания отчёта
|
||||
$report = $createAction->execute($dto);
|
||||
|
||||
// Вызов Use Case для сохранения снимка и расчёта статистики
|
||||
$stats = $snapshotAction->execute(
|
||||
$report,
|
||||
$dateRange,
|
||||
$request->user()->rf_department_id,
|
||||
$request->user()->id
|
||||
);
|
||||
|
||||
// Сохраняем наблюдаемых пациентов и нежелательные события
|
||||
if ($request->has('observables')) {
|
||||
$observableAction = app(SaveObservablePatientsAction::class);
|
||||
$observableAction->execute($report, $validated['observables']);
|
||||
}
|
||||
|
||||
if ($request->has('unwanted_events')) {
|
||||
$unwantedAction = app(SaveUnwantedEventsAction::class);
|
||||
$unwantedAction->execute($report, $validated['unwanted_events']);
|
||||
}
|
||||
|
||||
// Возвращаем Inertia-ответ (редирект или рендер)
|
||||
return Inertia::location(route('reports.duty.show', $report->id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Infrastructure\Http\Controllers\Web;
|
||||
|
||||
use App\Domain\Patient\Actions\GetDepartmentJournalPatientAction;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PatientController
|
||||
{
|
||||
public function getDepartmentPatient(
|
||||
Request $request,
|
||||
GetDepartmentJournalPatientAction $patientAction
|
||||
)
|
||||
{
|
||||
$departmentId = $request->query('departmentId');
|
||||
|
||||
$patients = $patientAction->execute((int) $departmentId);
|
||||
|
||||
return response()->json($patients);
|
||||
}
|
||||
}
|
||||
27
app/Infrastructure/Http/Requests/CreateDutyReportRequest.php
Normal file
27
app/Infrastructure/Http/Requests/CreateDutyReportRequest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Infrastructure\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateDutyReportRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'period_start' => ['required', 'date'],
|
||||
'period_end' => ['required', 'date', 'after_or_equal:period_start'],
|
||||
'period_type' => ['nullable', 'string', 'in:day,week,month'],
|
||||
'status_id' => ['nullable', 'integer', 'in:1,2,3'],
|
||||
'observables' => ['nullable', 'array'],
|
||||
'observables.*.id' => ['required', 'integer'],
|
||||
'unwanted_events' => ['nullable', 'array'],
|
||||
'unwanted_events.*.title' => ['required', 'string'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user