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


 
 ?>

 
 
<a href="#add_consultation" class="btn btn-success" data-toggle="modal"><i class="fa fa-plus" aria-hidden="true"></i> <span>Ajouter Consultation</span></a>


 </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:10%">N° Dossier </th>
                                           <th >Nom patient</th>
                                           <th >Motif</th>
                                           <th >Date</th>

                                           <th > Actions</th>
                                       </tr>
                                    </thead>

                                    <tbody>

       <?php
      
       $req_sql="SELECT *  FROM patients as p, consultations as c where c.id_patient=p.id and c.id_patient ";
     
       $query_consult=mysqli_query($con,$req_sql);

         while ($row_consult = mysqli_fetch_array($query_consult) ) {  ?>
         <tr>
          <td > <?php echo $row_consult['id_patient']; ?> </td>
          <td > <?php echo $row_consult['nom']." ".$row_consult['prenom']; ; ?> </td>
          <td > <?php echo $row_consult['motif']; ?> </td>
          <td > <?php $date=date_create($row_consult['date_creation']);  echo date_format($date,"d/m/Y H:i"); ?> </td>
          
      
          <td>
           <button type="button" class="btn btn-info btn-xs" data-toggle="modal"  data-target="#affiche<?php echo  $row_consult['id'];?>">Afficher</button>
             <button type="button" class="btn btn-warning btn-xs" data-toggle="modal"  data-target="#edit_consultation<?php echo  $row_consult['id'];?>">Modifier c</button>
               <a href="index.php?p=ordonnances&id_consult=<?php echo $row_consult['id'];?>" class="btn btn-success btn-xs"> Ordonnances</a>
             
         <button type="button" class="btn btn-danger btn-xs sup_consult"  data="<?php echo $row_consult['id'];?>" >Supprimer</button>
         <div class="modal fade" id="affiche<?php echo $row_consult['id'];?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Consultation  "<?php echo $row_consult["nom"]." ".$row_consult["prenom"];  ?> "</h4>
      </div>
      <div class="modal-body">
      <table class="table table-striped table-bordered table-hover" >
             <tr><th>Nom et prenom</th> <td > <?php echo $row_consult["nom"]." ".$row_consult["prenom"]; ?></td></tr>
             <tr><th>Motif </th> <td > <?php echo $row_consult["motif"]; ?></td></tr>
             <tr><th>Poids </th> <td > <?php echo $row_consult["poids"]; ?></td></tr>
             <tr><th>Taille </th> <td > <?php echo $row_consult["taille"]; ?></td></tr>
             <tr><th>Temperature </th> <td > <?php echo $row_consult["temperature"]; ?></td></tr>
             <tr><th>Frequence cardiaque </th> <td > <?php echo $row_consult["frequence_cardiaque"]; ?></td></tr>
             <tr><th>Glycemie </th> <td > <?php echo $row_consult["glycemie"]; ?></td></tr>
             <tr><th>Diagnostic medical </th> <td > <?php echo $row_consult["diagnostic_medical"]; ?></td></tr>



              <tr><th>date d'ajout </th> <td > <?php $date=date_create($row_consult['date_creation']);  echo date_format($date,"d/m/Y H:i"); ?></td></tr>
    

      </table>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
      </div>
    </div>
  </div>
</div>

          <!-----------------------add consultation modal -------------------------------------------------------------------->
          <!-----------------------add consultation modal -------------------------------------------------------------------->
<div id="add_consultation" class="modal fade popup-inzerat" tabindex="-1" role="dialog" aria-labelledby="add_consultation" aria-hidden="true">
    
                     <div class="modal-dialog">
                     <div class="modal-content">
                      <form id="add_consultation"  method="" class="form-horizontal" action=""  enctype="multipart/form-data">
                       <div class="modal-header">      
                        <h4 class="modal-title">Ajouter Consultation</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                       </div>
                       <div class="modal-body">     
                        <div class="form-group modalForm">
                         
                   
                      <div class="col-sm-12 col-xs-12">
                      <label>patients</label>
                           <select name="id_patient" class="form-control" disabled>
                          <option value="<?php echo $row_consult['id_patient']?>"><?php echo $row_consult['nom']." ".$row_consult['prenom']; ?></option>                    
                           </select>
                      </div>
                     
                      <div class="col-sm-12 col-xs-12">
                      <label>Motif </label>
                       <input type="text"  required="required"  class="form-control"  id="motif" name="motif">
                      
                      </div>
                     <div class="col-sm-12 col-xs-12">
                      <label>Poids</label>
                      <input  type="number" step="any" required="required"  class="form-control"  id="poids" name="poids">
                      </div>
                       <div class="col-sm-12 col-xs-12">
                      <label>Taille</label>
                      <input type="number" step="any" required="required"  class="form-control"  id="taille" name="taille">
                      </div> 
                       <div class="col-sm-4 col-xs-12">
                      <label>Périmètre crânien </label>
                      <input type="number" step="any" required="required"  class="form-control"  id="perimetre_cranien" name="perimetre_cranien">
                      </div> 
                        <div class="col-sm-12 col-xs-12">
                      <label>temperature</label>
                      <input type="number" step="any" required="required"  class="form-control"  id="temperature" name="temperature">
                      </div>                    
                       <div class="col-sm-12 col-xs-12">
                      <label>Frequence Cardiaque</label>
                      <input type="number" step="any" required="required"  class="form-control"  id="frequence_cardiaque" name="frequence_cardiaque">
                      </div>                      
                        <div class="col-sm-12 col-xs-12">
                      <label>Glycemie</label>
                      <input type="number" step="any" required="required"  class="form-control"  id="glycemie" name="glycemie">
                      </div>
                        <div class="col-sm-12 col-xs-12">
                      <label>Diagnostic Medical</label>
                      <textarea class="form-control"  id="diagnostic_medical" name="diagnostic_medical"></textarea>
                      </div>
                      </div>                     
                   </div>
                       <div class="modal-footer">
                        <input type="hidden" id="id_patient" name="id_patient" value="<?php echo $row_consult['id_patient']; ?>"> 
                        <input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
                        <input type="submit" class="btn btn-success " data-dismiss="modal" id="ajouterConsultation" value="Ajouter">

                             <div class="input-group message col-sm-6" id="mes">
      
                       </div>
                      </form>
                     </div>
                    </div>
    </div>
     </div>
    <!--------------------end  add consultation modal -------------------------------------------------------------------->

    <div id="edit_consultation<?php echo $row_consult['id'];?>" class="modal fade popup-inzerat" tabindex="-1" role="dialog" aria-labelledby="edit_consultation" aria-hidden="true">
                     <div class="modal-dialog">
                     <div class="modal-content">
                      <form id="edit_consultation"  method="" class="form-horizontal" action=""  enctype="multipart/form-data">
                      
                    
                       <div class="modal-header">      
                        <h4 class="modal-title">Modifier Consultation <?php echo $row_consult['nom']." ".$row_consult['prenom']; ?></h4>
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                       </div>
                       <div class="modal-body">     
                        <div class="form-group modalForm">
                         
                   
                      <div class="col-sm-12 col-xs-12">
                      <label>patient</label>
                           <select  class="id_patient" name="id_patient" class="form-control" disabled>
                          <option value="<?php echo $row_consult['id_patient']?>"><?php echo $row_consult['nom']." ".$row_consult['prenom']; ?></option>                    
                           </select>
                      </div>
                     
                      <div class="col-sm-12 col-xs-12">
                      <label>Motif </label>
                     <input type="text"  required="required"  class="form-control"  id="motif" name="motif" value="<?php echo $row_consult['motif'] ?>">
                      </div>
                     <div class="col-sm-12 col-xs-12">
                      <label>Poids</label>
                      <input  type="number" step="any" required="required"  class="form-control poids"  class="poids" name="poids" value="<?php echo $row_consult['poids'] ?>">
                      </div>
                       <div class="col-sm-12 col-xs-12">
                      <label>Taille</label>
                      <input type="number" step="any" required="required"  class="form-control taille"   name="taille" value="<?php echo $row_consult['taille'] ?>">
                      </div>                
                        <div class="col-sm-12 col-xs-12">
                      <label>temperature</label>
                      <input type="number" step="any" required="required"  class="form-control temperature"  class="temperature" name="temperature" value="<?php echo $row_consult['temperature'] ?>">
                      </div>                    
                       <div class="col-sm-12 col-xs-12">
                      <label>Frequence Cardiaque</label>
                      <input type="number" step="any" required="required"  class="form-control frequence_cardiaque"   name="frequence_cardiaque" value="<?php echo $row_consult['frequence_cardiaque'] ?>">
                      </div>                      
                        <div class="col-sm-12 col-xs-12">
                      <label>Glycemie</label>
                      <input type="number" step="any" required="required"  class="form-control glycemie"   name="glycemie" value="<?php echo $row_consult['glycemie'] ?>">
                      </div>
                        <div class="col-sm-12 col-xs-12">
                      <label>Diagnostic Medical</label>
                      <textarea class="form-control diagnostic_medical"   name="diagnostic_medical"> <?php echo $row_consult['diagnostic_medical'] ?></textarea>
                      </div>
                      </div>                     
                   </div>
                       <div class="modal-footer">
                        <input type="hidden" class="id_patient" name="id_patient" value="<?php echo $row_consult['id_patient']; ?>"> 
                         <input type="hidden" class="id" name="id" value="<?php echo $row_consult['id']; ?>"> 
                        <input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
                        <input type="submit" class="btn btn-success " data-dismiss="modal" id="editConsultation" value="Modifier">

                             <div class="input-group message col-sm-6" class="mes">
      
                       </div>
                      </form>
                     </div>
                    </div>
   
    <!--------------------end  add consultation modal -------------------------------------------------------------------->



 </td>

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

  function fetch_data()  
    {  
        var id_patient= $("#id_patient").val();
        $.ajax({  
            url:"actions/fonct.php",  
            method:"POST",  
            data:{"id_doc":id_doc},
            success:function(data){  
        $('.table_auteurs ').html(data);  
            }  
        });  
    }

   // fetch_data();



    $("#ajouterConsultation").click(function(){
            var id_patient= $("#id_patient").val();  
            var motif= $("#motif").val(); 
               var poids= $("#poids").val(); 
               var taille= $("#taille").val(); 
               var temperature= $("#temperature").val(); 

               var frequence_cardiaque= $("#frequence_cardiaque").val(); 
               var glycemie= $("#glycemie").val(); 
               var diagnostic_medical= $("#diagnostic_medical").val(); 
              
                 $.ajax({  
                     url:"actions/consultation/ajouter.php",  
                     method:"POST", 

                     data:{
                      "id_patient":id_patient,
                    "motif":motif,
                     "poids":poids,
                      "taille":taille,
                    "temperature":temperature,
                     "frequence_cardiaque":frequence_cardiaque,
                      "glycemie":glycemie,
                    "diagnostic_medical":diagnostic_medical
                     
                    },  
                     success:function(data)  
                     {  $("#ajouterConsultation")[0].reset();
                           setTimeout(function() {
                        location.reload();
                      }, 2000);
                           
                          /*fetch_data();*/
            
        }
      });
    }); 

/****************edit consultation modal *************************/

 $("#editConsultation").click(function(){
            var id= $(".id").val(); 
            var id_patient= $(".id_patient").val();  
            var motif= $(".motif").val(); 

           
               var poids= $(".poids").val(); 
               var taille= $(".taille").val(); 
               var temperature= $(".temperature").val(); 

               var frequence_cardiaque= $(".frequence_cardiaque").val(); 
               var glycemie= $(".glycemie").val(); 
               var diagnostic_medical= $(".diagnostic_medical").val(); 
              
                 $.ajax({  
                     url:"actions/consultation/modifier.php",  
                     method:"POST", 
                     data:{
                      "id":id,
                      "id_patient":id_patient,
                      "motif":motif,
                     "poids":poids,
                      "taille":taille,
                    "temperature":temperature,
                     "frequence_cardiaque":frequence_cardiaque,
                      "glycemie":glycemie,
                    "diagnostic_medical":diagnostic_medical   
                    },  
                     success:function(data) 
                     { 
                     setTimeout(function() {
              location.reload();
               }, 2000);//$("#editConsultation")[0].reset();
                     
                    /*fetch_data();*/
            
        }
      });
    }); 





$(".sup_consult").click(function ()
{   var id = $(this).attr('data');
 //var current_url = window.location.href;
 alert('current_url'+current_url);



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_consult&id="+id,function()
    {   
       setTimeout(function() {
             location.reload();
               }, 2000);
    });

    swal(

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


  }
})

});

 $(".liste_ordonnance").click(function ()
{   var id_consult =  $(this).attr('data');
$.get("actions/ordonnance/liste.php?id_consult="+id_consult);
});

$(".act_user").click(function ()
{   var id = $(this).attr('id');
$.get("actions/fonctions.php?type=act_user&id="+id,function()
    {    location.reload();
    });
});


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