Files
onboard/app/Services/ReportService.php

293 lines
11 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Services;
use App\Infrastructure\Reports\Services\AutoFillReportPayloadBuilder;
use App\Infrastructure\Reports\Services\ManualPatientManagementService;
use App\Infrastructure\Reports\Services\ObservationPatientManagementService;
use App\Infrastructure\Reports\Services\ReanimationIndicatorService;
use App\Infrastructure\Reports\Services\ReportClinicalSearchService;
use App\Infrastructure\Reports\Services\ReportMetadataReadService;
use App\Infrastructure\Reports\Services\ReportPatientsReadService;
use App\Infrastructure\Reports\Services\ReportRuntimeService;
use App\Infrastructure\Reports\Services\ReportSaveOrchestrator;
use App\Infrastructure\Reports\Services\ReportStatisticsReadService;
use App\Models\Department;
use App\Models\DepartmentPatientOperation;
use App\Models\Report;
use App\Models\ReanimationPatientIndicator;
use App\Models\User;
class ReportService
{
public function __construct(
protected DateRangeService $dateRangeService,
protected UnifiedPatientService $unifiedPatientService,
protected PatientService $patientQueryService,
protected SnapshotService $snapshotService,
protected StatisticsService $statisticsService,
?AutoFillReportPayloadBuilder $autoFillReportPayloadBuilder = null,
?ReportPatientsReadService $reportPatientsReadService = null,
?ReportStatisticsReadService $reportStatisticsReadService = null,
?ManualPatientManagementService $manualPatientManagementService = null,
?ObservationPatientManagementService $observationPatientManagementService = null,
?ReanimationIndicatorService $reanimationIndicatorService = null,
?ReportClinicalSearchService $reportClinicalSearchService = null,
?ReportMetadataReadService $reportMetadataReadService = null,
?ReportSaveOrchestrator $reportSaveOrchestrator = null,
?ReportRuntimeService $reportRuntimeService = null,
) {
$this->autoFillReportPayloadBuilder = $autoFillReportPayloadBuilder ?? app(AutoFillReportPayloadBuilder::class);
$this->reportPatientsReadService = $reportPatientsReadService ?? app(ReportPatientsReadService::class);
$this->reportStatisticsReadService = $reportStatisticsReadService ?? app(ReportStatisticsReadService::class);
$this->manualPatientManagementService = $manualPatientManagementService ?? app(ManualPatientManagementService::class);
$this->observationPatientManagementService = $observationPatientManagementService ?? app(ObservationPatientManagementService::class);
$this->reanimationIndicatorService = $reanimationIndicatorService ?? app(ReanimationIndicatorService::class);
$this->reportClinicalSearchService = $reportClinicalSearchService ?? app(ReportClinicalSearchService::class);
$this->reportMetadataReadService = $reportMetadataReadService ?? app(ReportMetadataReadService::class);
$this->reportSaveOrchestrator = $reportSaveOrchestrator ?? app(ReportSaveOrchestrator::class);
$this->reportRuntimeService = $reportRuntimeService ?? app(ReportRuntimeService::class);
}
protected AutoFillReportPayloadBuilder $autoFillReportPayloadBuilder;
protected ReportPatientsReadService $reportPatientsReadService;
protected ReportStatisticsReadService $reportStatisticsReadService;
protected ManualPatientManagementService $manualPatientManagementService;
protected ObservationPatientManagementService $observationPatientManagementService;
protected ReanimationIndicatorService $reanimationIndicatorService;
protected ReportClinicalSearchService $reportClinicalSearchService;
protected ReportMetadataReadService $reportMetadataReadService;
protected ReportSaveOrchestrator $reportSaveOrchestrator;
protected ReportRuntimeService $reportRuntimeService;
/**
* Получить статистику для отчета
*/
public function getReportStatistics(Department $department, User $user, DateRange $dateRange): array
{
return $this->reportStatisticsReadService->getReportStatistics($department, $user, $dateRange);
}
/**
* Создать или обновить отчет
*/
public function storeReport(array $data, User $user, $fillableAuto = false): Report
{
return $this->reportSaveOrchestrator->storeReport($data, $user, (bool) $fillableAuto);
}
public function prepareForHeavySave(): void
{
$this->reportRuntimeService->prepareForHeavySave();
}
public function syncCalculatedMetricsForStoredReport(Report $report, User $user, array $data): void
{
$this->reportSaveOrchestrator->syncCalculatedMetrics($report, $user, $data);
}
public function finalizeStoredReport(Report $report): void
{
$this->reportSaveOrchestrator->finalizeStoredReport($report);
}
public function saveLethalMetricForStoredReport(Report $report): void
{
$this->reportSaveOrchestrator->saveLethalMetricFromSnapshots($report);
}
public function clearCacheAfterStoredReport(User $user, Report $report): void
{
$this->reportRuntimeService->clearCacheAfterReportCreation($user, $report);
}
public function buildAutoFillReportPayload(User $user, Department $department, DateRange $dateRange): array
{
return $this->autoFillReportPayloadBuilder->build($user, $department, $dateRange);
}
/**
* Получить пациентов по статусу
*/
public function getPatientsByStatus(
Department $department,
User $user,
string $status,
DateRange $dateRange,
bool $onlyIds = false,
bool $beforeCreate = false,
?bool $includeCurrentPatients = null
) {
return $this->reportPatientsReadService->getPatientsByStatus(
$department,
$user,
$status,
$dateRange,
$onlyIds,
$beforeCreate,
$includeCurrentPatients
);
}
/**
* Получить количество пациентов по статусу
*/
public function getPatientsCountByStatus(
Department $department,
User $user,
string $status,
DateRange $dateRange
): int {
return $this->reportPatientsReadService->getPatientsCountByStatus($department, $user, $status, $dateRange);
}
public function getPatientsCountsMap(Department $department, User $user, DateRange $dateRange): array
{
return $this->reportPatientsReadService->getPatientsCountsMap($department, $user, $dateRange);
}
/**
* Получить информацию о текущем отчете
*/
public function getCurrentReportInfo(Department $department, User $user, DateRange $dateRange): array
{
return $this->reportMetadataReadService->getCurrentReportInfo($department, $user, $dateRange);
}
/**
* Удалить пациента из наблюдения
*/
public function removeObservationPatient(string $patientId): void
{
$this->observationPatientManagementService->removeObservationPatient($patientId);
}
public function createManualPatient(Department $department, User $user, array $data)
{
return $this->manualPatientManagementService->createManualPatient($department, $user, $data);
}
public function setManualPatientOutcome(User $user, int $departmentPatientId, array $data)
{
return $this->manualPatientManagementService->setManualPatientOutcome($user, $departmentPatientId, $data);
}
public function updateManualPatient(User $user, int $departmentPatientId, array $data)
{
return $this->manualPatientManagementService->updateManualPatient($user, $departmentPatientId, $data);
}
public function linkManualPatientToMis(int $departmentPatientId, int $medicalHistoryId)
{
return $this->manualPatientManagementService->linkManualPatientToMis($departmentPatientId, $medicalHistoryId);
}
public function getManualPatientOperations(User $user, int $departmentPatientId)
{
return $this->manualPatientManagementService->getManualPatientOperations($user, $departmentPatientId);
}
public function createManualPatientOperation(User $user, int $departmentPatientId, array $data): DepartmentPatientOperation
{
return $this->manualPatientManagementService->createManualPatientOperation($user, $departmentPatientId, $data);
}
public function updateManualPatientOperation(User $user, int $departmentPatientId, int $operationId, array $data): DepartmentPatientOperation
{
return $this->manualPatientManagementService->updateManualPatientOperation($user, $departmentPatientId, $operationId, $data);
}
public function deleteManualPatientOperation(User $user, int $departmentPatientId, int $operationId): void
{
$this->manualPatientManagementService->deleteManualPatientOperation($user, $departmentPatientId, $operationId);
}
public function saveReanimationIndicator(
User $user,
int $departmentId,
int $medicalHistoryId,
string $indicator,
?string $comment = null,
?int $reportId = null
): ReanimationPatientIndicator {
return $this->reanimationIndicatorService->save(
$user,
$departmentId,
$medicalHistoryId,
$indicator,
$comment,
$reportId
);
}
public function getLatestReanimationIndicators(int $departmentId, array $medicalHistoryIds)
{
return $this->reanimationIndicatorService->latestByMedicalHistory($departmentId, $medicalHistoryIds);
}
public function getReanimationIndicatorsHistory(
int $departmentId,
int $medicalHistoryId,
int $limit = 50
) {
return $this->reanimationIndicatorService->history($departmentId, $medicalHistoryId, $limit);
}
public function searchMisPatientsForDepartment(Department $department, string $query)
{
return $this->reportClinicalSearchService->searchMisPatientsForDepartment($department, $query);
}
/**
* Получить пациентов из снапшотов
*/
public function getPatientsFromSnapshots(
Department $department,
string $status,
DateRange $dateRange,
int $branchId,
bool $onlyIds = false
) {
return $this->reportPatientsReadService->getPatientsFromSnapshots(
$department,
$status,
$dateRange,
$branchId,
$onlyIds
);
}
/**
* Получить нежелательные события за дату
*/
public function getUnwantedEvents(Department $department, DateRange $dateRange)
{
return $this->reportMetadataReadService->getUnwantedEvents($department, $dateRange);
}
/**
* Получить отчеты за диапазон дат
*/
public function getReportsForDateRange(int $departmentId, DateRange $dateRange)
{
return $this->reportMetadataReadService->getReportsForDateRange($departmentId, $dateRange);
}
/**
* Получить статистику выполнения плана по госпитализации
*/
public function getRecipientPlanOfYear(Department $department, DateRange $dateRange): array
{
return $this->reportMetadataReadService->getRecipientPlanOfYear($department, $dateRange);
}
}