ward<?php
include('../config/config.php');
include('../classes/classPatient.php');
include("../classes/classImages.php");
include("../classes/classWardMgmt.php");

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

################## Delete Patient Start ####################################

if(isset($_GET['delAllotID'])&&$_GET['delAllotID']!='')
{
	try
	{
		$delBedAllotOb = new classWardMgmt;
		$delBedAllotOb->setWardBedAllotID(base64_decode($_GET['delAllotID']));
		$delBedAllotOb->deleteBedAllotment();
	}
	catch (MyException $e)
	{
		$error_message = $e->getUserMsg();
	}
}

################# retrieve all wards #######################################

if(isset($_POST['search_bed_no'])&&$_POST['search_bed_no']!='')
{
	$search_ipd_bed_no = $_POST['search_bed_no'];
}
else
{
	$search_ipd_bed_no = NULL;
}

if(isset($_POST['search_patient_name'])&&$_POST['search_patient_name']!='')
{
	$search_patient_name = $_POST['search_patient_name'];
}
else
{
	$search_patient_name = NULL;
}


try
{
	$wardOb = new classWardMgmt;
	$ward_array = $wardOb->retrieveWardAndBeds($_SESSION['security']['location_id'],$search_ipd_bed_no,$search_patient_name,'Occupied');
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}


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

?>
<!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></head><!-- 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" --><!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->

                   
					
    <title>Med2TEC Hospital Management Information System</title>
    
  <section id="main-content">
    <section class="wrapper">
      <!-- page start-->
      	<div class="row">
        <div class="col-sm-12">
          <section class="panel">
           	<header class="panel-heading">
              <h2>IPD BEDS REGISTER</h2>
            </header>

            
            <div class="panel-body">
              <div class="adv-table">
              
             	 <table class="bottomBorder" width="100%" cellpadding="0" cellspacing="0">
                
                  <thead>
                  
                    <tr>
                      
                      <th width="15%">Ward</th>
                      <th width="85%">
                  
                  </th>                      
                    </tr>
                    
                  </thead>
                  
                  <tbody>
                   <?php
					if(isset($ward_array[0]['ipd_ward_id'])&&$ward_array[0]['ipd_ward_id']!='')
					{
						for($w=0;$w<count($ward_array);$w++)
						{
							
							$ipd_ward_id = $ward_array[$w]['ipd_ward_id'];
							$ipd_ward_id_encode = base64_encode($ipd_ward_id);
							
							$ipd_ward_no = $ward_array[$w]['ipd_ward_no'];
							$ipd_ward_type = ucwords(str_replace('_',' ',$ward_array[$w]['ipd_ward_type']));
							$staff_id = $ward_array[$w]['staff_id'];
							$no_of_beds = $ward_array[$w]['no_of_beds'];
							
							?>
					<tr>
                      
                      <td><?php echo $ipd_ward_no;?> - <?php echo $ipd_ward_type;?><br />
                      <span class="message_grey">No. of Beds: <?php echo $no_of_beds;?></span></td>
                      <td>
                     
                             <?php
							if(isset($ward_array[$w]['bed_details'][0])&&$ward_array[$w]['bed_details'][0]!='')
							{
								for($wb=0;$wb<count($ward_array[$w]['bed_details']);$wb++)
								{
									
									
									$ipd_bed_id = $ward_array[$w]['bed_details'][$wb]['ipd_bed_id'];
									$ipd_bed_id_encode = base64_encode($ipd_bed_id);
									
									$ipd_bed_no = $ward_array[$w]['bed_details'][$wb]['ipd_bed_no'];
									$ipd_bed_fee = $ward_array[$w]['bed_details'][$wb]['ipd_bed_fee'];
									$ipd_bed_type = $ward_array[$w]['bed_details'][$wb]['ipd_bed_type'];
									$status = $ward_array[$w]['bed_details'][$wb]['status'];
									
									$patient_id = $ward_array[$w]['bed_details'][$wb]['patient_id'];
									$patient_name = $ward_array[$w]['bed_details'][$wb]['patient_name'];
									$allot_time = $ward_array[$w]['bed_details'][$wb]['allot_time'];
									$discharge_due_time = $ward_array[$w]['bed_details'][$wb]['discharge_due_time'];
									$ipd_bed_allotment_id = $ward_array[$w]['bed_details'][$wb]['ipd_bed_allotment_id'];
									$ipd_bed_allotment_id_encoded = base64_encode($ward_array[$w]['bed_details'][$wb]['ipd_bed_allotment_id']);
									
									$discharge_slip_created = $ward_array[$w]['bed_details'][$wb]['discharge_slip_created'];
									
									if($patient_id!=0)
									{
										$imageRetrieveOb = new classImages;
										$imageRetrieveOb->setPatientAutoID($patient_id);
										$image_id = $imageRetrieveOb->fetchImageOfPatient();
									}
									
									if($status=='Empty')
									{
										$image = 'bed_green';
										$button_type = '<a href="#allocate_ipdwardbed-box" class="allocate_ipdwardbed-window btn btn-success btn-sm allocate_ipdwardbed" id="'.$w.$wb.'">Allocate</a>';
										
										$transfer_button = '';
										
										$cancel_button = '';
									}
									if($status=='Occupied')
									{
										$image = 'bed_red';
										
										if($discharge_slip_created){$button_class = 'btn-success';}else{$button_class = 'btn-danger';}
										$button_type = "";
										
										$transfer_button = '<a href="#transfer_ipdwardbed-box" class="transfer_ipdwardbed-window btn btn-success btn-sm transfer_ipdwardbed" id="'.$w.$wb.'">Transfer</a>';
										
										$cancel_button = '';
									}
									if($status=='Reserved')
									{
										$image = 'bed_yellow';
										$button_type = '<a href="#allocate_ipdwardbed-box" class="allocate_ipdwardbed-window btn btn-success btn-sm allocate_reserved_ipdwardbed" id="'.$w.$wb.'">Allocate</a>';
										
										$transfer_button = '';
										
										$cancel_button = " <a href='?cbr=$ipd_bed_id_encode&cbra=$ipd_bed_allotment_id_encoded'>Cancel Reservation</a>";
										
									}
									
									?>
                                    
                                    <table width="100%" class="display table table-bordered table-striped">
                                    <tr>
                                      <td width="10%" align="left"><img src="../images/<?php echo @$image;?>.png" /></td>
                                      <td width="25%" align="left"><strong><?php echo $ipd_bed_no;?></strong><br />
                                      Fee: Rs. <?php echo number_format($ipd_bed_fee,2);?>
                                      <p>
                                      <span class="message_grey">Detail: <?php echo $ipd_bed_type;?></span>
                                      </p></td>
                                      <td width="5%" ><?php
										if(isset($image_id)&&$image_id!='')
										{
											?>
											<img src="../images/patient_images/<?php echo $image_id;?>.jpg" width="60" height="60" />
											<?php
										}
										else
										{
											?>
											<img src="../images/photo.png" width="60" height="60" />
											<?php
										}
										?></td>
                                      <td width="40%"><strong>Patient: <?php echo $patient_id;?> - <?php echo $patient_name;?></strong>
                                      <p>
                                      Admission No: <?php echo $ipd_bed_allotment_id;?><br />
                                      Admitted at: <?php echo $allot_time;?><br />
                                      Discharge Due at: <?php echo $discharge_due_time;?></p></td>
                                      
                                      <td width="10%" align="center"></td>
                                      
                                      <td width="10%" align="center"><?php echo $button_type;?></td>
                                      
                                    </tr>
                                     </table>

                                    
                            		
									<?php 
								}
								
							}
							else
							{
								?>
								There are no beds in this ward.<p>
								<?php
							}
						?>
                      
                      
                      </p></td>
                      
                    </tr>
                    </tbody>
                    <?php	
                         }
					}
					else
					{
						?>
                        <tr>
                             <td colspan="6">All Beds are currently empty!</td>
                        </tr>
                        <?php
					}
					?>       
                  
                  
               </table>
                
               
                <!--<div class="row-fluid">
                  <div class="span6">
                    <div class="dataTables_info" id="hidden-table-info_info">Showing 1 to 10 of 57 entries</div>
                  </div>
                  <div class="span6">
                    <div class="dataTables_paginate paging_bootstrap pagination">
                    
                      <ul>
                        <li class="prev disabled"><a href="#">? Previous</a></li>
                        <li class="active"><a href="#">1</a></li>
                        <li><a href="#">2</a></li>
                        <li><a href="#">3</a></li>
                        <li><a href="#">4</a></li>
                        <li><a href="#">5</a></li>
                        <li class="next"><a href="#">Next ? </a></li>
                      </ul>
                    </div>
                  </div>
                </div>-->
              </div>
            </div>
          </section>
        </div>
      </div>
      <!-- page end-->
      
    </section>
  </section>
  

  <!-- 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>


  
