<?php 
include('../config/config.php');
include("../classes/classShift.php");
include("../classes/classDoctor.php");
include("../classes/classVisits.php");
include('../classes/classPatient.php');
include("../classes/classImages.php");
include('../classes/classTransaction.php');


/*echo '<pre>';
print_r($_SESSION);
echo '</pre>';*/

if(isset($_GET['patientid'])&&isset($_GET['visitid']))
{
	$_SESSION['temp']['patient_id'] = base64_decode($_GET['patientid']);
	$_SESSION['temp']['visit_id'] = base64_decode($_GET['visitid']);
	//header("Location:mgmtvisits.php");
}

if(isset($_SESSION['temp']['shiftid'])&&$_SESSION['temp']['shiftid']!='')
{
	$shift_id = $_SESSION['temp']['shiftid'];
}
if(isset($_SESSION['temp']['doctorid'])&&$_SESSION['temp']['doctorid']!='')
{
	$doctor_id = $_SESSION['temp']['doctorid'];
}

if(isset($_SESSION['temp']['patient_id'])&&$_SESSION['temp']['patient_id']!='')
{
	$patient_id = $_SESSION['temp']['patient_id'];
}

if(isset($_SESSION['temp']['visit_id'])&&$_SESSION['temp']['visit_id']!='')
{
	$visit_id = $_SESSION['temp']['visit_id'];
}

