<!---
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.6 $
$Id: getitems.cfm,v 1.6 2010/05/04 16:01:58 arlen Exp $
$Date: 2010/05/04 16:01:58 $
--->

<cfparam name=t default="">
<cfparam name=id default=0>
<cfparam name="url.Dep_ID" default=0>
<cfparam name="URL.Auth_ID" default="1">

<cfif NOT isdefined("session.agencyid")>
	<h2>Your Session has timed out.</h2><br /> <p>Please Login again.<br /></p> 
<cfelse>

<cfif url.t eq "payroll">

		<cfif url.id eq ''>
			<select class="form-control" name="EmpPay_ID" id="selectpayroll" >
			<option value=0 selected>Select a Payroll Code...</option>
			</select>
		<cfelse>
			<cfquery  datasource="#Application.DataSrc#" name="payrolllist">
					SELECT Employee_Payroll.EmpPay_Id, Employee_Payroll.Emp_ID, Agency_Payroll.Visit_Type, Agency_Payroll.Description
					FROM   #Request.prefix_db_agency#.Employee_Payroll, #Request.prefix_db_agency#.Agency_Payroll
					WHERE  Agency_Payroll.Agency_Id = #session.AgencyId#
					AND    Agency_Payroll.Deleted != 'Y'
					AND    Employee_Payroll.Payroll_Id = Agency_Payroll.Payroll_Id
					AND    Employee_Payroll.Emp_ID = #url.id#
					AND    Employee_Payroll.Deleted != 'Y'
					AND    Employee_Payroll.Emp_ID<>'0'
					ORDER BY Employee_Payroll.Emp_ID, Agency_Payroll.Visit_Type, Agency_Payroll.Description
			</cfquery>

			<select class="form-control"  name="EmpPay_ID" id="selectpayroll"   <cfif session.eaScheduling does not contain  'edit_payroll_code'>disabled</cfif>>
			<option value=0 <cfif NOT (isdefined("url.payroll") AND len(trim(url.payroll)) AND val(url.payroll) GT 0)>selected</cfif>>Select a Payroll Code...</option>
			<cfoutput query=payrolllist>
			    <cfif isdefined("url.payroll")  and  #url.payroll# neq ''>
			      <option value=#EmpPay_ID# <cfif isdefined("url.payroll") and #url.payroll# eq #EmpPay_ID# >selected</cfif>>#visit_type# - #description#</option>
			     <cfelse>
				   <option value=#EmpPay_ID#<cfif isdefined("Session.AddSchedule.Payroll") and #Session.AddSchedule.Payroll# eq #EmpPay_ID# >selected</cfif>>#visit_type# - #description#</option>
			    </cfif>
			</cfoutput>
			</select>
		</cfif>


<cfelseif url.t eq "revenue">

		<cfif url.id eq ''>
			<select class="form-control" name="Rev_ID" id="Rev_ID" >
			 <option value=0 selected>Select a Revenue Code...</option>
			</select>
		<cfelse>
			<cfquery  name="getpayers" datasource="#Application.DataSrc#">
				SELECT * FROM   #Request.prefix_db_agency#.pPtPayer
                JOIN #Request.prefix_db_agency#.pPayer  on  pPtPayer.Payer_ID =  pPayer.Pay_ID 
                WHERE pPtPayer.Status = 0
                AND  pPtPayer.PtPayer_ID  = '#url.id#'
            </cfquery>

			<cfquery  name="revenuelist" datasource="#Application.DataSrc#">
				SELECT Rev_Code, Rev_CodeID, HCPCS, Visit_Type, Payer_ID, Description
				FROM #Request.prefix_db_agency#.pRevenue_Code
				WHERE Agency_ID = '#session.AgencyId#'
				AND   Status = '0'
				AND   EClaim_Price IS NOT NULL
				AND   Quick_Books_Price IS NOT NULL
				AND   Payer_ID = '#getpayers.Pay_ID#'
				<!--- <cfif getpayer.Output EQ 'Medicare'>  
			        GROUP BY Rev_Code,Visit_Type
			     </cfif> --->
			</cfquery>

			 <input type="hidden" name="Auth_Req" id="Auth_Req" value="<cfoutput>#getpayers.Auth_Req#</cfoutput>" >
			<select class="form-control" name="Rev_ID" id="Rev_ID"   <!--- <cfif  session.agencyid EQ '179' AND URL.Auth_ID EQ 0>onChange="unscheduledvisits(this.value)" </cfif>---> >
			 <option value="" selected><cfif revenuelist.recordcount lt 1>No Revenue Codes available for the Payer selected<cfelse>Select a Revenue Code...</cfif></option>
				<cfoutput query=revenuelist>
					<option value=#Rev_CodeID#>
					<cfif getpayers.Output EQ 'Medicare'>
							#Rev_Code# | #Visit_Type# | #LEFT(Description,20)#
					<cfelse>
							#Visit_Type# | #LEFT(Description,20)#... | #Rev_Code# | #HCPCS#
					</cfif>
					</option>
				</cfoutput>
			</select>
			
		<!---	<div class="row">
                        <div class="col-md-6">
						  <div class="form-group">
                            	  <select name="Rev_CodeID" id="selectrevenue" class="form-control" onchange="bindemployees('selectemployee_id',this);">
                                    <option value="0" selected ><cfif revenuelist.recordcount gt 0 and revenuelist.recordcount eq 1>No Revenue Codes available for the Payer selected<cfelse>Select a Revenue Code...</cfif></option>
                                    <cfoutput query="revenuelist">
                                        <option value="#Rev_CodeID#">#Visit_Type# | #LEFT(Description,20)#... | #Rev_Code# | #HCPCS#</option>
                                    </cfoutput>
                            	</select>
                        </div>
						</div>
						<div class="col-md-6">
						  <div class="form-group">
									<select name="Auth_ID" id="Auth_ID" class="form-control">
										<option value='' selected>--Select Authorizations--</option>
											<cfoutput query= authorizations>
											     <option value='#Auth_ID#'>#Revenue_Code# | #HCPCS_Code# | #PayName# | #DateFormat(StartDate,"mm/dd/yyyy")# - #DateFormat(EndDate,"mm/dd/yyyy")# | #Authorization_Number#</option>
											</cfoutput>
									</select>
	                          </div>
						</div>
					</div>--->
			
		</cfif>
		
