From 945b53c578a8cb3948bd61c51b4ce5d670d43ee5 Mon Sep 17 00:00:00 2001 From: brusnitsyn Date: Sun, 7 Dec 2025 22:33:19 +0900 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D1=81=D0=BC=D0=B5=D0=BD=D1=8B=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=B0=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20move=20=D0=BC=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B4=20=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=B2=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B8=D1=81=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ArchiveHistoryController.php | 32 +++++++++++++ .../Controllers/MedicalHistoryController.php | 5 +++ .../SI/SttMedicalHistoryResource.php | 3 +- app/Models/ArchiveHistory.php | 45 +++++++++++++++++++ app/Models/ArchiveInfo.php | 5 +++ app/Models/SI/SttMedicalHistory.php | 17 ++++--- .../Pages/Home/ArchiveHistoryModal/Index.vue | 4 +- .../Home/ArchiveHistoryMoveModal/Index.vue | 24 +++++++--- resources/js/Pages/Home/DataTable/Index.vue | 21 +++++++-- routes/api.php | 3 ++ 10 files changed, 142 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/ArchiveHistoryController.php b/app/Http/Controllers/ArchiveHistoryController.php index 07ac590..186fc22 100644 --- a/app/Http/Controllers/ArchiveHistoryController.php +++ b/app/Http/Controllers/ArchiveHistoryController.php @@ -2,8 +2,10 @@ namespace App\Http\Controllers; +use App\Http\Resources\ArchiveHistoryResource; use App\Models\ArchiveHistory; use Illuminate\Http\Request; +use Illuminate\Support\Carbon; class ArchiveHistoryController extends Controller { @@ -18,4 +20,34 @@ class ArchiveHistoryController extends Controller return response()->json($archiveHistory); } + + public function move(Request $request) + { + $data = $request->validate([ + 'issue_at' => 'nullable|numeric:', + 'return_at' => 'nullable|numeric:', + 'org_id' => 'required|numeric', + 'employee_name' => 'nullable|string', + 'employee_post' => 'nullable|string', + 'comment' => 'nullable|string', + 'has_lost' => 'boolean', + 'historyable_id' => 'nullable|numeric', + ]); + + // Находим связанную модель ?? + $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'); + } + + if (isset($data['return_at']) && is_numeric($data['return_at'])) { + $data['return_at'] = Carbon::createFromTimestampMs($data['return_at'])->format('Y-m-d'); + } + + $archiveHistory = ArchiveHistory::create($data); + + return response()->json(ArchiveHistoryResource::make($archiveHistory)); + } } diff --git a/app/Http/Controllers/MedicalHistoryController.php b/app/Http/Controllers/MedicalHistoryController.php index 82512f5..3f730c5 100644 --- a/app/Http/Controllers/MedicalHistoryController.php +++ b/app/Http/Controllers/MedicalHistoryController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Http\Resources\ArchiveHistoryResource; +use App\Http\Resources\ArchiveInfoResource; use App\Models\SI\SttMedicalHistory; use Illuminate\Http\Request; @@ -19,6 +20,10 @@ class MedicalHistoryController extends Controller $archiveJournal = ArchiveHistoryResource::collection($patient->archiveHistory); $archiveInfo = $patient->archiveInfo; + if (!empty($archiveInfo)) { + $archiveInfo = ArchiveInfoResource::make($patient->archiveInfo); + } + $patientInfo = [ 'info' => $patient, 'journal' => $archiveJournal, diff --git a/app/Http/Resources/SI/SttMedicalHistoryResource.php b/app/Http/Resources/SI/SttMedicalHistoryResource.php index d440a95..1b5c7af 100644 --- a/app/Http/Resources/SI/SttMedicalHistoryResource.php +++ b/app/Http/Resources/SI/SttMedicalHistoryResource.php @@ -20,7 +20,8 @@ class SttMedicalHistoryResource extends JsonResource 'fullname' => $this->getFullNameAttribute(), 'daterecipient' => Carbon::parse($this->daterecipient)->format('d.m.Y'), 'dateextract' => Carbon::parse($this->dateextract)->format('d.m.Y'), - 'narhiv' => $this->narhiv, + '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, diff --git a/app/Models/ArchiveHistory.php b/app/Models/ArchiveHistory.php index e08605e..3ca13ca 100644 --- a/app/Models/ArchiveHistory.php +++ b/app/Models/ArchiveHistory.php @@ -6,6 +6,51 @@ use Illuminate\Database\Eloquent\Model; class ArchiveHistory extends Model { + protected static function booted() + { + static::created(function ($archiveHistory) { + $archiveHistory->updateArchiveInfoStatus(); + }); + + static::updated(function ($archiveHistory) { + $archiveHistory->updateArchiveInfoStatus(); + }); + } + + public function updateArchiveInfoStatus() + { + // Получаем связанную модель через морф + $historyable = $this->historyable; + + if (!$historyable) { + return; + } + + // Проверяем, есть ли у модели архивная информация + if (method_exists($historyable, 'archiveInfo') && $historyable->archiveInfo) { + $historyable->archiveInfo->update([ + 'status_id' => $this->determineStatusId() + ]); + } + } + + public function determineStatusId() + { + if ($this->has_lost) { + return 4; // Утерян + } + + if ($this->issue_at && !$this->return_at) { + return 3; // Выдан + } + + if ($this->return_at) { + return 2; // В архиве + } + + return 2; // По умолчанию + } + protected $fillable = [ 'historyable_type', 'historyable_id', diff --git a/app/Models/ArchiveInfo.php b/app/Models/ArchiveInfo.php index d660e0b..3210de4 100644 --- a/app/Models/ArchiveInfo.php +++ b/app/Models/ArchiveInfo.php @@ -18,4 +18,9 @@ class ArchiveInfo extends Model { return $this->morphTo(); } + + public function status() + { + return $this->belongsTo(ArchiveStatus::class); + } } diff --git a/app/Models/SI/SttMedicalHistory.php b/app/Models/SI/SttMedicalHistory.php index 290d2c6..e2f057c 100644 --- a/app/Models/SI/SttMedicalHistory.php +++ b/app/Models/SI/SttMedicalHistory.php @@ -43,12 +43,19 @@ class SttMedicalHistory extends Model { return $query->where(function($q) use ($searchText) { if (is_numeric($searchText)) { - $q->where('medcardnum', 'ILIKE', "$searchText%"); + $q->where('medcardnum', 'ILIKE', "$searchText"); } else { - // Ищем по всем частям ФИО - $q->where('family', 'ILIKE', "%$searchText%") - ->orWhere('name', 'ILIKE', "%$searchText%") - ->orWhere('ot', 'ILIKE', "%$searchText%"); + // Ищем в объединенном ФИО и в отдельных полях + $searchPattern = "%{$searchText}%"; + + $q->where(function($subQ) use ($searchPattern) { + // Поиск в объединенной строке + $subQ->whereRaw("CONCAT(family, ' ', name, ' ', COALESCE(ot, '')) ILIKE ?", [$searchPattern]) + // И дополнительно в отдельных полях для точности + ->orWhere('family', 'ILIKE', $searchPattern) + ->orWhere('name', 'ILIKE', $searchPattern) + ->orWhere('ot', 'ILIKE', $searchPattern); + }); } }); } diff --git a/resources/js/Pages/Home/ArchiveHistoryModal/Index.vue b/resources/js/Pages/Home/ArchiveHistoryModal/Index.vue index db98048..17e71c7 100644 --- a/resources/js/Pages/Home/ArchiveHistoryModal/Index.vue +++ b/resources/js/Pages/Home/ArchiveHistoryModal/Index.vue @@ -92,8 +92,8 @@ watch(() => props.patientId, (newId) => { - - Не определен + + {{ patient.archiveInfo?.status?.text ?? 'Нет в архиве' }} diff --git a/resources/js/Pages/Home/ArchiveHistoryMoveModal/Index.vue b/resources/js/Pages/Home/ArchiveHistoryMoveModal/Index.vue index cbd6da4..d16fc68 100644 --- a/resources/js/Pages/Home/ArchiveHistoryMoveModal/Index.vue +++ b/resources/js/Pages/Home/ArchiveHistoryMoveModal/Index.vue @@ -11,6 +11,7 @@ const emits = defineEmits(['closeWithoutSave']) const loading = ref(false) const archiveHistory = ref({ + historyable_id: props.archiveHistoryId, issue_at: null, org_id: null, return_at: null, @@ -23,6 +24,7 @@ const orgs = ref([]) const onResetData = () => { archiveHistory.value = { + historyable_id: props.archiveHistoryId, issue_at: null, org_id: null, return_at: null, @@ -39,13 +41,13 @@ const onCloseWithoutSave = () => { const loadArchiveHistoryData = async () => { try { - axios.get('/api/orgs').then(res => { + await axios.get('/api/orgs').then(res => { orgs.value = res.data }) if (!props.archiveHistoryId) return - axios.get(`/api/archive/histories/${props.archiveHistoryId}`).then(res => { + await axios.get(`/api/archive/histories/${props.archiveHistoryId}`).then(res => { archiveHistory.value = res.data }) } catch (error) { @@ -55,10 +57,22 @@ const loadArchiveHistoryData = async () => { } } +const submit = () => { + try { + axios.post('/api/archive/histories/move', archiveHistory.value).then(res => { + onCloseWithoutSave() + }) + } catch (error) { + console.error(error) + } finally { + loading.value = false + } +} + // Наблюдаем за изменением archiveHistoryId -watch(() => props.archiveHistoryId, (newId) => { +watch(() => props.archiveHistoryId, async (newId) => { if (newId) { - loadArchiveHistoryData() + await loadArchiveHistoryData() } else { onResetData() } @@ -101,7 +115,7 @@ watch(() => props.archiveHistoryId, (newId) => { Закрыть без сохранения - + Сохранить diff --git a/resources/js/Pages/Home/DataTable/Index.vue b/resources/js/Pages/Home/DataTable/Index.vue index e72e8dc..e251198 100644 --- a/resources/js/Pages/Home/DataTable/Index.vue +++ b/resources/js/Pages/Home/DataTable/Index.vue @@ -1,5 +1,5 @@