Обновлен стартовый экран

Переписаны запросы для статистики, отчетов
Добавлена интеграция отчета сестры
This commit is contained in:
brusnitsyn
2026-05-28 22:10:00 +09:00
parent 90e0d04dfd
commit 739168d427
96 changed files with 6663 additions and 1465 deletions

View File

@@ -10,6 +10,9 @@ use App\Models\MigrationPatient;
use App\Models\MigrationPatientCorrection;
use App\Models\MigrationPatientNurse;
use App\Models\MisStationarBranch;
use App\Models\ReportNurse;
use App\Models\ReportNurseMigrationPatient;
use App\Models\ReportNursePatient;
use App\Models\UnifiedMedicalHistory;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@@ -146,6 +149,10 @@ class NurseController extends Controller
if ($historyCorrection && $migrationCorrection) {
DB::commit();
// Синхронизируем снапшот, чтобы правки были видны в МИС-вкладке
$reportNurseId = $request->input('report_nurse_id');
$this->syncNurseSnapshot($originalId, $data, $migrationData, $departmentId, $reportNurseId);
return response()->json([
'data' => $historyCorrection,
], 201);
@@ -157,17 +164,64 @@ class NurseController extends Controller
}
}
private function syncNurseSnapshot(
mixed $originalId,
array $data,
array $migrationData,
int $departmentId,
?int $reportNurseId
): void {
$patientUpdate = collect($data)
->only(['recipient_date', 'extract_date', 'death_date', 'urgency_id',
'visit_result_id', 'hospital_result_id', 'full_name', 'birth_date'])
->toArray();
if (empty($patientUpdate)) return;
// Если известен отчёт — обновляем только его и все последующие по этому отделению
$reportNurseQuery = ReportNursePatient::where('original_id', $originalId);
if ($reportNurseId) {
$fromReport = ReportNurse::find($reportNurseId);
if ($fromReport) {
$affectedReportIds = ReportNurse::where('rf_department_id', $fromReport->rf_department_id)
->where('period_start', '>=', $fromReport->period_start)
->pluck('id');
$reportNurseQuery->whereIn('report_nurse_id', $affectedReportIds);
}
}
$snapshotPatientIds = $reportNurseQuery->pluck('id');
if ($snapshotPatientIds->isEmpty()) return;
ReportNursePatient::whereIn('id', $snapshotPatientIds)->update($patientUpdate);
$migrationUpdate = array_filter([
'ingoing_date' => $migrationData['ingoing_date'] ?? null,
'out_date' => $migrationData['out_date'] ?? null,
'visit_result_id' => $migrationData['visit_result_id'] ?? null,
]);
if (!empty($migrationUpdate)) {
ReportNurseMigrationPatient::whereIn('medical_history_id', $snapshotPatientIds)
->where('department_id', $departmentId)
->update($migrationUpdate);
}
}
public function deleteHistory($id, Request $request)
{
$medicalHistory = UnifiedMedicalHistory::where('id', $id)->first();
$medicalHistoryId = $medicalHistory->original_id;
$originalMedicalHistoryId = $medicalHistory->original_id;
$nurseMedicalHistory = ReportNursePatient::where('original_id', $originalMedicalHistoryId)->first();
$migrationPatientsIds = $medicalHistory->migrations()->pluck('original_id');
foreach ($migrationPatientsIds as $migrationPatientsId) {
MigrationPatientNurse::query()->where('id', $migrationPatientsId)->delete();
foreach ($nurseMedicalHistory->migrations() as $nurseMigrationPatient) {
$nurseMigrationPatient->delete();
}
MedicalHistoryNurse::where('id', $medicalHistoryId)->delete();
$nurseMedicalHistory->delete();
return response()->json([]);
}