102 lines
3.0 KiB
PHP
102 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
|
|
class PasienExport implements FromCollection, WithHeadings
|
|
{
|
|
protected $data;
|
|
protected $role;
|
|
|
|
public function __construct($data, $role)
|
|
{
|
|
$this->data = $data;
|
|
$this->role = $role;
|
|
}
|
|
|
|
public function collection()
|
|
{
|
|
if ($this->role === 'super_admin') {
|
|
|
|
return $this->data->map(function ($row) {
|
|
|
|
return [
|
|
'nama_lengkap' => $row->nama_lengkap,
|
|
'nik' => $row->nik,
|
|
'email' => $row->email,
|
|
'no_telp' => $row->no_telp,
|
|
'tgl_lahir' => $row->tgl_lahir,
|
|
'jenis_kelamin' => $row->jenis_kelamin,
|
|
'alamat' => $row->alamat,
|
|
'fasyankes' => $row->nama_fasyankes,
|
|
'diagnosa' => $row->diagnosa,
|
|
'jam_minum' => $row->jam_minum,
|
|
'status_kesehatan' => $row->status_kesehatan,
|
|
'tgl_mulai_pengobatan' => $row->tgl_mulai_pengobatan,
|
|
'tgl_estimasi_selesai' => $row->tgl_estimasi_selesai,
|
|
'jumlah_tidak_minum' => $row->jumlah_tidak_minum
|
|
];
|
|
});
|
|
|
|
}
|
|
|
|
// ROLE ADMIN BIASA
|
|
return $this->data->map(function ($row) {
|
|
|
|
return [
|
|
'nama_lengkap' => $row->nama_lengkap,
|
|
'nik' => $row->nik,
|
|
'no_telp' => $row->no_telp,
|
|
'tgl_lahir' => $row->tgl_lahir,
|
|
'jenis_kelamin' => $row->jenis_kelamin,
|
|
'alamat' => $row->alamat,
|
|
'diagnosa' => $row->diagnosa,
|
|
'jam_minum' => $row->jam_minum,
|
|
'status_kesehatan' => $row->status_kesehatan,
|
|
'tgl_mulai_pengobatan' => $row->tgl_mulai_pengobatan,
|
|
'tgl_estimasi_selesai' => $row->tgl_estimasi_selesai,
|
|
'jumlah_tidak_minum' => $row->jumlah_tidak_minum
|
|
];
|
|
});
|
|
}
|
|
|
|
public function headings(): array
|
|
{
|
|
if ($this->role === 'super_admin') {
|
|
|
|
return [
|
|
'Nama Lengkap',
|
|
'NIK',
|
|
'Email',
|
|
'No. Telp',
|
|
'Tanggal Lahir',
|
|
'Jenis Kelamin',
|
|
'Alamat',
|
|
'Fasyankes',
|
|
'Diagnosa',
|
|
'Jam Minum Obat',
|
|
'Status Kesehatan',
|
|
'Tanggal Mulai Pengobatan',
|
|
'Estimasi Selesai',
|
|
'Jumlah Hari Tidak Minum Obat'
|
|
];
|
|
}
|
|
|
|
return [
|
|
'Nama Lengkap',
|
|
'NIK',
|
|
'No. Telp',
|
|
'Tanggal Lahir',
|
|
'Jenis Kelamin',
|
|
'Alamat',
|
|
'Diagnosa',
|
|
'Jam Minum Obat',
|
|
'Status Kesehatan',
|
|
'Tanggal Mulai Pengobatan',
|
|
'Estimasi Selesai',
|
|
'Jumlah Hari Tidak Minum Obat'
|
|
];
|
|
}
|
|
} |