Перевод на доменную архитектуру
This commit is contained in:
144
app/Infrastructure/Reports/Sources/MisPatientSource.php
Normal file
144
app/Infrastructure/Reports/Sources/MisPatientSource.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace App\Infrastructure\Reports\Sources;
|
||||
|
||||
use App\Data\UnifiedPatientData;
|
||||
use App\Models\User;
|
||||
use App\Services\DateRange;
|
||||
use App\Services\PatientService;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class MisPatientSource
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PatientService $patientService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Загрузить пациентов из МИС и нормализовать их в DTO для отчёта.
|
||||
*/
|
||||
public function getDtos(
|
||||
User $user,
|
||||
string $status,
|
||||
DateRange $dateRange,
|
||||
int $branchId,
|
||||
?bool $includeCurrent = null,
|
||||
bool $fillableAuto = false,
|
||||
bool $forSnapshots = false
|
||||
): Collection {
|
||||
return $this->getPatients($user, $status, $dateRange, $branchId, $includeCurrent, $fillableAuto, $forSnapshots)
|
||||
->map(fn ($patient) => UnifiedPatientData::fromMisMedicalHistory(
|
||||
$patient,
|
||||
(bool) ($patient->is_recipient_today ?? false),
|
||||
))
|
||||
->sortByDesc(fn (UnifiedPatientData $patient) => $patient->admittedAt ?? '')
|
||||
->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Загрузить сырые MIS-модели пациентов для запрошенного статуса отчёта.
|
||||
*/
|
||||
public function getPatients(
|
||||
User $user,
|
||||
string $status,
|
||||
DateRange $dateRange,
|
||||
int $branchId,
|
||||
?bool $includeCurrent = null,
|
||||
bool $fillableAuto = false,
|
||||
bool $forSnapshots = false
|
||||
): Collection {
|
||||
$isHeadOrAdmin = $user->isHeadOfDepartment() || $user->isAdmin();
|
||||
$includeCurrent = $includeCurrent ?? in_array($status, ['plan', 'emergency'], true);
|
||||
|
||||
return match ($status) {
|
||||
'plan', 'emergency' => $this->patientService->getPlanOrEmergencyPatients(
|
||||
$status,
|
||||
$isHeadOrAdmin,
|
||||
$branchId,
|
||||
$dateRange,
|
||||
false,
|
||||
false,
|
||||
$includeCurrent,
|
||||
$fillableAuto
|
||||
),
|
||||
'current' => $this->patientService->getAllPatientsInDepartment(
|
||||
$isHeadOrAdmin,
|
||||
$branchId,
|
||||
$dateRange,
|
||||
false,
|
||||
false,
|
||||
$fillableAuto
|
||||
),
|
||||
'recipient' => $this->patientService->getPlanOrEmergencyPatients(
|
||||
null,
|
||||
$isHeadOrAdmin,
|
||||
$branchId,
|
||||
$dateRange,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
$fillableAuto
|
||||
),
|
||||
'outcome' => $this->patientService->getOutcomePatients($branchId, $dateRange, 'without-transferred'),
|
||||
'outcome-discharged' => $this->patientService->getOutcomePatients($branchId, $dateRange, 'discharged'),
|
||||
'outcome-transferred' => $this->patientService->getOutcomePatients($branchId, $dateRange, 'transferred'),
|
||||
'outcome-deceased' => $this->patientService->getOutcomePatients($branchId, $dateRange, 'deceased'),
|
||||
'reanimation' => $this->patientService->getReanimationPatients($branchId, $dateRange),
|
||||
default => collect(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Посчитать MIS-пациентов без материализации DTO.
|
||||
*/
|
||||
public function getCount(
|
||||
User $user,
|
||||
string $status,
|
||||
DateRange $dateRange,
|
||||
int $branchId,
|
||||
?bool $includeCurrent = null,
|
||||
bool $fillableAuto = false
|
||||
): int {
|
||||
$isHeadOrAdmin = $user->isHeadOfDepartment() || $user->isAdmin();
|
||||
$includeCurrent = $includeCurrent ?? in_array($status, ['plan', 'emergency'], true);
|
||||
|
||||
return match ($status) {
|
||||
'plan', 'emergency' => $includeCurrent
|
||||
? $this->patientService->getPatientsCountWithCurrent($status, $isHeadOrAdmin, $branchId, $dateRange)
|
||||
: $this->patientService->getPlanOrEmergencyPatients(
|
||||
$status,
|
||||
$isHeadOrAdmin,
|
||||
$branchId,
|
||||
$dateRange,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
$fillableAuto
|
||||
),
|
||||
'current' => $this->patientService->getAllPatientsInDepartment(
|
||||
$isHeadOrAdmin,
|
||||
$branchId,
|
||||
$dateRange,
|
||||
true,
|
||||
false,
|
||||
$fillableAuto
|
||||
),
|
||||
'recipient' => $this->patientService->getPlanOrEmergencyPatients(
|
||||
null,
|
||||
$isHeadOrAdmin,
|
||||
$branchId,
|
||||
$dateRange,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
$fillableAuto
|
||||
),
|
||||
'outcome' => $this->patientService->getOutcomePatients($branchId, $dateRange, 'without-transferred', true)->count(),
|
||||
'outcome-discharged' => $this->patientService->getOutcomePatients($branchId, $dateRange, 'discharged', true)->count(),
|
||||
'outcome-transferred' => $this->patientService->getOutcomePatients($branchId, $dateRange, 'transferred', true)->count(),
|
||||
'outcome-deceased' => $this->patientService->getOutcomePatients($branchId, $dateRange, 'deceased', true)->count(),
|
||||
'reanimation' => $this->patientService->getReanimationPatients($branchId, $dateRange, true)->count(),
|
||||
default => 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user