<%@ include file="/includes.jsp" %>
<jsp:useBean id="helper" scope="page" class="com.ardeo.autoforms.FileUploadDispatcher"/>
<html >
	<head>
		<title>Print Form</title>
		<link rel="stylesheet" href="../css/webapp.css" type="text/css" />
		<link rel="stylesheet" href="printForm.css" type="text/css" />
		<c:if test="${not empty emdt.currentForm.colourCode}">
			<style>
				.formBgColor {
					background-color: ${emdt.currentForm.colourCode}
				}
			</style>
		</c:if>
	</head>
	<body onload="window.print()">
		<div class="printFormPart" align="center">
			<div class="printFormDefinition" align="left">
				<div class="printFormDefinitionTitle formBgColor">
					<c:out value="${emdt.currentForm.label}"/> 
				</div>
				<table border="0" width="100%">
					<tr>
						<td width="50%">
							<table width="100%">
								<tr>
									<td class="printFormDefinitionPropertyName">id:</td>
									<td class="printFormDefinitionPropertyValue"><c:out value="${printNote.id }"/></td>
								</tr>
								<tr>
									<td class="printFormDefinitionPropertyName">Description:</td>
									<td class="printFormDefinitionPropertyValue"><c:out value="${emdt.currentForm.description}"/></td>
								</tr>
								<tr>
									<td class="printFormDefinitionPropertyName">Date Created:</td>
									<td class="printFormDefinitionPropertyValue"><fmt:formatDate value="${printNote.creationDate }" type="date" pattern="dd/MM/yyyy HH:mm" /></td>
								</tr>
								<tr>
									<td class="printFormDefinitionPropertyName">Date Last Modified:</td>
									<td class="printFormDefinitionPropertyValue"><fmt:formatDate value="${printNote.modifiedDate }" type="date" pattern="dd/MM/yyyy HH:mm" /></td>
								</tr>
							</table>
						</td>
						<td width="50%">
							<table width="100%">
								<tr>
									<td class="printFormDefinitionPropertyName">Patient Name:</td>
									<td class="printFormDefinitionPropertyValue"><c:out value="${emdt.patient.forename}"/> <c:out value="${emdt.patient.surname}"/></td>
								</tr>
								<tr>
									<td class="printFormDefinitionPropertyName">Hospital Number:</td>
									<td class="printFormDefinitionPropertyValue"><c:out value="${emdt.patient.hospitalNumber}"/></td>
								</tr>
								<tr>
									<td class="printFormDefinitionPropertyName">NHS Number:</td>
									<td class="printFormDefinitionPropertyValue"><c:out value="${emdt.patient.nhsNumber}"/></td>
								</tr>
								<tr>
									<td class="printFormDefinitionPropertyName">Date of Birth:</td>
									<td class="printFormDefinitionPropertyValue"><fmt:formatDate value="${emdt.patient.dateOfBirth}" pattern="dd/MM/yyyy"/></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
				<br/>
				<br/>
				<c:forEach var="pge" items="${emdt.currentForm.children }">
					<div >
						<div class="printFormPage" align="left">
							<div class="printFormPageTitle formBgColor">
								<c:out value="${pge.label}"/>
							</div>
							<c:forEach var="section" items="${pge.children }">
								<div class="printFormPart" align="center">
									<table class="printFormDefintionSection" cellspacing="0">
										<tr>
											<td colspan="2" class="printFormDefintionSectionTitle formBgColor">
												<c:out value="${section.label}"/>
											</td>
										</tr>
										<c:forEach var="field" items="${section.children }">
											<tr>
												<td class="printFormFieldLabel">&nbsp;&nbsp;<c:out value="${field.label}"/></td>
												<td class="printFormFieldValue">
										<c:forEach var="value" items="${printNote.values[field.name].valueArray }">
										<c:choose>
											<c:when test="${field.inputType eq 5}">
												<webapp:listValue listName="${field.optionsMapName }" key="${value.code }" domain="${field.optionsMapDomain }"></webapp:listValue>
											</c:when>
											<c:when test="${field.inputType eq 9}">
												
												<c:forTokens var="filesName" items="${value.code }" delims="|" varStatus="status">

												<c:set var="dotIndex" value="${fn:indexOf(filesName, '.') }"/>
												<c:set var="displayFile" value="${fn:substring(filesName, 37, dotIndex-21)}"/>
												<c:set var="displayExt" value="${fn:substring(filesName, dotIndex, fn:length(filesName))}"/>
												<img src="../images/16x16/page.png" alt="Document" /> <c:out value="${displayFile}"></c:out><c:out value="${displayExt}"></c:out><br/>

												</c:forTokens>
											</c:when>
											<c:otherwise>
												<%-- this hack is to avoid an issue with vertical alignment when PRE tags are rendered in PDFs.  I'm using a DIV instead and searching and replacing newlines with BR tags --%>
												<c:set var="newline" value="<%='\n'%>" />
												<div style="vertical-align: top;">${fn:replace(value.code, newline, "<br/>") }</div>
											</c:otherwise>
										</c:choose>
										</c:forEach>
											<%-- special case for metadata fields.  TODO one day we should use the standard FieldRendererX.jsp for this - this is duplicating code --%>
										<c:if test="${(field.inputType eq 10) and (field.fieldType eq 101)}">
											<c:out value="${printNote.createdByUser.name}"/>
										</c:if>
										<c:if test="${field.inputType eq 10 and field.fieldType eq 102}">
											<c:out value="${printNote.modifiedByUser.name}"/>
										</c:if>
										<c:if test="${field.inputType eq 10 and field.fieldType eq 103}">
											<fmt:formatDate value="${printNote.creationDate}" pattern="dd MMM yyyy HH:mm"/>
										</c:if>
										<c:if test="${field.inputType eq 10 and field.fieldType eq 104}">
										<fmt:formatDate value="${printNote.modifiedDate}" pattern="dd MMM yyyy HH:mm"/>
										</c:if>
												</td>
											</tr>
										</c:forEach>
									</table>
								</div>
							</c:forEach>
						</div>
					</div>
				</c:forEach>
				<div>
				<h4>Notes</h4>
				<c:choose>
					<c:when test="${empty commentsList}">
						(none)
					</c:when>
					<c:otherwise>
					<table>
						<c:forEach items="${commentsList}" var="comment" varStatus="c">
							<tr>
								<td colspan="3">
								<hr color="lightgray" size="1" />
								</td>
							</tr>
							<tr>
								<td width="20%" class="commentsUserName"><c:out value="${comment.username}"/><br/><c:out value="${comment.hospitalCode}"/></td>
								<td width="60%" class="commentsText"><pre><c:out value="${comment.comment}"/></pre></td>
								<td width="20%" class="commentsDate"><fmt:formatDate value="${comment.dateOfComment}" pattern="dd MMM yyyy, HH:mm" /></td>
							</tr>
							<tr>
								<td class="commentsText"><input type="hidden" name="fileName" id="fileName" /></td>
								<td class="commentsAttachments">
									<c:if test="${not empty comment.attachedNotes}">
									<img src="../images/16x16/page.png" alt="Document" /> <c:out value="${comment.attachedNotesOriginalName}"/>
									</c:if>
								</td>
								<td></td>
							</tr>
						</c:forEach>
						</table>
					</c:otherwise>				
				</c:choose>
				
				</div>
			</div>
		</div>
	</body>
	<% session.removeAttribute("commentsList"); %>
</html>