This commit is contained in:
Server D3 Linksehat
2024-10-14 10:35:21 +07:00
parent 611689235b
commit 013c57d00a
86 changed files with 9199 additions and 729 deletions

View File

@@ -0,0 +1,270 @@
<?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) {
// 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;
}
}
// 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;
}
}
// 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();
// 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 ?? '-';
// 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 = [
$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[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);
}
}
$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')
]);
}
}

View File

@@ -0,0 +1,240 @@
<?php
namespace Modules\Internal\Http\Controllers\Api\Linksehat;
use App\Helpers\Helper;
use App\Models\OLDLMS\Prescription;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Internal\Transformers\ReportPrescriptionResource;
use Carbon\Carbon;
use Maatwebsite\Excel\Facades\Excel;
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
class PrescriptionController extends Controller
{
/**
* Display a listing of the resource.
* @return Renderable
*/
public function index(Request $request)
{
// return $request->toArray();
$prescription = Prescription::query()
->with(['livechat', 'user', 'items']);
if ($request->has('search')) {
$search = $request->search;
$prescription->where(function ($query) use ($search) {
$query->where('sDokterName', 'LIKE', '%' . $search . "%")
->orWhere('sKodeResep', 'LIKE', '%' . $search . "%");
});
}
if (($request->has('prescription_start') || $request->has('prescription_end'))
&& !empty($request->prescription_start)
&& !empty($request->prescription_end)
) {
$prescription = $prescription->where(function($q) use ($request) {
$q->where('dTanggalResep', '>=', $request->prescription_start)
->where('dTanggalResep', '<=', $request->prescription_end);
});
}
$prescriptions = $prescription->orderBy('dUpdateOn', 'DESC')
->paginate();
return Helper::responseJson(Helper::paginateResources(ReportPrescriptionResource::collection($prescriptions)));
}
/**
* 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 Resep Online';
// Membuat penulis entitas Spout
$writer = WriterEntityFactory::createXLSXWriter();
// Membuka penulis untuk menulis ke file
$writer->openToFile(public_path('files/Report-Resep-Online.xlsx'));
$headerArray = [
'No',
'Prescription Code',
'Date Consultation',
'Patient',
'Doctor',
'Jenis Obat (Drugs)',
'Jumlah Obat (QTY)',
'Cara Minum Obat',
];
// Sheet 1
$writer->getCurrentSheet()->setName('Data');
$headerRow = WriterEntityFactory::createRowFromArray($headerArray);
$writer->addRow($headerRow);
// Query prescription data
$prescriptionQuery = Prescription::query()
->with(['livechat', 'user', 'items']);
if ($request->has('search')) {
$search = $request->search;
$prescriptionQuery->where(function ($query) use ($search) {
$query->where('sDokterName', 'LIKE', '%' . $search . '%')
->orWhere('sKodeResep', 'LIKE', '%' . $search . '%');
});
}
if ($request->has('prescription_start') && $request->has('prescription_end') &&
!empty($request->prescription_start) && !empty($request->prescription_end)) {
$prescriptionQuery->whereBetween('dTanggalResep', [$request->prescription_start, $request->prescription_end]);
}
$prescriptions = $prescriptionQuery->get();
if ($prescriptions->isNotEmpty()) {
$no = 1;
foreach ($prescriptions as $index => $row) {
if ($row->items->isNotEmpty()) {
$rowData = [
$no++,
$row->sKodeResep ?? '-',
$row->dTanggalResep ? Carbon::parse($row->dTanggalResep)->format('Y-m-d') : '-',
$row->user->name ?? '-',
$row->sDokterName ?? '-',
];
// Create a row from the array and add it to the writer
$rowEntity = WriterEntityFactory::createRowFromArray($rowData);
$writer->addRow($rowEntity);
foreach ($row->items as $item) {
$rowSubData = [
'',
'',
'',
'',
'',
$item->sItemName ?? '-',
$item->nQty ?? '-',
$item->sSigna ?? '-'
];
$subData = WriterEntityFactory::createRowFromArray($rowSubData);
$writer->addRow($subData);
}
} else {
$rowData = [
$no++,
$row->sKodeResep ?? '-',
$row->dTanggalResep ? Carbon::parse($row->dTanggalResep)->format('Y-m-d') : '-',
$row->user->name ?? '-',
$row->sDokterName ?? '-',
];
// 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 Resep Online " . date('Y-m-d h:i:s'),
'file_url' => url('files/Report-Resep-Online.xlsx')
]);
}
}

View File

@@ -0,0 +1,243 @@
<?php
namespace Modules\Internal\Http\Controllers\Api\Linksehat;
use App\Helpers\Helper;
use App\Models\OLDLMS\Rujukan;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Internal\Transformers\ReportRujukanResource;
use Carbon\Carbon;
use Maatwebsite\Excel\Facades\Excel;
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
class RujukanController extends Controller
{
/**
* Display a listing of the resource.
* @return Renderable
*/
public function index(Request $request)
{
// return $request->toArray();
$rujukan = Rujukan::query()
->with(['livechat', 'livechat.user']);
if ($request->has('search')) {
$search = $request->search;
$rujukan->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('rujukan_start') || $request->has('rujukan_end'))
&& !empty($request->rujukan_start)
&& !empty($request->rujukan_end)
) {
$rujukan = $rujukan->where(function($q) use ($request) {
$q->where('dCreateOn', '>=', $request->rujukan_start)
->where('dCreateOn', '<=', $request->rujukan_end);
});
}
if ($request->has('healthcare_id') && !empty($request->healthcare_id)) {
$rujukan->where('nIDHealthCare', $request->healthcare_id);
}
$rujukans = $rujukan->orderBy('dUpdateOn', 'DESC')
->paginate();
return Helper::responseJson(Helper::paginateResources(ReportRujukanResource::collection($rujukans)));
}
/**
* 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);
$rujukans = Livechat::query()
->with([ 'user', 'doctor', 'doctor.user', 'doctor.user.detail', 'doctor.speciality', 'appointment', 'healthCare', 'summary']);
if ($request->has('search')) {
$search = $request->search;
$rujukans->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('rujukan_start') || $request->has('rujukan_end'))
&& !empty($request->rujukan_start)
&& !empty($request->rujukan_end)
) {
$rujukans = $rujukans->where(function($q) use ($request) {
$q->where('dCreateOn', '>=', $request->rujukan_start)
->where('dCreateOn', '<=', $request->rujukan_end);
});
}
$rujukans = $rujukans->get();
if ($rujukans){
foreach ($rujukans 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')
]);
}
}