Files
aso/Modules/Client/Transformers/AlarmCenter/DataListClaimMemberResource.php
ivan-sim 5cb26d9553 Update
2024-10-16 12:02:33 +07:00

55 lines
1.7 KiB
PHP
Executable File

<?php
namespace Modules\Client\Transformers\AlarmCenter;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\Service;
use App\Models\Organization;
use Illuminate\Support\Str;
class DataListClaimMemberResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
$filesGroupByType = $this->files->mapToGroups(function($file) {
return [Str::slug($file->type, '_') => $file];
});
$serviceData = Service::where('code', $this->service_code)->first();
$organization = Organization::where('id', $this->organization_id)->first();
$organizationName = '-';
if ($organization){
$organizationName = $organization->name;
}
if ($serviceData) {
$serviceName = $serviceData->name;
} else {
$serviceName = $this->service_code;
}
if ($this->status == 'approved' && $this->status_final_log ){
$status = 'Done';
} else if ($this->status == 'declined' || $this->status_final_log == 'declined') {
$status = 'Declined';
} else {
$status = 'Ongoing';
}
return [
'id' => $this->id,
'admission_date' => $this->submission_date ?? null,
'discharge_date' => $this->discharge_date ?? null,
'code' => $this->code ?? null,
'provider_name' => $organizationName ?? null,
'service_type' => $serviceName,
'status' => $status,
'files_by_type' => $filesGroupByType
];
}
}