Files
onboard/app/Domain/ReportDuty/Services/SnapshotDataTransformer.php
2026-07-31 17:19:03 +09:00

72 lines
3.6 KiB
PHP

<?php
namespace App\Domain\ReportDuty\Services;
use App\Domain\ReportDuty\DTO\MigrationSnapshotData;
use App\Domain\ReportDuty\DTO\PatientSnapshotData;
use App\Domain\ReportDuty\DTO\ReanimationSnapshotData;
use Illuminate\Support\LazyCollection;
class SnapshotDataTransformer
{
/**
* @param LazyCollection<int, PatientSnapshotData> $patients
* @return array{patients: LazyCollection<int, PatientSnapshotData>, migrations: LazyCollection<int, MigrationSnapshotData>, reanimations: LazyCollection<int, ReanimationSnapshotData>}
*/
public function transform(LazyCollection $patients): array
{
$migrationsCollect = collect();
$reanimationsCollect = collect();
foreach ($patients as $patient) {
// Для каждой миграции пациента создаём MigrationSnapshotData
foreach ($patient->migrations as $migration) {
$migrationsCollect->push(new MigrationSnapshotData(
id: $migration['id'] ?? 0,
medicalHistoryId: $patient->id,
ingoingDate: $migration['ingoing_date'] ?? null,
outDate: $migration['out_date'] ?? null,
diagnosisId: $migration['diagnosis_id'] ?? null,
diagnosisCode: $migration['diagnosis_code'] ?? null,
diagnosisName: $migration['diagnosis_name'] ?? null,
interruptedEventId: $migration['interrupted_event_id'] ?? null,
stationarBranchId: $migration['stationar_branch_id'] ?? null,
departmentId: $migration['department_id'] ?? null,
visitResultId: $migration['visit_result_id'] ?? null,
statCureResultId: $migration['stat_cure_result_id'] ?? null,
userId: $migration['user_id'] ?? null,
misUserId: $migration['mis_user_id'] ?? null,
comment: $migration['comment'] ?? null,
reanimations: $migration['reanimations'] ?? [],
));
// Для каждой реанимации в миграции
foreach ($migration['reanimations'] ?? [] as $reanimation) {
$reanimationsCollect->push(new ReanimationSnapshotData(
id: $reanimation['id'] ?? 0,
migrationPatientId: $migration['id'] ?? 0,
medicalHistoryId: $patient->id,
inDate: $reanimation['in_date'] ?? null,
outDate: $reanimation['out_date'] ?? null,
description: $reanimation['description'] ?? null,
stationarBranchId: $reanimation['stationar_branch_id'] ?? null,
migrationStationarBranchId: $reanimation['migration_stationar_branch_id'] ?? null,
migrationDepartmentId: $reanimation['migration_department_id'] ?? null,
doctorId: $reanimation['doctor_id'] ?? null,
userId: $reanimation['user_id'] ?? null,
misUserId: $reanimation['mis_user_id'] ?? null,
comment: $reanimation['comment'] ?? null,
));
}
}
}
// Преобразуем в LazyCollection для единообразия
return [
'patients' => $patients, // уже LazyCollection
'migrations' => LazyCollection::make($migrationsCollect),
'reanimations' => LazyCollection::make($reanimationsCollect),
];
}
}