Изменения в основном 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,7 +3,9 @@
namespace App\Services;
use App\Models\MisMigrationPatient;
use App\Models\MedicalHistory;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class CurrentPatientService
{
@@ -13,6 +15,20 @@ class CurrentPatientService
public function getCurrentMedicalHistoryIds(string $type, int $branchId, DateRange $dateRange, bool $fillableAuto = false)
{
if (! $fillableAuto && $this->useMaterializedViews()) {
return MedicalHistory::query()
->when($type === 'plan', fn ($query) => $query->urgency(1))
->when($type === 'emergency', fn ($query) => $query->whereIn('urgency_id', self::EMERGENCY_STATUSES))
->whereHas('migrations', fn ($query) => $query
->where('stationar_branch_id', $branchId)
->current($dateRange))
->pluck('original_id')
->filter()
->map(fn ($id) => (int) $id)
->values()
->all();
}
if ($fillableAuto) {
return $this->getHistoricalCurrentMedicalHistoryIds($type, $branchId, $dateRange);
}
@@ -79,4 +95,9 @@ class CurrentPatientService
->pluck('last_mp.rf_MedicalHistoryID')
->toArray();
}
private function useMaterializedViews(): bool
{
return Schema::hasTable('mv_medicalhistory_summary') && Schema::hasTable('mv_migrationpatient_details');
}
}