<?php 
include('accesscheck2.php');
require_once('Connections/courier.php'); 
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($action=='check_patient_insurance'){
	$insurance_no=$_POST['insurance_no1'];
	$insurance_com1=$_POST['insurance_com1'];

$query_rsodest_insurer = "SELECT * FROM ins_claims_database where status='Active'";
$rsodest_insurer = mysql_query($query_rsodest_insurer, $courier) or die(mysql_error());
$row_rsodest_insurer=mysql_fetch_assoc($rsodest_insurer);
$totalRows_rsodest_insurer = mysql_num_rows($rsodest_insurer);	

$ins_claim_database=$row_rsodest_insurer['claims_database'];
	

$query_rsodest_insurer = "SELECT * FROM `$ins_claim_database`.`insurance_company` a inner join `$ins_claim_database`.`activation` b on a.company_code=b.ins_company where a.status='Active' and a.company_code='$insurance_com1' order by company_name";
$rsodest_insurer = mysql_query($query_rsodest_insurer, $courier) or die(mysql_error());
$row_rsodest_insurer=mysql_fetch_assoc($rsodest_insurer);
$totalRows_rsodest_insurer = mysql_num_rows($rsodest_insurer);
	

if($totalRows_rsodest_insurer>0){	
	$query_rsodest_check = "SELECT * FROM `$ins_claim_database`.`patient_info` where ins_company='$insurance_com1' and member_no='$insurance_no'";
$rsodest_check = mysql_query($query_rsodest_check, $courier) or die(mysql_error());
$row_rsodest_check = mysql_fetch_assoc($rsodest_check);
$totalRows_rsodest_check = mysql_num_rows($rsodest_check);	

if($totalRows_rsodest_check>0){
if($row_rsodest_check['expiry_date']<date('Y-m-d')) { $cardstatus='Inactive'; $cardtag="Expired";}else{
	$cardstatus='Active'; $cardtag="Active";
	}
	
	
if($cardstatus=='Active'){
if($row_rsodest_check['status']=='Active'){  $cardstatus='Active'; $cardtag="Active";    }
if($row_rsodest_check['status']=='Inactive'){ $cardstatus='Inactive'; $cardtag="Inactive";}   	
}

if($cardstatus=='Active'){										
												
$plan=$row_rsodest_check['member_plan'];
$query_rsodest_officer = "SELECT * FROM `$ins_claim_database`.provider_api_plans where status='Active' and plan='$plan'";
$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($totalRows_rsodest_officer==0){
	$cardstatus='Inactive';
	$cardtag="Benefit <u>$plan</u> plan not supported by your facility";
	
}
												   
											   }
}else{
$cardstatus='Inactive';
	$cardtag="Insurance Number Not Found.";	
}


											   

										   
if($cardstatus=='Active' ){echo "<span style='color:#090;'>$cardtag</span>";}
if($cardstatus=='Inactive' ){echo "<span style='color:red;'>$cardtag</span>";}	

}else{
echo "<span style='color:red;'>Sorry Insurance Company Not Supported By Rx Claim</span>";	
}




	
}


if($action=='check_doctors_availability'){
$appoint_date = $_POST['appoint_date'];
$speciality = $_POST['specialist'];
$time2= $_POST['hour'].":".$_POST['min'];



$get_schedule = mysql_query("SELECT * FROM duty_roster where staff_no='$speciality' and duty_date='$appoint_date'");
$rs_get_schedule=mysql_fetch_assoc($get_schedule);
$trows = mysql_num_rows($get_schedule);

if($trows>0){
$start_time = strtotime($rs_get_schedule['start_time']);
$end_time = strtotime($rs_get_schedule['end_time']);
$time_to_check = strtotime($time2);

	if(($time_to_check>=$start_time) && ($time_to_check<=$end_time)){
		echo "Doctor Available";
		
	}
	else{echo "Doctor Not Available."."\n"."Doctor available between ".$rs_get_schedule['start_time']."and ".$rs_get_schedule['end_time'];}

	
}else {echo "Doctor not on duty on this date";}

}

?>
