Новая логика поисковой выдачи

И добавлена кнопка Добавить карту в архив
This commit is contained in:
brusnitsyn
2025-12-26 17:41:25 +09:00
parent 329304076d
commit c5c1a2b3e1
14 changed files with 508 additions and 38 deletions

View File

@@ -38,7 +38,7 @@ class ArchiveHistoryController extends Controller
'employee_post' => 'nullable|string',
'comment' => 'nullable|string',
'has_lost' => 'boolean',
'archive_info_id' => 'required|numeric',
'history_id' => 'required',
'type' => 'required|string',
]);
@@ -55,9 +55,16 @@ class ArchiveHistoryController extends Controller
->format('Y-m-d');
}
$archiveInfo = ArchiveInfo::whereId($data['archive_info_id'])->first();
if ($data['type'] === 'mis') {
$archiveHistory = $archiveInfo->misHistory->archiveHistory()->create([
$patient = \App\Models\Mis\SttMedicalHistory::where('MedicalHistoryID', $data['history_id'])->first();
} else {
$patient = \App\Models\Si\SttMedicalHistory::where('keykarta', $data['history_id'])->first();
}
// $archiveInfo = ArchiveInfo::whereId($data['archive_info_id'])->first();
if ($data['type'] === 'mis') {
$archiveHistory = $patient->archiveHistory()->create([
'issue_at' => $data['issue_at'],
'return_at' => $data['return_at'],
'org_id' => $data['org_id'],
@@ -65,10 +72,10 @@ class ArchiveHistoryController extends Controller
'employee_post' => $data['employee_post'],
'comment' => $data['comment'],
'has_lost' => $data['has_lost'],
'mis_history_id' => $archiveInfo->mis_history_id
'mis_history_id' => $patient->MedicalHistoryID
]);
} else {
$archiveHistory = $archiveInfo->foxproHistory->archiveHistory()->create([
$archiveHistory = $patient->archiveHistory()->create([
'issue_at' => $data['issue_at'],
'return_at' => $data['return_at'],
'org_id' => $data['org_id'],
@@ -76,7 +83,7 @@ class ArchiveHistoryController extends Controller
'employee_post' => $data['employee_post'],
'comment' => $data['comment'],
'has_lost' => $data['has_lost'],
'foxpro_history_id' => $archiveInfo->foxpro_history_id,
'foxpro_history_id' => $patient->keykarta,
]);
}
@@ -131,10 +138,9 @@ class ArchiveHistoryController extends Controller
$data['post_in'] = Carbon::createFromTimestampMs($data['post_in'])->format('Y-m-d');
}
$archiveInfo = ArchiveInfo::whereId($patientId)->first();
$archiveInfo = ArchiveInfo::whereId($data['id'])->first();
$archiveInfo->updateOrCreate(
['id' => $patientId],
$archiveInfo->update(
[
'archive_num' => $data['num'],
'post_in' => $data['post_in'],

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Http\Controllers;
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;
}
}

View File

@@ -2,21 +2,25 @@
namespace App\Http\Controllers;
use App\Http\Resources\IndexSttMedicalHistoryResource;
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 App\Services\ArchiveCardService;
use Illuminate\Http\Request;
use Inertia\Inertia;
class IndexController extends Controller
{
private MedicalHistoryRepository $repository;
private ArchiveCardService $cardService;
public function __construct(MedicalHistoryRepository $repository)
public function __construct(MedicalHistoryRepository $repository, ArchiveCardService $cardService)
{
$this->repository = $repository;
$this->cardService = $cardService;
}
public function index(Request $request)
@@ -27,7 +31,15 @@ class IndexController extends Controller
$dateExtractTo = $request->get('date_extract_to', null);
$status = $request->get('status', null);
$data = $this->repository->unifiedSearch(
// $data = $this->repository->unifiedSearch(
// $searchText,
// $dateExtractFrom,
// $dateExtractTo,
// $status,
// $pageSize
// );
$data = $this->cardService->get(
$searchText,
$dateExtractFrom,
$dateExtractTo,
@@ -35,6 +47,8 @@ class IndexController extends Controller
$pageSize
);
// dd($data);
$statuses = ArchiveStatus::all()->map(function ($status) {
return [
'value' => $status->id,
@@ -42,13 +56,8 @@ class IndexController extends Controller
];
});
$statuses->push([
'value' => 0,
'label' => 'Нет в архиве',
]);
return Inertia::render('Home/Index', [
'cards' => MisSttMedicalHistoryResource::collection($data),
'cards' => IndexSttMedicalHistoryResource::collection($data),
'statuses' => $statuses,
'filters' => array_merge($request->only([
'search', 'date_extract_from', 'date_extract_to',

View File

@@ -33,7 +33,7 @@ class MedicalHistoryController extends Controller
'can_be_issued' => $patient->canBeIssued()
],
'journal' => $archiveJournal,
'archiveInfo' => $archiveInfo
'archiveInfo' => $archiveInfo ? ArchiveInfoResource::make($archiveInfo) : null
];
return response()->json($patientInfo);

View File

@@ -0,0 +1,74 @@
<?php
namespace App\Http\Controllers;
use App\Models\Mis\SttMedicalHistory;
use Illuminate\Http\Request;
class MisHistoryController extends Controller
{
public function search(Request $request)
{
$data = $request->validate([
'query' => 'required|string'
]);
$searchText = $data['query'];
$searchParts = preg_split('/\s+/', trim($searchText));
$query = SttMedicalHistory::query();
// Проверяем, начинается ли строка с цифры (вероятно, это номер карты)
$isCardNumberSearch = is_numeric($searchParts[0]);
if ($isCardNumberSearch) {
// Паттерн: № Ф И О
$query->where('MedCardNum', 'ILIKE', "$searchParts[0]%");
// ФИО начинается со второй части
$fioStartIndex = 1;
} else {
// Паттерн: Ф И О (без номера)
$fioStartIndex = 0;
}
// Ищем ФИО в зависимости от количества оставшихся частей
$fioPartsCount = count($searchParts) - $fioStartIndex;
if ($fioPartsCount === 1) {
// Одно слово - ищем в фамилии, имени или отчестве
$query->where(function ($q) use ($searchParts, $fioStartIndex) {
$q->where('FAMILY', 'ILIKE', "{$searchParts[$fioStartIndex]}%")
->orWhere('Name', 'ILIKE', "{$searchParts[$fioStartIndex]}%")
->orWhere('OT', 'ILIKE', "{$searchParts[$fioStartIndex]}%");
});
} elseif ($fioPartsCount === 2) {
// Два слова - фамилия и инициал имени
$query->where(function ($q) use ($searchParts, $fioStartIndex) {
$q->where('FAMILY', 'ILIKE', "{$searchParts[$fioStartIndex]}%")
->where('Name', 'ILIKE', "{$searchParts[$fioStartIndex + 1]}%");
});
} elseif ($fioPartsCount === 3) {
// Три слова - полное ФИО
$query->where(function ($q) use ($searchParts, $fioStartIndex) {
$q->where('FAMILY', 'ILIKE', "{$searchParts[$fioStartIndex]}%")
->where('Name', 'ILIKE', "{$searchParts[$fioStartIndex + 1]}%")
->where('OT', 'ILIKE', "{$searchParts[$fioStartIndex + 2]}%");
});
}
// Также ищем полную строку в объединенных полях
$query->orWhereRaw("CONCAT(\"MedCardNum\", ' ', \"FAMILY\", ' ', \"Name\", ' ', \"OT\") ILIKE ?", ["{$searchText}%"]);
$results = $query->select([
'MedicalHistoryID', 'MedCardNum', 'FAMILY', 'Name', 'OT'
])->get()->map(function ($item) {
return [
'label' => "$item->MedCardNum - $item->FAMILY $item->Name $item->OT",
'value' => $item->MedicalHistoryID
];
});
return response()->json($results);
}
}