<%@ 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 TREATED IN THE LAST WEEK</title>
	<title>31 DAY PTL - TREATMENT MODALITY - ANTI CANCER</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 TREATED IN THE LAST WEEK - <%=sdf.format(new java.util.Date()) %></u></h2>
<h2><u>31 DAY PTL - TREATMENT MODALITY - ANTI CANCER</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="numTreated" value="0"/>
<c:set var="numNotTreated" 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:set var="ctm" value="${result[2].values['CancerTreatmentModality'].value}"/>

	<c:if test="${ctm == '2'||ctm == '3'||ctm == '14'||ctm == '15'}">						 		
			 <%-- Set decision to treat CTD and TSD  date --%>
						<c:set var="ctd" value="${result[2].values['CancerTreatmentPeriodStartDate'].value}"/>

<c:set var="tsd" value="${result[2].values['TreatmentStartDateCancer'].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 Days = 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 using TSD --%>																	
	<emdt:breachStatus testDate="${tsd}" startDate="${ctd}" breach="${breachDays}" var="s" warn="5" />				

<%-- calculate if the TSD is within the last 7 days --%>													
	<emdt:breachStatus testDate="${today}" startDate="${tsd}" breach="${breachDays}" var="t" warn="5" />				
								
<%-- 31 Day PTL breach calculations --%>

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

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

<%-- TSD this week --%>
<c:if test="${t.daysSinceStart >= 0}">
<c:if test="${t.daysSinceStart <= 7}">


<%-- Treated within 31 days calculations --%>
		<c:if test="${s.daysSinceStart <= 31 }">

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

<%-- Not treated within 31 days calculations --%>
		<c:if test="${s.daysSinceStart > 31 }">

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

	</c:if> <%-- End of TSD this week --%>

	</c:if> <%-- End of TSD this week --%>
	
	</c:if> <%-- End of 31 Day PTL breach calculations with TSD --%>

	</c:if> <%-- End of 31 Day PTL breach calculations with RRD --%>

		</c:if> <%-- Treatment Modality Anti Cancer  --%>

			</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>Number of patients treated within 31 days</th>
		<th>Number of patients not treated within 31 days</th>
		</tr>
<td>Patients treated in the last 7 days</td>
<td>  <c:out value="${numTreated}"/></td>
<td>  <c:out value="${numNotTreated}"/></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>