<cfelseif url.t eq "rev_auth">
		
		<cfquery  name="revenuelist" datasource="#Application.DataSrc#">
				SELECT Rev_Code, Rev_CodeID, HCPCS, Visit_Type, Payer_ID, Description
				FROM #Request.prefix_db_agency#.pRevenue_Code
				WHERE Agency_ID = '#session.AgencyId#'
				AND   Status = '0'
				AND   EClaim_Price IS NOT NULL
				AND   Quick_Books_Price IS NOT NULL
				AND   Payer_ID = '#url.id#'
		</cfquery>
			
	
        <div class="col-md-6">
		    <div class="form-group">
		        <label>Revenue Code</label>
            	<select name="Rev_CodeID" id="selectrevenue" class="form-control" onchange="bindemployees('selectemployee_id',this);">
                    <option value="0" selected ><cfif revenuelist.recordcount gt 0 and revenuelist.recordcount eq 1>No Revenue Codes available for the Payer selected<cfelse>Select a Revenue Code...</cfif></option>
                    <cfoutput query="revenuelist">
                        <option value="#Rev_CodeID#">#Visit_Type# | #LEFT(Description,20)#... | #Rev_Code# | #HCPCS#</option>
                    </cfoutput>
            	</select>
            </div>
		</div>
						
			<cfquery  name="Get_auth_date" datasource="#Application.DataSrc#">
			select authorizations.StartDate,authorizations.EndDate from #Request.prefix_db_agency#.authorizations
			WHERE  authorizations.Patient_ID = '#Session.CS.PatientID#'
			AND authorizations.Payer_ID = '#url.id#'
			AND authorizations.Deleted <> 1
			</cfquery>
			
			
			<cfquery  name="authorizations" datasource="#Application.DataSrc#">
			SELECT authorizations.Auth_ID,authorizations.Payer_ID,Payer.PayName,authorizations.Authorization_Number,
			authorizations.Revenue_Code,authorizations.HCPCS_Code,authorizations.StartDate,authorizations.EndDate from 
			#Request.prefix_db_agency#.authorizations,#Request.prefix_db_agency#.Payer,#Request.prefix_db_agency#.ScheduleItems 
			WHERE authorizations.Payer_ID= Payer.Payer_ID
			AND authorizations.Revenue_Code= ScheduleItems.Rev_Code
			AND authorizations.Payer_ID= ScheduleItems.Payer_ID
			AND authorizations.Patient_ID = '#Session.CS.PatientID#'
			 AND authorizations.Payer_ID = '#url.id#'
			AND ScheduleItems.Visit_Date >= '#DateFormat(Get_auth_date.StartDate,"yyy-mm-dd")#'
			AND ScheduleItems.Visit_Date <= '#DateFormat(Get_auth_date.EndDate,"yyy-mm-dd")#'
			AND authorizations.Deleted <> 1
			Group By authorizations.Auth_ID
			</cfquery>
			
						<div class="col-md-6">
						  <div class="form-group">
						  <label>Authorization</label>
									<select name="Auth_ID" id="Auth_ID" class="form-control">
										<option value='' selected>--Select Authorizations--</option>
											<cfoutput query= authorizations>
											     <option value='#Auth_ID#'>#Revenue_Code# | #HCPCS_Code# | #PayName# | #DateFormat(StartDate,"mm/dd/yyyy")# - #DateFormat(EndDate,"mm/dd/yyyy")# | #Authorization_Number#</option>
											</cfoutput>
									</select>
	                          </div>
						</div>
					</div>
		
