Много чего

This commit is contained in:
brusnitsyn
2025-12-25 17:30:50 +09:00
parent c4bb7ec6f9
commit a5209f45c8
25 changed files with 1521 additions and 574 deletions

View File

@@ -6,6 +6,7 @@ use App\Http\Resources\ArchiveHistoryResource;
use App\Http\Resources\ArchiveInfoResource;
use App\Models\ArchiveHistory;
use App\Models\ArchiveInfo;
use App\Models\SI\SttMedicalHistory;
use App\Rules\DateTimeOrStringOrNumber;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
@@ -21,7 +22,10 @@ class ArchiveHistoryController extends Controller
{
$archiveHistory = ArchiveHistory::find($id);
return response()->json($archiveHistory);
return response()->json([
...$archiveHistory->toArray(),
'type' => $archiveHistory->historyType()
]);
}
public function moveStore(Request $request)
@@ -34,36 +38,46 @@ class ArchiveHistoryController extends Controller
'employee_post' => 'nullable|string',
'comment' => 'nullable|string',
'has_lost' => 'boolean',
'historyable_id' => 'nullable|numeric',
'historyable_type' => 'required|string',
'archive_info_id' => 'required|numeric',
'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');
$data['issue_at'] = Carbon::createFromTimestampMs($data['issue_at'])
->setTimezone(config('app.timezone'))
->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');
$data['return_at'] = Carbon::createFromTimestampMs($data['return_at'])
->setTimezone(config('app.timezone'))
->format('Y-m-d');
}
$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();
}
}
$archiveInfo = ArchiveInfo::whereId($data['archive_info_id'])->first();
if ($data['type'] === 'mis') {
$archiveHistory = $archiveInfo->misHistory->archiveHistory()->create([
'issue_at' => $data['issue_at'],
'return_at' => $data['return_at'],
'org_id' => $data['org_id'],
'employee_name' => $data['employee_name'],
'employee_post' => $data['employee_post'],
'comment' => $data['comment'],
'has_lost' => $data['has_lost'],
'mis_history_id' => $archiveInfo->mis_history_id
]);
} else {
$archiveHistory = $archiveInfo->foxproHistory->archiveHistory()->create([
'issue_at' => $data['issue_at'],
'return_at' => $data['return_at'],
'org_id' => $data['org_id'],
'employee_name' => $data['employee_name'],
'employee_post' => $data['employee_post'],
'comment' => $data['comment'],
'has_lost' => $data['has_lost'],
'foxpro_history_id' => $archiveInfo->foxpro_history_id,
]);
}
return response()->json(ArchiveHistoryResource::make($archiveHistory));
@@ -79,17 +93,20 @@ class ArchiveHistoryController extends Controller
'employee_post' => 'nullable|string',
'comment' => 'nullable|string',
'has_lost' => 'boolean',
'historyable_id' => 'nullable|numeric',
'historyable_type' => 'required|string',
'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');
$data['issue_at'] = Carbon::createFromTimestampMs($data['issue_at'])
->setTimezone(config('app.timezone'))
->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');
$data['return_at'] = Carbon::createFromTimestampMs($data['return_at'])
->setTimezone(config('app.timezone'))
->format('Y-m-d');
}
$archiveHistory = ArchiveHistory::find($id);
@@ -105,7 +122,8 @@ class ArchiveHistoryController extends Controller
'id' => 'required|numeric',
'num' => 'nullable|string',
'post_in' => ['nullable', new DateTimeOrStringOrNumber],
'historyable_type' => 'required|string',
'status' => 'nullable',
'type' => 'nullable'
]);
// Преобразуем timestamp в дату, если пришли числа
@@ -113,25 +131,16 @@ class ArchiveHistoryController extends Controller
$data['post_in'] = Carbon::createFromTimestampMs($data['post_in'])->format('Y-m-d');
}
if ($patientId && $request->filled('historyable_type')) {
// Найти связанную модель
$historyableClass = $request->input('historyable_type');
$archiveInfo = ArchiveInfo::whereId($patientId)->first();
// Проверяем, существует ли класс модели
if (class_exists($historyableClass)) {
$historyableModel = $historyableClass::find($patientId);
$archiveInfo->updateOrCreate(
['id' => $patientId],
[
'archive_num' => $data['num'],
'post_in' => $data['post_in'],
]
);
if ($historyableModel) {
// Связываем модели
$historyableModel->archiveInfo()->updateOrCreate([
'historyable_type' => $historyableClass,
'historyable_id' => $patientId,
], $data);
return response()->json(ArchiveInfoResource::make($historyableModel->archiveInfo));
}
}
}
return response()->json()->setStatusCode(500);
return response()->json()->setStatusCode(200);
}
}