<%@ 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>Breast Symptoms Target</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>Breast Symptoms Target - <%=sdf.format(new java.util.Date()) %></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 }"/>
				
<table class="bigTable" cellspacing="0">
	<tr>
		<th>Tumour Site</th>
		<th>Hosp. No</th>
		<th>Name</th>
		<th>Referral Received <br>Date</th>
		<th>Date first seen</th>
		<th>Primary Diagnosis</th>
		<th>Treatment Type</th>
		<th>Treating Trust</th>
		<th>Cancer Treatment <br>Period <br>Start Date</th>
		<th>Treatment <br>Start Date<br>(Cancer)</th>
		<th>31 Day <br>Target <br>Days To <br>Breach</th>
		<th>31 Day <br>Target Breach Date</th>
		<th>62 Day <br>Target <br>Days To <br>Breach</th>
		<th>62 Day <br>Target Breach Date</th>
		<th>Next Step</th>
		<th class="noPrint">Edit</th>
	</tr>
	<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 == 'Breast Symptoms'}">
				 		
	 			<%-- Set referral received RRD date --%>
	 			<c:set var="rrd" value="${result[2].values['ReferralReceivedDate'].value}"/>
				<%-- Set cancer treatment CTD date --%>
				<c:set var="ctd" value="${result[2].values['CancerTreatmentPeriodStartDate'].value}"/>
	
				<%-- Set adjustment days first seen --%>
				<c:set var="adj1" value="${result[2].values['Adjustmentfirstseen'].value}"/>
				<c:if test="${adj1 == ''}"><c:set var="adj1" value="0"/></c:if>
				<%-- Set adjustment days treatment --%>
				<c:set var="adj2" value="${result[2].values['WaitingTimeAdjustmentTreatment'].value}"/>
				<c:if test="${adj2 == ''}"><c:set var="adj2" value="0"/></c:if>
	
				<%-- number of days in waiting period eg 62 Day Target = 62 --%>
				<c:set var="breachDays" value="${62 + adj1 + adj2}"/>
				<%-- number of days in waiting period eg 31 Day Target = 31 --%>
				<c:set var="breach31Days" value="${31 + adj2}"/>
	
				<%-- 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 s-62 day and t-31 day --%>						
				<emdt:breachStatus 	testDate="${today}" startDate="${rrd}" breach="${breachDays}" var="s" warn="14" />
	
				<emdt:breachStatus 	testDate="${today}" startDate="${ctd}" breach="${breach31Days}" var="t" warn="14" />				
					
				<tr class="<c:out value="${s.code }"/>">
				<td>
					<webapp:listValue listName="WaitTumour Site" key="${result[2].values['TumourSite'].value}" domain="EMDT" cacheable="true" />
				</td>
				<td> <c:out value="${result[0].hospitalNumber}"/> </td>
				<td> <c:out value="${result[0].forename}"/> <c:out value="${result[0].surname}"/></td>
				<td> <c:out value="${result[2].values['ReferralReceivedDate'].value}"/>  </td>
				<td> <c:out value="${result[2].values['Date1stseen'].value}"/>  </td>
				<td>
					<webapp:listValue listName="WaitICD" key="${result[2].values['PrimaryDiagnosisICD'].value}" domain="EMDT" cacheable="true" />
				</td>				
				<td> <webapp:listValue listName="WaitTreatment Modality" key="${result[2].values['CancerTreatmentModality'].value}" domain="EMDT" cacheable="true" /></td>
				<td> <c:out value="${result[2].values['TreatingTrust'].value}"/>  </td>													
				<td> <c:out value="${result[2].values['CancerTreatmentPeriodStartDate'].value}"/>  </td>
				<td> <c:out value="${result[2].values['TreatmentStartDateCancer'].value}"/>  </td>
				
				<%-- Breach days - 31 --%>	
				<td class="<c:out value="${t.code }"/>">
					<c:if test="${ctd != null}">
						<c:if test="${t.breachDays - t.daysSinceStart > 0 }">
							<c:out value="${t.breachDays - t.daysSinceStart }"/>
						</c:if>
						<c:if test="${t.breachDays - t.daysSinceStart <= 0 }">
							Breach
						</c:if>
					</c:if>
					<c:if test="${ctd == null}">
						No CTD
					</c:if>
					
				</td>
				<td class="<c:out value="${t.code }"/>">
					<c:if test="${ctd != null}">
						<fmt:formatDate value="${t.breachDate }" pattern="dd/MM/yyyy"/>										
					</c:if>
				</td>
	
				<%-- Breach days - 62 --%>	
				<td class="<c:out value="${s.code }"/>">
					<c:if test="${rrd != null}">
						<c:if test="${s.breachDays - s.daysSinceStart > 0 }">
							<c:out value="${s.breachDays - s.daysSinceStart }"/>
						</c:if>
						<c:if test="${s.breachDays - s.daysSinceStart <= 0 }">
							Breach
						</c:if>
					</c:if>
					<c:if test="${rrd == null}">
						No RR
					</c:if>
				
				</td>
				<td class="<c:out value="${s.code }"/>">
					<c:if test="${rrd != null}">
						<fmt:formatDate value="${s.breachDate }" pattern="dd/MM/yyyy"/>										
					</c:if>								
				</td>
				<td> <c:out value="${result[2].values['NEXTSTEP'].value}"/>  </td>
				
				<td class="noPrint"> <a href="../consultationNote.form?conNoteId=<c:out value="${result[2].guid }"/>" class="noPrint"><img src="../../images/16x16/edit.png" alt="View Patient Form" border="0" class="noPrint"/></a></td>
				</tr>
			</c:if>	
		</c:if>
	</c:forEach>
</c:if>
</table>
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>