<?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/classProduct.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'];
}

/////////////////////////////Delete prec////////////////////////

if(isset($_GET['del_prec']))
{
	$del_prec = base64_decode($_GET['del_prec']);
		
	try
	{	
		$delVisitOb = new classVisits;
		$delVisitOb->setPrescriptionItemID($del_prec);
		$delVisitOb->deletePrescription();
		
		header("Location:addpresc.php");
	}
	catch (MyException $e)
	{
		$error_message = $e->getUserMsg();
	}	
}


///////////// retrieve default procedures ////////////////////////////////////////
if((isset($_POST['submit'])&&$_POST['submit']=='Add to Prescription')||(isset($_POST['save_exit'])&&$_POST['save_exit']!=''))
{
	/*echo '<pre>';
	print_r($_POST);
	echo '</pre>';
	exit;*/
	
	
	try
	{
		
		$updateVisitOb = new classVisits;
		$updateVisitOb->setTemp($_POST['temp']);
		$updateVisitOb->setBp($_POST['bp']);
		$updateVisitOb->setBsr($_POST['bsr']);
		$updateVisitOb->setWeight($_POST['weight']);
		$updateVisitOb->setComplaint($_POST['complaint']);
		$updateVisitOb->setDiagnosis($_POST['diagnosis']);
		$updateVisitOb->setNotes($_POST['notes']);
		
		$updateVisitOb->setZakat(@$_POST['zakat']);
		$updateVisitOb->setKhairat(@$_POST['khairat']);
		$updateVisitOb->setDiscount(@$_POST['discount']);
		
		$updateVisitOb->setFee($_POST['fee']);
		$updateVisitOb->setPayment($_POST['payment']);
		$updateVisitOb->setVisitID($visit_id);
		$updateVisitOb->updatePrescription();
		
		if(isset($_POST['medicine_id'][0])&&$_POST['medicine_id'][0]!='')
		{
			$updateVisitOb->insertPrescriptionItems($visit_id,'medicine',$_POST['medicine_id']);
		}
		if(isset($_POST['labtest_id'][0])&&$_POST['labtest_id'][0]!='')
		{
			$updateVisitOb->insertPrescriptionItems($visit_id,'labtest',$_POST['labtest_id']);
		}
		if(isset($_POST['procedure_id'][0])&&$_POST['procedure_id'][0]!='')
		{
			$updateVisitOb->insertPrescriptionItems($visit_id,'procedure',$_POST['procedure_id']);
		}
		if(isset($_POST['dressing_id'][0])&&$_POST['dressing_id'][0]!='')
		{
			$updateVisitOb->insertPrescriptionItems($visit_id,'dressing',$_POST['dressing_id']);
		}
		
		if(isset($_POST['dosage'])||isset($_POST['quantity'])||isset($_POST['duration'])||isset($_POST['dressing_duration']))
		{
			$updateDosageOb = new classVisits;
			$updateDosageOb->setVisitID($visit_id);
			if(isset($_POST['dosage']))
			{	
				$updateDosageOb->setDosage($_POST['dosage']);
				$updateDosageOb->updateDosage();
			}
			
			if(isset($_POST['quantity']))
			{
				$updateDosageOb->setQuantity($_POST['quantity']);
				$updateDosageOb->updateDosageQuantity();
			}
			
			if(isset($_POST['duration']))
			{
				$updateDosageOb->setDuration($_POST['duration']);
				$updateDosageOb->updateDosageDuration();
			}
			if(isset($_POST['dressing_duration']))
			{
				$updateDosageOb->setDuration($_POST['dressing_duration']);
				$updateDosageOb->updateDressingDuration();
			}
		}
		
		if(isset($_POST['save_exit'])&&$_POST['save_exit']!='')
		{
			header("location:opdhistory.php");
		}

		
		
	}
	catch(MyException $e)
	{
		$error_message = $e->getUserMsg();
	}	
}
///////////// 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 patient image ///////////////////////////////
	
	$imageRetrieveOb = new classImages;
	$imageRetrieveOb->setPatientAutoID($patient_id);
	$image_id = $imageRetrieveOb->fetchImageOfPatient();
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	

