<?php include('accesscheck2.php'); 
require_once('Connections/courier.php');
error_reporting(0);
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_courier, $courier);
if(!isset($id)){
$id = $_POST['id'];
}

$query_rsodest_patient = "SELECT *, DATE_FORMAT(dateofbirth, '%D %b %Y') as datenew, (DATE_FORMAT(current_date, '%Y') - DATE_FORMAT(dateofbirth, '%Y') - (DATE_FORMAT(current_date, '00-%m-%d') < DATE_FORMAT(dateofbirth, '00-%m-%d'))) AS age FROM patient_information where id='$id'";
$rsodest_patient = mysql_query($query_rsodest_patient, $courier) or die(mysql_error());
$row_rsodest_patient = mysql_fetch_assoc($rsodest_patient);

$MEMBERSHIPID=$row_rsodest_patient['id'];
$patient_no=$row_rsodest_patient['card_number'];
$PROVIDERID=$_SESSION['provider_id'];
$type_of_client=$row_rsodest_patient['type_of_client'];
$_SESSION['client_type']=$type_of_client;

function getinsurance($ins_code){
if($ins_code=='CASH' || $ins_code=='Staff'){
$ccode=$ins_code;	
}
else{
$query_rsodest_insurer = "SELECT * FROM insurance_company where company_code='$ins_code'";
$rsodest_insurer = mysql_query($query_rsodest_insurer) or die(mysql_error());
$row_rsodest_insurer=mysql_fetch_assoc($rsodest_insurer);
$ccode=$row_rsodest_insurer['company_name'];

}

return $ccode;
	
}

function getshortcode($ins_code){
$query_rsodest_insurer = "SELECT * FROM provider_api where short_code='$ins_code'";
$rsodest_insurer = mysql_query($query_rsodest_insurer) or die(mysql_error());
$row_rsodest_insurer=mysql_fetch_assoc($rsodest_insurer);
$ccode=$row_rsodest_insurer['facility_name'];



return $ccode;
	
}


function getpicpath($ins_code){
$query_rsodest_insurer = "SELECT * FROM insurance_company where company_code='$ins_code'";
$rsodest_insurer = mysql_query($query_rsodest_insurer) or die(mysql_error());
$row_rsodest_insurer=mysql_fetch_assoc($rsodest_insurer);
$ccode=$row_rsodest_insurer['pic_path'];



return $ccode;
	
}

function getnoofpatients($user_code){
$query_rsodest_insurer = "SELECT count(id) as noofpatients FROM process_claim_no where attending_officer_id='$user_code' and consulting_room_status='pending'";
$rsodest_insurer = mysql_query($query_rsodest_insurer) or die(mysql_error());
$row_rsodest_insurer=mysql_fetch_assoc($rsodest_insurer);
$ccode=$row_rsodest_insurer['noofpatients'];

return $ccode;
	
}

$query_rsodest_officer = "SELECT * FROM users where (security='MEDICAL OFFICER' or security='OPTICIAN' or security='DENTIST')  order by title, surname, firstnames";	     
$rsodest_officer = mysql_query($query_rsodest_officer, $courier) or die(mysql_error());
$row_rsodest_officer=mysql_fetch_assoc($rsodest_officer);
$totalRows_rsodest_officer = mysql_num_rows($rsodest_officer);

$query_rsodest_claim = "select *, DATE_FORMAT(datetimeadded, '%e %b %Y') as dateprocessing from process_claim_no where patient_no='$patient_no' and provider_id='$PROVIDERID' and status='In Use'";
//echo $query_rsodest_claim;
	$rsodest_claim = mysql_query($query_rsodest_claim, $courier) or die(mysql_error());
	$row_rsodest_claim = mysql_fetch_assoc($rsodest_claim);
	$totalRows_rsodest_claim = mysql_num_rows($rsodest_claim);
	$process_claim_no = $row_rsodest_claim['process_claim_no'];
	
	
$appoints = mysql_query("SELECT * FROM appointments where patient_no=$patient_no");
$rsodest_appoint = mysql_fetch_assoc($appoints);
$trows_appoint = mysql_num_rows($appoints);
?>
<link href="css/new.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../assets/css/themes/light.css">
<link rel="stylesheet" type="text/css" href="../assets/plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="../assets/bootstrap/css/datepicker.css">

<form name="form" id="form" method="post" onsubmit="getstep('records_insert_patient'); return false;">
<div class="content_area">
<div class="tab_content">
	<div id="member_info">
		<div class="list-group" style="padding: 0px">                        
          <div style="background-color: #428bca" class="portlet box">
            	<div class="portlet-title">
                      <div class="caption"><i style="color: #FFF" class="icon-globe"></i><span class="sectionTitle2">Patient Visits: <span class="captxt"><?php echo $row_rsodest_patient['surname']." ".$row_rsodest_patient['othernames'];?> (<?php echo $row_rsodest_patient['card_number']?></span>)</span>
                        
                      </div>
                     <div class="tools">
                     <a href="javascript:;" onClick="getstep('<?php echo $action?>','<?php echo $row_rsodest_patient['id'];?>')" class="reload"></a>
                        <a href="javascript:;" class="collapse"></a>
                       
                        
                        
                     </div>
            </div>
            
            	<div class="portlet-body" style="padding:0px;">
            		<div class="table-responsive" >
