diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a186cd2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 + +[compose.yaml] +indent_size = 4 diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c0660ea --- /dev/null +++ b/.env.example @@ -0,0 +1,65 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY= +APP_DEBUG=true +APP_URL=http://localhost + +APP_LOCALE=en +APP_FALLBACK_LOCALE=en +APP_FAKER_LOCALE=en_US + +APP_MAINTENANCE_DRIVER=file +# APP_MAINTENANCE_STORE=database + +# PHP_CLI_SERVER_WORKERS=4 + +BCRYPT_ROUNDS=12 + +LOG_CHANNEL=stack +LOG_STACK=single +LOG_DEPRECATIONS_CHANNEL=null +LOG_LEVEL=debug + +DB_CONNECTION=sqlite +# DB_HOST=127.0.0.1 +# DB_PORT=3306 +# DB_DATABASE=laravel +# DB_USERNAME=root +# DB_PASSWORD= + +SESSION_DRIVER=database +SESSION_LIFETIME=120 +SESSION_ENCRYPT=false +SESSION_PATH=/ +SESSION_DOMAIN=null + +BROADCAST_CONNECTION=log +FILESYSTEM_DISK=local +QUEUE_CONNECTION=database + +CACHE_STORE=database +# CACHE_PREFIX= + +MEMCACHED_HOST=127.0.0.1 + +REDIS_CLIENT=phpredis +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=log +MAIL_SCHEME=null +MAIL_HOST=127.0.0.1 +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_FROM_ADDRESS="hello@example.com" +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= +AWS_USE_PATH_STYLE_ENDPOINT=false + +VITE_APP_NAME="${APP_NAME}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b71b1ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +*.log +.DS_Store +.env +.env.backup +.env.production +.phpactor.json +.phpunit.result.cache +/.fleet +/.idea +/.nova +/.phpunit.cache +/.vscode +/.zed +/auth.json +/node_modules +/public/build +/public/hot +/public/storage +/storage/*.key +/storage/pail +/vendor +Homestead.json +Homestead.yaml +Thumbs.db diff --git a/README.md b/README.md new file mode 100644 index 0000000..0165a77 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +
+ + + +## About Laravel + +Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: + +- [Simple, fast routing engine](https://laravel.com/docs/routing). +- [Powerful dependency injection container](https://laravel.com/docs/container). +- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. +- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). +- Database agnostic [schema migrations](https://laravel.com/docs/migrations). +- [Robust background job processing](https://laravel.com/docs/queues). +- [Real-time event broadcasting](https://laravel.com/docs/broadcasting). + +Laravel is accessible, powerful, and provides tools required for large, robust applications. + +## Learning Laravel + +Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. You can also check out [Laravel Learn](https://laravel.com/learn), where you will be guided through building a modern Laravel application. + +If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. + +## Laravel Sponsors + +We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com). + +### Premium Partners + +- **[Vehikl](https://vehikl.com)** +- **[Tighten Co.](https://tighten.co)** +- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)** +- **[64 Robots](https://64robots.com)** +- **[Curotec](https://www.curotec.com/services/technologies/laravel)** +- **[DevSquad](https://devsquad.com/hire-laravel-developers)** +- **[Redberry](https://redberry.international/laravel-development)** +- **[Active Logic](https://activelogic.com)** + +## Contributing + +Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). + +## Code of Conduct + +In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). + +## Security Vulnerabilities + +If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. + +## License + +The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php new file mode 100644 index 0000000..4fa5494 --- /dev/null +++ b/app/Http/Controllers/AuthController.php @@ -0,0 +1,102 @@ +validate([ + 'email' => 'required|email', + 'password' => 'required', + ]); + + $credentials = $request->only('email', 'password'); + $remember = $request->boolean('remember'); + + if (Auth::attempt($credentials, $remember)) { + $request->session()->regenerate(); + return redirect()->intended(route('halaman.prediksi')); + } + + return back() + ->withInput($request->only('email')) + ->with('error', 'Email atau password salah.'); + } + + // ── REGISTER ────────────────────────────────────── + public function showRegister() + { + return view('login.register'); + } + + public function register(Request $request) + { + $request->validate([ + 'email' => 'required|email|unique:users,email', + 'password' => 'required|min:8|confirmed', // confirmed = butuh field password_confirmation + ], [ + 'email.unique' => 'Email ini sudah terdaftar.', + 'password.min' => 'Password minimal 8 karakter.', + 'password.confirmed' => 'Konfirmasi password tidak cocok.', + ]); + + // Ambil nama dari bagian sebelum @ di email + $name = explode('@', $request->email)[0]; + + $user = User::create([ + 'name' => $name, + 'email' => $request->email, + 'password' => Hash::make($request->password), + ]); + + Auth::login($user); + + return redirect()->route('halaman.prediksi'); + } + + // ── LUPA PASSWORD ───────────────────────────────── + public function showLupaPassword() + { + return view('login.lupa-password'); + } + + public function resetPassword(Request $request) + { + $request->validate([ + 'email' => 'required|email|exists:users,email', + 'password' => 'required|min:8|confirmed', + ], [ + 'email.exists' => 'Email tidak ditemukan.', + 'password.min' => 'Password minimal 8 karakter.', + 'password.confirmed' => 'Konfirmasi password tidak cocok.', + ]); + + User::where('email', $request->email)->update([ + 'password' => Hash::make($request->password), + ]); + + return redirect()->route('login')->with('success', 'Password berhasil diubah. Silakan masuk.'); + } + + // ── LOGOUT ──────────────────────────────────────── + public function logout(Request $request) + { + Auth::logout(); + $request->session()->invalidate(); + $request->session()->regenerateToken(); + return redirect('/'); + } +} diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php new file mode 100644 index 0000000..8677cd5 --- /dev/null +++ b/app/Http/Controllers/Controller.php @@ -0,0 +1,8 @@ +with(['prompt' => 'select_account']) + ->redirect(); + } + + // Callback setelah login Google berhasil + public function callback() + { + try { + $googleUser = Socialite::driver('google')->user(); + + $user = User::where('email', $googleUser->getEmail())->first(); + + if ($user) { + // Email sudah ada, update google_id saja + $user->update(['google_id' => $googleUser->getId()]); + } else { + // Email baru, buat akun baru + $user = User::create([ + 'name' => $googleUser->getName(), + 'email' => $googleUser->getEmail(), + 'google_id' => $googleUser->getId(), + 'password' => null, + ]); + } + + Auth::login($user); + + return redirect()->route('halaman.prediksi'); + + } catch (\Exception $e) { + return redirect()->route('login') + ->with('error', $e->getMessage()); + } + } +} diff --git a/app/Http/Controllers/PrediksiController.php b/app/Http/Controllers/PrediksiController.php new file mode 100644 index 0000000..758b80d --- /dev/null +++ b/app/Http/Controllers/PrediksiController.php @@ -0,0 +1,82 @@ +all(); + $gejala = $request->gejala ?? []; + + if (count($gejala) < 2) { + return redirect()->back()->with('error', 'Gejala yang dimasukkan belum cukup untuk melakukan prediksi penyakit.'); + } + + $response = Http::post('https://alyaghania.pythonanywhere.com/predict', [ + "Smoking_Status" => $request->merokok == "ya" ? 1 : 0, + "Alcohol_Use" => $request->alkohol == "ya" ? 1 : 0, + "Stress_Level" => $request->stres == "ya" ? 1 : 0, + + "Abdominal_Pain" => in_array("g1", $gejala) ? 1 : 0, + "Bloating" => in_array("g2", $gejala) ? 1 : 0, + "Heartburn" => in_array("g3", $gejala) ? 1 : 0, + "Rectal_Bleeding"=> in_array("g4", $gejala) ? 1 : 0, + "Appetite_Loss" => in_array("g5", $gejala) ? 1 : 0, + "Weight_Loss" => in_array("g6", $gejala) ? 1 : 0, + + "NSAID_Use" => $request->obat == "ya" ? 1 : 0, + ]); + + $hasil = $response->json()['hasil_prediksi'] ?? "Tidak ada hasil"; + $indikasi = $response->json()['indikasi_lain'] ?? []; + + $mapping = [ + 'GASTRITIS' => 'Gastritis', + 'GERD' => 'Gerd', + 'DISPEPSIA' => 'Dispepsia', + ]; + $hasil = $mapping[$hasil] ?? $hasil; + + // Simpan ke database + if ($hasil != "Tidak ada hasil" && Auth::check()) { + RiwayatPrediksi::create([ + 'user_id' => Auth::id(), + 'nama' => Auth::user()->name, // ambil dari akun + 'jenis_kelamin' => null, + 'umur' => null, + 'gejala' => $gejala, + 'stres' => $request->stres, + 'merokok' => $request->merokok, + 'alkohol' => $request->alkohol, + 'obat' => $request->obat, + 'hasil' => $hasil, + 'indikasi' => $indikasi + ]); + } + + return view('tampilanutama.prediksi', compact('hasil', 'data', 'indikasi')); + } + + // riwayat prediksi + public function riwayat() + { + $riwayat = RiwayatPrediksi::where('user_id', Auth::id()) + ->orderBy('created_at', 'desc') + ->get(); + + return view('tampilanutama.riwayat', compact('riwayat')); + } +} diff --git a/app/Models/RiwayatPrediksi.php b/app/Models/RiwayatPrediksi.php new file mode 100644 index 0000000..a00953a --- /dev/null +++ b/app/Models/RiwayatPrediksi.php @@ -0,0 +1,34 @@ + 'array', + 'indikasi' => 'array', // otomatis convert JSON ke array + ]; + + public function user() + { + return $this->belongsTo(User::class); + } +} diff --git a/app/Models/User.php b/app/Models/User.php new file mode 100644 index 0000000..749c7b7 --- /dev/null +++ b/app/Models/User.php @@ -0,0 +1,48 @@ + */ + use HasFactory, Notifiable; + + /** + * The attributes that are mass assignable. + * + * @var list
+ Reset password akun Anda
+
+ Buat akun baru Anda
+
+ Silakan masuk ke akun Anda
+Pemeriksaan Awal
+Daftar hasil prediksi yang pernah kamu lakukan
+Belum ada riwayat prediksi.
+ Mulai Prediksi +Gejala
+Gaya Hidup
+Indikasi Lain
++ Sistem ini menganalisis gejala dan gaya hidup untuk memberikan gambaran risiko penyakit seperti Dispepsia, Gerd, dan Gastritis. +
+ +
+ Menggunakan metode Decision Tree untuk menghasilkan prediksi yang akurat berdasarkan data klinis yang diinput.
+Data tidak disimpan atau dibagikan kepada pihak lain. Keamanan informasi kesehatan Anda adalah prioritas kami.
++ Melalui kuesioner sederhana, sistem akan menganalisis gejala dan gaya hidup dan memprosesnya dengan metode Decision Tree untuk menampilkan hasil prediksi risiko penyakit. +
+Langkah 01
+Isi data diri
+Masukkan informasi dasar seperti nama, usia, dan jenis kelamin sebagai identitas sebelum memulai pemeriksaan.
+Langkah 02
+Isi kuesioner gejala & gaya hidup
+Jawab pertanyaan seputar gejala yang dirasakan serta kebiasaan gaya hidup Anda seperti stres, kebiasaan merokok, konsumsi alkohol, dan penggunaan obat anti inflamasi
+Langkah 03
+Analisis Decision Tree
+Data yang dimasukkan diolah secara otomatis oleh algoritma pohon keputusan untuk menemukan pola yang paling sesuai.
+Langkah 04
+Hasil prediksi
+Sistem menampilkan kemungkinan risiko jenis penyakit sebagai gambaran awal kondisi kesehatan Anda.
++ Hasil sistem ini bukan diagnosis medis. Informasi yang diberikan hanya sebagai gambaran awal agar pengguna lebih waspada terhadap kondisi kesehatannya. +
+
+ {{ $item['desc'] }}
++ Belum punya akun? Daftar sekarang +
+ @endif + +