try
{
	$retrieveOb = new classVisits;
	$retrieveOb->setOrganizationID($_SESSION['security']['org_id']);
	$medicine_array = $retrieveOb->retrieveMedicines();
	$labtest_array = $retrieveOb->retrieveLabTests();
	$procedure_array = $retrieveOb->retrieveProcedures();
	$dosage_array = $retrieveOb->retrieveDosage();
	$dressing_array = $retrieveOb->retrieveDressing();
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	

if(strtolower($visit_array[0]['pay_status'])=='paid')
{
	$type = 'hidden';
	$disable = 'disabled';
}
else
{
	$type = 'text';
	$disable = '';
}

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

?>
<!DOCTYPE html>
<html><!-- InstanceBegin template="/Templates/main.dwt.php" codeOutsideHTMLIsLocked="false" -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head> 
    <link rel="shortcut icon" href="../images/favicon.png">
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>Med2TEC Hospital Management Information System</title>
    <!-- InstanceEndEditable -->
    <!--Core CSS -->
    <link href="../bs3/css/bootstrap.min.css" rel="stylesheet"> 
    <link href="../css/style.css" rel="stylesheet">
    <link href="../css/style-responsive.css" rel="stylesheet"/> 
    <link href="../popUp/popUp.css" rel="stylesheet">
    <link href="../css/bootstrap-fullcalendar.css" rel="stylesheet"/> 
    
    <link href="../css/clndr.css" rel="stylesheet">
    
    <link href="../css/css/font-awesome.css" rel="stylesheet">
    
    <link href="../assets/jquery-ui/jquery-ui-1.10.1.custom.min.css" rel="stylesheet">
    <link href="../assets/jvector-map/jquery-jvectormap-1.2.2.css" rel="stylesheet">    
    <link href="../assets/jquery-multi-select/css/multi-select.css" rel="stylesheet" type="text/css">
    <!--clock css-->
    <link href="../assets/css3clock/css/style.css" rel="stylesheet"> 
    <!--Morris Chart CSS -->
    <link rel="stylesheet" href="../assets/morris-chart/morris.css">
    <!-- Custom styles for this template -->
   
    <link href="../datepicker/jquery-ui.css" rel="stylesheet" >   
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>
<body>

<section id="container">
    <!--header start-->
    <header class="header fixed-top clearfix">
        <!--logo start-->
        <div class="brand">

            <a href="home.php" class="logo">
                <img src="../images/logo.png" alt="">
            </a>
            <div class="sidebar-toggle-box">
                <div class="fa fa-bars"></div>  
            </div>
        </div> 
        <!--logo end-->

        <div class="nav notify-row" id="top_menu" style="float: right; margin-top: 16px; margin-left: 0px; margin-right: 10px;">
            <!--  notification start -->
             <img alt="" src="../images/org_logos/<?php echo $_SESSION['security']['org_id']?>.png">
            <!--  notification end -->
        </div>
        <div class="top-nav clearfix">
            <!--search & user info start-->
            <ul class="nav pull-right top-menu">
                <li>
                    <div class="toggle-right-box"><!-- InstanceBeginEditable name="print" -->
                    <a href="javascript:Popup('<?php echo prec_print_file;?>')"><i class="fa fa-print" style="margin-left: 11px; margin-top: 11px;"></i></a>
					<!-- InstanceEndEditable --></div>
                </li>
                <!-- user login dropdown start-->
                <li class="dropdown">
                    <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                        <img alt="" src="../images/avatar1_small.jpg"> 
                        <span class="username"><?php echo $username;?></span>
                        <b class="caret"></b>
                    </a>
                    <ul class="dropdown-menu extended logout">
                        <li><a href="profile.php"><i class=" fa fa-suitcase"></i>Profile</a></li>
                        <li><a href="#update_password-box" class="update_password-window"><i class="fa fa-cog"></i> Change Password</a></li>
                        <li><a href="../logout.php"><i class="fa fa-key"></i> Log Out</a></li>
                    </ul>
                </li>
                <!-- user login dropdown end -->
                <li>
                    <div class="toggle-right-box">
                        <div class="fa fa-bars"></div>
                    </div>
                </li>
            </ul>
            <!--search & user info end-->
        </div>
    </header>
    <!--header end-->
    <!--sidebar start-->
   <aside>
        <div id="sidebar" class="nav-collapse">
            <!-- sidebar menu start-->
            <ul class="sidebar-menu" id="nav-accordion">
					  	<li>
                    	<a class="active" href="db.php" style="background:#0072BC;">
                        <i class="fa fa-dashboard"></i>
                        <span>Dashboard</span>
                    	</a>
                		</li>
					  <?php
					  
				
					  
$orgOb = new classUser;
$orgOb->retrieveOrgDataByOrgID($_SESSION['security']['org_id']);
           
		  
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==5||$_SESSION['security']['userrole_id']==9||$_SESSION['security']['userrole_id']==10)
				{
					?>
					    <li class="sub-menu">
                    	<a href="dbpatient.php" style="background:#BC1C4A;">
                        <i class="fa fa-user"></i>
                        <span>Patient Registration</span>
                    	</a>
                    	</li>
					  <?php
				}
		  
		  if($orgOb->getOPD())
		  {
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==4||$_SESSION['security']['userrole_id']==5||$_SESSION['security']['userrole_id']==9)
				{
					?>
						<li class="sub-menu">
						<a href="dbopd.php" style="background:#003366;">
						<i class="fa fa-th"></i>
						<span>Out-Patient (OPD)</span>
						</a>
						</li>
						<?php
				}
		  }
		  if($orgOb->getIPD())
		  {
			  	?>
						<li class="sub-menu">
						<a href="dbipd.php" style="background:#3AC7F9;">
						<i class="fa fa-th"></i>
						<span>In-Patient (IPD)</span>
						</a>
						</li>
						<?php
					
		  }
		  if($orgOb->getOT())
		  {
			   		?>
						<li class="sub-menu">
						<a href="dbot.php" style="background:#D6502A;">
						<i class="fa fa-th"></i>
						<span>Operation Theater</span>
						</a>
						</li>
                        <?php
		  }			
		  if($orgOb->getPharmacy())
		  {
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==6||$_SESSION['security']['userrole_id']==7||$_SESSION['security']['userrole_id']==8||$_SESSION['security']['userrole_id']==9)
				{
			  		?>
						<li class="sub-menu">
						<a href="dbpharmacy.php" style="background:#00869C;">
						<i class="fa fa-th"></i>
						<span>Pharmacy</span>
						</a>
						</li>
						<?php
				}
		  }
		  if($orgOb->getDiagnostic())
		  {
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==14||$_SESSION['security']['userrole_id']==9)
				{
			  	?>
						<li>
						<a href="dbdiagnostics.php" style="background:#380E4D;">
						<i class="fa fa-th"></i>
						<span>Diagnostics </span>
						</a>
						</li>
						<?php
				}
		  }
		  if($orgOb->getEmergency())
		  {
					  ?>
						<li class="sub-menu">
						<a href="dbemergency.php" style="background:#8EC63F;">
						<i class="fa fa-tasks"></i>
						<span>Emergency </span>
						</a>
						</li>
						<?php
		  }
          if($orgOb->getAdmin())
		  {
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==9)
				{
					?>
						<li class="sub-menu">
						<a href="dbadmin.php" style="background:#28282E;">
						<i class="fa fa-laptop"></i>
						<span>Admin Panel</span>
						</a>
						</li>
						<?php
				}
		  }
		  ?>
               
            </ul> 
            <div style="position: absolute; bottom: 2%; padding-left:10%;"><a href="http://www.softusion.com/" target="_blank"><img width="30" height="40" src="../images/SoftusionLOGO.png" alt=""><span style="font-size: 11px; float: right; margin-top: 15%;">Designed by Softusion Inc.</span></a></div><br>
            <!-- sidebar menu end-->
        </div>
    </aside>
    <!--sidebar end-->
    <!--main content start-->
	<!-- InstanceBeginEditable name="center" -->
    

  <section id="main-content">
    <section class="wrapper">
  <table cellspacing="0" cellpadding="0" width="100%" border="0" style="font-size:11px;">
  <tbody>
    <tr>
      <td width="12%" align="center"><a href="dbopd.php"><img src="../images/icondb.png"></a></td>
      <td width="12%" align="center"><a href="mgmtshifts.php"><img src="../images/iconshifts.png"></a></td>
      <td width="12%" align="center"><a href="mgmtvisits.php"><img src="../images/iconvisits.png" /></a></td>
      <td width="12%" align="center"><a href="opdhistory.php"><img src="../images/iconhistory.png"></a></td>
      <td width="12%" align="center"><a href="#add_medicine-box" class="add_medicine-window" id="add_medicine"><img src="../images/iconnewmed.png" /></a></td>
      <td width="12%" align="center"><a href="#add_labtest-box" class="add_labtest-window" id="add_labtest"><img src="../images/iconlab.png" /></td>
      <td width="12%" align="center"><a href="#add_procedure-box" class="add_procedure-window" id="add_procedure"><img src="../images/iconradio.png" /></a></td>
      <td width="12%" align="center"></td>
      <td width="2%" align="center">&nbsp;</td>
    </tr>
    <tr>
      <td align="center"><a href="dbopd.php">Out Patient</a></td>
      <td align="center"><a href="mgmtshifts.php">Manage Shifts</a></td>
      <td align="center"><a href="mgmtvisits.php">Manage Visits</a></td>
      <td align="center"><a href="opdhistory.php">Clinical Overview</a></td>
      <td align="center"><a href="#add_medicine-box" class="add_medicine-window" id="add_medicine">Add New Medicine</a></td>
      <td align="center"><a href="#add_labtest-box" class="add_labtest-window" id="add_labtest">Add New Test</a></td>
      <td align="center"><a href="#add_procedure-box" class="add_procedure-window" id="add_procedure">Add New Procedure</a></td>
      <td align="center"></td>
      <td height="24" align="center">&nbsp; </td>
    </tr>
  </tbody>
