Изменения в основном report

This commit is contained in:
brusnitsyn
2026-05-06 22:32:11 +09:00
parent c5da85763c
commit 723ccee8d3
56 changed files with 1911 additions and 3814 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Services;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use App\Models\MedicalHistory;
class RecipientPatientService
{
@@ -33,6 +35,17 @@ class RecipientPatientService
DateRange $dateRange,
bool $fillableAuto = false
) {
if (! $fillableAuto && $this->useMaterializedViews()) {
return MedicalHistory::query()
->selectRaw('original_id as "rf_MedicalHistoryID"')
->whereHas('migrations', fn ($query) => $query
->where('stationar_branch_id', $branchId)
->admitted($dateRange->startSql(), $dateRange->endSql()))
->when($type === 'plan', fn ($query) => $query->urgency(1))
->when($type === 'emergency', fn ($query) => $query->whereIn('urgency_id', [2, 4]))
->distinct();
}
$startAt = $dateRange->start()->copy()->format('Y-m-d H:i:s');
$endAt = $dateRange->end()->copy()->format('Y-m-d H:i:s');
@@ -96,4 +109,9 @@ class RecipientPatientService
return array_values(array_unique(array_merge($recipientIds, $currentIds)));
}
private function useMaterializedViews(): bool
{
return Schema::hasTable('mv_medicalhistory_summary') && Schema::hasTable('mv_migrationpatient_details');
}
}