<?php
if(!empty($_SESSION['user_connect_id']))
{  
 if(isset($_GET['id'])){
 $id_patient=$_GET['id'];
   $req_sql_pat="SELECT *  FROM patients as p where  p.id='$id_patient' ";
     
       $query_pat=mysqli_query($con,$req_sql_pat);
        $row_pat = mysqli_fetch_array($query_pat);
 
 ?>
<a href="#add_consultation"  class="btn btn-sm btn-success pull-right" 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:5%">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='$id_patient'  ORDER BY  c.date_creation DESC";}
     
       $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_c<?php echo  $row_consult['id'];?>">Modifier</button>
     <a href="index.php?p=ord_consult&id_consult=<?php echo $row_consult['id'];?>" class="btn btn-success btn-xs"> Ordonnances</a>
       <a href="index.php?p=bilan_consult&id_consult=<?php echo $row_consult['id'];?>" class="btn btn-primary btn-xs"> Bilans</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>

    <!--------------------end  add consultation modal -------------------------------------------------------------------->

<!-----------------------edit consultation modal -------------------------------------------------------------------->
  
    <div class="modal fade" id="edit_c<?php echo  $row_consult['id'];?>" tabindex="-1" role="dialog" aria-labelledby="edit_c" aria-hidden="true">

                     <div class="modal-dialog">
                     <div class="modal-content">
                      <form id="edit_c"  method="" class="form-horizontal" action=""  enctype="multipart/form-data">
                      
                    
                       <div class="modal-header">      
                        <h4 class="modal-title">Modifier Consultation <?php echo $row_pat['nom']." ".$row_pat['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>
                      <input  type="text"   class="form-control"   name="patient" value="<?php echo $row_consult['nom']." ".$row_consult['prenom']; ?>" disabled>
                           
                      </div>
                      <div class="col-sm-6 col-xs-12">
                      <label>Type </label>
                      <select name="type_consult" id="type_consult" class="form-control type_consult" >
                           <option value="<?php echo $row_consult['type_consult'] ?>"><?php echo $row_consult['type_consult']; ?></option>
                        <option value="Consultation">Consultation</option>
                         <option value="Controle">Controle</option>
                      </select>
                      </div>
                      <div class="col-sm-6 col-xs-12">
                      <label>Motif </label>
                      <input type="text"  required="required"  class="form-control motif"  id="motif" name="motif" value="<?php echo $row_consult['motif'] ?>">
                      </div>
                     <div class="col-sm-4 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-4 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-4 col-xs-12">
                      <label>Périmètre crânien </label>
                      <input type="number" step="any" required="required"  class="form-control perimetre_cranien"   name="perimetre_cranien" value="<?php echo $row_consult['perimetre_cranien'] ?>">
                      </div> 
                        <div class="col-sm-4 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-4 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-4 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" id="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>
   




 </td>

          </tr>
         



       

 <?php  } ?>
     </tbody>
     </table>

<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>Patient</label>
                      <input  type="text"   class="form-control"   name="patient" value="<?php echo $row_pat['nom']." ".$row_pat['prenom']; ?>" disabled>
                           
                      </div>
                     
                      <div class="col-sm-6 col-xs-12">
                      <label>Type </label>
                      <select name="type_consult" id="type_consult" class="form-control" >
                         <option value="0">Sélectionner le type</option> 
                        <option value="Consultation">Consultation</option>
                         <option value="Controle">Controle</option>
                      </select>
                      </div>
                        <div class="col-sm-6 col-xs-12">
                      <label>Motif </label>
                     <input type="text"  required="required"  class="form-control"  id="motif" name="motif">
                      </div>
                     <div class="col-sm-4 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-4 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-4 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-4 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-4 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">
                       
                        <div class="col-sm-12 col-xs-12">
                             <div class="col-sm-6 col-xs-12">
                        <input type="hidden"   class="form-control"  id="id_patient" name="id_patient" value="<?php echo $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>
                             <div class="input-group message col-sm-6" id="mes">
      
                       </div>
                      </form>
                     </div>
                    </div>
    </div>


     

     </div>
      </div>


                  </div>
          </div>
          </div>
<script type="text/javascript">
 $(document).ready(function() {
  $("#g_patient").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_patient":id_patient},
            success:function(data){  
        $('.table_auteurs ').html(data);  
            }  
        });  
    }





    $("#ajouterConsultation").click(function(){
            var id_patient= $("#id_patient").val();  
            var motif= $("#motif").val();          
            var type_consult= $("#type_consult").val();          
               var poids= $("#poids").val(); 
               var taille= $("#taille").val(); 
               var perimetre_cranien= $("#perimetre_cranien").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,
                    "type_consult":type_consult,
                     "poids":poids,
                      "taille":taille,
                      "perimetre_cranien":perimetre_cranien,
                    "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 type_consult= $(".type_consult").val();    
            var motif= $(".motif").val(); 

           
               var poids= $(".poids").val(); 
               var taille= $(".taille").val(); 
               var temperature= $(".temperature").val(); 
                 var perimetre_cranien= $(".perimetre_cranien").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,
                      
                       "type_consult":type_consult,
                      "motif":motif,
                     "poids":poids,
                      "taille":taille,
                    "temperature":temperature,
                     "perimetre_cranien":perimetre_cranien,
                     "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');

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();
   })
  


  }
})

});

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

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


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