<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>

<%@page import="com.ardeo.util.PropertiesUtils"%>
<%@page import="java.util.Properties"%>
<%@ include file="/includes.jsp"%>
<script type="text/javascript">
function changeReport(){
 document.location.href = '../emdt/patientCommentsReport.form?dateRange='+document.getElementById('dateRange').value;
}
function submitForm(action,fileName){
	document.getElementById("actionRequired").value=action;
	document.getElementById("fileName").value=fileName;
	document.getElementById("fileaction").submit();
}

</script>
<smvc:form action="fileAction.form?${_csrf.parameterName}=${_csrf.token}" method="post" enctype="multipart/form-data" modelAttribute="fileUploadForm" id="fileaction">
	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
	<input type="hidden" name="fileName" id="fileName"/>
	<input type="hidden" name="actionRequired" id="actionRequired"/>
</smvc:form>

<table width="80%" align="center">
    <tr height="50px"><td></td></tr>
	<tr>
		<td><b>Show:&nbsp;&nbsp;</b><select id="dateRange" onchange="changeReport()">
			<c:choose>
				<c:when test="${dateRange eq 'All'}"><option selected="selected" value="All">All</option></c:when>
				<c:otherwise><option value="All">All</option></c:otherwise>
			</c:choose>
				<c:choose>
				<c:when test="${dateRange eq 'Today'}"><option selected="selected" value="Today">Today</option></c:when>
				<c:otherwise><option value="Today">Today</option></c:otherwise>
			</c:choose>
				<c:choose>
				<c:when test="${dateRange eq 'Week'}"><option selected="selected" value="Week">Week</option></c:when>
				<c:otherwise><option value="Week">Week</option></c:otherwise>
			</c:choose>
				<c:choose>
				<c:when test="${dateRange eq 'Month'}"><option selected="selected" value="All">Month</option></c:when>
				<c:otherwise><option value="Month">Month</option></c:otherwise>
			</c:choose>
		</select></td>
	</tr>
	<tr height="10px"><td></td></tr>
</table>
<table width="90%" cellspacing="0" class="table" align="center">
	<tr class="tableHeader">
		<th class="tableColHeader" width="8%">Date</th>
		<th class="tableColHeader" width="10%">User Name</th>
		<th class="tableColHeader" width="10%">Patient Name</th>
		<th class="tableColHeader" width="10%">Form</th>
		<th class="tableColHeader" width="38%">Comment</th>
		<th class="tableColHeader" width="10%">Link</th>
		<th class="tableColHeader" width="10%">Attached Notes</th>
	</tr>
	<c:choose>
		<c:when
			test="${(commentsReportDTO.commentDTOList ne null) and (fn:length(commentsReportDTO.commentDTOList) gt 0)}">
			<c:forEach var="commentsDTO" items="${commentsReportDTO.commentDTOList}" varStatus="s1">
				<c:set var="rowClass"
					value="${s1.count % 2 == 0 ? 'evenRow' : 'oddRow'}" />
				<tr class="<c:out value="${rowClass}"/>">
					<td class="tableCell" ><fmt:formatDate
						value="${commentsDTO.dateOfComment}" pattern="dd MMM yyyy HH:mm"  /></td>
					<td class="tableCell"><c:out value="${commentsDTO.username }"/></td>
					<td class="tableCell"><c:out value="${commentsDTO.patientName }"/></td>
					<td class="tableCell"><c:out value="${commentsDTO.formLable}"/></td>
					<td class="tableCell"><pre><c:out value="${commentsDTO.comment }"/></pre></td>
					<td class="tableCell" align="center">
						<c:choose>
							<c:when test="${commentsDTO.consultationNoteGuid ne null }">
								<img src="../images/16x16/information.png" onmouseover="this.style.cursor = cursorPointer" onclick="document.location.href ='../emdt/consultationNote.form?conNoteId=<c:out value="${commentsDTO.consultationNoteGuid}"/>';">
							</c:when>
							<c:otherwise>
								<img src="../images/16x16/information.png" onmouseover="this.style.cursor = cursorPointer" onclick="document.location.href ='../emdt/viewPatient.form?patientId=<c:out value="${commentsDTO.patientGuid}"/>';">
							</c:otherwise>
						</c:choose>

						</td>
				<td class="tableCell">
					<c:if test="${not empty(commentsDTO.attachedNotes)}">
						<c:set var="actualfileName" value="${commentsDTO.attachedNotes}"></c:set>
						<a href="#" onclick="javascript:submitForm('commentsFileView','${fn:replace(commentsDTO.attachedNotes, "\'", "\\\'" ) }');"  title="Click to View or download file">
						<img src="../images/16x16/page.png" alt="Document" /> 
						<%int dotIndex =  ((String)pageContext.getAttribute("actualfileName")).lastIndexOf(".");%>
						<%int underScoreIndex =  ((String)pageContext.getAttribute("actualfileName")).indexOf("_Cnid");%>
						<c:set var="dotIndex" value="<%=dotIndex%>" /> 
						<c:set var="underScoreIndex" value="<%=underScoreIndex%>" /> 
						<c:out value="${fn:substring(commentsDTO.attachedNotes, 0, underScoreIndex)}${fn:substring(commentsDTO.attachedNotes, dotIndex, fn:length(commentsDTO.attachedNotes))}" />
						</a>
					</c:if>
				</td>
				</tr>
			</c:forEach>
		</c:when>
		<c:otherwise>
			<tr>
				<td align="center" class="message" colspan="10">No Comments
				Found</td>
			</tr>
		</c:otherwise>
	</c:choose>

	<tr class="tableFooter">
		<td colspan="10" align="left">&nbsp;</td>
	</tr>
</table>

<br/>