unduh excel & pdf data registrasi pasien

This commit is contained in:
hasrinuryawati 2025-04-27 20:42:42 +07:00
parent ced9b41539
commit 2c9b99b40a
8 changed files with 1461 additions and 4 deletions

View File

@ -0,0 +1,33 @@
<?php
namespace App\Exports;
use App\Models\Registrasi;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class RegistrasiExport implements FromCollection, WithStyles, ShouldAutoSize
{
protected $header;
protected $data;
public function __construct(array $header, array $data)
{
$this->header = $header;
$this->data = $data;
}
public function collection()
{
return collect([$this->header])->merge($this->data);
}
public function styles(Worksheet $sheet)
{
return [
1 => ['font' => ['bold' => true]],
];
}
}

View File

@ -2,13 +2,17 @@
namespace App\Http\Controllers;
use App\Exports\RegistrasiExport;
use App\Models\Asuransi;
use App\Models\Pasien;
use App\Models\Registrasi;
use App\Models\RuangPelayanan;
use App\Models\Tindakan;
use Barryvdh\DomPDF\Facade\Pdf as FacadePdf;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Maatwebsite\Excel\Facades\Excel;
use PDF;
class RegistrasiController extends Controller
{
@ -51,4 +55,51 @@ class RegistrasiController extends Controller
return redirect()->back()->with('message','Registrasi pasien berhasil');
}
public function excelExport()
{
$registrasi = Registrasi::with(['pasien', 'asuransi', 'pegawai', 'ruangPelayanan'])->orderByDesc('id')->get();
$data = [];
$no = 1;
foreach ($registrasi as $rgs) {
$data[] = [
'No' => $no++,
'Kode Registrasi' => $rgs->code,
'Tgl Registrasi' => $rgs->tgl_registrasi,
'Nama Pasien' => $rgs->pasien->nama,
'Tgl Lahir' => date('d/m/Y', strtotime($rgs->pasien->tgl_lahir)),
'Jenis Kelamin' => $rgs->pasien->jenis_kelamin === 'male' ? 'Laki-laki' : ($rgs->pasien->jenis_kelamin === 'female' ? 'Perempuan' : ''),
'Asuransi' => $rgs->asuransi->nama ?? null,
'No Asuransi' => $rgs->no_asuransi ?? null,
'Ruang Pelayanan' => $rgs->ruangPelayanan->nama,
'Pegawai' => $rgs->pegawai->nama,
];
}
$header = [
'No',
'Kode Registrasi',
'Tgl Registrasi',
'Nama Pasien',
'Tgl Lahir',
'Jenis Kelamin',
'Asuransi',
'No Asuransi',
'Ruang Pelayanan',
'Pegawai',
];
return Excel::download(new RegistrasiExport($header, $data), 'Data Registrasi Pasien '.now().'.xlsx');
}
public function generatePdf()
{
$registrasi = Registrasi::with(['pasien', 'asuransi', 'pegawai', 'ruangPelayanan'])->orderByDesc('id')->get();
$pdf = FacadePdf::loadview('module.registrasi.registrasi_pdf', ['registrasi' => $registrasi]);
$pdf->setPaper('A4');
return $pdf->stream('Data Regitrasi Pasien '.now().'.pdf');
}
}

View File

