<%@ include file="/includes.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<%@page import="java.util.Date,java.text.SimpleDateFormat" %>
<html>
<head>
	<title>PATIENTS WITHOUT A DECISION TO TREAT</title>
	<title>31 DAY PTL - PATIENTS WITHOUT A DECISION TO TREAT</title>
	<title>TREATMENT MODALITY - SURGERY</title>

	<link rel="icon" href="../../images/emdt.ico" type="image/x-icon" />
	<link rel="shortcut icon" href="../../images/emdt.ico" type="image/x-icon" />
	<link rel="stylesheet" href="../../css/webapp.css" type="text/css" />
	<link rel="stylesheet" href="PTL.css" type="text/css" media="screen, print"/>
	<style media="print">

	.noPrint{
		visibility: hidden;
		display: none;
	}
	</style>
</head>
<body>

<%
SimpleDateFormat sdf = new SimpleDateFormat("EEEE dd MMM yyyy"),
				timeSdf = new SimpleDateFormat("HH:mm:ss"),
				todaySdf = new SimpleDateFormat("dd/MM/yyyy");
%>
<h2><u>PATIENTS WITHOUT A DECISION TO TREAT - <%=sdf.format(new java.util.Date()) %></u></h2>
<h2><u>31 DAY PTL - PATIENTS WITHOUT A DECISION TO TREAT</u></h2>
<h2><u>TREATMENT MODALITY - SURGERY</u></h2>

<hibernate:executeQuery hql="select distinct new list (p, cs, cn, cs.primarySite) from CareSpell cs, Patient p, ConsultationNote cn join cn.values as fv join fv.values as v where cn.careSpellId = cs.id and p = cs.patient and cn.formName like '%CWT' and cn.deleted=false order by cs.primarySite" var="results" varError="hqlError" />

<c:out value="${hqlError }"/>


<c:set var="numBreach8To14" value="0"/>
<c:set var="numBreachIn7" value="0"/>
<c:set var="numBreachLast7" value="0"/>
<c:set var="numBreachDatePass" value="0"/>

	<c:if test="${results != null}">
		<c:forEach var="result" items="${results}">

	<%-- Selection criteria for current record and report type --%>
			<c:if test="${empty result[2].values['TrackingEpisodeComplete'].value}">
								
					<c:if test="${result[2].values['Targetapplicableto'].value == '31 Day'}">

					<c:if test="${result[2].values['CancerTreatmentModality'].value == '1'}">

						 		
<%-- Set decision to treat CTD date --%>

<c:set var="ctd" value="${result[2].values['CancerTreatmentPeriodStartDate'].value}"/>

<%-- Set adjustment days first seen --%>
			<c:set var="adj1" value="0" />
	<c:if test="${! empty result[2].values['Adjustmentfirstseen'].value}">
	<c:set var="adj1" value="${result[2].values['Adjustmentfirstseen'].value}" />
					</c:if>


<%-- number of days in waiting period eg 31 Day = 31 --%>
		<c:set var="breachDays" value="${31 + adj1}"/>
						
<%-- the date we are testing the breach against i.e. today --%>
						<c:set var="today" value="<%=todaySdf.format(new java.util.Date()) %>"/>
						
<%-- calculate the breach status. 'warn' is how long before breach to display warning --%>																	
	<emdt:breachStatus testDate="${today}" startDate="${rrd}" breach="${breachDays}" var="s" warn="5" />
								
								
<%-- 31 Day PTL breach calculations --%>

<c:if test="${ctd == null}">


<%-- 8 - 14 day breach calculations --%>
		<c:if test="${s.breachDays - s.daysSinceStart >= 8 }">
		<c:if test="${s.breachDays - s.daysSinceStart <= 14 }">

	<c:set var="numBreach8To14" value="${numBreach8To14+ 1}"/>
									</c:if>
									</c:if>

<%-- Next 7 day breach calculations --%>
		<c:if test="${s.breachDays - s.daysSinceStart >= 1 }">
		<c:if test="${s.breachDays - s.daysSinceStart <= 7 }">

	<c:set var="numBreachIn7" value="${numBreachIn7+ 1}"/>
									</c:if>
									</c:if>
<%-- Last 7 day breach calculations --%>
		<c:if test="${s.breachDays - s.daysSinceStart <= 0 }">
		<c:if test="${s.breachDays - s.daysSinceStart >= -7 }">

	<c:set var="numBreachLast7" value="${numBreachLast7+ 1}"/>
									</c:if>
									</c:if>
<%-- Total breach calculations --%>
		<c:if test="${s.breachDays - s.daysSinceStart <= 0 }">

	<c:set var="numBreachDatePass" value="${numBreachDatePass+ 1}"/>
									</c:if>
	
</c:if> <%-- End of 31 Day PTL breach calculations for without CTD --%>

		</c:if> <%-- Treatment Modality Surgery --%>

					</c:if> <%-- 31 Day --%>
						
			</c:if>	<%-- TrackingEpisodeComplete--%>
		
		</c:forEach> 	<%-- results --%>
	
	</c:if>	<%-- not null results --%>



<table border="1">

	<tr style="background-color:#ccc">
		<th> </th>
		<th>Patients who will breach in 8 - 14 days</th>
		<th>Patients who will breach in next 7 days</th>
		<th>Number of patients who passed their breach in the last 7 days</th>
		<th>Total number of patients whose breach date has already passed  </th>
		</tr>
<td>Number of patients who do not have a treatment date within target time</td>
<td>  <c:out value="${numBreach8To14}"/></td>
<td>  <c:out value="${numBreachIn7}"/></td>
<td>  <c:out value="${numBreachLast7}"/></td>
<td>  <c:out value="${numBreachDatePass}"/></td>
</table>
<br/>
Time: <%=timeSdf.format(new java.util.Date()) %>
<br/>
<br/>

<a href="../reportMenu.jsp" class="noPrint"><img src="../../images/16x16/action_back.png" border="0"/>Back</a>
</body>
</html>