<%@ 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() {
		document.getElementById('actionRequired').value = "SAVE";
		document.forms[0].submit();
	}
	function sendReferral() {
		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) {
			document.getElementById('actionRequired').value = "DELETE";
			document.forms[0].submit();
			return true;
		} else {
			return false;
		}
	}
</script>
<c:if test="${emdt.currentCareSpell ne null and emdt.currentCareSpell.patient.id ne null}">
	<div class="header2">
		<div class="smallBlueDiv">&nbsp;</div>
		<div class="mediumBlueDiv">
			&nbsp; <label class="labelBlue">Patient:</label> <span class="labelBrown"><c:out value="${emdt.currentCareSpell.patient.forename}"/>&nbsp;<c:out value="${emdt.currentCareSpell.patient.surname }"/></span>
		</div>
		<div class="smallBlueDiv">&nbsp;</div>

		<c:set var="date" value="${emdt.currentCareSpell.patient.dateOfBirth}"></c:set>
		<div class="mediumBlueDiv">
			&nbsp; <label class="labelBlue">DOB:</label><span class="labelBrown"> <fmt:formatDate value="${emdt.currentCareSpell.patient.dateOfBirth}" pattern="MM/dd/yyyy" />
			</span>
		</div>
		<div class="smallBlueDiv">&nbsp;</div>
		<div class="mediumBlueDiv">
			&nbsp; <label class="labelBlue">NHS Number:</label> <span class="labelBrown"><c:out value="${emdt.currentCareSpell.patient.nhsNumber}"/></span>
		</div>
		<div class="smallBlueDiv">&nbsp;</div>
	</div>
</c:if>
<smvc:form name="referralsSummaryForm" method="post" action="referralssummary.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 ="/referrals/tiles/referralsFormMenu.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</strong> <br />
					<br />
					<div class="fieldSetBoxBlue">
						<strong>You have entered these forms:</strong> <br />
						<c:if test="${fn:length(summaryModel.enteredFormNames) == 0}">
							<br />No information entered. Please provide necessary information.
         	</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">
							<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="menuButtonHolderPinkLong1" onclick="sendReferral();" style="padding-top: 15px;">
									Refer Patient To <br /><c:out value="${centralHubHospital.hospitalName}"/><br />
								</div>
							</c:when>
							<c:otherwise>
								<div class="menuButtonHolderPinkLong1" style="cursor: default; color: gray; padding-top: 15px;" title="This patient cannot be referred yet, due to incomplete information">
									Refer Patient To <br /><c:out value="${centralHubHospital.hospitalName}"/><br />
								</div>
							</c:otherwise>
						</c:choose>
						<br />
						<div class="menuButtonHolderPinkLong1" onclick="saveAndEdit();" style="padding-top: 12px;" title="Save this draft referral to Unsent Referrals folder">
							<br />Save And Edit Later
						</div>
						<br />
						<c:choose>
							<c:when test="${allowDeleteReferrals == true}">
								<div class="menuButtonHolderPinkLong1" onclick="return deleteReferral();" style="padding-top: 12px;" title="Cancel referral and also permanently delete all details for this patient">
									<br/>Delete this Referral
								</div>
							</c:when>
							<c:otherwise>
								<div class="menuButtonHolderPinkLong1" style="padding-top: 12px; cursor: default; color: gray;" title="Action not permitted">
									<br/>Delete this Referral
								</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}">
						<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>
							</c:if>


						</div>
						<div class="middleBox">
							<div class="centerDivRed">
								Please note that a referral <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>
				<c:if test="${fn:length(summaryModel.groupsToBeEnteredFormNames) != 0}">
						<br/>

						<div class="fieldSetBoxRed">
							<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>
						</div>
				</c:if>
				<div style="height: 10%; float: left; width: 100%">
					<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>