<cfinclude template='/__Security-Block.cfm' />

<cfset NAVROOT="..">
<cfparam name="url.id" default=0>
<cfparam name="url.date" default=''>
<cfparam name="url.type" default='visit'>
<cfparam name="url.formtype" default='unassign'>
<!--- Get Patient info for display at top of form --->


<!--- #10486: include HCPCS & Description from revenue code --->
<cfquery  datasource="#Application.DataSrc#" name="Getschedules">
	SELECT
		pSchedules.Schedule_ID,
		pSchedules.Visit_Date,
		pSchedules.Patient_ID,
		pSchedules.Assmt_ID,
		pPatients.Pt_Last,
		pPatients.Pt_First,
		IFNULL(pRevenue_Code.HCPCS, '') AS HCPCS,
		IFNULL(pRevenue_Code.Description, '') AS Rev_Description
	FROM  #Request.prefix_db_agency#.pSchedules
	LEFT OUTER JOIN  #Request.prefix_db_lookup#.pEmployee on pSchedules.Emp_ID = pEmployee.Emp_ID
	LEFT OUTER JOIN  #Request.prefix_db_agency#.pPatients on pSchedules.Patient_ID = pPatients.Patient_ID
	LEFT OUTER JOIN #Request.prefix_db_agency#.pAssessments on pSchedules.Assmt_ID = pAssessments.Assmt_ID
	LEFT OUTER JOIN #Request.prefix_db_agency#.pRevenue_Code
		ON pRevenue_Code.Rev_CodeID = pSchedules.HCPCS_ID
		AND pRevenue_Code.Status = 0
	WHERE 
	<cfif url.formtype EQ "deletevisit">
		pSchedules.Patient_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#url.id#"> 
	<cfelse>
		pSchedules.Emp_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#url.id#"> 
	</cfif>
	AND  pSchedules.Status = <cfqueryparam cfsqltype="cf_sql_integer" value="0" >
	AND  pPatients.Status < <cfqueryparam cfsqltype="cf_sql_integer" value="2" >
	AND  pAssessments.Status = <cfqueryparam cfsqltype="cf_sql_integer" value="0" >
	AND pSchedules.Visit_Date > CURDATE()
	GROUP BY pSchedules.Schedule_ID
	ORDER BY pSchedules.Visit_Date ASC

</cfquery>


<cfif Getschedules.recordcount>
	<!-- BEGIN SAMPLE TABLE PORTLET-->
			<style>
				.schedule-action-col {
					width: 180px;
					text-align: center;
					vertical-align: middle !important;
				}

				.schedule-action-cell {
					text-align: center;
					vertical-align: middle !important;
				}

				.select-all-wrap {
					display: inline-flex;
					align-items: center;
					gap: 6px;
					margin-top: 6px;
					font-weight: normal;
				}

				.select-all-wrap input,
				.schedule-action-cell input[type="checkbox"] {
					margin: 0;
				}
			</style>

			<table class="table table-bordered table-striped table-condensed flip-content">
				<thead class="flip-content">
					<tr>
						<th>
							Patient Name
						</th>
						<th>
							Visit Date
						</th>
						<th>
							HCPCS
						</th>
						<th>
							Description
						</th>
						<th class="schedule-action-col">
							Action<br>
							<cfif url.formtype EQ "deletevisit">
								<label for="selectAllVisits" class="select-all-wrap">
									<input type="checkbox" id="selectAllVisits">
									<span>Select All</span>
								</label>
							</cfif>
						</th>
					</tr>
				</thead>
				<tbody>
					<cfoutput query="Getschedules">
						<tr>
							<td>#HTMLEditFormat(Pt_Last)#, #HTMLEditFormat(Pt_First)#</td>
							<td>#DateFormat(Visit_Date,'mmm dd, yyyy')#</td>
							<td>#HTMLEditFormat(HCPCS)#</td>
							<td>#HTMLEditFormat(Rev_Description)#</td>
							<td class="schedule-action-cell"><input type="checkbox" name="Schedule_ID" class="schedule-checkbox" value="#Schedule_ID#"></td>
						</tr>
					</cfoutput>
				</tbody>
			</table>
			<div class="form-actions">
				<a class="btn blue" onclick="unassignvisits();">
					<cfif url.formtype EQ 'deletevisit'> Delete Visit<cfelse>Un-assign Now</cfif>
						
					</a>
			</div>
		
	<!-- END SAMPLE TABLE PORTLET--> 
<cfelseif url.id neq 0>
	<div align="center">
		No Visits Exist for this Employee
	</div>
</cfif>
