<!DOCTYPE html>
<html>
<head>
<title><?= $judul; ?></title>

<style>
body{
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11pt;
    margin: 25px;
    color:#000;
}

h1,h2,h3{
    margin:4px 0;
}

.header{
    border-bottom:2px solid #000;
    padding-bottom:8px;
    margin-bottom:15px;
}

.section{
    margin-top:20px;
    page-break-inside: avoid;
}

.section-title{
    background:#e6e6e6;
    padding:6px 10px;
    font-weight:bold;
    border:1px solid #000;
}

.table{
    width:100%;
    border-collapse:collapse;
    margin-top:5px;
}

.table td,.table th{
    border:1px solid #000;
    padding:6px;
    vertical-align:top;
}

.table th{
    background:#f3f3f3;
    font-weight:bold;
}

.no-border td{
    border:none;
    padding:3px;
}

.label{
    width:220px;
    font-weight:bold;
}

.text-center{ text-align:center; }
.text-right{ text-align:right; }

@media print{
    body{ margin:20px; }
    .section{ page-break-inside: avoid; }
}
</style>

<script>
window.onload = function(){
    window.print();
    setTimeout(window.close,500);
}
</script>

</head>
<body>

<!-- ================= HEADER ================= -->
<div class="header">
<table class="no-border" width="100%">
<tr>
<td width="90">
<img src="<?= base_url('images/logo2.png'); ?>" height="70">
</td>
<td>
<h2><?= $utama['NamaPerusahaan']; ?></h2>
<?= $utama['AlamatPerusahaan']; ?>
</td>
</tr>
</table>
</div>

<h2 align="center">REKAM MEDIS PASIEN</h2>

<!-- ================= IDENTITAS ================= -->
<div class="section">
<div class="section-title">IDENTITAS PASIEN</div>
<table class="table">
<tr>
<td class="label">Case ID / MR</td>
<td><?= $pasien['Case ID'].' / '.$pasien['PatientCode']; ?></td>
<td class="label">Nama</td>
<td><?= $pasien['Description']; ?></td>
</tr>
<tr>
<td class="label">Jenis Kelamin</td>
<td><?= $pasien['Sex']==1?'Perempuan':'Laki-Laki'; ?></td>
<td class="label">Tanggal Lahir</td>
<td><?= date('d-m-Y',strtotime($pasien['DOB'])); ?></td>
</tr>
<tr>
<td class="label">Umur</td>
<td colspan="3">
<?php
$tgl=new DateTime($pasien['DOB']);
$today=new DateTime();
$diff=$today->diff($tgl);
echo $diff->y.' Tahun '.$diff->m.' Bulan '.$diff->d.' Hari';
?>
</td>
</tr>
</table>
</div>

<!-- ================= TANDA VITAL ================= -->
<div class="section">
<div class="section-title">TANDA VITAL</div>
<table class="table text-center">
<tr>
<th>BB</th>
<th>TB</th>
<th>Suhu</th>
<th>Resp Rate</th>
<th>Heart Rate</th>
<th>Tensi</th>
<th>IMT</th>
<th>Nyeri</th>
</tr>
<tr>
<td><?= $pasien['BeratBadan']; ?></td>
<td><?= $pasien['TinggiBadan']; ?></td>
<td><?= $pasien['Suhu']; ?></td>
<td><?= $pasien['respRate']; ?></td>
<td><?= $pasien['heartRate']; ?></td>
<td><?= $pasien['Tensi'].'/'.$pasien['Diastole']; ?></td>
<td><?= $pasien['IMT']; ?></td>
<td><?= $pasien['tingkat_nyeri']; ?></td>
</tr>
</table>
</div>

<!-- ================= RIWAYAT ================= -->
<div class="section">
<div class="section-title">RIWAYAT PASIEN</div>
<table class="table">
<tr>
<td class="label">Pernah Dirawat</td>
<td><?= $pasien['pernahDirawat']; ?></td>
<td class="label">Sakit Yang Sama</td>
<td><?= $pasien['SakitYangSama']; ?></td>
</tr>
<tr>
<td class="label">Pernah Operasi</td>
<td><?= $pasien['Operasi']; ?></td>
<td class="label">Penyakit Keluarga</td>
<td><?= $pasien['PenyakitKeluarga']; ?></td>
</tr>
<tr>
<td class="label">Riwayat Obat</td>
<td><?= $pasien['RiwayatObatDiminum']; ?></td>
<td class="label">Psikososial</td>
<td><?= $pasien['Psikososial']; ?></td>
</tr>
<tr>
<td class="label">Spiritual</td>
<td colspan="3"><?= $pasien['Spiritual']; ?></td>
</tr>
</table>
</div>

