<%@ include file="/includes.jsp"%>
<%@ page import="com.ardeo.referrals.constants.ReferralFieldConstants"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>

<style>
	#scrollTopButton {
		display: none;
		position: fixed;
		bottom: 20px;
		right: 20px;
		z-index: 99;
		font-size: 16px;
		border: none;
		outline: none;
		background-color: lightgrey;
		color: white;
		cursor: pointer;
		padding: 10px;
		border-radius: 4px;
	}

	#scrollTopButton:hover {
		background-color: lightseagreen;
	}

</style>
<script type="text/javascript">
	var unsavedData = ${param.unsavedData != null};
</script>
<script type="text/javascript">
	$(document).ready(function(){
		   if(document.getElementById("noteModifiedByOtherUser") && document.getElementById("noteModifiedByOtherUser").value == 'yes'){
			   openNoteModificationPopup();
		   }
	});
	function changeSummaryData() {
		fullScreenPleaseWait();
		//var summarySince=document.getElementById('summarySince').value;
		var summaryId = document.getElementById('summaryId').value;
		document.location = "changeSummary.form?summaryId=" + summaryId;//+"&summarySince="+summarySince;
	}

	function changeUrl(reloadpage) {
		fullScreenPleaseWait();
		var loc = location.href;
		if (reloadpage) {
			var frmIndex = loc.lastIndexOf("/") + 1;
			var toIndex = loc.length;
			var strToReplace = loc.substring(frmIndex, toIndex);
			var newLoc = loc.replace(strToReplace, "viewPatients.jsp");
			window.location = newLoc;
		}
	}

	// JQuery code to show or hide the sticky patient demographics heading when the page scrolls
	$(function() {
		// Check the initial Poistion of the Sticky Header
		var stickyHeaderTop = $('#stickyheader').offset().top;

		$(window).scroll(function() {
			if ($(window).scrollTop() > stickyHeaderTop) {
				$('#stickyheader').css({
					position : 'fixed',
					top : '0px',
					left : '0px',
					width : '100%',
					visibility : 'visible'
				});
				$('#stickyalias').css('display', 'block');
			} else {
				$('#stickyheader').css({
					position : 'static',
					top : '0px',
					visibility : 'hidden'
				});
				$('#stickyalias').css('display', 'none');
			}

			if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
				document.getElementById("scrollTopButton").style.display = "block";
			} else {
				document.getElementById("scrollTopButton").style.display = "none";
			}
		});
	});

	// When the user clicks on the button, scroll to the top of the document
	function topFunction() {
		document.body.scrollTop = 0;
		document.documentElement.scrollTop = 0;
	}
</script>
<br />
<!-- hovering TOP navigation button -->
<button onclick="topFunction()" id="scrollTopButton" title="Go to top">Top</button>

<a id="topOfPage">
	<!-- anchor for navigation to top of page -->