</table>
<br>
 
      <!-- page start-->
      <div class="row" >
        <div class="col-sm-12" >
          <section class="panel">
          
           	<header class="panel-heading">
              <h2>PRESCRIPTION</h2>
            </header>
            <?php
			if(isset($error_message)&&$error_message!='')
			{
				?><span class="message_red"><?php echo $error_message;?></span><br><br>
				<?php
			}
			?>
           
           <form class="cmxform form-horizontal" method="post" action="">
           
           	<p align="left" style="left-margin:5px;">
            <input type="submit" value="Save & Exit" class="btn btn-success btn-sm" name="save_exit">
            <input type="submit" value="Add to Prescription" class="btn btn-success btn-sm" name="submit">
            </p>
            
            <div class="col-md-6">
            <section class="panel">
              <div class="panel-body">
              
                <table width="94%" cellpadding="2" cellspacing="0">
                <tr>
                  <td width="45%" align="left"  valign="top">Select Medicines:
                  <div class="row-fluid">
                    <div class="span6">
                        <div id="dynamic-table_length">
                        <label>
                            <select name="medicine_id[]"  class="form-control" aria-controls="dynamic-table" style=" width: 320px; height: 85px;" multiple>
                            <!--<option value="0">Select Medicines</option>-->
                            <?php
                            if(isset($medicine_array[0]['product_id']))
                            {
                                for($m=0;$m<count($medicine_array);$m++)
                                {
                                    $singleProdOb = new classProduct;
                                    $prod_loc_array = $singleProdOb->retrieveProductLocationRelationship($medicine_array[$m]['product_id'],$_SESSION['security']['location_id']);
                                    ?>
                                    <option value="<?php echo $medicine_array[$m]['product_id'];?>"><?php echo ucwords($medicine_array[$m]['product_name']).' - '.$medicine_array[$m]['medicine_type'].' - Qty : '.$prod_loc_array[0]['unit_qtyinstock'];?></option>
                                    <?php
                                }
                            }
                            ?>
                            </select>
                        </label>
                        </div>
                    </div>
                </div></td>
                <td width="45%" align="left"  valign="top">Select Lab Tests:
                  <div class="row-fluid">
                <div class="span6">
                    <div id="dynamic-table_length">
                        <label>
                            <select name="labtest_id[]"  class="form-control" aria-controls="dynamic-table" style=" width: 320px; height: 85px;" multiple>
                                <!--<option value="0">Select Lab Tests</option>-->
                                 <?php
                                if(isset($labtest_array[0]['labtest_id']))
                                {
                                    for($l=0;$l<count($labtest_array);$l++)
                                    {
                                        ?>
                                        <option value="<?php echo $labtest_array[$l]['labtest_id'];?>"><?php echo ucwords($labtest_array[$l]['labtest_name']);?></option>
                                        <?php
                                    }
                                }
                                ?>
                            </select>
                        </label>
                    </div>
                </div>
            </div></td>
                </tr>
                
                <tr>
                  <td align="left" valign="top">Select Procedures:
                  <div class="row-fluid">
                    <div class="span6">
                        <div id="dynamic-table_length">
                        <label>
                            <select name="procedure_id[]"  class="form-control" aria-controls="dynamic-table" style=" width: 320px; height: 85px;" multiple>
                                <!--<option value="0">Select Procedures</option>-->
                                <?php
                                if(isset($procedure_array[0]['procedure_id']))
                                {
                                    for($p=0;$p<count($procedure_array);$p++)
                                    {
                                        ?>
                                        <option value="<?php echo $procedure_array[$p]['procedure_id'];?>"><?php echo ucwords($procedure_array[$p]['procedure_name']);?></option>
                                        <?php
                                    }
                                }
                                ?>
                            </select>
                        </label>
                        </div>
                    </div>
                    </div>
                    </td>
                    <td align="left" valign="top">Select Dressing:
                  <div class="row-fluid">
                    <div class="span6">
                        <div id="dynamic-table_length">
                        <label>
                            <select name="dressing_id[]"  class="form-control" aria-controls="dynamic-table" style=" width: 320px; height: 85px;" multiple>
                                <option value="0">Select Dressing</option>
                                <?php
                                if(isset($dressing_array[0]['dressing_id']))
                                {
                                    for($d=0;$d<count($dressing_array);$d++)
                                    {
                                        ?>
                                        <option value="<?php echo $dressing_array[$d]['dressing_id'];?>"><?php echo ucwords($dressing_array[$d]['dressing']);?></option>
                                        <?php
                                    }
                                }
                                ?>
                            </select>
                        </label>
                        </div>
                    </div>
                    </div>
                   </td>
                </tr>
                </table>
                       
                </div>
            </section>
            <section class="panel">
             <table width="100%" class="display table table-bordered table-striped" id="dynamic-table">
                <tr>
                    <td><table width="100%" border="0">
                    <tr>
                    
                      <th width="10%" align="right">Temp: </th>
                      <td width="15%"><input type="text" value="<?php if(isset($visit_array[0]['temp'])){echo $visit_array[0]['temp'];}?>" class=" form-control1" id="lastname5" name="temp" style="width:100%;"></td>
                      
                      <th width="10%" align="right">BP: </th>
                      <td width="15%"><input type="text" value="<?php if(isset($visit_array[0]['bp'])){echo $visit_array[0]['bp'];}?>" class=" form-control1" id="lastname5" name="bp" style="width:100%;"></td>
                      
                      <th width="10%" align="right">BSR: </th>
                      <td width="15%"><input type="text" value="<?php if(isset($visit_array[0]['bsr'])){echo $visit_array[0]['bsr'];}?>" class=" form-control1" id="lastname5" name="bsr" style="width:100%;"></td>
                      
                      <th width="10%" align="right">Weight: </th>
                      <td width="15%"><input type="text" value="<?php if(isset($visit_array[0]['weight'])){echo $visit_array[0]['weight'];}?>" class=" form-control1" id="lastname5" name="weight" style="width:100%;"></td>
                      
                    </tr>
                    </table></td>
                </tr>
             </table> 
            </section>
          	</div>
          
            <div class="col-md-4" style="float: right;">
                <div class="profile-nav alt">
                    <section class="panel">
                    <div class="user-heading alt clock-row terques-bg">
                    
                    <h1><?php  if(isset($patient_single_detail[0]['patient_id'])){echo $patient_single_detail[0]['patient_id'];}?> - <?php if(isset($patient_single_detail[0]['patient_fname'])){echo $patient_single_detail[0]['patient_fname'].' '.$patient_single_detail[0]['patient_lname'];}else{echo 'Outdoor';}?></h1>
                    
                    <p class="text-left">Age: <?php echo $patient_age?> <span style="float:right; padding-right:10%;">Blood Group: <?php if(isset($patient_single_detail[0]['blood_group'])){echo $patient_single_detail[0]['blood_group'];}?></span></p>
                    
                    <br>
                    
                    <table width="100%" border="0">
                    <tr>
                            <td width="5%" align="left">Fee:</td>
                            <td width="20%"><input name="fee" type="text" size="10" value="<?php echo $visit_array[0]['fee'];?>" <?php echo $disable;?>/></td>
                            <td width="20%" align="left"></td>
                            <td width="5%"></td>
                            <td width="50%"><span style="float:right; padding-right:10%;">Payable: <?php echo $visit_array[0]['payable'];?></span></td>
                        </tr>
                    
                        <tr>
                            <td width="5%" align="left">Zakat:</td>
                            <td width="20%"><input name="zakat" type="text" size="7" value="<?php echo $visit_array[0]['zakat']; ?>" <?php echo $disable;?> /></td>
                            <td width="20%" align="left"></td>
                            <td width="5%"></td>
                            <td width="50%"></td>
                        </tr>
                        <tr>
                            <td width="5%" align="left">Khairat:</td>
                            <td width="20%"><input name="khairat" type="text" size="7" value="<?php echo $visit_array[0]['khairat']; ?>" <?php echo $disable;?> /></td>
                            <td width="20%" align="left"></td>
                            <td width="5%"></td>
                            <td width="50%"></td>
                        </tr>
                        <tr>
                            <td width="5%" align="left">Discount:</td>
                            <td width="20%"><input name="discount" type="text" size="7" value="<?php echo $visit_array[0]['discount']; ?>" <?php echo $disable;?> /></td>
                            <td width="20%" align="left"></td>
                            <td width="5%"></td>
                            <td width="50%"></td>
                        </tr>
                    </table>
                    
                    </div>
                    </section>
                </div>                
            </div>
            
            
            <div style="float: right;"><?php
			if(isset($image_id)&&$image_id!='')
			{
				?>
				<img src="../images/patient_images/<?php echo $image_id;?>.jpg" width="66" height="70">
				<?php
			}
			else
			{
				?>
				<img src="../images/photo.png" height="70" width="66">
				<?php
			}
			?>
          	</div>
            
            <div class="col-md-4" style="float: right;">
                    <div class="profile-nav alt">
                        <section class="panel">
                        <table width="50%" class="display table table-bordered table-striped" id="dynamic-table">
                            <tbody>
                            <tr>
                                <th width="50%" align="left">Tests</th>
                                <th width="50%" align="left">Procedures</th>
                            </tr>
                            <tr class="gradeX">
                                <td>
                            <?php
                            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();
                                    ?>
                                    <a href="?del_prec=<?php echo base64_encode($prec_array[$prm]['presc_item_id']);?>"><img border="0" alt="Delete" src="../images/cross.png"><?php echo ucwords($labtest_info[0]['labtest_name']);?></a>  <br>
                                    
                                    <?php
                                    }
                                }
                            ?>  
                            </td>
                                <td>
                            <?php
                            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();
                                    ?>
                                    <a href="?del_prec=<?php echo base64_encode($prec_array[$prm]['presc_item_id']);?>"><img border="0" alt="Delete" src="../images/cross.png"><?php echo ucwords($procedure_info[0]['procedure_name']);?></a> <br>
                                    
                                    <?php
                                }
                            }
                            ?> 
                            </td>
                            </tr>
                            </tbody>
                        </table>
                        </section>
                    </div>
                </div>
          
          	<div class="row">
                <div class="col-sm-12">
                
                <div class="col-md-6">
                
                    
                
                </div>
                
                <div class="col-md-4" style="float: right;">
                    <div class="profile-nav alt">
                      <section class="panel">
                        <table width="50%" class="display table table-bordered table-striped" id="dynamic-table">
                            <tbody>
                                <tr>
                                    <th width="100%" align="left">Medicines</th>
                                </tr>
                                <tr>
                                <th> 
                                <?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();
										?>
										<table width="100%" border="0">
										<tr>
											<th width="40%" align="right"><a href="?del_prec=<?php echo base64_encode($prec_array[$prm]['presc_item_id']);?>"><img border="0" alt="Delete" src="../images/cross.png"><?php echo ucwords($med_info[0]['product_name']);?></a> </th>
										
											<td width="30%">
											<select class="form-control input-sm m-bot15 urdu" id="dosage_select"  name="dosage[<?php echo $prec_array[$prm]['product_id']?>]">
											<option value="">Select dosage</option>
											<?php
											for($d=0;$d<count($dosage_array);$d++)
											{
												?>
												<option value="<?php echo $dosage_array[$d]['dosage_id']?>" <?php if($prec_array[$prm]['dosage_id']==$dosage_array[$d]['dosage_id']){echo 'selected';}?>><?php echo $dosage_array[$d]['dosage']?></option>
												<?php	
											}
											?>
                                            </select>
											</td>
                                            <td width="15%">
                                            <input class="form-control" type="text" name="quantity[<?php echo $prec_array[$prm]['product_id']?>]" value="<?php echo $prec_array[$prm]['quantity']?>">
                                           <?php 
										   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 = '';}
										   echo $type_of_med;
										   ?> 
											</td>
                                             <td width="15%">
												<input class="form-control" type="text"  name="duration[<?php echo $prec_array[$prm]['product_id']?>]" value="<?php echo $prec_array[$prm]['duration']?>">دن
											</td>
                                        </tr>
                                        
                                        <tr>
											
                                            
                                           
                                            
                                            
										</tr>
                                        </table>
                                        
                                        <hr>
										<?php
									}
                                }
								?>  
								</th>
                            
                            </tr>
                            </tbody>
                        
                        </table>
                      </section>
                    </div>
                     <div class="profile-nav alt">
                      <section class="panel">
                        <table width="100%" class="display table table-bordered table-striped" id="dynamic-table">
                            <tbody>
                                <tr>
                                    <th width="100%" align="left">Dressing/پٹی اور اس کا طریقہ:</th>
                                </tr>
                                <tr>
                                <th> 
                                <?php
							  	for($prm=0;$prm<count($prec_array);$prm++)
							  	{
									if($prec_array[$prm]['dressing_id']!=0)
									{	
										$retreiveDressOb = new classVisits;
										$retreiveDressOb->setDressingID($prec_array[$prm]['dressing_id']);
										$dress_info = $retreiveDressOb->retrieveDressingByID();
										?>
										<table width="100%" border="0">
										<tr>
											<td width="80%" align="right"><a href="?del_prec=<?php echo base64_encode($prec_array[$prm]['presc_item_id']);?>"><img border="0" alt="Delete" src="../images/cross.png"><?php echo ucwords($dress_info[0]['dressing']);?></a></td>
                                       <td width="20%">
                                            <input class="form-control" type="text"  name="dressing_duration[<?php echo $prec_array[$prm]['dressing_id']?>]" value="<?php echo $prec_array[$prm]['duration']?>">دن
                                        </td>
                                        
										</tr>
                                        </table>
                                        
                                        
										<?php
									}
                                }
								?>  
								</th>
                            
                            </tr>
                            </tbody>
                        
                        </table>
                      </section>
                    </div>
                </div>
                
                <div class="col-md-8">
                <section class="panel">
                    <table width="50%" class="display table table-bordered table-striped" id="dynamic-table">
                    <tbody>
                        <tr>
                            <th width="30%" align="left">Complaints</th>
                            <th width="35%" align="left">Diagnosis</th>
                            <th width="35%" align="center">Notes</th>
                        </tr>
                        <tr class="gradeX">
                            <td><textarea class="form-control" rows="5" cols="55" name="complaint" style="width: 214px;"><?php if(isset($visit_array[0]['complaint'])){echo $visit_array[0]['complaint'];}?></textarea></td>
                            <td><textarea class="form-control" rows="5" cols="55" name="diagnosis" style="width: 214px;"><?php if(isset($visit_array[0]['diagnosis'])){echo $visit_array[0]['diagnosis'];}?></textarea></td>
                            <td><textarea class="form-control" rows="5" cols="55" name="notes" style="width: 214px;"><?php if(isset($visit_array[0]['notes'])){echo $visit_array[0]['notes'];}?></textarea></td>
                        </tr>
                    </tbody>
                    </table>
                </section>
                </div>
              
                </div>
      		</div>
            
            <?php
			if(strtolower($visit_array[0]['pay_status'])=='paid')
			{
				?>
            	<input name="zakat" type="<?php echo $type;?>" value="<?php echo $visit_array[0]['zakat']; ?>"/>
            	<input name="khairat" type="<?php echo $type;?>" value="<?php echo $visit_array[0]['khairat']; ?>" />
            	<input name="discount" type="<?php echo $type;?>" value="<?php echo $visit_array[0]['discount'];?>"/>
                <input name="fee" type="<?php echo $type;?>" value="<?php echo $visit_array[0]['fee'];?>">
            	<?php
			}
			?>
        	
        	<input type="hidden" name="payment" value="<?php echo $visit_array[0]['payment'];?>">
        	</form>
            
        </section>
      
      <!-- page end-->
    </section>
  </section>
  <!-- InstanceEndEditable --><!--main content end-->
