<?php
date_default_timezone_set("Asia/Jakarta");
$caseID = $this->uri->segment(3);
$d = $this->db->query("Select * from Patient p join Cases c on p.PatientCode = c.PatientCode where c.[Case ID] = '$caseID' ")->row_array();
$tgll = date('Y-m-d', strtotime(@$d['DOB']));
$tanggal_lahir = new DateTime($tgll);
$sekarang = new DateTime("today");
if ($tanggal_lahir > $sekarang) {
    $thn = "0";
    $bln = "0";
    $tgl = "0";
}
$thn = $sekarang->diff($tanggal_lahir)->y;
$bln = $sekarang->diff($tanggal_lahir)->m;
$tgl = $sekarang->diff($tanggal_lahir)->d;
?>
    <section class="content">
        <div class="card" style="padding: 15px; background-color: white;border-radius: 5px;">
            <div class="card-body">
                <div class="row text-center">
                    <div class="col-md-2"></div>
                    <div class="col-md-2">
                        <img src="<?= base_url('images/logo.png'); ?>" height="80px">
                    </div>
                    <div class="col-md-6">
                        <h4 style="font-weight: bold;">
                            <?= $unit['NamaPerusahaan']; ?><br>
                            Resum Medis
                        </h4>
                    </div>
                    <div class="col-md-2"></div>
                </div>
                <div class="row text-center">
                    <div class="col-md-2"></div>
                    <div class="col-md-8">
                        <hr>
                    </div>
                    <div class="col-md-2"></div>
                </div>
                <table class="table table-striped table-hover" id="example1" style="border-collapse: collapse;text-align:left width:100%;">
                        <tr>
                            <td>No.MR</td>
                            <td>:</td>
                            <td><?= $d['PatientCode']; ?></td>
                        </tr>
                        <tr>
                            <td>No.Reg</td>
                            <td>:</td>
                            <td><?= $d['Case ID']; ?></td>
                        </tr>
                        <tr>
                            <td>Nama</td>
                            <td>:</td>
                            <td><?= $d['Description']; ?></td>
                        </tr>
                        <tr>
                            <td>Kunjungan</td>
                            <td>:</td>
                            <td><?= date('d-m-Y', strtotime($d['Intake Date'])); ?></td>
                        </tr>
                        <tr>
                            <td>Jenis Kelamin</td>
                            <td>:</td>
                            <?php
                            if ($d['Sex'] == 1) {
                                $Jenis = "Perempuan";
                            } else {
                                $Jenis = "Laki - Laki";
                            }
                            ?>
                            <td><?= $Jenis; ?></td>
                        </tr>
                        <tr>
                            <td>Tanggal Lahir</td>
                            <td>:</td>
                            <td>
                                <?php
                                if ($d['DOB'] == '') {
                                } else {
                                    echo date('d-m-Y', strtotime($d['DOB']));
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Umur</td>
                            <td>:</td>
                            <td><?= $thn . ' th ' . $bln . ' bulan ' . $tgl . ' hari'; ?></td>
                        </tr>
                        <tr>
                            <td>Alamat</td>
                            <td>:</td>
                            <td><?= $d['HomeAddress1']; ?></td>
                        </tr>
                    </table>
                    <hr><br>
                    <p style="text-align: center;"><b>RESUM MEDIS</b></p>
                    <table class="table table-striped" id="example1" style="border-collapse: collapse;text-align:left width:100%;">
                    <tr>
                        <td>Alasan Berobat</td>
                        <td>:</td>
                        <td><?=  $data['alasanberobat'];  ?></td>
                    </tr>
                    <tr>
                        <td>Diagnosa</td>
                        <td>:</td>
                        <td><?=  $data['diagnosa']; ?></td>
                    </tr>
                    <tr>
                        <td>Pemeriksaan Fisik *)</td>
                        <td>:</td>
                        <td><?=  $data['pemeriksaanfisik'];  ?></td>
                    </tr>
                    <tr>
                        <td>Terapi Yang Diberikan / Obat</td>
                        <td>:</td>
                        <td>
                        <?=  $data['terapi'];  ?>
                        </td>
                    </tr>
                    <tr>
                        <td>Pemeriksaan Penunjang *)</td>
                        <td>:</td>
                        <td><?=  $data['pemeriksaan'];  ?></td>
                    </tr>
                    <tr>
                        <td>Edukasi</td>
                        <td>:</td>
                        <td><?=  $data['edukasi'];  ?></td>
                    </tr>
                    <tr>
                        <td>Kontrol Kembali Tanggal</td>
                        <td>:</td>
                        <td><?=  $data['kontrol'];  ?></td>
                    </tr>
                    </table>
                    <table style="width: 100%;">
                    <tr> 
                        <td style="text-align: center; width:50%;"></td>
                        <td style="text-align: center; width:50%;"><p style="margin-top: 25px;">Dokter</p></td>
                    </tr>
                    <tr>
                    <td style="text-align: center; width:50%;"></td>
                        <td style="text-align: center; width:50%;"><br><br><br></td>
                    </tr>
                    <tr>
                        <td style="text-align: center; width:50%;"></td>
                        <td style="text-align: center; width:50%;"><p>(............................)</p></td>
                    </tr>
</table>
                    <br><br><br><br><br>
                    <label for=""><small style="aligen-text:right;"><i>*) Yang Dianggap Penting</i></small></label>
            </div>
        </div>
    </section>

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