<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<c:set var="browser" value="${header['User-Agent']}" scope="page" />
<style>
select {
	min-width: 18px;
	width: 215px;
	max-width: 215px;
}
</style>
<script type="text/javascript">

function updateSpecialistFields(index){
	var id='tempSpecialityId'+index;
	var userString=document.getElementById(id).value;
	var mySplitResult = userString.split(",");
	var str=mySplitResult[0];
	var rest = str.substring(0, str.lastIndexOf(" ") + 1);
	var last = str.substring(str.lastIndexOf(" ") + 1, str.length);
	document.getElementById('referringSpecialistsurmane').value=rest;
	document.getElementById('referringSpecialistforename').value=last;
	document.getElementById('referringSpecialistemail').value=mySplitResult[1];
}
</script>
<c:if
	test="${referralPatientDto.currentCareSpell.referralsDefinition ne null || emdt.currentCareSpell.referralsDefinition ne null}">
	<c:choose>
		<c:when
			test="${referralPatientDto.currentCareSpell.referralsDefinition ne null}">
			<c:set var="referralsDefinition"
				value="${referralPatientDto.currentCareSpell.referralsDefinition}"></c:set>
		</c:when>
		<c:otherwise>
			<c:set var="referralsDefinition"
				value="${emdt.currentCareSpell.referralsDefinition}"></c:set>
		</c:otherwise>
	</c:choose>
</c:if>
<div class="rowDiv">
	<div class="fieldSetBoxRadios">
		<div class="legendBox"><c:out value="${centralHubHospital.hospitalName}"/>
			Clinicians</div>
		<div class="legendBoxWrapper">
			Submit To Clinician:
			<smvc:select path="selectedClinician" id="selectedClinician">
			<c:choose>
				<c:when test="${referralsDefinition ne null }">
					<c:forEach var="clinicians"	items="${referralsDefinition.clinicians}">
						<smvc:option value="${clinicians.username}"><c:out value="${clinicians.name}"/></smvc:option>
					</c:forEach>
				</c:when>
				<c:otherwise>
					<c:forEach var="managementClinicians" items="${webapp.allManagementClinicians}">
						<smvc:option value="${managementClinicians.username}"><c:out value="${managementClinicians.name}"/></smvc:option>
					</c:forEach>
				</c:otherwise>
			</c:choose>
			<smvc:option value="Any">Any</smvc:option>
			</smvc:select>
		</div>
	</div>
</div>

