<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<script language="javascript">
function prepareRequestParams(operation,otherUser,selectedUser)
{
/*alert('inside prepareRequestParams'+"OP::"+operation+"*otherUser::"+otherUser+"*selectedUser::"+selectedUser);*/
	if(!isNullValue(operation)){
	    document.getElementById("op").value = operation;
	}

	if(!isNullValue(selectedUser)){
	    document.getElementById("selectedUser").value = selectedUser;
	}
	
	if(!isNullValue(otherUser)){
	    document.getElementById("otherUser").value = otherUser;
	}
}

function setFormAction(actionTo){
/*alert('inside setFormAction::'+actionTo);*/
    if(!isNullValue(actionTo)){
        document.getElementById("nrlsummary").action = actionTo;
    }
    document.getElementById("nrlsummary").submit();
}

function isNullValue(item){
	if( item == null){
	    return true;
	}else{
	    return false;
	}
}

</script>
<smvc:form method="post" action="nrlsummary.form" name="nrlsummary" id="nrlsummary">
<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
<input type="hidden" name="op" id="op" value=""/>
<input type="hidden" name="otherUser" id="otherUser" value=""/>
<input type="hidden" name="selectedUser" id="selectedUser" value=""/>
<input type="hidden" name="appendUrl" id="appendUrl" value=""/>

<table class="menu">
	<tr>
		<th class="menuTitle"><img border="0" src='images/16x16/icon.png'
			alt='Patient Referrals' />&nbsp;Patient&nbsp;Referrals</th>
	</tr>
	<tr>
		<td>
		<table border="1" class="nrlMenuInfoBox">
			<tr>
				<td>
				<table width="100%">
					<tr>
						<td width="5%">&nbsp;</td>
						<c:choose>
						
						
							<c:when test="${model.summaryType == 'In Tray'}">
                                <td width="70%"><a id="intray" class="nrlInfoBoxActive"
                                    href="javascript:prepareRequestParams('intray','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">In&nbsp;Tray</a></td>
                                <td width="25%" align="center"><a class="nrlInfoBoxActive"
                                    href="javascript:prepareRequestParams('intray','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">[<c:out
                                    value="${sessionScope.INTRAY_COUNT}"></c:out>]</a></td>
							</c:when>
							<c:otherwise>
								<td width="70%"><a id="intray" class="nrlInfoBox"
									href="javascript:prepareRequestParams('intray','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">In&nbsp;Tray</a></td>
								<td width="25%" align="center"><a class="nrlInfoBox"
									href="javascript:prepareRequestParams('intray','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">[<c:out
									value="${sessionScope.INTRAY_COUNT}"></c:out>]</a></td>
							</c:otherwise>

						</c:choose>
					</tr>
				</table>
				</td>
			</tr>
			<tr>
				<td>
				<table width="100%">
					<tr>
						<td width="5%">&nbsp;</td>
						<c:choose>
							<c:when test="${model.summaryType == 'Out Tray'}">

								<td width="70%"><a id="outtray" class="nrlInfoBoxActive"
									href="javascript:prepareRequestParams('outtray','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">Out&nbsp;Tray</a></td>
								<td width="25%" align="center"><a class="nrlInfoBoxActive"
									href="javascript:prepareRequestParams('outtray','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">[<c:out
									value="${sessionScope.OUTTRAY_COUNT}"></c:out>]</a></td>
							</c:when>
							<c:otherwise>
								<td width="70%"><a id="outtray" class="nrlInfoBox"
									href="javascript:prepareRequestParams('outtray','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">Out&nbsp;Tray</a></td>
								<td width="25%" align="center"><a class="nrlInfoBox"
									href="javascript:prepareRequestParams('outtray','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">[<c:out
									value="${sessionScope.OUTTRAY_COUNT}"></c:out>]</a></td>
							</c:otherwise>
						</c:choose>

					</tr>
				</table>
				</td>
			</tr>
			<tr>
				<td>
				<table width="100%">
					<tr>
						<td width="5%">&nbsp;</td>

						<c:choose>
							<c:when test="${model.summaryType == 'Completed'}">
								<td width="70%"><a id="completed" class="nrlInfoBoxActive"
									href="javascript:prepareRequestParams('completed','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">Completed</a></td>
								<td width="25%" align="center"><a class="nrlInfoBoxActive"
									href="javascript:prepareRequestParams('completed','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">[<c:out
									value="${sessionScope.COMPLETED_COUNT}"></c:out>]</a></td>
							</c:when>
							<c:otherwise>
								<td width="70%"><a id="completed" class="nrlInfoBox"
									href="javascript:prepareRequestParams('completed','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">Completed</a></td>
								<td width="25%" align="center"><a class="nrlInfoBox"
									href="javascript:prepareRequestParams('completed','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">[<c:out
									value="${sessionScope.COMPLETED_COUNT}"></c:out>]</a></td>
							</c:otherwise>
						</c:choose>
					</tr>
				</table>
				</td>
			</tr>
			<sec:authorize access="hasAnyRole('ADMIN,'ACCESS_ALL_PATIENTS')">
            <tr>
                <td>
                <table width="100%">
                    <tr>
                        <td width="5%">&nbsp;</td>

                        <c:choose>
                            <c:when test="${model.summaryType == 'Patients In Breach'}">
                                <td width="70%"><a id="patientsInBreach" class="nrlInfoBoxActive"
                                    href="javascript:prepareRequestParams('patientsInBreach','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">Priority List</a></td>
                                <td width="25%" align="center"><a class="nrlInfoBoxActive"
                                    href="javascript:prepareRequestParams('patientsInBreach','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">[<c:out
                                    value="${sessionScope.BREACH_COUNT}"></c:out>]</a></td>
                            </c:when>
                            <c:otherwise>
                                <td width="70%"><a id="patientsInBreach" class="nrlInfoBox"
                                    href="javascript:prepareRequestParams('patientsInBreach','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">Priority List</a></td>
                                <td width="25%" align="center"><a class="nrlInfoBox"
                                    href="javascript:prepareRequestParams('patientsInBreach','<c:out value="${sessionScope.OTHER_USER}"/>','<c:out value="${sessionScope.SELECTED_USER_NAME}"/>');setFormAction(null);">[<c:out
                                    value="${sessionScope.BREACH_COUNT}"></c:out>]</a></td>
                            </c:otherwise>
                        </c:choose>
                    </tr>
                </table>
                </td>
            </tr>
          </sec:authorize>
          
		</table>
		</td>
	</tr>
	<sec:authorize access="hasRole('ADMIN')">
           <tr><td>
		<table class="menu" width="100%">
			<tr>
				<td class="menuSectionTitle">Content Admin</td>
			</tr>
			<tr>
				<td>
				<table width="100%">
					<tr>
						<td class="menuItem"><a href="nrlUsersList.form">NRL Users</a></td>
					</tr>
					<tr>
						<td class="menuItem"><a href="nrlDepartments.form">NRL Departments</a></td>
					</tr>

				</table>
				</td>
			</tr>
		</table>
		</td></tr>
	</sec:authorize>
	<!-- Changes to allow NRL search based on user -->

