diff --git a/Modules/Linksehat/Http/Controllers/Api/PersonController.php b/Modules/Linksehat/Http/Controllers/Api/PersonController.php new file mode 100644 index 00000000..c629a48c --- /dev/null +++ b/Modules/Linksehat/Http/Controllers/Api/PersonController.php @@ -0,0 +1,132 @@ +organization_id; + $specialityId = $request->speciality_id; + + if (empty($organizationId) || empty($specialityId)) { + $messageorganizationId = !empty($organizationId) ? ' ' : ' organization_id or '; + $messageSpecialityId = !empty($specialityId) ? ' ' : 'speciality_id'; + + abort(400, 'missing parameter' . $messageorganizationId . $messageSpecialityId); + } + + $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) + ] + ]); + } + + 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}%"); + }) + // ->whereHas('speciality', function ($query) use ($request) { + // $query->where('name', 'LIKE', "%{$request->value}%"); + // }) + ->get(); + + 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) + // ] + // ]); + } + + /** + * Show the form for creating a new resource. + * @return Renderable + */ + public function create() + { + // + } + + /** + * Store a newly created resource in storage. + * @param Request $request + * @return Renderable + */ + public function store(Request $request) + { + // + } + + /** + * Show the specified resource. + * @param int $id + * @return Renderable + */ + public function show(Request $request, $id) + { + // + } + + /** + * Show the form for editing the specified resource. + * @param int $id + * @return Renderable + */ + public function edit($id) + { + // + } + + /** + * Update the specified resource in storage. + * @param Request $request + * @param int $id + * @return Renderable + */ + public function update(Request $request, $id) + { + // + } + + /** + * Remove the specified resource from storage. + * @param int $id + * @return Renderable + */ + public function destroy($id) + { + // + } +} diff --git a/Modules/Linksehat/Http/Controllers/Api/SpecialityController.php b/Modules/Linksehat/Http/Controllers/Api/SpecialityController.php index e31c3c1d..32dabb3c 100644 --- a/Modules/Linksehat/Http/Controllers/Api/SpecialityController.php +++ b/Modules/Linksehat/Http/Controllers/Api/SpecialityController.php @@ -2,9 +2,7 @@ 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; @@ -25,14 +23,24 @@ class SpecialityController extends Controller $messageorganizationId = !empty($organizationId) ? ' ' : ' organization_id or '; $messageSpecialityId = !empty($specialityId) ? ' ' : 'speciality_id'; - abort(400, 'missing parameter' . $messageorganizationId . $messageSpecialityId); + abort(400, 'Missing Parameter' . $messageorganizationId . $messageSpecialityId); } - $doctors = PractitionerRole::query()->with(['practitioner.person', 'speciality'])->where('organization_id', $organizationId)->where('speciality_id', $specialityId)->get(); + $doctors = PractitionerRole::query() + ->with(['practitioner.person', 'speciality', 'prices']) + ->whereHas('prices', function ($query) { + $query->where('priceable_type', 'App\Models\Practice'); + }) + ->where('organization_id', $organizationId) + ->where('speciality_id', $specialityId) + ->get(); foreach ($doctors as $key => $doctor) { $specialisName = $doctor->speciality->name; } + // return $doctors; + return SpecialityResource::collection($doctors); + return 'c'; // Price belum ke ambil return response()->json([ @@ -46,6 +54,32 @@ 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}%"); + }) + // ->whereHas('speciality', function ($query) use ($request) { + // $query->where('name', 'LIKE', "%{$request->value}%"); + // }) + ->get(); + + 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) + // ] + // ]); + } + /** * Show the form for creating a new resource. * @return Renderable diff --git a/Modules/Linksehat/Transformers/Hospitals/HospitalResourceDetail.php b/Modules/Linksehat/Transformers/Hospitals/HospitalResourceDetail.php index 26140408..e9534681 100644 --- a/Modules/Linksehat/Transformers/Hospitals/HospitalResourceDetail.php +++ b/Modules/Linksehat/Transformers/Hospitals/HospitalResourceDetail.php @@ -17,7 +17,7 @@ class HospitalResourceDetail extends JsonResource public function toArray($request) { $querySpecialitys = PractitionerRole::query() - ->with('speciality') + ->with(['speciality']) ->where('organization_id', $this->id) ->whereNotNull('speciality_id') ->orderBy('speciality_id') @@ -27,7 +27,7 @@ class HospitalResourceDetail extends JsonResource foreach ($querySpecialitys as $indexSpeciality => $speciality) { $specialitys[$indexSpeciality]['id'] = $speciality->speciality->id; $specialitys[$indexSpeciality]['name'] = $speciality->speciality->name; - $specialitys[$indexSpeciality]['avatar'] = null; + $specialitys[$indexSpeciality]['avatar'] = asset('images/default-specialisasi-image.png'); } if (empty($this->distance)) { diff --git a/Modules/Linksehat/Transformers/Speciality/SpecialityResource.php b/Modules/Linksehat/Transformers/Speciality/SpecialityResource.php index beddb480..98936d30 100644 --- a/Modules/Linksehat/Transformers/Speciality/SpecialityResource.php +++ b/Modules/Linksehat/Transformers/Speciality/SpecialityResource.php @@ -2,7 +2,7 @@ namespace Modules\Linksehat\Transformers\Speciality; -use App\Models\Practice; +use App\Helpers\Helper; use Illuminate\Http\Resources\Json\JsonResource; class SpecialityResource extends JsonResource @@ -15,13 +15,26 @@ class SpecialityResource extends JsonResource */ public function toArray($request) { + foreach ($this->practices as $practice) { + if ($practice->service_code === 'walkin') { + $practices[] = $practice->id; + } + } + + foreach ($this->prices as $price) { + if (in_array($price->priceable_id, $practices)) { + $prices = $price->price_net; + } + } + return [ 'doctors' => [ + 'id' => $this->practitioner->person->id, 'name' => $this->practitioner->person->name, 'specialis' => 'Spesialis ' . $this->speciality->name, 'experience' => rand(5, 12), 'rating' => rand(20, 100), - 'price' => '', + 'price' => Helper::currencyIdrFormat($prices), ] ]; } diff --git a/app/Models/PractitionerRole.php b/app/Models/PractitionerRole.php index 1b320f92..19efe922 100644 --- a/app/Models/PractitionerRole.php +++ b/app/Models/PractitionerRole.php @@ -64,8 +64,18 @@ class PractitionerRole extends Model return $this->hasMany(Practice::class, 'practitioner_role_id'); } + public function prices() + { + return $this->hasManyThrough(Price::class, Practice::class, 'practitioner_role_id', 'id'); + } + public function availabilities() { return $this->hasMany(PractitionerRoleAvailability::class, 'practitioner_role_id'); } + + public function person() + { + return $this->hasOneThrough(Person::class, Practitioner::class, 'person_id', 'id'); + } }