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


if(isset($_GET['diaginvoice_id'])&&$_GET['diaginvoice_id']!='')
{
	$_SESSION['temp']['diaginvoice_id'] = base64_decode($_GET['diaginvoice_id']);
}
if(isset($_GET['patientid'])&&$_GET['patientid']!='')
{
	$_SESSION['temp']['patient_id'] = base64_decode($_GET['patientid']);
}
if(isset($_GET['doctorid'])&&$_GET['doctorid']!='')
{
	$_SESSION['temp']['doctorid'] = base64_decode($_GET['doctorid']);
}


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





///////////// retrieve things ////////////////////////////////////////

try
{
	
	
	$diagInvOb = new classDiagnostic;
	$diagInvOb->setDiagInvoiceID($diaginvoice_id);
	$invoice_array = $diagInvOb->retrieveInvoiceDetail();
	$invoice_items_array = $diagInvOb->retrieveInvoiceItemsDetailGrouped();
	
	if($invoice_array[0]['visit_id']!=0)
	{
		$visitOb = new classVisits;
		$visitOb->setVisitID($labtest_array[$v]['visit_id']);
		$visit_info = $visitOb->retrieveVisitByVisitID();
		
		############# get doctor data ##########################
		$doctorOb = new classDoctor;
		$doctorOb->setDoctorID($visit_info[0]['doctor_id']);
		$doctor_detail = $doctorOb->retrieveDoctorByDoctorID();
		$referred_by = $doctor_detail[0]['title'].'. '.$doctor_detail[0]['doc_fname'].' '.$doctor_detail[0]['doc_lname'];
	}
	else
	{
		$referred_by = $invoice_array[0]['referred_by'];
	}
	
	///////////// retrieve patient single data ///////////////////////////////
	if($patient_id!=0)
	{
		$retrievePatientOb = new classPatient;
		$retrievePatientOb->setPatientAutoID($patient_id);
		$patient_single_detail = $retrievePatientOb->retrievePatientByPatientID();
		
	}
	else
	{
		
		$patient_name = 'Outdoor';
		$patient_gender = '';
		
	}
	
///////////// retrieve patient image ///////////////////////////////
	
	$imageRetrieveOb = new classImages;
	$imageRetrieveOb->setPatientAutoID($patient_id);
	$image_id = $imageRetrieveOb->fetchImageOfPatient();
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	




		


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

?>
<!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" />
<link href="../css/print.css" rel="stylesheet">

<title>Untitled Document</title>
<style>

.footer{
	color: #767676;
	font-size: 0.55em;
	bottom:-670px;
	text-align:center;
	left: 443px;
}

.footer2{
	color: #000;
	font-size: 14px;
	text-align:center;
	font-weight:600;
	bottom:-626px;
	text-align:center;
	left: 261px;
}

h2 { text-transform: uppercase; }
.bordertable{border-top:1px solid #000; border-bottom:1px solid #000;}
</style>
</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>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

		<tr>
        	<td height="140" align="center"><img src="../images/letterhead alhuda.png" width="100%" height="130" /></td>
      	</tr>
      
      	<tr>
            <td align="left">
             <?php
            if(isset($error_message)&&$error_message!='')
            {
                ?>
                <span class="message_red"><?php echo $error_message;?></span>
                <?php
            }
            ?>
            </td>
      	</tr>
        
        <tr>
        <td><table width="100%" border="0" cellspacing="3" cellpadding="0" align="center" style="border-bottom:1px solid #ccc;">
        
          	<tr>
            	<br />
			</tr>
          
            <tr>
                <td width="18%"><strong>Patient #:</strong></td>
                <td width="44%"><?php  if(isset($patient_single_detail[0]['patient_auto_id'])){echo $patient_single_detail[0]['patient_auto_id'];}?></td>
                <td width="17%"><strong>Date:</strong></td>
                <td width="21%"><?php echo date('d M Y',$invoice_array[0]['diaginvoice_date']);?></td>
            </tr>
            
            <tr>
                <td><strong>Patient Name:</strong></td>
                <td><?php if(isset($patient_single_detail[0]['patient_fname'])){echo ucwords($patient_single_detail[0]['patient_fname'].' '.$patient_single_detail[0]['patient_lname']);}else{echo 'Outdoor';}?></td>
                <td><strong>Invoice #:</strong></td>
                <td><?php echo $diaginvoice_id;?></td>
            </tr>
            
            <tr>
                <td><strong>s/d/w Name:</strong></td>
                <td><?php if(isset($patient_single_detail[0]['relationship_name'])){echo ucwords($patient_single_detail[0]['relationship_name']);}?></td>
                <td><strong>Referred by:</strong></td>
                <td><?php echo ucwords($referred_by);?></td>
            </tr>
            
            <tr>
                <td><strong>Phone:</strong></td>
                <td><?php if(isset($patient_single_detail[0]['phone'])){echo $patient_single_detail[0]['phone'];}?></td>
                <td><strong>Address:</strong></td>
                <td><?php if(isset($patient_single_detail[0]['address'])){echo $patient_single_detail[0]['address'];}?></td>
            </tr>
            
            <tr>
                <td><strong>Gender:</strong></td>
                <td><?php if(isset($patient_single_detail[0]['gender'])){echo $patient_single_detail[0]['gender'];}?></td>
                <td><strong>Age:</strong></td>
                <td><?php if(isset($patient_single_detail[0]['age'])){echo $patient_single_detail[0]['age'].' years';}?></td>
            </tr>
            
    	</table></td>
    	</tr>
        
  		<tr>
    	<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
    	<?php
		for($inv=0;$inv<count($invoice_items_array);$inv++)
		{
			?>
			<tr>
				<td>
                <?php
				if($invoice_items_array[$inv]['group_name']!='')
				{
					?><h2><?php echo ucwords($invoice_items_array[$inv]['group_name']);?></h2><?php
				}
				?>
                </td>
			</tr>
			
			<tr bgcolor="#C0C0C0">
				<td width="26%" height="40" class="bordertable"><strong>TEST</strong></td>
				<td width="28%" class="bordertable"><strong>RESULT</strong></td>
				<td width="25%" align="center" class="bordertable"><strong>UNIT</strong></td>
				<td width="21%" align="center" class="bordertable"><strong>NORMAL VALUE</strong></td>
			</tr>
			<?php
			for($prm=0;$prm<count($invoice_items_array[$inv]['group_items']);$prm++)
			{
		
				$type = $invoice_items_array[$inv]['group_items'][$prm]['diagnosis_type'];
				$id = $invoice_items_array[$inv]['group_items'][$prm]['diagnosis_id'];
				$diagitems_id = $invoice_items_array[$inv]['group_items'][$prm]['diagitems_id'];
				$group_id = $invoice_items_array[$inv]['group_items'][$prm]['group_id'];
				$diagnosis_result = $invoice_items_array[$inv]['group_items'][$prm]['diagnosis_result'];
				$diagnosis_name = $invoice_items_array[$inv]['group_items'][$prm]['diagnosis_name'];
				$normal_value = $invoice_items_array[$inv]['group_items'][$prm]['normal_value'];
				$unit = $invoice_items_array[$inv]['group_items'][$prm]['unit'];
				$labtest_notes = $invoice_items_array[$inv]['group_items'][$prm]['labtest_notes'];
				?>
			   
				<tr>
						<td><?php echo $diagnosis_name;?></td>
						<td><?php echo $diagnosis_result;?></td>
						<td align="center"><?php echo $unit;?></td>
						<td align="center"><?php echo $normal_value;?></td>
				</tr>
					
                
				<tr>
						<td colspan="4"><p>
                        <?php
						if($labtest_notes!='')
						{
							?>   
							
							<p><strong>NOTE:</strong></p>
							<?php echo ucfirst($labtest_notes);?>
							<!--<ul><li>. Borderline cases should be repeated after 4 - 6 weeks.</li>
							<li>. This test is performed on this state of the art abbott Architect immunodiagostics system uning CHEMILUMINESCENCE Technology patented as CHEMIFEX.</li>
							<li></li>
							<li>. This is a fourth generation ELISA test to detect the p24 antigen and HIV 1 and 2 antibodies.</li>
							</ul>-->
							
							<?php
						}
						?>
						</p></td>
					</tr>
						
				<?php
				
			}
			
		}
		?>
      	</table></td>
  		</tr>
     
      	<tr>
        	<td height="63"><div class="footer2">Elcctronically verified report. No signatures required.<br /> Lab test results should be interpreted by a physician in the context of clinical findings.</div></td>
        </tr>
        
        <tr>
        	<td><div class="footer">All Rights Reserved © Software designed by Softusion Inc. 2013<br />
        For details Contact: 061-4504428</div></td>
        </tr>
        
        <tr>
        	<td height="34">&nbsp;</td>
        </tr>
      
</table>

</body>
</html>
