220 lines
10 KiB
PHP
220 lines
10 KiB
PHP
<?php
|
|
|
|
namespace Modules\Client\Transformers\AlarmCenter;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Support\Carbon;
|
|
use App\Models\Icd;
|
|
use DB;
|
|
|
|
class DataServiceMonitoring extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$files = [];
|
|
$filesFinalLogResult = [];
|
|
$filesFinalLogDiagnosis = [];
|
|
$filesFinalLogKondisi = [];
|
|
if (count($this->files)>0){
|
|
foreach ($this->files as $key => $value) {
|
|
/*
|
|
Sementara di buat satu dulu, jangan di hapus..
|
|
karena suka labil client nya, tiba2 hide tiba2 munculin fitur :D
|
|
*/
|
|
|
|
// if($value->type == 'final-log-result'){
|
|
array_push($filesFinalLogResult, $value);
|
|
// };
|
|
|
|
// if($value->type == 'final-log-diagnosis'){
|
|
// array_push($filesFinalLogDiagnosis, $value);
|
|
// }
|
|
|
|
// if($value->type == 'final-log-kondisi'){
|
|
// array_push($filesFinalLogKondisi, $value);
|
|
// }
|
|
}
|
|
|
|
$files = [
|
|
'result' => $filesFinalLogResult,
|
|
'diagnosis' => $filesFinalLogDiagnosis,
|
|
'kondisi' => $filesFinalLogKondisi,
|
|
|
|
];
|
|
} else {
|
|
$files = [
|
|
'result' => [],
|
|
'diagnosis' => [],
|
|
'kondisi' => [],
|
|
|
|
];
|
|
}
|
|
|
|
$diagnosis = '-';
|
|
$main_diagnosis = '-';
|
|
if ($this->diagnosis){
|
|
$diagnosis = explode(',', $this->diagnosis);
|
|
if (count($diagnosis)>0){
|
|
|
|
foreach($diagnosis as $key => $d){
|
|
$icd = Icd::where('code', $d)->first('name');
|
|
if($key == 0){
|
|
if ($icd){
|
|
$main_diagnosis = $icd->name;
|
|
} else {
|
|
$main_diagnosis = $d;
|
|
}
|
|
$diagnosis = '-';
|
|
}
|
|
|
|
if ($key > 0){
|
|
if ($icd) {
|
|
$diagnosis .= $icd->name . ', ';
|
|
} else {
|
|
$diagnosis .= $d .', ';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return [
|
|
'companyName' => $this->member->currentCorporate->name ?? null,
|
|
'serviceCode' => $this->service_code ?? null,
|
|
'memberId' => $this->member->member_id ?? null,
|
|
'fullName' => $this->member->full_name ?? null,
|
|
'dateOfBirth' => $this->member->birth_date ?? null,
|
|
'phoneNumber' => $this->person->phone ?? null,
|
|
'email' => $this->member->email ?? ($this->member->person->email ?? null),
|
|
'serviceName' => $this->service->name ?? ($this->service_code ?? null),
|
|
'files' => $files,
|
|
'mainDiagnose' => $main_diagnosis,
|
|
'comparativeDiagnosis' => $diagnosis,
|
|
'benefits' => collect($this->requestLogBenefits)->map(function ($requestLogBenefit) {
|
|
return [
|
|
'amountIncurred' => $requestLogBenefit->amount_incurred,
|
|
'amountApproved' => $requestLogBenefit->amount_approved,
|
|
'amountNotAprroved' => $requestLogBenefit->amount_not_approved,
|
|
'excessPaid' => $requestLogBenefit->excess_paid,
|
|
'description' => $requestLogBenefit->keterangan,
|
|
'name' => $requestLogBenefit->benefit->description,
|
|
];
|
|
})->all() ?? null,
|
|
'keterangan' => $this->keterangan ?? null,
|
|
'catatan' => $this->catatan ?? null,
|
|
'benefitTotal' => $this->benefitTotal ?? null,
|
|
'hospital' => $this->organization->name ?? null,
|
|
'admissionDate' => $this->submission_date ?? null,
|
|
'dischargeDate' => $this->discharge_date ?? null,
|
|
'dailyMonitorings' => $this->when($this->service_code === 'IP', collect($this->requestLogDailyMonitorings)
|
|
->groupBy(function ($requestLogDailyMonitoring) {
|
|
return Carbon::parse($requestLogDailyMonitoring->submission_date)->format('d M Y');
|
|
})
|
|
->map(function ($groupedItems) {
|
|
return collect($groupedItems)
|
|
->map(function ($requestLogDailyMonitoring) {
|
|
$arr_document = [];
|
|
$document = DB::table('files')
|
|
->where([
|
|
'fileable_type' => 'App\Models\LaboratoriumResult',
|
|
'fileable_id' => $requestLogDailyMonitoring->id,
|
|
'deleted_at' => null
|
|
])
|
|
->whereIn('type', ['medical-action-letter', 'confirmation-medical-letter'])
|
|
->get();
|
|
if ($document){
|
|
foreach($document as $d){
|
|
$arr_document[]= [
|
|
'path' => env('APP_URL') . '/storage/lab_result/' . $d->name . '.' . $d->extension,
|
|
'type' => $d->type,
|
|
'original_name' => $d->original_name,
|
|
'name' => $d->name,
|
|
];
|
|
}
|
|
}
|
|
|
|
|
|
return [
|
|
'time' => Carbon::parse($requestLogDailyMonitoring->submission_date)->format('H:i') ?? null,
|
|
'status' => 'Done' ?? null,
|
|
'subject' => $requestLogDailyMonitoring->subject ?? null,
|
|
'object' => $requestLogDailyMonitoring->object ?? null,
|
|
'bodyTemperature' => $requestLogDailyMonitoring->body_temperature ?? null,
|
|
'sistole' => $requestLogDailyMonitoring->sistole ?? null,
|
|
'diastole' => $requestLogDailyMonitoring->diastole ?? null,
|
|
'respirationRate' => $requestLogDailyMonitoring->respiration_rate ?? null,
|
|
'analysis' => $requestLogDailyMonitoring->analysis ?? null,
|
|
'complaints' => $requestLogDailyMonitoring->complaints ?? null,
|
|
'plans' => $this->when($requestLogDailyMonitoring->requestLogMedicalPlans, collect($requestLogDailyMonitoring->requestLogMedicalPlans)
|
|
->map(function ($requestLogMedicalPlan) {
|
|
return [
|
|
'type' => $requestLogMedicalPlan->type,
|
|
'plan' => $requestLogMedicalPlan->plan
|
|
];
|
|
})
|
|
->sortBy('type')
|
|
->all()) ?? null,
|
|
'files' => $arr_document
|
|
];
|
|
})
|
|
->sortByDesc(function ($item) {
|
|
return $item['time'];
|
|
})
|
|
->values();
|
|
})
|
|
->sortByDesc(function ($groupedItems, $date) {
|
|
return Carbon::createFromFormat('d M Y', $date)->format('Y-m-d');
|
|
})
|
|
->all()) ?? null,
|
|
'laboratoriumResults' => $this->when($this->service_code === 'IP', collect($this->requestLogDailyMonitorings)
|
|
->groupBy(function ($requestLogDailyMonitoring) {
|
|
return Carbon::parse($requestLogDailyMonitoring->lab_date)->format('d M Y');
|
|
})
|
|
->map(function ($groupedItems) {
|
|
return collect($groupedItems)
|
|
->map(function ($test) {
|
|
$arr_document = [];
|
|
$document = DB::table('files')
|
|
->where([
|
|
'fileable_type' => 'App\Models\LaboratoriumResult',
|
|
'fileable_id' => $test->id,
|
|
'deleted_at' => null
|
|
])
|
|
->whereIn('type', ['laboratorium-result'])
|
|
->get();
|
|
if ($document){
|
|
foreach($document as $d){
|
|
$arr_document[]= [
|
|
'path' => env('APP_URL') . '/storage/lab_result/' . $d->name . '.' . $d->extension,
|
|
'type' => $d->type,
|
|
'original_name' => $d->original_name,
|
|
'name' => $d->name,
|
|
];
|
|
}
|
|
}
|
|
return [
|
|
'code' => $test->code,
|
|
'date' => Carbon::parse($test->lab_date)->format('d M Y') ?? null,
|
|
'examination' => $test->examination ?? null,
|
|
'location' => $test->provider ?? null,
|
|
'files' => $arr_document
|
|
];
|
|
})
|
|
->sortByDesc(function ($item) {
|
|
return $item['code'];
|
|
})
|
|
->values();
|
|
})
|
|
->sortByDesc(function ($groupedItems, $date) {
|
|
return Carbon::createFromFormat('d M Y', $date)->format('Y-m-d');
|
|
})
|
|
->all()) ?? null
|
|
];
|
|
}
|
|
}
|