Merge remote-tracking branch 'origin/mhmfajar'

This commit is contained in:
Muhammad Fajar
2022-11-08 10:36:08 +07:00
11 changed files with 7819 additions and 24967 deletions

View File

@@ -0,0 +1,122 @@
<?php
namespace Modules\Linksehat\Http\Controllers\Api;
use App\Helpers\Helper;
use App\Models\Appointment;
use App\Models\AppointmentParticipant;
use App\Models\Person;
use App\Models\PractitionerRole;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Gate;
use Modules\Linksehat\Transformers\Appointment\AppointmentDetailResource;
use Symfony\Component\HttpFoundation\Response;
class AppointmentController extends Controller
{
/**
* Display a listing of the resource.
* @return Renderable
*/
public function index()
{
return view('linksehat::index');
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Renderable
*/
public function store(Request $request)
{
$appointmentData = $request->only([
'appointment_type',
'organization_id',
'speciality_id',
]);
$appointmentData = array_merge($appointmentData, [
'start_time' => $request->date . ' ' . $request->time
]);
$appointment = Appointment::query()->create($appointmentData);
if ($request->has('doctor_id')) {
$practitionerRole = PractitionerRole::query()->find($request->doctor_id);
$practitionerRole->appointmentParticipantables()->create([
'appointment_id' => $appointment->id,
'type' => 'doctor',
]);
}
if ($request->has('patient_id')) {
$person = Person::query()->find($request->patient_id);
$person->appointmentParticipantables()->create([
'appointment_id' => $appointment->id,
'type' => 'patient',
]);
}
return Helper::responseJson($appointment, Response::HTTP_CREATED, 'Data appointment berhasil di buat');
}
/**
* Show the specified resource.
* @param int $id
* @return Renderable
*/
public function show($id)
{
$appointment = Appointment::query()->with(['appointmentParticipants', 'organization'])->find($id);
return Helper::responseJson(new AppointmentDetailResource($appointment));
}
/**
* Update the specified resource in storage.
* @param Request $request
* @param int $id
* @return Renderable
*/
public function update(Request $request, Appointment $appointment)
{
$idPatient = AppointmentParticipant::query()->where('appointment_id', $appointment->id)->where('participantable_type', Person::class)->first();
$patient = Person::query()->select(['owner_user_id'])->find($idPatient->participantable_id);
if (Gate::forUser(auth()->user())->allows('update-appointment', $patient)) {
$appointmentData = [
'start_time' => $request->date . ' ' . $request->time
];
$appointment->update($appointmentData);
$appointment->appointmentParticipants()->updateOrCreate(
[
'appointment_id' => $appointment->id,
'type' => 'patient',
'participantable_type' => Person::class,
],
[
'participantable_id' => $request->patient_id,
]
);
return Helper::responseJson(data: $appointment->with(['appointmentParticipants'])->get(), message: 'Data berhasil di update');
} elseif (Gate::forUser(auth()->user())->denies('update-appointment', $patient)) {
abort(Response::HTTP_FORBIDDEN, 'Tidak bisa update karena bukan pemilik!');
}
}
/**
* Remove the specified resource from storage.
* @param int $id
* @return Renderable
*/
public function destroy($id)
{
//
}
}

View File

@@ -1,5 +1,6 @@
<?php
use Modules\Linksehat\Http\Controllers\Api\AppointmentController;
use Modules\Linksehat\Http\Controllers\Api\AuthController;
use Modules\Linksehat\Http\Controllers\Api\DashboardController;
use Modules\Linksehat\Http\Controllers\Api\DoctorController;
@@ -55,9 +56,11 @@ Route::prefix('linksehat')->group(function () {
Route::post('doctors/{id}/schedule', 'schedule')->name('doctors.schedule');
});
Route::middleware('auth:sanctum')->group(function () {
Route::get('profile', [ProfileController::class, 'index'])->name('profile');
Route::post('profile', [ProfileController::class, 'update'])->name('profile.update');
Route::apiResource('appointment', AppointmentController::class);
Route::apiResource('families', PersonController::class)->except(['destroy']);
});
});

View File

