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