<?php

include ("header.php");

$sql="SELECT * FROM `pacientes` WHERE pac_activo = 1";

$resultado = mysqli_query($mysqli, $sql);

?>



        <div class="content-wrapper">

            <!-- START PAGE CONTENT-->

            <div class="page-heading">

                <h1 class="page-title">Expediente Clinico</h1>

            </div>

            <div class="page-content fade-in-up">

                <div class="ibox">

                    <div class="ibox-head">

                        <div class="ibox-title">Listado</div>

                    </div>

                    <div class="ibox-body">

                        <table class="table table-striped table-bordered table-hover" id="dataTablePacientes" cellspacing="0" width="100%">

                            <thead>

                                <tr>

                                        <th> NOMBRE </th>

                                        <th> TELEFONO </th>

                                        <th> CELULAR </th>

                                        <th> ULTIMA CONSULTA</th>

                                        <th>NOTA</th>

                                        <th>EXP</th>

                                        <th>EST</th>

                                    </tr>

                            </thead>

                                <tbody>          

                                    <?php $NUM=0;while($row = mysqli_fetch_array($resultado)) {

                                        $exp_pac_id=$row['pac_id'];

                                        $sqlexp = "SELECT * FROM `expediente`,pacientes WHERE `exp_pac_id`=pac_id and exp_pac_id = $exp_pac_id order by `exp_id` desc limit 1";

                                        $resultexp = $mysqli->query($sqlexp); 

                                        $rowexp = $resultexp->fetch_assoc();

                                        $ultima=$rowexp['exp_fecha'];

                                        if(!empty($rowexp['exp_fecha']))

                                        {

                                        ?>

                                    <tr>

                                        <td><?php echo $row['pac_nombre']; ?></td>

                                        <td><?php echo $row['pac_telefono']; ?></td>

                                        <td><?php echo $row['pac_celular']; ?></td>

                                        <td> <?php echo $ultima; ?></td>									

                                        <td> <a href="tiponota.php?id=<?php echo $row['pac_id']; ?>"><div class="icon-item"><i class="fa fa-file-text-o"></i></div></a> </td>

                                        <td> <a href="rexpediente.php?id=<?php echo $row['pac_id']; ?>"><div class="icon-item"><i class="fa fa-folder-open-o" aria-hidden="true"></i></div></a> </td>

                                        <td> <a href="estudios.php?id=<?php echo $row['pac_id']; ?>"><div class="icon-item"><i class="fa fa-file-pdf-o" aria-hidden="true"></i></div></a> </td>



                                    </tr>

                                    <?php }} ?>

                                </tbody>

                        </table>

                </div>

            </div>                

<?php 

    include ('footer.php');

?>