Update Doctors
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Models\PractitionerRole;
|
|||||||
use Illuminate\Contracts\Support\Renderable;
|
use Illuminate\Contracts\Support\Renderable;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Controller;
|
use Illuminate\Routing\Controller;
|
||||||
|
use Modules\Linksehat\Transformers\DoctorResource;
|
||||||
use Modules\Linksehat\Transformers\PractitionerRoleToDoctorDetailResource;
|
use Modules\Linksehat\Transformers\PractitionerRoleToDoctorDetailResource;
|
||||||
use Modules\Linksehat\Transformers\PractitionerRoleToDoctorResource;
|
use Modules\Linksehat\Transformers\PractitionerRoleToDoctorResource;
|
||||||
|
|
||||||
@@ -33,9 +34,13 @@ class DoctorController extends Controller
|
|||||||
} else if ($request->has('hospital_id')) {
|
} else if ($request->has('hospital_id')) {
|
||||||
$doctors->where('organization_id', $request->hospital_id);
|
$doctors->where('organization_id', $request->hospital_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$doctors = $doctors->paginate(6);
|
$limit = $request->limit ?? 6;
|
||||||
|
if ($limit > 20) {
|
||||||
|
$limit = 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
$doctors = $doctors->paginate($limit);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'Sukses mengambil data Dokter',
|
'message' => 'Sukses mengambil data Dokter',
|
||||||
@@ -69,12 +74,18 @@ class DoctorController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$doctor = PractitionerRole::query()
|
$doctor = Practitioner::query()
|
||||||
->with(['practitioner', 'practitioner.person', 'speciality', 'practitioner.metas', 'metas', 'organization'])
|
->with([
|
||||||
->where('id', $id)
|
'practitionerRoles',
|
||||||
->firstOrFail();
|
'practitionerRoles.metas',
|
||||||
|
'practitionerRoles.speciality',
|
||||||
return response()->json(PractitionerRoleToDoctorDetailResource::make($doctor));
|
'practitionerRoles.organization',
|
||||||
|
'person',
|
||||||
|
'metas',
|
||||||
|
])
|
||||||
|
->findOrFail($id);
|
||||||
|
|
||||||
|
return response()->json(DoctorResource::make($doctor));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,8 +57,13 @@ class HospitalController extends Controller
|
|||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
$limit = $request->limit ?? 6;
|
||||||
|
if ($limit > 20) {
|
||||||
|
$limit = 20;
|
||||||
|
}
|
||||||
|
|
||||||
$hospitals = $hospitals->paginate($request->limit ?? 6);
|
$hospitals = $hospitals->paginate($limit);
|
||||||
// dd($hospitals->toArray());
|
// dd($hospitals->toArray());
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,38 @@ class DoctorResource extends JsonResource
|
|||||||
*/
|
*/
|
||||||
public function toArray($request)
|
public function toArray($request)
|
||||||
{
|
{
|
||||||
return parent::toArray($request);
|
$practices = $this->practitionerRoles->map(function($practitionerRole) {
|
||||||
|
return [
|
||||||
|
'id' => $practitionerRole->id,
|
||||||
|
'doctor_id' => $practitionerRole->practitioner_id,
|
||||||
|
'hospital_id' => $practitionerRole->organization_id,
|
||||||
|
'speciality_id' => $practitionerRole->speciality_id,
|
||||||
|
'hospital' => HospitalResource::make($practitionerRole->organization),
|
||||||
|
'speciality' => SpecialityResource::make($practitionerRole->speciality)
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'full_name' => $this->person->full_name ?? null,
|
||||||
|
'name_prefix' => $this->person->name_prefix ?? null,
|
||||||
|
'name' => $this->person->name ?? null,
|
||||||
|
'name_suffix' => $this->person->name_suffix ?? null,
|
||||||
|
'gender' => $this->person->gender ?? null,
|
||||||
|
// 'speciality_name' => !empty($this->speciality->name ?? null) ? 'Spesialis '. $this->speciality->name : 'Spesialis Empty',
|
||||||
|
'is_online' => false,
|
||||||
|
// 'is_insurance_covered' => rand(0,1) == 1,
|
||||||
|
// 'price_range' => 'Rp 100.000 - Rp 350.000',
|
||||||
|
// 'price_start' => '100000',
|
||||||
|
// 'price_end' => '350000',
|
||||||
|
'avatar_url' => asset('images/default-doctor-avatar.png'),
|
||||||
|
'education' => $this->meta->education ?? '',
|
||||||
|
'medical_treatment' => $this->meta->medical_treatment ?? '',
|
||||||
|
'award' => $this->meta->award ?? '',
|
||||||
|
'work_experience' => $this->meta->work_experience ?? '',
|
||||||
|
'keilmuan' => $this->meta->keilmuan ?? '',
|
||||||
|
'description' => $this->meta->description ?? '',
|
||||||
|
'practices' => $practices
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class PractitionerRoleToDoctorDetailResource extends JsonResource
|
|||||||
'gender' => $this->practitioner->person->gender ?? null,
|
'gender' => $this->practitioner->person->gender ?? null,
|
||||||
'speciality_name' => !empty($this->speciality->name ?? null) ? 'Spesialis '. $this->speciality->name : 'Spesialis Empty',
|
'speciality_name' => !empty($this->speciality->name ?? null) ? 'Spesialis '. $this->speciality->name : 'Spesialis Empty',
|
||||||
'is_online' => false,
|
'is_online' => false,
|
||||||
|
'is_insurance_covered' => rand(0,1) == 1,
|
||||||
'price_range' => 'Rp 100.000 - Rp 350.000',
|
'price_range' => 'Rp 100.000 - Rp 350.000',
|
||||||
'price_start' => '100000',
|
'price_start' => '100000',
|
||||||
'price_end' => '350000',
|
'price_end' => '350000',
|
||||||
@@ -32,7 +33,7 @@ class PractitionerRoleToDoctorDetailResource extends JsonResource
|
|||||||
'award' => $this->meta->award ?? '',
|
'award' => $this->meta->award ?? '',
|
||||||
'work_experience' => $this->meta->work_experience ?? '',
|
'work_experience' => $this->meta->work_experience ?? '',
|
||||||
'keilmuan' => $this->meta->keilmuan ?? '',
|
'keilmuan' => $this->meta->keilmuan ?? '',
|
||||||
'description' => $this->meta->description ?? ''
|
'description' => $this->meta->description ?? '',
|
||||||
];
|
];
|
||||||
|
|
||||||
return parent::toArray($request);
|
return parent::toArray($request);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class PractitionerRoleToDoctorResource extends JsonResource
|
|||||||
] : null;
|
] : null;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->practitioner->id,
|
||||||
'organization_id' => $this->organization_id,
|
'organization_id' => $this->organization_id,
|
||||||
'full_name' => $this->practitioner->person->full_name,
|
'full_name' => $this->practitioner->person->full_name,
|
||||||
'name_prefix' => $this->practitioner->person->name_prefix,
|
'name_prefix' => $this->practitioner->person->name_prefix,
|
||||||
@@ -42,11 +42,12 @@ class PractitionerRoleToDoctorResource extends JsonResource
|
|||||||
'gender' => $this->practitioner->person->gender,
|
'gender' => $this->practitioner->person->gender,
|
||||||
// 'speciality_name' => !empty($this->speciality->name ?? null) ? 'Spesialis '. $this->speciality->name : 'Spesialis Empty',
|
// 'speciality_name' => !empty($this->speciality->name ?? null) ? 'Spesialis '. $this->speciality->name : 'Spesialis Empty',
|
||||||
'is_online' => false,
|
'is_online' => false,
|
||||||
|
'is_insurance_covered' => rand(0,1) == 1,
|
||||||
'price_range' => 'Rp 100.000 - Rp 350.000',
|
'price_range' => 'Rp 100.000 - Rp 350.000',
|
||||||
'price_start' => '100000',
|
'price_start' => '100000',
|
||||||
'price_end' => '350000',
|
'price_end' => '350000',
|
||||||
'avatar_url' => asset('images/default-doctor-avatar.png'),
|
'avatar_url' => asset('images/default-doctor-avatar.png'),
|
||||||
'organization' => $organization,
|
'hospital' => $organization,
|
||||||
'speciality' => $speciality,
|
'speciality' => $speciality,
|
||||||
];
|
];
|
||||||
return parent::toArray($request);
|
return parent::toArray($request);
|
||||||
|
|||||||
19
Modules/Linksehat/Transformers/SpecialityResource.php
Normal file
19
Modules/Linksehat/Transformers/SpecialityResource.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Linksehat\Transformers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class SpecialityResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return parent::toArray($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,4 +36,9 @@ class Practitioner extends Model
|
|||||||
{
|
{
|
||||||
return $this->morphMany(Meta::class, 'metaable');
|
return $this->morphMany(Meta::class, 'metaable');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function practitionerRoles()
|
||||||
|
{
|
||||||
|
return $this->hasMany(PractitionerRole::class, 'practitioner_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user