<?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%;">
       <table align="center">
    <tr>
    <td align="center">
            <label style='font-size:11px;font-weight:bold;'>(RACIKAN) <?= $Racik['NamaRacikan'] ?></label>
    </td>
    <td align="right" style="width:32px;">
            <b style="font-size:9px;">Qty : <?= $daTa['Qty']; ?></b>
    </td>
    </tr>
        <tr>
            <td align="center"><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>