<%@ include file="/includes.jsp" %>

<style>
.floaty	{
	display: block;
	width: 500;
	vertical-align: top;
}
.floaty .inputLabel td	{
	display: block;
}
.floaty .inputField td	{
	display: block;
	text-align: right;
}
</style>

<script type="text/javascript">
	function update() {
		var formObj = document.getElementById("editPatientDetails");
		if(formObj) {
			document.getElementById("toCancel").name = "org.apache.struts.action.CANCEL";
			
			formObj.submit();
		}
	}
	
	function pasUpdate() {
		var hosNumInput = document.getElementById("hosNumInput");
		if(hosNumInput && hosNumInput.value) {
			dispatch('pasUpdate');
			return true;
		} else {
			window.alert("Please provide a Hospital Number first");	
		}
		return false;
	}
	function fetchGPChoice() {
		var formObj = document.getElementById("editPatientDetails");
		if(formObj) {
			dispatch('gpUpdate');
			return true;
		}
	}
	function patientSupportingStaff(){    
    	var editsupportingStaff = document.getElementById("editsupportingStaff");
    	editsupportingStaff.value ="true";    	
    	var theUserForm = document.getElementById("editPatientDetails");
    	theUserForm.submit();
    	
    }

</script>

<smvc:form action="/emdt/editPatientDetails" styleId="editPatientDetails">
<input type="hidden" value="false" id="unsaveButtonId" />
	<sec:authorize access="hasAnyRole('ADMIN','ACCESS_ALL_PATIENTS')">
	<input type="hidden" name="userId" 	id="userId" value="<c:out value="${webapp.currentUser.id }"/>"/>  
    </sec:authorize>
	<input type="hidden" name="patientId" id="patientId	value="${editPatientDetailsForm.patient.id}"/>
	<input type="hidden" name="editsupportingStaff"	id="editsupportingStaff" value="false"/>
	<c:choose>
		<c:when test="${editPatientDetailsForm.editAllowed eq true}">
		   <c:set var="editDisabled" value="false"/>
		</c:when>
		<c:otherwise>
		   <c:set var="editDisabled" value="true"/>
		</c:otherwise>
	</c:choose>
	
	<c:if test="${requestScope.successMsg ne null}">
		<br/>
		<div class="message"><img src="../images/16x16/information.png"	alt="i" /><c:out value=" ${requestScope.successMsg}"/></div>
	</c:if>
	<c:if test="${editPatientDetailsForm.patient.id ne null}">
		<c:if test="${empty editPatientDetailsForm.patient.careSpells}">
		<p/>
		<table class="messageBox">
			<tr>
				<td>
					<table cellpadding="4">
						<tr>
						<td><img src="../images/16x16/information.png" alt="Information"/></td>
						<td>
						This patient does not yet have any Care Spells / Episodes.<br/>
						Would you like to create one?
						</td>
						<td>
							<input type="button" value="Create..." onclick="document.location='editCarespells.form'"/>&nbsp;
						</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<br/>
		</c:if>
	</c:if>
	
	<input type="hidden" name="toCancel" value="true" id="toCancel"/>
	<input type="hidden" name="method" value="save" id="dispatchMethod"/>
	
