Fix Doctor By Speciality
This commit is contained in:
@@ -44,8 +44,15 @@ class DoctorController extends Controller
|
||||
$query->whereHas('practitioner.person', function ($person) use ($search) {
|
||||
$person->where('name', 'LIKE', '%' . $search . '%');
|
||||
});
|
||||
})
|
||||
->whereHas('speciality');
|
||||
});
|
||||
|
||||
if ($request->has('speciality_id_in')) {
|
||||
$speciality_ids = explode(',', $request->speciality_id_in);
|
||||
$doctors->whereIn('speciality_id', $speciality_ids);
|
||||
} else if ($request->has('speciality_id')) {
|
||||
$doctors->where('speciality_id', $request->speciality_id);
|
||||
}
|
||||
|
||||
if ($request->has('hospital_id_in')) {
|
||||
$hospital_ids = explode(',', $request->hospital_id_in);
|
||||
$doctors->whereIn('organization_id', $hospital_ids);
|
||||
|
||||
@@ -18,43 +18,43 @@ class SpecialityController extends Controller
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function index(Request $request)
|
||||
// public function index(Request $request)
|
||||
// {
|
||||
// $organizationId = $request->organization_id;
|
||||
// $specialityId = $request->speciality_id;
|
||||
|
||||
// if (empty($organizationId) || empty($specialityId)) {
|
||||
// $messageorganizationId = !empty($organizationId) ? ' ' : ' organization_id or ';
|
||||
// $messageSpecialityId = !empty($specialityId) ? ' ' : 'speciality_id';
|
||||
|
||||
// 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', Practice::class);
|
||||
// })
|
||||
// ->where('organization_id', $organizationId)
|
||||
// ->where('speciality_id', $specialityId)
|
||||
// ->get();
|
||||
|
||||
// abort_if(count($doctors) === 0, Response::HTTP_NOT_FOUND, 'Data Doctor tidak ditemukan');
|
||||
|
||||
// foreach ($doctors as $key => $doctor) {
|
||||
// $specialisName = $doctor->speciality->name;
|
||||
// }
|
||||
|
||||
// return Helper::responseJson([
|
||||
// 'title' => 'Spesialis ' . $specialisName,
|
||||
// 'doctors' => SpecialityResource::collection($doctors)
|
||||
// ]);
|
||||
// }
|
||||
|
||||
public function index()
|
||||
{
|
||||
$organizationId = $request->organization_id;
|
||||
$specialityId = $request->speciality_id;
|
||||
$specialities = Speciality::query()->get();
|
||||
|
||||
if (empty($organizationId) || empty($specialityId)) {
|
||||
$messageorganizationId = !empty($organizationId) ? ' ' : ' organization_id or ';
|
||||
$messageSpecialityId = !empty($specialityId) ? ' ' : 'speciality_id';
|
||||
|
||||
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', Practice::class);
|
||||
})
|
||||
->where('organization_id', $organizationId)
|
||||
->where('speciality_id', $specialityId)
|
||||
->get();
|
||||
|
||||
abort_if(count($doctors) === 0, Response::HTTP_NOT_FOUND, 'Data Doctor tidak ditemukan');
|
||||
|
||||
foreach ($doctors as $key => $doctor) {
|
||||
$specialisName = $doctor->speciality->name;
|
||||
}
|
||||
|
||||
return Helper::responseJson([
|
||||
'title' => 'Spesialis ' . $specialisName,
|
||||
'doctors' => SpecialityResource::collection($doctors)
|
||||
]);
|
||||
}
|
||||
|
||||
public function listSpeciality()
|
||||
{
|
||||
$querySpecialities = Speciality::query()->get(['name']);
|
||||
|
||||
return Helper::responseJson(['specialities' => SpecialityResource::collection($querySpecialities)]);
|
||||
return Helper::responseJson(['specialities' => $specialities]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user