<%@page import="java.util.List"%>
<%@page import="com.ardeo.entities.autoforms.ValueData"%>
<%@ include file="/includes.jsp"%>
<c:set var="definition" value="${emdt.currentForm}"/>
<jsp:useBean id="helper" scope="page"
	class="com.ardeo.autoforms.FileUploadDispatcher" />
<head>
<title>Print Form</title>
<link rel="stylesheet" href="../webapp.css" type="text/css" />
<link rel="stylesheet" href="archiveFormView.css" type="text/css" />
<c:if test="${not empty definition.colourCode}">
	<style>
		.formBgColor {
			background-color:${definition.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="${definition.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="${consultationNoteForm.view.note.id}"/></td>
			</tr>
			<tr>
				<td class="printFormDefinitionPropertyName">Description:</td>
				<td class="printFormDefinitionPropertyValue"><c:out value="${definition.description}"/></td>
			</tr>
			<tr>
				<td class="printFormDefinitionPropertyName">Date Created:</td>
				<td class="printFormDefinitionPropertyValue">
					<fmt:formatDate value="${ formView.note.creationDate}" pattern="dd/MM/yyyy HH:mm" />
				</td>
			</tr>
			<tr>
				<td class="printFormDefinitionPropertyName">Date Last Modified:</td>
				<td class="printFormDefinitionPropertyValue">
					<fmt:formatDate value="${ formView.note.modifiedDate}" 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:if test="${definition.children ne null }">
<c:forEach var="pge" items="${definition.children }">
	<%com.ardeo.entities.autoforms.FormPage pge=(com.ardeo.entities.autoforms.FormPage)pageContext.getAttribute("pge"); %>
	<div>
	<div class="printFormPage" align="left">
	<div class="printFormPageTitle formBgColor"><c:out value="${pge.label}"/></div>
	<c:if test="${pge.children ne null }">
	<c:forEach var="section" items="${pge.children }">
	<%com.ardeo.entities.autoforms.FormSection section=(com.ardeo.entities.autoforms.FormSection)pageContext.getAttribute("section"); %>
		<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:if test="${section.children ne null }">
				<c:forEach var="field" items="${section.children }">
				<%com.ardeo.entities.autoforms.FormField field=(com.ardeo.entities.autoforms.FormField)pageContext.getAttribute("field"); %>
				<tr>
					<td class="printFormFieldLabel">&nbsp;&nbsp;<c:out value="${field.label}"/></td>
					<td class="printFormFieldValue">
					<c:if test="${field.optionsMapName ne null }">
						<% com.ardeo.entities.autoforms.FormView formView=(com.ardeo.entities.autoforms.FormView)pageContext.getAttribute("formView");
							ValueData[] vdArray=formView.getNote().getValueArray(field.getName());
						%>
						<c:set var="vdArray" value="<%=vdArray%>"></c:set>
						<c:if test="${vdArray ne null }">
							<c:forEach var="val"  items="formView.'<%="note.valueArray(" + field.getName() + ")"%>'>
								<div><webapp:listValue domain="EMDT" listName="${field.optionsMapName}" key="${val}" /></div>
							</c:forEach>
						</c:if>
					</c:if>
					<c:if test="${field.optionsMapName eq null }">
						<% com.ardeo.entities.autoforms.FormView formView=(com.ardeo.entities.autoforms.FormView)pageContext.getAttribute("formView");
							String delim = helper.SEARCH_DELIMITER;
							Integer id = formView.getNote().getId();
							String fieldName = field.getName();
							String  patientGuid=(String)pageContext.getAttribute("patientGuid");
							List<com.ardeo.entities.PatientDocumentMetaData> patientDocumentMetaDataList=helper.getFileNamesList(id,fieldName,patientGuid);
							String  hasPatientDocument="false";
							if(patientDocumentMetaDataList!=null && patientDocumentMetaDataList.size()>0)
								hasPatientDocument="true";
						%>
						<c:choose>
							<c:when test="${field.inputType eq 9}">
								<c:set var="hasPatientDocument" value="<%=hasPatientDocument%>"/>
								<c:if test="${hasPatientDocument eq 'true'}"> 
								<c:forEach var="patientDocumentMetaData" items="<%=patientDocumentMetaDataList%>">
									<tr>
										<td>
										<%
											int dotIndex = ((String) pageContext .getAttribute("filesName")).lastIndexOf(".");
										%> 
										<c:set var="dotIndex" value="<%=dotIndex%>" /> 
									    <c:set var="displayFile" value="${fn:substring(filesName, 0, dotIndex-21)}" /> 
										<c:set var="displayExt" value="${fn:substring(filesName, dotIndex, fn:length(filesName))}" />
										<td><c:out value="${displayFile}"/><c:out value="${displayExt}"/>&nbsp;</td> 

									</tr></c:forEach></c:if>
							
							</c:when>
							<c:otherwise>
							<c:if test="${field.optionsMapName eq null }">
								<% ValueData[] vdArray=formView.getNote().getValueArray(field.getName()); %>
								<c:set var="vdArray" value="<%=vdArray%>"></c:set>
								<c:if test="${vdArray ne null }">
								<webapp:iterate id="val" name="formView" property='<%="note.valueArray(" + field.getName() + ")"%>'>
									<div><c:out value="${val}"/></div>
								</webapp:iterate>
							</c:if>
								</c:if>
							</c:otherwise>
				</c:choose></c:if>
			</td></tr>
		</table>
		</div>
	</c:forEach></c:if></div>
	</div>
</c:forEach></c:if></div>
</div>
</body>
