<%@ include file="/includes.jsp"%>
<style>
.backButtonHolder{
	padding-top:5px;
	width:231px;
	height:75px;
	float:left;
	margin: 0 0 0 320px;
	display:inline;
	background:url(../referrals/images/imgPinkLong.gif) top center;
	background-repeat:no-repeat;
	text-align:center;
	font-weight: bold;
	color: #02018b;
	cursor: pointer;
}
</style>
<c:if test="${emdt.currentMeeting ne null}">
	<div class="menuButtonRect pink"><a href="../meetings/resumeMeeting.form">Resume Current Meeting</a> </div>
</c:if>
<c:choose>
	<c:when test="${filterForm.name ne null }"><c:set var="nameOfForm" value="${filterForm.name}"></c:set></c:when>
	<c:otherwise><c:if test="${consultationNoteForm ne null}"><c:set var="nameOfForm" value="${consultationNoteForm.view.formName}"></c:set></c:if></c:otherwise>
</c:choose>
<c:if test="${referralPatientDto.currentCareSpell.referralDetails.referralsDefinition ne null || emdt.currentCareSpell.referralDetails.referralsDefinition ne null}">
	<c:choose>
		<c:when test="${referralPatientDto.currentCareSpell.referralDetails.referralsDefinition ne null}">
			<c:set var="referralsDefinition" value="${referralPatientDto.currentCareSpell.referralDetails.referralsDefinition}" scope="request"></c:set>
		</c:when>
		<c:otherwise>
			<c:set var="referralsDefinition" value="${emdt.currentCareSpell.referralDetails.referralsDefinition}" scope="request"></c:set>
		</c:otherwise>
	</c:choose>
	<c:set var="currentCareSpell" value="${emdt.currentCareSpell}" scope="session"></c:set>
</c:if>
<c:if test="${referralsDefinition ne null}">
	<c:set var="groupBy" value="" scope="request" ></c:set>
	<c:if test="${nameOfForm !=null or nameOfForm ne ''}">
		<c:forEach var="formSummaryMapOrder" items="${referralsDefinition.formSummaryMapOrder}">
			<c:if
				test="${formSummaryMapOrder.formOrSummaryName eq nameOfForm and formSummaryMapOrder.groupName!='Top Level' }">
				<c:set var="groupBy" value="${formSummaryMapOrder.groupName}" scope="request"></c:set>
			</c:if>
		</c:forEach>
	</c:if>
	<c:if test="${nameOfForm !=null or nameOfForm ne '' }">
		<c:forEach var="formSummaryMapOrder"
			items="${referralsDefinition.formSummaryMapOrder}">
			<c:if
				test="${formSummaryMapOrder.formOrSummaryName eq summaryName and formSummaryMapOrder.groupName=='Top Level' }">
				<c:set var="groupBy" value="" scope="request"></c:set>
			</c:if>
		</c:forEach>
	</c:if>
	<c:choose>
	<c:when test="${ summaryName eq null and ((null eq nameOfForm) or  ('' eq nameOfForm)) and addToMeeting ne true }">
		<c:set var="menuButtonHolderDivClass" value="menuButtonSquare selected"/>
	</c:when>
	<c:otherwise>
		<c:set var="menuButtonHolderDivClass" value="menuButtonSquare blue"/></c:otherwise>
	</c:choose>
	<c:choose>
		<c:when test="${groupBy ne null and groupBy ne ''}">
					<div class="menuHolder">
						<div class="<c:out value="${menuButtonHolderDivClass}"/>">
							<a href="viewPatient.form?formName=">Patient<br />Details</a>
						</div>
						<tiles:insertTemplate template ="forms/groupFormsMenu.jsp"  /><br/>
						<tiles:insertTemplate template ="forms/formsMenu.jsp" />
						<div class="menuButtonSquare pink">
						<a href="../referrals/referralssummary.form"> <br /> Save Or Submit<br /> Record To<br /> <c:out value="${centralHubHospital.hospitalName}"/></a>
						</div>
					</div>
		</c:when>
		<c:otherwise>
			<div class="menuHolder">
					<div class="<c:out value="${menuButtonHolderDivClass}"/>">
						<a href="viewPatient.form?formName=">Patient<br /> Details</a>
					</div>
					<tiles:insertTemplate template ="forms/groupFormsMenu.jsp"  />
					<sec:authorize access="!hasRole('NMDT_COORD')">
					<div class="menuButtonSquare pink">
						<a href="../referrals/referralssummary.form"> <br /> Save Or Submit<br /> Record To<br /> <c:out value="${centralHubHospital.hospitalName}"/></a>
					</div>
					</sec:authorize>
					<sec:authorize access="hasRole('NMDT_COORD')">
						<div
						<c:choose>
		 					<c:when test="${addToMeeting eq true}">class="menuButtonSquare selected"</c:when>
							<c:otherwise>class="menuButtonSquare blue"</c:otherwise>
						</c:choose>>
						<a href="../referrals/addCurrentPatientToNextMeeting.form?task=selectNextMeeting"> Add to MDT <br />Meeting</a>
						</div>
					</sec:authorize>
			</div>
		</c:otherwise>
	</c:choose>
</c:if>