add search personOrSpeciality function
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use App\Models\Practice;
|
||||
use App\Models\PractitionerRole;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Linksehat\Transformers\Speciality\SpecialityResource;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SpecialityController extends Controller
|
||||
{
|
||||
@@ -23,13 +25,13 @@ class SpecialityController extends Controller
|
||||
$messageorganizationId = !empty($organizationId) ? ' ' : ' organization_id or ';
|
||||
$messageSpecialityId = !empty($specialityId) ? ' ' : 'speciality_id';
|
||||
|
||||
abort(400, 'Missing Parameter' . $messageorganizationId . $messageSpecialityId);
|
||||
abort(Response::HTTP_BAD_REQUEST, 'Missing Parameter' . $messageorganizationId . $messageSpecialityId);
|
||||
}
|
||||
|
||||
$doctors = PractitionerRole::query()
|
||||
->with(['practitioner.person', 'speciality', 'prices'])
|
||||
->whereHas('prices', function ($query) {
|
||||
$query->where('priceable_type', 'App\Models\Practice');
|
||||
$query->where('priceable_type', Practice::class);
|
||||
})
|
||||
->where('organization_id', $organizationId)
|
||||
->where('speciality_id', $specialityId)
|
||||
@@ -38,14 +40,10 @@ class SpecialityController extends Controller
|
||||
foreach ($doctors as $key => $doctor) {
|
||||
$specialisName = $doctor->speciality->name;
|
||||
}
|
||||
// return $doctors;
|
||||
return SpecialityResource::collection($doctors);
|
||||
return 'c';
|
||||
|
||||
// Price belum ke ambil
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'statusCode' => 200,
|
||||
'status' => 'success',
|
||||
'statusCode' => Response::HTTP_OK,
|
||||
'message' => 'Data Berhasil di ambil',
|
||||
'data' => [
|
||||
'title' => 'Spesialis ' . $specialisName,
|
||||
@@ -57,27 +55,28 @@ class SpecialityController extends Controller
|
||||
public function searchSpecialityOrPerson(Request $request)
|
||||
{
|
||||
$doctors = PractitionerRole::query()
|
||||
->with(['practitioner.person', 'speciality'])
|
||||
->whereHas('practitioner.person', function ($query) use ($request) {
|
||||
$query->where('name', 'LIKE', "%{$request->value}%");
|
||||
->with(['prices'])
|
||||
->whereHas('prices', function ($query) {
|
||||
$query->where('priceable_type', Practice::class);
|
||||
})
|
||||
// ->whereHas('speciality', function ($query) use ($request) {
|
||||
// $query->where('name', 'LIKE', "%{$request->value}%");
|
||||
// })
|
||||
->get();
|
||||
->leftJoin('specialities', function ($query) {
|
||||
$query->on('practitioner_roles.speciality_id', '=', 'specialities.id');
|
||||
})
|
||||
->leftJoin('persons', function ($query) {
|
||||
$query->on('practitioner_roles.practitioner_id', '=', 'persons.id');
|
||||
})
|
||||
->whereRaw("(persons.name LIKE '%{$request->value}%' OR specialities.name LIKE '%{$request->value}%')")
|
||||
->where('organization_id', $request->organization_id)
|
||||
->get(['persons.name AS person_name', 'specialities.name AS speciality_name', 'practitioner_id', 'practitioner_roles.id']);
|
||||
|
||||
return $doctors;
|
||||
|
||||
// Price belum ke ambil
|
||||
// return response()->json([
|
||||
// 'status' => true,
|
||||
// 'statusCode' => 200,
|
||||
// 'message' => 'Data Berhasil di ambil',
|
||||
// 'data' => [
|
||||
// 'title' => 'Spesialis ' . $specialisName,
|
||||
// 'doctors' => SpecialityResource::collection($doctors)
|
||||
// ]
|
||||
// ]);
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'statusCode' => Response::HTTP_OK,
|
||||
'message' => 'Data Berhasil di ambil',
|
||||
'data' => [
|
||||
'doctors' => SpecialityResource::collection($doctors)
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,7 @@ Route::prefix('linksehat')->group(function () {
|
||||
|
||||
Route::controller(SpecialityController::class)->group(function () {
|
||||
Route::get('specialities', 'index');
|
||||
Route::get('search-person', 'searchSpecialityOrPerson');
|
||||
Route::get('search', 'searchSpecialityOrPerson');
|
||||
});
|
||||
|
||||
Route::controller(HospitalController::class)->group(function () {
|
||||
|
||||
@@ -29,9 +29,9 @@ class SpecialityResource extends JsonResource
|
||||
|
||||
return [
|
||||
'doctors' => [
|
||||
'id' => $this->practitioner->person->id,
|
||||
'name' => $this->practitioner->person->name,
|
||||
'specialis' => 'Spesialis ' . $this->speciality->name,
|
||||
'id' => isset($this->practitioner->person->id) ? $this->practitioner->person->id : $this->practitioner_id,
|
||||
'name' => isset($this->practitioner->person->name) ? $this->practitioner->person->name : $this->person_name,
|
||||
'specialis' => 'Spesialis ' . (isset($this->speciality->name) ? $this->speciality->name : $this->speciality_name),
|
||||
'experience' => rand(5, 12),
|
||||
'rating' => rand(20, 100),
|
||||
'price' => Helper::currencyIdrFormat($prices),
|
||||
|
||||
Reference in New Issue
Block a user