<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<script src="../js/jquery/jquery-3.7.1.min.js"></script>
<script src="../js/AJAXSupport.js" type="text/javascript"></script>
<link rel="stylesheet" href="../css/popup.css" type="text/css" />
<script>
	function saveAndEdit() {
        fullScreenPleaseWait();
        document.getElementById('actionRequired').value = "SAVE";
		document.forms[0].submit();
	}
	function sendReferral() {
        fullScreenPleaseWait();
		document.getElementById('actionRequired').value = "SEND";
		document.forms[0].submit();
	}
	function fnDisplay_Computers(filePath) {
		window.open(filePath, "mywindow");
	}
	function deleteReferral() {
		var confirmed;
		confirmed = confirm("Deleting the patient referral will cause all data entered for this patient referral to be deleted. Please confirm that this is what you want.");
		if (confirmed) {
            fullScreenPleaseWait();
            document.getElementById('actionRequired').value = "DELETE";
			document.forms[0].submit();
			return true;
		} else {
			return false;
		}
	}
</script>
	<c:if test="${referralPatientDto.referralPatient ne null and referralPatientDto.referralPatient.id ne null}">
		<table class="header1" border="1" bordercolor="#F8F8FF">
			<tr>
				<td width="10%" align="center"><c:choose>
					<c:when test="${previousPatientId!=null}">
						<img src="../images/backward.png" title="previous Patient"
							 onclick="setNavigatePatient(<c:out value="${previousPatientId}"/>);"
							 onmouseover="this.style.cursor = cursorPointer" />
					</c:when>
					<c:otherwise>
						<input type="image" src="../images/disabled_back.png"
							   title="First Patient" onclick=""
							   onmouseover="this.style.cursor = cursorPointer" disabled="disabled" />
					</c:otherwise>
				</c:choose></td>
				<td width="30%">&nbsp; <label class="labelBlue">Patient:</label> <span
						class="labelBrown"><c:out value="${referralPatientDto.referralPatient.forename}"/>&nbsp;<c:out value="${referralPatientDto.referralPatient.surname }"/></span></td>
				<td width="20%">&nbsp; <label class="labelBlue">DOB:</label> <span
						class="labelBrown"><c:out value="${referralPatientDto.strDateOfBirth}"/></span></td>
				<td width="10%" >&nbsp; <label class="labelBlue">Age:</label> <span
						class="labelBrown"><c:out value="${referralPatientDto.referralPatient.currentAge}"/></span></td>
				<td width="20%">&nbsp; <label class="labelBlue">GP:</label> <span
						class="labelBrown"><c:out value="${referralPatientDto.referralPatient.gpForename}"/>&nbsp;
						<c:out value="${referralPatientDto.referralPatient.gpSurname}"/></span></td>
				<td width="10%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <c:choose>
					<c:when test="${nextPatientId!=null}">
						<img src="../images/forward.png" title="next Patient"
							 onclick="setNavigatePatient(<c:out value="${nextPatientId}"/>);"
							 onmouseover="this.style.cursor = cursorPointer" />
					</c:when>
					<c:otherwise>
						<input type="image" src="../images/disabled_forward.png"
							   title="Last Patient"
							   onmouseover="this.style.cursor = cursorPointer" disabled="disabled" />
					</c:otherwise>
				</c:choose></td>

			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp; <label class="labelBlue">Submitting Hospital:</label> <span
						class="labelBrown"><c:out value="${referralPatientDto.referralPatient.referredHospitalName
						}"/></span></td>
				<td colspan="2">&nbsp; <label class="labelBlue">Hospital Number:</label> <span
						class="labelBrown"><c:out value="${referralPatientDto.referralPatient.hospitalNumber
						}"/></span></td>
				<td>&nbsp; <label class="labelBlue"></label></td>
				<td>&nbsp;</td>
			</tr>
		</table>
	</c:if>

<div class="rowSpacer" style="height:15px">
	&nbsp;