<div class="pdLeftColumn">
	<div class="fieldSetSectionHolder">

		<div class="fieldSetBox">
			<div class="legendBox">Patient Details</div>
			<div class="legendBoxWrapper">
				<div class="fieldSetLeftColumn">NHS Number</div>
				<div class="fieldSetRightColumn">
					<c:choose>
						<%-- Only show PAS lookup when in management mode --%>
						<c:when test="${webapp.roleManagement}">
							<smvc:input path="referralPatient.nhsNumber" id="nhsNumberId"
								onkeypress="if(event.keyCode == 13) lookUpPatient()" />
							<a href="javascript:lookUpPatient()"
								title="Look Up Patient By NHS number"><img
								src="../images/16x16/zoom.png" />
							</a>
						</c:when>
						<c:otherwise>
							<smvc:input path="referralPatient.nhsNumber" id="nhsNumberId" />
						</c:otherwise>
					</c:choose>
				</div>
				<div class="fieldSetLeftColumn"><c:out value="${centralHubHospital.hospitalName}"/>
					Hospital Number</div>
				<div class="fieldSetRightColumnHT">
					<%-- Only allow edits to hub hospital number when in management mode --%>
					<c:choose>
						<c:when test="${webapp.roleManagement}">
							<smvc:input path="referralPatient.hospitalNumber" />
						</c:when>
						<c:otherwise>
							<smvc:input path="referralPatient.hospitalNumber" disabled="true"
								title='<c:out value="${centralHubHospital.hospitalName}"/> hospital number - not editable' />
						</c:otherwise>
					</c:choose>
				</div>


				<div class="fieldSetLeftColumn">Referring Hospital Number</div>
				<div class="fieldSetRightColumnHT">
					<%-- Only allow edits to referring hospital number when in referral mode --%>
					<c:choose>
						<c:when test="${webapp.roleReferrals}">
							<smvc:input
								path="currentCareSpell.referralDetails.referringHospitalNumber" />
						</c:when>
						<c:otherwise>
							<smvc:input
								path="currentCareSpell.referralDetails.referringHospitalNumber"
								readonly="true" title="Referring hospital number-not editable" />
						</c:otherwise>
					</c:choose>
				</div>


				<div class="fieldSetLeftColumn">Title</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.title" cssClass="mediumTxtBox"
						maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">
					<b>Surname</b>
				</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.surname" maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">First name</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.forename" maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">
					<span>Date of Birth</span>
				</div>
				<div class="fieldSetRightColumn">
					<spring:bind path="strDateOfBirth">
						<input id="strDateOfBirth" name="strDateOfBirth" type="text" value="<c:out value="${referralPatientDto.strDateOfBirth}"/>" placeholder="dd/mm/yyyy" class="mediumTxtBox"/>
					</spring:bind>
					<img title='Click to choose date' style='cursor: pointer'
						src='../images/16x16/date.png' id='strDateOfBirth_DateTrigger' />
				</div>
				<div class="fieldSetLeftColumn">
					<span>Date of Death</span>
				</div>
				<div class="fieldSetRightColumn">
					<spring:bind path="strDateOfDeath">
						<input id="strDateOfDeath" name="strDateOfDeath" type="text" value="<c:out value="${referralPatientDto.strDateOfDeath}"/>" placeholder="dd/mm/yyyy" class="mediumTxtBox"/>
					</spring:bind>
					<img title='Click to choose date' style='cursor: pointer'
						src='../images/16x16/date.png' id='strDateOfDeath_DateTrigger' />
				</div>
				<div class="fieldSetLeftColumn">
					<span>Deceased</span></div>
				<div class="fieldSetRightColumn"><smvc:checkbox path="referralPatient.deathIndicator"/>
				</div>
				<div class="fieldSetLeftColumn">
					<span>Sex</span>
				</div>
				<div class="fieldSetRightColumn">
					<label> <webapp:selectAndEditList domain="EMDT"
							path="referralPatient.sex" list="SexCode"
							currentValue="${referralPatientDto.referralPatient.sex}"
							includeEmpty="true" /> </label>
				</div>
			</div>
		</div>
	</div>

	<div class="fieldSetSectionHolder">
		<div class="fieldSetBox">
			<div class="legendBox">Patient Address</div>

			<div class="legendBoxWrapper">
				<div class="fieldSetLeftColumn">Address</div>
				<div class="fieldSetRightColumn">
					<span class="inputLabel"> <smvc:textarea
							path="referralPatient.address" cols="20" rows="3" /> </span>
				</div>
				<div class="fieldSetLeftColumn">Postcode</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.postcode" cssClass="mediumTxtBox"
						maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">Country</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.country" maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">Home Phone</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.homePhoneNumber" maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">Mobile Phone</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.mobilePhoneNumber"
						maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">Work Phone</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.workPhoneNumber" maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">Email Address</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.emailAddress" maxlength="255" />
					<img src="../emdt/images/imgEmailIcon.gif" alt="" />
				</div>
			</div>
		</div>
	</div>
	<c:if test="${emdt.prefShowPatientInfoExtraDemographics}">
		<div class="fieldSetSectionHolder">
			<div class="fieldSetBox">
				<div class="legendBox">Additional Patient Details</div>


				<div class="legendBoxWrapper">
					<div class="fieldSetLeftColumn">Marital Status</div>
					<div class="fieldSetRightColumn">
						<webapp:selectAndEditList domain="EMDT"
							path="referralPatient.maritalStatus" list="MaritalStatus"
							currentValue="${referralPatientDto.referralPatient.maritalStatus}"
							includeEmpty="true" />
					</div>
					<div class="fieldSetLeftColumn">Nationality</div>
					<div class="fieldSetRightColumn">
						<webapp:selectAndEditList path="referralPatient.nationality"
							domain="EMDT" list="Nationality"
							currentValue="${referralPatientDto.referralPatient.nationality}"
							includeEmpty="true" />
					</div>
					<div class="fieldSetLeftColumn">Language</div>
					<div class="fieldSetRightColumn">
						<webapp:selectAndEditList path="referralPatient.language"
							domain="EMDT" list="Language"
							currentValue="${referralPatientDto.referralPatient.language}"
							includeEmpty="true" />
					</div>
					<div class="fieldSetLeftColumn">Religion</div>
					<div class="fieldSetRightColumn">
						<webapp:selectAndEditList path="referralPatient.religion"
							domain="EMDT" list="Religion"
							currentValue="${referralPatientDto.referralPatient.religion}"
							includeEmpty="true" />
					</div>
					<div class="fieldSetLeftColumn">Ethnic Group</div>
					<div class="fieldSetRightColumn">
						<webapp:selectAndEditList path="referralPatient.ethnicity"
							domain="EMDT" list="Ethnicity"
							currentValue="${referralPatientDto.referralPatient.ethnicity}"
							includeEmpty="true" />
					</div>
					<div class="fieldSetLeftColumn">Occupation</div>
					<div class="fieldSetRightColumn">
						<smvc:input path="referralPatient.occupation" maxlength="255" />
					</div>
					<div class="fieldSetLeftColumn extraWidthLeft">Reg. Disabled</div>
					<div class="fieldSetRightColumn extraWidthRight">
						<smvc:radiobutton value="Yes"
							path="referralPatient.registeredDisabled" />
						Yes &nbsp;&nbsp;
						<smvc:radiobutton value="No"
							path="referralPatient.registeredDisabled" />
						No &nbsp;&nbsp;
					</div>
				</div>
			</div>
		</div>

	</c:if>
	<c:if test="${emdt.prefShowPatientInfoNextOfKin}">
		<div class="fieldSetSectionHolder marginBottomNone">

			<div class="fieldSetBox">
				<div class="legendBox">Next of Kin</div>


				<div class="legendBoxWrapper">
					<div class="fieldSetLeftColumn">Surname</div>
					<div class="fieldSetRightColumn">
						<smvc:input path="referralPatient.nokSurname" maxlength="255" />
					</div>
					<div class="fieldSetLeftColumn">First Name</div>
					<div class="fieldSetRightColumn">
						<smvc:input path="referralPatient.nokForenames" maxlength="255" />
					</div>
					<div class="fieldSetLeftColumn">Telephone</div>
					<div class="fieldSetRightColumn">
						<smvc:input path="referralPatient.nokTelephoneNumber1"
							maxlength="255" />
					</div>
					<div class="fieldSetLeftColumn">Address</div>
					<div class="fieldSetRightColumn">
						<span class="inputLabel"> <smvc:textarea
								path="referralPatient.nokAddress" cols="20" rows="3" /> </span>
					</div>
					<div class="fieldSetLeftColumn">Postcode</div>
					<div class="fieldSetRightColumn">
						<smvc:input path="referralPatient.nokPostcode" maxlength="255" />
					</div>
					<div class="fieldSetLeftColumn">
						<span>Relationship to patient</span>
					</div>
					<div class="fieldSetRightColumn">
						<webapp:selectAndEditList path="referralPatient.nokRelationship"
							domain="EMDT" list="PatientNOKRelationship"
							currentValue="${referralPatientDto.referralPatient.nokRelationship}"
							includeEmpty="true" />
					</div>
				</div>
			</div>
		</div>
		<div class="fieldSetSectionHolder txtCenter marginBottomNone">&nbsp;</div>
	</c:if>

