43 lines
1.6 KiB
PHP
43 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Infrastructure\Reports\Sources;
|
|
|
|
use App\Domain\Reports\Contracts\PatientSource;
|
|
use App\Domain\Reports\Models\PatientCollection;
|
|
use App\Domain\Reports\Models\ReportContext;
|
|
use App\Models\Department;
|
|
use App\Models\User;
|
|
use App\Services\DateRange;
|
|
use App\Infrastructure\Reports\Adapters\LegacyReportServiceAdapter;
|
|
use Carbon\Carbon;
|
|
|
|
final readonly class LegacyAutoFillPatientSource implements PatientSource
|
|
{
|
|
public function __construct(
|
|
private LegacyReportServiceAdapter $legacyAdapter,
|
|
) {}
|
|
|
|
public function load(ReportContext $context): PatientCollection
|
|
{
|
|
$department = Department::query()->findOrFail($context->departmentId);
|
|
$user = User::query()->findOrFail($context->actorUserId ?? $context->userId);
|
|
$scopedUser = clone $user;
|
|
$scopedUser->rf_department_id = $department->department_id;
|
|
$scopedUser->setRelation('department', $department);
|
|
$dateRange = new DateRange(
|
|
startDate: Carbon::parse($context->periodStart->format('Y-m-d H:i:s'), 'Asia/Yakutsk'),
|
|
endDate: Carbon::parse($context->periodEnd->format('Y-m-d H:i:s'), 'Asia/Yakutsk'),
|
|
startDateRaw: $context->periodStart->format('Y-m-d H:i:s'),
|
|
endDateRaw: $context->periodEnd->format('Y-m-d H:i:s'),
|
|
isOneDay: $context->periodStart->diff($context->periodEnd)->days <= 1,
|
|
);
|
|
|
|
return new PatientCollection(
|
|
items: [],
|
|
metadata: [
|
|
'payload' => $this->legacyAdapter->buildAutoFillPayload($scopedUser, $department, $dateRange),
|
|
],
|
|
);
|
|
}
|
|
}
|