Правка выдачи карт

This commit is contained in:
brusnitsyn
2025-12-26 14:29:55 +09:00
parent a5209f45c8
commit 329304076d
4 changed files with 25 additions and 24 deletions

View File

@@ -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,

View File

@@ -21,7 +21,6 @@ class ArchiveInfoResource extends JsonResource
'status' => $this->status,
'foxpro_num' => $this->foxpro_num,
'mis_num' => $this->mis_num,
'type' => $this->historyType()
];
}
}

View File

@@ -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,

View File

@@ -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\" = ?