
<cfparam name = "url.dashdisplay" default="0">
<cfif url.dashdisplay EQ '1'>
    <script type="text/javascript">
      $(document).ready(function () {
        $("#pendingvisits").dataTable({
          "sPaginationType": "full_numbers",
          "pageLength": 5
          //,"bLengthChange": false
        }); 
      });
    </script>
<cfelse>
<script type="text/javascript">
	$(document).ready(function () {
		$("#pendingvisits").dataTable({
			"sPaginationType": "full_numbers",
			"bJQueryUI": true,
			"aaSorting": [[2,'desc']]
		}); 
	});
</script>
</cfif>
<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())>



<cfquery  name="GetList"  datasource="#Application.DataSrc#"  cachedwithin="#createTimeSpan(0, 0, 5, 0)#" >
	SELECT pPatients.Patient_ID, pPatients.Pt_Last AS PatientLast, pPatients.Pt_First AS PatientFirst, 
	COALESCE(pAssessmentsById.F26, pAssessmentsByPatient.F26) AS F26, pSchedules.Assmt_ID, pSchedules.Schedule_ID,pSchedules.Visit_Date,pSchedules.Visit_Type,pSchedules.Skill,
	 pCareplan.Description,pEmployee.Emp_Last,pEmployee.Emp_First,pSchedules.pgnotesdraft,
	(SELECT pAss.F25 FROM #Request.prefix_db_agency#.pAssessments pAss
    WHERE pAss.Patient_ID =  pPatients.Patient_ID 
    AND  (LEFT(pSchedules.Visit_Type,1) = LEFT(pAss.F26,1)
	 OR (  COALESCE(pAssessmentsById.F26, pAssessmentsByPatient.F26) like pSchedules.Visit_Type))  AND pAss.F176 = pSchedules.Visit_Date
    AND pAss.Status = 0 LIMIT 0,1)
    AS assessments_completeds,
    	(SELECT pAss.F25 FROM #Request.prefix_db_agency#.pAssessments pAss
				  WHERE pAss.Patient_ID =  COALESCE(pAssessmentsById.Patient_ID, pAssessmentsByPatient.Patient_ID)
				  AND pAss.Admit_ID = COALESCE(pAssessmentsById.Admit_ID, pAssessmentsByPatient.Admit_ID)
				  AND pAss.F26 =  ( CASE 
									WHEN (pSchedules.Visit_Type = "1 - SOC - SN" )  THEN '1 - Start of care - further visits planned'
									WHEN (pSchedules.Visit_Type = "1 - SOC - PT" ) THEN '1 - Start of care - further visits planned - Physical Therapy'
									WHEN (pSchedules.Visit_Type = "1 - SOC - OT" ) THEN '1 - Start of care - further visits planned - Occupational Therapy'
									WHEN (pSchedules.Visit_Type = "3 - ROC - SN"  || pSchedules.Visit_Type = "3 - ROC - PT") THEN '3 - Resumption of care (after inpatient stay)'
									WHEN (pSchedules.Visit_Type = "PT Eval" ) THEN 'PT Adult Evaluation'
									WHEN (pSchedules.Visit_Type = "OT Eval" ) THEN 'OT Adult Evaluation'
									WHEN (pSchedules.Visit_Type = "ST Eval" ) THEN 'ST Adult Evaluation'
									WHEN (pSchedules.Visit_Type = "SN Eval" ) THEN 'SN Adult Evaluation'
									WHEN (pSchedules.Visit_Type = "MSW Eval" ) THEN 'MSW Evaluation'
									WHEN (pSchedules.Visit_Type = "PT FU Eval" ) THEN 'PT Followup'
							    WHEN (pSchedules.Visit_Type = "OT FU Eval" ) THEN 'OT Followup'
							    WHEN (pSchedules.Visit_Type = "ST FU Eval" ) THEN 'ST Followup'
							    WHEN (pSchedules.Visit_Type = "MSW FU Eval" ) THEN 'MSW Followup'
							    WHEN (pSchedules.Visit_Type = "SN FU Eval" ) THEN 'SN Followup'
							    WHEN (pSchedules.Visit_Type = "Hospice Comprehensive" ) THEN 'Hospice Comprehensive'
							    WHEN (pSchedules.Visit_Type = "SN Hospice" ) THEN 'SN Hospice'
							    WHEN (pSchedules.Visit_Type = "Chaplain Comprehensive Evaluation" ) THEN 'Chaplain Comprehensive Evaluation'
							    WHEN (pSchedules.Visit_Type = "Hospice Discharge" ) THEN 'Hospice Discharge'
									WHEN (pSchedules.Visit_Type = "4 - Recertification" ) THEN '4 - Recertification (follow-up) reassessment'
									WHEN (pSchedules.Visit_Type = "4 - Recertification PT" ) THEN '4 - Recertification (follow-up) reassessment - PT'
									WHEN (pSchedules.Visit_Type = "4 - Recertification OT" ) THEN '4 - Recertification (follow-up) reassessment - OT'
									WHEN (pSchedules.Visit_Type = "5 - Other follow-up" ) THEN '5 - Other follow-up'
									WHEN (pSchedules.Visit_Type = "6 - Transfer no discharge" ) THEN '6 - Transferred to an inpatient facility - patient not discharged from agency'
									WHEN (pSchedules.Visit_Type = "7 - Transfer discharged" ) THEN '7 - Transferred to an inpatient facility - patient discharged from agency'
									WHEN (pSchedules.Visit_Type = "8 - Death" ) THEN '8 - Death at home'
									WHEN (pSchedules.Visit_Type = "9 - Discharge from agency" ) THEN '9 - Discharge from agency'
							ELSE 0
							END )
				  AND pAss.Status = 0  AND pSchedules.Visit_Date = pAss.F176
				  ORDER BY F25 ASC LIMIT 0,1) AS assessments_completed 
 
	FROM #Request.prefix_db_agency#.pSchedules
	LEFT JOIN #Request.prefix_db_agency#.pAssessments pAssessmentsById
		ON pSchedules.Assmt_ID > 0
		AND pSchedules.Assmt_ID = pAssessmentsById.Assmt_ID
		AND pAssessmentsById.status = 0
	LEFT JOIN #Request.prefix_db_agency#.pAssessments pAssessmentsByPatient
		ON pSchedules.Assmt_ID = 0
		AND pAssessmentsByPatient.Patient_ID = pSchedules.Patient_ID
		AND pAssessmentsByPatient.status = 0
	LEFT OUTER JOIN  #Request.prefix_db_agency#.pAdmit ON ( pAdmit.Admit_ID = COALESCE(pAssessmentsById.Admit_ID, pAssessmentsByPatient.Admit_ID) )  AND pSchedules.Patient_ID =pAdmit.Patient_ID AND  pAdmit.status = 0
	JOIN #Request.prefix_db_agency#.pPatients ON  pPatients.Patient_ID = pSchedules.Patient_ID
	LEFT OUTER JOIN  #Request.prefix_db_lookup#.pEmployee ON  pEmployee.Emp_ID = pSchedules.Emp_ID
	LEFT OUTER JOIN #Request.prefix_db_agency#.pSched_Procedure ON  pSched_Procedure.Schedule_ID = pSchedules.Schedule_ID AND pSched_Procedure.Status = 0
	LEFT OUTER JOIN #Request.prefix_db_agency#.pCareplan ON  pCareplan.Careplan_ID = pSched_Procedure.Careplan_ID AND pCareplan.Status = 0
	WHERE  pPatients.Status  = 0
  AND  pSchedules.status = 0
	AND (pSchedules.Assmt_ID = 0 OR pAssessmentsById.Assmt_ID IS NOT NULL)
  AND pSchedules.Missed = 0 
  AND pSchedules.Visit_Date <= '#DateFormat(now(),"yyyy-mm-dd")#'
   <!---<cfif CGI.REMOTE_ADDR EQ '121.200.49.65'>
  	AND pSchedules.Patient_ID = 885
  </cfif>
  AND pSchedules.pgnotesdraft != 2 
  AND pSchedules.pgnotesdraft != 2 

  AND (LEFT(Visit_Type,1) IN (1,3,4,5,6,7,8,9) OR Visit_Type like '%Eval') --->
  <cfif (session.eaType EQ 1 OR  session.IsAgencyLogin EQ 0)  AND session.eaRole does not contain 'Project Manager' 
	     AND  session.eaRole does not contain 'Quality'>
  		 AND pSchedules.Emp_ID = #session.EmployeeID#
  </cfif>
   AND pSchedules.pgnotesdraft != 2 
  AND (LEFT(pSchedules.Visit_Type,1) NOT IN (6) OR pSchedules.Visit_Type IS NULL)
  GROUp BY pSchedules.Schedule_ID
  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> Pending Visits
					       
					</div>
					<div class="tools">
						<a href="javascript:;" class="collapse"></a>
						<a href="javascript:;" class="fullscreen" data-original-title="Expand" title="Expand"></a>
					</div>
				</div>
				
				<div class="portlet-body">

					<form name="filter" method="post" action="index.cfm?page=dashboard&cat=chartcompliance&rpt=dash_no_notes.cfm">
						
						<table class="table table-striped table-bordered table-hover" id="pendingvisits">
				            	<thead>
				               		<tr>
				               			<th  align="center"  width="20%">Patient</th>
				               			<th  align="center" width="15%">Visit Date</th>
				               			<th  align="center"  width="10%">Elapsed</th>		               			
				               			<cfif session.eaType GT 1 OR session.IsAgencyLogin EQ 1>
				               				<th  align="center" width="25%">Employee</th>
                                            <th  align="center" width="25%">Skill</th>
				               			</cfif>
				               			<th  align="center" width="30%">Procedure</th>
				               		</tr>
				               	</thead>
				               	<tbody>
				               	  <cfset visittypes = "1,3,4,5,6,7,8,9,Eval">
				               	   <cfset visittypes = "4,5,6,7,8,9,FU Eval">

				               		<cfoutput query="GetList">

			               				<!--- <cfquery name="GetAss" datasource="#Application.DataSrc#">
			               						SELECT pAss.F25 FROM #Request.prefix_db_agency#.pAssessments pAss
															  WHERE pAss.Patient_ID =  #Patient_ID# 
															  AND pAss.F26 = '#assesments#'
															  AND pAss.Status = 0
															  ORDER BY F25 ASC
			               				</cfquery>
			               				<cfset assessments_completed = GetAss.F25 /> --->
				               			<cfif ((#listContains(visittypes ,Right(Visit_Type,7))# GT 0
				               					 OR  #listContains(visittypes ,LEFT(Visit_Type,1))# GT 0) 
				               			     AND assessments_completed NEQ 1)
				               						OR  
				               					((#listContains(visittypes ,Right(Visit_Type,7))# GT 0
				               					 OR  #listContains(visittypes ,LEFT(Visit_Type,1))# GT 0) AND pgnotesdraft LT 2 )  

				               					OR 

				               					((#listContains(visittypes ,Right(Visit_Type,7))# EQ 0 
				               					 OR  #listContains(visittypes ,LEFT(Visit_Type,1))# EQ 0)
				               						AND len(Visit_Type) GT 0 AND assessments_completed NEQ 1)

				               					OR (len(Visit_Type) EQ 0 AND   pgnotesdraft LT 2)
				               					<!---	OR (assessments_completed EQ 1 AND pgnotesdraft LT 2)

				               						 OR (assessments_completed NEQ 1 AND pgnotesdraft LT 2) ---> >

                                <cfset enc_patientid  = encrypt(#Patient_ID#,#application.enckey#,"AES","Hex") /> 
                                <cfset enc_assid  = encrypt(#Assmt_ID#,#application.enckey#,"AES","Hex") />
                                <cfset enc_sid  = encrypt(#Schedule_ID#,#application.enckey#,"AES","Hex") />  
					               				<tr <cfif len(Description) EQ 0 OR len(Visit_Type) EQ 0>style="height:30px;background-color: white;"<cfelse>style="height:30px;"</cfif> class="list-hdr" id="tr#Schedule_ID#" >
					               				<!--- <td><a href="../patientadmin_new/index.cfm?page=patient&cat=Patient&id=#enc_patientid#&restrict=1&formonly=1&assid=#enc_assid#&sid=#enc_sid#&from=missingnotes">#PatientLast# #PatientFirst#</a></td>
					               				<td><a href="../patientadmin_new/index.cfm?page=patient&cat=assessment_form&AID=#enc_assid#&patient_id=#enc_patientid#&rpt=&ATID=#enc_assid#">#F26#</a></td>--->
					               				<td><a href="../patientadmin_new/index.cfm?page=patient&cat=Patient&id=#enc_patientid#&restrict=1&formonly=1&assid=#enc_assid#&sid=#enc_sid#&from=missingnotes">#PatientLast#, #PatientFirst#</a>
					               				<span style="color:red">

					               					<cfif ((#listContains(visittypes ,Right(Visit_Type,7))# GT 0
				               					 OR  #listContains(visittypes ,LEFT(Visit_Type,1))# GT 0) AND pgnotesdraft LT 2 )  >
					               						&nbsp(Progress notes not completed)
						               				<cfelseif   assessments_completed NEQ 1 AND len(Visit_Type) GT 0>
						               					&nbsp(OASIS/Evaluations not completed)
						               				</cfif>
					               				</span>
					               				</td>
					               				<td><a href="../patientadmin_new/index.cfm?page=patient&ID=#enc_patientid#&cat=patientedit_visit&restrict=1&formonly=1&AID=#enc_assid#&SID=#enc_sid#&frm=bill" >#DateFormat(Visit_Date,"mm/dd/yyy")#</a></td>
					               				<cfset elapsed_days = dateDiff("d", Visit_Date,now()) /> 
					               				<td>#elapsed_days#</td>
					            					<cfif session.eaType GT 1 OR session.IsAgencyLogin EQ 1>
	                             		 <td>#Emp_Last#, #Emp_First#</td>
	                                    <td>#Skill#</td>                
	                             	</cfif>
	                             	<td><!--- <a href="../patientadmin_new/index.cfm?page=patient&ID=#enc_patientid#&cat=authorizations&restrict=1&formonly=1&assid=#enc_assid#">---><cfif len(Visit_Type) EQ 0 >#Description#<cfelse>#Visit_Type#</cfif><!---</a>---></td>
	                             </tr>
	                            </cfif>
				               		</cfoutput>
				               	</tbody>
				               </table>

				               <!---</div>--->
				     </div>
	</div>
				
				
			

