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

if(isset($_GET['cbr'])&&$_GET['cbr']!='')
{
	$cbrID = base64_decode($_GET['cbr']);
	$cbra = base64_decode($_GET['cbra']);
	
	$canceResOb = new classWardMgmt;
	$canceResOb->setWardBedID($cbrID);
	$canceResOb->setWardBedStatus('Empty');
	$canceResOb->updateWardBedStatus();
	
	$canceResOb->setWardBedAllotID($cbra);
	$canceResOb->deleteBedAllotment();
	
	header("Location:mgmtadmissions.php");
}
################# 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);
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}


try
{
	$wardDDOb = new classWardMgmt;
	$wardDDOb->setLocationID($_SESSION['security']['location_id']);
	$ward_dropdown = $wardDDOb->retrieveAllWards();
	$bed_dropdown = $wardDDOb->retrieveAllEmptybedOfWard();
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}



?>
<!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="#"><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="dbipd.php"><img src="../images/icondb.png"></a></td>
      <td width="12%" align="center"><a href="mgmtinpatients.php"><img src="../images/iconipd.png"></a></td>
              <td width="12%" align="center"></td>
              <td width="12%" align="center"></td>
              <td width="12%" align="center"></td>
              <td width="12%" align="center"></td>
              <td width="12%" align="center"></td>
              <td width="12%" align="center"></td>
              <td width="12%" align="center"></td>
              <td width="2%" align="center">&nbsp;</td>
            </tr>
            <tr>
              <td align="center"><a href="dbipd.php">In Patient</a></td>
      <td align="center"><a href="mgmtinpatients.php">Beds Register</a></td>
              <td align="center"></td>
              <td align="center"></td>
              <td align="center"></td>
              <td align="center"></td>
              <td align="center"></td>
              <td align="center"></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>ADMISSIONS & DISCHARGE</h2>
            </header>
            
            <?php
            if(isset($error_message)&&$error_message!='')
            {
                ?>
                <tr>
                    <td><span class="message_red"><?php echo $error_message;?></span></td>
                </tr>
                <?php
            }
            ?>
            
            <table width="100%" border="0" cellpadding="1" cellspacing="0">
             <form action="" method="post">
              <tr>
              
                <td width="10%" align="right">Search Bed No: </td>
                <td width="10%">
                	<input type="text" name="search_bed_no" value="" class="form-control" aria-controls="dynamic-table">
                </td>
                
                <td width="10%" align="right">Patient Name: </td>
                <td width="15%">
                	<input type="text" name="search_patient_name" value="" class="form-control" aria-controls="dynamic-table">
                </td>
                
                <td width="5%"><input name="search" type="submit" class="btn btn-success btn-sm" value="Search"/></td>
                
                <td width="5%" align="right"><a href="mgmtadmissions.php">View All</a></td>
                
                <!--<td width="5%" align="right">Phone: </td>
                <td width="15%">
                	<input type="text" class="form-control" aria-controls="dynamic-table">
                </td>-->
                
                <td width="15%" align="right"><div class="row-fluid"></div></td>
                <td width="10%"></td>
              </tr>
              </form>
            </table>
            
            <br><br><br>
            
            <div class="panel-body" style="padding-top: 0px; margin-top: -34px;">
              <div class="adv-table">
              
              	<table  class="display table table-bordered" id="dynamic-table">
                
                  <thead>
                  
                    <tr>
                      
                      <th width="15%">Ward</th>
                      <th width="65%"> <!--<table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="20%">Beds</td>
                      <td width="20%"></td>
                      <td width="20%">Fee</td>
                      <td width="30%">Detail</td>
                      <td width="10%"></td></table>-->
                  
                  </th>
                      <th width="10%">No. of Beds</th>
                      <th width="10%">Ward Incharge</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;?></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_ward_id = $ward_array[$w]['bed_details'][$wb]['ipd_ward_id'];
									
									$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_id_encoded = base64_encode($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($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 = '';
										$show_info = "";
										
										
									}
									if($status=='Occupied')
									{
										$image = 'bed_red';
										
										if($discharge_slip_created)
										{
											$button_type = "<a href='ipddischarge.php?patient_id=$patient_id_encoded&allot_id=$ipd_bed_allotment_id_encoded' class='btn btn-danger btn-sm' id='$w$wb'>Discharge</a>";
										}
										else
										{
											$button_type = "<span class='btn btn-sm' style='background-color: #ccc; color:white;'>Discharge</span>";
										}
										
										$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 = '';
										$show_info = "Occupied by: $patient_name <br>
										Admitted at: $allot_time <br>
										Discharge Due at: $discharge_due_time <br><br>";
									}
									
									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>";
										$show_info = "Reserved by: $patient_name <br>
										Reserved at: $allot_time <br>";
									}
									
									?>
                                    
                                    <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="30%" align="left"><strong><?php echo $ipd_bed_no;?></strong><br>
                                    Fee: Rs. <?php echo number_format($ipd_bed_fee,2);?>
                                    <p>
                                    <span style="float:left;">Detail: <?php echo $ipd_bed_type;?></span></td>
                                    
                                    <td width="60%">
                                    <strong>Status: <?php echo $status.$cancel_button;?></strong><br>
                                    <?php echo $show_info;?>
                                    <span style="float:right;"><?php echo @$button_type;?> <?php echo @$transfer_button;?></span>     								</td>
                                    
                                    </tr>
                                    </table>

                                    
                                    <input type="hidden" name="ipd_ward_id" class="set_to_pop" id="ipd_ward_id_<?php echo $w.$wb;?>" value="<?php echo $ipd_ward_id;?>">
                                    <input type="hidden" name="ipd_bed_id" class="set_to_pop" id="ipd_bed_id_<?php echo $w.$wb;?>" value="<?php echo $ipd_bed_id;?>">
                                    
                                    <input type="hidden" name="ipd_bed_allotment_id" class="set_to_pop" id="ipd_bed_allotment_id_<?php echo $w.$wb;?>" value="<?php echo $ipd_bed_allotment_id;?>">
                                    
                                    <input type="hidden" name="ipd_patient_id" class="set_to_pop" id="ipd_patient_id_<?php echo $w.$wb;?>" value="<?php echo $patient_id;?>">
                                    <input type="hidden" name="ipd_patient_name" class="set_to_pop" id="ipd_patient_name_<?php echo $w.$wb;?>" value="<?php echo $patient_name;?>">
                                    
                                    <input type="hidden" name="ipd_ward_no" class="set_to_pop" id="ipd_ward_no_<?php echo $w.$wb;?>" value="<?php echo $ipd_ward_no;?>">
                                    
                                    <input type="hidden" name="ipd_bed_no" class="set_to_pop" id="ipd_bed_no_<?php echo $w.$wb;?>" value="<?php echo $ipd_bed_no;?>">
									<?php 
								}
								
							}
							else
							{
								?>
								There are no beds in this ward.<p>
								<?php
								
							}
						?>
                      
                      
                      </td>
                      		<td align="right"><?php echo $no_of_beds;?></td>
                      		<td><?php echo $staff_id;?></td>
                      
                            </tr>
                            <input type="hidden" name="ipd_ward_id" class="set_to_pop" id="ipd_ward_id_<?php echo $w;?>" value="<?php echo $ipd_ward_id;?>">
                            <input type="hidden" name="ipd_ward_no" class="set_to_pop" id="ipd_ward_no_<?php echo $w;?>" value="<?php echo $ipd_ward_no;?>">
                            <input type="hidden" name="ipd_ward_type" class="set_to_pop" id="ipd_ward_type_<?php echo $w;?>" value="<?php echo $ward_array[$w]['ipd_ward_type'];?>">
                            
                            <input type="hidden" name="staff_id" class="set_to_pop" id="staff_id_<?php echo $w;?>" value="<?php echo $staff_id;?>">	
                            <?php	
                         }
					}
					else
					{
						?>
                        <tr>
                             <td colspan="6">No Ward entered yet!</td>
                        </tr>
                        <?php
					}
					?>       
                  </tbody>
                  
               </table>
                
              </div>
            </div>

            
            
          </section>
        </div>
      </div>
      <!-- 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="select_patient-box" class="select_patient-popup">
    
    <div class="pop_header">
        <span>Select Patient</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <div class="scrollbar" style="height:300px;">
    
   		<form action="" method="post" id="patient_search_form">
    	<table width="100%" border="0" cellpadding="1" cellspacing="0">
         
          <tr>
          
            <td width="12%" align="right">Search Name: </td>
            <td width="15%">
                <input type="text" name="by_name" id="by_name" value="" class="form-control" aria-controls="dynamic-table">
            </td>
            
            <td width="5%" align="right">ID: </td>
            <td width="15%">
                <input type="text" name="by_id" id="by_id" value="" class="form-control" aria-controls="dynamic-table">
            </td>
            
            <td width="5%" align="right">Phone: </td>
            <td width="15%">
                <input type="text" name="by_phone" id="by_phone" value="" class="form-control" aria-controls="dynamic-table">
            </td>
            
            <td><input name="search" type="submit" id="patient_search" class="btn btn-success btn-sm" value="Search"/></td>
            
            <td width="15%" align="left"><a href="mgmtbeds" id="view_all_patients">View All</a></td>
            
          
          </tr>
        </table>
        <input type="hidden" name="search_patient" value="Search">
        <input type="hidden" name="refferer" value="mgmtbeds">
        
        </form>  
         
    	<table class="display table table-bordered table-striped" id="dynamic-table">
        
          <thead>
            <tr>
              <th width="5%" align="center">&nbsp;</th>
              <th width="5%" align="center">&nbsp;</th>
              <th width="5%" align="center">ID</th>
              <th width="10%" align="center">DOB</th>
              <th width="20%">Patient Name</th>
              <th width="15%">Phone</th>
              <th width="15%">Registration Date</th>
            </tr>
          </thead>
          <tbody id="default_body">
          
          </tbody>
         
        </table>
        
    </div>
    
