<%@ include file="/includes.jsp"%>
<jsp:useBean id="patientSearchPD" class="com.ardeo.util.PaginationData" scope="session"/>
<input type="hidden" id="action"/>
<table width="100%" cellspacing="0" class="table" id="searchTableId">
	<tr class="tableHeader">
		<c:if test="${webapp.roleManagement}">
			<th class="tableColHeader"></th>
		</c:if>
		<th class="tableColHeader">Surname</th>
		<th class="tableColHeader">Forename</th>
		<th class="tableColHeader">NHS&nbsp;Number</th>
		<th class="tableColHeader">Date&nbsp;of&nbsp;Birth</th>
		<th class="tableColHeader" >Speciality</th>
		<th class="tableColHeader">Primary Clinician</th>
		<th class="tableColHeader">Referral Date</th>
		<th class="tableColHeader">Referring Clinician</th>
		<th class="tableColHeader">Referring Hospital</th>
		<th class="tableColHeader" colspan="2">Tracking</th>
		<th class="tableColHeader">Image Availability</th>
	</tr>
	<c:choose>
		<c:when test="${(patientSearchDto.referralsPatient ne null) and (fn:length(patientSearchDto.referralsPatient) gt 0)}">
			<c:forEach var="patient" items="${patientSearchDto.referralsPatient}" varStatus="s1" begin="${patientSearchPD.startOfPageIndex}" end="${patientSearchPD.endOfPageIndex}">
				<c:set var="rowClass" value="${s1.count % 2 == 0 ? 'evenRow' : 'oddRow'}" />
				<tr class="<c:out value="${rowClass}"/>"  onmouseover="this.style.cursor = cursorPointer; ">
					<c:if test="${webapp.roleManagement}"><td></td></c:if>
					<td class="tableCell"><b><c:out value="${patient.patient_surname}"/></b>&nbsp;</td>
					<td class="tableCell"><strong><c:out value="${patient.patient_forename}"/></strong>&nbsp;</td>
					<td class="tableCell"><b><c:out value="${patient.patient_nhsNumber}"/></b>&nbsp;</td>
					<td class="tableCell"><b><fmt:formatDate value="${patient.patient_dateOfBirth }" pattern="dd MMM yyyy" /></b>&nbsp;</td>
					<td class="tableCell" colspan="8"></td>
				</tr>
				<c:forEach var="cs" items="${patient.careSpellsResultsDtoList}" varStatus="cs1">
					<tr class="<c:out value="${rowClass}"/>" id="rowId<c:out value="${s1.count}"/>.<c:out value="${cs1.count}"/>" onmouseover="this.style.cursor = cursorPointer; ">
						<c:if test="${webapp.roleManagement}">
							<td style="border-top: #B4B4B4 1px solid"><input type="image" src="../images/add.png" title="more details" value="Add" onclick="showPatientDtlsInSrchRecord('<c:out value="${patient.patient_guid}"/>','rowId<c:out value="${s1.count}"/>.<c:out value="${cs1.count}"/>','<c:out value="${parentScreen}"/>',0,'<c:out value="${cs.patient_careSpell_id}"/>');return false;" /></td>
						</c:if>
						<td colspan="12">
							<table style="width: 100%">
								<tr>
									<td class="tableCell"  colspan="5" ><webapp:listValue domain="EMDT" listName="Speciality" key="${cs.patient_careSpell_primarySite}" /></td>
									<td class="tableCell"  colspan="3"><c:out value="${webapp.userNameNameMap[cs.patient_careSpell_primaryClinician_username]}"/></td>
									<td class="tableCell" colspan="2"><c:out value="${cs.tracking}"/></td>
									<td class="tableCell"  colspan="2"><c:out value="${cs.countImgArrived}"/> out of <c:out value="${cs.countImgRequested}"/> images arrived</td>
								</tr>
								 <c:forEach var="formSummaryMapOrder" items="${cs.patient_careSpell_referralDetails_referralsDefinition.formSummaryMapOrder}">
									<c:if test="${formSummaryMapOrder.location eq 1}">
										<c:choose>
											<c:when test="${formSummaryMapOrder.type eq 'Form'}">
												<c:set var="hreference" value="../referrals/consultationNote.form?csId=${cs.patient_careSpell_id}&filterFormId=${formSummaryMapOrder.filterFormId}"/>
											</c:when>
											<c:otherwise>
												<c:set var="hreference" value="patientSummaryActions.form?csId=${cs.patient_careSpell_id}&method=view&summaryId=${formSummaryMapOrder.summaryGuid}&page=referrals"/>
											</c:otherwise>
									</c:choose>
									</c:if>
							    </c:forEach>
							 	<c:set var="countReferral" value="0" />
								<c:if test="${0 ne cs.patient_careSpell_referralDetails_referralStatus}">
									<c:set var="countReferral" value="${countReferral+1}" />
									<tr>
										<td class="tableCell" colspan="3" onclick="document.location.href ='<c:out value="${hreference}"/>&patientId=<c:out value="${patient.patient_guid}"/>&referralId=<c:out value="${cs.patient_careSpell_referralDetails_referralId }"/>'" >&nbsp;<c:out value="${countReferral}"/>.<webapp:listValue domain="EMDT" listName="ReferralMethods" key="${cs.patient_careSpell_referralDetails_referralMethod}" /></td>
										<td class="tableCell" colspan="2" onclick="document.location.href ='<c:out value="${hreference}"/>&patientId=<c:out value="${patient.patient_guid}"/>&referralId=<c:out value="${cs.patient_careSpell_referralDetails_referralId }"/>'"><c:out value="${cs.patient_careSpell_referralDetails_referralsDefinition.title}"/>&nbsp;</td>
										<td class="tableCell" colspan="1" onclick="document.location.href ='<c:out value="${hreference}"/>&patientId=<c:out value="${patient.patient_guid}"/>&referralId=<c:out value="${cs.patient_careSpell_referralDetails_referralId }"/>'"><fmt:formatDate	value="${cs.patient_careSpell_referralDetails_referralDate}" pattern="dd MMM yyyy" />&nbsp;</td>
										<td class="tableCell" colspan="2" onclick="document.location.href ='<c:out value="${hreference}"/>&patientId=<c:out value="${patient.patient_guid}"/>&referralId=<c:out value="${cs.patient_careSpell_referralDetails_referralId }"/>'"><c:out value="${webapp.userNameNameMap[cs.patient_careSpell_referralDetails_referringSpecialistUser_username]}"/></td>
										<td class="tableCell" colspan="2" onclick="document.location.href ='<c:out value="${hreference}"/>&patientId=<c:out value="${patient.patient_guid}"/>&referralId=<c:out value="${cs.patient_careSpell_referralDetails_referralId }"/>'"><c:out value="${webapp.hospMap[cs.patient_careSpell_referralDetails_referringFromHospitalId]}"/></td>
										<td  class="tableCell" colspan="1"></td>
									</tr>
								</c:if>
							</table>
						</td>
					</tr>
				</c:forEach>
			</c:forEach>
		</c:when>
		<c:otherwise>
			<tr>
				<c:choose>
					<c:when test="${webapp.roleManagement}">
						<td align="center" class="message" colspan="12">No Patient Found</td>
					</c:when>
					<c:otherwise>
						<td align="center" class="message" colspan="11">No Patient Found</td>
					</c:otherwise>
				</c:choose>
				
			</tr>
		</c:otherwise>
	</c:choose>
	<tr class="tableFooter">
		<c:choose>
			<c:when test="${webapp.roleManagement}">
				<td colspan="13" align="left">&nbsp;</td>
			</c:when>
			<c:otherwise>
			<td colspan="12" align="left">&nbsp;</td>
			</c:otherwise>
		</c:choose>
		
	</tr>
</table>