<?php

if (count(get_included_files()) == 0){

include 'connections/customPDO.php';

}



Class SubmitClaim{



function SubmitClaim($local,$live){

   $this->mysqllocal=$local;



   if ($connection==0 && $live!=0) {

   	# code...

   $this->mysqllive=$live;

   }

}



	function subClaims($INSCOMPANYCODE,$PROVIDERID, $MEMBERSHIPID, $CLAIMNUMBER)

	{

		# code...

		$INSCOMPANYCODE=$this->mysqllocal->quote($INSCOMPANYCODE);

		$PROVIDERID=$this->mysqllocal->quote($PROVIDERID);

		$MEMBERSHIPID=$this->mysqllocal->quote($MEMBERSHIPID);

		$CLAIMNUMBER=$this->mysqllocal->quote($CLAIMNUMBER);

       $totalRows_rsodest= $this->mysqllocal->selectData ( "select * from process_claim_no where ins_company=$INSCOMPANYCODE and provider_id=$PROVIDERID and member_no=$MEMBERSHIPID and process_claim_no=$CLAIMNUMBER");



	

	if($totalRows_rsodest!=false){

		

		

$queryItems = $this->mysqllocal->selectData ("SELECT * FROM claims_details WHERE process_claim_no=$CLAIMNUMBER");





if($queryItems!=false){



$submitted=$queryItems[0]['submitted_status'];



if($submitted!='submitted'){	

$row_rsclaim_drug=$this->mysqllocal->selectData ("SELECT * FROM patient_info where member_no=$MEMBERSHIPID and ins_company=$INSCOMPANYCODE");



$mobile_number=$row_rsclaim_drug[0]['telephone_no'];

$member_no_txt=$row_rsclaim_drug[0]['member_no'];	

$member_surname=$row_rsclaim_drug[0]['surname'];

$ins_company_code=$row_rsclaim_drug[0]['ins_company'];



$row_rsclaim_sms=$this->mysqllocal->selectData ("SELECT * from insurance_company WHERE company_code=$ins_company_code");



$sms_name=$row_rsclaim_sms[0]['sms_name'];

$company_tel=$row_rsclaim_sms[0]['company_tel'];

$app_address=$row_rsclaim_sms[0]['app_address'];



if($row_rsclaim_drug!=false){



$validation_key=md5($CLAIMNUMBER.$md5key);	

$query_insert=$this->mysqllocal->insertData ("update claims_details set submitted_status='submitted', submit_time=NOW(), validation_pin='$md5key', validation_key='$validation_key' where process_claim_no=$CLAIMNUMBER");	





$query_insert=$this->mysqllocal->insertData ("update process_claim_no set validation_key='$validation_key', submit_time=NOW(), status='Submitted' where process_claim_no=$CLAIMNUMBER");	





$row_rsclaim_total=$this->mysqllocal->selectData ("select sum(qty*unit_price) as claim_total from claims_details where process_claim_no=$CLAIMNUMBER");





$totalclaim2=number_format($row_rsclaim_total[0]['claim_total'],2);

$consultdate=date('dS M Y');



$mobile_number=trim($mobile_number);

//echo $facility_name;

 $smstxt="Dear $member_surname ($member_no_txt), $facility_name has made a claim of GHC $totalclaim2 for Claim No. $process_claim_no on $consultdate for you. For queries visit $app_address or call $company_tel";

//echo "john";

  

    $apikey="e5145ab0306774cecfcf";

    $text = urlencode($smstxt);

    $to = trim($mobile_number);



    

	$url = "http://bulk.mnotify.net/smsapi?key=$apikey&to=$to&msg=$text&sender_id=$sms_name";

//echo $url;

    // do auth call

	if($mobile_number){

   //$ret = file_get_contents($url);

	}

	

	$STATUSCODE="012";

	$STATUSMSG="Authorization Permitted. Claims Data Submitted Sucessfully";



	

	$data = array(

				"STATUSCODE"=>"$STATUSCODE",

				"STATUSMSG"=>"$STATUSMSG"

			);



	

}



	

}else{

$STATUSCODE="013";

$STATUSMSG="Authorization Permitted. Claims has already been submitted. You can't submit it again.";



$data = array(

				"STATUSCODE"=>"$STATUSCODE",

				"STATUSMSG"=>"$STATUSMSG"

			);			

	

}

			

}else{

$STATUSCODE="010";

$STATUSMSG="Authorization Permitted. Claim Details for Claim Number not found.";



$data = array(

				"STATUSCODE"=>"$STATUSCODE",

				"STATUSMSG"=>"$STATUSMSG"

			);		

	

}

		

	}else{

	

	$STATUSCODE="007";

	$STATUSMSG="Authorization Permitted. Claims Number Not Found for the given MEMBER. Please Contact your IT administrator";

	$data = array(

				"STATUSCODE"=>"$STATUSCODE",

				"STATUSMSG"=>"$STATUSMSG"

			);	

		

	}





	return $data;



        

	}





	

	

}

?>