Merge branch 'staging' of https://dev.sismedika.online/febio/aso into staging

This commit is contained in:
Linksehat Staging Server
2024-07-12 08:48:13 +07:00
15 changed files with 829 additions and 1054 deletions

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

@@ -31,6 +31,8 @@ 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\Linksehat\RujukanController;
use Modules\Internal\Http\Controllers\Api\Linksehat\PrescriptionController as PrescriptionControllerReport;
use Modules\Internal\Http\Controllers\Api\LivechatController;
use Modules\Internal\Http\Controllers\Api\MemberController;
use Modules\Internal\Http\Controllers\Api\OptionController;
@@ -88,6 +90,10 @@ Route::prefix('internal')->group(function () {
// Report LMS
Route::get('linksehat/phr', [HealthRecordController::class, 'index']);
Route::get('linksehat/phr/generate-excel', [HealthRecordController::class, 'generateExcel']);
Route::get('linksehat/prescription', [PrescriptionControllerReport::class, 'index']);
Route::get('linksehat/prescription/generate-excel', [PrescriptionControllerReport::class, 'generateExcel']);
Route::get('linksehat/rujukan', [RujukanController::class, 'index']);
Route::get('linksehat/rujukan/generate-excel', [RujukanController::class, 'generateExcel']);
Route::post('logout', [AuthController::class, 'logout'])->name('logout');
Route::get('/user', function (Request $request) {

View File

@@ -0,0 +1,32 @@
<?php
namespace Modules\Internal\Transformers;
use Illuminate\Http\Resources\Json\JsonResource;
use Carbon\Carbon;
class ReportPrescriptionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
$patientName = $this->user ? $this->user->sFirstName .' '. $this->user->sLastName : '-';
$data = [
'id' => $this->nID,
'patient_name' => $patientName,
'livechat' => $this->livechat,
'prescription_code' => $this->sKodeResep,
'date_consultation' => $this->dTanggalResep ? Carbon::parse($this->dTanggalResep)->format('Y-m-d H:i:s') : null,
'doctor_name' => $this->sDokterName ? $this->sDokterName : '-',
'items' => $this->items ? $this->items : [],
];
return $data;
}
}