<!-- ================= RISIKO JATUH ================= -->
<div class="section">
<div class="section-title">RISIKO JATUH</div>
<table class="table">
<tr>
<th>Cara Berjalan</th>
<th>Menopang Saat Duduk</th>
</tr>
<tr>
<td>
    <?= $pasien['resiko_a']; ?>
       <b>Cara Berjalan Pasien<br>
                    1. Tidak seimbang/Sempoyongan/limbung<br>
                    2. Jalan menggunakan alat bantu (keruk,tripot,kursi roda,oranglain)</b>
</td>
<td>
      <b> Menopang saat akan duduk : tampak memegang<br>
                    Pingggiran kursi atau meja / benda lain <br>
                    sebagai penopang saat akan duduk</b>
    <?= $pasien['resiko_b']; ?>
</td>
</tr>
<tr>
<td><b>Hasil Risiko</b><br><?= $pasien['hasilresiko']; ?></td>
<td><b>Tindakan</b><br><?= $pasien['tindakanresiko']; ?></td>
</tr>
</table>
</div>

<!-- ================= HASIL PEMERIKSAAN ================= -->
<?php if($countPemeriksaan>0): ?>
<div class="section">
<div class="section-title">HASIL PEMERIKSAAN</div>
<table classtable">
<tr><td class="label">Poli</td><td><?= $hasilpemeriksaan['poli']; ?></td></tr>
<tr><td class="label">Keluhan</td><td><?= $hasilpemeriksaan['keluhan_utama']; ?></td></tr>
<tr><td class="label">Pemeriksaan Fisik</td><td><?= $hasilpemeriksaan['pemeriksaan_fisik']; ?></td></tr>
<tr><td class="label">Diagnosa Primer</td><td><?= $hasilpemeriksaan['diagnosa_primer'].' ('.$hasilpemeriksaan['DESCRPTION'].')'; ?></td></tr>
<tr><td class="label">Diagnosa Sekunder</td><td><?= $hasilpemeriksaan['diagnosa_sekunder']; ?></td></tr>
<tr><td class="label">Rencana Tindakan</td><td><?= $hasilpemeriksaan['rencana_tindakan']; ?></td></tr>
<tr><td class="label">Tindak Lanjut</td><td><?= $hasilpemeriksaan['tindak_lanjut']; ?></td></tr>
<tr><td class="label">Catatan</td><td><?= $hasilpemeriksaan['catatan']; ?></td></tr>
<tr><td class="label">Alergi</td><td><?= $hasilpemeriksaan['alergi']; ?></td></tr>
</table>
</div>
<?php endif; ?>

<!-- ================= RESEP OBAT ================= -->
<?php if($countObat>0): ?>
<div class="section">
<div class="section-title">RESEP OBAT</div>
<table class="table text-center">
<tr>
<th>No</th>
<th>Nama Obat</th>
<th>Jumlah</th>
<th>Satuan</th>
<th>Dosis</th>
<th>Cara Pakai</th>
</tr>
<?php $no=1; foreach($hasilObat as $obat): ?>
<tr>
<td><?= $no++; ?></td>
<td><?= $obat['Obat']; ?></td>
<td><?= $obat['Jumlah']; ?></td>
<td><?= $obat['Satuan']; ?></td>
<td><?= $obat['Dosis']; ?></td>
<td><?= $obat['CaraPakai']; ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>

<!-- ================= CPPT ================= -->
<?php if($countcppt>0): ?>
<div class="section">
<div class="section-title">RIWAYAT CPPT</div>
<table c="lass="table">
<tr>
<th>Tanggal & Waktu</th>
<th>User</th>
<th>Deskripsi</th>
</tr>
<?php foreach($squery as $sd): ?>
<tr>
<td><?= date('d-m-Y',strtotime($sd['DateDetail'])).' '.date('H:i',strtotime($sd['TimeDetail'])); ?></td>
<td><?= $sd['UserCreated']; ?></td>
<td>
<?= $sd['Description']; ?><br>
<b>S:</b> <?= $sd['Subjek']; ?><br>
<b>O:</b> <?= $sd['Objek']; ?><br>
<b>A:</b> <?= $sd['Asesment']; ?><br>
<b>P:</b> <?= $sd['Penilaian']; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>

<!-- ================= TTD ================= -->
<br><br>
<table width="100%" class="no-border">
<tr>
<td width="60%"></td>
<td align="center">
<?= 'Jakarta'.', '.date("d-m-Y",strtotime($pasien['Intake Date'])); ?><br><br>
<img src="<?= $qr_dokter; ?>" width="90"><br><br><br>
<u><?= $pasien['doctorName']; ?></u>
</td>
</tr>
</table>

</body>
</html>