try
{
	$retrieveVisitPrecOb = new classVisits;
	$retrieveVisitPrecOb->setPatientID($patient_id);
	$visit_array = $retrieveVisitPrecOb->retrieveVisitByPatientID();
	
	
	///////////// retrieve patient single data ///////////////////////////////
	
	$retrievePatientOb = new classPatient;
	$retrievePatientOb->setPatientAutoID($patient_id);
	$patient_single_detail = $retrievePatientOb->retrievePatientByPatientID();
	
	$patient_age = $retrievePatientOb->age_from_dob($patient_single_detail[0]['dob']);
	
	$imageOb = new classImages;
	$imageOb->setPatientAutoID($patient_id);
	$image_id = $imageOb->fetchImageOfPatient();
	
	
	
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	

?>
<!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>Med2TEC Hospital Management Information System</title>
<link href="../css/print.css" rel="stylesheet">
</head>

<body>
<div align="right">
 <SCRIPT LANGUAGE="JavaScript"> 
if (window.print) {
document.write('<form class="no-print"><input type=button name=print value="Print" onClick="window.print()"></form>');
}
</script></div>
<section class="wrapper">
  <table cellspacing="0" cellpadding="0" width="100%" border="0" style="font-size:11px;">
  <tbody>
    <tr>
      <td align="left"><img src="../images/letterhead.png" width="820" height="180" /></td>
    </tr>
    
  </tbody>
</table>
<br>
 
      <!-- page start-->
      <div class="row">
        <div class="col-sm-12" >
          <section class="panel">
           <header class="panel-heading">
              <h2>CLINICAL OVERVIEW</h2>
            </header>
            <p>
              <?php
			if(isset($error_message)&&$error_message!='')
			{
				?>
              <span class="message_red"><?php echo $error_message;?></span>
              <?php
			}
			?>
            </p>
<table width="97%" border="0" cellspacing="1" cellpadding="0" style="border-bottom:1px solid #999;">
      <tr>
        <td width="70%"></td>
        <td width="30%" align="right"><?php
			if(isset($image_id)&&$image_id!='')
			{
				?>
				<img src="../images/patient_images/<?php echo $image_id;?>.jpg" height="148" width="140" >
				<?php
			}
			else
			{
				?>
				<img src="../images/photo.png" height="148" width="140">
				<?php
			}
			?></td>
      </tr>
</table>

<br />

<table width="100%" border="0" cellspacing="5" cellpadding="5" style="border-bottom:1px solid #999;">
      <tr>
        <td width="20%" align="right">Patient ID:</td>
        <td width="30%"><?php echo $patient_single_detail[0]['patient_id']; ?></td>
        <td width="20%" align="right">PR#:</td>
        <td width="30%"></td>
      </tr>
      <tr>
        <td align="right">Patient Name:</td>
        <td><?php echo $patient_single_detail[0]['patient_fname'].' '.$patient_single_detail[0]['patient_lname'];?></td>
        <td align="right">Date:</td>
        <td><?php echo date('d F Y',time());?></td>
      </tr>
       <tr>
        <td align="right">Gender:</td>
        <td></td>
        <td align="right">Visit ID:</td>
        <td></td>
      </tr>
       <tr>
        <td align="right">Age:</td>
        <td><?php echo $patient_age?></td>
        <td align="right">Visit Type:</td>
        <td>OPD</td>
      </tr>
</table> 
    
<br />

<table width="100%" border="0" cellspacing="5" cellpadding="5">
  <tr>
    <td valign="top"><table width="100%" height="200px" align="center" border="0" cellspacing="5" cellpadding="5" style="border:1px solid #999;">
      <tr>
        <td width="100%" align="left"><strong>Medications:</strong></td>
      </tr>
      <tr>
        <td align="left" valign="top"><table width="100%" >
                <thead>
                <tr>
                <th width="25%" align="left">Started on</th>
                <th width="30%" align="left">Medicine</th>
                <th width="30%" align="center">Prescribed by</th>
                <th width="15%" align="center">Active</th>
                </tr>
                </thead>
               <tbody>
                                <?php
								if(isset($visit_array[0]['visit_id']))
								{
									for($v=0;$v<count($visit_array);$v++)
									{
										$retrieveVisitPrecOb = new classVisits;
										$retrieveVisitPrecOb->setVisitID($visit_array[$v]['visit_id']);
										$prec_array = $retrieveVisitPrecOb->retrievePrescription();
										
										$doctorOb = new classDoctor;
										$doctorOb->setDoctorID($visit_array[$v]['doctor_id']);
										$doctor_detail = $doctorOb->retrieveDoctorByDoctorID();
										
										$doctor_name = $doctor_detail[0]['title'].'. '.$doctor_detail[0]['doc_fname'].' '.$doctor_detail[0]['doc_lname'];
										
										
										?>
                                        <tr class="gradeX">
                                        
                                        	<td>
                                            <?php
                                            echo date('d M Y',$visit_array[0]['visit_date']);
											?>
                                            </td>
                                            
                                            <td>
                                            <?php
											for($prm=0;$prm<count($prec_array);$prm++)
											{
												if($prec_array[$prm]['product_id']!=0)
												{	
													$retreiveMedOb = new classVisits;
													$retreiveMedOb->setMedicineID($prec_array[$prm]['product_id']);
													$med_info = $retreiveMedOb->retrieveMedicineByMedicineID();
													
													echo $med_info[0]['product_name']." - (".$prec_array[$prm]['dosage'].")".'<br>';
													
												}
											}
											?>
                                            </td>
                                            
                                            <td>
                                            <?php
											echo $doctor_name;
											?>
                                            </td>
                                            
                                            <td align="center"></td>
                                        </tr>
										<?php
									}
								}
								?>
                                </tbody>
                <tfoot>
                </tfoot>
                </table></td>
      </tr>
</table></td>
    <td valign="top"><table width="100%" height="200px" align="center" border="0" cellspacing="5" cellpadding="5" style="border:1px solid #999;">
      <tr>
        <td width="100%" align="left"><strong>Tests/Procedures:</strong></td>
      </tr>
      <tr>
        <td align="left" valign="top"><table width="100%">
                <thead>
                <tr>
                <th width="24%" align="left">Date</th>
                <th width="29%" align="left">Test</th>
                <th width="32%" align="center">Doctor</th>
                <th width="15%" align="center">Result</th>
                </tr>
                </thead>
               <tbody>
                                <?php
								if(isset($visit_array[0]['visit_id']))
								{
									for($v=0;$v<count($visit_array);$v++)
									{
										$retrieveVisitPrecOb = new classVisits;
										$retrieveVisitPrecOb->setVisitID($visit_array[$v]['visit_id']);
										$prec_array = $retrieveVisitPrecOb->retrievePrescription();
										
										$doctorOb = new classDoctor;
										$doctorOb->setDoctorID($visit_array[$v]['doctor_id']);
										$doctor_detail = $doctorOb->retrieveDoctorByDoctorID();
										
										$doctor_name = $doctor_detail[0]['title'].'. '.$doctor_detail[0]['doc_fname'].' '.$doctor_detail[0]['doc_lname'];
										
										
									
											for($prm=0;$prm<count($prec_array);$prm++)
											{
												?>
												 <tr class="gradeX">
                                            
                                                <td>
                                                <?php
                                                echo date('d M Y',$visit_array[0]['visit_date']);
                                                ?>
                                                </td>
                                                
                                                <td>
                                                <?php
                                                 if($prec_array[$prm]['labtest_id']!=0)
												 {	
													 $retreiveMedOb = new classVisits;
													 $retreiveMedOb->setLabTestID($prec_array[$prm]['labtest_id']);
													 $labtest_info = $retreiveMedOb->retrieveLabTestsByLabTestID();
																		
													 echo $labtest_info[0]['labtest_name'].'<br>';
												}
                                                if($prec_array[$prm]['procedure_id']!=0)
												{	
													$retreiveMedOb = new classVisits;
													$retreiveMedOb->setProcedureID($prec_array[$prm]['procedure_id']);
													$procedure_info = $retreiveMedOb->retrieveProcedureByProcedureID();
														
													echo $procedure_info[0]['procedure_name'];
												}
											    ?>
                                                </td>
                                                
                                                  <td>
                                            <?php
											echo $doctor_name;
											?>
                                            </td>
                                            
												
                                            <td></td>
                                            </tr>
											<?php	
												
											}
											
									}
								}
								?>
                            </tbody>
                <tfoot>
                </tfoot>
                </table></td>
      </tr>
</table></td>
  </tr>
  <tr>
    <td valign="top"><table width="100%" height="200px" align="center" border="0" cellspacing="5" cellpadding="5" style="border:1px solid #999;">
      <tr>
        <td width="100%" align="left"><strong>OPD Visits:</strong></td>
      </tr>
      <tr>
        <td align="left" valign="top"><table width="100%" class="display table table-bordered table-striped" id="dynamic-table2">
                        <thead>
                          <tr>
                            <th width="23%" align="left">Date</th>
                            <th width="22%" align="left">Doctor</th>
                            <th width="25%" align="center">Complaints</th>
                            <th width="30%" align="left">Diagnosis</th>
                          </tr>
                        </thead>
                        <tbody>
                                <?php
								if(isset($visit_array[0]['visit_id']))
								{
									for($v=0;$v<count($visit_array);$v++)
									{
										
										$doctorOb = new classDoctor;
										$doctorOb->setDoctorID($visit_array[$v]['doctor_id']);
										$doctor_detail = $doctorOb->retrieveDoctorByDoctorID();
										
										$doctor_name = $doctor_detail[0]['title'].'. '.$doctor_detail[0]['doc_fname'].' '.$doctor_detail[0]['doc_lname'];
										
										
										?>
                                        <tr class="gradeX">
                                        
                                            <td>
                                            <?php
											echo date('d M Y',$visit_array[0]['visit_date']);
											?>
                                            </td>
                                            
                                            <td>
                                            <?php
											echo $doctor_name;
											?>
                                            </td>
                                            
                                            <td>
                                            <?php
                                           echo  $visit_array[$v]['complaint'];
											?>
                                            </td>
                                             
                                            <td>
                                            <?php
                                           echo  $visit_array[$v]['diagnosis'];
											?>
                                            </td>
                                           
                                           
                                        </tr>
										<?php
									}
								}
								?>
                            </tbody>
                        <tfoot>
                        </tfoot>
              </table></td>
      </tr>
</table></td>
    <td valign="top"><table width="100%" height="200px" align="center" border="0" cellspacing="5" cellpadding="5" style="border:1px solid #999;">
      <tr>
        <td width="100%" align="left"><strong>IPD History:</strong></td>
      </tr>
      <tr>
        <td align="left" valign="top"><table width="100%" class="display table table-bordered table-striped" id="dynamic-table3">
                        <thead>
                          <tr>
                            <th width="20%" align="left">Date In</th>
                            <th width="30%" align="left">Visit Purpose</th>
                            <th width="30%" align="center">Referred by</th>
                            <th width="20%" align="center">Date Out</th>
                          </tr>
                        </thead>
                        <tbody>
                          <tr class="gradeX">
                            <td>12 Aug 2014</td>
                            <td>Cardio</td>
                            <td>Dr. x</td>
                            <td>12 Aug 2014</td>
                          </tr>
                        </tbody>
                        <tfoot>
                        </tfoot>
              </table></td>
      </tr>
</table></td>
  </tr>
</table>

<br />

<table width="100%" border="0" cellspacing="5" cellpadding="5">
  <tr>
    <td valign="top">Medical History: <?php echo $patient_single_detail[0]['med_history'];?></td>
  </tr>
  <tr>
    <td valign="top">Allergies: <?php echo $patient_single_detail[0]['allergies'];?></td>
  </tr>
  <tr>
    <td valign="top">Family History: <?php echo $patient_single_detail[0]['fam_history'];?></td>
  </tr>
  <tr>
    <td valign="top">Social History: <?php echo $patient_single_detail[0]['soc_history'];?></td>
  </tr>
</table>

           

        </div>
      	</div>
        
      
      <!-- page end-->
    

<div style="color:#999; text-align:center;">All Rights Reserved © Copyrights Softusion Inc. 2013<br />For details contact us at info@softusion.com</div>
</body>
</html>