Report Riwayat Medis Pasien dan excel
This commit is contained in:
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Internal\Http\Controllers\Api\Linksehat;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\OLDLMS\Livechat;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Internal\Transformers\ReportPhrResource;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
|
||||
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
|
||||
|
||||
class HealthRecordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
// 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) {
|
||||
$query->where('nID', $search)
|
||||
->orWhereHas('user', function ($detail) use ($search) {
|
||||
$detail->where('sFirstName', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('sLastName', 'LIKE', '%' . $search . '%');
|
||||
})
|
||||
->orWhereHas('healthCare', function ($detail) use ($search) {
|
||||
$detail->where('sHealthCare', 'LIKE', '%' . $search . '%');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->has('healthcare_id') && !empty($request->healthcare_id)) {
|
||||
$livechat->where('nIDHealthCare', $request->healthcare_id);
|
||||
}
|
||||
|
||||
$livechats = $livechat->orderBy('dUpdateOn', 'DESC')
|
||||
->paginate();
|
||||
|
||||
return Helper::responseJson(Helper::paginateResources(ReportPhrResource::collection($livechats)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('internal::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @param Request $request
|
||||
* @return Renderable
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('internal::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('internal::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
public function generateExcel(Request $request){
|
||||
Helper::setCustomPHPIniSettings();
|
||||
|
||||
$file_name = 'Data Report Riwayat Rekam Medis';
|
||||
// Membuat penulis entitas Spout
|
||||
$writer = WriterEntityFactory::createXLSXWriter();
|
||||
// Membuka penulis untuk menulis ke file
|
||||
$writer->openToFile(public_path('files/Report-Riwayat-Rekam-Medis.xlsx'));
|
||||
$headerArray = [
|
||||
'Healthcare',
|
||||
'Patient',
|
||||
'Doctor',
|
||||
'Speciality',
|
||||
'Date',
|
||||
'Keluhan (Subjective)',
|
||||
'Pemerikasan Fisik Online (Objective)',
|
||||
'Diagnosa (Assessment)',
|
||||
'Tata Laksana (Plan)',
|
||||
];
|
||||
// Sheet 1
|
||||
$writer->getCurrentSheet()->setName('Data');
|
||||
$headers_map_to_table_fields = $headerArray;
|
||||
$headerRow = WriterEntityFactory::createRowFromArray($headers_map_to_table_fields);
|
||||
$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) {
|
||||
$query->where('nID', $search)
|
||||
->orWhereHas('user', function ($detail) use ($search) {
|
||||
$detail->where('sFirstName', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('sLastName', 'LIKE', '%' . $search . '%');
|
||||
})
|
||||
->orWhereHas('healthCare', function ($detail) use ($search) {
|
||||
$detail->where('sHealthCare', 'LIKE', '%' . $search . '%');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (($request->has('livechat_start') || $request->has('livechat_end'))
|
||||
&& !empty($request->livechat_start)
|
||||
&& !empty($request->livechat_end)
|
||||
) {
|
||||
$livechats = $livechats->where(function($q) use ($request) {
|
||||
$q->where('dCreateOn', '>=', $request->livechat_start)
|
||||
->where('dCreateOn', '<=', $request->livechat_end);
|
||||
});
|
||||
}
|
||||
|
||||
$livechats = $livechats->get();
|
||||
|
||||
if ($livechats){
|
||||
foreach ($livechats as $index => $row) {
|
||||
$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) {
|
||||
$plan = $this->processPlan($row->summary->sPlan);
|
||||
}
|
||||
|
||||
$rowData = [
|
||||
$row->healthCare ? $row->healthCare->sHealthCare : '-',
|
||||
$row->user ? $row->user->sFirstName : '-',
|
||||
$doctor_name,
|
||||
$speciality,
|
||||
$row->summary ? Carbon::parse($row->dCreateOn)->format('Y-m-d H:i:s') : '-',
|
||||
$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
|
||||
];
|
||||
|
||||
// Create a row from the array and add it to the writer
|
||||
$rowEntity = WriterEntityFactory::createRowFromArray($rowData);
|
||||
$writer->addRow($rowEntity);
|
||||
}
|
||||
}
|
||||
$writer->close();
|
||||
return Helper::responseJson([
|
||||
'file_name' => "Data Riwayat Log " . date('Y-m-d h:i:s'),
|
||||
"file_url" => url('files/Report-Riwayat-Rekam-Medis.xlsx')
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ use Modules\Internal\Http\Controllers\Api\DrugController;
|
||||
use Modules\Internal\Http\Controllers\Api\FormulariumController;
|
||||
use Modules\Internal\Http\Controllers\Api\FormulariumTemplateController;
|
||||
use Modules\Internal\Http\Controllers\Api\Linksehat\PaymentController;
|
||||
use Modules\Internal\Http\Controllers\Api\Linksehat\HealthRecordController;
|
||||
use Modules\Internal\Http\Controllers\Api\LivechatController;
|
||||
use Modules\Internal\Http\Controllers\Api\MemberController;
|
||||
use Modules\Internal\Http\Controllers\Api\OptionController;
|
||||
@@ -72,6 +73,9 @@ Route::prefix('internal')->group(function () {
|
||||
|
||||
Route::get('linksehat/payments', [PaymentController::class, 'index']);
|
||||
Route::get('linksehat/payments/generate-excel', [PaymentController::class, 'generateExcel']);
|
||||
|
||||
|
||||
|
||||
Route::get('diagnosis', [RequestLogController::class, 'diagnosis']);
|
||||
Route::get('drugs', [DrugController::class, 'drugList']);
|
||||
Route::get('units', [DrugController::class, 'unitList']);
|
||||
@@ -80,6 +84,10 @@ Route::prefix('internal')->group(function () {
|
||||
|
||||
Route::middleware('auth:sanctum')->group(function () {
|
||||
|
||||
// Report LMS
|
||||
Route::get('linksehat/phr', [HealthRecordController::class, 'index']);
|
||||
Route::get('linksehat/phr/generate-excel', [HealthRecordController::class, 'generateExcel']);
|
||||
|
||||
Route::post('logout', [AuthController::class, 'logout'])->name('logout');
|
||||
Route::get('/user', function (Request $request) {
|
||||
return $request->user();
|
||||
|
||||
38
Modules/Internal/Transformers/ReportPhrResource.php
Normal file
38
Modules/Internal/Transformers/ReportPhrResource.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Internal\Transformers;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ReportPhrResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$doctor_name = null;
|
||||
|
||||
if ($this->doctor && $this->doctor->user && $this->doctor->user->detail) {
|
||||
$doctor_name = $this->doctor->user->detail->sTitlePrefix . ' ' . $this->doctor->user->fullname;
|
||||
}
|
||||
$data = [
|
||||
'id' => $this->nID,
|
||||
'healthcare' => $this->healthCare ? $this->healthCare->sHealthCare : null,
|
||||
'patient_name' => $this->user ? $this->user->sFirstName : null,
|
||||
'doctor_name' => $doctor_name,
|
||||
'specialis' => $this->doctor ? $this->doctor->speciality->sSpesialis : null,
|
||||
'date_consultation' => $this->summary ? Carbon::parse($this->dCreateOn)->format('Y-m-d H:i:s') : null ,
|
||||
'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,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user