<!-- start emdt/patientSearchResults.jsp -->
<%@ include file="/includes.jsp" %>
<jsp:useBean id="patientSearchPD" class="com.ardeo.util.PaginationData" scope="session"/>
<c:if test="${param.pageSize != null}">
	<jsp:setProperty name="patientSearchPD" property="pageSize" value="${param.pageSize}"/>
</c:if>
<jsp:setProperty name="patientSearchPD" property="size" value="${patientSearchResultsByCarespellMap.size()}"/>
<c:choose>
	<c:when test="${param.page != null}">
		<jsp:setProperty name="patientSearchPD" property="currentPage" value="${param.page}"/>
	</c:when>
	<c:otherwise>
		<jsp:setProperty name="patientSearchPD" property="currentPage" value="1"/>
	</c:otherwise>
</c:choose>
<webapp:namedList name="PrimaryClinician" domain="EMDT" id="primaryclinicianNL"/>
<webapp:namedList name="speciality" domain="EMDT" id="primarysiteNL"/>
<webapp:namedList name="KeyWorker" domain="EMDT" id="keyworkerNL"/>
<webapp:listToMap var="primaryclinicianMap" list="${primaryclinicianNL}"/>
<webapp:listToMap var="primarysiteMap" list="${primarysiteNL}"/>
<webapp:listToMap var="keyworkerMap" list="${keyworkerNL}"/>
<script>
	function openPatient(id) {
		if(id) {
			document.location = "viewPatient.form?patientId=" + id;
		} else {
			window.alert("No patient id");
		}
	}
	
	function openPatientWithCarespell(id, carespellId) {
		if(id) {
			document.location = "viewPatient.form?patientId=" + id + "&csId=" + carespellId;
		} else {
			window.alert("No patient id");
		}
	}
	
	function changePageSize(el) {
		document.location = 'patientSearch.form?pageSize=' + el.options[el.selectedIndex].value;
	}
	function fetchNextOrPreviousBatch(resultPart){
		document.getElementById('resultPart').value=resultPart;
		document.getElementById("patientSearchForm").submit();
		
	}
</script>

<c:set var="resultPart" value="${patientSearchForm.resultPart}"/>
<c:set var="resultInToParts" value="${patientSearchForm.resultInToParts}"/>
<c:if test="${resultInToParts>1 and not empty patientsMaxMessage}">
	<span class="info"><c:out value="${patientsMaxMessage}"/>&nbsp;
	<%--
		<c:if test="${resultPart ne 1}">
			<img src="../images/backwardbutton.png"
				title="click to fetch previous set of patients" onclick="fetchNextOrPreviousBatch('<c:out value="${resultPart-1}')" />&nbsp;
					</c:if>
		<c:if test="${resultPart ne resultInToParts}">
			<img src="../images/forwardbutton.png"
				title="click to fetch next set of patients" onclick="fetchNextOrPreviousBatch('<c:out value="${resultPart+1}')"/>
		</c:if>
	 --%>
	</span>
</c:if>

