62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Resources\ArchiveInfoResource;
|
|
use App\Models\ArchiveInfo;
|
|
use App\Models\Mis\SttMedicalHistory;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class ArchiveInfoController extends Controller
|
|
{
|
|
public function store(Request $request)
|
|
{
|
|
$data = $request->validate([
|
|
'id' => 'required',
|
|
'num' => 'required',
|
|
'post_in' => 'required'
|
|
]);
|
|
|
|
// Преобразуем timestamp в дату, если пришли числа
|
|
if (isset($data['post_in']) && is_numeric($data['post_in'])) {
|
|
$data['post_in'] = Carbon::createFromTimestampMs($data['post_in'])
|
|
->setTimezone(config('app.timezone'))
|
|
->format('Y-m-d');
|
|
}
|
|
|
|
$history = SttMedicalHistory::where('MedicalHistoryID', $data['id'])->first();
|
|
|
|
$hasCreated = ArchiveInfo::create([
|
|
'mis_num' => $history->MedCardNum,
|
|
'mis_history_id' => $data['id'],
|
|
'archive_num' => $data['num'],
|
|
'post_in' => $data['post_in'],
|
|
]);
|
|
|
|
return $hasCreated;
|
|
}
|
|
|
|
public function check(Request $request)
|
|
{
|
|
$data = $request->validate([
|
|
'id' => 'required',
|
|
]);
|
|
|
|
$archive = ArchiveInfo::where('mis_history_id', $data['id'])
|
|
->orWhere('foxpro_history_id', $data['id'])
|
|
->first();
|
|
|
|
if (isset($archive)) {
|
|
return response()->json([
|
|
'id' => $archive->mis_history_id ?? $archive->foxpro_history_id,
|
|
'type' => $archive->mis_history_id ? 'mis' : 'foxpro',
|
|
]);
|
|
}
|
|
|
|
return response()->json([
|
|
'message' => 'Карты нет в архиве'
|
|
])->setStatusCode(404);
|
|
}
|
|
}
|