<?php
if(!empty($_SESSION['user_connect_id']))
{
    
      
 if(isset($_GET['id_consult'])){


      $id_consult=$_GET['id_consult'];
 $req_sql_pat="SELECT *  FROM patients as p,consultations as c  where p.id=c.id_patient and  c.id='$id_consult' ";
     
       $query_pat=mysqli_query($con,$req_sql_pat);
        $row_pat = mysqli_fetch_array($query_pat);
 ?>

 <div class="head-content col-sm-12">
   <div class="col-sm-1">
    <input type="button"  class="btn btn-sm btn-primary btn-block" value="Retour" onclick="history.go(-1)" >
    </div>
   <div class="col-sm-11">                       
<a href="index.php?p=add_bilan&id_consult=<?php echo $id_consult;?>"  class="btn btn-sm btn-success pull-right">Ajouter Bilan</a> 
  </div>
 </div>

 <h4 class="title"><i class="fa fa-users"></i> Liste des bilans du patient "<span class="title-name"><?php echo $row_pat['nom']." ".$row_pat['prenom']; ?><span>"
 </h4>

        <div class="row">
          <div class="col-lg-12">
                  <div class="form-panel">
                    <table id="dataTables" class="table table-striped table-bordered table-hover">
                                    <thead>
                                        <tr> 
                                           <th style="width: 3%;">N° </th>
                                           <th >Nom patient</th>
                                           <th >Type Consultation</th>
                                           <th >Date</th>

                                           <th style=""> Actions</th>
                                       </tr>
                                    </thead>

                                    <tbody>

       <?php
      
   
         $req_sql_ord= "SELECT *,o.id_bilan,o.date_creation FROM bilans as o,consultations as c, consultation_bilan as co  
         WHERE o.id_bilan=co.id_bilan and  c.id=co.id_consult and c.id='$id_consult' ORDER BY  o.date_creation DESC"; 
        $result_bilan= mysqli_query($con,$req_sql_ord);


         while ($row_bilan = mysqli_fetch_array($result_bilan) ) {  ?>
         <tr>
         <td > <?php echo  $row_pat['id_patient']  ?> </td>
          <td > <?php echo $row_pat['nom']." ".$row_pat['prenom']; ?> </td>
          <td > <?php echo $row_bilan['type_consult'] ; ?> </td>
        
          <td > <?php $date=date_create($row_bilan['date_creation']);  echo date_format($date,"d/m/Y H:i"); ?> </td>
          <td>
<a href="pages/bilan/bilan.php?id_bilan=<?php echo $row_bilan['id_bilan'];?>&id_patient=<?php echo $row_pat['id_patient'] ;?>" class="btn btn-info btn-xs">Print</a>
       


 <button type="button" class="btn btn-danger btn-xs sup_bilan"  data="<?php echo $row_bilan['id_bilan'];?>" >Supprimer</button>


               

     

       

 </td>

          </tr>
          <?php  } ?>
     </tbody>
     </table>
                  </div>
          </div>
          </div>
<script type="text/javascript">
 $(document).ready(function() {
  $("#g_patient").addClass("active");
 document.title = 'Liste des Bilans ';

 $(".add_ord").click(function ()
{   var id_consult = $(this).attr('data');
$.get("actions/ordonnance/ajouter.php?id_consult="+id_consult,function()
    {    location.reload();
    });
});









$(".sup_bilan").click(function ()
{   var id = $(this).attr('data');

swal({
  title: ' Voulez vous vraiment supprimer cet enregistrement ?',
  text: "Vous ne serez pas capable de revenir à cela!",
  type: 'warning',
  width: 600,
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Oui, supprimez-le !',
  cancelButtonText:  'Non'
}).then((result) => {
  if (result.value) {
//if click oui
$.get("actions/fonctions.php?type=sup_bilan&id="+id,function()
    {   
       setTimeout(function() {
              location.reload();
               }, 2000);
    });

    swal(

      'Supprimé !',
      'L\'enregistrement a été supprimé.',
      'success'
    ).then(function(){ 
   location.reload();
   })
  


  }
})

});




} );
      </script>
<?php }} ?>