<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<style>
	.selectedMeeting {
		background-color: #ECFF7F;
	}
	.patientsdiv	{
		display: none;
	}
	.patientslisting {
		width: 100%;
		border:	1px lightgray solid;
	}
	.patientslisting td	{
		padding: 10px;
		vertical-align: top;
		text-align: left;
	}
	.patientslisting th	{
		background-color: #EBF5FF;
	}
	.mytoggler	{
		cursor: pointer;
	}
	.patientsdiv a:link	{
		padding-bottom: 18px;
	}
	
</style>
<br/>


<script type="text/javascript">
function selectMeetingFormSubmit()
{
document.getElementById("selectmeetingform").submit();
}
</script>

<!-- table to keep main content centred...should use css really -->

<div class="message" align="center"><c:out value="${requestScope.message}"/>"/></div>
<table width="100%">
<tr>
<td align="center">
	<table width="80%">
		<tr>
		<td>
		
			<h2><c:out value="${emdt.meetingListFilter['class'].name }"/>"/></h2>
			
			<smvc:form action="setMeetingFilter.form" method="get" id="selectmeetingform">
					Show <select name="filterId" onchange="selectMeetingFormSubmit();">
						<option value="3" <c:if test="${fn:substring(title, 0, 5) eq 'Today'}">selected="selected"</c:if> >Today's</option>
						<option value="2" <c:if test="${fn:substring(title, 0, 7) eq 'Planned'}">selected="selected"</c:if> >Planned</option>
						<option value="1" <c:if test="${fn:substring(title, 0, 8) eq 'Previous'}">selected="selected"</c:if> >Historic</option>
						<option value="0" <c:if test="${fn:substring(title, 0, 3) eq 'All'}">selected="selected"</c:if> >All</option>
					</select>
					&nbsp;Location&nbsp;
					
					<select name="hospitalFilterId" onchange="selectMeetingFormSubmit();">
						<option value="">Any</option>
						<c:forEach var="hospitals" items="${webapp.hospMap}">
						    <option value="<c:out value="${hospitals.key}"/>" <c:if test='${hospitalFilterIdSelected eq hospitals.key }'> selected='selected'</c:if> ><c:out value="${hospitals.value}"/></option>
						</c:forEach>
					</select>&nbsp;Speciality&nbsp;
					<webapp:namedList name="speciality" domain="EMDT" id="nl"/>
					<select name="specialityFilterId" onchange="selectMeetingFormSubmit();">
						<option value="">Any</option>
						<c:forEach var="pair" items="${nl.pairIterator }">
						<option value="<c:out value="${pair.first}" />"  <c:if test='${specialityFilterIdSelected eq pair.first }'> selected='selected'</c:if> ><c:out value="${pair.second }"/></option>
						</c:forEach>
					</select>
					<a href="javascript:selectMeetingFormSubmit();">
					<img src="../images/16x16/bullet_go.png" /></a>
				</smvc:form>
			
			
				<table class="patientslisting" width="100%">
					<tr>
						<th class="tableColHeader" width="20%">Date</th>
						<th class="tableColHeader">Speciality</th>
						<th class="tableColHeader">Location</th>
						<th class="tableColHeader">Patients</th>
						<th class="tableColHeader">Attendees</th>
						<th class="tableColHeader" width="16px"><!-- locked --></th>
						<th class="tableColHeader"><!-- link --></th>
					</tr>
					<c:set value="${emdt.meetings }" var="filteredMeetings"/>
					<c:forEach var="meeting" items="${filteredMeetings }" varStatus="s">
						<c:choose>
							<c:when test="${emdt.currentMeeting != null and  emdt.currentMeeting.id == meeting.meeting_id}"><c:set var="selMeeting" value="selectedMeeting"/> </c:when> 
							<c:otherwise><c:set var="selMeeting" value="unselectedMeeting"/></c:otherwise>
						</c:choose>
						
						<tr class='<c:out value="${s.index%2 == 0 ? 'even' : 'odd' }"/>Row  <c:out value="${selMeeting }"/>'>
							<td  align="center"><fmt:formatDate value="${meeting.meeting_date }" pattern="dd MMM yyyy"/>-<fmt:formatDate value="${meeting.meeting_date }" pattern="HH:mm"/></td>
							<td ><webapp:listValue domain="emdt" listName="speciality" key="${meeting.meeting_tumourGroup }" />&nbsp;</td>
							<td ><c:out value="${meeting.meeting_hospital_hospitalName}"/><br/><c:out value="${meeting.meeting_location}"/>&nbsp;</td>
							<td >
							<div>
								<div class="mytoggler"><c:out value="${fn:length(meeting.meetingItemDtoList) }"/> patient<c:if test="${fn:length(meeting.meetingItemDtoList) ne 1 }">s</c:if> <img src="../images/next-sm.png"/></div>
								<div class="patientsdiv">
								<c:if test="${fn:length(meeting.meetingItemDtoList) gt 0 }">
									<c:forEach var="item" items="${meeting.meetingItemDtoList}" varStatus="counter">
									<c:choose>
										<c:when test="${item.patientFlag}">
										<br/>
										<a href="selectMeeting.form?id=<c:out value="${meeting.meeting_guid }"/>&forward=selectItem&itemId=<c:out value="${item.meeting_items_guid }"/>"><c:out value="${item.meeting_items_patientDiscussed_forename}"/> <c:out value="${fn:toUpperCase( item.meeting_items_patientDiscussed_surname )}"/></a>
										</c:when>
										<c:otherwise>
										(no permission to view patient <c:out value="${counter+1}"/>)<br/>
										</c:otherwise>
									</c:choose>
									</c:forEach>
								</c:if>
								</div>
							</div>
							</td>
							<td >
								<c:forEach items="${meeting.meetingAttendeeDtoList}" var="attendee" varStatus="loop">
									<c:if test="${!empty attendee && attendee.meeting_attendees_user_username!=null}">
										<c:out value="${attendee.meeting_attendees_user_forename}"/> <c:out value="${attendee.meeting_attendees_user_surname}"/>
									<c:if test="${!loop.last}">,</c:if></c:if>
								</c:forEach>
								&nbsp;
							</td>
							<td><c:if test="${meeting.locked }"><img src="../emdt/images/16x16/locked.png" alt="lock" title="This meeting is locked."/></c:if>
							</td>
							<td align="right" ><a href="selectMeeting.form?forward=selectItem&id=<c:out value="${meeting.guid}"/>">Select <img src="../images/16x16/bullet_go.png" alt="icon" /></a></td>
						</tr>
					</c:forEach>
					<c:if test="${empty filteredMeetings}">
						<tr>
							<td colspan="7">
							No meetings found
							</td>
						</tr>
					</c:if>
					
					<c:if test="${not empty filteredMeetings}">
						<tr>
							<td colspan="7" style="color:gray;">
							<c:out value="${fn:length(filteredMeetings) }"/> meeting<c:if test="${fn:length(filteredMeetings) != 1 }">s</c:if>
							<c:if test="${count > 0 }">
								<br/><b><c:out value="${count }"/> meetings(s) have been filtered out.</b>
							</c:if>
	
							</td>
						</tr>
					</c:if>
				</table>

			</td>
		</tr>

		<tr>
			<td>
				&nbsp;<br/> <!--  spacer -->
			</td>
		</tr>


		<tr>
			<td>		
			</td>
		</tr>
		
		<tr>
			<td>

			<%@ include file="meetingsNavigationPanel.include.jsp"%>
			</td>
		</tr>
	</table>
		</td>
	</tr>
</table>

<script>
$(".mytoggler").click(function() {
	  $(this).parent().children(".patientsdiv").toggle(100);
	});
</script>

