56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Aturan;
|
|
use App\Models\Indikator;
|
|
use App\Models\Penyakit;
|
|
use App\Models\RiwayatKonsultasi;
|
|
use Illuminate\Http\Request;
|
|
use App\Services\DempsterShaferService;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class KonsultasiController extends Controller
|
|
{
|
|
public function getGejala()
|
|
{
|
|
$gejala = Indikator::all();
|
|
|
|
return response()->json(
|
|
$gejala
|
|
);
|
|
}
|
|
|
|
public function predictDisease(Request $request)
|
|
{
|
|
$indicators = $request->input('indicators');
|
|
|
|
if (is_null($indicators)) {
|
|
return response()->json(['error' => 'No indicators provided'], 400);
|
|
}
|
|
|
|
$prediction = DempsterShaferService::calculatePrediction($indicators);
|
|
|
|
|
|
$riwayatKonsultasi = new RiwayatKonsultasi();
|
|
$riwayatKonsultasi->id_user = auth()->id();
|
|
$riwayatKonsultasi->indikator = Indikator::whereIn('id', $indicators)->pluck('indikator')->implode(', ');
|
|
$riwayatKonsultasi->penyakit = $prediction['predicted_disease']->penyakit;
|
|
$riwayatKonsultasi->nilai_cf = $prediction['confidence_score'];
|
|
$riwayatKonsultasi->save();
|
|
|
|
return response()->json([
|
|
'predicted_disease' => $prediction['predicted_disease'],
|
|
'confidence_score' => $prediction['confidence_score'],
|
|
]);
|
|
}
|
|
|
|
public function getRiwayat()
|
|
{
|
|
return response()->json(RiwayatKonsultasi::where('id_user', Auth::id())
|
|
->get());
|
|
}
|
|
} |