Профиль хирургии
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Models\Report;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SnapshotService
|
||||
{
|
||||
@@ -182,28 +183,41 @@ class SnapshotService
|
||||
?int $branchId = null,
|
||||
bool $onlyIds = false
|
||||
): Collection {
|
||||
// Для плановых и экстренных включаем уже лечащихся
|
||||
// $includeCurrent = in_array($type, ['plan', 'emergency']);
|
||||
|
||||
$medicalHistoryIds = MedicalHistorySnapshot::whereIn('rf_report_id', $reportIds)
|
||||
// Получаем ID историй болезни напрямую через DB::table() — это быстрее
|
||||
$medicalHistoryIds = DB::table('medical_history_snapshots')
|
||||
->select('rf_medicalhistory_id')
|
||||
->whereIn('rf_report_id', $reportIds)
|
||||
->where('patient_type', $type)
|
||||
->pluck('rf_medicalhistory_id')
|
||||
->unique()
|
||||
->toArray();
|
||||
->distinct()
|
||||
->pluck('rf_medicalhistory_id');
|
||||
|
||||
if (empty($medicalHistoryIds)) {
|
||||
if ($medicalHistoryIds->isEmpty()) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
if ($onlyIds) {
|
||||
return collect($medicalHistoryIds);
|
||||
$query = MisMedicalHistory::whereIn('MedicalHistoryID', $medicalHistoryIds);
|
||||
|
||||
if ($type === 'plan') {
|
||||
$query->plan();
|
||||
} elseif ($type === 'emergency') {
|
||||
$query->emergency();
|
||||
}
|
||||
|
||||
return MisMedicalHistory::whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->when($type === 'plan', fn($q) => $q->plan())
|
||||
->when($type === 'emergency', fn($q) => $q->emergency())
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->get();
|
||||
// Загрузка отношений, необходимых для FormattedPatientResource
|
||||
$query->with([
|
||||
'outcomeMigration.mainDiagnosis.mkb', // mkb через диагноз
|
||||
'surgicalOperations.serviceMedical', // операции с услугами
|
||||
]);
|
||||
|
||||
$query->orderBy('DateRecipient', 'DESC');
|
||||
|
||||
$results = $query->get();
|
||||
|
||||
if ($onlyIds) {
|
||||
return $results->pluck('MedicalHistoryID');
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user