<?php
 $cc=0;
 
 
  require_once"labClass.php";

  $con=new labClass();
 
 if(isset($_POST["patientID"]) && isset($_POST["sdate"]))
 {
  $patientID=$_POST['patientID'];
  $sdate=$_POST['sdate'];
  $fn="";
  $mn="";
  $ln="";
  $gn="";
  $pAge="";
  $np=$con->getThisPatientD($patientID);
  if($np->rowCount()>0)
  {
  $pn=$np->fetch();

  $regdate=Date("Y-m-d");
  $pAge= date('Y',strtotime($regdate))-date('Y',strtotime($pn['dob']));
  $fn=$pn['fname'];
  $mn=$pn['mname'];
  $ln=$pn['lname'];
  $gn=$pn['gender'];
  }
  ?>  
  <div class="container-fluid " id="co">
    <img src="assets/phead.PNG" width="100%" height="80px">
  <small><h6>
    <?php echo $fn." ". $mn." ".$ln. "'s ";?>PATIENTS DIAGNOSIS RECORDS:</h6></small>
 <br><?php echo "Gender:" .$gn?><br> 
 <?php 
  echo "Age:". $pAge;
   ?> <br><?php echo "Patient ID:".$patientID;?><br> 
  <table class="table"><tr>
    <td align="right"> <button type="submit" class="btn btn-primary" style="width:88px; height:35px;" onclick="var sdate=$('#sdate').val(); var patientID=$('#pID').val();if (patientID!=''&& sdate!='') {$.post('pProfileDiagnosisAll.php',{sdate:sdate,patientID:patientID},function(data){$('#disp').html(data).show();});} else{document.getElementById('disp').innerHTML='System date required!..';}"> All visits</button></td></table>

<div class="container-fluid table-responsive" id="dpl" >

  <table class="table table-bordered">
  <thead class="bg-secondary">
   
      <th>  
        <small><h6>DATE OF VISIT</h6></small>
      </th>

      <th>  
        <small><h6>PATIENT VIEW</h6></small>
      </th>
      
      <th>  
        <small><h6>ROS</h6></small>
      </th>
      <th>  
        <small><h6>CODE DISEASE</h6></small>
      </th>
      <th>
        <small><h6>INVESTIGATION</h6></small>
      </th>
      
       
      <th>
        <small><h6>TREATMENT</h6></small>
      </th>
    </thead>
  <tbody>
   
  <?php
 $ttPrice=0;

 $rQ= $con->getCrrReports($patientID,$sdate);
 
 if ($rQ->rowCount()>0) {

  $chp=$rQ->fetchAll();
    
      
 foreach ($chp as $key => $p) 
 {
 
     
$dateB=$p['dateB'];
$cc++;  
        ?>


    <tr> 
       <td> 

         <?php echo $p['dateB'];?> 
       
      </td>
       <td> 
        <?php
          $Q= $con->getCompReports($patientID,$dateB);
           if ($Q->rowCount()>0) {
             $cp=$Q->fetchAll(); 
               ?> 
           <table class="table table-bordered">
                <th>  
                  <small style="font-weight:0.8em;">Complain</small>
                 </th>
                 <th> 
                  <small style="font-weight:0.8em;">hpi</small>
                 </th>
                 <th> 
                  <small style="font-weight:0.8em;">Examination</small>
                 </th>
              <?php    
               foreach ($cp as $key => $c) {
               
               ?>
             
                  
               
                 <tr>
                    <td> 
                      <?php echo $c['comlain'];?> 
                    </td>
                     <td> 
                        <?php echo $c['hpi'];?> 
                     </td>
                     <td> 
                        <?php echo $c['gExam'];?> 
                    </td>
                 </tr>
                

               <?php
             }
               ?> 
           </table>
              <?php
           }
         ?>          
       
      </td>
      <td> 
        <?php
          $Q= $con->getRosReports($patientID,$dateB);
           if ($Q->rowCount()>0) {
             $cp=$Q->fetchAll();
               ?> 
             <table class="table table-bordered">
                <th>  
                  <small style="font-weight:0.8em;">System</small>
                 </th>
                 <th> 
                  <small style="font-weight:0.8em;">Status</small>
                 </th>
              <?php     
               foreach ($cp as $key => $c) {
               
               ?>
              
                 <tr>
                    <td> 
                      <?php echo $c['ros'];?> 
                    </td>
                     <td> 
                        <?php echo $c['descrip'];?> 
                     </td>
                      
                 </tr>
              

               <?php
             }
             ?> 
           </table>
              <?php 
           }
         ?>          
       
      </td> 
       <td> 
        <?php
          $Q= $con->getCodeReports($patientID,$dateB);
           if ($Q->rowCount()>0) {
             $cp=$Q->fetchAll();
             ?> 
             <table class="table table-bordered">
                <th>  
                  <small style="font-weight:0.8em;">Provisional</small>
                 </th>
                 <th> 
                  <small style="font-weight:0.8em;">Final</small>
                 </th>
              <?php      
               foreach ($cp as $key => $c) {
               
               ?>
               
                 <tr>
                    <td> 

                     <?php echo $c['pcode'].":". $c['proviD'];?> 
       
                     </td>
                     <td> 

                     <?php echo $c['fcode'].":". $c['finalD'];?> 
       
                    </td>
                 </tr>

               

               <?php
             }
             ?>
           </table>
              <?php 
           }
         ?>          
       
      </td>
       <td> 
        <?php
          $Q= $con->getMTReports($patientID,$dateB);
           if ($Q->rowCount()>0) {
             $cp=$Q->fetchAll();
             ?>
               <table class="table table-bordered">
                <th>  
                  <small style="font-weight:0.8em;">Test</small>
                 </th>
                 <th> 
                  <small style="font-weight:0.8em;">Result</small>
                 </th>
              <?php      
               foreach ($cp as $key => $c) {
               
               ?>
              
                 <tr>
                    <td> 
                      <?php echo $c['mTest'];?> 
                    </td>
                     <td> 
                        <?php echo $c['rDescrip'];?> 
                     </td>
                     
                 </tr>
               

               <?php
             }
             ?>
           </table>
             <
              <?php 
           }
         ?>          
       
      </td>
      <td> 
        <?php
          $Q= $con->getDrugReports($patientID,$dateB);
           if ($Q->rowCount()>0) {
             $cp=$Q->fetchAll(); 
             ?>
               <table class="table table-bordered">
                <th>  
                  <small style="font-weight:0.8em;">Drug</small>
                 </th>
                 <th> 
                  <small style="font-weight:0.8em;">Dosage</small>
                 </th>
             <?php    
               foreach ($cp as $key => $c) {
               
               ?>
               
               
                 <tr>
                    <td> 
                      <?php echo $c['drugname'];?> 
                    </td>
                     <td> 
                        <?php echo $c['dosage'];?> 
                     </td>
                     
                 </tr>
               

               <?php
             }
             ?>
           </table>
              <?php 
           } 
         ?>          
       
      </td>
      
       
  </tr>

 
  <?php
 
}
  $cc=0;
}
/////////////////////////else//////////////////////////////////////
else{
    
$dateB=$sdate;
$cc++;  
        ?>


    <tr> 
       <td> 

         <?php echo $sdate;?> 
       
      </td>
       <td> 
        <?php
          $Q= $con->getCompReports($patientID,$dateB);
           if ($Q->rowCount()>0) {
             $cp=$Q->fetchAll();     
               foreach ($cp as $key => $c) {
               
               ?>
               <table>
                 <tr>
                    <td> 
                      <?php echo $c['compain'];?> 
                    </td>
                     <td> 
                        <?php echo $c['hpi'];?> 
                     </td>
                     <td> 
                        <?php echo $c['gExam'];?> 
                    </td>
                 </tr>
               </table>

               <?php
             }
           }
         ?>          
       
      </td>
      <td> 
        <?php
          $Q= $con->getRosReports($patientID,$dateB);
           if ($Q->rowCount()>0) {
             $cp=$Q->fetchAll();     
               foreach ($cp as $key => $c) {
               
               ?>
               <table>
                 <tr>
                    <td> 
                      <?php echo $c['ros'];?> 
                    </td>
                     <td> 
                        <?php echo $c['descrip'];?> 
                     </td>
                      
                 </tr>
               </table>

               <?php
             }
           }
         ?>          
       
      </td> 
       <td> 
        <?php
          $Q= $con->getCodeReports($patientID,$dateB);
           if ($Q->rowCount()>0) {
             $cp=$Q->fetchAll();     
               foreach ($cp as $key => $c) {
               
               ?>
               <table>
                 <tr>
                    <td> 

                     <?php echo $c['pcode'].":". $c['proviD'];?> 
       
                     </td>
                     <td> 

                     <?php echo $c['fcode'].":". $c['finalD'];?> 
       
                    </td>
                 </tr>

               </table>

               <?php
             }
           }
         ?>          
       
      </td>
       <td> 
        <?php
          $Q= $con->getMTReports($patientID,$dateB);
           if ($Q->rowCount()>0) {
             $cp=$Q->fetchAll();     
               foreach ($cp as $key => $c) {
               
               ?>
               <table>
                 <tr>
                    <td> 
                      <?php echo $c['mTest'];?> 
                    </td>
                     <td> 
                        <?php echo $c['rDescrip'];?> 
                     </td>
                     
                 </tr>
               </table>

               <?php
             }
           }
         ?>          
       
      </td>
      <td> 
        <?php
          $Q= $con->getDrugReports($patientID,$dateB);
           if ($Q->rowCount()>0) {
             $cp=$Q->fetchAll();     
               foreach ($cp as $key => $c) {
               
               ?>
               <table>
                 <tr>
                    <td> 
                      <?php echo $c['drugname'];?> 
                    </td>
                     <td> 
                        <?php echo $c['dosage'];?> 
                     </td>
                     
                 </tr>
               </table>

               <?php
             }
           }
         ?>          
       
      </td>
      
       
  </tr>
  <?php
} 

?>
 
</tbody>
</table>
</div>

    <!--<img src="assets/pfooter.PNG" width="100%" height="80px">-->
</div>
<div>
   <button type="submit" class="btn btn-primary" value="Print" style="width:10%; height:30px;" onclick="printPageArea();">Print </button>
</div>
<?php
} 
else{
  echo "Valid detail required!..";
}
?>
<script type="text/javascript">
  function printPageArea(){
    var printContent = document.getElementById('co').innerHTML;
    var originalContent = document.body.innerHTML;
    document.body.innerHTML = printContent;
    window.print();
    document.body.innerHTML = originalContent;
}

</script>