Изменения в основном report
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user