147 lines
5.3 KiB
PHP
147 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
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;
|
|
|
|
class ArchiveHistoryController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
|
|
}
|
|
|
|
public function show($id, Request $request)
|
|
{
|
|
$archiveHistory = ArchiveHistory::find($id);
|
|
|
|
return response()->json([
|
|
...$archiveHistory->toArray(),
|
|
'type' => $archiveHistory->historyType()
|
|
]);
|
|
}
|
|
|
|
public function moveStore(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',
|
|
'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'])
|
|
->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'])
|
|
->setTimezone(config('app.timezone'))
|
|
->format('Y-m-d');
|
|
}
|
|
|
|
$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));
|
|
}
|
|
|
|
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',
|
|
'type' => 'required|string',
|
|
]);
|
|
|
|
// Преобразуем timestamp в дату, если пришли числа
|
|
if (isset($data['issue_at']) && is_numeric($data['issue_at'])) {
|
|
$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'])
|
|
->setTimezone(config('app.timezone'))
|
|
->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],
|
|
'status' => 'nullable',
|
|
'type' => 'nullable'
|
|
]);
|
|
|
|
// Преобразуем timestamp в дату, если пришли числа
|
|
if (isset($data['post_in']) && is_numeric($data['post_in'])) {
|
|
$data['post_in'] = Carbon::createFromTimestampMs($data['post_in'])->format('Y-m-d');
|
|
}
|
|
|
|
$archiveInfo = ArchiveInfo::whereId($patientId)->first();
|
|
|
|
$archiveInfo->updateOrCreate(
|
|
['id' => $patientId],
|
|
[
|
|
'archive_num' => $data['num'],
|
|
'post_in' => $data['post_in'],
|
|
]
|
|
);
|
|
|
|
return response()->json()->setStatusCode(200);
|
|
}
|
|
}
|