Много всего

This commit is contained in:
brusnitsyn
2025-12-12 17:10:05 +09:00
parent 54f36e91fa
commit 98e9f8b52e
25 changed files with 1118 additions and 145 deletions

View File

@@ -3,7 +3,10 @@
namespace App\Http\Controllers;
use App\Http\Resources\ArchiveHistoryResource;
use App\Http\Resources\ArchiveInfoResource;
use App\Models\ArchiveHistory;
use App\Models\ArchiveInfo;
use App\Rules\DateTimeOrStringOrNumber;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
@@ -21,22 +24,20 @@ class ArchiveHistoryController extends Controller
return response()->json($archiveHistory);
}
public function move(Request $request)
public function moveStore(Request $request)
{
$data = $request->validate([
'issue_at' => 'nullable|numeric:',
'return_at' => 'nullable|numeric:',
'issue_at' => ['nullable', new DateTimeOrStringOrNumber],
'return_at' => ['nullable', new DateTimeOrStringOrNumber],
'org_id' => 'required|numeric',
'employee_name' => 'nullable|string',
'employee_post' => 'nullable|string',
'comment' => 'nullable|string',
'has_lost' => 'boolean',
'historyable_id' => 'nullable|numeric',
'historyable_type' => 'required|string',
]);
// Находим связанную модель ??
$historyable = SttMedicalHistory::findOrFail($data['historyable_id']);
// Преобразуем timestamp в дату, если пришли числа
if (isset($data['issue_at']) && is_numeric($data['issue_at'])) {
$data['issue_at'] = Carbon::createFromTimestampMs($data['issue_at'])->format('Y-m-d');
@@ -48,6 +49,89 @@ class ArchiveHistoryController extends Controller
$archiveHistory = ArchiveHistory::create($data);
// Если переданы данные для полиморфной связи
if ($request->filled('historyable_id') && $request->filled('historyable_type')) {
// Найти связанную модель
$historyableClass = $request->input('historyable_type');
// Проверяем, существует ли класс модели
if (class_exists($historyableClass)) {
$historyableModel = $historyableClass::find($request->input('historyable_id'));
if ($historyableModel) {
// Связываем модели
$archiveHistory->historyable()->associate($historyableModel);
$archiveHistory->save();
}
}
}
return response()->json(ArchiveHistoryResource::make($archiveHistory));
}
public function moveUpdate($id, Request $request)
{
$data = $request->validate([
'issue_at' => ['nullable', new DateTimeOrStringOrNumber],
'return_at' => ['nullable', new DateTimeOrStringOrNumber],
'org_id' => 'required|numeric',
'employee_name' => 'nullable|string',
'employee_post' => 'nullable|string',
'comment' => 'nullable|string',
'has_lost' => 'boolean',
'historyable_id' => 'nullable|numeric',
'historyable_type' => 'required|string',
]);
// Преобразуем timestamp в дату, если пришли числа
if (isset($data['issue_at']) && is_numeric($data['issue_at'])) {
$data['issue_at'] = Carbon::createFromTimestampMs($data['issue_at'])->format('Y-m-d');
}
if (isset($data['return_at']) && is_numeric($data['return_at'])) {
$data['return_at'] = Carbon::createFromTimestampMs($data['return_at'])->format('Y-m-d');
}
$archiveHistory = ArchiveHistory::find($id);
$hasUpdated = $archiveHistory->update($data);
return response()->json(ArchiveHistoryResource::make($archiveHistory));
}
public function infoUpdate($patientId, Request $request)
{
$data = $request->validate([
'id' => 'required|numeric',
'num' => 'nullable|string',
'post_in' => ['nullable', new DateTimeOrStringOrNumber],
'historyable_type' => 'required|string',
]);
// Преобразуем timestamp в дату, если пришли числа
if (isset($data['post_in']) && is_numeric($data['post_in'])) {
$data['post_in'] = Carbon::createFromTimestampMs($data['post_in'])->format('Y-m-d');
}
if ($patientId && $request->filled('historyable_type')) {
// Найти связанную модель
$historyableClass = $request->input('historyable_type');
// Проверяем, существует ли класс модели
if (class_exists($historyableClass)) {
$historyableModel = $historyableClass::find($patientId);
if ($historyableModel) {
// Связываем модели
$historyableModel->archiveInfo()->updateOrCreate([
'historyable_type' => $historyableClass,
'historyable_id' => $patientId,
], $data);
return response()->json(ArchiveInfoResource::make($historyableModel->archiveInfo));
}
}
}
return response()->json()->setStatusCode(500);
}
}