<!--right sidebar start-->
 
<!--right sidebar end-->
</section>
<!-- Placed js at the end of the document so the pages load faster -->
<!--Core js-->
<!--<script src="../js/jquery-1.10.2.min.js"></script>-->
  
 
<script src="../assets/jquery-ui/jquery-ui-1.10.1.custom.min.js"></script>
<script src="../bs3/js/bootstrap.min.js"></script>



<script src="../js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="../popUp/popUp.js"></script>
<script src="../js/ajax.js"></script>

<script src="../js/lib/jquery.js"></script>
<script src="../assets/fullcalendar/fullcalendar/fullcalendar.min.js"></script>
<script src="../js/calendar/external-dragging-calendar.js"></script>
<script src="../js/accordion-menu/jquery.dcjqaccordion.2.7.js"></script>
<script src="../js/scrollTo/jquery.scrollTo.min.js"></script>
<script src="../js/nicescroll/jquery.nicescroll.js" type="text/javascript"></script>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/flot-chart/excanvas.min.js"></script><![endif]-->
<script src="../assets/jQuery-slimScroll-1.3.0/jquery.slimscroll.js"></script>
<script src="../assets/skycons/skycons.js"></script>
<script src="../assets/jquery.scrollTo/jquery.scrollTo.js"></script>
<script src="../js/jquery.easing.min.js"></script>
<script src="../assets/calendar/clndr.js"></script>
<script src="../js/underscore-min.js"></script>
<script src="../assets/calendar/moment-2.2.1.js"></script>
<script src="../js/calendar/evnt.calendar.init.js"></script>
<script src="../assets/jvector-map/jquery-jvectormap-1.2.2.min.js"></script>
<script src="../assets/jvector-map/jquery-jvectormap-us-lcc-en.js"></script>
<script src="../assets/gauge/gauge.js"></script>



