initial commit
This commit is contained in:
@@ -3,15 +3,12 @@
|
||||
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')
|
||||
@@ -21,20 +18,28 @@ class MedicalDashboardController extends Controller
|
||||
->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')
|
||||
// treatments memakai medicine_id. Nama obat diambil dari tabel medicines.
|
||||
$topObats = Treatment::query()
|
||||
->join('medicines', 'treatments.medicine_id', '=', 'medicines.id')
|
||||
->select(
|
||||
'medicines.id',
|
||||
'medicines.nama_obat',
|
||||
DB::raw('SUM(treatments.qty_used) as total_used')
|
||||
)
|
||||
->whereNotNull('treatments.medicine_id')
|
||||
->groupBy('medicines.id', 'medicines.nama_obat')
|
||||
->orderByDesc('total_used')
|
||||
->take(5)
|
||||
->limit(5)
|
||||
->get();
|
||||
|
||||
// 3. Keluhan/Penyakit yang Paling Sering Muncul
|
||||
$topComplaints = Treatment::select('keluhan', DB::raw('COUNT(*) as total'))
|
||||
->whereNotNull('keluhan')
|
||||
->where('keluhan', '!=', '')
|
||||
->groupBy('keluhan')
|
||||
->orderByDesc('total')
|
||||
->take(5)
|
||||
->limit(5)
|
||||
->get();
|
||||
|
||||
return view('pages.dashboard.medical', compact('monthlyTrends', 'topMedicines', 'topComplaints'));
|
||||
return view('pages.dashboard.medical', compact('monthlyTrends', 'topObats', 'topComplaints'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user