</a>
<%@ include file="lockMeetingPopUp.jsp"%>
<input type="hidden" id="csrfparameterName" value="<c:out value="${_csrf.parameterName}"/>" />
<input type="hidden" id="csrfparametervalue" value="<c:out value="${_csrf.token}"/>" />
<table width="100%">
	<tr>
		<td valign="top" align="center">
			<div align="center">

				<c:if test="${emdt.currentMeeting != null}">
					<table class="meetingDetailsPanel">
						<tr height="4">
							<td></td>
						</tr>
						<tr>
							<td></td>
							<td class="meetingDetailsLabel">Meeting Title</td>
							<td class="meetingDetailsLabel">Date</td>
							<td class="meetingDetailsLabel">Time</td>
							<td class="meetingDetailsLabel">Speciality</td>
							<td class="meetingDetailsLabel">Hospital</td>
							<td class="meetingDetailsLabel">Location</td>

						</tr>
						<tr>
							<td>&nbsp;</td>
							<td class="meetingDetailsData"><c:out value="${emdt.currentMeeting.title }"/>
								<c:if test="${emdt.currentMeeting.locked }">
									<span style="color: red; margin-left: 20px;"> <img
										src="../emdt/images/16x16/locked.png" alt="lock" /> This
										meeting is locked
									</span>
								</c:if>
							</td>
							<td class="meetingDetailsData"><fmt:formatDate
									value="${emdt.currentMeeting.date }" pattern="dd MMM yyyy" /></td>
							<td class="meetingDetailsData"><fmt:formatDate
									value="${emdt.currentMeeting.date }" pattern="HH:mm" /> - <fmt:formatDate
									value="${emdt.currentMeeting.endDate }" pattern="HH:mm" /></td>
							<td class="meetingDetailsData"><webapp:listValue
									domain="emdt" listName="speciality"
									key="${emdt.currentMeeting.tumourGroup }" /></td>
							<td class="meetingDetailsData"><c:out value="${emdt.currentMeeting.hospital.hospitalName }"/></td>
							<td class="meetingDetailsData"><c:out value="${emdt.currentMeeting.location }"/></td>
						</tr>
						<tr height="4">
							<td></td>
						</tr>
					</table>
				</c:if>
				<c:if test="${error ne null }">
					<table>
						<tr>
							<td align="center" class="error">
								<c:out value="${error }"/>
									<br /></td>
						</tr>
					</table></c:if>
				<c:set var="forwardOnError" value="meetingPatientList"
					scope="request" />
				<c:set var="cnDetails" value="fromMeeting" scope="request" />
				<br />
				<c:if test="${requestScope.message ne null}">
					<div class="message">
						<img src="../images/16x16/information.png" alt="i" />
						<c:out value="${requestScope.message}"/>
					</div>
				</c:if>
				<c:if test="${emdt.currentMeeting == null}">
					<span class="warning">There is no meeting selected - please
						either choose one or add a new meeting.</span>
				</c:if>

				<c:choose>
					<c:when test="${showForm ne null}">
						<c:set var="formExists" value="${showForm}"></c:set>
					</c:when>
					<c:otherwise>
						<c:set var="formExists" value="true"></c:set>
					</c:otherwise>
				</c:choose>

				<!--  Patient Navigation section -->

				<c:if
					test="${emdt.currentMeeting != null and emdt.currentMeeting.currentItem != null }">
						
						<c:set var="currentPatientIndex" value="-1" />
						<c:forEach var="item" items="${emdt.currentMeeting.items }" varStatus="s">
							<c:if test="${item.patientDiscussed.id eq emdt.currentMeeting.currentItem.patientDiscussed.id}">
								<c:set var="currentPatientIndex" value="${s.count}" />
							</c:if>
							
						</c:forEach>
					
					<table width="90%" class="navButtonBar">
						<tr>
							<td align="right"><a
								href="navigateMeeting.form?action=previousMeetingItem"
								class="buttonClass"> <img src="../images/backward.png" />
									Previous patient&nbsp;&nbsp;
							</a></td>
							<td align="center">Patient <span id="currentPatientCountDiv"><c:out value="${currentPatientIndex}"/></span>
								of <c:out value="${fn:length(emdt.currentMeeting.items)}"/>
							</td>
							<td><a href="navigateMeeting.form?action=nextMeetingItem"
								class="buttonClass"> Next patient <img
									src="../images/forward.png" />&nbsp;&nbsp;
							</a></td>

							<td align="center"><input type="hidden"
								id="currentSelectedPatient"
								value="<c:out value="${emdt.currentMeeting.currentItem.guid}"/>" /> Jump to
								patient: <select name="patients" id="patients" class="selectBox">
									<c:forEach var="item" items="${emdt.currentMeeting.items }" varStatus="s" >
										<%-- conditionally allow user to view patient details --%>
										<c:choose> 
											<c:when test="${item.patientFlag}">
												<option value="<c:out value="${item.guid}"/>"
													<c:if test="${item.guid == emdt.currentMeeting.currentItem.guid}" >selected="selected"</c:if>>
													<c:out value="${s.count}"/>. <c:out value="${item.patientDiscussed.surname }"/>,&nbsp;<c:out value="${item.patientDiscussed.forename }"/>&nbsp;</option>
											</c:when>
											<c:otherwise>
												<option value="<c:out value="${item.guid}"/>" disabled="disabled">(no
													permission to view patient)</option>
											</c:otherwise>
										</c:choose>
									</c:forEach>
							</select></td>
						</tr>
					</table>
				</c:if>

				<br />
				<!--  Start main patients table -->
				<table width="90%">
					<tr>
						<td>
							<c:set var="item" value="${emdt.currentMeeting.currentItem}" />

							<input type="hidden" id="currentPatientCount" value="<c:out value="${currentPatientIndex}"/>" />

							<%-- conditionally allow user to view patient details --%>
							<c:choose>
								<c:when test="${item.patientFlag}">

									<!--  Patient demographics and meeting item section -->
									<div class="meetingSection">

										<h2>Demographics</h2>
										<table width="100%">
											<tr>
												<td valign="top">
													<table class="meetingPatientDetails">
														<tr>
															<td class="meetingPatientDetailsLabel">Patient Name</td>
															<td class="meetingPatientDetailsData"><b><c:out value="${item.patientDiscussed.forename }"/> <c:out value="${fn:toUpperCase(item.patientDiscussed.surname) }"/></b></td>
														</tr>
														<tr>
															<td class="meetingPatientDetailsLabel">Age</td>
															<td class="meetingPatientDetailsData"><c:if test="${! empty item.patientDiscussed.dateOfBirth }"><c:out value="${item.patientDiscussed.currentAge }"/></c:if></td>
														</tr>
														<tr>
															<td class="meetingPatientDetailsLabel">Date of Birth</td>
															<td class="meetingPatientDetailsData"><fmt:formatDate 	value="${item.patientDiscussed.dateOfBirth }" pattern="dd MMM yyyy" /></td>
														</tr>
														<tr>
															<td class="meetingPatientDetailsLabel">Hospital number</td>
															<td class="meetingPatientDetailsData"><c:out value="${item.patientDiscussed.hospitalNumber }"/></td>
														</tr>
														<tr>
															<td class="meetingPatientDetailsLabel">NHS Number</td>
															<td class="meetingPatientDetailsData"><c:out value="${item.patientDiscussed.nhsNumber }"/></td>
														</tr>
													</table>
												</td>
												<td valign="top">
													<table>
														<tr>
															<td class="meetingPatientDetailsLabel">Primary clinician</td>
															<td class="meetingPatientDetailsData"><c:out value="${item.patientDiscussed.primaryClinicianInCSMatchesMeetingTG}"/></td>
														</tr>
														<tr>
															<td class="meetingPatientDetailsLabel">Last discussed at MDT</td>
															<td class="meetingPatientDetailsData"><fmt:formatDate value="${item.lastDiscussedDate}" pattern="dd MMM yyyy" /></td>
														</tr>
														<tr>
															<td class="meetingPatientDetailsLabel">Follow up date</td>
															<td class="meetingPatientDetailsData"><fmt:formatDate value="${item.followUpDate}" pattern="dd MMM yyyy" /></td>
														</tr>
														<tr>
															<td class="meetingPatientDetailsLabel">
																<!-- Meeting Type  -->
															</td>
															<td class="meetingPatientDetailsData">
																<!-- <webapp:listValue domain="EMDT" listName="MeetingItemType" key="${item.type}" /> -->
															</td>
														</tr>
													</table>
												</td>
											</tr>
											<tr>
												<td colspan="2" valign="bottom" align="right"><a href="../emdt/viewPatient.form?patientId=<c:out value="${item.patientDiscussed.guid}"/>">Go to Patient Record <img src="../images/16x16/bullet_go.png" /></a></td>
											</tr>
										</table>
										
										<c:if test="${item.patientDiscussed.deathIndicator }"><span class="patientDeceasedMessage warning">Patient is Deceased</span></c:if>
										
									</div>
									
									<!-- Sticky header for patient demographics, initially invisible -->
									<div id="stickyheader">
										<table class="navButtonBar">
											<tr>
												<td class="meetingPatientDetailsLabel">Patient Name</td>
												<td class="meetingPatientDetailsData"><b><c:out value="${item.patientDiscussed.forename }"/> <c:out value="${fn:toUpperCase(item.patientDiscussed.surname) }"/></b></td>
												<td class="meetingPatientDetailsLabel">DOB</td>
												<td class="meetingPatientDetailsData"><fmt:formatDate value="${item.patientDiscussed.dateOfBirth }" pattern="dd MMM yyyy" /></td>
												<td class="meetingPatientDetailsLabel">Age</td>
												<td class="meetingPatientDetailsData"><c:if test="${! empty item.patientDiscussed.dateOfBirth }"><c:out value="${item.patientDiscussed.currentAge }"/></c:if></td>
												<td class="meetingPatientDetailsLabel">Hospital number</td>
												<td class="meetingPatientDetailsData"><c:out value="${item.patientDiscussed.hospitalNumber }"/></td>
												<td class="meetingPatientDetailsLabel">Primary clinician</td>
												<td class="meetingPatientDetailsData"><c:out value="${item.patientDiscussed.primaryClinicianInCSMatchesMeetingTG}"/></td>
											</tr>
										</table>
									</div>
									<!--  this div marks the location we compare with the window scroll position to to display the sticky header above -->
									<div id="stickyalias"></div>

									<!--  Summary Report section -->

									<div class="meetingSection">

										<table width="100%">
											<tr>
												<td>
													<h2>Summary</h2>
												</td>
												<td align="right"><br /> 
													<select name="summaryId" onchange="changeSummaryData();" id="summaryId">
														<option value=""></option>
														<c:forEach var="summary" items="${emdt.patientSummaries}">
															<option value="<c:out value="${summary.id}"/>"
																<c:if test="${emdt.currentMeeting.summaryId != null and emdt.currentMeeting.summaryId eq summary.id }">selected="selected"</c:if>>
																<c:out value="${summary.title}"/></option>
														</c:forEach>
													</select>
												</td>
											</tr>
										</table>
										
										<c:if test="${emdt.currentMeeting.summaryId != null}">

											<div class="divMeetingPatientSummary">
												<emdt:runSummary summaryId="${emdt.currentMeeting.summaryGuid}" patientId="${item.patientDiscussed.guid }" />
												<tiles:insertTemplate template="../../emdt/tiles/patientSummaryTile.jsp" >
													<tiles:putAttribute name="patientGuid" value="${item.patientDiscussed.guid}"/>
												</tiles:insertTemplate>
											</div>
											
										</c:if>
									</div>


									<!-- Imaging section -->
									<c:if test="${imagingEnabled eq 'true' }">
										<div class="meetingSection">

											<h2>Imaging</h2>
											<ul>
												<c:forEach var="imagingStatus"
													items="${imagingStatusList}">

													<li>
													<a href="../referrals/imgStatusTracking.form?patientId=<c:out value="${item.patientDiscussed.guid}"/>&loadImage=imgStatusTracking&dateOfScan=<fmt:formatDate value="${imagingStatus.dateOfScan}" pattern="dd/MM/yyyy" />&hospitalNumber=<c:out value="${item.patientDiscussed.hospitalNumber}"/>&accessionNo=<c:out value="${imagingStatus.accessionNum}"/>" title="View imaging" target="_blank"> View <c:out value="${imagingStatus.description}"/> &nbsp; <img src="../images/16x16/zoom.png" /></a>
												</c:forEach>


												<c:if
													test="${imagingStatusList eq null or fn:length(imagingStatusList) == 0}">
														This patient does not appear to have any completed image transfers.  <br />&nbsp;<br />
													<a
														href="../referrals/imgStatusTracking.form?patientId=<c:out value="${item.patientDiscussed.guid}"/>"
														title="View imaging" target="_blank"> View all
														Images and reports &nbsp; <img
														src="../images/16x16/zoom.png" /></a>

												</c:if>
											</ul>
										</div>
									</c:if>
									
									<c:if test="${emdt.currentMeeting.virtualMeeting }">
									<div class="meetingSection">

										<h2>Virtual MDT Discussion</h2>
										<smvc:form id="blogForm" method="POST">
											<input type="hidden" name="itemId" value="<c:out value="${item.guid}"/>"></input>
											<input type="hidden" name="blogAction" id="blogAction" value=""></input>
											<input type="hidden" name="blogPostId" id="blogPostId" value=""></input>

											<div id="blogLockContainer">
												<input type="hidden" name="isBloggingAllowed"
													id="isBloggingAllowed" value="<c:out value="${item.bloggingAllowed}"/>"></input>
													<sec:authorize access="hasAnyRole('MEETING_ADMIN','ADMIN')">
														<c:choose>
														<c:when test="${item.bloggingAllowed}">
															<button id="lockUnlockBlog" title="Click to lock this Virtual MDT discussion and prevent further comments for this patient. (Admin only)" ><img src="../images/16x16/lock.png" alt="lock"> <span id="blogLockButtonText">Lock Discussion</span></button>
														</c:when>
														<c:otherwise>
															<c:if test="${! emdt.currentMeeting.locked }">
																<button id="lockUnlockBlog" title="Click to unlock this Virtual MDT discussion and allow further comments for this patient. (Admin only)" ><img src="../images/16x16/lock.png" alt="lock"> <span id="blogLockButtonText">Unlock Discussion</span></button>
															</c:if>
														</c:otherwise>
														</c:choose>
												</sec:authorize>
												<c:if test="${! item.bloggingAllowed }">
													<div id="blogLockedMessage"><img src="../images/16x16/lock.png" alt="lock"> This Virtual MDT discussion is closed.</div>
												</c:if>
											</div>

											<br />
											<c:set var="blogContributeStyle" value="style='display: none;'"/>
											<c:if test="${item.bloggingAllowed }">
												<c:set var="blogContributeStyle" value="style='display: inline-block;'"/>
											</c:if>

											<%-- don't show delete button if not privileged --%>
											<sec:authorize access="!hasAnyRole('MEETING_ADMIN','ADMIN')">
												<style type="text/css">
													.blogDelete	{
														display: none;
													}
												</style>
											</sec:authorize>
											<%-- don't show delete button if privileged and meeting is locked --%>
											<sec:authorize access="hasAnyRole('MEETING_ADMIN','ADMIN')">
												<c:if test="${emdt.currentMeeting.locked }">
												<style type="text/css">
													.blogDelete	{
														display: none;
													}
												</style>
												</c:if>
											</sec:authorize>

											<div id="blogContributeContainer" ${blogContributeStyle} >
												Contribute to discussion<br/>
												<textarea id="blogComment" name="blogComment" rows="3" cols="70" placeholder="Enter comment" class="noUnsavedWarning"></textarea><br/>
												<input type="submit" id="blogSave" name="blogSave"  value="Save Comment" class="noUnsavedWarning" />
												<img id="spinner" src="../images/ajax-loader-bl.gif" style="display: none;"/>
											</div>
	
											<div id="blogMessageArea"><!-- the success/failure message will appear here --></div>
		
											<div id="blogPosts">
											<%-- JSP renders the blog posts on page load, but future posts displayed by JS --%>
											<c:forEach items="${item.blogComments}" var="blog">
												<div class="blogRow">
													<div class="blogUser"><c:out value="${blog.userMakingComment.fullName}"/>
													<br/><div class="blogHospital"><c:out value="${blog.userMakingComment.hospital.hospitalName}"/></div>
													</div>
													<pre class="blogComment"><c:out value="${blog.comment}"/></pre>
													<div class="blogDate"><fmt:formatDate value="${blog.dateOfComment}" pattern="dd MMM yyyy,  HH:mm"/>
													<sec:authorize access="hasAnyRole('ROLE_MEETING_ADMIN','ROLE_ADMIN')">
														<div class="blogDelete">
														<a href="javascript:deleteBlogPost(<c:out value="${blog.id}"/>)" class="noUnsavedWarning" title="Delete this comment..."><img src="../images/delete.png" alt="Delete"/></a>
														</div>
													</sec:authorize>
													</div> 
													
												</div>
											</c:forEach>
											<c:choose>
											<c:when test="${empty item.blogComments }">
												<span>There are no comments.</span>
											</c:when>
											<c:otherwise>
												<span>(<c:out value="${item.blogComments.size()}"/> comments)</span>
											</c:otherwise>
											</c:choose>
											</div>

										</smvc:form>

									<script src="tiles/virtualMeetingBlog.js" type="text/javascript"></script>
									</div> <%--end of Virtual MDT Discussion --%>
									</c:if>


									<!-- Meeting notes form section -->
									<div class="meetingSection">
										<h2>Notes</h2>
										<a name="notesSectionPosition"> <!-- anchor for position after form submit --> </a>
										<c:choose>
											<c:when
												test="${emdt.currentMeeting.formPath ne null && emdt.currentMeeting.formPath ne '' and formExists eq 'true'}">

												<c:set var="isFromMeeting" value="isFromMeeting" scope="request" />
												<tiles:insertTemplate template="/meetings/tiles/consultationNoteLayout.jsp" />

											</c:when>
											<c:otherwise>
												<div>
													<img src="../images/16x16/information.png" /> This
													meeting does not have a notes form specified, therefore
													no form will appear here. Please check the meeting
													overview.
												</div>
											</c:otherwise>
										</c:choose>
									</div>
									<!-- Feed notes section -->


									<c:if test="${showFeedNotes}">

										<div class="meetingSection">

											<h2>Feed notes</h2>

											<c:out value="${feedNotes}"/>
										</div>
									</c:if>
									<!--  Meeting response and other things will be added here( start) -->
									<c:if test="${emdt.currentMeeting.hospital.virtualHospital}">
									<sec:authorize access="hasAnyRole('ROLE_NMDT_COORD')">

										<div class="meetingSection">
											<h2>Response</h2>
											<smvc:form id="meetingItemResponseForm" method="POST" >
												<input type="hidden" name="itemId" id="itemId" value="<c:out value="${item.guid }"/>"></input>

												<div class="infoMessage" id="responseMessage"><c:out value="${responseMessage}"/></div>
												<div class="meetingActionAndReponseLabel">Date of Information</div>
												<div>
													<c:choose>
														<c:when test="${readOnly}">
															<input type="text"
																name="meetingResponseDateOfInformation" size="0"
																id="meetingResponseDateOfInformation" class="form-control" readonly="readonly"
																value="<c:out value="${item.meetingResponse.dateOfInformation}"/>"
																placeholder="dd/mm/yyyy" />
														</c:when>
														<c:otherwise>
															<input type="text"
																name="meetingResponseDateOfInformation" size="0"
																id="meetingResponseDateOfInformation" class="form-control"
																value="<c:out value="${item.meetingResponse.dateOfInformation}"/>"
																placeholder="dd/mm/yyyy" />&nbsp;<img title='Click to choose date'
																style='cursor: pointer;'
																src='../images/16x16/date.png' id='meetingResponseDateOfInformation_DateTrigger' />
														</c:otherwise>
													</c:choose>
												</div>
												<div class="meetingActionAndReponseLabel">Title</div>
												<div>
													<input type="text" name="meetingResponseTitle"
														value="<c:out value="${item.meetingResponse.title}"/>" />
												</div>
												<div class="meetingActionAndReponseLabel">Response to Primary Clinician Submitting patient:</div>
												<div>
													<textarea
														name="meetingResponseResponsetoPrimaryClinician"
														cols="100" rows="5"><c:out value="${item.meetingResponse.responsetoPrimaryClinician}"/></textarea>
												</div>
												<div><input type="submit" id="responseSubmit" value="Send response" />
												<img id="responseSpinner" src="../images/ajax-loader-bl.gif" style="display: none;"/>
												</div>
														
											</smvc:form>
										</div>
										
										<div class="meetingSection">
											
											<h2>Actions</h2>
											<smvc:form id="meetingItemActionForm" method="POST">
												<input type="hidden" name="itemId" id="itemId" value="<c:out value="${item.guid }"/>"></input>
												<div class="infoMessage" id="actionMessage"><c:out value="${actionMessage}"/></div>
												<input type="checkbox" id="patientDiscussed" name="patientDiscussed"	<c:if test="${item.discussed ne null and item.discussed eq true }">checked="checked"</c:if> />
												<label for="patientDiscussed" class="meetingActionAndReponseLabel">Patient has been discussed in this meeting</label>
												<div class="meetingActionAndReponseLabel">Actions from Meeting:</div>
												<textarea name="meetingItemAction" cols="100"
													rows="5"><c:out value="${item.meetingItemAction}"/></textarea>
													
												<div>
													<input type="checkbox" id="meetingItemActionCompleted" name="meetingItemActionCompleted" <c:if test="${item.meetingItemActionCompleted ne null and item.meetingItemActionCompleted eq true }">checked="checked"</c:if> />
													<label for="meetingItemActionCompleted" class="meetingActionAndReponseLabel"> These Actions have been Completed</label>
												</div>
												<div style="margin-top: 0.5em;">
													<input type="submit" id="actionSubmit" value="Save actions" />
													<img id="actionSpinner" src="../images/ajax-loader-bl.gif" style="display: none;"/>
												</div>
											</smvc:form>
										</div>
									</sec:authorize>
									</c:if>
									<!--  Meeting response and other things will be added here( end ) -->
									
								</c:when>
								<c:otherwise>
									<span class="warning"
										style="margin-left: auto; margin-right: auto;">You
										don't have permission to view this patient.</span>
								</c:otherwise>
							</c:choose>
							
							 <br /> <br />


							<div class="meetingNavigationPanel">
								<table>
									<tr>
										<th>Meeting actions</th>
										<th>Attendee actions</th>
										<th>Patient actions</th>
									</tr>
									<tr>
										<td><a href="printPatientsInCurrentMeeting.jsp"
											target="_blank">Print Meeting <img
												src="../images/16x16/bullet_go.png" />
										</a> <br /> <br /> <a href="setMeetingFilter.form?filterId=0">Select
												Another Meeting <img src="../images/16x16/bullet_go.png" />
										</a> <br /> <br /> <sec:authorize
												access="hasAnyRole('MEETING_ADMIN','ADMIN')">
												<a
													href="createAndEditMeeting.form?action=edit">Edit
													Meeting <img src="../images/16x16/bullet_go.png" />
												</a>
												<br />
												<br />
												<c:if test="${emdt.currentMeeting.locked eq 'false'}">
													<c:if
														test="${emdt.currentMeeting.id gt 0 and emdt.currentMeeting.pastMeeting eq 'true'}">
														<a href="javaScript:confirmLockMeeting();">Lock
															Meeting <img src="../images/16x16/bullet_go.png" />
														</a>
														<br />
														<br />
													</c:if>
												</c:if>
											</sec:authorize> <a
											href="closeMeeting.form">Close
												Meeting <img src="../images/16x16/bullet_go.png" />
										</a> <br /> <br /></td>

										<td><sec:authorize
												access="hasAnyRole('MEETING_ADMIN','ADMIN')">

												<a href="viewMeetingAttendee.form">Change
													or Invite Attendees <img
													src="../images/16x16/bullet_go.png" />
												</a>
												<br />
												<br />
												<a href="editMeetingFollowupMails.form">Post-Meeting
													Follow Ups <img src="../images/16x16/bullet_go.png" />
												</a>
												<br />
												<br />

											</sec:authorize></td>

										<td><c:if
												test="${emdt.currentMeeting.currentItem.patientDiscussed != null}">
												<a href="printPatientMeetingReport.jsp" target="_blank">Print
													meeting report for this patient <img
													src="../images/16x16/bullet_go.png" />
												</a>
												<br />
												<br />
												<a href="patientMeetingHistoryReport.form?patient=${emdt.currentMeeting.currentItem.patientDiscussed.guid}" target="_blank">All
													meetings involving this patient <img
													src="../images/16x16/bullet_go.png" />
												</a>
												<br />
												<br />
											</c:if> <sec:authorize access="hasAnyRole('MEETING_ADMIN','ADMIN')">
												<a href="addMeetingPatients.form">Change
													Patients <img src="../images/16x16/bullet_go.png" />
												</a>
												<br />
												<br />
												<c:choose>
													<c:when
														test="${requestScope.message ne null and requestScope.message eq 'There are no patients in this meeting.'}">
													</c:when>
													<c:otherwise>
														<a href="reOrderMeetingItems.jsp">Change Patient
															Order <img src="../images/16x16/bullet_go.png" />
														</a>
													</c:otherwise>
												</c:choose>
											</sec:authorize></td>
									</tr>

								</table>
							</div> <br /></td>
					</tr>
				</table>

			</div>
		</td>
	</tr>
