90 lines
4.1 KiB
PHP
90 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\Internal\Transformers;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use App\Helpers\Helper;
|
|
use App\Models\Prescription;
|
|
use App\Models\PrescriptionItem;
|
|
|
|
class LivechatResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$prescription = Prescription::where('livechat_id', $this->nID)->first();
|
|
$diagnosis = $prescription ? $prescription->icd_code : '';
|
|
$hospital = $prescription ? $prescription->organization_id : '';
|
|
|
|
$prescriptionItem = $prescription ? PrescriptionItem::where('prescription_id', $prescription->id)->get() : [
|
|
[
|
|
'drug_id' => 0,
|
|
'qty' => 0,
|
|
'signa' => '',
|
|
'unit_id' => 0,
|
|
'note' => '', // input to database
|
|
]
|
|
];
|
|
|
|
$livechat = [
|
|
'id' => $this->nID,
|
|
'doctor_name' => isset($this->doctor->user->sFirstName) ? $this->doctor->user->detail->sTitlePrefix . '. ' . $this->doctor->user->sFirstName . ' ' . $this->doctor->user->sLastName . ' ' . $this->doctor->user->detail->sTitleSuffix : null,
|
|
'pasien_name' => isset($this->user->sFirstName) ? $this->user->sFirstName . ' ' . $this->user->sLastName : null,
|
|
'pasien_phone' => isset($this->user->sPhone) ? $this->user->sPhone : '-',
|
|
'pasien_email' => isset($this->user->sEmail) ? $this->user->sEmail : '-',
|
|
'speciality' => $this->doctor->speciality->sKeterangan ?? null,
|
|
'health_care' => $this->healthCare->sHealthCare ?? null,
|
|
'date_appointment' => $this->appointment !== null ?
|
|
Carbon::parse($this->appointment->appointmentDetail->dTanggalAppointment)->format('d-m-Y')
|
|
. ' ' . $this->appointment->appointmentDetail->tTimeAppointment :
|
|
null,
|
|
'status_appointment' => $this->appointment->paymentStatus ?? null,
|
|
'date_created' => Carbon::parse($this->dCreateOn)->format('d-m-Y') ?? null,
|
|
'time_request' => Carbon::parse($this->dCreateOn)->format('H:i:s') ?? null,
|
|
'patient_media' => $this->sMedia ?? null,
|
|
'doctor_media' => $this->sMediaDokter ?? null,
|
|
'appointment_media' => $this->appointment->sMedia ?? null,
|
|
'status_chat' => $this->status_name ?? null,
|
|
'payment_method' => $this->appointment->payment_method ?? null,
|
|
'diagnosis' => $diagnosis,
|
|
'hospital' => $hospital,
|
|
'medicine' => $prescriptionItem
|
|
];
|
|
|
|
$start_time = $this->dStartTime;
|
|
$end_time = $this->dEndTime;
|
|
$data_duration = 0 . ' jam ' . 0 . ' menit ' . 0 . ' detik';
|
|
if ($start_time != null && $end_time != null) {
|
|
$duration = Carbon::parse($start_time)->diffInMinutes(Carbon::parse($end_time));
|
|
$hours = floor($duration / 60);
|
|
$minutes = $duration % 60;
|
|
$seconds = ($duration - ($hours * 60) - $minutes) * 60;
|
|
|
|
$data_duration = $hours . ' jam ' . $minutes . ' menit ' . $seconds . ' detik';
|
|
}
|
|
|
|
$livechat['duration'] = $data_duration;
|
|
|
|
$payment_detail = null;
|
|
|
|
if ($this->appointment !== null && $this->appointment->appointmentDetail->sPaymentDetails !== null) {
|
|
$payment_detail = [
|
|
'payment_type' => $this->appointment->appointmentDetail->sPaymentDetails['payment_type'],
|
|
'transaction_time' => $this->appointment->appointmentDetail->sPaymentDetails['transaction_time'],
|
|
'gross_amount' => Helper::formatRupiah($this->appointment->appointmentDetail->sPaymentDetails['gross_amount']),
|
|
'currency' => $this->appointment->appointmentDetail->sPaymentDetails['currency'],
|
|
'status_message' => $this->appointment->appointmentDetail->sPaymentDetails['status_message'],
|
|
];
|
|
}
|
|
|
|
$livechat['payment_detail'] = $payment_detail;
|
|
return $livechat;
|
|
}
|
|
}
|