<cfelseif url.t eq "auth">
		
		<cfquery  name="Get_auth_date" datasource="#Application.DataSrc#">
			select authorizations.StartDate,authorizations.EndDate from #Request.prefix_db_agency#.authorizations
			WHERE  authorizations.Patient_ID = '#Session.CS.PatientID#'
			AND authorizations.Payer_ID = '#url.id#'
			AND authorizations.Deleted <> 1
			</cfquery>
			
			
			<cfquery  name="authorizations" datasource="#Application.DataSrc#">
			SELECT authorizations.Auth_ID,authorizations.Payer_ID,Payer.PayName,authorizations.Authorization_Number,
			authorizations.Revenue_Code,authorizations.HCPCS_Code,authorizations.StartDate,authorizations.EndDate from 
			#Request.prefix_db_agency#.authorizations,#Request.prefix_db_agency#.Payer,#Request.prefix_db_agency#.ScheduleItems 
			WHERE authorizations.Payer_ID= Payer.Payer_ID
			AND authorizations.Revenue_Code= ScheduleItems.Rev_Code
			AND authorizations.Payer_ID= ScheduleItems.Payer_ID
			AND authorizations.Patient_ID = '#Session.CS.PatientID#'
			 AND authorizations.Payer_ID = '#url.id#'
			AND ScheduleItems.Visit_Date >= '#DateFormat(Get_auth_date.StartDate,"yyy-mm-dd")#'
			AND ScheduleItems.Visit_Date <= '#DateFormat(Get_auth_date.EndDate,"yyy-mm-dd")#'
			AND authorizations.Deleted <> 1
			Group By authorizations.Auth_ID
			</cfquery>
		
		<select name="Auth_ID" id="Auth_ID" class="form-control">
			<option value='' selected>--Select Authorizations--</option>
				<cfoutput query= authorizations>
				     <option value='#Auth_ID#'>#Revenue_Code# | #HCPCS_Code# | #PayName# | #DateFormat(StartDate,"mm/dd/yyyy")# - #DateFormat(EndDate,"mm/dd/yyyy")# | #Authorization_Number#</option>
				</cfoutput>
		</select>

<cfelseif url.t eq "remittance">
		
		<cfquery name="GetPayers" datasource="#Application.DataSrc#">
		    SELECT Distinct Pay_ID, Pay_Name,Payer_No  FROM   #Request.prefix_db_agency#.pPayer
		    WHERE  Loc_ID = #session.AgencyID#
		    AND Status = 0 
		    AND Payer_No = '#url.id#'
		    ORDER BY Pay_Name
		</cfquery>
		<cfquery  name="getdep" datasource="#Application.DataSrc#">
		    SELECT pDeposit.*,Invoices.PatientPayer_ID,pPayer.Pay_ID,Invoices.Invoice_ID   FROM  #Request.prefix_db_agency#.pDeposit 
		    LEFT OUTER JOIN #Request.prefix_db_agency#.Invoices ON Invoices.Internal_control_number = pDeposit.Internal_control_number 
		    AND Invoices.Deleted = 0
		    LEFT OUTER JOIN  #Request.prefix_db_agency#.pPayer ON Invoices.PatientPayer_ID = pPayer.Pay_ID 
		    WHERE  pDeposit.Dep_ID = '#url.Dep_ID#'
		    AND pDeposit.Status = 0
		    GROUP BY pDeposit.Dep_ID
		</cfquery>

		<cfset theid= #getdep.Payer_ID# />
        <select class="form-control input-medium" name="Payer_ID" id="Payer_ID">
            <option value="0" <cfif theid eq ''>Selected</cfif>>--Select--</option>
            <cfoutput query="GetPayers">
                <option value="#GetPayers.Pay_ID#" <cfif #GetPayers.Pay_ID# eq theid>selected</cfif>>#GetPayers.Pay_Name#</option>
            </cfoutput>
        </select>



</cfif>
</cfif>




	