</table>

<!-- Actions and Responses AJAX handlers -->
<script type="text/javascript">

$("#meetingItemResponseForm").on("submit", function (e) {
	console.log('on submit form - start');
    e.preventDefault();
	// enable button, hide progress indicator
	$('#responseSubmit').prop('disabled', true);
	$('#responseSpinner').show();

    updateResponse();
    
	// enable button, hide progress indicator
	$('#responseSubmit').prop('disabled', false);
	$('#responseSpinner').hide();

	console.log('on submit form - finished');
	return false;
});

function updateResponse () {
	console.log("update response()");
	var csrfdata=document.getElementById("csrfparameterName").value;
	csrfdata=csrfdata+"="+document.getElementById("csrfparametervalue").value;
	$.ajax({
		type : "POST",
		method : "POST",
		data : $("#meetingItemResponseForm").serialize(),
		url : "updateResponse.form?" + csrfdata,
		success : function(msg) {
			//show response sent message
			console.log("ajax success");
			showActionResponseSuccessMessage ("#responseMessage", msg.responseMessage);
			var saveButton = document.getElementById('saveDataButton');
			if(saveButton==null || (saveButton && saveButton.style.border != '1px dashed red'))
				unsavedData=false;
		},
		error: function(msg){
			console.log('ajax error: ' + msg);
			showActionResponseSuccessMessage ("#responseMessage", "There was a problem updating the response");
		}
	});
	console.log("after update response()");
}