</div>

<div id="allocate_ipdwardbed-box" class="allocate_ipdwardbed-popup">
    
    <div class="pop_header">
        <span>Allocate Bed to Patient</span>
        <a href="#" class="pop2_close" style="float:right;">Close (X)</a>
    </div>
    
    <table width="100%" border="0" cellspacing="2" cellpadding="2" class="panel">
        <tr>
            <td>
            
            <div id="result_allocate_ipdwardbed_form"></div>
            
            <form action="" method="post" id="allocate_ipdwardbed_form" class="cmxform form-horizontal" onsubmit="return false;">
            
            <div class="form-group">
                <label class="control-label col-lg-3" for="firstname">Ward No:</label>
                <div class="col-lg-6" id="ipd_ward_no" style="margin-top:7px;">
                	
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-lg-3" for="firstname">Bed No:</label>
                <div class="col-lg-6" id="ipd_bed_no" style="margin-top:7px;">
                	
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-lg-3" for="firstname">Patient: </label>
                
                <div class="col-lg-6" id="patient_name" style="margin-top:7px;">
                <a href="#select_patient-box" class="select_patient-window"  id="select_patient_popup">Select Patient</a>
                </div>
                 
            </div>
            
            <div class="form-group">
                <label class="control-label col-lg-3" for="firstname">Allocation Time:</label>
                <div class="col-lg-6">
                	<input type="text" name="allocation_date_due" value="<?php echo date('Y-m-d',time());?>" id="datepicker" style="width:45%; display:inline;" readonly>
                    <input id="allocation_time_due" name="allocation_time_due" type="text" class="time" value="<?php echo date('H:i A',time());?>"  style="width:45%;"/>
                </div>
            </div>
            
            <div class="form-group">
                <label class="control-label col-lg-3" for="firstname">Discharge Due at:</label>
                <div class="col-lg-6">
                	<input type="text" name="discharge_date_due" value="<?php echo date('Y-m-d',time());?>" id="datepicker1"  style="width:45%; display:inline;" readonly>
                    <input id="discharge_time_due" name="discharge_time_due" type="text" class="time" value="<?php echo date('H:i A',strtotime('+1 hour'));?>"  style="width:45%;"/>
                </div>
            </div>
            
            <div class="form-group" id="bed_status">
           	 	<label class="control-label col-lg-3" for="firstname">Bed Status:</label>
                <div class="col-lg-6">
                    <select name="bed_status"  class="form-control">
                        <option value="Occupied">Allocate</option>
                        <option value="Reserved">Reserve</option>
                    </select>
                    
                </div>
            </div>
            
           
            <p align="right">
            	<input type="hidden" name="bed_id" id="bed_id_allot" value="">
                <input type="hidden" name="patient_id" id="patient_id" value="">
                <input type="hidden" name="ward_id" id="ward_id" value="">
                <input type="hidden" name="ipd_bed_allotment_id" id="ipd_bed_allotment_id" value="">
            	<input type="hidden" name="allocate_ipdwardbed" value="Allocate_ipdwardbed">
                <input type="hidden" id="allocate_type" name="allocate_type" value="allocate_new">
                <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Allocate"/>
            </p>
            
            </form>
            
            </td>
        </tr>
    </table>
    