@@ -0,0 +1,73 @@
<?php
namespace Modules\Linksehat\Transformers\Appointment;
use App\Helpers\Helper;
use App\Models\Person;
use App\Models\PractitionerRole;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;
class AppointmentDetailResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
foreach ($this->appointmentParticipants as $appoinmentParticipant) {
if ($appoinmentParticipant->participantable_type == Person::class) {
$patiendId = $appoinmentParticipant->participantable_id;
} elseif ($appoinmentParticipant->participantable_type == PractitionerRole::class) {
$doctorId = $appoinmentParticipant->participantable_id;
}
}
$queryPatient = Person::query()
->find($patiendId);
$patient = [
'id' => $queryPatient->id,
'name' => $queryPatient->name,
'email' => $queryPatient->email,
'phone' => $queryPatient->phone,
];
$queryDoctor = PractitionerRole::query()
->with(['practitioner.person', 'speciality', 'practices.prices'])
->where('practitioner_id', $doctorId)
->first();
foreach ($queryDoctor->practices as $qPractice) {
foreach ($qPractice->prices as $qPrice) {
if (strtolower($qPractice->service_code) == strtolower($this->appointment_type)) {
$price = $qPrice->price_net;
}
}
}
$doctor = [
'id' => $doctorId,
'name' => $queryDoctor->person->name,
'speciality' => 'Spesialis ' . $queryDoctor->speciality->name,
'length_of_work_year' => rand(1, 10)
];
return [
'id' => $this->id,
'date' => Carbon::createFromFormat('Y-m-d H:i:s', $this->start_time)->format('Y-m-d'),
'time' => Carbon::createFromFormat('Y-m-d H:i:s', $this->start_time)->format('H:i'),
'doctor' => $doctor,
'organization' => [
'id' => $this->organization->id,
'name' => $this->organization->name,
'address' => $this->organization->currentAddress->text,
],
'patient' => $patient,
'price' => Helper::currencyIdrFormat($price)
];
}
}

View File

@@ -12,7 +12,7 @@ class Appointment extends Model
protected $fillable = [
'status',
'cancelation_reason',
'appointmnet_type',
'appointment_type',
'speciality_id',
'description',
'duration_minutes',
@@ -22,4 +22,19 @@ class Appointment extends Model
'comment',
'patient_instruction'
];
public function appointmentParticipants()
{
return $this->hasMany(AppointmentParticipant::class, 'appointment_id');
}
public function speciality()
{
return $this->belongsTo(Speciality::class, 'speciality_id');
}
public function organization()
{
return $this->belongsTo(Organization::class, 'organization_id');
}
}

View File

@@ -15,4 +15,9 @@ class AppointmentParticipant extends Model
'participantable_type',
'participantable_id',
];
public function participantable()
{
return $this->morphTo();
}
}

View File

@@ -102,4 +102,9 @@ class Person extends Model
{
return $this->hasOne(User::class, 'person_id');
}
public function appointmentParticipantables()
{
return $this->morphMany(AppointmentParticipant::class, 'participantable');
}
}

View File

@@ -89,4 +89,9 @@ class PractitionerRole extends Model
{
return $this->hasOneThrough(Person::class, Practitioner::class, 'person_id', 'id');
}
public function appointmentParticipantables()
{
return $this->morphMany(AppointmentParticipant::class, 'participantable');
}
}

View File

@@ -28,5 +28,9 @@ class AuthServiceProvider extends ServiceProvider
Gate::define('update-person', function ($user, $person) {
return $user->id == $person->owner_user_id;
});
Gate::define('update-appointment', function ($user, $patient) {
return $user->id == $patient->owner_user_id;
});
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -50,6 +50,7 @@
"@mui/x-data-grid": "^5.16.0",
"@mui/x-date-pickers": "5.0.0-beta.2",
"@vitejs/plugin-react": "^1.3.2",
"apexcharts": "^3.36.3",
"axios": "^0.27.2",
"change-case": "^4.1.2",
"csstype": "^3.1.0",
@@ -63,6 +64,7 @@
"nprogress": "^0.2.0",
"numeral": "^2.0.6",
"react": "^17.0.2",
"react-apexcharts": "^1.4.0",
"react-dom": "^17.0.2",
"react-dropzone": "^14.2.2",
"react-helmet-async": "^1.3.0",

File diff suppressed because it is too large Load Diff