<%@ include file="/includes.jsp"%>
<link href="../referrals/css/main.css" type="text/css" rel="stylesheet" />
<style type="text/css">
.patientHistoryFormNameTD	{
	padding-left:	20px;
	color: #303070;
	text-align:	left;
}
</style>
<script type="text/javascript">
	function openPatient(id) {
		if(id) {
			document.location = "viewPatient.form?patientId=" + id;
		} else {
			window.alert("No patient id");
		}
	}
	function addPatientsToMeeting(){
		var checked=false;
		var av=document.getElementsByName("selected");
		for (e=0;e<av.length;e++) {
		  if (av[e].checked==true) {
			  checked=true;
		   }
		}
		if(!checked){
			alert("Please select Patients to add to Meeting");
			return false;
		}
		document.getElementById('patientsInClinicToNextMeeting').submit();
	}
</script>

<webapp:namedList name="speciality" domain="EMDT" id="specialityNL"/>
<webapp:listToMap var="specialityMap" list="${specialityNL}"/>
<form id="patientsInClinicToNextMeeting" action="addCurrentPatientToNextMeeting.form" method="post">
<input type="hidden" name="task" value="selectNextMeeting">
<input type="hidden" name="isMultipleSelect" value="true">
<c:choose>
	<c:when test="${param.sortOrder == 'asc' }">
		<c:set var="sortOrder" value="desc"></c:set>	</c:when>
	<c:otherwise>
		<c:set var="sortOrder" value="asc"></c:set>
	</c:otherwise>
