Add Doctor Organization Filter
This commit is contained in:
@@ -19,19 +19,27 @@ class DoctorController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$hospitals = PractitionerRole::query()
|
$doctors = PractitionerRole::query()
|
||||||
->with(['practitioner.person', 'speciality', 'practitioner.metas', 'metas', 'organization'])
|
->with(['practitioner.person', 'speciality', 'practitioner.metas', 'metas', 'organization'])
|
||||||
->when($request->search ?? null, function($query, $search) {
|
->when($request->search ?? null, function($query, $search) {
|
||||||
$query->whereHas('practitioner.person', function($person) use ($search) {
|
$query->whereHas('practitioner.person', function($person) use ($search) {
|
||||||
$person->where('name', 'LIKE', '%'.$search.'%');
|
$person->where('name', 'LIKE', '%'.$search.'%');
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
->paginate(6);
|
->whereHas('speciality');
|
||||||
|
if ($request->has('hospital_id_in')) {
|
||||||
|
$hospital_ids = explode(',', $request->hospital_id_in);
|
||||||
|
$doctors->whereIn('organization_id', $hospital_ids);
|
||||||
|
} else if ($request->has('hospital_id')) {
|
||||||
|
$doctors->where('organization_id', $request->hospital_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$doctors = $doctors->paginate(6);
|
||||||
|
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'Sukses mengambil data Dokter',
|
'message' => 'Sukses mengambil data Dokter',
|
||||||
'doctors' => Helper::paginateResources(PractitionerRoleToDoctorResource::collection($hospitals))
|
'doctors' => Helper::paginateResources(PractitionerRoleToDoctorResource::collection($doctors))
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,19 +14,40 @@ class PractitionerRoleToDoctorResource extends JsonResource
|
|||||||
*/
|
*/
|
||||||
public function toArray($request)
|
public function toArray($request)
|
||||||
{
|
{
|
||||||
|
$organization = [
|
||||||
|
'id' => $this->organization->id,
|
||||||
|
'name' => $this->organization->name,
|
||||||
|
'code' => $this->organization->code,
|
||||||
|
'description' => $this->organization->description,
|
||||||
|
'address' => $this->organization->currentAddress->text ?? null,
|
||||||
|
'lat' => $this->organization->currentAddress->lat ?? null,
|
||||||
|
'lng' => $this->organization->currentAddress->lng ?? null,
|
||||||
|
'distance' => '200 m',
|
||||||
|
'city_name' => 'Kota Tangerang',
|
||||||
|
];
|
||||||
|
|
||||||
|
$speciality = $this->speciality ? [
|
||||||
|
'id' => $this->speciality->id ?? null,
|
||||||
|
'name' => $this->speciality->name ?? null,
|
||||||
|
'code' => $this->speciality->code ?? null,
|
||||||
|
] : null;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->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,
|
||||||
'name' => $this->practitioner->person->name,
|
'name' => $this->practitioner->person->name,
|
||||||
'name_suffix' => $this->practitioner->person->name_suffix,
|
'name_suffix' => $this->practitioner->person->name_suffix,
|
||||||
'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,
|
||||||
'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,
|
||||||
|
'speciality' => $speciality,
|
||||||
];
|
];
|
||||||
return parent::toArray($request);
|
return parent::toArray($request);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user