Правка выдачи карт
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|||||||
use App\Http\Resources\ArchiveHistoryResource;
|
use App\Http\Resources\ArchiveHistoryResource;
|
||||||
use App\Http\Resources\ArchiveInfoResource;
|
use App\Http\Resources\ArchiveInfoResource;
|
||||||
use App\Http\Resources\PatientInfoResource;
|
use App\Http\Resources\PatientInfoResource;
|
||||||
|
use App\Http\Resources\SI\SttMedicalHistoryResource;
|
||||||
use App\Models\ArchiveInfo;
|
use App\Models\ArchiveInfo;
|
||||||
use App\Models\SI\SttMedicalHistory as SiSttMedicalHistory;
|
use App\Models\SI\SttMedicalHistory as SiSttMedicalHistory;
|
||||||
use App\Models\Mis\SttMedicalHistory as MisSttMedicalHistory;
|
use App\Models\Mis\SttMedicalHistory as MisSttMedicalHistory;
|
||||||
@@ -18,17 +19,11 @@ class MedicalHistoryController extends Controller
|
|||||||
$viewType = $request->get('view_type', 'mis');
|
$viewType = $request->get('view_type', 'mis');
|
||||||
$patientId = $request->get('patient_id');
|
$patientId = $request->get('patient_id');
|
||||||
|
|
||||||
$archiveInfo = ArchiveInfo::whereId($id)->first()->load('status');
|
if ($viewType == 'foxpro') $patient = SiSttMedicalHistory::where('keykarta', $id)->first();
|
||||||
if ($viewType == 'foxpro') $patient = $archiveInfo->foxproHistory;
|
else $patient = MisSttMedicalHistory::where('MedicalHistoryID', $id)->first();
|
||||||
else $patient = $archiveInfo->misHistory;
|
|
||||||
|
|
||||||
$archiveJournal = $patient->archiveHistory ? ArchiveHistoryResource::collection($patient->archiveHistory) : null;
|
$archiveJournal = $patient->archiveHistory ? ArchiveHistoryResource::collection($patient->archiveHistory) : null;
|
||||||
// dd($archiveInfo);
|
$archiveInfo = $patient->archiveInfo ? $patient->archiveInfo : null;
|
||||||
if (!empty($archiveInfo)) {
|
|
||||||
$archiveInfo = ArchiveInfoResource::make($archiveInfo)->toArray(request());
|
|
||||||
} else {
|
|
||||||
$archiveInfo = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$patientInfo = [
|
$patientInfo = [
|
||||||
'historyable_type' => $viewType == 'foxpro' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class,
|
'historyable_type' => $viewType == 'foxpro' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class,
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ class ArchiveInfoResource extends JsonResource
|
|||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
'foxpro_num' => $this->foxpro_num,
|
'foxpro_num' => $this->foxpro_num,
|
||||||
'mis_num' => $this->mis_num,
|
'mis_num' => $this->mis_num,
|
||||||
'type' => $this->historyType()
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,14 +25,20 @@ class SttMedicalHistoryResource extends JsonResource
|
|||||||
$name = $this->resource['name'] ?? '';
|
$name = $this->resource['name'] ?? '';
|
||||||
$ot = $this->resource['ot'] ?? '';
|
$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
|
// Для временных записей (не в архиве) используем данные из MIS
|
||||||
if ($isTemporary) {
|
if ($isTemporary) {
|
||||||
// Данные из stt_medicalhistory (не в архиве)
|
// Данные из stt_medicalhistory (не в архиве)
|
||||||
$fullName = trim("{$family} {$name} {$ot}");
|
$fullName = trim("{$family} {$name} {$ot}");
|
||||||
$birthDate = $this->resource['birth_date'] ?? null;
|
$birthDate = $this->resource['birth_date'] ?? null;
|
||||||
$dateExtract = $this->resource['date_extract'] ?? null;
|
$dateExtract = $this->resource['date_extract'] ?? null;
|
||||||
$dateRecipient = null; // Для MIS записей не в архиве может не быть
|
$dateRecipient = $this->resource['date_recipient'] ?? null;
|
||||||
$cardNumber = $this->resource['card_number'] ?? null;
|
|
||||||
$archiveNum = null;
|
$archiveNum = null;
|
||||||
$postIn = null;
|
$postIn = null;
|
||||||
$status = $this->resource['status_text'] ?? 'Не в архиве';
|
$status = $this->resource['status_text'] ?? 'Не в архиве';
|
||||||
@@ -40,19 +46,11 @@ class SttMedicalHistoryResource extends JsonResource
|
|||||||
// Данные из archive_infos (в архиве)
|
// Данные из archive_infos (в архиве)
|
||||||
$fullName = trim("{$family} {$name} {$ot}");
|
$fullName = trim("{$family} {$name} {$ot}");
|
||||||
$birthDate = $this->resource['birth_date'] ?? null;
|
$birthDate = $this->resource['birth_date'] ?? null;
|
||||||
|
|
||||||
// Для архивных записей date_extract может быть из MIS или FoxPro
|
// Для архивных записей date_extract может быть из MIS или FoxPro
|
||||||
$dateExtract = $this->resource['date_extract'] ?? null;
|
$dateExtract = $this->resource['date_extract'] ?? null;
|
||||||
|
|
||||||
// Для MIS записей в архиве
|
$dateRecipient = $this->resource['date_recipient'] ?? null;
|
||||||
if ($historyType === 'mis') {
|
|
||||||
$dateRecipient = $this->resource['date_recipient'] ?? null;
|
|
||||||
} else {
|
|
||||||
// Для FoxPro записей в архиве
|
|
||||||
$dateRecipient = $this->resource['mpostdate'] ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cardNumber = $this->resource['card_number'] ?? null;
|
|
||||||
$archiveNum = $this->resource['archive_num'] ?? null;
|
$archiveNum = $this->resource['archive_num'] ?? null;
|
||||||
$postIn = $this->resource['post_in'] ?? null;
|
$postIn = $this->resource['post_in'] ?? null;
|
||||||
$status = $this->resource['status_text'] ?? 'Неизвестно';
|
$status = $this->resource['status_text'] ?? 'Неизвестно';
|
||||||
@@ -64,8 +62,10 @@ class SttMedicalHistoryResource extends JsonResource
|
|||||||
$formattedDateExtract = $dateExtract ? Carbon::parse($dateExtract)->format('d.m.Y') : null;
|
$formattedDateExtract = $dateExtract ? Carbon::parse($dateExtract)->format('d.m.Y') : null;
|
||||||
$formattedPostIn = $postIn ? Carbon::parse($postIn)->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 [
|
return [
|
||||||
'id' => $this->resource['id'],
|
'id' => $id,
|
||||||
'history_type' => $historyType,
|
'history_type' => $historyType,
|
||||||
'in_archive' => $isFromArchive,
|
'in_archive' => $isFromArchive,
|
||||||
'is_temporary' => $isTemporary,
|
'is_temporary' => $isTemporary,
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ class MedicalHistoryRepository
|
|||||||
WHERE NOT EXISTS (
|
WHERE NOT EXISTS (
|
||||||
SELECT 1 FROM archive_infos ai
|
SELECT 1 FROM archive_infos ai
|
||||||
WHERE ai.mis_history_id = mh.\"MedicalHistoryID\"
|
WHERE ai.mis_history_id = mh.\"MedicalHistoryID\"
|
||||||
)
|
) AND mh.\"DateExtract\" > CAST('01-01-1900' as date)
|
||||||
";
|
";
|
||||||
|
|
||||||
$misConditions = $this->buildMisConditions($searchText, $status);
|
$misConditions = $this->buildMisConditions($searchText, $status);
|
||||||
@@ -425,6 +425,7 @@ class MedicalHistoryRepository
|
|||||||
COALESCE(mh.\"Name\", fp.im), ' ',
|
COALESCE(mh.\"Name\", fp.im), ' ',
|
||||||
COALESCE(mh.\"OT\", fp.ot)
|
COALESCE(mh.\"OT\", fp.ot)
|
||||||
) as full_name,
|
) as full_name,
|
||||||
|
COALESCE(mh.\"DateRecipient\", fp.mpostdate) as date_recipient,
|
||||||
COALESCE(mh.\"DateExtract\", fp.menddate) as date_extract,
|
COALESCE(mh.\"DateExtract\", fp.menddate) as date_extract,
|
||||||
COALESCE(mh.\"BD\", fp.dr) as birth_date,
|
COALESCE(mh.\"BD\", fp.dr) as birth_date,
|
||||||
true as in_archive,
|
true as in_archive,
|
||||||
@@ -478,6 +479,7 @@ class MedicalHistoryRepository
|
|||||||
mh.\"Name\" as name,
|
mh.\"Name\" as name,
|
||||||
mh.\"OT\" as ot,
|
mh.\"OT\" as ot,
|
||||||
CONCAT(mh.\"FAMILY\", ' ', mh.\"Name\", ' ', COALESCE(mh.\"OT\", '')) as full_name,
|
CONCAT(mh.\"FAMILY\", ' ', mh.\"Name\", ' ', COALESCE(mh.\"OT\", '')) as full_name,
|
||||||
|
mh.\"DateRecipient\" as date_recipient,
|
||||||
mh.\"DateExtract\" as date_extract,
|
mh.\"DateExtract\" as date_extract,
|
||||||
mh.\"BD\" as birth_date,
|
mh.\"BD\" as birth_date,
|
||||||
false as in_archive,
|
false as in_archive,
|
||||||
@@ -491,6 +493,7 @@ class MedicalHistoryRepository
|
|||||||
NULL as enp
|
NULL as enp
|
||||||
FROM stt_medicalhistory mh
|
FROM stt_medicalhistory mh
|
||||||
WHERE mh.\"MedicalHistoryID\" IN ({$placeholders})
|
WHERE mh.\"MedicalHistoryID\" IN ({$placeholders})
|
||||||
|
AND mh.\"DateExtract\" > CAST('01-01-1900' AS DATE)
|
||||||
";
|
";
|
||||||
|
|
||||||
$results = DB::select($sql, $ids);
|
$results = DB::select($sql, $ids);
|
||||||
@@ -659,7 +662,8 @@ class MedicalHistoryRepository
|
|||||||
// Добавляем NOT EXISTS в начало
|
// Добавляем NOT EXISTS в начало
|
||||||
$allConditions = array_merge(
|
$allConditions = array_merge(
|
||||||
["NOT EXISTS (SELECT 1 FROM archive_infos ai WHERE ai.mis_history_id = mh.\"MedicalHistoryID\")"],
|
["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 = "
|
$sql = "
|
||||||
@@ -688,6 +692,7 @@ class MedicalHistoryRepository
|
|||||||
'family' => $item->family,
|
'family' => $item->family,
|
||||||
'name' => $item->name,
|
'name' => $item->name,
|
||||||
'ot' => $item->ot,
|
'ot' => $item->ot,
|
||||||
|
'date_recipient' => $item->date_recipient,
|
||||||
'date_extract' => $item->date_extract,
|
'date_extract' => $item->date_extract,
|
||||||
'birth_date' => $item->birth_date,
|
'birth_date' => $item->birth_date,
|
||||||
'created_at' => $item->created_at,
|
'created_at' => $item->created_at,
|
||||||
@@ -886,6 +891,7 @@ class MedicalHistoryRepository
|
|||||||
true as in_archive,
|
true as in_archive,
|
||||||
'archive' as source,
|
'archive' as source,
|
||||||
ai.created_at,
|
ai.created_at,
|
||||||
|
COALESCE(mh.\"DateRecipient\", fp.mpostdate) as date_recipient,
|
||||||
COALESCE(mh.\"DateExtract\", fp.menddate) as date_extract
|
COALESCE(mh.\"DateExtract\", fp.menddate) as date_extract
|
||||||
FROM archive_infos ai
|
FROM archive_infos ai
|
||||||
LEFT JOIN stt_medicalhistory mh ON ai.mis_history_id = mh.\"MedicalHistoryID\"
|
LEFT JOIN stt_medicalhistory mh ON ai.mis_history_id = mh.\"MedicalHistoryID\"
|
||||||
@@ -918,6 +924,7 @@ class MedicalHistoryRepository
|
|||||||
false as in_archive,
|
false as in_archive,
|
||||||
'mis' as source,
|
'mis' as source,
|
||||||
mh.\"DateExtract\" as created_at,
|
mh.\"DateExtract\" as created_at,
|
||||||
|
mh.\"DateRecipient\" as date_recipient,
|
||||||
mh.\"DateExtract\" as date_extract
|
mh.\"DateExtract\" as date_extract
|
||||||
FROM stt_medicalhistory mh
|
FROM stt_medicalhistory mh
|
||||||
WHERE mh.\"MedCardNum\" = ?
|
WHERE mh.\"MedCardNum\" = ?
|
||||||
|
|||||||
Reference in New Issue
Block a user