Files
onboard/app/Http/Resources/Api/DepartmentPatientOperationResource.php
2026-04-24 16:46:10 +09:00

37 lines
1.3 KiB
PHP

<?php
namespace App\Http\Resources\Api;
use App\Models\DepartmentPatientOperation;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;
class DepartmentPatientOperationResource extends JsonResource
{
public function toArray(Request $request): array
{
/** @var DepartmentPatientOperation $operation */
$operation = $this->resource;
$serviceCode = $operation->serviceMedical?->ServiceMedicalCode ?? $operation->service_code;
$serviceName = $operation->serviceMedical?->ServiceMedicalName ?? $operation->service_name;
return [
'id' => $operation->department_patient_operation_id,
'urgency' => $operation->urgency,
'service' => [
'id' => $operation->rf_kl_service_medical_id,
'code' => $serviceCode,
'name' => $serviceName,
'label' => trim(($serviceCode ? "{$serviceCode} " : '').($serviceName ?? '')),
],
'startAt' => $operation->started_at?->toIso8601String(),
'endAt' => $operation->ended_at?->toIso8601String(),
'duration' => $operation->started_at && $operation->ended_at
? Carbon::parse($operation->started_at)->diffInMinutes(Carbon::parse($operation->ended_at))
: null,
];
}
}