<!--clock init-->
<script src="../assets/css3clock/js/script.js"></script>
<!--Easy Pie Chart-->
<script src="../assets/easypiechart/jquery.easypiechart.js"></script>
<!--Sparkline Chart-->
<!--Morris Chart-->
<script src="../assets/morris-chart/morris.js"></script>
<script src="../assets/morris-chart/raphael-min.js"></script>
<!--jQuery Flot Chart-->
<script src="../assets/flot-chart/jquery.flot.animator.min.js"></script>
<script src="../assets/flot-chart/jquery.flot.growraf.js"></script>
<script src="../js/dashboard.js"></script>
<script src="../js/custom-select/jquery.customSelect.min.js" ></script>
<!--common script init for all pages-->
<script src="../js/scripts.js"></script>
<!--dynamic table initialization -->
<script src="../js/dynamic_table/dynamic_table_init.js"></script>



<!--dynamic table initialization -->
<script src="../js/dynamic_table/dynamic_table_init.js"></script>
<!--<start===================>-->
<script src="../js/lib/jquery.js"></script>


<script src="../bs3/js/bootstrap.min.js"></script>



<script class="include" type="text/javascript" src="../js/accordion-menu/jquery.dcjqaccordion.2.7.js"></script>

<script src="../js/scrollTo/jquery.scrollTo.min.js"></script>
<script src="../js/nicescroll/jquery.nicescroll.js" type="text/javascript"></script>
<!--Easy Pie Chart-->
<script src="../assets/easypiechart/jquery.easypiechart.js"></script>
<!--Sparkline Chart-->
<script src="../assets/sparkline/jquery.sparkline.js"></script>
<!--jQuery Flot Chart-->
<script src="../assets/flot-chart/jquery.flot.js"></script>
<script src="../assets/flot-chart/jquery.flot.tooltip.min.js"></script>
<script src="../assets/flot-chart/jquery.flot.resize.js"></script>
<script src="../assets/flot-chart/jquery.flot.pie.resize.js"></script>
<script type="text/javascript" src="../assets/bootstrap-daterangepicker/daterangepicker.js"></script>
<script type="text/javascript" src="../assets/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>

