128 lines
3.3 KiB
PHP
128 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Controllers\helper\helperController;
|
|
use App\Models\patient;
|
|
use Illuminate\Http\Request;
|
|
|
|
class PatientController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$data = [
|
|
'title' => 'Pasien'
|
|
];
|
|
return view('pasien.index', $data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
try {
|
|
$data = request()->validate([
|
|
'name' => 'required',
|
|
'birth' => 'required',
|
|
'gender' => 'required'
|
|
],[
|
|
'name.required' => 'Nama wajib diisi',
|
|
'birth.required' => 'Tanggal lahir wajib diisi',
|
|
'gender.required' => 'Jenis kelamin wajib diisi'
|
|
]);
|
|
$data['uid'] = (new helperController)->getUid();
|
|
patient::create($data);
|
|
return response()->json([
|
|
'status' => 'success',
|
|
'message' => 'Berhasil menambahkan data'
|
|
]);
|
|
} catch (\Throwable $th) {
|
|
return response()->json([
|
|
'status'=> 'error',
|
|
'message' => 'Gagal, Terdapat kesalahan' . $th->getMessage()
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(patient $patient)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(patient $patient)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, string $uid)
|
|
{
|
|
try {
|
|
$data = request()->validate([
|
|
'name' => 'required',
|
|
'birth' => 'required',
|
|
'gender' => 'required'
|
|
],[
|
|
'name.required' => 'Nama wajib diisi',
|
|
'birth.required' => 'Tanggal lahir wajib diisi',
|
|
'gender.required' => 'Jenis kelamin wajib diisi'
|
|
]);
|
|
$patient = patient::where('uid', $uid)->first();
|
|
$patient->update($data);
|
|
return response()->json([
|
|
'status' => 'success',
|
|
'message' => 'Berhasil mengupdate data'
|
|
], 200);
|
|
} catch (\Throwable $th) {
|
|
return response()->json([
|
|
'status'=> 'error',
|
|
'message' => 'Gagal, Terdapat kesalahan' . $th->getMessage()
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $uid)
|
|
{
|
|
try {
|
|
patient::where('uid', $uid)->update([
|
|
'is_delete' => true
|
|
]);
|
|
return response()->json([
|
|
'status' => 'success',
|
|
'message' => 'Berhasil! Hapus data'
|
|
]);
|
|
} catch (\Throwable $th) {
|
|
return response()->json([
|
|
'status' => 'error',
|
|
'message' => 'gagal! hapus data' . $th->getMessage()
|
|
]);
|
|
}
|
|
}
|
|
public function datatable(){
|
|
return patient::where('is_delete', false)->get();
|
|
}
|
|
}
|