<table width="100%">
<tr>
<td align="center">
	<fieldset class="floaty">
	<legend>Patient Details</legend>
		<table>
			<tr>
				<td class="inputLabel">NHS Number</td>
				<td class="inputField"><html:text size="20" property="patient.nhsNumber" readonly="${editDisabled}" /></td>
			</tr>
			<tr>
				<td class="inputLabel">Hospital Number</td>
				<td class="inputField"><html:text size="20" property="patient.hospitalNumber" styleId="hosNumInput" readonly="${editDisabled}" /><c:if test="${webapp.allowLookup}">
				<html:image src="../images/16x16/zoom.png"  onclick="return pasUpdate()" title="Look up hospital number in PAS"/>
				</c:if>
				</td>
			</tr>
			<tr>
				<td class="inputLabel">Title</td>
				<td class="inputField"><html:text size="10" property="patient.title" readonly="<c:out value="${editDisabled}"/>"/></td>
			</tr>
			<tr>
				<td class="inputLabel"><b>Surname</b></td>
				<td class="inputField"><html:text size="20" property="patient.surname" readonly="<c:out value="${editDisabled}"/>"/></td>
			</tr>
			<tr>
				<td class="inputLabel">First Name</td>
				<td class="inputField"><html:text size="20" property="patient.forename" readonly="<c:out value="${editDisabled}"/>"/></td>
			</tr>
			<tr>
				<td class="inputLabel">Date of Birth</td>
				<td class="inputField"><webapp:date property="dateOfBirth" styleId="dateOfBirth" readonly="${editDisabled}"/></td>
			</tr>
			<tr>
				<td class="inputLabel">Date of Death</td>
				<td class="inputField"><webapp:date property="dateOfDeath" styleId="dateOfDeath" readonly="${editDisabled}"/></td>
			</tr>
			<tr>
				<td class="inputLabel">Sex</td>
				<td class="inputField">
					<webapp:selectFromList property="patient.sex" domain="EMDT" list="SexCode" includeEmpty="true" disabled="${editDisabled}" />
				</td>
			</tr>
		</table>
	</fieldset>
	
	<fieldset class="floaty">
	<legend>Patient Address</legend>
		<table>
			<tr>
				<td valign="top" class="inputLabel">Address</td>
				<td class="inputField"><html:textarea rows="4" cols="25" property="patient.address" readonly="<c:out value="${editDisabled}"/>"/></td>
			</tr>
			<tr>
				<td class="inputLabel">Postcode</td>
				<td class="inputField"><html:text  size="8" property="patient.postcode" readonly="<c:out value="${editDisabled}"/>"/></td>
			</tr>
			<tr>
				<td class="inputLabel">Country</td>
				<td class="inputField"><html:text  size="20" property="patient.country" readonly="<c:out value="${editDisabled}"/>"/></td>
			</tr>
			<tr>
				<td class="inputLabel">Home&nbsp;Phone</td>
				<td class="inputField"><html:text  size="20" property="patient.homePhoneNumber" readonly="<c:out value="${editDisabled}"/>"/></td>
			</tr>
			<tr>
				<td class="inputLabel">Mobile&nbsp;Phone</td>
				<td class="inputField">
					<html:text  size="20" property="patient.mobilePhoneNumber" readonly="${editDisabled}" />
				</td>
			</tr>
			<tr>
				<td class="inputLabel">Email&nbsp;Address</td>
				<td class="inputField">
					<html:text  size="20" property="patient.emailAddress" readonly="<c:out value="${editDisabled}"/>"/>
				<c:if test="${editPatientDetailsForm.patient.emailAddress ne null}">
				<a href="mailto:${editPatientDetailsForm.patient.emailAddress}" title="Compose email to patient"><img src="../images/16x16/email.png" border="0" /></a>
				</c:if>
				</td>
			</tr>
		</table>
	</fieldset>


<c:if test="${emdt.prefShowPatientInfoExtraDemographics}">
	<fieldset class="floaty">
	<legend>Additional Patient Details</legend>			
		<table>
			<tr>
				<td class="inputLabel">Marital Status</td>
				<td class="inputField">
					<webapp:selectFromList property="patient.maritalStatus" domain="EMDT" list="MaritalStatus" includeEmpty="true" disabled="${editDisabled}"/>
				</td>
			</tr>
			<tr>
				<td class="inputLabel">Nationality</td>
				<td class="inputField">
					<webapp:selectFromList property="patient.nationality" domain="EMDT" list="Nationality" includeEmpty="true" disabled="${editDisabled}"/>
				</td>
			</tr>
			<tr>
				<td class="inputLabel">Language</td>
				<td class="inputField">
					<webapp:selectFromList property="patient.language" domain="EMDT" list="Language" includeEmpty="true" disabled="${editDisabled}"/>
				</td>
			</tr>
			<tr>
				<td class="inputLabel">Religion</td>
				<td class="inputField">
					<webapp:selectFromList property="patient.religion" domain="EMDT" list="Religion" includeEmpty="true" disabled="${editDisabled}"/>
				</td>
			</tr>
			<tr>
				<td class="inputLabel">Ethnic Group</td>
				<td class="inputField">
					<webapp:selectFromList property="patient.ethnicity" domain="EMDT" list="Ethnicity" includeEmpty="true" disabled="${editDisabled}"/>
				</td>
			</tr>

			<tr>
				<td class="inputLabel">Occupation</td>
				<td class="inputField"><html:text size="20" property="patient.occupation" readonly="${editDisabled}" /></td>
			</tr>
			<tr>
				<td class="inputLabel">Overseas Visitor</td>
				<td class="inputField">
					<html:radio value="Yes" property="patient.overseasVisitor" disabled="<c:out value="${editDisabled}"/>" />&nbsp;Yes&nbsp;
					<html:radio value="No" property="patient.overseasVisitor" disabled="<c:out value="${editDisabled}"/>" />&nbsp;No
				</td>
			</tr>
			<tr>
				<td class="inputLabel">Reg. Disabled</td>
				<td class="inputField">
					<html:radio value="Yes" property="patient.registeredDisabled" disabled="<c:out value="${editDisabled}"/>"/>&nbsp;Yes&nbsp;
					<html:radio value="No" property="patient.registeredDisabled" disabled="<c:out value="${editDisabled}"/>"/>&nbsp;No
				</td>
			</tr>
		</table>
	</fieldset>
	</c:if>

