Много всего

This commit is contained in:
brusnitsyn
2025-12-12 17:10:05 +09:00
parent 54f36e91fa
commit 98e9f8b52e
25 changed files with 1118 additions and 145 deletions

View File

@@ -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);
}
}

View File

@@ -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'
// ]),
// ]);
}
}

View File

@@ -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);
}
}

View File

@@ -18,7 +18,7 @@ class ArchiveHistoryResource extends JsonResource
return [
'id' => $this->id,
'issue_at' => Carbon::parse($this->issue_at)->format('d.m.Y'),
'return_at' => Carbon::parse($this->return_at)->format('d.m.Y'),
'return_at' => $this->return_at ? Carbon::parse($this->return_at)->format('d.m.Y') : null,
'comment' => $this->comment,
'org_id' => $this->org_id,
'org' => $this->org->name,

View File

@@ -18,7 +18,9 @@ class ArchiveInfoResource extends JsonResource
'id' => $this->id,
'num' => $this->num,
'post_in' => $this->post_in,
'status' => $this->status
'status' => $this->status,
'historyable_id' => $this->historyable_id,
'historyable_type' => $this->historyable_type,
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources\Mis;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;
class SttMedicalHistoryResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->MedicalHistoryID,
'fullname' => $this->getFullNameAttribute(),
'daterecipient' => Carbon::parse($this->DateRecipient)->format('d.m.Y'),
'dateextract' => Carbon::parse($this->DateExtract)->format('d.m.Y'),
'card_num' => $this->archiveInfo->num ?? null,
'status' => $this->archiveInfo->status ?? null,
'datearhiv' => $this->archiveInfo?->post_at ? Carbon::parse($this->archiveInfo->post_at)->format('d.m.Y') : null,
'medcardnum' => $this->MedCardNum,
'dr' => Carbon::parse($this->BD)->format('d.m.Y'),
'can_be_issue' => $this->canBeIssued()
];
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PatientInfoResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id ?? $this->MedicalHistoryID,
'medcardnum' => $this->medcardnum ?? $this->MedCardNum,
'family' => $this->family ?? $this->FAMILY,
'name' => $this->name ?? $this->Name,
'ot' => $this->ot ?? $this->OT,
];
}
}

View File

@@ -22,11 +22,10 @@ class SttMedicalHistoryResource extends JsonResource
'dateextract' => Carbon::parse($this->dateextract)->format('d.m.Y'),
'card_num' => $this->archiveInfo->num ?? null,
'status' => $this->archiveInfo->status ?? null,
'datearhiv' => Carbon::parse($this->datearhiv)->format('d.m.Y'),
'statgod' => $this->statgod,
'enp' => $this->enp,
'datearhiv' => $this->archiveInfo?->post_at ? Carbon::parse($this->archiveInfo->post_at)->format('d.m.Y') : null,
'medcardnum' => $this->medcardnum,
'dr' => Carbon::parse($this->dr)->format('d.m.Y'),
'can_be_issue' => $this->canBeIssued()
];
}
}