</c:choose>
<c:set var="sorthref" value="patientInClinic.form?action=SortAction&sortCol=" ></c:set>
<table width="90%" cellspacing="0" class="table" id="searchTableId" >
	<tr class="tableHeader">
		<th class="tableColHeader" >Select</th>
		<th class="tableColHeader" >
		<c:choose>
			<c:when test="${param.sortCol == 'hospnum' && param.sortOrder == 'asc' }">
				<a href="<c:out value="${sorthref}"/>hospnum&sortOrder=desc">Hospital Number</a>
			</c:when>
			<c:otherwise>
				<a href="<c:out value="${sorthref}"/>hospnum&sortOrder=asc">Hospital Number</a>
			</c:otherwise>
		</c:choose>
		</th>
		<th class="tableColHeader" >
		<c:choose>
			<c:when test="${param.sortCol == 'nhsnum' && param.sortOrder == 'asc' }">
				<a href="<c:out value="${sorthref}"/>nhsnum&sortOrder=desc">NHS Number</a>
			</c:when>
			<c:otherwise>
				<a href="<c:out value="${sorthref}"/>nhsnum&sortOrder=asc">NHS Number</a>
			</c:otherwise>
		</c:choose>
		</th>
		<th class="tableColHeader">
		<c:choose>
			<c:when test="${param.sortCol == 'surname' && param.sortOrder == 'asc' }">
				<a href="<c:out value="${sorthref}"/>surname&sortOrder=desc">Patient Surname</a>
			</c:when>
			<c:otherwise>
				<a href="<c:out value="${sorthref}"/>surname&sortOrder=asc">Patient Surname</a>
			</c:otherwise>
		</c:choose>
		</th>
		<th class="tableColHeader">
		<c:choose>
			<c:when test="${param.sortCol == 'forename' && param.sortOrder == 'asc' }">
				<a href="<c:out value="${sorthref}"/>forename&sortOrder=desc">Patient Forename</a>
			</c:when>
			<c:otherwise>
				<a href="<c:out value="${sorthref}"/>forename&sortOrder=asc">Patient Forename</a>
			</c:otherwise>
		</c:choose>
		</th>
		<th class="tableColHeader" >Gender</th>
		<th class="tableColHeader" >
		<c:choose>
			<c:when test="${param.sortCol == 'dob' && param.sortOrder == 'asc' }">
				<a href="<c:out value="${sorthref}"/>dob&sortOrder=desc">&nbsp;Date&nbsp;of&nbsp;Birth&nbsp;</a>
			</c:when>
			<c:otherwise>
				<a href="<c:out value="${sorthref}"/>dob&sortOrder=asc">&nbsp;Date&nbsp;of&nbsp;Birth&nbsp;</a>
			</c:otherwise>
		</c:choose>
		</th>
		<th class="tableColHeader" >
		<c:choose>
			<c:when test="${param.sortCol == 'speciality' && param.sortOrder == 'asc' }">
				<a href="<c:out value="${sorthref}"/>speciality&sortOrder=desc">Clinic Type</a>
			</c:when>
			<c:otherwise>
				<a href="<c:out value="${sorthref}"/>speciality&sortOrder=asc">Clinic Type</a>
			</c:otherwise>
		</c:choose>
		</th>
		<th class="tableColHeader" >
		<c:choose>
			<c:when test="${param.sortCol == 'clinicDate' && param.sortOrder == 'asc' }">
				<a href="<c:out value="${sorthref}"/>clinicDate&sortOrder=desc">Last Appointment Date</a>
			</c:when>
			<c:otherwise>
				<a href="<c:out value="${sorthref}"/>clinicDate&sortOrder=asc">Last Appointment Date</a>
			</c:otherwise>
		</c:choose>
		</th>
		<th class="tableColHeader">
		<c:choose>
			<c:when test="${param.sortCol == 'institutionCode' && param.sortOrder == 'asc' }">
				<a href="<c:out value="${sorthref}"/>institutionCode&sortOrder=desc">Hospital</a>
			</c:when>
			<c:otherwise>
				<a href="<c:out value="${sorthref}"/>institutionCode&sortOrder=asc">Hospital</a>
			</c:otherwise>
		</c:choose>
		</th>
		<th class="tableColHeader">
		<c:choose>
			<c:when test="${param.sortCol == 'consultantname' && param.sortOrder == 'asc' }">
				<a href="<c:out value="${sorthref}"/>consultantname&sortOrder=desc">Consultant</a>
			</c:when>
			<c:otherwise>
				<a href="<c:out value="${sorthref}"/>consultantname&sortOrder=asc">Consultant</a>
			</c:otherwise>
		</c:choose>
		</th>
	</tr>
	<c:choose>
		<c:when
			test="${(clinicsList ne null) and (fn:length(clinicsList) gt 0)}">
			<c:forEach var="clinicDto" items="${clinicsList}" >
				<tr class="clickable">
					<td><input type="checkbox" name="selected" value="<c:out value="${clinicDto.patient.guid }"/>" title="select to add to MDT meeting"/></td>
					<td class="tableCell" onclick="openPatient('<c:out value="${clinicDto.patient.guid}"/>')">
					<c:out value="${clinicDto.patient.hospitalNumber}"/>&nbsp;</td>
					<td class="tableCell" onclick="openPatient('<c:out value="${clinicDto.patient.guid}"/>')">
					<c:out value="${clinicDto.patient.nhsNumber}"/>&nbsp;</td>
					<td class="tableCell" onclick="openPatient('<c:out value="${clinicDto.patient.guid}"/>')">
					<c:out value="${clinicDto.patient.surname}"/>&nbsp;</td>
					<td class="tableCell" onclick="openPatient('<c:out value="${clinicDto.patient.guid}"/>')">
					<c:out value="${clinicDto.patient.forename}"/>&nbsp;</td>
					<td class="tableCell" onclick="openPatient('<c:out value="${clinicDto.patient.guid}"/>')">
					<c:out value="${clinicDto.patient.sex}"/>&nbsp;</td>
					<td class="tableCell" onclick="openPatient('<c:out value="${clinicDto.patient.guid}"/>')">
					<fmt:formatDate	value="${clinicDto.patient.dateOfBirth}" pattern="dd MMM yyyy" />&nbsp;</td>
					<td class="tableCell" onclick="openPatient('<c:out value="${clinicDto.patient.guid}"/>')">
					<c:out value="${specialityMap[clinicDto.clinic.speciality] }"/>&nbsp;</td>
					<td class="tableCell" onclick="openPatient(<c:out value="${clinicDto.patient.guid}"/>)">
					<fmt:formatDate pattern="dd MMM yyyy" value="${clinicDto.clinic.clinicDate}" /></td>
					<td class="tableCell" onclick="openPatient('<c:out value="${clinicDto.patient.guid}"/>')">
					<c:out value="${hospMap[clinicDto.clinic.institutionCode]}"/>&nbsp;</td>
					<td class="tableCell" onclick="openPatient('<c:out value="${clinicDto.patient.guid}"/>')">
					<c:out value="${clinicDto.clinic.consultantForename}"/>&nbsp;<c:out value="${clinicDto.clinic.consultantSurname}"/> </td>
				</tr>
			</c:forEach>
		</c:when>
		<c:otherwise>
			<tr>
				<td align="center" class="message" colspan="10">No Patients	Found</td>
			</tr>
		</c:otherwise>
	</c:choose>
	<tr class="tableFooter">
		<c:if test="${(clinicsList ne null) and (fn:length(clinicsList) gt 0)}">
			<td colspan="13" align="left">
				<input type="button" value="Add Selected Patients to MDT Meeting"
				 onclick="addPatientsToMeeting();" />
			</td>
		</c:if>
		<c:if test="${(clinicsList eq null) or (fn:length(clinicsList) le 0)}">
			<td colspan="13" align="left">&nbsp;</td>
		</c:if>
	</tr>
</table>
</form>