<br/>

	<fieldset class="floaty">
	<legend>GP Details</legend>

		<table>
			<tr>
                <td class="inputLabel">Admitting&nbsp;Physician</td>
                <td>
                    <c:choose>
                    <c:when test = "${fn:length(editPatientDetailsForm.emdtUsers) > 0}">
                            <c:choose >
                            <c:when test="${editDisabled eq true}">
                                <html:select property="patient.admittingPhysician" disabled="true" >
                                                            <html:option value=""></html:option>
                            <c:forEach var="user" items="${editPatientDetailsForm.emdtUsers}">
                            <html:option value="${user.id}"><c:out value="${user.username}"/></html:option>
                            </c:forEach>
                            </html:select>
                                
                            </c:when>
                            <c:otherwise>
                                <html:select property="patient.admittingPhysician">
                                <html:option value="" />
                            <c:forEach var="user" items="${editPatientDetailsForm.emdtUsers}">
                            <html:option value="${user.id}"><c:out value="${user.username}"/></html:option>
                            </c:forEach>
                            </html:select>
                                
                            </c:otherwise>
                            </c:choose>
                            
                   </c:when>
                    <c:otherwise>  
                        <html:text size="20"  property="username" value="<c:out value="${editPatientDetailsForm.username}"/>" disabled="true"/>
                   </c:otherwise>
                    </c:choose>   
                </td>
            </tr>
            <tr>
				<td class="inputLabel">GP List</td>
				<td class="inputField">
					<webapp:selectFromList includeEmpty="true" property="patient.gpGmpCode" domain="DATABASE" list="GP List" disabled="${editDisabled}"/>
					   <c:choose>
					   <c:when test="${editDisabled eq true}">
                       <html:image src="../images/16x16/zoom.png"  style='cursor: default' disabled="true" title="Look up GP"/>
					   </c:when>
					   <c:otherwise>
					   <html:image src="../images/16x16/zoom.png"  onclick="return fetchGPChoice()" title="Look up GP"/>
					   </c:otherwise>
					   </c:choose>
				</td>
			</tr>
			<tr>
				<td class="inputLabel">GMP Code</td>
				<td class="inputField"><html:text size="10"  property="patient.gpGmpCode" title="GMP Code" readonly="${editDisabled}" /></td>
			</tr>
			<tr>
				<td class="inputLabel">Surname</td>
				<td class="inputField"><html:text size="20"  property="patient.gpSurname" readonly="${editDisabled}" /></td>
			</tr>
			<tr>
				<td class="inputLabel">First Name</td>
				<td class="inputField"><html:text size="20"  property="patient.gpForename" readonly="${editDisabled}" /></td>
			</tr>
			<tr>
				<td class="inputLabel">Telephone</td>
				<td class="inputField"><html:text size="20"  property="patient.gpTelephoneNumber" readonly="${editDisabled}" /></td>
			</tr>
			<tr>
				<td class="inputLabel">Fax Number</td>
				<td class="inputField"><html:text size="20"  property="patient.gpFaxNumber" readonly="${editDisabled}" /></td>
			</tr>
			<tr>
				<td class="inputLabel">Email Address</td>
				<td class="inputField"><html:text size="20"  property="patient.gpEmailAddress" readonly="${editDisabled}" /><c:if test="${editPatientDetailsForm.patient.gpEmailAddress ne null}"> <a href="mailto:${editPatientDetailsForm.patient.gpEmailAddress}" title="Compose email to GP"><img src="../images/16x16/email.png" border="0" /></a></c:if>
				</td>
			</tr>

			<tr>
				<td class="inputLabel">Practice Name</td>
				<td class="inputField"><html:text size="20"  property="patient.gpPracticeName" readonly="${editDisabled}" /></td>
			</tr>
			<tr>
				<td class="inputLabel">Practice Code</td>
				<td class="inputField"><html:text size="10"  property="patient.gpPracticeCode" readonly="${editDisabled}" /></td>
			</tr>
			<tr>
				<td class="inputLabel">Surgery<br/>Address</td>
				<td class="inputField"><html:textarea rows="4" cols="22" property="patient.gpSurgeryAddress" readonly="${editDisabled}" /></td>
			</tr>
			<tr>
				<td class="inputLabel">Postcode</td>
				<td class="inputField"><html:text size="8"  property="patient.gpPostcode" readonly="${editDisabled}" /></td>
			</tr>
			<tr>
				<td class="inputLabel">PCT Name</td>
				<td class="inputField"><html:text size="20"  property="patient.gpPctName" title="Primary Care Trust Name" readonly="${editDisabled}" /></td>
			</tr>
			<tr>
				<td class="inputLabel">PCT Code</td>
				<td class="inputField"><html:text size="10"  property="patient.gpPctCode" title="Primary Care Trust Code" readonly="${editDisabled}" /></td>
			</tr>
		</table>
	</fieldset>