<!--dynamic table-->
<!--common script init for all pages-->
<script src="../js/scripts.js"></script>

<!--dynamic table initialization -->
<script src="../js/dynamic_table/dynamic_table_init.js"></script>

<script type="text/javascript" src="../datepicker/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../datepicker/jquery-ui.js"></script>

<!--<script type="text/javascript" src="../popUp/jquery-1.9.0.js"></script>-->
<script type="text/javascript">

 function Popup(apri) { 
	window.open(apri,"","top=10,left=200,width=800,height=700,status=no,menubar=no,toolbar=no,scrollbars=yes"); 
 }
</script> 

<div id="update_password-box" class="update_password-popup">
    
    <div class="pop_header">
        <span>Change Password</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <table width="100%" border="0" cellspacing="2" cellpadding="2" class="panel">
      <tr>
        <td>
          <div id="result_update_password_form"></div>
          
          <form action="" method="post" id="update_password_form" class="cmxform form-horizontal" onSubmit="return false;">
          	
            <br>
            
         	<div class="form-group">
            <label class="control-label col-lg-3" for="lastname">New Password:</label>
                <div class="col-lg-6">
                    <input type="password" name="password" class="form-control" value="" id="exampleInputPassword1">
                </div>
            </div>
           
            <p align="right">
            	<input type="hidden" name="user_id" value="<?php if(isset($user_id)&&$user_id!=''){echo $user_id;}else{ echo 
				$_SESSION['security']['user_id'];}?>">
                <input type="hidden" name="updateUserPwd" value="yes">
                <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Update"/>
            </p>
            
          </form>
          </td>
          
      </tr>
    </table>
