Compare commits
2 Commits
c3ad3ca9fd
...
6b3a4bfceb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b3a4bfceb | ||
|
|
d194ea3030 |
@@ -14,12 +14,14 @@ use App\Services\DateRangeService;
|
||||
use App\Services\DutyMedicalHistoryService;
|
||||
use App\Services\DutyReportService;
|
||||
use App\Services\MedicalHistoryService;
|
||||
use App\Services\MetrikaService;
|
||||
use App\Services\NurseMedicalHistoryService;
|
||||
use App\Services\NurseReportService;
|
||||
use App\Services\UnifiedMedicalHistoryService;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Inertia\Inertia;
|
||||
|
||||
@@ -31,6 +33,7 @@ class DutyReportController extends Controller
|
||||
protected DutyMedicalHistoryService $dutyMedicalHistoryService,
|
||||
protected DutyReportService $dutyReportService,
|
||||
protected NurseMedicalHistoryService $nurseMedicalHistoryService,
|
||||
protected MetrikaService $metrikaService,
|
||||
)
|
||||
{}
|
||||
|
||||
@@ -59,7 +62,7 @@ class DutyReportController extends Controller
|
||||
->where('period_start', '>=', $dateRange->startSql())
|
||||
->where('period_end', '<=', $dateRange->endSql())
|
||||
->orderBy('period_end', 'desc')
|
||||
->with(['unwantedEvents', 'doctor'])
|
||||
->with(['unwantedEvents', 'doctor', 'metrikaResult'])
|
||||
->get();
|
||||
|
||||
$reportsNurse = ReportNurse::where('rf_department_id', $departmentId)
|
||||
@@ -109,7 +112,8 @@ class DutyReportController extends Controller
|
||||
|
||||
$latestReport = $reportsDuty->first();
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Для прошедшего периода - данные из отчета
|
||||
$patients = $hasDutyReport
|
||||
? $this->dutyMedicalHistoryService->getGroupedHistories(
|
||||
@@ -146,7 +150,7 @@ class DutyReportController extends Controller
|
||||
'canSaveReport' => $isRangeOneDay && $user->currentRoleCan('report.create'),
|
||||
'canEditPastReport' => $user->currentRoleCan('report.edit.past'),
|
||||
'canSaveNurseReport' => $isRangeOneDay && $user->currentRoleCan('nurse.report.create'),
|
||||
'stats' => $this->prepareStats($patients, $nursePatients, $loaded, $bedsInDepartment),
|
||||
'stats' => $this->prepareStats($reportsDuty, $patients, $nursePatients, $loaded, $bedsInDepartment),
|
||||
'dates' => [
|
||||
$dateRange->startDate->getTimestampMs(),
|
||||
$dateRange->endDate->getTimestampMs(),
|
||||
@@ -281,7 +285,7 @@ class DutyReportController extends Controller
|
||||
/**
|
||||
* Подготавливает статистику для отображения на фронтенде
|
||||
*/
|
||||
private function prepareStats(array $patients, array $nursePatients, int $loaded, ?int $bedsInDepartment): array
|
||||
private function prepareStats(Collection $reportsDuty, array $patients, array $nursePatients, int $loaded, ?int $bedsInDepartment): array
|
||||
{
|
||||
$deceased = $patients['meta']['counts']['deceased'] ?? 0; // Умершие
|
||||
$discharged = $patients['meta']['counts']['discharged'] ?? 0; // Выписанные
|
||||
@@ -290,6 +294,8 @@ class DutyReportController extends Controller
|
||||
? round(($deceased / $discharged) * 100, 2)
|
||||
: 0;
|
||||
|
||||
$baseMetrics = $this->metrikaService->calculateBaseStatistics($reportsDuty);
|
||||
|
||||
return [
|
||||
'nurse' => [
|
||||
'current' => !empty($nursePatients)
|
||||
@@ -305,13 +311,14 @@ class DutyReportController extends Controller
|
||||
'duty' => [
|
||||
'beds' => $bedsInDepartment ?? 0,
|
||||
'loaded' => $loaded,
|
||||
'current' => $patients['meta']['counts']['in_department'] ?? 0,
|
||||
'recipient' => $patients['meta']['counts']['recipient'] ?? 0,
|
||||
'discharged' => ($patients['meta']['counts']['discharged'] ?? 0) + ($patients['meta']['counts']['deceased'] ?? 0),
|
||||
'current' => $baseMetrics['current'],// $patients['meta']['counts']['in_department'] ?? 0,
|
||||
'recipient' => $baseMetrics['recipient'] ?? 0,
|
||||
'discharged' => $baseMetrics['outcome'] + ($patients['meta']['counts']['deceased'] ?? 0), //($patients['meta']['counts']['discharged'] ?? 0) + ($patients['meta']['counts']['deceased'] ?? 0),
|
||||
'deceased' => $patients['meta']['counts']['deceased'] ?? 0,
|
||||
'lethality' => $lethality,
|
||||
'surgical_planned' => $patients['meta']['counts']['surgical_planned'] ?? 0,
|
||||
'surgical_urgent' => $patients['meta']['counts']['surgical_urgent'] ?? 0,
|
||||
'staff' => $baseMetrics['staff']
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -329,6 +336,12 @@ class DutyReportController extends Controller
|
||||
$unwantedEvents = $request->get('unwanted_events', []);
|
||||
$selectedUserId = $request->get('userId') ? (int) $request->get('userId') : null;
|
||||
$selectedDepartmentId = $request->get('departmentId') ? (int) $request->get('departmentId') : null;
|
||||
|
||||
// Приоритет над метриками (поступило, выбыло, состоит и мед. персонал)
|
||||
$statRecipient = $request->get('recipient') ? (int) $request->get('recipient') : null;
|
||||
$statDischarged = $request->get('discharged') ? (int) $request->get('discharged') : null;
|
||||
$statCurrent = $request->get('current') ? (int) $request->get('current') : null;
|
||||
|
||||
$staff = (int) $request->get('staff', 0);
|
||||
|
||||
$dateRange = $this->dateRangeService->getDateRangeFromRequest($request, $user, extendRangeEnd: false);
|
||||
@@ -337,7 +350,13 @@ class DutyReportController extends Controller
|
||||
$this->dutyReportService->saveObservables($observables, $report);
|
||||
$this->dutyReportService->saveUnwantedEvents($unwantedEvents, $report);
|
||||
|
||||
$this->dutyReportService->saveMetrics($stats, $report, $staff);
|
||||
$statsOverride = [
|
||||
'recipient' => $statRecipient,
|
||||
'outcome' => $statDischarged,
|
||||
'in_department' => $statCurrent
|
||||
];
|
||||
|
||||
$this->dutyReportService->saveMetrics($stats, $report, $staff, $statsOverride);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
@@ -357,6 +376,8 @@ class DutyReportController extends Controller
|
||||
'observable_out' => $dateRange->endDate,
|
||||
'out_reason' => 'Закрыто пользователем'
|
||||
]);
|
||||
|
||||
return response()->json()->setStatusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,6 +70,11 @@ class ReportDuty extends Model
|
||||
return $this->hasMany(DutyUnwantedEvent::class, 'report_duty_id', 'id');
|
||||
}
|
||||
|
||||
public function metrikaResult()
|
||||
{
|
||||
return $this->hasMany(DutyReportMetricResult::class, 'rf_report_id', 'id');
|
||||
}
|
||||
|
||||
public function getLoadedDepartmentAttribute(int $patientsInDepartment)
|
||||
{
|
||||
$beds = DutyReportMetricResult::where('rf_report_id', $this->id)
|
||||
|
||||
@@ -921,16 +921,19 @@ class DutyReportService
|
||||
];
|
||||
}
|
||||
|
||||
public function saveMetrics(array $stats, ReportDuty $reportDuty, int $staff = 0)
|
||||
public function saveMetrics(array $stats, ReportDuty $reportDuty, int $staff = 0, array $statsOverride = [])
|
||||
{
|
||||
$byStatus = $stats['by_status'] ?? [];
|
||||
$byUrgency = $stats['by_urgency'] ?? [];
|
||||
$admitted = $stats['admitted'] ?? [];
|
||||
|
||||
// === Базовые счётчики ===
|
||||
$patientsIsRecipient = $byStatus['recipient'] ?? 0;
|
||||
$patientsInDepartment = $byStatus['in_department'] ?? 0;
|
||||
$patientsIsDischarged = $stats['outcome'] ?? 0;
|
||||
$patientsIsRecipient = array_key_exists('recipient', $statsOverride) && !empty($statsOverride['recipient'])
|
||||
? $statsOverride['recipient'] : $byStatus['recipient'] ?? 0;
|
||||
$patientsInDepartment = array_key_exists('in_department', $statsOverride) && !empty($statsOverride['in_department'])
|
||||
? $statsOverride['in_department'] : $byStatus['in_department'] ?? 0;
|
||||
$patientsIsDischarged = array_key_exists('outcome', $statsOverride) && !empty($statsOverride['outcome'])
|
||||
? $statsOverride['outcome'] : $byStatus['outcome'] ?? 0;
|
||||
$patientsIsTransferred = $stats['transferred'] ?? 0;
|
||||
$patientsIsDeceased = $byStatus['deceased'] ?? 0;
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ use App\Models\MedicalHistory;
|
||||
use App\Models\MedicalHistorySnapshot;
|
||||
use App\Models\Report;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MetrikaService
|
||||
{
|
||||
@@ -110,4 +112,32 @@ class MetrikaService
|
||||
|
||||
return $metrics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Подсчитывает базовую статистику для отчетов дежурного врача
|
||||
* Поступило, выбыло, состоит и мед. персонал
|
||||
* @param Collection $reportsDuty
|
||||
* @return array
|
||||
*/
|
||||
public function calculateBaseStatistics(Collection $reportsDuty): array
|
||||
{
|
||||
$reportIds = $reportsDuty->pluck('id'); // получаем ID всех отчётов
|
||||
|
||||
// Один запрос, который сразу возвращает суммы по каждому типу
|
||||
$totals = DB::table('duty_report_metric_results')
|
||||
->whereIn('rf_report_id', $reportIds) // предполагаем внешний ключ `report_id`
|
||||
->whereIn('rf_metrika_item_id', [3, 7, 8, 17])
|
||||
->select('rf_metrika_item_id', DB::raw('SUM(value::integer) as total'))
|
||||
->groupBy('rf_metrika_item_id')
|
||||
->pluck('total', 'rf_metrika_item_id')
|
||||
->toArray();
|
||||
|
||||
// Формируем итоговый массив с ключами, как у вас
|
||||
return [
|
||||
'recipient' => $totals[3] ?? 0,
|
||||
'outcome' => $totals[7] ?? 0,
|
||||
'current' => $totals[8] ?? 0,
|
||||
'staff' => $totals[17] ?? 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,10 +120,10 @@ const latestReportObj = ref(props.latestReport ?? {
|
||||
const loading = ref(false)
|
||||
const showUnwantedEventModal = ref(false)
|
||||
const reportForm = ref({
|
||||
recipient: props.stats.nurse.recipient,
|
||||
discharged: props.stats.nurse.discharged,
|
||||
current: props.stats.nurse.current,
|
||||
staff: 0,
|
||||
recipient: props.stats.duty.recipient,
|
||||
discharged: props.stats.duty.discharged,
|
||||
current: props.stats.duty.current,
|
||||
staff: props.stats.duty.staff,
|
||||
observables: []
|
||||
})
|
||||
const updateReportForm = (form) => {
|
||||
@@ -199,9 +199,9 @@ const syncPageProps = (pageProps = props) => {
|
||||
latestReportObj.value = pageProps.latestReport ?? { unwanted_events: [] }
|
||||
reportForm.value = {
|
||||
...reportForm.value,
|
||||
recipient: pageProps.stats.nurse.recipient,
|
||||
discharged: pageProps.stats.nurse.discharged,
|
||||
current: pageProps.stats.nurse.current,
|
||||
recipient: pageProps.stats.duty.recipient,
|
||||
discharged: pageProps.stats.duty.discharged,
|
||||
current: pageProps.stats.duty.current,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user