<?php require('../db/db.php');

$doctorid=$_SESSION['doctorid'];

if(isset($_GET['visitid'])&&isset($_GET['patientid']))
{
	$visitid=$_GET['visitid'];  /// getting Shiftid from mgmtshift page
	$patientid=$_GET['patientid'];  /// getting Doctorid from mgmtshift page
	
	$_SESSION['visitid']=$visitid;
	$_SESSION['patientid']=$patientid;
}
else
{
	$visitid=$_SESSION['visitid'];
	$patientid=$_SESSION['patientid'];
}

if($username == ""){
	echo "You are currently not logged in to the system. Please <a href='../index.php'>Click here</span></a> to sign in!";}
else{ ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<p align="right">
<SCRIPT LANGUAGE="JavaScript"> 
if (window.print) {
document.write('<form class="no-print"><input type=button name=print value="Print" class="no-print" onClick="window.print()"></form>');
}
</script>
</p>  
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" style="font-size:12px; font-family:Arial, Helvetica, sans-serif;">

  <tr>
    <td align="center"><img src="../images/letterhead.png" width="900" height="180" /></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="1" cellpadding="0">
      <tr>
        <td width="79%">&nbsp;</td>
         <?php $raw_results2 = mysql_query("SELECT * FROM doctors WHERE doctor_id='$doctorid'");
while($row2 = mysql_fetch_array($raw_results2))
{ 
$title = $row2["title"];
$docfname = $row2["doc_fname"];
$doclname = $row2["doc_lname"]; ?>
        <td width="21%" style="border:1px solid #CCC; "><span style=" font-weight:200; font-size:18px; margin-left:12px;"><?php echo $title.". "; echo $docfname;
			echo " ";
			echo $doclname;?></span></br>
 <p  style="margin-left:12px;"><?php echo  $row2["specialization"]; ?> </br> <?php echo  $row2["degree"]; ?> </p>
<!--Contact No: //<?php //echo  $row2["doc_phone"]; ?> </br> Timings: <?php //echo  $row2["timings"]; ?>--></td> <?PHP } ?>
      </tr>
      <tr>
      <?php
$result = mysqli_query($con,"SELECT * FROM visits where visit_id='$visitid'");
while($row = mysqli_fetch_assoc($result))
{ 
?>
        <td><strong>Date: <?PHP echo $row['visit_date']; ?></strong></td><?php }?>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><img src="../images/iconrx.png" widtd="80" height="80" /></td>
<?php

function age_from_dob($dob) 
{

list($y,$m,$d) = explode('-', $dob);

if (($m = (date('m') - $m)) < 0) 
{
$y++;
} 
elseif ($m == 0 && date('d') - $d < 0)
{
$y++;
}

return date('Y') - $y;
}
$raw_results = mysqli_query($con,"SELECT * FROM patients where patient_id='$patientid'");
while($row = mysqli_fetch_array($raw_results))
{ 
?>
          <td style="border:1px solid #CCC;"><p style="margin-left:12px;margin-top: 5px;margin-bottom: 5px;margin-right: 5px;">Patient Name: <?php echo $row['patient_fname']; echo " "; echo $row['patient_lname']; ?></br>
          Age: <?php echo age_from_dob($row['dob']).' years';?></br>
          Gender:<?php echo $row['gender'];?></br>
          Patient ID: <?php echo $row['reg_id'];?></p></td>
          
          
<?php }?>
        <td>&nbsp;</td>
      </tr>
      <tr>
       <td>&nbsp;</td>
      </tr>
      
      <tr>
       <td>&nbsp;</td>
      </tr>
      <tr>
       <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-size:14px;">
          <tr>
            <td width="10%" align="left" ><p style="margin-left:5px; margin-top:5px; font-size:10px"><strong>Observations</strong></p></td>
            <td width="70%" align="left">&nbsp;</td>
            <td width="20%" align="left" style="font-size:10px"><strong>Lab Diagnosis</strong></td>
          </tr>
          <tr>
            <td valign="top">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php
$result = mysqli_query($con,"SELECT * FROM visits where visit_id='$visitid'");
while($row = mysqli_fetch_assoc($result))
{ 
?> <tr>
            <td style="font-size:12px"><p style="margin-left:5px; margin-top:5px;">Temp:<?php echo $row['temp']; ?></br>
              BP:<?php echo $row['bp']; ?></br>
              BSR:<?php echo $row['bsr']; ?></br>
              Weight:<?php echo $row['weight']; ?></p></td>
            </tr>
<?php } ?>
            </table>
             </td>          
            <td valign="top">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php
$result1 = mysqli_query($con,"SELECT * FROM presc_items where visit_id='$visitid'");
while($row1 = mysqli_fetch_array($result1))
{
$productid=$row1['product_id'];  
$result2 = mysqli_query($con,"SELECT * FROM products where product_id='$productid'");
while($row2 = mysqli_fetch_array($result2))
{ ?>
            <tr>
            <td align="left">
            <p style="margin-left: 96px;"><?PHP echo $row2['product_name']. " - " . $row2['medicine_type']; ?></p>
            </td>
            <td align="left">
            <p><?PHP echo $row1['dosage']; ?></p>
            </td>
            </tr>
<?php } }?>

            </table> 
            </td>
            <td valign="top">			
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php
$result1 = mysqli_query($con,"SELECT * FROM presc_items where visit_id='$visitid'");
while($row1 = mysqli_fetch_array($result1))
{
$labtestid=$row1['labtest_id'];  
 
$result2 = mysqli_query($con,"SELECT * FROM labtests where labtest_id='$labtestid'");
while($row2 = mysqli_fetch_array($result2))
{ ?>
            <tr>
            <td>
            <p><?php echo $row2['labtest_name']; ?></p>
            </td>
             </tr>
         <?php } }?>    
<?php
$result1 = mysqli_query($con,"SELECT * FROM presc_items where visit_id='$visitid'");
while($row1 = mysqli_fetch_array($result1))
{
$proid=$row1['procedure_id']; 	
 $result3 = mysqli_query($con,"SELECT * FROM procedures where procedure_id='$proid'");
while($row3 = mysqli_fetch_array($result3))
{ ?>
            <tr>
            <td>
            <p><?php echo $row3['procedure_name']; ?></p>
            </td>
            </tr>           
            
<?php } }?>
            </table> </td>
          </tr>
          <tr>
            <td valign="top">&nbsp;</td>
            <td valign="top">&nbsp;</td>
            <td valign="top">&nbsp;</td>
          </tr>
        </table></td>
        </tr>
    </table></td>
  </tr>
  
</table>

<p align="center" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; margin-top:260px;"><strong>For Appointment Call at 042-35151666 (bring your Patient ID Card)</strong></br>317 A-1, Nursery Stop, Township, Lahore 042-35151666 </br>(Not Valid for Court or any Legal Purpose)</p>
<?php }?>
</body>
</html>