api get person/doctor by speciality

This commit is contained in:
Muhammad Fajar
2022-10-28 15:03:21 +07:00
parent 03fdf2684d
commit e025675210
4 changed files with 59 additions and 17 deletions

View File

@@ -105,10 +105,9 @@ class DoctorController extends Controller
$query->select(['availability_id', 'day']);
}])->where('practitioner_role_id', $id)->get(['id', 'start_time']);
return $queryDoctor->is_chat_available;
$doctor = DoctorResourceDetail::make($queryDoctor);
$doctor['day_available'] = Helper::dailyAvailabilities($queryAvailables);
// return $doctor;
return response()->json(compact('doctor'));
}

View File

@@ -2,10 +2,13 @@
namespace Modules\Linksehat\Http\Controllers\Api;
use App\Models\Practice;
use App\Models\PractitionerRole;
use App\Models\Price;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Linksehat\Transformers\Speciality\SpecialityResource;
class SpecialityController extends Controller
{
@@ -25,7 +28,22 @@ class SpecialityController extends Controller
abort(400, 'missing parameter' . $messageorganizationId . $messageSpecialityId);
}
return PractitionerRole::query()->with('practitioner')->where('organization_id', $organizationId)->where('speciality_id', $specialityId)->get();
$doctors = PractitionerRole::query()->with(['practitioner.person', 'speciality'])->where('organization_id', $organizationId)->where('speciality_id', $specialityId)->get();
foreach ($doctors as $key => $doctor) {
$specialisName = $doctor->speciality->name;
}
// Price belum ke ambil
return response()->json([
'status' => true,
'statusCode' => 200,
'message' => 'Data Berhasil di ambil',
'data' => [
'title' => 'Spesialis ' . $specialisName,
'doctors' => SpecialityResource::collection($doctors)
]
]);
}
/**

View File

@@ -0,0 +1,28 @@
<?php
namespace Modules\Linksehat\Transformers\Speciality;
use App\Models\Practice;
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 [
'doctors' => [
'name' => $this->practitioner->person->name,
'specialis' => 'Spesialis ' . $this->speciality->name,
'experience' => rand(5, 12),
'rating' => rand(20, 100),
'price' => '',
]
];
}
}

View File

@@ -18,25 +18,22 @@ class Practice extends Model
'deleted_by'
];
// public $appends = [
// 'price'
// ];
// public function getPriceAttribute()
// {
// $orgPrice = [];
// foreach ($this->prices as $price) {
// $orgPrice[$this->service_code] = $price->price_net;
// }
// return $orgPrice;
// }
public function getPriceAttribute()
{
return $this->prices->where('priceable_id', $this->id)->max('price_net');
}
public function getPricesGroupOneAttribute()
{
$orgPrices = [];
foreach ($this->prices->where('price_group_id', 1) as $price) {
$orgPrices[$this->service_code] = $price->price_net;
}
return $orgPrices;
}
public function prices()
{
return $this->morphMany(Price::class, 'priceable');