function showActionResponseSuccessMessage(control, message)	{
	$(control).empty();
	$(control).append('<span class="info">' + message + '</span>');
}

$("#meetingItemActionForm").on("submit", function (e) {
	console.log('on submit form - start');
    e.preventDefault();
	// enable button, hide progress indicator
	$('#actionSubmit').prop('disabled', true);
	$('#actionSpinner').show();

    updateAction();
    
	// enable button, hide progress indicator
	$('#actionSubmit').prop('disabled', false);
	$('#actionSpinner').hide();

	console.log('on submit form - finished');
	return false;
});


function updateAction() {
	console.log("updateAction()");
	var csrfdata=document.getElementById("csrfparameterName").value;
	csrfdata=csrfdata+"="+document.getElementById("csrfparametervalue").value;
	$.ajax({
		type : "POST",
		method : "POST",
		data : $("#meetingItemActionForm").serialize(),
		url : "updateAction.form?" + csrfdata,
		success : function(msg) {
			//show response sent message
			console.log("ajax success");
			showActionResponseSuccessMessage ("#actionMessage", msg.actionMessage);
			var saveButton = document.getElementById('saveDataButton');
			if(saveButton==null || (saveButton && saveButton.style.border != '1px dashed red'))
				unsavedData=false;
		},
		error: function(msg){
			console.log('ajax error: ' + msg);
			showActionResponseSuccessMessage ("#actionMessage", "There was a problem updating the action");
		}
	});
	console.log("after updateAction()");
}
// change patient select handler
$("#patients").on("change", function (el) {
	if (!dataGuard())	{
		// reselect previous patient
		$("#patients").val( $("#currentSelectedPatient").val() );
		$("#patients").blur();
		return;
	}
	var ptid = $("#patients").val();
	fullScreenPleaseWait();
	document.location = 'selectMeetingItem.form?itemId=' + ptid;
});

</script>
