Много всего
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,41 +2,119 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\SI\SttMedicalHistoryResource;
|
||||
use App\Http\Resources\SI\SttMedicalHistoryResource as SiSttMedicalHistoryResource;
|
||||
use App\Http\Resources\Mis\SttMedicalHistoryResource as MisSttMedicalHistoryResource;
|
||||
use App\Models\ArchiveStatus;
|
||||
use App\Models\SI\SttMedicalHistory;
|
||||
use App\Repositories\MedicalHistoryRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
private MedicalHistoryRepository $repository;
|
||||
|
||||
public function __construct(MedicalHistoryRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$pageSize = $request->get('page_size', 15);
|
||||
$pageSize = $request->get('page_size', 50);
|
||||
$searchText = $request->get('search', null);
|
||||
$dateExtractFrom = $request->get('date_extract_from', null);
|
||||
$dateExtractTo = $request->get('date_extract_to', null);
|
||||
$viewType = $request->get('view_type', 'archive');
|
||||
$database = $request->get('database', 'separate'); // si, mis
|
||||
$status = $request->get('status', null);
|
||||
|
||||
$cardsQuery = SttMedicalHistory::query();
|
||||
$data = [];
|
||||
$databaseStats = $this->repository->getDatabaseStats();
|
||||
|
||||
if (!empty($searchText)) {
|
||||
$cardsQuery = $cardsQuery->search($searchText);
|
||||
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;
|
||||
}
|
||||
|
||||
if (!empty($dateExtractFrom)) {
|
||||
$cardsQuery = $cardsQuery->whereDate('dateextract', '>=', $dateExtractFrom);
|
||||
if (!empty($dateExtractTo)) {
|
||||
$cardsQuery = $cardsQuery->whereDate('dateextract', '<=', $dateExtractTo);
|
||||
}
|
||||
}
|
||||
|
||||
$cards = SttMedicalHistoryResource::collection($cardsQuery->paginate($pageSize));
|
||||
$statuses = ArchiveStatus::all()->map(function ($status) {
|
||||
return [
|
||||
'value' => $status->id,
|
||||
'label' => $status->text
|
||||
];
|
||||
});
|
||||
|
||||
return Inertia::render('Home/Index', [
|
||||
'cards' => $cards,
|
||||
'filters' => $request->only([
|
||||
'search', 'date_extract_from', 'date_extract_to', 'page_size', 'page', 'view_type'
|
||||
]),
|
||||
'cards' => $data,
|
||||
'statuses' => $statuses,
|
||||
'databaseStats' => $databaseStats,
|
||||
'filters' => array_merge($request->only([
|
||||
'search', 'date_extract_from', 'date_extract_to',
|
||||
'page_size', 'page', 'view_type', 'database', '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'
|
||||
// ]),
|
||||
// ]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\ArchiveHistoryResource;
|
||||
use App\Http\Resources\ArchiveInfoResource;
|
||||
use App\Models\SI\SttMedicalHistory;
|
||||
use App\Http\Resources\PatientInfoResource;
|
||||
use App\Models\SI\SttMedicalHistory as SiSttMedicalHistory;
|
||||
use App\Models\Mis\SttMedicalHistory as MisSttMedicalHistory;
|
||||
use App\Repositories\MedicalHistoryRepository;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MedicalHistoryController extends Controller
|
||||
@@ -15,22 +18,27 @@ class MedicalHistoryController extends Controller
|
||||
$patientId = $request->get('patient_id');
|
||||
|
||||
$patientInfo = null;
|
||||
if ($viewType == 'si') {
|
||||
$patient = SttMedicalHistory::where('id', $id)->first();
|
||||
$archiveJournal = ArchiveHistoryResource::collection($patient->archiveHistory);
|
||||
$archiveInfo = $patient->archiveInfo;
|
||||
if ($viewType == 'si') $patient = SiSttMedicalHistory::where('id', $id)->first();
|
||||
else $patient = MisSttMedicalHistory::where('MedicalHistoryID', $id)->first();
|
||||
$archiveJournal = $patient->archiveHistory ? ArchiveHistoryResource::collection($patient->archiveHistory) : null;
|
||||
|
||||
if (!empty($archiveInfo)) {
|
||||
$archiveInfo = ArchiveInfoResource::make($patient->archiveInfo);
|
||||
}
|
||||
|
||||
$patientInfo = [
|
||||
'info' => $patient,
|
||||
'journal' => $archiveJournal,
|
||||
'archiveInfo' => $archiveInfo,
|
||||
];
|
||||
if (!empty($patient->archiveInfo)) {
|
||||
$archiveInfo = ArchiveInfoResource::make($patient->archiveInfo)->toArray(request());
|
||||
} else {
|
||||
$archiveInfo = null;
|
||||
}
|
||||
|
||||
$patientInfo = [
|
||||
'historyable_type' => $viewType == 'si' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class,
|
||||
'info' => [
|
||||
'historyable_type' => $viewType == 'si' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class,
|
||||
...PatientInfoResource::make($patient)->toArray(request()),
|
||||
'can_be_issued' => $patient->canBeIssued()
|
||||
],
|
||||
'journal' => $archiveJournal,
|
||||
'archiveInfo' => $archiveInfo
|
||||
];
|
||||
|
||||
return response()->json($patientInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user