<script>
$(".discharge_ipdwardbed").click(function() {
	var id = this.id;
	//alert(id);
	ipd_bed_id = $("#ipd_bed_id_"+id).val();
	$("#discharge_bed_id").val(ipd_bed_id);
	
	ipd_ward_no = $("#ipd_ward_no_"+id).val();
	$("#dis_ward_no").html(ipd_ward_no);
	
	ipd_bed_no = $("#ipd_bed_no_"+id).val();
	$("#dis_bed_no").html(ipd_bed_no);
	
	ipd_bed_allotment_id = $("#ipd_bed_allotment_id_"+id).val();
	$("#dis_bed_allotment_id").val(ipd_bed_allotment_id);
	
	ipd_patient_id = $("#ipd_patient_id_"+id).val();
	$("#discharge_patient_id").val(ipd_patient_id);
	
	ipd_patient_name = $("#ipd_patient_name_"+id).val();
	$("#discharge_patient_name").html(ipd_patient_name);
});

$(function() {
		
		
		
		$("#datepicker2").datepicker({
		showOn: "button",
		buttonImage: "../images/calendar.gif",
		buttonImageOnly: true,
		changeMonth: true,
		changeYear: true,
		dateFormat: "yy-mm-dd",
		minDate: '0'
		});
	
	});
</script>


<!--<script type="text/javascript" src="../timepicker/lib/bootstrap-datepicker.js"></script>
<link rel="stylesheet" type="text/css" href="../timepicker/lib/bootstrap-datepicker.css" />

<script type="text/javascript" src="../timepicker/dist/datepair.js"></script>           
<script type="text/javascript" src="../timepicker/dist/jquery.datepair.js"></script>
-->

<script>


$('#dis_time').timepicker();
	
</script>