</div>

<div id="transfer_ipdwardbed-box" class="transfer_ipdwardbed-popup">
    
    <div class="pop_header">
        <span>Transfer Patient to Another Bed</span>
        <a href="#" class="pop2_close" style="float:right;">Close (X)</a>
    </div>
    
    <table width="100%" border="0" cellspacing="2" cellpadding="2" class="panel">
        <tr>
            <td>
            
            <div id="result_transfer_ipdwardbed_form"></div>
            
            <form action="" method="post" id="transfer_ipdwardbed_form" class="cmxform form-horizontal" onsubmit="return false;">
            
            <div class="form-group">
           	 	<label class="control-label col-lg-3" for="firstname">Patient:</label>
                <div class="col-lg-6" id="transfer_patient_name"></div>
            </div>
            
            <div class="form-group">
           	 	<label class="control-label col-lg-3" for="firstname">Current Bed:</label>
                <div class="col-lg-6" id="current_bed_no"></div>
            </div>
            
            <div class="form-group">
           	 	<label class="control-label col-lg-3" for="firstname">Transfer to Ward:</label>
                <div class="col-lg-6">
                    <select name="ward_id" id="ajax_ward_id"  class="form-control">
                        <option value="0">Select Ward</option>
                        <?php
                        for($wdd=0;$wdd<count($ward_dropdown);$wdd++)
                        {
                            ?>
                            <option value="<?php echo $ward_dropdown[$wdd]['ipd_ward_id']?>"><?php echo ucwords($ward_dropdown[$wdd]['ipd_ward_no'].'-'.str_replace('_',' ',$ward_dropdown[$wdd]['ipd_ward_type']));?></option>
                            <?php
                        }
                        ?>
                    </select>
                </div>
            </div>
            
            <div class="form-group">
           	 	<label class="control-label col-lg-3" for="firstname">Transfer to Bed:</label>
                <div class="col-lg-6">
                    <select name="bed_id" id="ajax_bed_id"  class="form-control">
                        <option value="">Select Bed</option>
                    </select>
                </div>
            </div>
            
            <p align="right">
            	<input type="hidden" name="ipd_bed_allotment_id" id="transfer_bed_allotment_id" value="">
            	<input type="hidden" name="transfer_ipdwardbed" value="Transfer_ipdwardbed">
                <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Transfer"/>
            </p>
            
            </form>
            
            </td>
        </tr>
    </table>
    