</div>

<div class="pdRightColumn">

	<div class="fieldSetSectionHolder">

		<div class="fieldSetBox">
			<div class="legendBox">Referring Specialist</div>
			<div class="legendBoxWrapper">
				<div class="fieldSetLeftColumn">Job Title</div>
				<div class="fieldSetRightColumn">
					<webapp:selectAndEditList
						path="currentCareSpell.referralDetails.referringSpecialistJobTitle"
						domain="EMDT" list="ReferringSpecialistJobTitle"
						currentValue="${referralPatientDto.currentCareSpell.referralDetails.referringSpecialistJobTitle}"
						includeEmpty="true" />
				</div>
				<br /> <br />
				<div class="fieldSetLeftColumn">Name</div>
				<div class="fieldSetRightColumn">
					<c:choose>
						<c:when
							test="${webapp.roleManagement and ('ReferAPatient' ne parentScreen)}">
							<smvc:input path="currentCareSpell.referralDetails.referringSpecialistUser.username" readonly="true" />
						</c:when>
						<c:otherwise>
							<smvc:select path="selectedReferringSpName" onchange="javascript:updateSpecialistFields(this.selectedIndex);">
								<smvc:option value=""></smvc:option>
								<c:forEach items="${webapp.usersByHospitalIdMap[webapp.currentUser.hospital.id]}" var="mDMBean">
										<c:if test="${webapp.userIdUsernameMap[mDMBean] eq referralPatientDto.currentCareSpell.referralDetails.referringSpecialistUser.username}">
											<c:set var="selected" value="true"/>
										</c:if>
										<smvc:option value="${webapp.userIdUsernameMap[mDMBean]}" <c:if test="${selected}">selected='selected'</c:if> ><c:out value="${webapp.userIdNameMap[mDMBean]}"/></smvc:option>
										<c:remove var="selected" />
								</c:forEach>
							</smvc:select>
							<c:forEach varStatus="loop" items="${webapp.usersByHospitalIdMap[webapp.currentUser.hospital.id]}" var="mDMBean">
								<input type="hidden" id="tempSpecialityId<c:out value="${loop.count}"/>" value="<c:out value="${webapp.userIdNameMap[mDMBean]}"/>,<c:out value="${webapp.userIdEmailMap[mDMBean]}"/>" /></c:forEach>
						</c:otherwise>
					</c:choose>
				</div>
				<div class="fieldSetLeftColumn">Referring User</div>
				<div class="fieldSetRightColumn">
					<c:choose>
						<c:when
							test="${referralPatientDto.currentCareSpell.referralDetails.referredFromUser.username != null}">
							<input type="text"
								value="<c:out value="${referralPatientDto.currentCareSpell.referralDetails.referredFromUser.username}"/>"
								readonly="readonly" />
						</c:when>
						<c:otherwise>
							<input type="text" value="<c:out value="${webapp.currentUser.username}"/>"
								readonly="readonly" />
						</c:otherwise>
					</c:choose>
				</div>
				Overseas or Private Patient
				<smvc:checkbox path="overseasOrPrivate" />
				<div class="fieldSetRightColumn"></div>
			</div>


			<div class="inputLabelLast">&nbsp;</div>
		</div>
	</div>




	<div class="fieldSetSectionHolder">



		<div class="fieldSetBox">
			<div class="legendBox">Referring Specialist's Address</div>


			<div class="legendBoxWrapper">
				<div class="fieldSetLeftColumn">Surname</div>
				<div class="fieldSetRightColumn">
					<input
						value="<c:out value="${referralPatientDto.currentCareSpell.referralDetails.referringSpecialistUser.surname}"/>"
						maxlength="50" id="referringSpecialistsurmane" />
				</div>
				<div class="fieldSetLeftColumn">First Name</div>
				<div class="fieldSetRightColumn">
					<input
						value="<c:out value="${referralPatientDto.currentCareSpell.referralDetails.referringSpecialistUser.forename}"/>"
						maxlength="50" id="referringSpecialistforename" />
				</div>
				<div class="fieldSetLeftColumn">Telephone</div>
				<div class="fieldSetRightColumn">
					<smvc:input
						path="currentCareSpell.referralDetails.referringSpecialistTelephone"
						maxlength="20" />
				</div>
				<div class="fieldSetLeftColumn">Fax Number</div>
				<div class="fieldSetRightColumn">
					<smvc:input
						path="currentCareSpell.referralDetails.referringSpecialistFax"
						maxlength="20" />
				</div>
				<div class="fieldSetLeftColumn">Email Address</div>
				<div class="fieldSetRightColumn">
					<input
						value="<c:out value="${referralPatientDto.currentCareSpell.referralDetails.referringSpecialistUser.email}"/>"
						maxlength="50" id="referringSpecialistemail" /> <img
						src="../emdt/images/imgEmailIcon.gif" alt="" />
				</div>
				<div class="fieldSetLeftColumn">
					<span>Address</span>
				</div>
				<div class="fieldSetRightColumn">
					<span class="inputLabel"> <smvc:textarea
							path="currentCareSpell.referralDetails.referringSpecialistAddress"
							cols="20" rows="3" /> </span>
				</div>
				<div class="fieldSetLeftColumn">Postcode</div>
				<div class="fieldSetRightColumn">
					<smvc:input
						path="currentCareSpell.referralDetails.referringSpecialistPostcode"
						cssClass="mediumTxtBox" maxlength="20" />
				</div>
			</div>
		</div>
	</div>
	<div class="fieldSetSectionHolder">
		<div class="fieldSetBox">
			<div class="legendBox">GP Details</div>


			<div class="legendBoxWrapper">
				<div class="fieldSetLeftColumn">GMP Code</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.gpGmpCode"
						cssClass="mediumTxtBox" maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">Surname</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.gpSurname" maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">First Name</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.gpForename" maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">Telephone</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.gpTelephoneNumber"
						maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">Fax Number</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.gpFaxNumber" maxlength="255" />
				</div>
				<div class="fieldSetLeftColumn">Email Address</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.gpEmailAddress" maxlength="255" />
					<img src="../emdt/images/imgEmailIcon.gif" alt="" />xxx
				</div>
				<div class="fieldSetLeftColumn">
					<span>Surgery Address</span>
				</div>
				<div class="fieldSetRightColumn">
					<span class="inputLabel"> <smvc:textarea
							path="referralPatient.gpSurgeryAddress" cols="20" rows="3" /> </span>
				</div>
				<div class="fieldSetLeftColumn">Postcode</div>
				<div class="fieldSetRightColumn">
					<smvc:input path="referralPatient.gpPostcode"
						cssClass="mediumTxtBox" maxlength="255" />
				</div>
			</div>
		</div>
	</div>
