<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<script type="text/javascript">
function exportPatientSummary(form){
	if(isChecked(form.selected))
	{
	    var isConfirmed = confirm('Are you sure you wish to export the selected patient summary definitions?');
	    if(!isConfirmed){
	          return false;
	    }
	    var previousFormAction = form.action;
	    form.action = "exportPatientSummary.form";
	    form.submit();
	    form.action = previousFormAction;
		deselectCheckBox(form.selected);
    }else{
        alert("Please select atleast one patient summary definition to export.");
        return false;
    }
 }
function submitForm(methodName,id){
	document.getElementById('dispatchMethod').value=methodName;
	if(id.length > 0){
		document.getElementById('id').value=id;
	}
	document.getElementById('patientSummaryForm').submit();
}
function loadSummary(id){
	document.getElementById('dispatchMethod').value='load';
	location.href="patientSummaryActions.form?method=load&id="+id;
}

$(function() {
    $('input:radio[name="filter"]').change(function() {
        location.href="patientSummaryActions.form?method=list&filter="+$(this).val();
    });
});
</script>
<div class="breadcrumb">
You are here: <a href="../emdt/emdtHome.form"><img src="../emdt/images/16x16/icon.png" style="vertical-align: top;"/> eMDT</a> &gt; <a href="../emdt/reportMenu.jsp">Reports</a> &gt; <a class="selected" href="../emdt/patientSummaryActions.form?method=list">Patient Summaries</a> 
</div>
<smvc:form action="../emdt/patientSummaryActions.form" modelAttribute="patientSummaryForm" id="patientSummaryForm">
	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
	<input type="hidden" name="method" value="delete" id="dispatchMethod"/>
	<input type="hidden" name="id" id="id"/>
	<br/>
	<c:if test="${not empty patientSummaryReferencesMessage}">
		<span class="warning">
		<c:forEach var="mes" items="${patientSummaryReferencesMessage}">
			<c:out value="${mes}"/><br/>
		</c:forEach>
		</span>
	</c:if>

	<smvc:errors cssClass="error" />

	<table width="70%">
		<tr>
			<td align="left">
				Show: 
				<input type="radio" name="filter" value="true" <c:if test="${filter eq 'true'}" >checked</c:if> />My  Summaries 
				<input type="radio" name="filter" value="false"  <c:if test="${filter eq 'false'}" >checked</c:if> />All Summaries
			</td>
		</tr>
		<tr>
			<td>
				<br/>
				<tags:table title="Patient Summaries">
					<table width="100%" cellpadding="4" cellspacing="0" class="table">
						<tr>
							<th  align="left">Title</th>
							<th width="1%">View</th>
							<th width="1%">Edit</th>
							<th>Owner</th>
							<th width="1%">Select</th>
						</tr>
						<webapp:forEach id="summary" items="${summaries}" statusId="status">
							<tr class="<c:out value="${status.oddOrEven}"/>Row">
								<td  align="left"><c:out value="${summary.title}" />

								</td>
								<td align="center">
									<c:if test="${emdt.currentCareSpell != null }">									
										<a title="Click to view this Summary" onclick ="submitForm('view','<c:out value="${summary.guid}"/>')"><img src="../images/16x16/application_view_columns.png"/></a>
									</c:if>
									<c:if test="${emdt.currentCareSpell == null }">									
										&nbsp;
									</c:if>
								</td>
								<td align="center">
									<a onclick ="loadSummary('<c:out value="${summary.guid}"/>')" title="Edit this Summary" ><img src="../images/page_white_edit.png" border="0" alt="Edit" /></a>
								</td>
								<td  width="1%"><c:out value="${summary.createdBy.username}"/></td>
								<td width="1%" align="center"><smvc:checkbox  path="selected" value="${summary.id }"/></td>
							</tr>
						</webapp:forEach>
                        <c:if test="${not empty summaries }">
							<tr>
								<td colspan="4"></td>
								<td><input type="submit" value="Delete" onclick="return confirmAndDispatch('delete', 'Are you sure you wish to delete these summaries?')"/></td>
							</tr>
                            <tr>
                             <td colspan="4"></td>
                             <td><input type="button" value="Export" onclick="exportPatientSummary(this.form);"/></td>
                            </tr>
							
						</c:if>
						 <c:if test="${empty summaries }">
							<tr>
								<td colspan="5" align="center">No summaries found.</td>
							</tr>
						</c:if>
					</table>
				</tags:table>
			</td>
		</tr>
		<tr>
			<td><c:if test="${emdt.currentCareSpell == null }">
					<div class="helpmessage"> To view a summary, please select a patient first.</div>
				</c:if></td>
		</tr>

		<tr>
			<td>
			<br>
			<table> 
				<tr>
					<td>
						<input type="button" value="New Summary..." onclick ="submitForm('create','')"/>
					</td>
					<td>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					</td>
					<td>
						<input type="button" value="Import Summary..." onclick="document.location='importPatientSummary.form'"/>
					</td>
				</tr>
			</table>
		</tr>			
	</table>
</smvc:form>