report excel
This commit is contained in:
@@ -27,7 +27,7 @@ class HealthRecordController extends Controller
|
||||
// return $request->toArray();
|
||||
$livechat = Livechat::query()
|
||||
->with([ 'user', 'doctor', 'doctor.user', 'doctor.user.detail', 'doctor.speciality', 'appointment', 'healthCare', 'summary']);
|
||||
|
||||
|
||||
if ($request->has('search')) {
|
||||
$search = $request->search;
|
||||
$livechat->where(function ($query) use ($search) {
|
||||
@@ -41,13 +41,13 @@ class HealthRecordController extends Controller
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (($request->has('livechat_start') || $request->has('livechat_end'))
|
||||
&& !empty($request->livechat_start)
|
||||
&& !empty($request->livechat_end)
|
||||
) {
|
||||
|
||||
|
||||
|
||||
|
||||
$livechat = $livechat->where(function($q) use ($request) {
|
||||
$q->where('dCreateOn', '>=', $request->livechat_start)
|
||||
->where('dCreateOn', '<=', $request->livechat_end);
|
||||
@@ -124,36 +124,50 @@ class HealthRecordController extends Controller
|
||||
//
|
||||
}
|
||||
|
||||
// Function to determine if a string is serialized
|
||||
private function is_serialized($string) {
|
||||
// Function to determine if a string is serialized
|
||||
private function is_serialized($string) {
|
||||
// Check if string is empty
|
||||
if (empty($string)) {
|
||||
return false;
|
||||
}
|
||||
// Check for common serialized string patterns
|
||||
return ($string == 'b:0;' || @unserialize($string) !== false);
|
||||
}
|
||||
|
||||
// Function to determine if a string is JSON
|
||||
private function is_json($string) {
|
||||
// Check if string is empty
|
||||
if (empty($string)) {
|
||||
return false;
|
||||
}
|
||||
// Decode JSON and check for errors
|
||||
json_decode($string);
|
||||
return (json_last_error() == JSON_ERROR_NONE);
|
||||
}
|
||||
|
||||
// Function to safely process the plan
|
||||
private function processPlan($sPlan) {
|
||||
// Check if the string is serialized
|
||||
if ($this->is_serialized($sPlan)) {
|
||||
$unserializedPlan = @unserialize($sPlan);
|
||||
if ($unserializedPlan !== false || $sPlan === 'b:0;') {
|
||||
return $unserializedPlan;
|
||||
}
|
||||
} elseif ($this->is_json($sPlan)) {
|
||||
}
|
||||
// Check if the string is JSON
|
||||
elseif ($this->is_json($sPlan)) {
|
||||
$jsonPlan = json_decode($sPlan, true);
|
||||
if (json_last_error() == JSON_ERROR_NONE) {
|
||||
return $jsonPlan;
|
||||
}
|
||||
}
|
||||
return $sPlan; // Treat as plain text if not serialized or JSON
|
||||
// Treat as plain text if not serialized or JSON
|
||||
return $sPlan;
|
||||
}
|
||||
|
||||
public function generateExcel(Request $request){
|
||||
Helper::setCustomPHPIniSettings();
|
||||
|
||||
|
||||
$file_name = 'Data Report Riwayat Rekam Medis';
|
||||
// Membuat penulis entitas Spout
|
||||
$writer = WriterEntityFactory::createXLSXWriter();
|
||||
@@ -177,7 +191,7 @@ class HealthRecordController extends Controller
|
||||
$writer->addRow($headerRow);
|
||||
$livechats = Livechat::query()
|
||||
->with([ 'user', 'doctor', 'doctor.user', 'doctor.user.detail', 'doctor.speciality', 'appointment', 'healthCare', 'summary']);
|
||||
|
||||
|
||||
if ($request->has('search')) {
|
||||
$search = $request->search;
|
||||
$livechats->where(function ($query) use ($search) {
|
||||
@@ -191,7 +205,7 @@ class HealthRecordController extends Controller
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (($request->has('livechat_start') || $request->has('livechat_end'))
|
||||
&& !empty($request->livechat_start)
|
||||
&& !empty($request->livechat_end)
|
||||
@@ -201,7 +215,7 @@ class HealthRecordController extends Controller
|
||||
->where('dCreateOn', '<=', $request->livechat_end);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$livechats = $livechats->get();
|
||||
|
||||
if ($livechats){
|
||||
@@ -209,12 +223,24 @@ class HealthRecordController extends Controller
|
||||
$doctor_name = '-';
|
||||
if ($row->doctor && $row->doctor->user && $row->doctor->user->detail) {
|
||||
$doctor_name = $row->doctor->user->detail->sTitlePrefix . ' ' . $row->doctor->user->fullname;
|
||||
}
|
||||
}
|
||||
$speciality = $row->doctor->speciality->sSpesialis ?? '-';
|
||||
// Process the plan
|
||||
$plan = '-';
|
||||
if ($row->summary && $row->summary->sPlan) {
|
||||
// Check if $row->summary and $row->summary->sPlan are set and not null
|
||||
if (isset($row->summary) && isset($row->summary->sPlan)) {
|
||||
$plan = $this->processPlan($row->summary->sPlan);
|
||||
|
||||
if (is_array($plan)) {
|
||||
// Mengubah array menjadi string dengan format yang diinginkan
|
||||
$plans = implode(', ', array_map(function($item) {
|
||||
return !empty($item['note']) ? $item['note'] : '-';
|
||||
}, $plan));
|
||||
} else {
|
||||
// Jika $plan bukan array, set $plans menjadi tanda '-'
|
||||
$plans = '-';
|
||||
}
|
||||
} else {
|
||||
// If $row->summary or $row->summary->sPlan are not set, set $plans to '-'
|
||||
$plans = '-';
|
||||
}
|
||||
|
||||
$rowData = [
|
||||
@@ -226,9 +252,10 @@ class HealthRecordController extends Controller
|
||||
$row->summary ? $row->summary->sSubjective : '-',
|
||||
$row->summary ? $row->summary->sObjective : '-',
|
||||
$row->summary ? $row->summary->sAssessment : '-',
|
||||
is_array($plan) ? implode(', ', $plan) : $plan, // Handle arrays from unserialized or JSON data
|
||||
// is_array($plan) ? implode(', ', $plan[0]) : $plan, // Handle arrays from unserialized or JSON data
|
||||
$row->summary ? $plans : '-',
|
||||
];
|
||||
|
||||
|
||||
// Create a row from the array and add it to the writer
|
||||
$rowEntity = WriterEntityFactory::createRowFromArray($rowData);
|
||||
$writer->addRow($rowEntity);
|
||||
|
||||
@@ -20,6 +20,13 @@ class ReportPhrResource extends JsonResource
|
||||
if ($this->doctor && $this->doctor->user && $this->doctor->user->detail) {
|
||||
$doctor_name = $this->doctor->user->detail->sTitlePrefix . ' ' . $this->doctor->user->fullname;
|
||||
}
|
||||
|
||||
// Process the plan
|
||||
$plan = [];
|
||||
if ($this->summary && $this->summary->sPlan) {
|
||||
$plan = $this->processPlan($this->summary->sPlan);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id' => $this->nID,
|
||||
'healthcare' => $this->healthCare ? $this->healthCare->sHealthCare : null,
|
||||
@@ -30,9 +37,36 @@ class ReportPhrResource extends JsonResource
|
||||
'subject' => $this->summary ? $this->summary->sSubjective : null,
|
||||
'object' => $this->summary ? $this->summary->sObjective : null,
|
||||
'assessment' => $this->summary ? $this->summary->sAssessment : null,
|
||||
'plan' => $this->summary ? unserialize($this->summary->sPlan) : null,
|
||||
'plan' => $plan,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Function to determine if a string is serialized
|
||||
private function is_serialized($string) {
|
||||
return ($string == 'b:0;' || @unserialize($string) !== false);
|
||||
}
|
||||
|
||||
// Function to determine if a string is JSON
|
||||
private function is_json($string) {
|
||||
json_decode($string);
|
||||
return (json_last_error() == JSON_ERROR_NONE);
|
||||
}
|
||||
|
||||
// Function to safely process the plan
|
||||
private function processPlan($sPlan) {
|
||||
if ($this->is_serialized($sPlan)) {
|
||||
$unserializedPlan = @unserialize($sPlan);
|
||||
if ($unserializedPlan !== false || $sPlan === 'b:0;') {
|
||||
return $unserializedPlan;
|
||||
}
|
||||
} elseif ($this->is_json($sPlan)) {
|
||||
$jsonPlan = json_decode($sPlan, true);
|
||||
if (json_last_error() == JSON_ERROR_NONE) {
|
||||
return $jsonPlan;
|
||||
}
|
||||
}
|
||||
return $sPlan; // Treat as plain text if not serialized or JSON
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user