<?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');
include('../classes/classDiagnostic.php');

################## Search Patients Start ####################################
try
{
	if(isset($_SESSION['print']['search'])&&$_SESSION['print']['search']=='Search')
	{
		$retrievePatientOb = new classPatient;
		$patients_array = $retrievePatientOb->searchPatient($_SESSION['print']['by_id'],$_SESSION['print']['by_name'],$_SESSION['print']['by_phone'],$_SESSION['security']['location_id']);
		
		if(isset($patients_array[0]['patient_auto_id']))
		{
			for($p=0;$p<count($patients_array);$p++)
			{
				$diagTestOb = new classDiagnostic;
				$diagTestOb->setLocationID($_SESSION['security']['location_id']);
				$diagTestOb->setDiagnosisType('labtest');
				$diagTestOb->setPatientID($patients_array[$p]['patient_auto_id']);
				$patient_single_array = $diagTestOb->retrieveInvoiceItemsDetailByLocationIDPatientIDAndType();
				if($patient_single_array[0]!='')
				{
					for($ps=0;$ps<count($patient_single_array);$ps++)
					{
						$labtest_array[] = $patient_single_array[$ps];
					}
					
				}
				
			}
		}
	}
	else
	{
		$diagTestOb = new classDiagnostic;
		$diagTestOb->setLocationID($_SESSION['security']['location_id']);
		$diagTestOb->setDiagnosisType('labtest');
		$labtest_array = $diagTestOb->retrieveInvoiceItemsDetailByLocationIDAndType();
	}
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}

try
{
	$labtestOb = new classDiagnostic;
	$labtestOb->setOrganizationID($_SESSION['security']['org_id']);
	$labtest_dropdown = $labtestOb->retrieveLabTests();
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}

/*echo '<pre>';
print_r($labtest_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"><!-- InstanceBegin template="/Templates/print.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <link rel="shortcut icon" href="../images/favicon.png">
    <title>Med2TEC Hospital Management Information System</title> 
    <link href="../css/print.css" rel="stylesheet">
    <link href="../datepicker/jquery-ui.css" rel="stylesheet" >  
    <script type="text/javascript" src="../datepicker/jquery-1.9.1.js"></script>
	<script type="text/javascript" src="../datepicker/jquery-ui.js"></script> 
</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">
<div style="background:#FFF; padding:0px 0px 0; height:auto;">
  <table cellspacing="0" cellpadding="0" width="100%" border="0" style="font-size:11px;">
    <tbody>
      <tr>
        <td align="left" style="background:#fff;"><img alt="" src="../images/org_print_logos/<?php echo $_SESSION['security']['org_id']?>.png" style="width:100%;"></td>
      </tr>
    </tbody>
  </table>
  
</br>

</div>

<div class="row">
          <section class="panel">
            <header class="panel-heading">
              <h2><!-- InstanceBeginEditable name="title" -->BLOOD TEST RESULTS<!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
  <!-- page start-->
  <div class="panel-body">
              <div class="adv-table">
                  <table class="bottomBorder" cellpadding="0" cellspacing="0" width="100%">
                  <thead>
                    <tr>
            		 <th width="5%" align="center">ID</th>
           			 <th width="10%" align="center">Invoice Date</th>
            		 <th width="15%" align="left">Patient's Name</th>
           		 	 <th width="10%" align="left">Phone</th>
            		 <th width="15%" align="left">Referred by</th>
            		 <th width="15%" align="center">Test</th>
                     <th width="10%" align="left">Specimen No.</th>
                     <th width="10%" align="left">Result</th>
                    </tr>
                  </thead>
                  <tbody>
                   <?php
                    if(isset($labtest_array[0]['diagitems_id'])&&$labtest_array[0]['diagitems_id']!='')
                    {
                    	for($v=0;$v<count($labtest_array);$v++)
						{
							if($v%2==0){$class = 'gradeX';}{$class = 'gradeC';}
							
							$diagitems_id = $labtest_array[$v]['diagitems_id'];
							$diagitems_id_encoded = base64_encode($diagitems_id);
							
							$patient_id = $labtest_array[$v]['patient_id'];
							$patient_id_encoded = base64_encode($patient_id);
							
							$diagnosis_id = $labtest_array[$v]['diagnosis_id'];
							
							$group_id = $labtest_array[$v]['group_id'];
							
							if($patient_id!=0)
							{
								$patientOb = new classPatient;
								$patientOb->setPatientAutoID($patient_id);
								$patient_info = $patientOb->retrievePatientByPatientID();
								
								$patient_name = $patient_info[0]['patient_fname'].' '.$patient_info[0]['patient_lname'];
								$patient_phone = $patient_info[0]['phone'];
							}
							else
							{
								$patient_name = 'Outdoor';
								$patient_phone = '';
							}
							
							if($labtest_array[$v]['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 = $labtest_array[$v]['referred_by'];
							}
							
							
							$retreiveTestOb = new classDiagnostic;
							$retreiveTestOb->setLabTestID($diagnosis_id);
							$labtest_info = $retreiveTestOb->retrieveLabTestsByLabTestID();
							
							$getGroupNameOb = new classDiagnostic;
							$group_name = $getGroupNameOb->retrieveTestGroupNameByID($group_id);
							
							
							?>
							<tr class="<?php echo $class;?>">
                                <td align="center"><?php echo $labtest_array[$v]['diaginvoice_id'];?></td>                                <td align="center"><?php echo date('d M Y',$labtest_array[$v]['diagitem_date']);?></td>
                                <td align="left"><?php echo $patient_name;?></td>
                                <td align="left"><?php echo $patient_phone;?></td>
                                <td align="left"><?php echo $referred_by;?></td>
                                <td align="left"><?php echo $labtest_info['0']['labtest_name'];?></td>
                                <td align="left"><?php echo $labtest_array[$v]['specimen'];?></td>
                                <td align="left"><?php if($labtest_array[$v]['diagnosis_result']!=''){echo $labtest_array[$v]['diagnosis_result'].' '.$labtest_info['0']['unit'];}?></td>
                                
							</tr>
                            
                            
                            <?php
						}
                    }
					else
					{
						?>
							<tr>
								<table>
									<tr>
										<td>No entries found!</td>
									</tr>
								</table>
							</tr>
						<?php
					}
                    ?>
                  </tbody>
                  <tfoot>
                  </tfoot>
                </table>
                
      </div>
    </div>
  <!-- page end-->

<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>317 A-1, Nursery Stop, Township, Lahore 042-35151666 (Not Valid for Court or any Legal Purpose)</p>
<!-- InstanceEndEditable -->
</section>
</div>

<!--<p align="center" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; margin-top:260px;"><strong><!--317 A-1, Nursery Stop, Township, Lahore. 
Ph: 042-35151666</strong><br />
For Appointment call at 042-35151666 (bring your Patient ID Card) </p>-->

   <div class="sidepop" style="float:right;">
    <div class="sidepopbutton stemp"><div style="color: rgb(0, 0, 0); text-align: right; font-size: 10px; margin-top: 4px; position: absolute; right: 180px;">© Software by Softusion Inc. 0322 6155 219</div>   
    </div>
</div>

<!--<div class="sidepop" style="float:right;">
    <div class="sidepopbutton stemp"><div style="color:#000; text-align:right; font-size:9px;">© Software designed by Softusion Inc. Contact us at 0322 6155 219</div>   
    </div>
</div>-->


          
</body>
<!-- InstanceEnd --></html>