<!---
This file is Copyright © 1998-2009 by Home Care Business Services. This work may not be reproduced, in whole or in part, 
using any medium, including, but not limited to, electronic transmission, CD-ROM or published in print, without the express 
permission of Home Care Business Services.

$Revision: 1.4 $
$Id: visit_edit_action.cfm,v 1.4 2009/06/12 15:31:14 arlen Exp $
$Date: 2009/06/12 15:31:14 $
--->


<!--- Page specific code, such as queries and variable settings should go here --->
<!--- Calculate EClaim and QB Totals --->
<cfquery  name="GetRev" datasource="#Application.DataSrc#">
SELECT *
FROM #Request.prefix_db_agency#.Revenue_Code
WHERE Agency_ID = #session.AgencyID#
AND Rev_CodeID = '#form.Rev_CodeID#'
</cfquery>

<cfquery  name="GetEPay" datasource="#Application.DataSrc#">
SELECT Pay_Rate
FROM #Request.prefix_db_agency#.Employee_Payroll
WHERE Agency_ID = #session.AgencyID#
AND EmpPay_ID = '#form.EmpPay_ID#'
</cfquery>

<cfquery  name="GetOutput" datasource="#Application.DataSrc#">
SELECT Output_Type
FROM #Request.prefix_db_agency#.Payer
WHERE Agency_ID = #session.AgencyID#
AND Payer_ID = '#form.Payer_ID#'
</cfquery>


<cfif #form.StartTime# IS NOT "" AND #form.EndTime# IS NOT "">
	<!--- Determine number of minutes (n) apart --->
	<cfset diff = #DateDiff("n",form.StartTime,form.EndTime)#>
	<!--- Calculate number of units (4 per hour) --->
	<cfif #GetRev.Measure# IS ".25"><cfset units = (#diff#/60)*100/25></cfif>
	<cfif #GetRev.Measure# IS "1"><cfset units = (#diff#/60)*100></cfif>
	<cfif #GetRev.Measure# IS "visit"><cfset units = 1></cfif>
	<cfif units lt 0><cfset units=units+96></cfif>
	<cfset eclaimtot = #GetRev.EClaim_Price# * #units#>
	<cfset qbtot = #GetRev.Quick_Books_Price# * #units#>
<cfelse>
	<cfset units = 0>
	<cfset eclaimtot = 0>
	<cfset qbtot = 0>
</cfif>

<cfif #form.StartTime# IS NOT "" AND #form.EndTime# IS NOT "" AND #form.EmpPay_ID# IS NOT 0>
	<!--- Determine number of minutes (n) apart --->
	<cfset diff = #DateDiff("n",form.StartTime,form.EndTime)#>
	<cfif diff lt 0><cfset diff=diff+(24*60)></cfif>
	<!--- <cfset units = (#diff#/60)*100/25> --->
	<cfset epay_min = #GetEPay.Pay_Rate#/60>
	<cfset total_epay = #diff# * #epay_min#>
<cfelse>
	<cfset emppay_ID = 0>
	<cfset total_epay = 0>
</cfif>

<cfif #GetOutput.Output_Type# IS "Medicare" AND #GetRev.Visit_Type# IS 'Assessment'>
	<cfset Output_Type = 'RAP'>
	<cfelse> 
	<cfset Output_Type = #GetOutput.Output_Type#>
</cfif>

<cfif #GetRev.Rev_CodeID# IS NOT "">
	<cfset Rev_Code = #GetRev.Rev_Code#>
	<cfset HCPCS = #GetRev.HCPCS#>
	<cfset Visit_Type = #GetRev.Visit_Type#>
	<cfset Bill_Type = #GetRev.Description#>
</cfif>

<cfquery  name="UpdateSchedule" datasource="#Application.DataSrc#">
	Update #Request.prefix_db_agency#.ScheduleItems
	Set
	Patient_ID = #form.patient_ID#,
	Visit_Date = #CreateODBCDateTime(form.visitdate)#, 
	Employee_ID = #form.employee_ID#, 
	Record_Mod_Date = #now()#, 
	Record_Mod_By = #Session.EmployeeID#, 
	Payer_ID = '#form.Payer_ID#',
	Rev_CodeID = '#form.Rev_CodeID#',
	EmpPay_ID = '#form.EmpPay_ID#',
	StartTime = '#form.StartTime#',
	EndTime = '#form.EndTime#',
	Rev_Code = '#Rev_Code#',
	Visit_Type = '#Visit_Type#',
	Bill_Type = '#Bill_Type#',
	HCPCS = '#HCPCS#',
	Output_Type = '#Output_Type#',
	Total_Units = #units#,
	Total_EClaim = #eclaimtot#,
	Total_QB = #qbtot#,
	Total_EPay = #total_epay#,
	Progress_Note = '#form.progress_note#',
	Visit_Notes = '#form.visit_notes#',
	Missed = '#form.missed#'
	Where ScheduleItems_ID = #Form.ScheduleItems_ID#
	AND Agency_ID = #session.AgencyID#
</cfquery>

<!--- End page specific code --->

					<h1>Visit Updated</h1>
					<FORM><INPUT type="button" value="Click here to go back" onClick="history.back()"> </FORM><br>
					<cfoutput><a href="employee_compliance.cfm">Click to return to Employee Compliance.</a></cfoutput>