<c:if test="${emdt.prefShowPatientInfoNextOfKin}">
	<fieldset class="floaty">
	<legend>Next of Kin</legend>

<table>
	<tr>
		<td class="inputLabel">Surname</td>
		<td class="inputField"><html:text size="20" property="patient.nokSurname" readonly="${editDisabled}" /></td>
	</tr>
	<tr>
		<td class="inputLabel">First Name</td>
		<td class="inputField"><html:text size="20" property="patient.nokForenames" readonly="${editDisabled}" /></td>
	</tr>
	<tr>
		<td class="inputLabel">Telephone 1</td>
		<td class="inputField"><html:text size="20"  property="patient.nokTelephoneNumber1" readonly="${editDisabled}" /></td>
	</tr>
	<tr>
		<td class="inputLabel">Telephone 2</td>
		<td class="inputField"><html:text size="20"  property="patient.nokTelephoneNumber2" readonly="${editDisabled}" /></td>
	</tr>
	<tr>
		<td class="inputLabel">Address</td>
		<td class="inputField"><html:textarea rows="4" cols="22" property="patient.nokAddress" readonly="${editDisabled}" /></td>
	</tr>
	<tr>
		<td class="inputLabel">Postcode</td>
		<td class="inputField"><html:text size="15" property="patient.nokPostcode" readonly="${editDisabled}" /></td>
	</tr>
	<tr>
		<td class="inputLabel">Country</td>
		<td class="inputField"><html:text size="20" property="patient.nokCountry" readonly="${editDisabled}" /></td>
	</tr>
	<tr>
		<td class="inputLabel">Relationship to patient</td>
		<td class="inputField">
			<webapp:selectFromList property="patient.nokRelationship" domain="EMDT" list="PatientNOKRelationship" includeEmpty="true" disabled="${editDisabled}"/>
		</td>
	</tr>
</table>
</fieldset>
</c:if>



<div align="center" >
&nbsp;
</div>
<div align="center" >
<c:if test="${editPatientDetailsForm.patient.id != null and emdt.accessEditSupportStaff}">
			<input type="button" value="Edit Patient Support Staff" onclick="patientSupportingStaff()"/>&nbsp;			
</c:if>
	<html:reset disabled="<c:out value="${editDisabled}"/>" />&nbsp;
	<c:if test="${editPatientDetailsForm.patient.id != null}">
		<input type="button" value="Export" onclick="document.location='exportPatientRecord.form'"/>&nbsp;
	</c:if>
	<!-- 
	<sec:authorize access="hasRole('ADMIN')">	
		<c:if test="${editPatientDetailsForm.patient.id != null}">
			<input type="button" value="Delete" onclick="document.location='deletePatient.do'"/>&nbsp;
		</c:if>
	</sec:authorize>
	 -->
	<html:submit value="Save"  disabled="${editDisabled}"/>" styleId="save"/>
</div>

</td>
</tr>
</table>	

</smvc:form>