<table width="100%" cellspacing="0" cellpadding="2" border="0">
       <tbody>
       <tr>
            <td height="30" colspan="2" class="areacontop" style="background:#D3E1F1 url(images/toolbar_bg.png) top left repeat-x">
                
               <div class="btn-group pull-right">
						<button type="button" class="btn red dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="1000" data-close-others="true">
						Patient Menu <i class="icon-angle-down"></i>
						</button>
                        
                        
						<ul class="dropdown-menu pull-right" role="menu">
							<li>
						<a href="#" onClick="getstep('view_patient_visits',<?php echo $row_rsodest_patient['id']; ?>);"><span class="view">Patient Visits</span></a>
					</li>
                    <li>
						<a href="#" onClick="getstep('view_patient_appointments',<?php echo $row_rsodest_patient['id']; ?>);"><span class="view">Patient Appointments</span></a>
					</li>
                    <li>
						<a href="#" onClick="getstep('view_patient_bills',<?php echo $row_rsodest_patient['id']; ?>);"><span class="view">Billing Information</span></a>
					</li>
                    <li>
						<a href="#" onClick="getstep('view_patient_full',<?php echo $id; ?>);"><span class="view">View Patient Information</span></a>
					</li>
                    <li>
						<a href="#" onClick="getstep('edit_patient_records',<?php echo $row_rsodest_patient['id']; ?>);"><span class="view">Edit Patient Information</span></a>
					</li>
                    
							
						</ul>
					</div> 
					
				
                </td>
        </tr>
          <tr>
            <td width="10%" valign="top">
              
              <table width="100%" height="" cellspacing="1" cellpadding="1" border="0" class="sectionText1">
                <tbody>
                  <tr>
                    <td valign="middle" style="padding: 5px; text-align:center;" id="pic_frame0" align="center">
                      
                      
                      <?php $picpath=$row_rsodest_patient['picpath']; 
										  
										  if(!$picpath){ 
											
											
											if($row_rsodest_patient['insurance_no1']){
											$inspicpath=getpicpath($row_rsodest_patient['insurance_company1']);
											
											if($inspicpath){
											
											$member_id=preg_replace("/[^0-9]/","",$row_rsodest_patient['insurance_no1']);
											
											$picpath=$inspicpath."/".ltrim($member_id,0).".jpg";
											}else{
											$picpath="images/profile.gif";		
											}
											}else{
											$picpath="images/profile.gif";	
											}
										  }
										  
										  ?>
                      
                      
                      <p><img alt="no_photo" width="100" height="100" src="<?php echo $picpath;?>" style="text-align: center">
                        
                        <input type="hidden" id="filepath0" name="filepath0" value="images/profile.gif">
                        </p>
                      </td>
                    </tr>
                  <tr>
                    <td valign="middle" align="center"><div style="text-align:center"><strong style="color:#900; font-size:12px;"><?php echo $row_rsodest_patient['card_number']?>
                      <input type="hidden" name="patient_no" id="patient_no" value="<?php echo $row_rsodest_patient['card_number']?>">
                      <br>
                      </strong>
                      <strong style="color:#060; font-size:12px;">Old Card: <?php echo $row_rsodest_patient['old_card_no']?>
                        </strong>
                      </div>
                      
                     
                      
                      </td>
                    </tr>
                  </tbody>
                </table>
              
              </td>
            
            <td width="90%"  valign="top"><table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
              <tbody>
                <tr>
                  <td width="" valign="top"><table width="100%" height="60" cellspacing="0" cellpadding="0" border="0" class="nav_tbl">
                    <tbody>
                      <tr>
                        <td valign="top" height="30" class="areacontop"><table width="100%" cellspacing="1" cellpadding="1" border="0" class="sectionText1">
                          <tbody>
                            <tr>
                              <td valign="top" height="20" bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="1" cellspacing="1" class="sectionText1" id="membershipinfo">
                                <tbody>
                                  <tr>
                                    <td height="25" valign="middle" style="color: #FFFFFF; background-color: #0066cc;cursor: pointer;" class="baseborder"><i class="icon-user"></i> Basic Information:</td>
                                    </tr>
                                  <tr class="baseborder">
                                    <td height="30" align="right" style="text-align: left;padding-left: 10px;"><table width="100%" border="0" cellpadding="1" cellspacing="1">
                                      <tr>
                                        <td height="23" align="right"  style="text-align: left;padding-left: 10px;">Fullname: </td>
                                        <td align="left" ><span class="captxt"><?php echo $row_rsodest_patient['surname']." ".$row_rsodest_patient['othernames'];?></span></td>
                                        <td height="23" align="right"  style="text-align: left;padding-left: 10px;">Sex:</td>
                                        <td align="left" ><span class="captxt">
                                          <?php if($row_rsodest_patient['sex'] == 'M'){echo 'Male';} elseif($row_rsodest_patient['sex']=='F'){echo 'Female';}else{echo $row_rsodest_patient['sex'];} ?>
                                          </span></td>
                                        </tr>
                                      <tr>
                                        <td height="23" align="right"  style="text-align: left;padding-left: 10px;">Age:</td>
                                        <td align="left" ><span class="captxt"><?php echo $row_rsodest_patient['age']; ?> yr(s)</span></td>
                                        <td height="23" align="right"  style="text-align: left;padding-left: 10px; padding-bottom:5px;">Next of Kin:</td>
                                        <td align="left" style="padding-top:5px;"><span class="captxt"><?php echo $row_rsodest_patient['next_of_kin_name'];?></span></td>
                                        </tr>
                                      <tr>
                                        <td height="23" align="right"  style="text-align: left;padding-left: 10px; padding-bottom:5px;">Tel/Mobile:</td>
                                        <td align="left" style="padding-bottom:5px;"><span class="captxt"><?php 
										
										if($row_rsodest_patient['tel']){
										echo $row_rsodest_patient['tel'];
										}else{
										echo $row_rsodest_patient['next_of_kin_tel'];	
										}
										
										?></span></td>
                                        <td height="23" align="right"  style="text-align: left;padding-left: 10px;">Next of KinTel:</td>
                                        <td  align="left" ><span class="captxt"><?php echo $row_rsodest_patient['next_of_kin_tel'];?></span></td>
                                        </tr>
                                      <tr>
                                        <td height="23" align="right"  style="text-align: left;padding-left: 10px;">Home Language:</td>
                                        <td align="left" ><span class="captxt"><?php echo $row_rsodest_patient['home_language']?></span></td>
                                        <td height="23" align="right"  style="text-align: left;padding-left: 10px; padding-bottom:5px;">Marital Status:</td>
                                        <td height="23" align="left" style="padding-top:5px;"><span class="captxt"><?php echo $row_rsodest_patient['marital_status']?></span></td>
                                        </tr>
                                      </table></td>
                                    </tr>
                                  </tbody>
                                </table></td>
                              </tr>
                            </tbody>
                          </table></td>
                        </tr>
                      </tbody>
                    </table></td>
                  </tr>
                </tbody>
              </table></td>
          </tr>
          <tr>
            <td valign="top" colspan="2">
              </td>
          </tr>
  </tbody></table>
  
  </div>
  				</div>
          </div>
		</div>
  	</div>
  <div id="member_consultation">
    <div class="list-group" style="padding: 0px">                        
          <div style="background-color: #428bca" class="portlet box">
            <div class="portlet-title">
                      <div class="caption"><i style="color: #FFF" class="icon-hospital"></i>Folder Activities</div>
                     <div class="tools">
                        <a href="javascript:;" class="collapse"></a>
                        <a href="#portlet-config" data-toggle="modal" class="config"></a>
                     </div>
            </div>
            
            <div class="portlet-body">
            <?php if($cardstatus=='inactive'){?>
           
           
           
            <?php }else{?>
            <ul class="nav nav-tabs">
									<li class="<?php if($totalRows_rsodest_claim==0 && $action!='process_invoice_number'){echo "active";}?>">
										<a aria-expanded="true" href="#tab_1_1" data-toggle="tab">
										<strong>Patient Visits</strong> </a>
									</li>
                                    
                                    <li class="<?php if($action=='view_patient_appointments'){echo "active";}?>">
										<a aria-expanded="true" href="#tab_1_3" data-toggle="tab">
										<strong>Scheduled Appointments</strong> </a>
									</li>
                                    
                                    <li class="<?php if($action=='process_invoice_number'){echo "active";}?>">
										<a aria-expanded="true" href="#tab_1_3_1" data-toggle="tab">
										<strong>Proforma Invoice</strong> </a>
									</li>
                                
                                 <li class="<?php if($totalRows_rsodest_claim>0 && $action!='process_invoice_number' && $action!='view_patient_appointments'){echo "active";}?>" <?php if($totalRows_rsodest_claim==0 && $action!='process_invoice_number'){?>style="display:none;" <?php } ?> id="administrative_charges">
										<a aria-expanded="false" href="#tab_1_2" data-toggle="tab">
										<strong>Administrative Charges</strong> </a>
									</li>
                                    
                                    <li class=""  <?php if($totalRows_rsodest_claim==0){?>style="display:none;" <?php } ?>>
										<a aria-expanded="true" href="#tab_1_4" data-toggle="tab">
										<strong>Reassign Patient</strong> </a>
									</li>
									
                                    
								</ul>
                                <div class="tab-content">
									
								<div class="tab-pane fade<?php if($totalRows_rsodest_claim==0){echo " active in";}?>" id="tab_1_1">
										
                                        
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="55%"><?php
										
										$patient_no=$row_rsodest_patient['card_number'];
										$query_rsodest_claims_invoice = "select *, DATE_FORMAT(datetimeadded, '%e %b %Y') as datenew from process_claim_no where patient_no='$patient_no' order by id desc";
										//echo $query_rsodest_claims_invoice;		
$rsodest_claims_invoice = mysql_query($query_rsodest_claims_invoice, $courier) or die(mysql_error());
$row_rsodest_claims_invoice = mysql_fetch_assoc($rsodest_claims_invoice);	
$totalRows_claims_invoice = mysql_num_rows($rsodest_claims_invoice);	
?>
                     <div class="portlet box green" style="height:290px;width:99%;overflow-y:scroll;" id="port2">

	<div class="portlet-body" style="min-height:350px;" id="port2">
                  
										<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" class="table table-hover table-striped table-bordered">
										  <thead>
										    <tr>
										      <th style="background-color: #FBB;color: #000; font-weight:bold" class="count">&nbsp;</th>
										      <th style="background-color: #FBB;color: #000; font-size:12px;" >Date of Visit</th>
										      <th style="background-color: #FBB;color: #000; font-size:12px;">Visit No:</th>
										      <th style="background-color: #FBB;color: #000; font-size:12px;">Attending Officer</th>
										      <th style="background-color: #FBB;color: #000; font-size:12px;">Area</th>
										      <th style="background-color: #FBB;color: #000; font-size:12px;">Status</th>
									        </tr>
									      </thead>
										  <tbody>  <?php if ($totalRows_claims_invoice> 0) { ?>
										    <?php
                                                    do {
                                                        $start_row=$start_row+1;
                                                        ?>
										    <tr <?php
                                                        if (fmod($start_row, 2) > 0) {
                                                            echo 'class="odd"';
                                                        } else {
                                                            echo 'style="background: linen"';
                                                        }
                  ?>>
										      <td height="23" valign="top" class="count"><span><?php echo $start_row; ?></span></td>
										      <td valign="top" style="cursor: pointer;" onclick="getclaimdetails('view_patient_claim','<?php echo $row_rsodest_claims_invoice['process_claim_no']; ?>','view_claim_details');"><?php if($checkstatus==''){$checkstatus=$row_rsodest_claims_invoice['status'];}echo $row_rsodest_claims_invoice['datenew']; ?></td>
										      <td valign="top" onclick="getclaimdetails('view_patient_claim','<?php echo $row_rsodest_claims_invoice['process_claim_no']; ?>','view_claim_details');" style="cursor: pointer;"><?php echo $row_rsodest_claims_invoice['process_claim_no']; ?></td>
										      <td valign="top" onclick="getclaimdetails('view_patient_claim','<?php echo $row_rsodest_claims_invoice['process_claim_no']; ?>','view_claim_details');" style="cursor: pointer;"><?php echo $row_rsodest_claims_invoice['attending_officer']; ?></td>
										      <td valign="top" onclick="getclaimdetails('view_patient_claim','<?php echo $row_rsodest_claims_invoice['process_claim_no']; ?>','view_claim_details');" style="cursor: pointer;"><?php echo $row_rsodest_claims_invoice['area_specialisation'];?></td>
										      <td valign="top" style="cursor: pointer;" onclick="getclaimdetails('view_patient_claim','<?php echo $row_rsodest_claims_invoice['process_claim_no']; ?>','view_claim_details');">
                                              
                                              <?php if($row_rsodest_claims_invoice['status']=='In Use'){$statuscolor='green';}
				  if($row_rsodest_claims_invoice['status']=='Submitted'){$statuscolor='red';}
					  
					  echo "<span style='color:$statuscolor; font-weight:bold;'>".$row_rsodest_claims_invoice['status']."</span>";?>
                                              
                                              </td>
									        </tr>
										    
										    <?php } while ($row_rsodest_claims_invoice = mysql_fetch_assoc($rsodest_claims_invoice)); ?>
											
											<?php }else{?>
                                            <tr <?php
                                                        if (fmod($start_row, 2) > 0) {
                                                            echo 'class="odd"';
                                                        } else {
                                                            echo 'style="background: linen"';
                                                        }
                  ?>>
										      <td height="23" colspan="6" valign="top" class="count">Sorry, No Patient Visits Recorded Yet.</td>
									        </tr>
                                            
                                            <?php }?>
									      </tbody>
								    </table>
                                    
						  </div>
                        </div>
                      </td>
                                        
    <td width="45%">
    <div class="portlet box green" style="height:290px;width:99%;overflow-y:scroll;" id="port2">

	<div class="portlet-body" style="min-height:290px;" id="port2">
   
   <div id="claimsno">
   
   <?php 
   //echo $checkdate;
   
   if($checkstatus!='In Use'){?>
   
   <table width="100%" border="0" cellpadding="1" cellspacing="1" class="table-hover table-striped table-bordered">
  <tbody>
    <tr >
      <td width="30%" height="30" align="right" valign="top" style="font-weight:bold; font-size:10px;"> Officer:</td>
      <td align="left" valign="top"><select name="attending_officer" id="attending_officer">
          <option value="" selected>Please Select Attending Officer to Assign</option>
          <?php do{ $fullname=$row_rsodest_officer['title']." ".$row_rsodest_officer['firstnames']." ".$row_rsodest_officer['surname']." (".$row_rsodest_officer['area_specialisation'].") - ".getnoofpatients($row_rsodest_officer['id'])." Patients"; ?>
          <option value="<?php echo $row_rsodest_officer['id'];?>"> <?php echo $fullname; ?></option>
          <?php } while ($row_rsodest_officer = mysql_fetch_assoc($rsodest_officer)); ?>
         
        </select></td>
    </tr>
    <tr class="baseborder">
      <td height="30" align="right" valign="top" style="font-weight:bold; font-size:10px;">Service Category:</td>
      <td align="left" valign="top"><select name="service_category" id="service_category">
        <option value="" selected>Please select service category</option>
        <option value="General">General</option>
        <option value="Emergency">Emergency</option>
      </select></td>
    </tr>
    <?php if($row_rsodest_patient['pregnancy_status']=='Yes'){ ?>
    <tr>
    	<td height="30" align="right" valign="top" style="font-weight:bold; font-size:10px;">Pregnancy Visit Type</td>
        <td align="left" valign="top">
          <select name="visit_type" id="visit_type">
        	<option value="">--select--</option>
            <option value="First">First</option>
            <option value="Repeat">Repeat</option>
        </select>
        </td>
    </tr> <?php } ?>
    <tr>
    	<td height="30" align="right" valign="top" style="font-weight:bold; font-size:10px;">Type of visit: </td>
        <td align="left" valign="top">
        
                               <input name="visit_type1" type="radio" value="Out Patient" checked="checked"/>Out Patient&nbsp;&nbsp;&nbsp;<input type="radio" name="visit_type1" value="In Patient"/>In-Patient
                                  
                                 
        
        </td>
    </tr>
    <tr class="baseborder">
      <td height="30" align="right" style="font-weight:bold; font-size:10px;">Mode of Payment:</td>
      <td align="left"><select name="mode_of_payment" id="mode_of_payment" onchange="showtext(this.value);">
        <option value="cash" <?php if($row_rsodest_patient['type_of_client']=='cash' || !$row_rsodest_patient['type_of_client']){ echo "selected";}?>>CASH</option>
        <option value="insurance" <?php if($row_rsodest_patient['type_of_client']=='insurance'){ echo "selected";}?>>INSURANCE</option>
        <option value="company" <?php if($row_rsodest_patient['type_of_client']=='company'){ echo "selected";}?>>COMPANY</option>
        <option value="staff" <?php if($row_rsodest_patient['type_of_client']=='staff'){ echo "selected";}?>>STAFF</option>
        </select>
        <div id="cashbox" style="display:none;"></div></td>
    </tr>
    <tr class="baseborder">
      <td  height="30" colspan="2" align="right" style="font-weight:bold; font-size:10px;">
      
        
        <div id="insurance" style="display:<?php if($row_rsodest_patient['type_of_client']=='insurance'){ echo "block";}else{echo "none";}?>">
          <table width="100%" border="0" cellpadding="1" cellspacing="1" class="sectionText1" id="membershipinfo3">
            <tbody>
              <tr class="baseborder">
                <td width="30%"  height="30" align="right" style="font-weight:bold; font-size:10px;">Insurance Company:</td>
                <td  align="left"><select name="insurance_com1">
                  <option value="">--Select Insurance Company --</option>
                  <?php
$query_rsodestship_company_name = "SELECT * FROM insurance_company where status='Active' and type='insurance' order by company_name";
$rsodestship_company_name = mysql_query($query_rsodestship_company_name, $courier) or die(mysql_error());
$row_rsodestship_company_name = mysql_fetch_assoc($rsodestship_company_name);
$totalRows_rsodestship_company_name = mysql_num_rows($rsodestship_company_name);
do {  
?>
                  <option value="<?php echo $row_rsodestship_company_name['company_code']; ?>" <?php if($row_rsodest_patient['insurance_company1']==$row_rsodestship_company_name['company_code']){ echo "selected";}?>><?php echo strtoupper($row_rsodestship_company_name['company_name']);?></option>
                  <?php
} while ($row_rsodestship_company_name = mysql_fetch_assoc($rsodestship_company_name));
  $rows = mysql_num_rows($rsodestship_company_name);
  if($rows > 0) {
      mysql_data_seek($rsodestship_company_name, 0);
	  $row_rsodestship_company_name = mysql_fetch_assoc($rsodestship_company_name);
  }
?>
                </select></td>
              </tr>
              <tr class="baseborder">
                <td height="30" align="right" style="font-weight:bold; font-size:10px;">Insurance No:</td>
                <td align="left"><input type="text" name="insurance_no1" id="insurance_no1" value="<?php echo $row_rsodest_patient['insurance_no1']; ?>"> <a href="#" onClick="getinsurancevalidate('check_patient_insurance','validation_results');"><span class="view">Validate Card</span><div id='validation_results'></div></a></td>
              </tr>
            </tbody>
          </table>
        </div>
        <div id="staff" style="display:<?php if($row_rsodest_patient['type_of_client']=='staff'){ echo "block";}else{echo "none";}?>">
          <table width="100%" border="0" cellpadding="1" cellspacing="1" class="sectionText1" id="membershipinfo2">
            <tbody>
              <tr class="baseborder" >
                <td width="30%" height="30" align="right" style="font-weight:bold; font-size:10px;">Staff No:</td>
                <td align="left"><input type="text" name="staff_no" id="staff_no" class="captxt" value="<?php echo $row_rsodest_patient['medifem_staff_no']; ?>"></td>
                </tr>
              </tbody>
            </table>
          </div>
        <div id="company" style="display:<?php if($row_rsodest_patient['type_of_client']=='company'){ echo "block";}else{echo "none";}?>">
          <table width="100%" border="0" cellpadding="1" cellspacing="1" class="sectionText1" id="membershipinfo2">
            <tbody>
              <tr class="baseborder" >
                <td width="30%" height="30" align="right" style="font-weight:bold; font-size:10px;">Company:</td>
                <td align="left"><select name="company" style="width:200px;" >
                  <option value="">--Select Company --</option>
                  <?php
$query_rsodestship_company_name = "SELECT * FROM insurance_company where status='Active' and type='company' order by company_name";
$rsodestship_company_name = mysql_query($query_rsodestship_company_name, $courier) or die(mysql_error());
$row_rsodestship_company_name = mysql_fetch_assoc($rsodestship_company_name);
$totalRows_rsodestship_company_name = mysql_num_rows($rsodestship_company_name);
do {  
?>
                  <option value="<?php echo $row_rsodestship_company_name['company_code']; ?>" <?php if($row_rsodest_patient['company']==$row_rsodestship_company_name['company_code']){ echo "selected";}?>><?php echo strtoupper($row_rsodestship_company_name['company_name']);?></option>
                  <?php
} while ($row_rsodestship_company_name = mysql_fetch_assoc($rsodestship_company_name));
  $rows = mysql_num_rows($rsodestship_company_name);
  if($rows > 0) {
      mysql_data_seek($rsodestship_company_name, 0);
	  $row_rsodestship_company_name = mysql_fetch_assoc($rsodestship_company_name);
  }
?>
                  </select></td>
                </tr>
              <tr class="baseborder" >
                <td width="30%" height="30" align="right" style="font-weight:bold; font-size:10px;">Company Staff No:</td>
                <td align="left"><span style="color: green;font-weight: bold;font-size: 12px">
                  <input type="text" name="company_staff_no" id="company_staff_no" class="captxt" value="<?php echo $row_rsodest_patient['company_staff_no']; ?>">
                  </span></td>
                </tr>
              </tbody>
            </table>
          </div></td>
    </tr>
  </tbody>
</table>
   
   <a href="#" onClick="getclaimprocessing('patientvisitno','claimsno','<?php echo $row_rsodest_patient['id']; ?>');" >
    <div id="claimprocessing_num" style="height:100px;" class="add_new_claim"></div>
    </a>
    <?php }else{
		
	include("process_visit_no.php");	
	}?>
    </div>
   
    <input type="hidden" id="ins_company" name="ins_company" value="<?php echo $row_rsodest['ins_company']; ?>">
                                           <input type="hidden" id="member_no" name="member_no" value="<?php echo $row_rsodest['member_no']; ?>">
                                           <input type="hidden" id="user_id" name="user_id" value="<?php echo $_SESSION['myMM_Userid']; ?>">
                                            <input type="hidden" id="process_claim_no" name="process_claim_no" value="<?php echo $process_claim_no; ?>">
                                             
                                            
    
    </div>
    </div>
    </td>
  </tr>
</table>


								  </div>
                                  
                                <div class="tab-pane fade<?php if($totalRows_rsodest_claim>0){echo " active in";}?>" id="tab_1_2">
 <?php
 $query_rsodest_claim_no = "select * from process_claim_no where process_claim_no='$process_claim_no'";
//echo $query_rsodest_claim;
	$rsodest_claim_no = mysql_query($query_rsodest_claim_no, $courier) or die(mysql_error());
	$row_rsodest_claim_no = mysql_fetch_assoc($rsodest_claim_no);
	$totalRows_rsodest_claim_no = mysql_num_rows($rsodest_claim_no);
    ?>

<?php include('diagnostic_prescription.php'); ?>


</div>

								<div class="tab-pane fade" id="tab_1_3">
										
                                        
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="60%">
      
      <div class="portlet box green" style="height:290px;width:99%;overflow-y:scroll;" id="port2">
        
        <div class="portlet-body" style="min-height:350px;" id="port2">
          
          <table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" class="table table-hover table-striped table-bordered">
            <thead>
              <tr>
                <th style="background-color: #FBB;color: #000; font-weight:bold" class="count">&nbsp;</th>
                <th style="background-color: #FBB;color: #000; font-size:12px;" >Date Generated</th>
                <th style="background-color: #FBB;color: #000; font-size:12px;">Claim No:</th>
                <th style="background-color: #FBB;color: #000; font-size:12px;">Status</th>
                </tr>
              </thead>
            <tbody>
              <?php if ($trows_appoint> 0) { 
                                                    do {
                                                        $start_row2=$start_row2+1;
                                                        ?>
              <tr <?php
                                                        if (fmod($start_row2, 2) > 0) {
                                                            echo 'class="odd"';
                                                        } else {
                                                            echo 'style="background: linen"';
                                                        }
                  ?>>
                <td height="23" valign="top" class="count"><span><?php echo $start_row2; ?></span></td>
                <td valign="top" style="cursor: pointer;" onclick="getclaimdetails('view_patient_claim','<?php echo $row_rsodest_claims_invoice['process_claim_no']; ?>','view_claim_details');"><?php if($checkstatus==''){$checkstatus=$row_rsodest_claims_invoice1['status'];}echo $row_rsodest_claims_invoice1['datenew']; ?></td>
                <td valign="top" onclick="getclaimdetails('view_patient_claim','<?php echo $row_rsodest_claims_invoice1['process_claim_no']; ?>','view_claim_details');" style="cursor: pointer;"><?php echo $row_rsodest_claims_invoice1['process_claim_no']; ?></td>
                <td valign="top" style="cursor: pointer;" onclick="getclaimdetails('view_patient_claim','<?php echo $row_rsodest_claims_invoice1['process_claim_no']; ?>','view_claim_details');">
                  
                  <?php if($row_rsodest_claims_invoice1['status']=='In Use'){$statuscolor='green';}
				  if($row_rsodest_claims_invoice1['status']=='Submitted'){$statuscolor='red';}
					  
					  echo "<span style='color:$statuscolor; font-weight:bold;'>".$row_rsodest_claims_invoice1['status']."</span>";?>
                  
                  </td>
                </tr>
              <?php } while ($row_rsodest_claims_invoice1 = mysql_fetch_assoc($rsodest_claims_invoice1)); 
	  			}else{?>
                                            <tr <?php
                                                        if (fmod($start_row, 2) > 0) {
                                                            echo 'class="odd"';
                                                        } else {
                                                            echo 'style="background: linen"';
                                                        }
                  ?>>
										      <td height="23" colspan="6" valign="top" class="count">Sorry, No Patient Visits Recorded Yet.</td>
									        </tr>
                                            
                                            <?php }?>
			  
              </tbody>
            </table>
          
          </div>
        </div>
    </td>
    <td width="40%">
    	<div class="portlet box green" style="height:290px;width:99%;overflow-y:scroll;">
        	<div class="portlet-body" style="min-height:350px;">
            	<form name="appointment" method="post">
    			<table class="table" width="100%">
                    <tbody>
                    <tr>
                            	<td colspan="2" style="font-weight:bolder; color: #FFFFFF; background-color: #35A26B;cursor: pointer;" class="baseborder">MAKE APPOINTMENT</td>
                            </tr>
                    	<tr>
                        <?php
						$query_rsodest_officer1 = "SELECT * FROM users where (security='MEDICAL OFFICER' or security='OPTICIAN' or security='DENTIST')  order by title, surname, firstnames";	     
$rsodest_officer1 = mysql_query($query_rsodest_officer1, $courier) or die(mysql_error());
$row_rsodest_officer1=mysql_fetch_assoc($rsodest_officer1);
$totalRows_rsodest_officer1 = mysql_num_rows($rsodest_officer1);
						
						?>
                    	  <td height="15" valign="top" class="captxt"><b>Medical Officer</b></td>
                    	  <td width="47%"><span class="captxt">
                    	    <select name="specialist">
                    	      <option value="">--Select Medical Officer--</option>
                    	      <?php
                                    do {  
?>
                    	      <option value="<?php echo $row_rsodest_officer1['id']; ?>"><?php echo $row_rsodest_officer1['firstnames'].' '.$row_rsodest_officer1['surname']?></option>
                    	      <?php
} while ($row_rsodest_officer1 = mysql_fetch_assoc($rsodest_officer1));
 ?>
                  	      </select>
                    	  </span></td>
                  	  </tr>
                    	<tr >
                        	 <td width="20%" height="15" valign="top" class="captxt"><span class="captxt" style="text-align: left;padding-left: 10px; padding-bottom:5px;font-weight:bold">Speciality</span></td>
                             <td><span style="padding-top:5px;">
                               <select name="specialisation">
                                 <option value="">--Select Speciality--</option>
                                <?php
						$query_rsodest_officer2 = "SELECT DISTINCT area_specialisation FROM users where (security='MEDICAL OFFICER' or security='OPTICIAN' or security='DENTIST')  order by title, surname, firstnames";	     
$rsodest_officer2 = mysql_query($query_rsodest_officer2, $courier) or die(mysql_error());
$row_rsodest_officer2=mysql_fetch_assoc($rsodest_officer2);
$totalRows_rsodest_officer2 = mysql_num_rows($rsodest_officer2);
	
								 do { ?>
                    	      <option value="<?php echo $row_rsodest_officer2['area_specialisation']; ?>"><?php echo $row_rsodest_officer2['area_specialisation'];?></option>
                    	      <?php
} while ($row_rsodest_officer2 = mysql_fetch_assoc($rsodest_officer2));?>
                                 
                               </select>
                             </span></td>
                        </tr>
                        <tr class="pickdate">
                        	<td width="20%" class="captxt"><b>Starting Date</b></td>
                             <td><input type="text" id="dateofbirth" name="appoint_date" readonly="	" />              
              
              <select name="hour" style="width:50px">
              <?php
			  $h= date('H');
              	for ($i = 0; $i <=23 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else { ?> <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
	?>
              </select>
              <select name="min" style="width:50px">
              	<?php
				$m= date('i');
              	for ($i = 0; $i <=59 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else {?> <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           ;
	<?php 
	 }
				?>
              </select>
                               <a href="#" onClick="getinsurancevalidate('check_doctors_availability','check_results');"><span class="view">Check Doctor's Availability</span></a><div id='check_results' style="color:green; font-weight:bold;"></div></td>
                        </tr>
                        <tr>
                        	<td height="23" align="right" class="captxt"  style="text-align: left;padding-left: 10px; padding-bottom:5px;font-weight:bold;">Purpose</td>
                           <td><select width="200px" name="purpose" onchange="showproc(this.value)">
                           	<option value="review" onclick="$('#sel_proc').hide();" >Review</option>
                            <option value="procedure" onclick="$('#sel_proc').show();">Procedure</option>
                           </select>
                           </td>
                           
                        </tr>
                        <tr style="display:none"  id="sel_proc">
                        	<td height="23" width="20%" align="right" class="captxt" style="text-align: left;padding-left: 10px;font-weight:bold;">Procedure:</td>
                        <td align="left" >
                        	
                                    	<select name="procedure" id="procedure" >
                          					<option value="">-------- SELECT -------</option>
                          					<option value="LAPAROSCOPY/CHROMOTUBATION">LAPAROSCOPY/CHROMOTUBATION</option>
                            				<option value="CAESARIAN SECTION">CAESARIAN SECTION</option>
                        				</select>
                           	
                        </td>
                        </tr>
                        <tr>
                        <td>&nbsp;</td>
                        <td><button style="float:right;"  onClick="getstep('admin_list_of_patients');" type="reset" class="btn default">Cancel</button><button style="float:right;" class="btn green" onclick="getstep('saveappoint',<?php echo $id?>);">Save</button></td>
                        
                        </tr>
                    </tbody>
                </table>
                </form>
         	</div>
    	</div>
    </td>
    </tr>
</table>


								  </div>
                                  
                                <div class="tab-pane fade" id="tab_1_3_1">
           		<div class="portlet box blue" style="height:350px;width:100%;overflow-y:scroll;">
                	<div class="portlet-body" style="min-height:350px;">
                    
					
					<?php 
					//$tdate=date('Y-m-d');
					$query_rsodest_claim = "select * from invoice_numbers where patient_no='$patient_no' and status='In Use'";

	$rsodest_claim = mysql_query($query_rsodest_claim, $courier) or die(mysql_error());
	$row_rsodest_claim = mysql_fetch_assoc($rsodest_claim);
	$totalRows_rsodest_claim = mysql_num_rows($rsodest_claim);	
	$invoice_no = $row_rsodest_claim['invoice_no'];
					
					if($totalRows_rsodest_claim==0){
					?>
                    
                    <button type="button" class="btn green" onClick="getstep('process_invoice_number','<?php echo $id; ?>');">Generate Invoice Number&nbsp;<i class="icon-plus-sign"></i></button><input name="invoice_no" type="hidden" value="<?php echo $invoice_no; ?>" /> <?php }else { ?><span style="background-color:#35A26B;height:10%;"><strong style="color:#FFF">INVOICE NUMBER: &nbsp; <?php echo $invoice_no; ?>&nbsp;</strong></span> <?php }
                    	include ('proforma_invoice.php'); ?>
                    </div>
                </div>
          	
								 	</div>
                                    
                                <div class="tab-pane fade" id="tab_1_4">
                                    <?php
                                    	$reass_query = mysql_query("select *,(patient_information.datetimeadded) as patient_time from process_claim_no left outer join patient_information on process_claim_no.patient_id=patient_information.id where process_claim_no.patient_id = '$id' order by process_claim_no.datetimeadded DESC") or die(mysql_error());
$rs_reass_query = mysql_fetch_assoc($reass_query);

$query_rsodest_officer = "SELECT * FROM users where (security='MEDICAL OFFICER' or security='OPTICIAN' or security='DENTIST')  order by title, surname, firstnames";	     
$rsodest_officer = mysql_query($query_rsodest_officer, $courier) or die(mysql_error());
$row_rsodest_officer=mysql_fetch_assoc($rsodest_officer);
$totalRows_rsodest_officer = mysql_num_rows($rsodest_officer);

if(!function_exists('getnoofpatients')){
function getnoofpatients($user_code){
$query_rsodest_insurer = "SELECT count(id) as noofpatients FROM process_claim_no where attending_officer_id='$user_code' and consulting_room_status='pending'";
$rsodest_insurer = mysql_query($query_rsodest_insurer) or die(mysql_error());
$row_rsodest_insurer=mysql_fetch_assoc($rsodest_insurer);
$ccode=$row_rsodest_insurer['noofpatients'];

return $ccode;
	
}}?>
		<div class="row">
        	<div class="col-md-6">
           		<div class="portlet box blue" style="height:290px;width:100%;overflow-y:scroll;">
                	<div class="portlet-body" style="min-height:290px;">
                    	<table class="table table-striped" width="100%">
                        	<tr>
                            	<td colspan="2" style="font-weight:bold; color: #FFFFFF; background-color: #35A26B;cursor: pointer;" class="baseborder">ASSIGNED DETAILS</td>
                            </tr>
                        	<tr>
                            	<td><label for="textfield">Time Added</label></td>
                    	    	<td style="font-weight:bold; font-size:12px;"><?php echo $rs_reass_query['datetimeadded'] ?></td>
                    		</tr>
                            <tr>
                            	<td><label for="textfield">Consulting Room Status</label></td>
                    	    	<td style="font-weight:bold; font-size:12px;"><?php echo strtoupper($rs_reass_query['consulting_room_status']); ?></td>
                    		</tr>
                            <tr>
                            	<td><label for="textfield">Attending Officer</label></td>
                    	    	<td style="font-weight:bold; font-size:12px;"><?php echo $rs_reass_query['attending_officer']; ?></td>
                    		</tr>
                            <tr>
                            	<td><label for="textfield">Area of Specialisation</label></td>
      							<td style="font-weight:bold; font-size:12px;"><?php echo $rs_reass_query['area_specialisation']; ?></td>
                    		</tr>
                            
                                
                        </table>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
            	<div class="portlet box blue" style="height:290px;width:100%;overflow-y:scroll;">
                	<div class="portlet-body" style="min-height:290px;">
                    <form name="reassign" method="post">
                    	<table class="table table-striped" width="100%">
                        	<tr>
                            	<td colspan="2" style="font-weight:bolder; color: #FFFFFF; background-color: #35A26B;cursor: pointer;" class="baseborder">REASSIGN PATIENT</td>
                            </tr>
                            <tr>
                            	<td>&nbsp;</td>
                                <td>&nbsp;<input type="hidden" name="patient_no" id="patient_no" value="<?php echo $rs_reass_query['patient_no']; ?>" disabled></td>
                            </tr>
                        	<!--<tr>
                            	<td><label for="textfield">Patient No</label></td>
                    	    	<td></td>
                    		</tr>
                           
-->                            <tr>
                            	<td><label for="textfield">Attending Officer</label></td>
                    	    	<td><input type="text" name="attending_officer" value="<?php echo $rs_reass_query['attending_officer']; ?>" id="attending_officer" disabled></td>
                    		</tr>
                            <tr>
                            	<td height="30" align="right" valign="top"><label for="textfield">New Attending Officer</label></td>
      <td align="left" valign="top"><select name="attending_officer_new" id="attending_officer">
          <option value="" selected>Please Select Attending Officer to Assign</option>
          <?php do{ $fullname=$row_rsodest_officer['title']." ".$row_rsodest_officer['firstnames']." ".$row_rsodest_officer['surname']." (".$row_rsodest_officer['area_specialisation'].") - ".getnoofpatients($row_rsodest_officer['id'])." Patients"; ?>
          <option value="<?php echo $row_rsodest_officer['id'];?>"> <?php echo $fullname; ?></option>
          <?php } while ($row_rsodest_officer = mysql_fetch_assoc($rsodest_officer)); ?>
         
        </select></td>
                    		</tr>
                        </table>
                        <input type="button" class="btn green" name="reassign" value="Reassign" onclick="getstep('reassign_new','<?php echo $id; ?>')"/>
                        </form>
                    </div>
                </div>
            </div>
        </div>
                                    </div>
                                  
                                  
                                  
									
									
								</div>
            
    		<?php }?>
			</div>
           </div>
            
 	</div>
          
    </div>
  
</div>
</div>
</form>