</div> 
 
</body>  
<!-- InstanceEnd --></html>

<div id="add_medicine-box" class="add_medicine-popup">
    
    <div class="pop_header">
        <span>Add Medicine</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <table width="100%" border="0" cellspacing="2" cellpadding="2" class="panel">
      <tr>
        <td>
          <div id="result_insert_medicine_form"></div>
          
          <form action="" method="post" id="insert_medicine_form" class="cmxform form-horizontal" onsubmit="return false;">
          
          	<div class="form-group">
            <label class="control-label col-lg-3" for="firstname">Medicine:</label>
            	<div class="col-lg-6">
                     <input type="text" name="medicine_name" id="medicine_name" value="" class="form-control">
                </div>
            </div>
            
            <div class="form-group">
            <label class="control-label col-lg-3" for="password">Medicine Type:</label>
                <div class="col-lg-6">
                <select name="medicine_type" class="form-control input-sm m-bot15">
                
                <option  value="Tablets/Capsules">Tablets/Capsules</option>
                <option value="Cream">Cream</option>
                <option value="Ointment">Ointment</option>
                <option value="Syrup">Syrup</option>
                <option value="Injection">Injection</option>
                <option value="Sachet">Sachet</option>
                <option value="Lotion">Lotion</option>
                <option value="Drops">Drops</option>
                <option value="Gel">Gel</option>
                <option value="Soap">Soap</option>
                <option value="Paste">Paste</option>
                <option value="Other">Other</option>
                </select>
                </div>
            </div>
            
            
            <p align="right">
                <input type="hidden" name="add_medicine" value="Add_medicine">
               <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Add"/>
            </p>
            
          </form>
          </td>
          
      </tr>
      
      <tr>
      	<td><a href="mgmtprescmedicines.php">Manage Medicines</a></td>
      </tr>
    </table>
