* связка таблицы архива с пациентами

* добавил разграничение карт по типам баз
* модель для хранения изменений статуса карт
* добавил окно с просмотром выдачи карты
* добавил фильтрацию вывода карт
This commit is contained in:
brusnitsyn
2025-12-02 17:15:28 +09:00
parent 063ddafdfb
commit 2dfa45707c
21 changed files with 656 additions and 71 deletions

View File

@@ -13,17 +13,30 @@ class IndexController extends Controller
{
$pageSize = $request->get('page_size', 15);
$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');
$cards = SttMedicalHistory::query();
$cardsQuery = SttMedicalHistory::query();
if (!empty($searchText)) {
$cards = $cards->search($searchText);
$cardsQuery = $cardsQuery->search($searchText);
}
$cards = SttMedicalHistoryResource::collection($cards->paginate($pageSize));
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

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Controllers;
use App\Models\SI\SttMedicalHistory;
use Illuminate\Http\Request;
class MedicalHistoryController extends Controller
{
public function patient($id, Request $request)
{
$viewType = $request->get('view_type', 'si');
$patientId = $request->get('patient_id');
$patientInfo = null;
if ($viewType == 'si') {
$patient = SttMedicalHistory::where('id', $id)->first();
$archiveJournal = $patient->archiveHistory;
$patientInfo = [
'info' => $patient,
'journal' => $archiveJournal,
];
}
return response()->json($patientInfo);
}
}

View File

@@ -16,14 +16,15 @@ class SttMedicalHistoryResource extends JsonResource
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'fullname' => $this->getFullNameAttribute(),
'mpostdate' => Carbon::parse($this->mpostdate)->format('d.m.Y'),
'menddate' => Carbon::parse($this->menddate)->format('d.m.Y'),
'daterecipient' => Carbon::parse($this->daterecipient)->format('d.m.Y'),
'dateextract' => Carbon::parse($this->dateextract)->format('d.m.Y'),
'narhiv' => $this->narhiv,
'datearhiv' => Carbon::parse($this->datearhiv)->format('d.m.Y'),
'statgod' => $this->statgod,
'enp' => $this->enp,
'nkarta' => $this->nkarta,
'medcardnum' => $this->medcardnum,
'dr' => Carbon::parse($this->dr)->format('d.m.Y'),
];
}

View File

@@ -11,9 +11,11 @@ class ArchiveHistory extends Model
'historyable_id',
'issue_at',
'return_at',
'name_org',
'comment',
'org_id',
'employee_name',
'employee_position',
'employee_post',
'has_lost',
];
public function historyable()

12
app/Models/Org.php Normal file
View File

@@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Org extends Model
{
protected $fillable = [
'name'
];
}

View File

@@ -10,25 +10,25 @@ class SttMedicalHistory extends Model
protected $table = 'si_stt_patients';
protected $fillable = [
'fam', // Фамилия
'im', // Имя
'family', // Фамилия
'name', // Имя
'ot', // Отчество
'mpostdate', // Д. пост.
'menddate', // Д. вып.
'daterecipient', // Д. пост. (mpostdate)
'dateextract', // Д. вып. (menddate)
'narhiv', // № в архиве
'datearhiv', // Д. архив
'statgod', // Год нахождения в стационаре
'enp', // ЕНП
'nkarta', // № карты
'medcardnum', // № карты
'dr', // ДР
];
public function getFullNameAttribute()
{
return "$this->fam $this->im $this->ot";
return "$this->family $this->name $this->ot";
}
public function getArchiveHistory()
public function archiveHistory()
{
return $this->morphMany(ArchiveHistory::class, 'historyable');
}
@@ -37,12 +37,12 @@ class SttMedicalHistory extends Model
{
return $query->where(function($q) use ($searchText) {
if (is_numeric($searchText)) {
$q->where('nkarta', 'LIKE', "$searchText%");
$q->where('medcardnum', 'ILIKE', "$searchText%");
} else {
// Ищем по всем частям ФИО
$q->where('fam', 'LIKE', "%$searchText%")
->orWhere('im', 'LIKE', "%$searchText%")
->orWhere('ot', 'LIKE', "%$searchText%");
$q->where('family', 'ILIKE', "%$searchText%")
->orWhere('name', 'ILIKE', "%$searchText%")
->orWhere('ot', 'ILIKE', "%$searchText%");
}
});
}