</div>
<smvc:form name="referralsSummaryForm" method="post" action="nmdmReferralssummary.form" onsubmit="return submitTheForm();">
<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
	<input type="hidden" name="actionRequired" id="actionRequired" />
	<div class="largeContainer" style="height: 100%">
		<div class="container" style="height: 90%">
			<tiles:insertTemplate template ="/nationalMDT/tiles/nationalMDTFormMenu.jsp" ></tiles:insertTemplate>
			<div class="bodySection">
				<div>
					<c:choose>
						<c:when test="${requestScope.successMsg != null || requestScope.errorMsg != null}">
							<c:if test="${requestScope.successMsg != null}">
								<div class="message">
									<img src="../images/16x16/information.png" alt="i" /> <c:out value="${requestScope.successMsg}"/>
								</div>
							</c:if>
							<c:if test="${requestScope.errorMsg != null}">
								<div class="error">
									<img src="../images/16x16/error.png" alt="!" border="0" />&nbsp;&nbsp;<c:out value="${requestScope.errorMsg}"/>
								</div>
								<br />
							</c:if>
						</c:when>
						<c:otherwise>
							<div class="rowSpacer">&nbsp;</div>
						</c:otherwise>
					</c:choose>
				</div>
				<div class="rowDivSubPage">
					<strong>Progress/Activity Summary: <c:out value="${summaryModel.pathwayTitle}"/></strong> <br />
					<br />
					<div class="fieldSetBoxBlue">
						<strong>You have entered these forms:</strong> <br />
						<c:if test="${fn:length(summaryModel.enteredFormNames) == 0}">
							<br />No forms entered.
         	</c:if>
						<br />
						<c:if test="${fn:length(summaryModel.enteredFormNames)!= 0}">
							<c:forEach var="enteredFormName" items="${summaryModel.enteredFormNames }">
								<img src="../images/16x16/tick.png" alt="i" /> <c:out value="${enteredFormName}"/><br />
							</c:forEach>
						</c:if>
					</div>

					<div class="middleBox">
						<div class="fieldSetBoxBlue1" style="display:none;">
							<b>Request Image Transfer</b> <br />
							<br />
							<br /> Choose Method:<br /> <br />
							<select name="imgTransferMethods" id="imgTransferMethods" class="selectBox">
								<c:forEach items="${summaryModel.imageTransferMethods}" var="transferMethod">
									<c:choose>
										<c:when test="${transferMethod.isPreferred}">
											<option selected="selected" value="<c:out value="${transferMethod.imgTansMethod.imgTransCode}"/>"><c:out value="${transferMethod.imgTansMethod.description}"/></option>
										</c:when>
										<c:otherwise>
											<option value="<c:out value="${transferMethod.imgTansMethod.imgTransCode}"/>"><c:out value="${transferMethod.imgTansMethod.description}"/></option>
										</c:otherwise>
									</c:choose>

								</c:forEach>
							</select>
						</div>
					</div>
					<div class="fieldSetBoxBlue2">
						<c:choose>
							<c:when test="${fn:length(summaryModel.toBeEnteredFormNames) == 0 && fn:length(summaryModel.groupsToBeEnteredFormNames) == 0}">
								<div class="menuButtonRectLarge pink" onclick="javascript:sendReferral()">
									<br /><br />Finish Submission
								</div>
							</c:when>
							<c:otherwise>
								<div class="menuButtonRectLarge pink" style="cursor: not-allowed; color: grey;" title="This patient cannot be referred yet, due to incomplete information">
									<br /><br />Finish Submission
								</div>
							</c:otherwise>
						</c:choose>
						<br />
						<div class="menuButtonRectLarge blue" title="Save this draft referral to Unsent Referrals folder"  onclick="javascript:saveAndEdit()">
							<br /><br />Save And Edit Later
						</div>
						<br />
						<c:choose>
							<c:when test="${allowDeleteReferrals == true}">
								<div class="menuButtonRectLarge blue" title="Cancel referral and also permanently delete all details for this patient" onclick="javascript:deleteReferral()">
									<br /><br />Delete this Submission 
								</div>
							</c:when>
							<c:otherwise>
								<div class="menuButtonRectLarge blue" style="cursor: not-allowed; color: grey;" title="Action not permitted">
									<br /><br />Delete this Submission
								</div>
							</c:otherwise>
						</c:choose>
					</div>
				</div>
				<c:if test="${fn:length(summaryModel.toBeEnteredFormNames) == 0 && fn:length(summaryModel.groupsToBeEnteredFormNames) == 0}">
						<div class="fieldSetBoxGreen">
							<br /> <br />All information entered.
						</div>
						<div>&nbsp;</div>
				</c:if>
				<c:if test="${(fn:length(summaryModel.toBeEnteredFormNames) != 0) or (fn:length(summaryModel.groupsToBeEnteredFormNames) != 0)}">
						<div class="fieldSetBoxRed">
							<c:if test="${fn:length(summaryModel.toBeEnteredFormNames) != 0}">
								<strong>You have not yet entered the following forms:</strong>
								<br />
								<br />
								<c:forEach var="toBeEnteredFormName" items="${summaryModel.toBeEnteredFormNames }">
									<img src="../images/16x16/cross.png" alt="i" /> <c:out value="${toBeEnteredFormName}"/> (Mandatory) <br />
								</c:forEach>
								<br/>
							</c:if>

							<c:if test="${fn:length(summaryModel.groupsToBeEnteredFormNames) != 0}">
								<strong> At the least one form should be entered under the following groups:</strong> <br />
								<br />
								<c:forEach var="groupsToBeEnteredFormName" items="${summaryModel.groupsToBeEnteredFormNames }">
									<img src="../images/16x16/cross.png" alt="i" /> <c:out value="${groupsToBeEnteredFormName}"/> <br />
								</c:forEach>
							</c:if>
			

						</div>
						<div class="middleBox">
							<div class="centerDivRed">
								Please note that a submission<br />cannot be sent unless the <br />record includes all the Mandatory forms. <br />Please contact us directly if you have any queries with this
								patient. <br />Thank you.
							</div>
						</div>
				</c:if>
				<div style="height: 10%; float: left; width: 100%;display:none;">
					<br />
					<br />
					<div align="center">
						<strong>Notes about your submission</strong>
					</div>
					<div>
						<textarea name="notes" class="txtArea" rows="8"><c:out value="${summaryModel.notes}"/></textarea>
					</div>
				</div>
			</div>
		</div>
	</div>
</smvc:form>