From f0bf98b15320c81d491b83644ff79942eaf80134 Mon Sep 17 00:00:00 2001 From: Muhammad Fajar Date: Tue, 8 Nov 2022 09:31:09 +0700 Subject: [PATCH] api detail appointment --- .../Controllers/Api/AppointmentController.php | 4 +--- .../Appointment/AppointmentDetailResource.php | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Modules/Linksehat/Http/Controllers/Api/AppointmentController.php b/Modules/Linksehat/Http/Controllers/Api/AppointmentController.php index 40baa991..b2ddce78 100755 --- a/Modules/Linksehat/Http/Controllers/Api/AppointmentController.php +++ b/Modules/Linksehat/Http/Controllers/Api/AppointmentController.php @@ -70,9 +70,7 @@ class AppointmentController extends Controller { $appointment = Appointment::query()->with(['appointmentParticipants', 'organization'])->find($id); - return new AppointmentDetailResource($appointment); - - return response()->json($appointment); + return Helper::responseJson(new AppointmentDetailResource($appointment)); } /** diff --git a/Modules/Linksehat/Transformers/Appointment/AppointmentDetailResource.php b/Modules/Linksehat/Transformers/Appointment/AppointmentDetailResource.php index f7d3726e..449d47c2 100755 --- a/Modules/Linksehat/Transformers/Appointment/AppointmentDetailResource.php +++ b/Modules/Linksehat/Transformers/Appointment/AppointmentDetailResource.php @@ -2,6 +2,7 @@ namespace Modules\Linksehat\Transformers\Appointment; +use App\Helpers\Helper; use App\Models\Person; use App\Models\PractitionerRole; use Carbon\Carbon; @@ -25,7 +26,8 @@ class AppointmentDetailResource extends JsonResource } } - $queryPatient = Person::query()->find($patiendId); + $queryPatient = Person::query() + ->find($patiendId); $patient = [ 'id' => $queryPatient->id, @@ -34,7 +36,18 @@ class AppointmentDetailResource extends JsonResource 'phone' => $queryPatient->phone, ]; - $queryDoctor = PractitionerRole::query()->with(['practitioner.person', 'speciality'])->where('practitioner_id', $doctorId)->first(); + $queryDoctor = PractitionerRole::query() + ->with(['practitioner.person', 'speciality', 'practices.prices']) + ->where('practitioner_id', $doctorId) + ->first(); + + foreach ($queryDoctor->practices as $qPractice) { + foreach ($qPractice->prices as $qPrice) { + if (strtolower($qPractice->service_code) == strtolower($this->appointment_type)) { + $price = $qPrice->price_net; + } + } + } $doctor = [ 'id' => $doctorId, @@ -54,6 +67,7 @@ class AppointmentDetailResource extends JsonResource 'address' => $this->organization->currentAddress->text, ], 'patient' => $patient, + 'price' => Helper::currencyIdrFormat($price) ]; } }