<?php

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

include 'connections/customPDO.php';

}



class AddClaim {

    



    private	$mysqllocal;





	function __construct($local)

	{

		# code...

		$this->mysqllocal=$local;





	}









	function addClaims($INSCOMPANYCODE,$PROVIDERID,$MEMBERSHIPID,$CLAIMNUMBER,$PROVIDERITEMID,$PROVIDERITEMNAME,$QTY,$UNITPRICE,$ATTENDINGOFFICER,$TYPEOFVISIT,$USERID,$ICDCODE,$DIAGNOSIS,$DATEOFCONSULTATION,$DATEOFADMISSION,$DATEOFDISCHARGE,$DOSAGE,$DOSAGEUNITS,$FREQUENCY,$NOOFDAYS,$METHOD)

	{

		# code...

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

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

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

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

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

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

		

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

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

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

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

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

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

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

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

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

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

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

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



		$query_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 ($query_rsodest!=false) {

			# code...

           $queryItems = $this->mysqllocal->selectData("SELECT * FROM service_items WHERE ins_item_code=$PROVIDERITEMID AND item=$PROVIDERITEMNAME");



        if ($queryItems!=false) {

        	# code...

        	foreach ($queryItems as $arrayItems) {

        		# code...

$PROVIDERITEMID=$arrayItems['id'];

$provider_item_id=$arrayItems['id'];

$ins_item_code=$arrayItems['ins_item_code'];

$item=$arrayItems['item'];

//$unit_price=$arrayItems['price'];

//$unit_price=$this->mysqllocal->quote($UNITPRICE);

$unitprice=$UNITPRICE;

$submitted=$arrayItems['submitted_status'];

if ($METHOD=="UPDATECLAIM" ) {

	# code...



//$unit_price=$arrayItems['unit_price'];

$qtynow=$arrayItems['qty']+$QTY;

$noofdaysnow=$arrayItems['no_of_days']+$NOOFDAYS;

$total_price=$qtynow*$UNITPRICE;

}

$item_class=$arrayItems['itemclass'];

$item_service=$arrayItems['service'];

$item_service_type=$arrayItems['service_type'];

$rx_item_name=$arrayItems['rx_item_name'];

$rx_brand_name=$arrayItems['rx_brand_name'];

$rx_cartegory=$arrayItems['rx_cartegory'];

$rx_prescription_name=$arrayItems['rx_prescription_name'];

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

$total_award='';	



        	}

$ins=$this->mysqllocal->selectData("SELECT * FROM claims_details WHERE ins_company=$INSCOMPANYCODE AND provider_id=$PROVIDERID AND member_no=$MEMBERSHIPID AND process_claim_no=$CLAIMNUMBER AND item='$item' AND provider_item_id=$PROVIDERITEMID");



switch ($METHOD) {

	case 'ADDCLAIM':

		# code...

if ($ins==false) {

	# code...

	    $total_price=$QTY*$UNITPRICE;

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

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

	$this->mysqllocal->insertData("INSERT INTO `claims_details` ( `ins_company`, `provider_id`, `member_no`, `user_id`, `process_claim_no`,  `attending_officer`, `diagnosis`, `diagnosis_code`, `type_of_visit`, `date_of_consultation`, `date_of_admission`, `provider_ref_no`, `provider_item_id`, `ins_item_code`, `item`, `item_class`, `item_service`, `item_service_type`, `unit_price`, `date_added`, `date_added_short`, `qty`, `total_price`, `rx_item_name`, `rx_brand_name`, `rx_cartegory`, `rx_prescription_name`, `dose`, `dosage_form`, `frequency`, `no_of_days`, `action_status`, `current_location`, `supplied`,`provider_id_data_for`) VALUES ( $INSCOMPANYCODE, $PROVIDERID, $MEMBERSHIPID, $USERID, $CLAIMNUMBER, $ATTENDINGOFFICER, $DIAGNOSIS, $ICDCODE, $TYPEOFVISIT, $DATEOFCONSULTATION, $DATEOFADMISSION,  $PROVIDERID, $PROVIDERITEMID, '$ins_item_code', '$item', '$item_class', '$item_service', '$item_service_type', $UNITPRICE, NOW(), NOW(), $QTY, $total_price, '$rx_item_name', '$rx_brand_name', '$rx_cartegory', '$rx_prescription_name', $DOSAGE , $DOSAGEUNITS, $FREQUENCY , $NOOFDAYS ,'Sent to Claims','Claims Office','supplied',$PROVIDERID)");



	$STATUSCODE="008";

	$STATUSMSG="Authorization Permitted. Claims Data has been submitted for the given ITEM";



$data = array(

				"STATUSCODE"=>"$STATUSCODE",

				"STATUSMSG"=>"$STATUSMSG"

			);	

}else{



   $STATUSCODE="009";

	$STATUSMSG="Authorization Permitted. Claims Data has already been submitted before for the given ITEM. Please update Quantity, Dosage, Frequency or Number of Days for Item";



$data = array(

				"STATUSCODE"=>"$STATUSCODE",

				"STATUSMSG"=>"$STATUSMSG"

			);		



}

		break;



case 'UPDATECLAIM':

	# code...

if ($ins==false) {

	$STATUSCODE="011";

	$STATUSMSG="Authorization Permitted. ITEM not Found";



	

	$data = array(

				"STATUSCODE"=>"$STATUSCODE",

				"STATUSMSG"=>"$STATUSMSG"

			);

}else{

$qtynow=$QTY;

$noofdaysnow=$NOOFDAYS;

$total_price=$qtynow*$UNITPRICE;

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

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

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

if($submitted!='submitted'){		

	$this->mysqllocal->insertData( "UPDATE claims_details SET qty=$qtynow, total_price=$total_price, dose=$DOSAGE, dosage_form=$DOSAGEUNITS, frequency=$FREQUENCY, no_of_days=$noofdaysnow,unit_price=$UNITPRICE WHERE process_claim_no=$CLAIMNUMBER AND provider_item_id=$PROVIDERITEMID");

	





	$STATUSCODE="011";

	$STATUSMSG="Authorization Permitted. Claims Data has been Updated for the given ITEM";



	

	$data = array(

				"STATUSCODE"=>"$STATUSCODE",

				"STATUSMSG"=>"$STATUSMSG"

			);

}else{

$STATUSCODE="012";

$STATUSMSG="Authorization Permitted. ITEM found but ITEM has been already submitted to insurance company. Update not successful.";



$data = array(

				"STATUSCODE"=>"$STATUSCODE",

				"STATUSMSG"=>"$STATUSMSG"

			);			

	

}}

	break;







case 'DELETECLAIM':

	# code...

if ($ins==false) {

	$STATUSCODE="011";

	$STATUSMSG="Authorization Permitted. ITEM not Found";



	

	$data = array(

				"STATUSCODE"=>"$STATUSCODE",

				"STATUSMSG"=>"$STATUSMSG"

			);

}else{



if($submitted!='submitted'){		

	$this->mysqllocal->insertData(" DELETE FROM claims_details where process_claim_no=$CLAIMNUMBER and provider_item_id=$PROVIDERITEMID");

	





	$STATUSCODE="011";

	$STATUSMSG="Authorization Permitted. Claims Data has been Deleted for the given ITEM ".$item;



	

	$data = array(

				"STATUSCODE"=>"$STATUSCODE",

				"STATUSMSG"=>"$STATUSMSG"

			);

}else{

$STATUSCODE="012";

$STATUSMSG="Authorization Permitted. ITEM found but the ITEM ".$item." has been already submitted to insurance company. Deletion was not successful.";



$data = array(

				"STATUSCODE"=>"$STATUSCODE",

				"STATUSMSG"=>"$STATUSMSG"

			);			

	

}}

	break;



	

}









 









        }else{

        	$STATUSCODE="010";

$STATUSMSG="Authorization Permitted. ITEM not found in Database";



$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;

	}

}



?>