* изменил таблицы в основном отчете
* изменил метод сохранения пациентов основного отчета
This commit is contained in:
118
app/Http/Controllers/Web/DutyReportController.php
Normal file
118
app/Http/Controllers/Web/DutyReportController.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\MedicalHistoryResource;
|
||||
use App\Models\Department;
|
||||
use App\Models\ReportDuty;
|
||||
use App\Models\ReportNurse;
|
||||
use App\Services\DateRangeService;
|
||||
use App\Services\DutyMedicalHistoryService;
|
||||
use App\Services\DutyReportService;
|
||||
use App\Services\MedicalHistoryService;
|
||||
use App\Services\NurseMedicalHistoryService;
|
||||
use App\Services\NurseReportService;
|
||||
use App\Services\UnifiedMedicalHistoryService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class DutyReportController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected DateRangeService $dateRangeService,
|
||||
protected MedicalHistoryService $medicalHistoryService,
|
||||
protected DutyMedicalHistoryService $dutyMedicalHistoryService,
|
||||
protected DutyReportService $dutyReportService,
|
||||
protected NurseMedicalHistoryService $nurseMedicalHistoryService
|
||||
)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Получение базовой информации для заполнения отчета для дежурного
|
||||
* @param Request $request
|
||||
* @return \Inertia\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$departmentId = $request->query('departmentId', $user->department->department_id);
|
||||
$department = Department::where('department_id', $departmentId)->firstOrFail();
|
||||
$dateRange = $this->dateRangeService->getDateRangeFromRequest($request, $user);
|
||||
|
||||
// Проверяем, есть ли отчет за этот период
|
||||
$isPastPeriod = $this->dateRangeService->isPastPeriod($dateRange);
|
||||
$existsReport = ReportDuty::where('rf_department_id', $departmentId)
|
||||
->where('period_end', '>', $dateRange->startSql())
|
||||
->where('period_end', '<=', $dateRange->endSql())
|
||||
->exists();
|
||||
|
||||
$hasReport = $existsReport && $isPastPeriod;
|
||||
|
||||
if ($hasReport) {
|
||||
$inDepartmentHistories = $this->dutyMedicalHistoryService->getDepartmentHistories($dateRange, $department->rf_mis_department_id);
|
||||
$recipientHistories = $this->dutyMedicalHistoryService->getRecipientHistories($dateRange, $department->rf_mis_department_id);
|
||||
$dischargedHistories = $this->dutyMedicalHistoryService->getDischargedHistories($dateRange, $department->rf_mis_department_id);
|
||||
$deceasedHistories = $this->dutyMedicalHistoryService->getDeceasedHistories($dateRange, $department->rf_mis_department_id);
|
||||
$transferredHistories = $this->dutyMedicalHistoryService->getTransferredHistories($dateRange, $department->rf_mis_department_id);
|
||||
} else if ($this->dateRangeService->isPastPeriod($dateRange)) {
|
||||
$inDepartmentHistories = collect([]);
|
||||
$recipientHistories = collect([]);
|
||||
$dischargedHistories = collect([]);
|
||||
$deceasedHistories = collect([]);
|
||||
$transferredHistories = collect([]);
|
||||
} else {
|
||||
$inDepartmentHistories = MedicalHistoryResource::collection(
|
||||
$this->medicalHistoryService->getDepartmentHistories($dateRange, $department->rf_mis_department_id)
|
||||
);
|
||||
$plannedHistories = MedicalHistoryResource::collection(
|
||||
$this->medicalHistoryService->getPlannedHistories($dateRange, $department->rf_mis_department_id)
|
||||
);
|
||||
$emergencyHistories = MedicalHistoryResource::collection(
|
||||
$this->medicalHistoryService->getEmergencyHistories($dateRange, $department->rf_mis_department_id)
|
||||
);
|
||||
$recipientHistories = MedicalHistoryResource::collection(
|
||||
$this->medicalHistoryService->getRecipientHistories($dateRange, $department->rf_mis_department_id)
|
||||
);
|
||||
$dischargedHistories = MedicalHistoryResource::collection(
|
||||
$this->medicalHistoryService->getDischargedHistories($dateRange, $department->rf_mis_department_id)
|
||||
);
|
||||
$deceasedHistories = MedicalHistoryResource::collection(
|
||||
$this->medicalHistoryService->getDeceasedHistories($dateRange, $department->rf_mis_department_id)
|
||||
);
|
||||
$transferredHistories = MedicalHistoryResource::collection(
|
||||
$this->medicalHistoryService->getTransferredHistories($dateRange, $department->rf_mis_department_id)
|
||||
);
|
||||
}
|
||||
|
||||
return Inertia::render('Report/Index', [
|
||||
'inDepartmentHistories' => $inDepartmentHistories,
|
||||
'plannedHistories' => $plannedHistories,
|
||||
'emergencyHistories' => $emergencyHistories,
|
||||
'recipientHistories' => $recipientHistories,
|
||||
'dischargedHistories' => $dischargedHistories,
|
||||
'deceasedHistories' => $deceasedHistories,
|
||||
'transferredHistories' => $transferredHistories,
|
||||
'dates' => [
|
||||
$dateRange->startDate->getTimestampMs(),
|
||||
$dateRange->endDate->getTimestampMs(),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Сохранение отчета от роли мед. сестра
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$dateRange = $this->dateRangeService->getDateRangeFromRequest($request, $user);
|
||||
$report = $this->dutyReportService->saveReport($dateRange);
|
||||
$this->dutyReportService->saveSnapshot($dateRange, $report);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user