From 329304076db3d45da3179cf0bbfb2b1f92e7a97c Mon Sep 17 00:00:00 2001 From: brusnitsyn Date: Fri, 26 Dec 2025 14:29:55 +0900 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B4=D0=B0=D1=87=D0=B8=20=D0=BA=D0=B0=D1=80=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/MedicalHistoryController.php | 13 ++++------ app/Http/Resources/ArchiveInfoResource.php | 1 - .../Mis/SttMedicalHistoryResource.php | 24 +++++++++---------- app/Repositories/MedicalHistoryRepository.php | 11 +++++++-- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/MedicalHistoryController.php b/app/Http/Controllers/MedicalHistoryController.php index ae4f6f7..c67d3cc 100644 --- a/app/Http/Controllers/MedicalHistoryController.php +++ b/app/Http/Controllers/MedicalHistoryController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Http\Resources\ArchiveHistoryResource; use App\Http\Resources\ArchiveInfoResource; use App\Http\Resources\PatientInfoResource; +use App\Http\Resources\SI\SttMedicalHistoryResource; use App\Models\ArchiveInfo; use App\Models\SI\SttMedicalHistory as SiSttMedicalHistory; use App\Models\Mis\SttMedicalHistory as MisSttMedicalHistory; @@ -18,17 +19,11 @@ class MedicalHistoryController extends Controller $viewType = $request->get('view_type', 'mis'); $patientId = $request->get('patient_id'); - $archiveInfo = ArchiveInfo::whereId($id)->first()->load('status'); - if ($viewType == 'foxpro') $patient = $archiveInfo->foxproHistory; - else $patient = $archiveInfo->misHistory; + if ($viewType == 'foxpro') $patient = SiSttMedicalHistory::where('keykarta', $id)->first(); + else $patient = MisSttMedicalHistory::where('MedicalHistoryID', $id)->first(); $archiveJournal = $patient->archiveHistory ? ArchiveHistoryResource::collection($patient->archiveHistory) : null; -// dd($archiveInfo); - if (!empty($archiveInfo)) { - $archiveInfo = ArchiveInfoResource::make($archiveInfo)->toArray(request()); - } else { - $archiveInfo = null; - } + $archiveInfo = $patient->archiveInfo ? $patient->archiveInfo : null; $patientInfo = [ 'historyable_type' => $viewType == 'foxpro' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class, diff --git a/app/Http/Resources/ArchiveInfoResource.php b/app/Http/Resources/ArchiveInfoResource.php index 7d189d9..0f1d682 100644 --- a/app/Http/Resources/ArchiveInfoResource.php +++ b/app/Http/Resources/ArchiveInfoResource.php @@ -21,7 +21,6 @@ class ArchiveInfoResource extends JsonResource 'status' => $this->status, 'foxpro_num' => $this->foxpro_num, 'mis_num' => $this->mis_num, - 'type' => $this->historyType() ]; } } diff --git a/app/Http/Resources/Mis/SttMedicalHistoryResource.php b/app/Http/Resources/Mis/SttMedicalHistoryResource.php index c5b74cf..2a06239 100644 --- a/app/Http/Resources/Mis/SttMedicalHistoryResource.php +++ b/app/Http/Resources/Mis/SttMedicalHistoryResource.php @@ -25,14 +25,20 @@ class SttMedicalHistoryResource extends JsonResource $name = $this->resource['name'] ?? ''; $ot = $this->resource['ot'] ?? ''; + $misCardNumber = $this->resource['mis_card_number']; + $foxproCardNumber = $this->resource['foxpro_card_number']; + + $hasDividerCardNumber = isset($misCardNumber) && isset($foxproCardNumber); + + $cardNumber = $hasDividerCardNumber ? "$misCardNumber / $foxproCardNumber" : $misCardNumber ?? $foxproCardNumber; + // Для временных записей (не в архиве) используем данные из MIS if ($isTemporary) { // Данные из stt_medicalhistory (не в архиве) $fullName = trim("{$family} {$name} {$ot}"); $birthDate = $this->resource['birth_date'] ?? null; $dateExtract = $this->resource['date_extract'] ?? null; - $dateRecipient = null; // Для MIS записей не в архиве может не быть - $cardNumber = $this->resource['card_number'] ?? null; + $dateRecipient = $this->resource['date_recipient'] ?? null; $archiveNum = null; $postIn = null; $status = $this->resource['status_text'] ?? 'Не в архиве'; @@ -40,19 +46,11 @@ class SttMedicalHistoryResource extends JsonResource // Данные из archive_infos (в архиве) $fullName = trim("{$family} {$name} {$ot}"); $birthDate = $this->resource['birth_date'] ?? null; - // Для архивных записей date_extract может быть из MIS или FoxPro $dateExtract = $this->resource['date_extract'] ?? null; - // Для MIS записей в архиве - if ($historyType === 'mis') { - $dateRecipient = $this->resource['date_recipient'] ?? null; - } else { - // Для FoxPro записей в архиве - $dateRecipient = $this->resource['mpostdate'] ?? null; - } + $dateRecipient = $this->resource['date_recipient'] ?? null; - $cardNumber = $this->resource['card_number'] ?? null; $archiveNum = $this->resource['archive_num'] ?? null; $postIn = $this->resource['post_in'] ?? null; $status = $this->resource['status_text'] ?? 'Неизвестно'; @@ -64,8 +62,10 @@ class SttMedicalHistoryResource extends JsonResource $formattedDateExtract = $dateExtract ? Carbon::parse($dateExtract)->format('d.m.Y') : null; $formattedPostIn = $postIn ? Carbon::parse($postIn)->format('d.m.Y') : null; + $id = $historyType === 'mis' ? $this->resource['mis_history_id'] : $this->resource['foxpro_history_id']; + return [ - 'id' => $this->resource['id'], + 'id' => $id, 'history_type' => $historyType, 'in_archive' => $isFromArchive, 'is_temporary' => $isTemporary, diff --git a/app/Repositories/MedicalHistoryRepository.php b/app/Repositories/MedicalHistoryRepository.php index 8ae76a4..f8994fb 100644 --- a/app/Repositories/MedicalHistoryRepository.php +++ b/app/Repositories/MedicalHistoryRepository.php @@ -236,7 +236,7 @@ class MedicalHistoryRepository WHERE NOT EXISTS ( SELECT 1 FROM archive_infos ai WHERE ai.mis_history_id = mh.\"MedicalHistoryID\" - ) + ) AND mh.\"DateExtract\" > CAST('01-01-1900' as date) "; $misConditions = $this->buildMisConditions($searchText, $status); @@ -425,6 +425,7 @@ class MedicalHistoryRepository COALESCE(mh.\"Name\", fp.im), ' ', COALESCE(mh.\"OT\", fp.ot) ) as full_name, + COALESCE(mh.\"DateRecipient\", fp.mpostdate) as date_recipient, COALESCE(mh.\"DateExtract\", fp.menddate) as date_extract, COALESCE(mh.\"BD\", fp.dr) as birth_date, true as in_archive, @@ -478,6 +479,7 @@ class MedicalHistoryRepository mh.\"Name\" as name, mh.\"OT\" as ot, CONCAT(mh.\"FAMILY\", ' ', mh.\"Name\", ' ', COALESCE(mh.\"OT\", '')) as full_name, + mh.\"DateRecipient\" as date_recipient, mh.\"DateExtract\" as date_extract, mh.\"BD\" as birth_date, false as in_archive, @@ -491,6 +493,7 @@ class MedicalHistoryRepository NULL as enp FROM stt_medicalhistory mh WHERE mh.\"MedicalHistoryID\" IN ({$placeholders}) + AND mh.\"DateExtract\" > CAST('01-01-1900' AS DATE) "; $results = DB::select($sql, $ids); @@ -659,7 +662,8 @@ class MedicalHistoryRepository // Добавляем NOT EXISTS в начало $allConditions = array_merge( ["NOT EXISTS (SELECT 1 FROM archive_infos ai WHERE ai.mis_history_id = mh.\"MedicalHistoryID\")"], - $conditions['conditions'] + $conditions['conditions'], + ["mh.\"DateExtract\" > CAST('01-01-1900' AS DATE)"] ); $sql = " @@ -688,6 +692,7 @@ class MedicalHistoryRepository 'family' => $item->family, 'name' => $item->name, 'ot' => $item->ot, + 'date_recipient' => $item->date_recipient, 'date_extract' => $item->date_extract, 'birth_date' => $item->birth_date, 'created_at' => $item->created_at, @@ -886,6 +891,7 @@ class MedicalHistoryRepository true as in_archive, 'archive' as source, ai.created_at, + COALESCE(mh.\"DateRecipient\", fp.mpostdate) as date_recipient, COALESCE(mh.\"DateExtract\", fp.menddate) as date_extract FROM archive_infos ai LEFT JOIN stt_medicalhistory mh ON ai.mis_history_id = mh.\"MedicalHistoryID\" @@ -918,6 +924,7 @@ class MedicalHistoryRepository false as in_archive, 'mis' as source, mh.\"DateExtract\" as created_at, + mh.\"DateRecipient\" as date_recipient, mh.\"DateExtract\" as date_extract FROM stt_medicalhistory mh WHERE mh.\"MedCardNum\" = ?