<?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,
 d.FirstName, d.LastName 
    FROM Cases C join Patient P on c.PatientCode = P.PatientCode join [Activity Drugs] a on a.[Case ID] = c.[Case ID]
    join CaseAdmin ca on ca.[Case ID] = c.[Case ID] 
    Join Doctor d on d.DoctorID = ca.DoctorID
    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 'Umur : '. $thn . ' th ' . $bln . ' bulan ' . $tgl . ' hari';
                    }
                    ?>
            </b></td>
            <td align="right" style="width:100px;">
            <b style="font-size:7px;"><?= $dList['FirstName'].''. $dList['LastName']; ?></b>
            </td>
        </tr>
    </table>
    <hr style="  border: none;
    border-top: 1px dotted #f00;
    color: #000;
    background-color: #fff;
    height: 1px;
    width: 50%;"><br>
     <table align="center" style="margin-top: -12px;">
    <tr>
    <td align="center">
            <label style='font-size:10px;font-weight:bold;'><?= $daTa['Description'] ?></label>
    </td>
    <td align="right" style="width:32px;">
            <b style="font-size:9px;">Qty : <?= $daTa['Qty']; ?></b>
    </td>
    </tr>
        <tr>
            <td align="center" style="margin-top: 2px;"><label style='font-size:11px'><?= $daTa['Dosis'].''.$daTa['Unit'] ?></label></td>
        </tr>
        <tr>
            <td align="center"><label style='font-size:10px'><?= $daTa['Cara'] ?></label></td>
        </tr>
        <tr>
            <td align="center">
                <label style='font-size:11px'><?= $daTa['Ket'] ?></label>
            </td>
        </tr>
        <tr>
        <td align="center">
                <label style='font-size:10px'><?= $daTa['Indikasi'] ?></label>
            </td>
        </tr>
        <tr>
            <td align="center">
                <label style='font-size:6px'>~ SEMOGA LEKAS SEMBUH ~</label>
            </td>
        </tr>
    </table>
    <?php endforeach; ?>