<cfcomponent displayname="Locations Functions" hint="I Return Locations Information" output="false">

	<cfset client.Loc_ID = 0 />
	
   <cffunction name="init" displayname="Initialize Component" access="public" returntype="Employees" hint="I initialize and return the Employees object.">
		<cfreturn this>
	</cffunction>
    
   	<cffunction name="get_all_employees"  returntype="any" access="public" output="false" >
	    <cfargument name="Loc_ID" required="no" hint="Loc_ID" default="#client.Loc_ID#">
	    <cfargument name="status" required="no" hint="status" default="0">
		  <cfquery name = "getall" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.employee
				 WHERE Loc_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#client.Loc_ID#">
				 AND Status = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.status#">
		  </cfquery>
		 <cfreturn  getall>
	</cffunction>

	<cffunction name="get_emp"  returntype="any" access="public" output="false" >
	    <cfargument name="empid" required="yes" hint="Emp_ID" >
	    <cfargument name="Loc_ID" required="no" hint="Loc_ID" default="#client.Loc_ID#">
	    		  <cfquery name = "getall" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.employee
				 WHERE Loc_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.Loc_ID#">
				 AND Emp_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.empid#">
		  </cfquery>
		 <cfreturn  getall>
	</cffunction>

    <cffunction name="check_emp_email" access="remote"  httpmethod="GET" returnformat="plain" >
	    <cfargument name="email" required="yes" hint="email">
	    <cfargument name="phone" required="yes" hint="Phonenumber">
	    <cfargument name="username" required="yes" hint="username">
        <cfargument name="empid" required="no" hint="Emp_ID" default="0">

		  <cfquery name = "get_email" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.employee
				 WHERE Emp_Email =  <cfqueryparam VALUE="#arguments.email#"  cfsqltype="cf_sql_varchar">
				 AND Emp_ID != <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.empid#">
		  </cfquery>
		  <cfquery name = "get_phone" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.employee 
				WHERE Emp_Telephone = <cfqueryparam VALUE="#arguments.phone#"  cfsqltype="cf_sql_varchar">
				AND Emp_ID != <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.empid#">
		  </cfquery>
		   <cfquery name = "get_username" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.employee 
				WHERE Username = <cfqueryparam VALUE="#arguments.username#"  cfsqltype="cf_sql_varchar">
				AND Emp_ID != <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.empid#">
		  </cfquery>
		  <cfif get_email.recordcount gt 0>
			 <cfreturn 'email'>
		  <cfelseif get_phone.recordcount gt 0>
			 <cfreturn 'phone'>
		  <cfelseif get_username.recordcount gt 0>
			 <cfreturn 'username'>
		  <cfelse>
		     <cfreturn 'Success'>
		 </cfif>
	</cffunction>

	 <cffunction name="check_email" access="remote"  httpmethod="GET" returnformat="plain" >
	    <cfargument name="email" required="yes" hint="email">
	    <cfargument name="phone" required="yes" hint="Phonenumber">
	    <cfargument name="username" required="yes" hint="username">
        <cfargument name="empid" required="no" hint="Emp_ID" default="0">

			<cfquery  name='chkemail' datasource='#Application.DataSrc#'>
					SELECT count(Emp_Email) as email from #Request.prefix_db_lookup#.pEmployee 
					WHERE Emp_Email = <cfqueryparam VALUE="#arguments.email#"  cfsqltype="cf_sql_varchar"> 
					AND Loc_ID =  #session.agencyid#
					group by Emp_Email having count(Emp_Email) >= 1
			</cfquery>

			<cfquery  name='chkusername' datasource='#Application.DataSrc#'>
					SELECT count(Username) as username from #Request.prefix_db_lookup#.pEmployee 
					WHERE Username = <cfqueryparam VALUE="#arguments.username#"  cfsqltype="cf_sql_varchar"> 
					group by Username having count(Username) >= 1
			</cfquery>
			
			<cfquery  name='chkphone' datasource='#Application.DataSrc#'>
					SELECT count(Emp_Telephone) as phone from #Request.prefix_db_lookup#.pEmployee 
					WHERE Emp_Telephone = <cfqueryparam VALUE="#arguments.phone#"  cfsqltype="cf_sql_varchar"> 
					group by Emp_Telephone having count(Emp_Telephone) >= 1
			</cfquery>
					
		  <cfif chkemail.email gte 1 >
			 <cfreturn 'email'>
		  <cfelseif chkphone.phone gte 1>
			 <cfreturn 'phone'>
		  <cfelseif chkusername.username gte 1>
			 <cfreturn 'username'>
		  <cfelse>
		     <cfreturn 'Success'>
		 </cfif>
	</cffunction>

    
     <cffunction name="get_all_physician"  returntype="any" access="public" output="false" >
	    <cfargument name="Loc_ID" required="no" hint="Loc_ID" default="#client.Loc_ID#">
		  <cfquery name = "getall" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.physicians
				 WHERE Loc_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#client.Loc_ID#">
		  </cfquery>
		 <cfreturn  getall>
	</cffunction>

	<cffunction name="get_phy"  returntype="any" access="public" output="false" >
	    <cfargument name="phyid" required="yes" hint="Phyician_ID" >
	    <cfargument name="Loc_ID" required="no" hint="Loc_ID" default="#client.Loc_ID#">
	    		  <cfquery name = "getphy" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.physicians
				 WHERE Loc_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.Loc_ID#">
				 AND Phys_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.phyid#">
		  </cfquery>
		 <cfreturn  getphy>
	</cffunction>

	 <cffunction name="check_phy_email" access="remote"  httpmethod="GET" returnformat="plain" >
	    <cfargument name="email" required="yes" hint="email">
	    <cfargument name="phone" required="yes" hint="Phonenumber">
	    <cfargument name="username" required="yes" hint="username">
        <cfargument name="phyid" required="no" hint="Phy_ID" default="0">

		  <cfquery name = "get_email" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.physicians
				 WHERE Phys_Email =  <cfqueryparam VALUE="#arguments.email#"  cfsqltype="cf_sql_varchar">
				 AND Phys_ID != <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.phyid#">
				 AND Phys_Email != ''
		  </cfquery>
		  <cfquery name = "get_phone" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.physicians 
				WHERE Phys_Phone = <cfqueryparam VALUE="#arguments.phone#"  cfsqltype="cf_sql_varchar">
				AND Phys_ID != <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.phyid#">
		  </cfquery>
		   <cfquery name = "get_username" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.physicians 
				WHERE Username = <cfqueryparam VALUE="#arguments.username#"  cfsqltype="cf_sql_varchar">
				AND Phys_ID != <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.phyid#">
		  </cfquery>
		  <cfif get_email.recordcount gt 0>
			 <cfreturn 'email'>
		  <cfelseif get_phone.recordcount gt 0>
			 <cfreturn 'phone'>
		  <cfelseif get_username.recordcount gt 0>
			 <cfreturn 'username'>
		  <cfelse>
		     <cfreturn 'Success'>
		 </cfif>
	</cffunction>

	<cffunction name="get_all_payers"  returntype="any" access="public" output="false" >
	    <cfargument name="Loc_ID" required="no" hint="Loc_ID" default="#client.Loc_ID#">
		  <cfquery name = "getall" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.payers
				 WHERE Loc_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#client.Loc_ID#">
		  </cfquery>
		 <cfreturn  getall>
	</cffunction>

     <cffunction name="get_pay"  returntype="any" access="public" output="false" >
	    <cfargument name="payid" required="yes" hint="Payer_ID" >
	    <cfargument name="Loc_ID" required="no" hint="Loc_ID" default="#client.Loc_ID#">
	    		  <cfquery name = "getpay" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.payers
				 WHERE Loc_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.Loc_ID#">
				 AND Pay_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.payid#">
		  </cfquery>
		 <cfreturn  getpay>
	</cffunction>

	<cffunction name="get_empform"  access="remote" output="Yes" returnFormat= "plain">   
	<cfargument name="empid" required="yes" hint="empid" > 
	<cfargument name="Loc_ID" required="no" hint="Loc_ID" default="#client.Loc_ID#">
	     <cfif arguments.empid neq 0>
				<cfset arguments.empid  = decrypt(#arguments.empid#,#application.key#,"AES","Hex") />	 
	     </cfif>  
               <cfinclude template="#application.secure#/locations/emp_form_new.cfm"> 
               <cfreturn html_list />	
   </cffunction>

   <cffunction name="get_phyform"  access="remote" output="Yes" returnFormat= "plain">   
	<cfargument name="phyid" required="yes" hint="phyid" > 
	<cfargument name="Loc_ID" required="no" hint="Loc_ID" default="#client.Loc_ID#">
	          <cfinclude template="#application.secure#/locations/physician_form_new.cfm"> 
               <cfreturn html_content />	
   </cffunction>
        

  <cffunction name="get_payform"  access="remote" output="Yes" returnFormat= "plain">   
	<cfargument name="payid" required="yes" hint="payid" > 
	<cfargument name="Loc_ID" required="no" hint="Loc_ID" default="#client.Loc_ID#">
	          <cfinclude template="#application.secure#/locations/payer_form_new.cfm"> 
               <cfreturn html_content />	
   </cffunction>
        


</cfcomponent>