Fix Doctor By Speciality

This commit is contained in:
R
2022-11-17 13:43:40 +07:00
parent 9a869968dc
commit 52e5cdb779
12 changed files with 64 additions and 38 deletions

View File

@@ -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);

View File

@@ -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]);
}
}

View File

@@ -6,6 +6,7 @@ use App\Traits\Blameable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
class Speciality extends Model
{
@@ -20,4 +21,22 @@ class Speciality extends Model
'code',
'name'
];
protected $hidden = [
'created_at',
'updated_at',
'deleted_at',
'created_by',
'updated_by',
'deleted_by',
];
protected $appends = [
'image_url'
];
public function getImageUrlAttribute()
{
return asset('images/specialities/'.Str::slug($this->name, '-').'.png');
}
}

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB