<?php
foreach ($Obat as $daTa) :
?>
<?php
 $case = $this->uri->segment(4);
 $dList = $this->db->query("
 SELECT C.[Case ID] AS ID, C.PatientCode AS MR, C.Description AS Nama, C.[Intake Date] AS Kunjungan , P.DOB AS TTL,a.DateCreated 
    FROM Cases C join Patient P on c.PatientCode = P.PatientCode join [Activity Drugs] a on a.[Case ID] = c.[Case ID]
    where c.[Case ID] = '$case'
 ")->row_array();
 $tgll = date('Y-m-d', strtotime(@$dList['TTL']));
 $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;
 ?>

<table>
        <tr>
            <td> <b style="font-size:7px;"><?= $dList['DateCreated']; ?></b></td>
        </tr>
        <tr>
            <td align="center" width="20px"> <b style="font-size:7px;">Nama : <?= $dList['Nama']; ?></b></td>
            <td align="right" style="width:32px;">
            <b style="font-size:7px;">(<?= $dList['MR']; ?>)</b>
        </td>
        </tr>
    </table>
    
    <table>
        <tr>
            <td> <b style="font-size:7px;">
                    <?php
                    if ($dList['TTL'] == '') {
                    } else {
                        echo $thn . ' th ' . $bln . ' bulan ' . $tgl . ' hari';
                    }
                    ?>
            </b></td>
        </tr>
    </table>
    <hr style="  border: none;
    border-top: 1px dotted #f00;
    color: #000;
    background-color: #fff;
    height: 1px;
    width: 50%;">
     <table align="center">
    <tr>
    <td align="center">
            <label style='font-size:9px;font-weight:bold;'><?= $daTa['Description'] ?></label>
    </td>
    </tr>
        <tr>
            <td align="center"><label style='font-size:9px'><?= $daTa['Dosis'] ?></label></td>
        </tr>
        <tr>
            <td align="center"><label style='font-size:9px'><?= $daTa['Cara'] ?></label></td>
        </tr>
        <tr>
            <td align="center">
                <label style='font-size:5px'><?= $daTa['Ket'] ?></label>
            </td>
        </tr>
        <tr>
        <td align="center">
                <label style='font-size:5px'><?= $daTa['Indikasi'] ?></label>
            </td>
        </tr>
        <tr>
            <td align="center">
                <label style='font-size:6px'>~ SEMOGA LEKAS SEMBUH ~</label>
            </td>
        </tr>
    </table>
    <br>
    <?php endforeach; ?>