@ -6,10 +6,12 @@
"license": "MIT",
"require": {
"php": "^8.1",
"barryvdh/laravel-dompdf": "^3.1",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
"laravel/tinker": "^2.8"
"laravel/tinker": "^2.8",
"maatwebsite/excel": "^3.1"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",

959
composer.lock generated

File diff suppressed because it is too large Load Diff

301
config/dompdf.php Normal file
View File

@ -0,0 +1,301 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings
|--------------------------------------------------------------------------
|
| Set some default values. It is possible to add all defines that can be set
| in dompdf_config.inc.php. You can also override the entire config file.
|
*/
'show_warnings' => false, // Throw an Exception on warnings from dompdf
'public_path' => null, // Override the public path if needed
/*
* Dejavu Sans font is missing glyphs for converted entities, turn it off if you need to show and £.
*/
'convert_entities' => true,
'options' => [
/**
* The location of the DOMPDF font directory
*
* The location of the directory where DOMPDF will store fonts and font metrics
* Note: This directory must exist and be writable by the webserver process.
* *Please note the trailing slash.*
*
* Notes regarding fonts:
* Additional .afm font metrics can be added by executing load_font.php from command line.
*
* Only the original "Base 14 fonts" are present on all pdf viewers. Additional fonts must
* be embedded in the pdf file or the PDF may not display correctly. This can significantly
* increase file size unless font subsetting is enabled. Before embedding a font please
* review your rights under the font license.
*
* Any font specification in the source HTML is translated to the closest font available
* in the font directory.
*
* The pdf standard "Base 14 fonts" are:
* Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique,
* Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique,
* Times-Roman, Times-Bold, Times-BoldItalic, Times-Italic,
* Symbol, ZapfDingbats.
*/
'font_dir' => storage_path('fonts'), // advised by dompdf (https://github.com/dompdf/dompdf/pull/782)
/**
* The location of the DOMPDF font cache directory
*
* This directory contains the cached font metrics for the fonts used by DOMPDF.
* This directory can be the same as DOMPDF_FONT_DIR
*
* Note: This directory must exist and be writable by the webserver process.
*/
'font_cache' => storage_path('fonts'),
/**
* The location of a temporary directory.
*
* The directory specified must be writeable by the webserver process.
* The temporary directory is required to download remote images and when
* using the PDFLib back end.
*/
'temp_dir' => sys_get_temp_dir(),
/**
* ==== IMPORTANT ====
*
* dompdf's "chroot": Prevents dompdf from accessing system files or other
* files on the webserver. All local files opened by dompdf must be in a
* subdirectory of this directory. DO NOT set it to '/' since this could
* allow an attacker to use dompdf to read any files on the server. This
* should be an absolute path.
* This is only checked on command line call by dompdf.php, but not by
* direct class use like:
* $dompdf = new DOMPDF(); $dompdf->load_html($htmldata); $dompdf->render(); $pdfdata = $dompdf->output();
*/
'chroot' => realpath(base_path()),
/**
* Protocol whitelist
*
* Protocols and PHP wrappers allowed in URIs, and the validation rules
* that determine if a resouce may be loaded. Full support is not guaranteed
* for the protocols/wrappers specified
* by this array.
*
* @var array
*/
'allowed_protocols' => [
'data://' => ['rules' => []],
'file://' => ['rules' => []],
'http://' => ['rules' => []],
'https://' => ['rules' => []],
],
/**
* Operational artifact (log files, temporary files) path validation
*/
'artifactPathValidation' => null,
/**
* @var string
*/
'log_output_file' => null,
/**
* Whether to enable font subsetting or not.
*/
'enable_font_subsetting' => false,
/**
* The PDF rendering backend to use
*
* Valid settings are 'PDFLib', 'CPDF' (the bundled R&OS PDF class), 'GD' and
* 'auto'. 'auto' will look for PDFLib and use it if found, or if not it will
* fall back on CPDF. 'GD' renders PDFs to graphic files.
* {@link * Canvas_Factory} ultimately determines which rendering class to
* instantiate based on this setting.
*
* Both PDFLib & CPDF rendering backends provide sufficient rendering
* capabilities for dompdf, however additional features (e.g. object,
* image and font support, etc.) differ between backends. Please see
* {@link PDFLib_Adapter} for more information on the PDFLib backend
* and {@link CPDF_Adapter} and lib/class.pdf.php for more information
* on CPDF. Also see the documentation for each backend at the links
* below.
*
* The GD rendering backend is a little different than PDFLib and
* CPDF. Several features of CPDF and PDFLib are not supported or do
* not make any sense when creating image files. For example,
* multiple pages are not supported, nor are PDF 'objects'. Have a
* look at {@link GD_Adapter} for more information. GD support is
* experimental, so use it at your own risk.
*
* @link http://www.pdflib.com
* @link http://www.ros.co.nz/pdf
* @link http://www.php.net/image
*/
'pdf_backend' => 'CPDF',
/**
* html target media view which should be rendered into pdf.
* List of types and parsing rules for future extensions:
* http://www.w3.org/TR/REC-html40/types.html
* screen, tty, tv, projection, handheld, print, braille, aural, all
* Note: aural is deprecated in CSS 2.1 because it is replaced by speech in CSS 3.
* Note, even though the generated pdf file is intended for print output,
* the desired content might be different (e.g. screen or projection view of html file).
* Therefore allow specification of content here.
*/
'default_media_type' => 'screen',
/**
* The default paper size.
*
* North America standard is "letter"; other countries generally "a4"
*
* @see CPDF_Adapter::PAPER_SIZES for valid sizes ('letter', 'legal', 'A4', etc.)
*/
'default_paper_size' => 'a4',
/**
* The default paper orientation.
*
* The orientation of the page (portrait or landscape).
*
* @var string
*/
'default_paper_orientation' => 'portrait',
/**
* The default font family
*
* Used if no suitable fonts can be found. This must exist in the font folder.
*
* @var string
*/
'default_font' => 'serif',
/**
* Image DPI setting
*
* This setting determines the default DPI setting for images and fonts. The
* DPI may be overridden for inline images by explictly setting the
* image's width & height style attributes (i.e. if the image's native
* width is 600 pixels and you specify the image's width as 72 points,
* the image will have a DPI of 600 in the rendered PDF. The DPI of
* background images can not be overridden and is controlled entirely
* via this parameter.
*
* For the purposes of DOMPDF, pixels per inch (PPI) = dots per inch (DPI).
* If a size in html is given as px (or without unit as image size),
* this tells the corresponding size in pt.
* This adjusts the relative sizes to be similar to the rendering of the
* html page in a reference browser.
*
* In pdf, always 1 pt = 1/72 inch
*
* Rendering resolution of various browsers in px per inch:
* Windows Firefox and Internet Explorer:
* SystemControl->Display properties->FontResolution: Default:96, largefonts:120, custom:?
* Linux Firefox:
* about:config *resolution: Default:96
* (xorg screen dimension in mm and Desktop font dpi settings are ignored)
*
* Take care about extra font/image zoom factor of browser.
*
* In images, <img> size in pixel attribute, img css style, are overriding
* the real image dimension in px for rendering.
*
* @var int
*/
'dpi' => 96,
/**
* Enable embedded PHP
*
* If this setting is set to true then DOMPDF will automatically evaluate embedded PHP contained
* within <script type="text/php"> ... </script> tags.
*
* ==== IMPORTANT ==== Enabling this for documents you do not trust (e.g. arbitrary remote html pages)
* is a security risk.
* Embedded scripts are run with the same level of system access available to dompdf.
* Set this option to false (recommended) if you wish to process untrusted documents.
* This setting may increase the risk of system exploit.
* Do not change this settings without understanding the consequences.
* Additional documentation is available on the dompdf wiki at:
* https://github.com/dompdf/dompdf/wiki
*
* @var bool
*/
'enable_php' => false,
/**
* Rnable inline JavaScript
*
* If this setting is set to true then DOMPDF will automatically insert JavaScript code contained
* within <script type="text/javascript"> ... </script> tags as written into the PDF.
* NOTE: This is PDF-based JavaScript to be executed by the PDF viewer,
* not browser-based JavaScript executed by Dompdf.
*
* @var bool
*/
'enable_javascript' => true,
/**
* Enable remote file access
*
* If this setting is set to true, DOMPDF will access remote sites for
* images and CSS files as required.
*
* ==== IMPORTANT ====
* This can be a security risk, in particular in combination with isPhpEnabled and
* allowing remote html code to be passed to $dompdf = new DOMPDF(); $dompdf->load_html(...);
* This allows anonymous users to download legally doubtful internet content which on
* tracing back appears to being downloaded by your server, or allows malicious php code
* in remote html pages to be executed by your server with your account privileges.
*
* This setting may increase the risk of system exploit. Do not change
* this settings without understanding the consequences. Additional
* documentation is available on the dompdf wiki at:
* https://github.com/dompdf/dompdf/wiki
*
* @var bool
*/
'enable_remote' => false,
/**
* List of allowed remote hosts
*
* Each value of the array must be a valid hostname.
*
* This will be used to filter which resources can be loaded in combination with
* isRemoteEnabled. If enable_remote is FALSE, then this will have no effect.
*
* Leave to NULL to allow any remote host.
*
* @var array|null
*/
'allowed_remote_hosts' => null,
/**
* A ratio applied to the fonts height to be more like browsers' line height
*/
'font_height_ratio' => 1.1,
/**
* Use the HTML5 Lib parser
*
* @deprecated This feature is now always on in dompdf 2.x
*
* @var bool
*/
'enable_html5_parser' => true,
],
];

