<?php
include('accesscheck2.php'); 
require_once('Connections/courier.php');

$action = $_POST['act'];
//$id = $_POST['id'];

if($action=='guestvisitno'){
$client = 'Guest';	
}

$PROVIDERID=$_SESSION['provider_id'];
$user_id=$_SESSION['myMM_Userid'];
$MEMBERSHIPID=$id;
$card_number = mysql_fetch_assoc(mysql_query("SELECT card_number FROM patient_information WHERE id = '$MEMBERSHIPID'"));
$patient_no=$card_number['card_number'];

$typeofvisit=$_POST['visit_type1'];
$insurance_claim_no=$_POST['insurance_claim_no'];
$attending_officer_id=$_POST['attending_officer'];
$service_cat = $_POST['service_category'];
$fvisit_type = $_POST['visit_type'];
$service= $_POST['service'];
/*echo $service;
echo $action;*/
$payment_mode = $_POST['payment_mode'];
$short_code=$_SESSION['provider_short_code'];

$modeofpayment=$_POST['mode_of_payment'];

if($mem_id==''){
$mem_id=$_POST['mem_id'];
}

$REQUESTMODE='SOFTWARE';
$query_rsodest_claim = "select *, DATE_FORMAT(datetimeadded, '%e %b %Y %r') as dateprocessing from process_claim_no where  patient_no='$patient_no' and provider_id='$PROVIDERID' and patient_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);	
	
	$query_rsodest_officer = "SELECT * FROM users where id='$attending_officer_id'";
	//echo $query_rsodest_officer;	     
$rsodest_officer = mysql_query($query_rsodest_officer, $courier) or die(mysql_error());
$row_rsodest_officer=mysql_fetch_assoc($rsodest_officer);
$attending_officer=$row_rsodest_officer['title']." ".$row_rsodest_officer['firstnames']." ".$row_rsodest_officer['surname'];
$area_specialisation=$row_rsodest_officer['area_specialisation'];



$characters = array("A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z", "1","2","3","4","5","6","7","8","9");
		$PASSSALT=$characters[rand(0,32)].$characters[rand(0,32)];
		
		$characters = array("A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z", "1","2","3","4","5","6","7","8","9");
		$VALIDSALT=$characters[rand(0,32)].$characters[rand(0,32)].$characters[rand(0,32)].$characters[rand(0,32)];
		
                $query_rsodest="INSERT INTO `process_claim_no` (`id`, `provider_id`, `mode_of_payment`,`insurance_company`, `insurance_no`, `patient_id`, `patient_no`, `pass_salt`, `datetimeadded`, `date_added`, `request_mode`, `validation_salt`, `typeofvisit`, `pregnancy_visit_type`,`attending_officer_id`, `attending_officer`, `user_id`, `area_specialisation`,service_category ,insurance_claim_no,consulting_room_status,old_folder) VALUES (NULL, '$PROVIDERID', '$modeofpayment', '$insurance_company', '$insurance_no', '$MEMBERSHIPID', '$patient_no', '$PASSSALT', NOW(), CURDATE(), '$REQUESTMODE', '$VALIDSALT', '$typeofvisit','$fvisit_type', '$attending_officer_id', '$attending_officer', '$user_id', '$area_specialisation','$service_cat','$insurance_claim_no','discharged','yes');";
		
		$rsodest = mysql_query($query_rsodest, $courier) or die(mysql_error());
		$CLAIMID=mysql_insert_id();

		$lenclaim=strlen($CLAIMID);
		$lenprovider=strlen($PROVIDERID);
		$claimidzero=str_repeat("0",(5-$lenclaim)).$CLAIMID;
			
	
		$CLAIMNUMBER='OLD'.$_SESSION['provider_short_code'].$claimidzero.$PASSSALT.date('y');
		
		$query_rsodest="update process_claim_no set process_claim_no='$CLAIMNUMBER' where id='$CLAIMID'";
		$rsodest = mysql_query($query_rsodest, $courier) or die(mysql_error());
		
		
		
		$query_rsodest_claim = "select *, DATE_FORMAT(datetimeadded, '%e %b %Y %r') as dateprocessing  from process_claim_no where patient_no='$patient_no' and provider_id='$PROVIDERID' and id=$CLAIMID";
//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);
	
	$CLAIMNUMBER=$row_rsodest_claim['process_claim_no'];
$claimdate=$row_rsodest_claim['dateprocessing'];
$status=$row_rsodest_claim['patient_status'];
$validation_key=$row_rsodest_claim['validation_key'];
$validation_salt=$row_rsodest_claim['validation_salt'];
$typeofvisit=$row_rsodest_claim['typeofvisit'];
$attending_officer=$row_rsodest_claim['attending_officer'];


$process_claim_no = $CLAIMNUMBER;
$patient_id = $MEMBERSHIPID;
?>