diff --git a/app/Http/Controllers/PatientController.php b/app/Http/Controllers/PatientController.php index f056ce9..f83016b 100644 --- a/app/Http/Controllers/PatientController.php +++ b/app/Http/Controllers/PatientController.php @@ -2,9 +2,64 @@ namespace App\Http\Controllers; +use App\Http\Requests\ManagePatient\StoreNewPatient; +use App\Http\Requests\ManagePatient\UpdatePatient; +use App\Models\Patient; use Illuminate\Http\Request; class PatientController extends Controller { - // + public function index() + { + $patients = Patient::all(); + return view('patient.index', compact('patients')); + } + + public function create() + { + return view('patient.add'); + } + + public function store(StoreNewPatient $request) + { + $patient = new Patient(); + $patient->fill($request->validated()); + + // Generate a 16-character medical record number + $uniqueNumber = str_pad(rand(1, 99999999), 8, '0', STR_PAD_LEFT); // Ensure 8 digits + $timestamp = substr(time(), -5); // Take the last 8 digits of the timestamp + $patient->medical_record_number = 'MR' . $timestamp . $uniqueNumber; // Combine to make 16 characters + $patient->save(); + + return redirect()->route('patient-management.index')->with('success', 'Data pasien baru berhasil ditambahkan!'); + } + + public function show($id) + { + $patient = Patient::findOrFail($id); + return view('patient.show', compact('patient')); + } + + public function edit($id) + { + $patient = Patient::findOrFail($id); + return view('patient.edit', compact('patient')); + } + + public function update(UpdatePatient $request, $id) + { + $patient = Patient::findOrFail($id); + $patient->fill($request->validated()); + $patient->save(); + + return redirect()->route('patient-management.index')->with('success', 'Data pasien berhasil diperbarui!'); + } + + public function destroy($id) + { + $patient = Patient::findOrFail($id); + $patient->delete(); + + return redirect()->route('patient-management.index')->with('success', 'Data pasien berhasil dihapus!'); + } } diff --git a/app/Http/Requests/ManagePatient/StoreNewPatient.php b/app/Http/Requests/ManagePatient/StoreNewPatient.php new file mode 100644 index 0000000..933a2bf --- /dev/null +++ b/app/Http/Requests/ManagePatient/StoreNewPatient.php @@ -0,0 +1,80 @@ +|string> + */ + public function rules(): array + { + return [ + 'identity_number' => ['required', 'numeric', 'unique:patients,identity_number'], + 'first_name' => ['required', 'string', 'max:255'], + 'last_name' => ['required', 'string', 'max:255'], + 'birth_date' => ['required', 'date'], + 'gender' => ['required', Rule::in(['L', 'P'])], + 'blood_type' => ['required', Rule::in(['A', 'B', 'AB', 'O'])], + 'phone_number' => ['required', 'string', 'max:15'], + 'email' => ['required', 'email', 'unique:patients,email'], + 'address' => ['required', 'string'], + 'allergies' => ['required', 'string'], + 'current_medicines' => ['required', 'string'], + 'medical_history' => ['required', 'string'], + ]; + } + + /** + * Get custom error messages for validation rules. + * + * @return array + */ + public function messages(): array + { + return [ + 'identity_number.required' => 'NIK wajib diisi.', + 'identity_number.numeric' => 'NIK harus berupa angka.', + 'identity_number.unique' => 'NIK sudah terdaftar.', + 'first_name.required' => 'Nama depan wajib diisi.', + 'first_name.string' => 'Nama depan harus berupa teks.', + 'first_name.max' => 'Nama depan tidak boleh lebih dari 255 karakter.', + 'last_name.required' => 'Nama belakang wajib diisi.', + 'last_name.string' => 'Nama belakang harus berupa teks.', + 'last_name.max' => 'Nama belakang tidak boleh lebih dari 255 karakter.', + 'birth_date.required' => 'Tanggal lahir wajib diisi.', + 'birth_date.date' => 'Tanggal lahir harus berupa tanggal yang valid.', + 'gender.required' => 'Jenis kelamin wajib dipilih.', + 'gender.in' => 'Jenis kelamin harus berupa Laki-Laki (L) atau Perempuan (P).', + 'blood_type.required' => 'Golongan darah wajib dipilih.', + 'blood_type.in' => 'Golongan darah harus berupa A, B, AB, atau O.', + 'phone_number.required' => 'Nomor HP wajib diisi.', + 'phone_number.string' => 'Nomor HP harus berupa teks.', + 'phone_number.max' => 'Nomor HP tidak boleh lebih dari 15 karakter.', + 'email.required' => 'Email wajib diisi.', + 'email.email' => 'Email harus berupa alamat email yang valid.', + 'email.unique' => 'Email sudah terdaftar.', + 'address.required' => 'Alamat wajib diisi.', + 'address.string' => 'Alamat harus berupa teks.', + 'allergies.required' => 'Alergi wajib diisi.', + 'allergies.string' => 'Alergi harus berupa teks.', + 'current_medicines.required' => 'Konsumsi obat saat ini wajib diisi.', + 'current_medicines.string' => 'Konsumsi obat saat ini harus berupa teks.', + 'medical_history.required' => 'Histori medis wajib diisi.', + 'medical_history.string' => 'Histori medis harus berupa teks.', + ]; + } +} diff --git a/app/Http/Requests/ManagePatient/UpdatePatient.php b/app/Http/Requests/ManagePatient/UpdatePatient.php new file mode 100644 index 0000000..5d2fa6f --- /dev/null +++ b/app/Http/Requests/ManagePatient/UpdatePatient.php @@ -0,0 +1,88 @@ +|string> + */ + public function rules(): array + { + return [ + 'identity_number' => [ + 'required', + 'numeric', + Rule::unique('patients', 'identity_number')->ignore($this->route('id')), + ], + 'first_name' => ['required', 'string', 'max:255'], + 'last_name' => ['required', 'string', 'max:255'], + 'birth_date' => ['required', 'date'], + 'gender' => ['required', Rule::in(['L', 'P'])], + 'blood_type' => ['required', Rule::in(['A', 'B', 'AB', 'O'])], + 'phone_number' => ['required', 'string', 'max:15'], + 'email' => [ + 'required', + 'email', + Rule::unique('patients', 'email')->ignore($this->route('id')), + ], + 'address' => ['required', 'string'], + 'allergies' => ['required', 'string'], + 'current_medicines' => ['required', 'string'], + 'medical_history' => ['required', 'string'], + ]; + } + + /** + * Get custom error messages for validation rules. + * + * @return array + */ + public function messages(): array + { + return [ + 'identity_number.required' => 'NIK wajib diisi.', + 'identity_number.numeric' => 'NIK harus berupa angka.', + 'identity_number.unique' => 'NIK sudah terdaftar.', + 'first_name.required' => 'Nama depan wajib diisi.', + 'first_name.string' => 'Nama depan harus berupa teks.', + 'first_name.max' => 'Nama depan tidak boleh lebih dari 255 karakter.', + 'last_name.required' => 'Nama belakang wajib diisi.', + 'last_name.string' => 'Nama belakang harus berupa teks.', + 'last_name.max' => 'Nama belakang tidak boleh lebih dari 255 karakter.', + 'birth_date.required' => 'Tanggal lahir wajib diisi.', + 'birth_date.date' => 'Tanggal lahir harus berupa tanggal yang valid.', + 'gender.required' => 'Jenis kelamin wajib dipilih.', + 'gender.in' => 'Jenis kelamin harus berupa Laki-Laki (L) atau Perempuan (P).', + 'blood_type.required' => 'Golongan darah wajib dipilih.', + 'blood_type.in' => 'Golongan darah harus berupa A, B, AB, atau O.', + 'phone_number.required' => 'Nomor HP wajib diisi.', + 'phone_number.string' => 'Nomor HP harus berupa teks.', + 'phone_number.max' => 'Nomor HP tidak boleh lebih dari 15 karakter.', + 'email.required' => 'Email wajib diisi.', + 'email.email' => 'Email harus berupa alamat email yang valid.', + 'email.unique' => 'Email sudah terdaftar.', + 'address.required' => 'Alamat wajib diisi.', + 'address.string' => 'Alamat harus berupa teks.', + 'allergies.required' => 'Alergi wajib diisi.', + 'allergies.string' => 'Alergi harus berupa teks.', + 'current_medicines.required' => 'Konsumsi obat saat ini wajib diisi.', + 'current_medicines.string' => 'Konsumsi obat saat ini harus berupa teks.', + 'medical_history.required' => 'Histori medis wajib diisi.', + 'medical_history.string' => 'Histori medis harus berupa teks.', + ]; + } +} diff --git a/app/Models/Patient.php b/app/Models/Patient.php index aaa1032..7bcfad5 100644 --- a/app/Models/Patient.php +++ b/app/Models/Patient.php @@ -9,4 +9,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; class Patient extends Model { use HasFactory, SoftDeletes; + + protected $table = "patients"; + protected $guarded = ["id"]; } diff --git a/database/migrations/2025_04_27_015119_create_patients_table.php b/database/migrations/2025_04_27_015119_create_patients_table.php index fb89c76..943e7e4 100644 --- a/database/migrations/2025_04_27_015119_create_patients_table.php +++ b/database/migrations/2025_04_27_015119_create_patients_table.php @@ -27,9 +27,9 @@ return new class extends Migration // Medical Information $table->string('blood_type', 10); // (Golongan Darah) - $table->string('allergies'); - $table->string('current_medicines'); - $table->text('medical_history'); + $table->string('allergies')->nullable(); // (Alergi) + $table->string('current_medicines')->nullable(); // (Obat yang Sedang Dikonsumsi) + $table->text('medical_history')->nullable(); // (Riwayat Penyakit) $table->timestamps(); $table->softDeletes(); }); diff --git a/resources/views/patient/add.blade.php b/resources/views/patient/add.blade.php new file mode 100644 index 0000000..e7af1e4 --- /dev/null +++ b/resources/views/patient/add.blade.php @@ -0,0 +1,170 @@ +@extends('layouts.app') +@section('content-header') +
+
+
+
+

Tambah Pasien

+
+
+ +
+
+
+
+@endsection +@section('main-content') +
+
+
+
+

Data Pasien

+
+
+ @csrf +
+
+
+
+ + + @error('identity_number') + {{ $message }} + @enderror +
+
+ + + @error('first_name') + {{ $message }} + @enderror +
+
+ + + @error('last_name') + {{ $message }} + @enderror +
+
+ + + @error('birth_date') + {{ $message }} + @enderror +
+
+ + + @error('gender') + {{ $message }} + @enderror +
+
+ + + @error('phone_number') + {{ $message }} + @enderror +
+
+ + + @error('email') + {{ $message }} + @enderror +
+
+
+
+ + + @error('gender') + {{ $message }} + @enderror +
+
+ + + @error('address') + {{ $message }} + @enderror +
+
+ + + @error('allergies') + {{ $message }} + @enderror +
+
+ + + @error('current_medicines') + {{ $message }} + @enderror +
+
+ + + @error('medical_history') + {{ $message }} + @enderror +
+
+
+
+ + * Wajib Diisi + + +
+
+
+
+@endsection +@push('scripts') + @if (session('success')) + + @endif +@endpush diff --git a/resources/views/patient/edit.blade.php b/resources/views/patient/edit.blade.php new file mode 100644 index 0000000..e19b43d --- /dev/null +++ b/resources/views/patient/edit.blade.php @@ -0,0 +1,187 @@ +@extends('layouts.app') +@section('content-header') +
+
+
+
+

Edit Pasien

+
+
+ +
+
+
+
+@endsection +@section('main-content') +
+
+
+
+

Edit Data Pasien

+
+
+ @csrf + @method('PUT') +
+
+
+
+ + +
+
+ + + @error('identity_number') + {{ $message }} + @enderror +
+
+ + + @error('first_name') + {{ $message }} + @enderror +
+
+ + + @error('last_name') + {{ $message }} + @enderror +
+
+ + + @error('birth_date') + {{ $message }} + @enderror +
+
+ + + @error('gender') + {{ $message }} + @enderror +
+
+ + + @error('phone_number') + {{ $message }} + @enderror +
+
+ + + @error('email') + {{ $message }} + @enderror +
+
+
+
+ + + @error('blood_type') + {{ $message }} + @enderror +
+
+ + + @error('address') + {{ $message }} + @enderror +
+
+ + + @error('allergies') + {{ $message }} + @enderror +
+
+ + + @error('current_medicines') + {{ $message }} + @enderror +
+
+ + + @error('medical_history') + {{ $message }} + @enderror +
+
+
+
+ + * Wajib Diisi + + +
+
+
+
+@endsection +@push('scripts') + @if (session('success')) + + @endif +@endpush diff --git a/resources/views/patient/index.blade.php b/resources/views/patient/index.blade.php new file mode 100644 index 0000000..e090d23 --- /dev/null +++ b/resources/views/patient/index.blade.php @@ -0,0 +1,158 @@ +@extends('layouts.app') + +@push('styles') + + + + +@endpush + +@section('content-header') +
+
+
+
+

Manajemen Pasien

+
+
+ +
+
+
+
+@endsection + +@section('main-content') +
+ +
+ + + + + + + + + + + + @foreach ($patients as $index => $data) + + + + + + + + @endforeach + +
NoRekam MedisNama LengkapDibuat PadaAksi
{{ $index + 1 }}{{ $data->medical_record_number }}{{ $data->first_name }} {{ $data->last_name }}{{ $data->created_at }} + +   Lihat + + + +   Edit + + + +
+
+ +
+ + + + +@endsection + +@push('scripts') + @if (session('success')) + + @endif + @if (session('error')) + + @endif + + + + + + + +@endpush diff --git a/resources/views/patient/show.blade.php b/resources/views/patient/show.blade.php new file mode 100644 index 0000000..fb7be0a --- /dev/null +++ b/resources/views/patient/show.blade.php @@ -0,0 +1,53 @@ +@extends('layouts.app') +@section('content-header') +
+
+
+
+

Detail Pasien

+
+
+ +
+
+
+
+@endsection +@section('main-content') +
+
+
+
+

Data Pasien

+
+
+
+
+

No. Rekam Medis: {{ $patient->medical_record_number }}

+

NIK: {{ $patient->identity_number }}

+

Nama Depan: {{ $patient->first_name }}

+

Nama Belakang: {{ $patient->last_name }}

+

Tanggal Lahir: {{ $patient->birth_date }}

+

Jenis Kelamin: {{ $patient->gender == 'L' ? 'Laki-Laki' : 'Perempuan' }}

+

No. HP: {{ $patient->phone_number }}

+

Email: {{ $patient->email }}

+
+
+

Golongan Darah: {{ $patient->blood_type }}

+

Alamat: {{ $patient->address }}

+

Alergi: {{ $patient->allergies }}

+

Konsumsi Obat Saat Ini: {{ $patient->current_medicines }}

+

Histori Medis: {{ $patient->medical_history }}

+
+
+
+ +
+
+
+@endsection diff --git a/routes/web.php b/routes/web.php index 88d4478..a49dd69 100644 --- a/routes/web.php +++ b/routes/web.php @@ -5,6 +5,7 @@ use App\Http\Controllers\DashboardController; use App\Http\Controllers\ManageUserController; use App\Http\Controllers\ProfileController; use App\Http\Controllers\InsuranceController; +use App\Http\Controllers\PatientController; use App\Http\Controllers\ServiceRoomController; use App\Http\Controllers\TreatmentController; use Illuminate\Support\Facades\Route; @@ -67,6 +68,15 @@ Route::middleware('auth')->group(function () { Route::delete('/ruang-pelayanan/{id}', [ServiceRoomController::class, 'destroy'])->name('service-room.destroy'); }); + # Manage Pasien + Route::get('/pasien', [PatientController::class, 'index'])->name('patient-management.index'); + Route::get('/pasien/tambah', [PatientController::class, 'create'])->name('patient-management.create'); + Route::post('/pasien', [PatientController::class, 'store'])->name('patient-management.store'); + Route::get('/pasien/{id}/edit', [PatientController::class, 'edit'])->name('patient-management.edit'); + Route::put('/pasien/{id}', [PatientController::class, 'update'])->name('patient-management.update'); + Route::delete('/pasien/{id}', [PatientController::class, 'destroy'])->name('patient-management.destroy'); + Route::get('/pasien/{id}', [PatientController::class, 'show'])->name('patient-management.show'); + // Profile Page Route::get('/profil-akun', [ProfileController::class, 'edit'])->name('profile.edit'); Route::put('/profil-akun', [ProfileController::class, 'update'])->name('profile.update');