<?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');



if(isset($_GET['visitid'])&&$_GET['visitid']!='')
{
	$_SESSION['temp']['visit_id'] = base64_decode($_GET['visitid']);
}
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']['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'];
}


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

try
{
	$retrieveVisitPrecOb = new classVisits;
	$retrieveVisitPrecOb->setVisitID($visit_id);
	$visit_array = $retrieveVisitPrecOb->retrieveVisitByVisitID();
	$prec_array = $retrieveVisitPrecOb->retrievePrescription();
	
	///////////// 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']);
	
	
///////////// retrieve doctor Detail ////////////////////////////////////////

try
{
	$doctorOb = new classDoctor;
	$doctorOb->setDoctorID($doctor_id);
	$doctor_detail = $doctorOb->retrieveDoctorByDoctorID();
	
	$doctor_name = $doctor_detail[0]['title'].' '.$doctor_detail[0]['doc_fname'].' '.$doctor_detail[0]['doc_lname'];
	
	$doctor_acc_id = $doctor_detail[0]['account_id'];
	$specialization = $doctor_detail[0]['specialization'];
	$degree = $doctor_detail[0]['degree'];
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	

	///////////// retrieve patient image ///////////////////////////////
	
	$imageRetrieveOb = new classImages;
	$imageRetrieveOb->setPatientAutoID($patient_id);
	$image_id = $imageRetrieveOb->fetchImageOfPatient();
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	

try
{
	$retrieveOb = new classVisits;
	$medicine_array = $retrieveOb->retrieveMedicines();
	$labtest_array = $retrieveOb->retrieveLabTests();
	$procedure_array = $retrieveOb->retrieveProcedures();
	$dressing_array = $retrieveOb->retrieveDressing();
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	

/*echo '<pre>';
print_r($_SESSION);
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 rel="shortcut icon" href="../images/favicon.png">
    <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" style="background:#fff;"><img alt="" src="../images/org_print_logos/<?php echo $_SESSION['security']['org_id']?>.png" style="width:100%;"></td>
      </tr>
    </tbody>
  </table>


</div>

	<div class="row">
    <section class="panel">

    <!-- page start-->
    
        <p>
        <?php
        if(isset($error_message)&&$error_message!='')
        {
            ?>
            <span class="message_red"><?php echo $error_message;?></span>
            <?php
        }
        ?>
        </p>
        <table width="100%" border="0" cellspacing="5" cellpadding="5">
  <tr>
    <td width="20%" valign="top" style="border-right:1px solid #000; height:700px;"><table width="100%" border="0" cellspacing="5" cellpadding="5">
  <tr>
    <td>BP: <?php echo $visit_array[0]['bp']; ?><br />
    	Pulse: <?php echo $visit_array[0]['pulse']; ?><br />
        Temp: <?php echo $visit_array[0]['temp']; ?><br />
        BSR: <?php echo $visit_array[0]['bsr']; ?> <br />
        Height: <?php echo $visit_array[0]['height']; ?> <br />
        Weight: <?php echo $visit_array[0]['weight']; ?> <br />
    	</td>
  </tr>
  <tr>
    <td><?php 
			if(isset($visit_array[0]['notes'])&&$visit_array[0]['notes']!='')
                {
                    ?>
                        <span class="smallblue">Notes:</span><br /><br />
                        <?php echo ucwords($visit_array[0]['notes']); ?>
                    <?php
                }
                
                ?></td>
  </tr>
</table>
</td>
    <td width="80%" valign="top" ><table width="100%" border="0" align="right" cellpadding="5" cellspacing="5" >
        
        <tr>
          <td>	<table width="100%" border="0" cellpadding="0" cellspacing="5" style="border-bottom:1px solid #999; border-top:1px solid #999; font-size:14px;">
            <tr>
              <td width="25%">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>Patient Name:</td>
              <td><?php echo $patient_single_detail[0]['patient_fname'].' '.$patient_single_detail[0]['patient_lname'];?></td>
              <td width="25%">Date:</td>
              <td width="20%"><?php echo date('d M Y',$visit_array[0]['visit_date']); ?></td>
              </tr>
            <tr>
              <td>s/d/w of:</td>
              <td><?php echo $patient_single_detail[0]['parent_name'];?></td>
              <td>Visit ID:</td>
              <td>OPD-<?php echo $visit_id;?></td>
              </tr>
            <tr>
              <td>Age:</td>
              <td><?php echo $patient_age;?></td>
              <td>Phone:</td>
              <td><?php echo $patient_single_detail[0]['phone'];?></td>
              </tr>
            </table></td>
          </tr>
          
        <tr>
          <td>
                <table width="100%" border="0" cellspacing="2" cellpadding="0">
  <tr>
    <td width="60%" valign="top"><?php
                
                if($retrieveVisitPrecOb->checkMedicineLabTestProcedureInPrescription($visit_id,'medicine'))
                {
                    ?>
                    <table class="rounded_corners" width="100%">
                    <tr bgcolor="#e8e8e8">
                        <td width="90%" align="left" colspan="2"><strong>Medication:</strong></td>
                    </tr>
                    <?php
					$no_of_med = 1;
                    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();
							?>
                            <tr>
                            <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            
                            <tr>
                            	<td width="40%" align="left"><?php echo $no_of_med.'. '.ucwords($med_info[0]['product_name']);?><br /></td>
                                <td width="40%" align="right"><?php echo $prec_array[$prm]['dosage'];
								
                                if($prec_array[$prm]['quantity']!=0)
								{
									if($med_info[0]['medicine_type']=='Tablets/Capsules'){$type_of_med = 'گولیاں';}elseif($med_info[0]['medicine_type']=='Syrup'){$type_of_med = 'چمچ';}elseif($med_info[0]['medicine_type']=='Cream'){$type_of_med = 'مٹر کا دانہ';}else{$type_of_med = '';}
									?></td>
									<td width="20%" align="right"><?php echo $type_of_med; ?></td>
									<td width="1%"><?php echo ' '.$prec_array[$prm]['quantity']; ?></td>
									<?php
								}
								
								?>
                            </tr>
                            <?php
							if($prec_array[$prm]['duration']!=0)
							{
								?>
								<tr>
								<td>&nbsp; </td>
								<td align="right"> </td>
								<td align="right"><?php echo ' دن '; ?></td>
								<td><?php echo ' '.$prec_array[$prm]['duration']; ?></td>
								</tr>
								<?php
							}
							?>
                           
                            
                            <tr>
                                <td>&nbsp; </td>
                                <td>&nbsp; </td>
                                <td>&nbsp; </td>
                                <td align="right"></td>
                            </tr>
                            
                            </table></td>
                            </tr>
                            
							<?php
							$no_of_med++;
						}
                     }
					?>
                    </table>
                    <?php
                    
                }
				?></td>
    <td width="40%" ><table width="100%" border="0" cellspacing="2" cellpadding="0">
  <?php
                if($retrieveVisitPrecOb->checkMedicineLabTestProcedureInPrescription($visit_id,'labtest'))
                {
                    ?><tr>
                    <td valign="top"><table class="rounded_corners" width="100%">
                
                    <tr bgcolor="#e8e8e8">
                        <td width="100%" align="left"><strong>Tests:</strong></td>
                    </tr>
                    
                    <tr>
                        <td align="left" valign="top"><table width="100%">
                            <tr>
                                <td align="left" width="40%">
								<?php
								$no_of_test=1;
                                for($prm=0;$prm<count($prec_array);$prm++)
                                {
									if($prec_array[$prm]['labtest_id']!=0)
									{
										$retreiveMedOb = new classVisits;
										$retreiveMedOb->setLabTestID($prec_array[$prm]['labtest_id']);
										$labtest_info = $retreiveMedOb->retrieveLabTestsByLabTestID();
										echo $no_of_test.'. '.ucwords($labtest_info[0]['labtest_name']); ?>
										<p></p>
										<?php 
										$no_of_test++;
									}
										
                                } 
                                ?>
                                </td>
                            </tr>
                        </table></td>
                    </tr>
                
                    </table></td>
  </tr><?php
                
                } ?>
                <?php
	  if($retrieveVisitPrecOb->checkMedicineLabTestProcedureInPrescription($visit_id,'procedure'))
                {
                    ?>
                    
  <tr>
  
                    <td  valign="top"><table class="rounded_corners" width="100%">
                      <tr bgcolor="#e8e8e8">
                        <td width="100%" align="left"><strong>Procedures:</strong></td>
                      </tr>
                      <tr>
                        <td align="left" valign="top"><table width="100%">
                          <tr>
                            <td align="left" width="40%">
                            <?php
							$no_of_prod = 1;
                            for($prm=0;$prm<count($prec_array);$prm++)
                            {
								if($prec_array[$prm]['procedure_id']!=0)
								{
									$retreiveMedOb = new classVisits;
									$retreiveMedOb->setProcedureID($prec_array[$prm]['procedure_id']);
									$procedure_info = $retreiveMedOb->retrieveProcedureByProcedureID();
									echo $no_of_prod.'. '.ucwords($procedure_info[0]['procedure_name']);?>
									<p></p>
									<?php
									$no_of_prod++; 
								}
                            } 
                            ?>
                            </td>
                          </tr>
                        </table></td>
                        </tr>
                    </table></td>
  </tr><?php
                    
                }
                ?>
</table>
</td>
  </tr>
</table>
		  </td>
        </tr>
           </table></td>
  </tr>
          
        </table>
     
     
      <!-- page end-->
    </section>
	</div>

</section>



<style>


#block{
    display:block;
    margin:auto;
    position:absolute;
	float:right;
    }

#text {
    padding:0;
    margin:0;
    position:relative;
    font-size:9px;
    -webkit-transform: rotate(-90deg);
    -moz-transform: rotate(-90deg);
    -ms-transform: rotate(-90deg);
    -o-transform: rotate(-90deg);
	left: 880px; top: 348px;
}
</style>
<!--<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>-->
<div align="center" style="font-size:28px; font-family:Arial, Helvetica, sans-serif; margin-bottom:5px; border-bottom:1px solid #000;">
Al-Shifa Clinic & Maternity Home</div>

<div style="text-align:center; font-size:16px; margin-bottom:-6px;">Near Rahim Chowk, Masoom Shah Road, Multan. Tel: 061-6778011</div>  

</strong>
</div>
        
</body>
</html>

