initial commit

This commit is contained in:
2026-06-23 13:28:38 +07:00
commit 966ed115b2
590 changed files with 111412 additions and 0 deletions
+158
View File
@@ -0,0 +1,158 @@
<?php
namespace App\Http\Controllers;
use App\Interfaces\DoctorRepositoryInterface;
use App\Interfaces\PatientRepositoryInterface;
use App\Interfaces\UserRepositoryInterface;
use DB;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Throwable;
class AdminController extends Controller
{
private PatientRepositoryInterface $patientRepository;
private DoctorRepositoryInterface $doctorRepository;
public function __construct(
PatientRepositoryInterface $patientRepository,
DoctorRepositoryInterface $doctorRepository
)
{
$this->patientRepository = $patientRepository;
$this->doctorRepository = $doctorRepository;
}
/**
* Assign doctor with patients.
*
* @param Request $request
* @return JsonResponse
* @throws Throwable
*/
public function assign(Request $request): JsonResponse
{
try {
DB::beginTransaction();
$input = $request->all();
$doctor = $this->doctorRepository->getDoctorById($input['doctor_id']);
$patients = $this->patientRepository->getManyPatientById($input['patient_ids']);
$validate = array_values($doctor->patients->pluck('id')->toArray());
foreach ($patients as $patient){
if (in_array($patient->id, $validate)){
continue;
}else{
$patient->doctors()->attach($doctor);
}
}
DB::commit();
return baseResponse(
'success',
'success assign doctor with patients!',
null,
null,
200
);
}catch (Throwable $exception){
DB::rollBack();
return baseResponse(
'failed',
'failed assign doctor with patients!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Unassigned doctor with patients.
*
* @param Request $request
* @return JsonResponse
* @throws Throwable
*/
public function unassign(Request $request): JsonResponse
{
try {
DB::beginTransaction();
$input = $request->all();
$doctor = $this->doctorRepository->getDoctorById($input['doctor_id']);
$patients = $this->patientRepository->getManyPatientById($input['patient_ids']);
foreach ($patients as $patient){
$patient->doctors()->detach($doctor);
}
DB::commit();
return baseResponse(
'success',
'success unassigned doctor with patients!',
null,
null,
200
);
}catch (Throwable $exception){
DB::rollBack();
return baseResponse(
'failed',
'failed unassigned doctor with patients!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Unassigned doctor with patients.
*
* @param Request $request
* @return JsonResponse
* @throws Throwable
*/
public function unassignByDoctor(Request $request): JsonResponse
{
try {
DB::beginTransaction();
$input = $request->all();
$doctors = $this->doctorRepository->getDoctorById($input['doctor_ids']);
$patient = $this->patientRepository->getManyPatientById($input['patient_id']);
foreach ($doctors as $doctor){
$doctor->patients()->detach($patient);
}
DB::commit();
return baseResponse(
'success',
'success unassigned doctor with patients!',
null,
null,
200
);
}catch (Throwable $exception){
DB::rollBack();
return baseResponse(
'failed',
'failed unassigned doctor with patients!',
null,
$exception->getMessage(),
500
);
}
}
}
+83
View File
@@ -0,0 +1,83 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\LoginRequest;
use App\Interfaces\DiagnoseRepositoryInterface;
use App\Interfaces\PatientRepositoryInterface;
use Carbon\Carbon;
use Auth;
use Http;
use Storage;
class AuthController extends Controller
{
function login(LoginRequest $request) {
$credentials = $request->all();
$auth = Auth::guard('web');
if (!$auth->attempt($credentials)) {
return response()->json(['error'=>'Email or password incorrect'], 401);
}
$token = $auth->user()->createToken('authToken');
return baseResponse(
'success',
'success login!',
[
'user' => $auth->user(),
'access_token' => $token->accessToken,
'expired' => $token->token->expires_at->diffInSeconds(Carbon::now()),
],
null,
200
);
}
function profile() {
$user = Auth::user();
$role = Auth::user()->getRoleNames()[0];
return baseResponse(
'success',
'success get profile!',
[
'user' => collect($user->setAttribute('role',$role)),
'profile' => $role !== 'admin' ? collect($user->$role->setAttribute('relations', $user->$role->pivot))->except(['pivot']) : null,
],
null,
200
);
}
function logout() {
$user = Auth::user();
if (!$user){
return baseResponse(
'failed',
'You do not have the required authorization!',
null,
null,
401
);
}
$user->token()->revoke();
return baseResponse(
'success',
'success logout!',
$user,
null,
200
);
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
@@ -0,0 +1,262 @@
<?php
namespace App\Http\Controllers;
use App\Interfaces\DiagnoseRepositoryInterface;
use App\Interfaces\DoctorRepositoryInterface;
use App\Interfaces\PatientRepositoryInterface;
use Auth;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Traits\EnumeratesValues;
class DashboardController extends Controller
{
private DoctorRepositoryInterface $doctorRepository;
private PatientRepositoryInterface $patientRepository;
private DiagnoseRepositoryInterface $diagnoseRepository;
public function __construct(
DoctorRepositoryInterface $doctorRepository,
PatientRepositoryInterface $patientRepository,
DiagnoseRepositoryInterface $diagnoseRepository
)
{
$this->doctorRepository = $doctorRepository;
$this->patientRepository = $patientRepository;
$this->diagnoseRepository = $diagnoseRepository;
}
public function admin_dashboard_statistic(): JsonResponse
{
// jadi nanti ada beberapa card yang isinya:
// 1. total dokter
// 2. total pasien
// 3. total normal
// 4. total mi
// 5. total gender
// 6. total patient today
$total_doctor = count($this->doctorRepository->getAllDoctors());
$total_patient = count($this->patientRepository->getAllPatients());
$total_patient_normal = collect($this->patientRepository->getAllPatients())->where('condition','normal')->count();
$total_patient_mi = collect($this->patientRepository->getAllPatients())->where('condition','mi')->count();
$total_patient_male = collect($this->patientRepository->getAllPatients())->where('gender','male')->count();
$total_patient_female = collect($this->patientRepository->getAllPatients())->where('gender','female')->count();
$total_patient_today = collect($this->patientRepository->getAllPatients())
->filter(function ($patient) {
return Carbon::parse($patient->updated_at)->isToday();
})
->count();
return baseResponse(
'success',
'success admin_get_total_statistic!',
[
'total_doctor' => $total_doctor,
'total_patient' => $total_patient,
'total_patient_normal' => $total_patient_normal,
'total_patient_mi' => $total_patient_mi,
'total_patient_male' => $total_patient_male,
'total_patient_female' => $total_patient_female,
'total_patient_today' => $total_patient_today
],
null,
200
);
}
private function get_patient_by_date($start, $end): EnumeratesValues|Collection
{
return collect($this->patientRepository->getAllPatients())
->whereBetween('updated_at', [$start, $end]);
}
public function admin_dashboard_graph(Request $request): JsonResponse
{
// 2. patient weekly (done)
// 3. patient monthly
// 4. custom date
// 5. tinggal bikin kondisi lagi
$filter = $request->query('filter');
$startOfWeek = Carbon::now()->startOfWeek();
$endOfWeek = Carbon::now()->endOfWeek();
$startOfMonth = Carbon::now()->startOfMonth();
$endOfMonth = Carbon::now()->endOfMonth();
$organizedData = [];
$patients = $this->patientRepository->getAllPatients();
if ($filter === 'weekly'){
for ($date = $startOfWeek; $date->lte($endOfWeek); $date->addDay()) {
// Your code here
$_date = Carbon::parse($date);
$organizedData[$_date->format('Y-m-d')] = collect($patients)->where('updated_at', '>=', $_date->startOfDay())->where('updated_at', '<=', $_date->endOfDay())->count();
}
}elseif ($filter === 'monthly'){
for ($date = $startOfMonth; $date->lte($endOfMonth); $date->addWeek()) {
// Your code here
$_date = Carbon::parse($date);
$organizedData['week ' . $_date->weekOfMonth] = collect($patients)->where('updated_at', '>=', $_date->startOfWeek())->where('updated_at', '<=', $_date->endOfWeek())->count();
}
}
elseif ($filter === 'custom'){
if (!$request->query('end_date') || !$request->query('start_date')){
return baseResponse(
'error',
'error admin_dashboard_graph!',
null,
null,
500
);
}
$customStart = Carbon::createFromFormat('Y-m-d', $request->query('start_date'));
$customEnd = Carbon::createFromFormat('Y-m-d', $request->query('end_date'));
for ($date = $customStart; $date->lte($customEnd); $date->addDay()) {
// Your code here
$_date = Carbon::parse($date);
$organizedData[$_date->format('Y-m-d')] = collect($patients)->where('updated_at', '>=', $_date->startOfDay())->where('updated_at', '<=', $_date->endOfDay())->count();
}
}
else{
for ($date = $startOfWeek; $date->lte($endOfWeek); $date->addDay()) {
// Your code here
$_date = Carbon::parse($date);
$organizedData[$_date->format('Y-m-d')] = collect($patients)->where('updated_at', '>=', $_date->startOfDay())->where('updated_at', '<=', $_date->endOfDay())->count();
}
}
return baseResponse(
'success',
'success admin_get_total_statistic!',
[
'patient' => $organizedData
],
null,
200
);
}
public function doctor_dashboard_statistic(): JsonResponse
{
// jadi nanti ada beberapa card yang isinya:
// 1. total pasien
// 2. total verified
// 3. total unverified
// 4. total mi
// 5. total normal
// 6. total gender
$user = Auth::user();
$patients = $user->doctor->patients;
$diagnoses = $this->diagnoseRepository->getCustomAllDiagnoses('doctor_id', $user->doctor->id);
$total_patient = collect($patients)->count();
$total_verified = collect($diagnoses)->where('is_verified',1)->count();
$total_unverified = collect($diagnoses)->where('is_verified',0)->count();
$total_patient_normal = collect($patients)->where('condition','normal')->count();
$total_patient_mi = collect($patients)->where('condition','mi')->count();
$total_patient_male = collect($patients)->where('gender','male')->count();
$total_patient_female = collect($patients)->where('gender','female')->count();
return baseResponse(
'success',
'success doctor_get_total_statistic!',
[
'total_patient' => $total_patient,
'total_verified' => $total_verified,
'total_unverified' => $total_unverified,
'total_patient_normal' => $total_patient_normal,
'total_patient_mi' => $total_patient_mi,
'total_patient_male' => $total_patient_male,
'total_patient_female' => $total_patient_female,
],
null,
200
);
}
public function doctor_dashboard_latest_diagnose(): JsonResponse
{
// get latest diagnose
$user = Auth::user();
$diagnoses = collect($this->diagnoseRepository->getCustomAllDiagnoses('doctor_id', $user->doctor->id))->sortByDesc('updated_at')->slice(0,5)->values()->toArray();
return baseResponse(
'success',
'success doctor_dashboard_latest_diagnose!',
[
'diagnoses' => $diagnoses
],
null,
200
);
}
public function patient_dashboard_statistic(): JsonResponse
{
// jadi nanti ada beberapa card yang isinya:
// 1. total verified
// 2. total unverified
// 3. total mi
// 4. total normal
$user = Auth::user();
$diagnoses = $user->patient->diagnoses;
$total_verified = collect($diagnoses)->where('is_verified',1)->count();
$total_unverified = collect($diagnoses)->where('is_verified',0)->count();
$total_patient_normal = collect($diagnoses)->where('diagnoses','normal')->count();
$total_patient_mi = collect($diagnoses)->where('diagnoses','mi')->count();
return baseResponse(
'success',
'success patient_get_total_statistic!',
[
'total_verified' => $total_verified,
'total_unverified' => $total_unverified,
'total_patient_normal' => $total_patient_normal,
'total_patient_mi' => $total_patient_mi,
],
null,
200
);
}
public function patient_dashboard_latest_diagnose(): JsonResponse
{
// get latest diagnose
$user = Auth::user();
$diagnoses = collect($user->patient->diagnoses)->sortByDesc('updated_at')->slice(0,5)->values()->toArray();
return baseResponse(
'success',
'success patient_dashboard_latest_diagnose!',
[
'diagnoses' => $diagnoses
],
null,
200
);
}
}
+419
View File
@@ -0,0 +1,419 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\DiagnoseRequest;
use App\Interfaces\DiagnoseRepositoryInterface;
use App\Interfaces\PatientRepositoryInterface;
use App\Interfaces\UserRepositoryInterface;
use Auth;
use DB;
use Http;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Storage;
use Throwable;
class DiagnoseController extends Controller
{
private DiagnoseRepositoryInterface $diagnoseRepository;
private PatientRepositoryInterface $patientRepository;
public function __construct(
DiagnoseRepositoryInterface $diagnoseRepository,
UserRepositoryInterface $userRepository,
PatientRepositoryInterface $patientRepository
)
{
$this->diagnoseRepository = $diagnoseRepository;
$this->patientRepository = $patientRepository;
$this->middleware('role:doctor', [
'only' => ['update'],
'except' => ['store']
]);
$this->middleware('role:patient', [
'only' => ['store'],
'except' => ['update']
]);
}
/**
* Display a listing of the resource.
*
* @return JsonResponse
*/
public function index(): JsonResponse
{
$user = Auth::user();
$data = $this->diagnoseRepository->getCustomAllDiagnoses($user->roles[0]['name'].'_id',$user->role_data['id']);
return baseResponse(
'success',
'success get all diagnose data',
$data,
null,
200
);
}
/**
* Store a newly created resource in storage.
*
* @param DiagnoseRequest $request
* @return JsonResponse
* @throws Throwable
*/
public function store(DiagnoseRequest $request): JsonResponse
{
try {
$input = $request->all();
$user = Auth::user();
$patient = $user->patient;
$doctor = $patient->doctors[0];
if (!$patient || !$doctor){
return baseResponse(
'failed',
'please make sure you already assign with doctor, or asking admin!',
null,
null,
500
);
}
$input['patient_id'] = $patient->id;
$input['doctor_id'] = $doctor->id;
$input['file'] = Storage::disk('s3')->put('apicta', $input['file']);
$diagnose = $this->diagnoseRepository->createDiagnose($input);
DB::commit();
return baseResponse(
'success',
'success create diagnose data!',
$diagnose,
null,
201
);
}catch (Throwable $exception){
DB::rollBack();
return baseResponse(
'failed',
'failed create diagnose data!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Display the specified resource.
*
* @param string $diagnose_id
* @return JsonResponse
*/
public function show(string $diagnose_id): JsonResponse
{
try {
$diagnose = $this->diagnoseRepository->getDiagnoseById($diagnose_id);
return baseResponse(
'success',
'success show diagnose data!',
$diagnose,
null,
200
);
}catch (Throwable $exception){
return baseResponse(
'failed',
'failed show diagnose data!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Update the specified resource in storage.
*
* @param DiagnoseRequest $request
* @param string $diagnose_id
* @return JsonResponse
* @throws Throwable
*/
public function update(DiagnoseRequest $request, string $diagnose_id): JsonResponse
{
try {
$data = $request->all();
DB::beginTransaction();
$diagnose_data = $this->diagnoseRepository->getDiagnoseById($diagnose_id);
$this->patientRepository->updatePatient($diagnose_data->patient_id, ['condition' => $data['diagnoses']]);
$this->diagnoseRepository->updateDiagnose($diagnose_id,$data);
DB::commit();
return baseResponse(
'success',
'success update diagnose data!',
null,
null,
200
);
}catch (Throwable $exception){
DB::rollBack();
return baseResponse(
'failed',
'failed update diagnose data!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Remove the specified resource from storage.
*
* @param string $diagnose_id
* @return JsonResponse
* @throws Throwable
*/
public function destroy(string $diagnose_id): JsonResponse
{
try {
DB::beginTransaction();
$this->diagnoseRepository->deleteDiagnose($diagnose_id);
DB::commit();
return baseResponse(
'success',
'success delete diagnose data!',
null,
null,
200
);
}catch (Throwable $exception){
DB::rollBack();
return baseResponse(
'failed',
'failed delete diagnose data!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Remove the specified resource from storage.
*
* @param Request $request
* @return JsonResponse
* @throws Throwable
*/
public function predict_patient(Request $request)
{
$file = $request->file('file');
$patient_id = $request->input('patient_id');
if (!$file){
return baseResponse(
'failed',
'please make sure you sending the file',
null,
null,
500
);
}
if (!$patient_id){
return baseResponse(
'failed',
'please make sure you sending the patient id',
null,
null,
500
);
}
try {
DB::beginTransaction();
$response = Http::attach('file',file_get_contents($file), $file->getClientOriginalName())
->post('https://myoscope.distancing.my.id/predict');
$patient = $this->patientRepository->getPatientById($patient_id);
$file_path = Storage::disk('s3')->put('apicta', $file);
$this->diagnoseRepository->createDiagnose([
'patient_id' =>$patient->id,
'doctor_id' =>$patient->doctors[0]->id,
'diagnoses' => $response['result'] ? 'mi' : 'normal',
'notes' => '-',
'is_verified' => false,
'file' => $file_path
]);
DB::commit();
return baseResponse(
'success',
'success predict',
$response->json(),
null,
200
);
}catch (Throwable $exception) {
DB::rollBack();
return baseResponse(
'failed',
'error when predict',
null,
$exception->getMessage(),
500
);
}
}
public function predict_doctor(Request $request)
{
$file = $request->file('file');
$patient_id = $request->input('patient_id');
if (!$file){
return baseResponse(
'failed',
'please make sure you sending the file',
null,
null,
500
);
}
if (!$patient_id){
return baseResponse(
'failed',
'please make sure you sending the patient id',
null,
null,
500
);
}
try {
DB::beginTransaction();
$response = Http::attach('file',file_get_contents($file), $file->getClientOriginalName())
->post('https://myoscope.distancing.my.id/predict');
$patient = $this->patientRepository->getPatientById($patient_id);
$file_path = Storage::disk('s3')->put('apicta', $file);
$this->diagnoseRepository->createDiagnose([
'patient_id' =>$patient->id,
'doctor_id' =>Auth::user()->doctor->id,
'diagnoses' => $response['result'] ? 'mi' : 'normal',
'notes' => '-',
'is_verified' => false,
'file' => $file_path
]);
DB::commit();
return baseResponse(
'success',
'success predict',
$response->json(),
null,
200
);
}catch (Throwable $exception) {
DB::rollBack();
return baseResponse(
'failed',
'error when predict',
null,
$exception->getMessage(),
500
);
}
}
public function repredict(Request $request){
$file_path = $request->input('file_path');
if (!$file_path){
return baseResponse(
'failed',
'please make sure you sending the file',
null,
null,
500
);
}
$file = Storage::disk('s3')->get($file_path);
$temp_file = tempnam(sys_get_temp_dir(), 's3');
file_put_contents($temp_file, $file);
if (!$file){
return baseResponse(
'failed',
'please make sure you sending the file',
null,
null,
500
);
}
try {
// $file_path = 'apicta/963q79jNwGT8Pqhs910e1eC57hZbWugnXnbYb2wr.wav';
// $file = Storage::disk('s3')->get($file_path);
//
// $local_path = 'files-alfara/alfara.wav';
// $res = Storage::disk('public')->put($local_path, $file);
// dd(file_get_contents(storage_path('app/public/files-alfara/alfara.wav')));
$response = Http::attach('file', file_get_contents($temp_file), basename($file_path))
->post('https://myoscope.distancing.my.id/predict');
//
// $response = Http::attach('file', file_get_contents($temp_file), 'ddddddd.wav');
// dd($response);
return baseResponse(
'success',
'success predict',
$response->json(),
null,
200
);
}catch (Throwable $exception){
return baseResponse(
'failed',
'error when predict',
null,
$exception->getMessage(),
500
);
}
}
}
+227
View File
@@ -0,0 +1,227 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\DoctorRequest;
use App\Interfaces\DoctorRepositoryInterface;
use App\Interfaces\UserRepositoryInterface;
use Auth;
use DB;
use Throwable;
use Illuminate\Http\JsonResponse;
use Hash;
class DoctorController extends Controller
{
private DoctorRepositoryInterface $doctorRepository;
private UserRepositoryInterface $userRepository;
public function __construct(
DoctorRepositoryInterface $doctorRepository,
UserRepositoryInterface $userRepository
)
{
$this->doctorRepository = $doctorRepository;
$this->userRepository = $userRepository;
}
/**
* Display a listing of the resource.
*
* @return JsonResponse
*/
public function index(): JsonResponse
{
$data = $this->doctorRepository->getAllDoctors();
return baseResponse(
'success',
'success get all doctor data',
$data,
null,
200
);
}
/**
* Store a newly created resource in storage.
*
* @param DoctorRequest $request
* @return JsonResponse
* @throws Throwable
*/
public function store(DoctorRequest $request): JsonResponse
{
try {
$input = $request->all();
DB::beginTransaction();
$user = $this->userRepository->createUser([
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
$user->assignRole('doctor');
$input['user_id'] = $user->id;
$doctor = $this->doctorRepository->createDoctor($input);
DB::commit();
return baseResponse(
'success',
'success create doctor data!',
$doctor,
null,
201
);
}catch (Throwable $exception){
DB::rollBack();
return baseResponse(
'failed',
'failed create doctor data!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Display the specified resource.
*
* @param string $doctor_id
* @return JsonResponse
*/
public function show(string $doctor_id): JsonResponse
{
try {
$doctor = $this->doctorRepository->getDoctorById($doctor_id);
return baseResponse(
'success',
'success show doctor data!',
$doctor,
null,
200
);
}catch (Throwable $exception){
return baseResponse(
'failed',
'failed show doctor data!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Update the specified resource in storage.
*
* @param DoctorRequest $request
* @param string $doctor_id
* @return JsonResponse
* @throws Throwable
*/
public function update(DoctorRequest $request, string $doctor_id): JsonResponse
{
try {
$data = $request->all();
DB::beginTransaction();
$this->doctorRepository->updateDoctor($doctor_id,$data);
DB::commit();
return baseResponse(
'success',
'success update doctor data!',
null,
null,
200
);
}catch (Throwable $exception){
DB::rollBack();
return baseResponse(
'failed',
'failed update doctor data!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Remove the specified resource from storage.
*
* @param string $doctor_id
* @return JsonResponse
* @throws Throwable
*/
public function destroy(string $doctor_id): JsonResponse
{
try {
DB::beginTransaction();
$this->doctorRepository->deleteDoctor($doctor_id);
DB::commit();
return baseResponse(
'success',
'success delete doctor data!',
null,
null,
200
);
}catch (Throwable $exception){
DB::rollBack();
return baseResponse(
'failed',
'failed delete doctor data!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Get patient list by doctor authentication.
*
* @return JsonResponse
* @throws Throwable
*/
public function getPatientByDoctor(): JsonResponse
{
try {
$user = Auth::user();
$doctor = $user->doctor;
if (!$doctor){
return baseResponse(
'failed',
'failed get list patient data!',
null,
null,
500
);
}
return baseResponse(
'success',
'success get list patient data!',
$doctor->patients,
null,
200
);
}catch (Throwable $exception){
return baseResponse(
'failed',
'failed get list patient data!',
null,
$exception->getMessage(),
500
);
}
}
}
@@ -0,0 +1,86 @@
<?php
namespace App\Http\Controllers;
use App\Models\Heartwave;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class HeartwaveController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param Heartwave $heartwave
* @return Response
*/
public function show(Heartwave $heartwave)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param Heartwave $heartwave
* @return Response
*/
public function edit(Heartwave $heartwave)
{
//
}
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param Heartwave $heartwave
* @return Response
*/
public function update(Request $request, Heartwave $heartwave)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param Heartwave $heartwave
* @return Response
*/
public function destroy(Heartwave $heartwave)
{
//
}
}
+215
View File
@@ -0,0 +1,215 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\PatientRequest;
use App\Interfaces\PatientRepositoryInterface;
use App\Interfaces\UserRepositoryInterface;
use DB;
use Illuminate\Support\Facades\Auth;
use Throwable;
use Illuminate\Http\JsonResponse;
use Hash;
class PatientController extends Controller
{
private PatientRepositoryInterface $patientRepository;
private UserRepositoryInterface $userRepository;
public function __construct(
PatientRepositoryInterface $patientRepository,
UserRepositoryInterface $userRepository
)
{
$this->patientRepository = $patientRepository;
$this->userRepository = $userRepository;
}
/**
* Display a listing of the resource.
*
* @return JsonResponse
*/
public function index(): JsonResponse
{
$data = $this->patientRepository->getAllPatients();
return baseResponse(
'success',
'success get all patient data',
$data,
null,
200
);
}
/**
* Display a listing of the resource.
*
* @return JsonResponse
*/
public function indexExceptDoctor(string $doctor_id): JsonResponse
{
$data = $this->patientRepository->getAllPatientsExceptDoctor($doctor_id);
return baseResponse(
'success',
'success get all patient data',
$data,
null,
200
);
}
/**
* Store a newly created resource in storage.
*
* @param PatientRequest $request
* @return JsonResponse
* @throws Throwable
*/
public function store(PatientRequest $request): JsonResponse
{
try {
$input = $request->all();
DB::beginTransaction();
$user = $this->userRepository->createUser([
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
$user->assignRole('patient');
$input['user_id'] = $user->id;
$patient = $this->patientRepository->createPatient($input);
DB::commit();
return baseResponse(
'success',
'success create patient data!',
$patient,
null,
201
);
}catch (Throwable $exception){
DB::rollBack();
return baseResponse(
'failed',
'failed create patient data!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Display the specified resource.
*
* @param string $patient_id
* @return JsonResponse
*/
public function show(string $patient_id): JsonResponse
{
try {
$patient = $this->patientRepository->getPatientById($patient_id);
$result_patient = collect($patient);
if ($result_patient['diagnoses'] && Auth::user()->doctor){
$result_patient['diagnoses'] = collect($patient['diagnoses'])->where('doctor_id',Auth::user()->doctor->id)->values()->all();
}
return baseResponse(
'success',
'success show patient data!',
$result_patient,
null,
200
);
}catch (Throwable $exception){
return baseResponse(
'failed',
'failed show patient data!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Update the specified resource in storage.
*
* @param PatientRequest $request
* @param string $patient_id
* @return JsonResponse
* @throws Throwable
*/
public function update(PatientRequest $request, string $patient_id): JsonResponse
{
try {
$data = $request->all();
DB::beginTransaction();
$this->patientRepository->updatePatient($patient_id,$data);
DB::commit();
return baseResponse(
'success',
'success update patient data!',
null,
null,
200
);
}catch (Throwable $exception){
DB::rollBack();
return baseResponse(
'failed',
'failed update patient data!',
null,
$exception->getMessage(),
500
);
}
}
/**
* Remove the specified resource from storage.
*
* @param string $patient_id
* @return JsonResponse
* @throws Throwable
*/
public function destroy(string $patient_id): JsonResponse
{
try {
DB::beginTransaction();
$this->patientRepository->deletePatient($patient_id);
DB::commit();
return baseResponse(
'success',
'success delete patient data!',
null,
null,
200
);
}catch (Throwable $exception){
DB::rollBack();
return baseResponse(
'failed',
'failed delete patient data!',
null,
$exception->getMessage(),
500
);
}
}
}