<div class="message"><c:out value="${patientSearchForm.message}"/></div>
<table cellspacing="0" width="700px">
	<tr>
		<td class="tableTitleBar">Search Results&nbsp;(<c:out value="${patientSearchResultsByCarespellMap.size()}"/> matches)</td>
		<td align="right">
			<table>
				<tr>
					<td align="right">Page <c:out value="${patientSearchPD.currentPage }"/> of <c:out value="${patientSearchPD.numberOfPages }"/></td>
					<td width="1">
						<c:choose>
							<c:when test="${patientSearchPD.previousPageNum != null}">
								<a title="Previous Page" href="patientSearch.form?page=<c:out value="${patientSearchPD.previousPageNum}"/>"><img src="../images/16x16/action_back.png"/></a>
							</c:when>
							<c:otherwise>
								<img src="../images/16x16/action_back_disabled.png"/>
							</c:otherwise>
						</c:choose>
					</td>
					<td width="1" align="right">
						<c:choose>
							<c:when test="${patientSearchPD.nextPageNum != null}">
								<a title="Next Page" href="patientSearch.form?page=<c:out value="${patientSearchPD.nextPageNum}"/>"><img src="../images/16x16/action_forward.png"/></a>
							</c:when>
							<c:otherwise>
								<img src="../images/16x16/action_forward_disabled.png"/>
							</c:otherwise>
						</c:choose>
					</td>
				</tr>
			</table>
		
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<table width="100%" cellspacing="0" class="table">
				<tr class="tableHeader">
					<th class="tableColHeader"><a href="patientSearch.form?action=sort&searchFieldId=0">Surname</a></th>
					<th class="tableColHeader"><a href="patientSearch.form?action=sort&searchFieldId=1">Forename</a></th>
					<th class="tableColHeader"><a href="patientSearch.form?action=sort&searchFieldId=2">NHS&nbsp;Number</a></th>
					<th class="tableColHeader"><a href="patientSearch.form?action=sort&searchFieldId=3">Hospital Number</a></th>
					<th class="tableColHeader"><a href="patientSearch.form?action=sort&searchFieldId=4">Date&nbsp;of&nbsp;Birth</a></th>
					<th class="tableColHeader">Clinician</th>
					<th class="tableColHeader">Status</th>
				</tr>
				<c:forEach var="patientByCarespellMap" items="${patientSearchResultsByCarespellMap}" varStatus="s1" begin="${patientSearchPD.startOfPageIndex}" end="${patientSearchPD.endOfPageIndex}">
					<c:set var="patient" value="${patientByCarespellMap.value[0]}"/>
					<c:set var="rowClass" value="${s1.count % 2 == 0 ? 'evenRow' : 'oddRow'}"/>
					<tr class="clickable <c:out value="${rowClass}"/> <c:out value="${patient.patient_deathIndicator ? 'patientDeceasedMessage' : '' }"/>" onclick="openPatient('<c:out value="${patient.patient_guid}"/>')" >
						<td class="tableCell">
							<c:out value="${patient.patient_surname}"/>&nbsp;
						</td>
						<td class="tableCell"><c:out value="${patient.patient_forename}"/>&nbsp;</td>
						<td class="tableCell"><c:out value="${patient.patient_nhsNumber}"/>&nbsp;</td>
						<td class="tableCell"><c:out value="${patient.patient_hospitalNumber}"/>&nbsp;</td>
						<td class="tableCell" align="center"><fmt:formatDate value="${patient.patient_dateOfBirth}" pattern="dd MMM yyyy"/>&nbsp;</td>
						<td class="tableCell"><c:if test="${patient.patient_deathIndicator}"><span class="patientDeceasedMessage">(Deceased)</span></c:if></td>
						<c:if test="${webapp.userIdNameMap[patient.patient_admittingPhysician] ne ''}">
							<td class="tableCell"><c:out value="${webapp.userIdNameMap[patient.patient_admittingPhysician]}"/>&nbsp;</td>
						</c:if>
					</tr>
					<c:forEach var="cspatient" items="${patientByCarespellMap.value}">
					<tr class="clickable <c:out value="${s1.count % 2 == 0 ? 'evenRow' : 'oddRow'}"/> <c:out value="${patient.patient_deathIndicator ? 'patientDeceasedMessage' : ''}"/>" onclick="openPatientWithCarespell('<c:out value="${patient.patient_guid}"/>', '<c:out value="${cspatient.patient_careSpells_id }"/>')" >
						<td class="tableCell" >&nbsp;</td>
						<td class="tableCell" colspan="4"><c:out value="${primarysiteMap[cspatient.patient_careSpells_primarySite] }"/></td>
						<c:choose>
							<c:when test="${webapp.userNameNameMap[cspatient.patient_careSpells_primaryClinician_username] ne ''}">
							<td class="tableCell"><c:out value="${webapp.userNameNameMap[cspatient.patient_careSpells_primaryClinician_username]}"/></td>
							</c:when>
							<c:otherwise>
							<td class="tableCell"><c:out value="${cspatient.patient_careSpells_primaryClinician_username}"/></td>
							</c:otherwise>
						</c:choose>
						<td class="tableCell"><c:out value="${cspatient.patient_careSpells_status }"/></td>
					</tr>
				</c:forEach>
				</c:forEach>
				
				<tr class="tableFooter">
					<td colspan="7" align="left"  >&nbsp;</td>
				</tr>
			</table>
			<c:if test="${count > 0 }">
				<br/><b><c:out value="${count }"/> patient(s) have been filtered out.</b>
			</c:if>
		</td>
	</tr>
</table>
<table width="700">
	<tr>
		<!-- 
		<td>
			<a href="exportPatientRecords.form"><img src="../images/16x16/database_save.png" title="Export patients" border="0" /> <b>Export patients</b></a>
		</td>
		 -->
		<td align="left">
		Show 
			<select  name="selectPageSize" onchange="changePageSize(this)">
				<webapp:option value="10" currentValue="${patientSearchPD.pageSize }">10</webapp:option>
				<webapp:option value="20" currentValue="${patientSearchPD.pageSize }">20</webapp:option>
				<webapp:option value="30" currentValue="${patientSearchPD.pageSize }">30</webapp:option>
				<webapp:option value="40" currentValue="${patientSearchPD.pageSize }">40</webapp:option>
				<webapp:option value="50" currentValue="${patientSearchPD.pageSize }">50</webapp:option>
				<webapp:option value="${patientSearchPD.size }" currentValue="${patientSearchPD.pageSize }">All</webapp:option>
			</select>
			items per page
		</td>
		<td align="right" width="100">Page <c:out value="${patientSearchPD.currentPage }"/> of <c:out value="${patientSearchPD.numberOfPages }"/></td>
		<td width="1">
			<c:choose>
				<c:when test="${patientSearchPD.previousPageNum != null}">
					<a title="Previous Page" href="patientSearch.form?page=<c:out value="${patientSearchPD.previousPageNum}"/>"><img src="../images/16x16/action_back.png"/></a>
				</c:when>
				<c:otherwise>
					<img src="../images/16x16/action_back_disabled.png"/>
				</c:otherwise>
			</c:choose>
		</td>
		<td width="1" align="right">
			<c:choose>
				<c:when test="${patientSearchPD.nextPageNum != null}">
					<a title="Next Page" href="patientSearch.form?page=<c:out value="${patientSearchPD.nextPageNum}"/>"><img src="../images/16x16/action_forward.png"/></a>
				</c:when>
				<c:otherwise>
					<img src="../images/16x16/action_forward_disabled.png"/>
				</c:otherwise>
			</c:choose>
		</td>
	</tr>
</table>

			
<br/>
<br/>

<!-- end emdt/patientSearchResults.jsp -->