<div class="row-fluid">
    <div class="span12">


        <?php if($titular->num_rows() > 0){ ?>

        <?php echo anchor('medico/expedienteExcel/'.$cvepaciente, '<i class="icon-save"></i>Excel', array('class' => 'btn btn-success btn-app'));?> 

        <h1>Información del paciente</h1>
        <table id="titulares-table" class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th>#</th>
                    <th>Clave Paciente</th>
                    <th>Dependencia</th>
                    <th>Tipo</th>
                    <th>Nombre</th>
                    <th>Paterno</th>
                    <th>Materno</th>
                    <th>Edad</th> 
                    <th>Genero</th>
                    <th>Cobertura</th>
                </tr>
            </thead>
            <tbody>
                <?php 
                
                $num=0;
                
                foreach($titular->result() as $row){

                    $cvepaciente = $row->cvepaciente;
                    $pat = $row->apaterno;
                    $mat = $row->amaterno;
                    $nombre = $row->nombre;
                    $sexo = $row->sexo;
                    $edad = $row->edad;
                    $idprograma = $row->idprograma;
                    $num++;    

                    
                    ?>
                    <tr>
                        <td><?php echo $num; ?></td>
                        <td><?php echo $row->cvepaciente; ?></td>
                        <td><?php echo $row->dependencia; ?></td>
                        <td><?php echo $row->titular; ?></td>
                        <td><?php echo $row->nombre; ?></td>
                        <td><?php echo $row->apaterno; ?></td>
                        <td><?php echo $row->amaterno; ?></td>
                        <td><?php echo $row->edad; ?></td>
                        <td><?php echo $row->genero; ?></td>
                        <td><?php echo $row->programa; ?></td>

                    </tr>
                    
                    
                    <?php 

                } 
                
                ?>
            </tbody>
        </table>


        <div class="row-fluid">
            <div class="span6">
                <h2>Ingresa tus anotaciones para su expediente.</h2>


                <?php

                echo MY_form_open('medico/insert_expediente');

                ?>
                <input type="hidden" name="cvepaciente" id="cvepaciente" value="<?php echo $cvepaciente; ?>">

                <table class="table">
                    <tr>
                        <td>Observaciones: </td>
                        <td><textarea class="span12" name="observaciones" id="observaciones" rows="8" cols="250" required="required"></textarea></td>
                    </tr>
                    <tr>
                        <td>Diagnostico: </td>
                        <td><input class="span12" type="text" name="dx" id="dx" required="required"></td>
                    </tr>
                </table>

                <?php
                echo MY_form_submit();
                echo form_close();
                ?>

            </div>

            <div class="span6">
                <h2>Enfermedades cronicas presentes</h2>

                <?php 

                foreach($cronicas->result() as $c){

                    if($c->presente == 1)
                    {
                        $checked = 'checked';
                    }else{
                        $checked = null;
                    }

                    ?>
                    <input class="span1 cronica" type="checkbox" name="cronica_<?php echo $c->cronica_id; ?>" value="<?php echo $c->cronica_id; ?>" data-cvepaciente="<?php echo $cvepaciente; ?>" <?php echo $checked; ?> /> <?php echo $c->cronica; ?><br />
                    <?php } ?>
            </div>
        </div>

        <?php }     ?>


        <table id="ventas-table" class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th>#</th>
                    <th>Fecha</th>
                    <th>Clave Paciente</th>
                    <th>Observaciones</th>
                    <th>Diagnostico</th>
                    <th>Medico</th>
                </tr>
            </thead>
            <tbody>
                <?php 

                $num=0;

                foreach($query->result() as $row){
                    $num++;    


                    ?>
                    <tr>
                        <td><?php echo $num; ?></td>
                        <td><?php echo $row->expediente_created; ?></td>
                        <td><?php echo $row->cvepaciente; ?></td>
                        <td><?php echo $row->observaciones; ?></td>
                        <td><?php echo $row->dx; ?></td>
                        <td><?php echo $row->nombremedico; ?></td>
                    </tr>


                    <?php 

                } 

                ?>
            </tbody>
        </table>


        <h3>Recetas emitidas</h3>

        <table id="ventas-table" class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th>#</th>
                    <th>Folio Receta</th>
                    <th>Unidad</th>
                    <th>Nombre de unidad</th>
                    <th>Clave Medico</th>
                    <th>Nombre Medico</th>                    
                    <th>Fecha Consulta</th>
                    <th>Cobertura</th>
                    <th>Imprimir</th>
                </tr>
            </thead>
            <tbody>
                <?php 

                $num=0;

                foreach($recetas->result() as $row){
                    $num++;    


                    ?>
                    <tr>
                        <td><?php echo $num; ?></td>
                        <td><?php echo $row->recetaID; ?></td>
                        <td><?php echo $row->clvsucursal; ?></td>
                        <td><?php echo $row->descsucursal; ?></td>
                        <td><?php echo $row->cvemedico; ?></td>
                        <td><?php echo $row->nombremedico; ?></td>
                        <td><?php echo $row->fecha; ?></td>
                        <td><?php echo $row->programa; ?></td>
                        <td><?php if($row->surtida == 0){ echo anchor('medico/imprimeReceta/'.$row->recetaID, 'Imprimir', array('target' => '_blank')); } ?></td>

                    </tr>


                    <?php 

                } 

                ?>
            </tbody>
        </table>

    </div>
</div>