</div>

<div id="add_labtest-box" class="add_labtest-popup">
    
    <div class="pop_header">
        <span>Add Lab Test</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <table width="100%" border="0" cellspacing="2" cellpadding="2" class="panel">
      <tr>
        <td>
          <div id="result_insert_labtest_form"></div>
          
          <form action="" method="post" id="insert_labtest_form" class="cmxform form-horizontal" onsubmit="return false;">
          
          	<div class="form-group">
            <label class="control-label col-lg-3" for="firstname">Lab Test:</label>
            	<div class="col-lg-6">
                     <input type="text" name="labtest_name" id="labtest_name" value="" class="form-control">
                </div>
            </div>
            
            
            <p align="right">
                <input type="hidden" name="add_labtest" value="Add_labtest">
               <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Add"/>
            </p>
            
          </form>
          </td>
          
      </tr>
      
      <tr>
      	<td><a href="mgmtpresctests.php">Manage Lab Tests</a></td>
      </tr>
      
    </table>
</div>

<div id="add_procedure-box" class="add_procedure-popup">
    
    <div class="pop_header">
        <span>Add Procedure</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <table width="100%" border="0" cellspacing="2" cellpadding="2" class="panel">
      <tr>
        <td>
          <div id="result_insert_procedure_form"></div>
          
          <form action="" method="post" id="insert_procedure_form" class="cmxform form-horizontal" onsubmit="return false;">
          
          	<div class="form-group">
            <label class="control-label col-lg-3" for="firstname">Procedure:</label>
            	<div class="col-lg-6">
                     <input type="text" name="procedure_name" id="procedure_name" value="" class="form-control">
                </div>
            </div>
            
            
            <p align="right">
                <input type="hidden" name="add_procedure" value="Add_procedure">
               <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Add"/>
            </p>
            
          </form>
          </td>
          
      </tr>
      
       <tr>
      	<td><a href="mgmtprescprocedures.php">Manage Procedures</a></td>
      </tr>
      
    </table>
</div>

<!--<script>

 $(document).ready(function(e) {
	 
    $('#dosage_input').keypress(function(e) {
        $('#dosage_select').remove()
    });
	
	 $('#dosage_select').change(function(e) {
        $('#dosage_input').remove()
    });
		
});
	 
	 
</script> -->
<script type="text/javascript">

     function Popup(apri) { 
        window.open(apri,"","top=10,left=200,width=950,height=700,status=no,menubar=no,toolbar=no,scrollbars=yes"); 
     }
	 
	 
</script> 