</div>



<script>

$(".allocate_ipdwardbed").click(function() {
	var id = this.id;
	//alert(id);
	ipd_bed_id = $("#ipd_bed_id_"+id).val();
	$("#bed_id_allot").val(ipd_bed_id);
	
	ipd_ward_id = $("#ipd_ward_id_"+id).val();
	$("#ward_id").val(ipd_ward_id);
	
	ipd_ward_no = $("#ipd_ward_no_"+id).val();
	$("#ipd_ward_no").html(ipd_ward_no);
	
	ipd_bed_no = $("#ipd_bed_no_"+id).val();
	$("#ipd_bed_no").html(ipd_bed_no);
});

$(".allocate_reserved_ipdwardbed").click(function() {
	var id = this.id;
	//alert(id);
	ipd_bed_id = $("#ipd_bed_id_"+id).val();
	$("#bed_id_allot").val(ipd_bed_id);
	
	ipd_ward_id = $("#ipd_ward_id_"+id).val();
	$("#ward_id").val(ipd_ward_id);
	
	ipd_ward_no = $("#ipd_ward_no_"+id).val();
	$("#ipd_ward_no").html(ipd_ward_no);
	
	ipd_bed_no = $("#ipd_bed_no_"+id).val();
	$("#ipd_bed_no").html(ipd_bed_no);
	
	ipd_patient_id = $("#ipd_patient_id_"+id).val();
	$("#patient_id").val(ipd_patient_id);
	
	ipd_patient_name = $("#ipd_patient_name_"+id).val();
	$("#patient_name").html(ipd_patient_name);
	
	ipd_bed_allotment_id = $("#ipd_bed_allotment_id_"+id).val();
	$("#ipd_bed_allotment_id").val(ipd_bed_allotment_id);
	
	$("#allocate_type").val('allocate_reserved');
	
	$("#select_patient_popup").hide();
	
	$("#bed_status").hide();
	
	
});




$(".transfer_ipdwardbed").click(function() {
	var id = this.id;
	//alert(id);
	
	ipd_bed_allotment_id = $("#ipd_bed_allotment_id_"+id).val();
	$("#transfer_bed_allotment_id").val(ipd_bed_allotment_id);
	
	ipd_patient_name_ = $("#ipd_patient_name_"+id).val();
	$("#transfer_patient_name").html(ipd_patient_name_);
	
	ipd_bed_no = $("#ipd_bed_no_"+id).val();
	$("#current_bed_no").html(ipd_bed_no);
	
});


$(function() {
		
		$("#datepicker").datepicker({
		showOn: "button",
		buttonImage: "../images/calendar.gif",
		buttonImageOnly: true,
		changeMonth: true,
		changeYear: true,
		dateFormat: "yy-mm-dd",
		minDate: '0'
		});
		
		$("#datepicker1").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/jquery.timepicker.js"></script>
<link rel="stylesheet" type="text/css" href="../timepicker/jquery.timepicker.css" />

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

$('#allocation_time_due').timepicker();


$('#discharge_time_due').timepicker();



	
</script>

