<cfif session.earole does not contain 'Scheduling' AND session.earole does not contain 'Project Manager'>
	<p>You don&apos;t have accees to this report</p><cfabort>
</cfif>
<script type="text/javascript">
	$(document).ready(function () {
		$("#DataTable").dataTable({
			"sPaginationType": "full_numbers"
			//"bJQueryUI": true,
			//"aaSorting": [[1,'ASC']]
		});
	});
</script>
<cfparam name="FORM.pid"  default="">
<cfparam name="FORM.eid"  default="">
<cfparam name="Form.df" type="string" default="">
<cfparam name="Form.dt" type="string" default="">
<cfsetting requestTimeOut="50000">
<cfset Period = DateAdd("d",-1,Now())>


    
<!--- Query matches getMissingEligibility from cron_dashboard_emp_count.cfm --->
<cfquery  name="GetList"  datasource="#Application.DataSrc#">
	SELECT 
		pPatients.Patient_ID, pPatients.Pt_Last AS PatientLast, pPatients.Pt_First AS PatientFirst,
		MIN(pPayer.Pay_Name) AS Pay_Name, MIN(pPtPayer.PtPayer_ID) AS PtPayer_ID,
		pEmployee.Emp_Last, pEmployee.Emp_First,
		pAdmit.Case_Manager
	FROM #Request.prefix_db_agency#.pAdmit pAdmit
	JOIN #Request.prefix_db_agency#.pPatients pPatients ON pPatients.Patient_ID = pAdmit.Patient_ID
		AND pPatients.Status = 0
	JOIN #Request.prefix_db_agency#.pPtPayer ON pPtPayer.Patient_ID = pPatients.Patient_ID
		AND pPtPayer.PtPayer_ID IS NOT NULL
		AND pPtPayer.status = 0
	JOIN #Request.prefix_db_agency#.pPayer ON pPayer.Pay_ID = pPtPayer.Payer_ID
		AND pPayer.Status = 0
	LEFT OUTER JOIN #Request.prefix_db_agency#.Eligibility ON Eligibility.PtPayer_ID = pPtPayer.PtPayer_ID
		AND Eligibility.Status = 0
		AND (Eligibility.Expiration_Date >= <cfqueryparam value="#Now()#" cfsqltype="CF_SQL_TIMESTAMP">
			OR (Eligibility.Expiration_Date IS NULL AND Eligibility.Start_Date IS NOT NULL))
	LEFT OUTER JOIN #Request.prefix_db_lookup#.pEmployee ON pEmployee.Emp_ID = pAdmit.Case_Manager
	LEFT OUTER JOIN #Request.prefix_db_agency#.employee_auth ON pEmployee.Emp_ID = employee_auth.eaID
	WHERE pAdmit.Status = 0
		AND Eligibility.Elig_ID IS NULL
		AND pAdmit.Admit_ID NOT IN (
			SELECT pAssessments.Admit_ID
			FROM #Request.prefix_db_agency#.pAssessments
			WHERE (pAssessments.F26 like '9%' OR pAssessments.F26 like '7%' OR pAssessments.F26 like '8%')
				AND pAssessments.Status = 0
		)
		AND pPatients.Loc_ID = '#session.agencyid#'
		<cfif session.earole contains 'Field' AND session.eaRole does not contain 'Project Manager' AND session.eaRole does not contain 'Quality'>
			AND COALESCE(pAdmit.Case_Manager, 2) = <cfqueryparam value="#session.employeeid#" cfsqltype="CF_SQL_INTEGER">
		</cfif>
	GROUP BY pPatients.Patient_ID, pPatients.Pt_Last, pPatients.Pt_First, pEmployee.Emp_Last, pEmployee.Emp_First, pAdmit.Case_Manager
	ORDER BY pPatients.Pt_Last ASC, pPatients.Pt_First ASC
</cfquery>
	
<style>
	@media print
	{
		a[href]:after
		{
		content:none
		}
	}
</style>

<div class="portlet box yellow">
	<div class="portlet-title">
		<div class="caption">
			<i class="fa fa-gear"></i> Missing Eligibility
		       
		</div>
		<div class="tools">
			<a href="javascript:;" class="collapse"></a>
		</div>
		<div class="actions">payer requirement for eligibility in Setup > Payers&nbsp;&nbsp;
			<input type="button" class="btn default btn-xs" name="Cancel" value="Back" onclick="window.history.back();">
		</div>
	</div>
	
	<div class="portlet-body">			
	   <table class="table table-striped table-bordered table-hover" id="DataTable">
        	<thead>
           		<tr>
           			<th  align="center" >Patient</th>
           			<th  align="center" >Payer</th>
           		</tr>
           	</thead>
           	<tbody>
           		<cfset totalDisplayedCount = 0>
           		<cfoutput query="GetList" group="Patient_ID">
                	<cfset totalDisplayedCount = totalDisplayedCount + 1>
                	<cfset enc_patientid  = encrypt(#Patient_ID#,"#Application.enckey#","AES","Hex") />
           			<tr style="height:30px;" class="list-hdr" id="tr#Patient_ID#">
           				<td><a href="../patientadmin_new/index.cfm?page=patient&cat=Patient&id=#enc_patientid#&restrict=1&formonly=1">#PatientLast# #PatientFirst#</a></td>
           				<td>#Pay_Name#</td>
           			</tr>
               	</cfoutput>
           	</tbody>
         </table>

         <!--- Only mark/insert when report was filtered to logged employee (session.employeeid in query) --->
         <cfif session.IsAgencyLogin EQ 0 AND session.earole contains 'Field' AND session.eaRole does not contain 'Project Manager' AND session.eaRole does not contain 'Quality'>
         <!--- Disable existing count and insert latest TR count for logged employee --->
         <cfquery name="markDashCountForLoggedEmployee" datasource="#Application.DataSrc#">
             UPDATE #Request.prefix_db_agency#.Dash_emp_count SET status = 1
             WHERE status = 0 AND Header = <cfqueryparam value="missing eligibility" cfsqltype="CF_SQL_VARCHAR">
             AND Emp_ID = <cfqueryparam value="#session.employeeid#" cfsqltype="CF_SQL_INTEGER">
         </cfquery>
         <cfquery name="insertDashEmpCount" datasource="#Application.DataSrc#">
             INSERT INTO #Request.prefix_db_agency#.Dash_emp_count (Daily_QA_Date, Emp_ID, Emp_Count, Header, Created_Date, status)
             VALUES (
                 <cfqueryparam value="#DateFormat(Now(), 'yyyy-mm-dd')#" cfsqltype="CF_SQL_DATE">,
                 <cfqueryparam value="#session.employeeid#" cfsqltype="CF_SQL_INTEGER">,
                 <cfqueryparam value="#totalDisplayedCount#" cfsqltype="CF_SQL_INTEGER">,
                 <cfqueryparam value="missing eligibility" cfsqltype="CF_SQL_VARCHAR">,
                 <cfqueryparam value="#Now()#" cfsqltype="CF_SQL_TIMESTAMP">,
                 <cfqueryparam value="0" cfsqltype="CF_SQL_INTEGER">
             )
         </cfquery>
         </cfif>

	 </div>
</div>


				        
				
				
			