<sec:authorize access="hasAnyRole('ADMIN','ACCESS_ALL_PATIENTS')">
	<tr><td>
	<table border="1" class="menuInfoBox">
	<tr>
	<td>Select user:</td>
	</tr>
	<tr>
	<td nowrap="nowrap">
	<input  type="text" size="11" id="searchKey" name="searchKey" value="<c:out value="${sessionScope.userSearchKey}"/>" 
			alt="Search User" 
			onkeyup="searchSuggest();" autocomplete="off"/>
	<input type="submit" value="OK"  onclick="javascript:prepareRequestParams('intray','yes',document.getElementById('searchKey').value);setFormAction(null);" /></td>
	</tr>
	</table>
		<div id="search_suggest">
		</div>
	<script src="../ajax/ajax_search.js" type="text/javascript"></script>
	</td></tr>
</sec:authorize>
</table>


<!--  End of Changes to allow NRL search based on user-->
<div id="patientInfoDiv">
<c:if test="${patientInfo !=null}">
	<table border = "1" class="menuInfoBox">
		<tr>
		<td class="menu"><br/></td>
		</tr>
		<tr>
		<td>
		<table width="100%">
		<tr>
			<td class="menuInfoBoxLabel" colspan="2"><b>Patient Details</b></td>
		</tr>
		<tr>
			<td class="menuInfoBoxLabel">Forename:</td>
			<td class="menuInfoBoxValue"><c:out value="${patientInfo.foreName }"/></td>
		</tr>
		<tr>
			<td class="menuInfoBoxLabel">Surname:</td>
			<td class="menuInfoBoxValue"><c:out value="${patientInfo.surName }"/></td>
		</tr>
		<tr>
			<td class="menuInfoBoxLabel">Sex:</td>
			<td class="menuInfoBoxValue"><webapp:listValue domain="EMDT" listName="SexCode" key="${patientInfo.sex}" /></td>
		</tr>
		<tr>
			<td class="menuInfoBoxLabel">Age:</td>
			<td class="menuInfoBoxValue"><c:out value="${patientInfo.age }"/>	</td>
		</tr>
		<tr>
			<td class="menuInfoBoxLabel">NHS No.:</td>
			<td class="menuInfoBoxValue"><c:out value="${patientInfo.nhsNumber }"/></td>
		</tr>
		<tr>
			<td class="menuInfoBoxLabel">Hospital Number:</td>
			<td class="menuInfoBoxValue"><c:out value="${patientInfo.hospitalNumber }"/></td>
		</tr>
		</table>
	</td>
	</tr>
	<tr>
		<td class="menu" ><br/></td>
		</tr>
	</table>
</c:if>
</div>
</smvc:form>