View File

@ -6,8 +6,8 @@
<div class="col-12">
<div class="card">
<div class="card-header">
<a href="#" class="btn btn-success"><i class="fas fa-file-excel"></i>Unduh Excel</a>
<a href="#" class="btn btn-danger"><i class="fas fa-file-pdf"></i>Unduh PDF</a>
<a href="{{ route('registrasi.excel.export') }}" class="btn btn-success"><i class="fas fa-file-excel"></i>Unduh Excel</a>
<a href="{{ route('registrasi.generate_pdf') }}" class="btn btn-danger"><i class="fas fa-file-pdf"></i>Unduh PDF</a>
<button type="button" class="btn btn-primary float-right" data-toggle="modal" data-target="#modal-add">Registrasi</button>
</div>
<!-- /.card-header -->

View File

@ -0,0 +1,111 @@
<!DOCTYPE html>
<html>
<head>
<title>Data Registrasi Pasien</title>
<style>
/* Gaya tabel */
table {
border-collapse: collapse;
width: 100%;
}
/* Gaya sel header */
th {
border-bottom: 1px solid black;
text-align: left;
padding: 5px;
}
/* Gaya sel data */
td {
border-bottom: 1px solid black;
padding: 5px;
}
/* Gaya untuk border dalam horizontal */
tr:nth-child(even) td {
border-top: 1px solid black;
}
thead{
background-color: silver;
}
/* Gaya untuk judul tabel */
.table-title {
text-align: center;
font-size: 24px;
/* font-weight: bold; */
/* padding: 10px; */
}
/* posisi text laporan yg dibawah kanan tengah */
.center-right {
text-align: right;
padding-left: 60%;
}
.text-center {
text-align: center;
}
.logo-container {
text-align: center;
}
.logo {
width: 90%;
margin: 0 auto;
}
</style>
</head>
<body>
<p class="table-title">DATA REGISTRASI PASIEN</p>
<table>
<thead>
<tr>
<th>No</th>
<th>Tgl Registrasi</th>
<th>Nama Pasien</th>
<th>Tgl Lahir</th>
<th>Jenis Kelamin</th>
<th>Asuransi</th>
<th>Ruang Pelayanan</th>
<th>Pegawai</th>
</tr>
</thead>
<tbody>
@php
$no = 1;
@endphp
@foreach ($registrasi as $data)
<tr>
<td>{{ $no++ }}</td>
<td>{{ date('d/m/Y', strtotime($data->tgl_registrasi)) }}</td>
<td>{{ $data->pasien->nama }}</td>
<td>{{ $data->pasien->tgl_lahir }}</td>
<td>
@if ($data->pasien->jenis_kelamin === "male")
Laki-laki
@else
Perempuan
@endif
</td>
<td>{{ $data->asuransi->nama ?? null }}</td>
<td>{{ $data->ruangPelayanan->nama}}</td>
<td>{{ $data->pegawai->nama }}</td>
</tr>
@endforeach
</tbody>
</table>
<div class="center-right">
<div class="text-center">
@php
$tanggal = \Carbon\Carbon::now();
@endphp
<p>Jakarta, {{ $tanggal->locale('id')->isoFormat('dddd D MMMM YYYY') }}</p>
</div>
</div>
</body>
</html>

View File

@ -35,6 +35,8 @@ Route::middleware('auth:pegawai')->group(function () {
Route::get('/registrasi', [RegistrasiController::class, 'index'])->name('registrasi.index');
Route::post('/registrasi', [RegistrasiController::class, 'store'])->name('registrasi.store');
Route::get('/registrasi/excel/export/', [RegistrasiController::class, 'excelExport'])->name('registrasi.excel.export');
Route::get('/registrasi/generate_pdf', [RegistrasiController::class, 'generatePdf'])->name('registrasi.generate_pdf');
// Pasien
Route::get('/pasien', [PasienController::class, 'index'])->name('pasien.index');