Много чего
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,58 +25,15 @@ class IndexController extends Controller
|
||||
$searchText = $request->get('search', null);
|
||||
$dateExtractFrom = $request->get('date_extract_from', null);
|
||||
$dateExtractTo = $request->get('date_extract_to', null);
|
||||
$database = $request->get('database', 'separate'); // si, mis
|
||||
$status = $request->get('status', null);
|
||||
|
||||
$data = [];
|
||||
$databaseStats = $this->repository->getDatabaseStats();
|
||||
|
||||
switch ($database) {
|
||||
case 'si':
|
||||
$paginator = $this->repository->searchInPostgres(
|
||||
$searchText,
|
||||
$dateExtractFrom,
|
||||
$dateExtractTo,
|
||||
$pageSize
|
||||
);
|
||||
$data['si'] = SiSttMedicalHistoryResource::collection($paginator);
|
||||
break;
|
||||
|
||||
case 'mis':
|
||||
$paginator = $this->repository->searchInMssql(
|
||||
$searchText,
|
||||
$dateExtractFrom,
|
||||
$dateExtractTo,
|
||||
$pageSize
|
||||
);
|
||||
$data['mis'] = MisSttMedicalHistoryResource::collection($paginator);
|
||||
break;
|
||||
|
||||
case 'smart':
|
||||
$paginator = $this->repository->smartSearch(
|
||||
$searchText,
|
||||
$dateExtractFrom,
|
||||
$dateExtractTo,
|
||||
$pageSize
|
||||
);
|
||||
$data['smart'] = SiSttMedicalHistoryResource::collection($paginator);
|
||||
break;
|
||||
|
||||
case 'separate':
|
||||
$separateResults = $this->repository->separateSearch(
|
||||
$searchText,
|
||||
$dateExtractFrom,
|
||||
$dateExtractTo,
|
||||
$status,
|
||||
$pageSize
|
||||
);
|
||||
$data = [
|
||||
'si' => SiSttMedicalHistoryResource::collection($separateResults['si']),
|
||||
'mis' => MisSttMedicalHistoryResource::collection($separateResults['mis']),
|
||||
'stats' => $separateResults['stats'],
|
||||
];
|
||||
break;
|
||||
}
|
||||
$data = $this->repository->unifiedSearch(
|
||||
$searchText,
|
||||
$dateExtractFrom,
|
||||
$dateExtractTo,
|
||||
$status,
|
||||
$pageSize
|
||||
);
|
||||
|
||||
$statuses = ArchiveStatus::all()->map(function ($status) {
|
||||
return [
|
||||
@@ -91,35 +48,13 @@ class IndexController extends Controller
|
||||
]);
|
||||
|
||||
return Inertia::render('Home/Index', [
|
||||
'cards' => $data,
|
||||
'cards' => MisSttMedicalHistoryResource::collection($data),
|
||||
'statuses' => $statuses,
|
||||
'databaseStats' => $databaseStats,
|
||||
'filters' => array_merge($request->only([
|
||||
'search', 'date_extract_from', 'date_extract_to',
|
||||
'page_size', 'page', 'view_type', 'database', 'status'
|
||||
'page_size', 'page', 'status'
|
||||
]))
|
||||
]);
|
||||
|
||||
// $cardsQuery = SttMedicalHistory::query();
|
||||
//
|
||||
// if (!empty($searchText)) {
|
||||
// $cardsQuery = $cardsQuery->search($searchText);
|
||||
// }
|
||||
//
|
||||
// if (!empty($dateExtractFrom)) {
|
||||
// $cardsQuery = $cardsQuery->whereDate('dateextract', '>=', $dateExtractFrom);
|
||||
// if (!empty($dateExtractTo)) {
|
||||
// $cardsQuery = $cardsQuery->whereDate('dateextract', '<=', $dateExtractTo);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// $cards = SttMedicalHistoryResource::collection($cardsQuery->paginate($pageSize));
|
||||
//
|
||||
// return Inertia::render('Home/Index', [
|
||||
// 'cards' => $cards,
|
||||
// 'filters' => $request->only([
|
||||
// 'search', 'date_extract_from', 'date_extract_to', 'page_size', 'page', 'view_type'
|
||||
// ]),
|
||||
// ]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Http\Resources\ArchiveHistoryResource;
|
||||
use App\Http\Resources\ArchiveInfoResource;
|
||||
use App\Http\Resources\PatientInfoResource;
|
||||
use App\Models\ArchiveInfo;
|
||||
use App\Models\SI\SttMedicalHistory as SiSttMedicalHistory;
|
||||
use App\Models\Mis\SttMedicalHistory as MisSttMedicalHistory;
|
||||
use App\Repositories\MedicalHistoryRepository;
|
||||
@@ -14,24 +15,25 @@ class MedicalHistoryController extends Controller
|
||||
{
|
||||
public function patient($id, Request $request)
|
||||
{
|
||||
$viewType = $request->get('view_type', 'si');
|
||||
$viewType = $request->get('view_type', 'mis');
|
||||
$patientId = $request->get('patient_id');
|
||||
|
||||
$patientInfo = null;
|
||||
if ($viewType == 'si') $patient = SiSttMedicalHistory::where('id', $id)->first();
|
||||
else $patient = MisSttMedicalHistory::where('MedicalHistoryID', $id)->first();
|
||||
$archiveJournal = $patient->archiveHistory ? ArchiveHistoryResource::collection($patient->archiveHistory) : null;
|
||||
$archiveInfo = ArchiveInfo::whereId($id)->first()->load('status');
|
||||
if ($viewType == 'foxpro') $patient = $archiveInfo->foxproHistory;
|
||||
else $patient = $archiveInfo->misHistory;
|
||||
|
||||
if (!empty($patient->archiveInfo)) {
|
||||
$archiveInfo = ArchiveInfoResource::make($patient->archiveInfo)->toArray(request());
|
||||
$archiveJournal = $patient->archiveHistory ? ArchiveHistoryResource::collection($patient->archiveHistory) : null;
|
||||
// dd($archiveInfo);
|
||||
if (!empty($archiveInfo)) {
|
||||
$archiveInfo = ArchiveInfoResource::make($archiveInfo)->toArray(request());
|
||||
} else {
|
||||
$archiveInfo = null;
|
||||
}
|
||||
|
||||
$patientInfo = [
|
||||
'historyable_type' => $viewType == 'si' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class,
|
||||
'historyable_type' => $viewType == 'foxpro' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class,
|
||||
'info' => [
|
||||
'historyable_type' => $viewType == 'si' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class,
|
||||
'historyable_type' => $viewType == 'foxpro' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class,
|
||||
...PatientInfoResource::make($patient)->toArray(request()),
|
||||
'can_be_issued' => $patient->canBeIssued()
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user