</div>
<table>
	<tr height="290">
		<td></td>
	</tr>
	<tr>
		<td width="115"></td>
		<td align="left"><div class="rightSaveDiv"
				onclick="savePatient('<c:out value="${sessionScope.parentScreen}"/>');" id="save">
				<br />Save Patient Details
			</div>
		</td>
	</tr>
	<tr height="2">
		<td></td>
	</tr>
</table>

<div id="commentsDiv" class="commentsBox">
	<div>
		<a name="commentsAnchor"></a>
	</div>
	<div class="commentsHeading">
		<img src="../images/16x16/comments.png" /> Comments <br />&nbsp;
	</div>

	<table>
		<c:set var="comment" value='<%=request.getAttribute("commentList")%>' />
		<c:forEach var="report" items='${comment}'>
			<tr>
				<td width="70%" class="commentsUserName"><c:out value="${report.username}"/>&nbsp;/
					<c:out value="${report.hospitalCode}"/><br />
				</td>
				<td width="30%" class="commentsText"><c:out value="${report.comment}"/></td>
			</tr>
			<tr>
				<td class="commentsDate"><fmt:formatDate
						value="${report.dateOfComment}" pattern="dd MMM yyyy, HH:mm" />
				</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td colspan="2"><hr color="lightgray" size="1" />
				</td>
			</tr>
		</c:forEach>
		<tr>
			<td class="commentsLabel">Send a comment or question about this
				page:</td>
			<td><textarea id="comments" name="comments" cols="80" rows="3"></textarea>
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td class="commentsLabel" align="right">(Max 250 characters)</td>
		</tr>

	</table>
</div>
