40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Treatment;
|
|
use App\Models\Medicine;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Carbon\Carbon;
|
|
|
|
class MedicalDashboardController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
// 1. Tren Penyakit Bulanan (Data 6 Bulan Terakhir)
|
|
$monthlyTrends = Treatment::select(
|
|
DB::raw('MONTHNAME(tanggal) as month'),
|
|
DB::raw('COUNT(*) as total')
|
|
)
|
|
->where('tanggal', '>=', now()->subMonths(6))
|
|
->groupBy('month', DB::raw('MONTH(tanggal)'))
|
|
->orderBy(DB::raw('MONTH(tanggal)'))
|
|
->get();
|
|
|
|
// 2. Daftar Obat Paling Sering Digunakan (Top 5)
|
|
$topMedicines = Treatment::select('nama_obat', DB::raw('SUM(qty_used) as total_used'))
|
|
->groupBy('nama_obat')
|
|
->orderByDesc('total_used')
|
|
->take(5)
|
|
->get();
|
|
|
|
// 3. Keluhan/Penyakit yang Paling Sering Muncul
|
|
$topComplaints = Treatment::select('keluhan', DB::raw('COUNT(*) as total'))
|
|
->groupBy('keluhan')
|
|
->orderByDesc('total')
|
|
->take(5)
|
|
->get();
|
|
|
|
return view('pages.dashboard.medical', compact('monthlyTrends', 'topMedicines', 'topComplaints'));
|
|
}
|
|
} |