diff --git a/iTrust/WebRoot/auth/admin/menu.jsp b/iTrust/WebRoot/auth/admin/menu.jsp index 8ceae79a1302faa8fccc2e741e3f7826896e26a0..cdfeab9ebcff917fee0794622deacf7328308849 100644 --- a/iTrust/WebRoot/auth/admin/menu.jsp +++ b/iTrust/WebRoot/auth/admin/menu.jsp @@ -31,6 +31,18 @@ </ul> </div> </div> + +<div class="panel panel-default"> + <div class="panel-heading" anim-type="collapse" anim-target="#messaging-menu"> + <h2 class="panel-title">Messaging</h2> + </div> + <div class="panel-body" id="messaging-menu"> + <ul class="nav nav-sidebar"> + <li><a href="/iTrust/auth/admin/viewReminderOutbox.jsp">Reminder Message Outbox</a></li> + </ul> + </div> +</div> + <div class="panel panel-default"> <div class="panel-heading" anim-type="collapse" anim-target="#other-menu"> <h2 class="panel-title">Other</h2> @@ -44,6 +56,7 @@ <li><a href="/iTrust/auth/admin/sessionTimeout.jsp">Change Global Session Timeout </a></li> <li><a href="/iTrust/auth/surveyResults.jsp">Satisfaction Survey Results</a></li> <li><a href="/iTrust/auth/admin/activatePatient.jsp">Activate Patient</a></li> + <li><a href="/iTrust/auth/admin/sendAppointmentReminders.jsp">Send Appointment Reminders</a></li> </ul> </div> </div> \ No newline at end of file diff --git a/iTrust/WebRoot/auth/admin/reminderMessage.jsp b/iTrust/WebRoot/auth/admin/reminderMessage.jsp new file mode 100644 index 0000000000000000000000000000000000000000..a9f7df9ab5a859a62572af8d38293722c7f4d7ea --- /dev/null +++ b/iTrust/WebRoot/auth/admin/reminderMessage.jsp @@ -0,0 +1,74 @@ +<%@page errorPage="/auth/exceptionHandler.jsp"%> + +<%@page import="edu.ncsu.csc.itrust.action.ViewMyMessagesAction"%> +<%@page import="edu.ncsu.csc.itrust.beans.MessageBean"%> +<%@page import="java.util.List"%> + +<%@include file="/global.jsp" %> + +<% +pageTitle = "iTrust - View Message"; +%> + +<%@include file="/header.jsp" %> + +<% + ViewMyMessagesAction action = new ViewMyMessagesAction(prodDAO, loggedInMID.longValue()); + MessageBean original = null; + + loggingAction.logEvent(TransactionType.OUTBOX_VIEW, loggedInMID.longValue(), 0, ""); + + if (request.getParameter("msg") != null) { + String msgParameter = request.getParameter("msg"); + int msgIndex = 0; + try { + msgIndex = Integer.parseInt(msgParameter); + } catch (NumberFormatException nfe) { + response.sendRedirect("viewReminderOutbox.jsp"); + } + List<MessageBean> messages = null; + if (session.getAttribute("messages") != null) { + messages = (List<MessageBean>) session.getAttribute("messages"); + if(msgIndex > messages.size() || msgIndex < 0) { + msgIndex = 0; + response.sendRedirect("oops.jsp"); + } + } else { + response.sendRedirect("viewReminderOutbox.jsp"); + } + original = (MessageBean)messages.get(msgIndex); + session.setAttribute("message", original); + } + else { + response.sendRedirect("viewReminderOutbox.jsp"); + } + +%> + <div> + <table width="99%"> + <tr> + <td><b>To:</b> <%= StringEscapeUtils.escapeHtml("" + ( action.getName(original.getTo()) )) %></td> + </tr> + <tr> + <td><b>Subject:</b> <%= StringEscapeUtils.escapeHtml("" + ( original.getSubject() )) %></td> + </tr> + <tr> + <td><b>Date & Time:</b> <%= StringEscapeUtils.escapeHtml("" + ( original.getSentDate() )) %></td> + </tr> + </table> + </div> + + <table> + <tr> + <td colspan="2"><b>Message:</b></td> + </tr> + <tr> + <td colspan="2"><%= StringEscapeUtils.escapeHtml("" + ( original.getBody() )).replace("\n","<br/>") %></td> + </tr> + <tr> + <td colspan="2"><a href="viewReminderOutbox.jsp">Back</a></td> + </tr> + </table> + + +<%@include file="/footer.jsp" %> \ No newline at end of file diff --git a/iTrust/WebRoot/auth/admin/sendAppointmentReminders.jsp b/iTrust/WebRoot/auth/admin/sendAppointmentReminders.jsp new file mode 100644 index 0000000000000000000000000000000000000000..711032f0c4cf478d0a95bbc755bf61860e04bec0 --- /dev/null +++ b/iTrust/WebRoot/auth/admin/sendAppointmentReminders.jsp @@ -0,0 +1,50 @@ + +<%@taglib prefix="itrust" uri="/WEB-INF/tags.tld"%> +<%@page errorPage="/auth/exceptionHandler.jsp"%> +<%@page import="edu.ncsu.csc.itrust.action.SendRemindersAction" %> +<%@page import="edu.ncsu.csc.itrust.exception.ITrustException" %> +<%@page import="java.lang.NumberFormatException" %> + +<%@include file="/global.jsp" %> + +<% +pageTitle = "iTrust - Send Reminder Message"; +%> + +<%@include file="/header.jsp" %> + +<% + String input = request.getParameter("withinDays"); + if (input != null && !input.equals("")) { + try { + int days = Integer.valueOf(input); + if (days <= 0) { +%> + <span class="iTrustError"><%=StringEscapeUtils.escapeHtml("Provide a positive number") %></span> +<% + } + else { + SendRemindersAction action = new SendRemindersAction(prodDAO, loggedInMID.longValue()); + action.sendReminderForAppointments(days); +%> + <span class="iTrustMessage"><%=StringEscapeUtils.escapeHtml("Reminders were successfully sent") %></span> +<% + } + + } catch (NumberFormatException | ITrustException e) { +%> + <span class="iTrustError"><%=StringEscapeUtils.escapeHtml("Reminders failed to send. Please provide a positive number") %></span> +<% + } + } +%> + +<div class="page-header"><h1>Send Reminder Message</h1></div> + +<form method="post"> +<h4> Send reminders to all patients with an appointment within the next n days. Provide n: </h4> +<input type="text" name="withinDays"></td> +<input type="submit" style="font-size: 12pt; font-weight: bold;" value="Send Appointment Reminders"> +</form> + +<%@include file="/footer.jsp" %> \ No newline at end of file diff --git a/iTrust/WebRoot/auth/admin/viewReminderOutbox.jsp b/iTrust/WebRoot/auth/admin/viewReminderOutbox.jsp new file mode 100644 index 0000000000000000000000000000000000000000..d2f2618da93dbc02f634568a57b81f0081a924f4 --- /dev/null +++ b/iTrust/WebRoot/auth/admin/viewReminderOutbox.jsp @@ -0,0 +1,71 @@ +<%@page errorPage="/auth/exceptionHandler.jsp"%> + +<%@page import="java.util.List"%> + +<%@page import="edu.ncsu.csc.itrust.action.ViewMyMessagesAction"%> +<%@page import="edu.ncsu.csc.itrust.beans.MessageBean"%> +<%@page import="edu.ncsu.csc.itrust.dao.DAOFactory"%> + +<%@include file="/global.jsp" %> + +<% +pageTitle = "iTrust - View My Sent Messages"; +%> + +<%@include file="/header.jsp" %> + +<div align=center> + <h2>Sent Reminders</h2> + <% + loggingAction.logEvent(TransactionType.OUTBOX_VIEW, loggedInMID.longValue(), loggedInMID.longValue(), ""); + + ViewMyMessagesAction action = new ViewMyMessagesAction(prodDAO, 9000000009L); + List<MessageBean> messages = null; + if(request.getParameter("sortby") != null) { + if(request.getParameter("sortby").equals("name")) { + if(request.getParameter("sorthow").equals("asce")) { + messages = action.getAllMySentMessagesNameAscending(); + } else { + messages = action.getAllMySentMessagesNameDescending(); + } + } else if(request.getParameter("sortby").equals("time")) { + if(request.getParameter("sorthow").equals("asce")) { + messages = action.getAllMySentMessagesTimeAscending(); + } else { + messages = action.getAllMySentMessages(); + } + } + } + else { + messages = action.getAllMySentMessages(); + } + session.setAttribute("messages", messages); + if (messages.size() > 0) { %> + <br /> + <table class="fancyTable"> + <tr> + <th>To</th> + <th>Subject</th> + <th>Sent</th> + <th></th> + </tr> + <% int index = 0; %> + <% for(MessageBean message : messages) { %> + <tr <%=(index%2 == 1)?"class=\"alt\"":"" %>> + <td><%= StringEscapeUtils.escapeHtml("" + ( action.getName(message.getTo()) )) %></td> + <td><%= StringEscapeUtils.escapeHtml("" + ( message.getSubject() )) %></td> + <td><%= StringEscapeUtils.escapeHtml("" + ( message.getSentDate() )) %></td> + <td><a href="reminderMessage.jsp?msg=<%= StringEscapeUtils.escapeHtml("" + ( index )) %>">Read</a></td> + </tr> + <% index ++; %> + <% } %> + </table> + <% } else { %> + <div> + <i>No reminders sent</i> + </div> + <% } %> + <br /> +</div> + +<%@include file="/footer.jsp" %> \ No newline at end of file diff --git a/iTrust/WebRoot/auth/hcp-patient/messageInbox.jsp b/iTrust/WebRoot/auth/hcp-patient/messageInbox.jsp index c38fc2f1e1b90d7346e82efb326f6298dcb0b932..b0cd7e48303408e9c7f6163a588cb0d544716ba5 100644 --- a/iTrust/WebRoot/auth/hcp-patient/messageInbox.jsp +++ b/iTrust/WebRoot/auth/hcp-patient/messageInbox.jsp @@ -24,4 +24,4 @@ loggingAction.logEvent(TransactionType.INBOX_VIEW, loggedInMID.longValue(), 0L, </div> -<%@include file="/footer.jsp" %> +<%@include file="/footer.jsp" %> \ No newline at end of file diff --git a/iTrust/WebRoot/auth/hcp-pha/viewEpidemics.jsp b/iTrust/WebRoot/auth/hcp-pha/viewEpidemics.jsp index 1d9d99ecd40b3e3e0e73a9ee5c155f2e767a75af..dd1e1dd96756024f214b13c267bc0b9b34bf3157 100644 --- a/iTrust/WebRoot/auth/hcp-pha/viewEpidemics.jsp +++ b/iTrust/WebRoot/auth/hcp-pha/viewEpidemics.jsp @@ -101,7 +101,7 @@ <% if (dsBean != null && avgBean != null) { %> <p style="display:block; margin-left:auto; margin-right:auto; width:600px;"> -<%@include file="DiagnosisEpidemicsChart.jsp" %> + </p> <% diff --git a/iTrust/WebRoot/auth/hcp/menu.jsp b/iTrust/WebRoot/auth/hcp/menu.jsp index a5b31eb260cb613f90a0c066787f0ef9d09dad0c..5b2fc4a5bd7fca5fd88541fabc00b291dfa619dc 100644 --- a/iTrust/WebRoot/auth/hcp/menu.jsp +++ b/iTrust/WebRoot/auth/hcp/menu.jsp @@ -59,17 +59,18 @@ </div> <div class="panel panel-default"> - <div class="panel-heading" anim-type="collapse" anim-target="#msg-menu"> - <h2 class="panel-title">Messaging</h2> - </div> - <div class="panel-body" id="msg-menu"> - <ul class="nav nav-sidebar"> - <li><a href="/iTrust/auth/hcp/sendMessage.jsp">Compose a Message</a> - <li><a href="/iTrust/auth/hcp-patient/messageInbox.jsp">Message Inbox</a> - <li><a href="/iTrust/auth/hcp-patient/messageOutbox.jsp">Message Outbox</a> - <li><a href="/iTrust/auth/hcp-uap/showEmailHistory.jsp">Email History</a> - </ul> - </div> + <div class="panel-heading" anim-type="collapse" anim-target="#msg-menu"> + <h2 class="panel-title">Messaging</h2> + </div> + <div class="panel-body" id="msg-menu"> + <ul class="nav nav-sidebar"> + <li><a href="/iTrust/auth/hcp/sendMessage.jsp">Compose a Message</a> + <li><a href="/iTrust/auth/hcp/messageInbox.jsp">Message Inbox</a> + <li><a href="/iTrust/auth/hcp/messageOutbox.jsp">Message Outbox</a> + <li><a href="/iTrust/auth/hcp-uap/showEmailHistory.jsp">Email History</a> + </ul> + </div> + </div> <div class="panel panel-default"> diff --git a/iTrust/WebRoot/auth/hcp/messageInbox.jsp b/iTrust/WebRoot/auth/hcp/messageInbox.jsp index bea87e3c3f2c84e95a34e494dc6bab7f9b9b1ade..408048ddd7fd847de0f2f9fd5e5b8674a4d142fd 100644 --- a/iTrust/WebRoot/auth/hcp/messageInbox.jsp +++ b/iTrust/WebRoot/auth/hcp/messageInbox.jsp @@ -35,6 +35,8 @@ pageTitle = "iTrust - View My Message "; //Edit Filter backend boolean editing = false; String headerMessage = ""; + String filterMessage = ""; + String[] fields = new String[6]; if(request.getParameter("edit") != null && request.getParameter("edit").equals("true")) { editing = true; @@ -57,7 +59,8 @@ pageTitle = "iTrust - View My Message "; nf += request.getParameter("endDate"); //Validate Filter - nf = action.validateAndCreateFilter(nf); + + filterMessage = nf; if(nf.startsWith("Error")) { error = true; headerMessage = nf; @@ -65,16 +68,24 @@ pageTitle = "iTrust - View My Message "; if(!error) { if(request.getParameter("test") != null) { + filterMessage = nf; response.sendRedirect("messageInbox.jsp?edit=true&testFilter="+nf); - } else if(request.getParameter("save") != null) { - f_action.editMessageFilter(nf); - response.sendRedirect("messageInbox.jsp?filter=true"); + } + + if(request.getParameter("save") != null) { + filterMessage = nf; + + f_action.editMessageFilter(nf); + response.sendRedirect("messageInbox.jsp?filter=true&testFilter="+nf); } } } if(request.getParameter("testFilter") != null) { String filter = request.getParameter("testFilter"); + + filterMessage = filter; + String[] f = filter.split(",", -1); for(i=0; i<6; i++) { try { @@ -85,6 +96,9 @@ pageTitle = "iTrust - View My Message "; } } else { String filter = dao.getPersonnel(loggedInMID.longValue()).getMessageFilter(); + + filterMessage = filter; + if(!filter.equals("")) { String[] f = filter.split(",", -1); for(i=0; i<6; i++) { @@ -124,9 +138,14 @@ pageTitle = "iTrust - View My Message "; String filter = ""; if(request.getParameter("testFilter") != null) { filter = request.getParameter("testFilter"); + + filterMessage = filter; } else { filter = dao.getPersonnel(loggedInMID.longValue()).getMessageFilter(); + + filterMessage = filter; } + if(!filter.equals("") && !filter.equals(",,,,,")) { List<MessageBean> filtered = action.filterMessages(messages, filter); messages = filtered; @@ -217,7 +236,7 @@ pageTitle = "iTrust - View My Message "; </tr> <tr> <td><a href="messageInbox.jsp?edit=true" >Edit Filter</a></td> - <td><a href="messageInbox.jsp?filter=true" >Apply Filter</a></td> + <td><a href="messageInbox.jsp?filter=true&testFilter=<%=filterMessage%>" >Apply Filter</a></td> </tr> </table> </form> diff --git a/iTrust/WebRoot/auth/hcp/messageOutbox.jsp b/iTrust/WebRoot/auth/hcp/messageOutbox.jsp index 5ed4b2df06362044971c415a3a484bb01f5f017e..52ef995f712bb03e7a40e5ed95fbe19766f8f686 100644 --- a/iTrust/WebRoot/auth/hcp/messageOutbox.jsp +++ b/iTrust/WebRoot/auth/hcp/messageOutbox.jsp @@ -3,8 +3,15 @@ <%@page import="java.util.List"%> <%@page import="edu.ncsu.csc.itrust.action.ViewMyMessagesAction"%> +<%@page import="edu.ncsu.csc.itrust.action.EditPersonnelAction"%> <%@page import="edu.ncsu.csc.itrust.beans.MessageBean"%> <%@page import="edu.ncsu.csc.itrust.dao.DAOFactory"%> +<%@page import="edu.ncsu.csc.itrust.dao.mysql.PersonnelDAO"%> +<%@page import="java.util.ArrayList"%> +<%@page import="java.text.DateFormat"%> +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="java.util.Date"%> +<%@page import="java.util.Calendar"%> <%@include file="/global.jsp" %> @@ -17,12 +24,90 @@ pageTitle = "iTrust - View My Sent Messages"; <div align=center> <h2>My Sent Messages</h2> <a href="/iTrust/auth/hcp/sendMessage.jsp">Compose a Message</a><br /><br /> + <% - loggingAction.logEvent(TransactionType.OUTBOX_VIEW, loggedInMID.longValue(), 0, ""); - + loggingAction.logEvent(TransactionType.OUTBOX_VIEW, loggedInMID.longValue(), 0, ""); + ViewMyMessagesAction action = new ViewMyMessagesAction(prodDAO, loggedInMID.longValue()); + EditPersonnelAction f_action = new EditPersonnelAction(prodDAO, loggedInMID.longValue(), loggedInMID.toString()); + PersonnelDAO dao = new PersonnelDAO(prodDAO); List<MessageBean> messages = null; - if(request.getParameter("sortby") != null) { + + //Edit Filter backend + boolean editing = false; + String headerMessage = ""; + String filterMessage = ""; + String[] fields = new String[6]; + if(request.getParameter("edit") != null && request.getParameter("edit").equals("true")) { + editing = true; + + int i; + for(i=0; i<6; i++) { + fields[i] = ""; + } + + if(request.getParameter("cancel") != null) + response.sendRedirect("messageOutbox.jsp"); + else if(request.getParameter("test") != null || request.getParameter("save") != null) { + boolean error = false; + String nf = ""; + nf += request.getParameter("receiver").replace(",","")+","; + nf += request.getParameter("subject").replace(",","")+","; + nf += request.getParameter("hasWords").replace(",","")+","; + nf += request.getParameter("notWords").replace(",","")+","; + nf += request.getParameter("startDate").replace(",","")+","; + nf += request.getParameter("endDate"); + + //Validate Filter + + if(nf.startsWith("Error")) { + error = true; + headerMessage = nf; + } + + if(!error) { + if(request.getParameter("test") != null) { + filterMessage = nf; + response.sendRedirect("messageOutbox.jsp?edit=true&testFilter="+nf); + } else if(request.getParameter("save") != null) { + + filterMessage = nf; + + f_action.editMessageFilter(nf); + response.sendRedirect("messageOutbox.jsp?filter=true&testFilter="+nf); + } + } + } + + if(request.getParameter("testFilter") != null) { + String filter = request.getParameter("testFilter"); + filterMessage = filter; + String[] f = filter.split(",", -1); + for(i=0; i<6; i++) { + try { + fields[i] = f[i]; + } catch(ArrayIndexOutOfBoundsException e) { + //do nothing + } + } + } else { + String filter = dao.getPersonnel(loggedInMID.longValue()).getMessageFilter(); + filterMessage = filter; + if(!filter.equals("")) { + String[] f = filter.split(",", -1); + for(i=0; i<6; i++) { + try { + fields[i] = f[i]; + } catch(ArrayIndexOutOfBoundsException e) { + //do nothing + } + } + } + } + } + + //Sorts messages + if(request.getParameter("sort") != null) { if(request.getParameter("sortby").equals("name")) { if(request.getParameter("sorthow").equals("asce")) { messages = action.getAllMySentMessagesNameAscending(); @@ -40,9 +125,87 @@ pageTitle = "iTrust - View My Sent Messages"; else { messages = action.getAllMySentMessages(); } + + //Filters Messages + boolean is_filtered = false; + if((request.getParameter("filter") != null && request.getParameter("filter").equals("true")) || request.getParameter("testFilter") != null) { + String filter = ""; + if(request.getParameter("testFilter") != null) { + filter = request.getParameter("testFilter"); + + filterMessage = filter; + } else { + filter = dao.getPersonnel(loggedInMID.longValue()).getMessageFilter(); + filterMessage = filter; + } + if(!filter.equals("") && !filter.equals(",,,,,")) { + List<MessageBean> filtered = action.filterSentMessages(messages, filter); + messages = filtered; + is_filtered = true; + } + } + session.setAttribute("messages", messages); - if (messages.size() > 0) { %> - <form method="post" action="messageOutbox.jsp"> + %> + + <% + + if(editing) { + %> + <div class="filterEdit"> + <div align="center"> + <span style="font-size: 13pt; font-weight: bold;">Edit Message Filter</span> + <%= headerMessage.equals("") ? "" : "<br /><span class=\"iTrustMessage\">"+headerMessage+"</span><br /><br />" %> + <form method="post" action="messageOutbox.jsp?edit=true"> + <table> + <tr style="text-align: right;"> + <td> + <label for="receiver">Receiver: </label> + <input type="text" name="receiver" id="receiver" value="<%= StringEscapeUtils.escapeHtml("" + (fields[0] )) %>" /> + </td> + <td style="padding-left: 10px; padding-right: 10px;"> + <label for="hasWords">Has the words: </label> + <input type="text" name="hasWords" id="hasWords" value="<%= StringEscapeUtils.escapeHtml("" + (fields[2] )) %>" /> + </td> + <td> + <label for="startDate">Start Date: </label> + <input type="text" name="startDate" id="startDate" value="<%= StringEscapeUtils.escapeHtml("" + (fields[4] )) %>" /> + <input type="button" value="Select Date" onclick="displayDatePicker('startDate');" /> + </td> + </tr> + <tr style="text-align: right;"> + <td> + <label for="subject">Subject: </label> + <input type="text" name="subject" id="subject" value="<%= StringEscapeUtils.escapeHtml("" + (fields[1] )) %>" /> + </td> + <td style="padding-left: 10px; padding-right: 10px;"> + <label for="notWords">Does not have the words: </label> + <input type="text" name="notWords" id="notWords" value="<%= StringEscapeUtils.escapeHtml("" + (fields[3] )) %>" /> + </td> + <td> + <label for="endDate">End Date: </label> + <input type="text" name="endDate" id="endDate" value="<%= StringEscapeUtils.escapeHtml("" + (fields[5] )) %>" /> + <input type="button" value="Select Date" onclick="displayDatePicker('endDate');" /> + </td> + </tr> + <tr style="text-align: center;"> + <td colspan="3"> + <input type="submit" name="test" value="Test Filter" /> + <input type="submit" name="save" value="Save" /> + <input type="submit" name="cancel" value="Cancel" /> + </td> + </tr> + </table> + </form> + </div> + </div> + <br /> + <% + } + + %> + + <form method="post" action="messageOutbox.jsp<%= StringEscapeUtils.escapeHtml("" + (is_filtered?"?filter=true":"" )) %>"> <table> <tr> <td> @@ -60,27 +223,32 @@ pageTitle = "iTrust - View My Sent Messages"; </select> </td> <td> - <input type="submit" value="Sort" /> + <input type="submit" name="sort" value="Sort" /> </td> </tr> + <tr> + <td><a href="messageOutbox.jsp?edit=true" >Edit Filter</a></td> + <td><a href="messageOutbox.jsp?filter=true&testFilter=<%=filterMessage%>" >Apply Filter</a></td> + </tr> </table> </form> <br /> + <%if(messages.size() > 0) { %> <table class="fancyTable"> <tr> <th>To</th> <th>Subject</th> - <th>Sent</th> + <th>Received</th> <th></th> </tr> -<% int index = 0; %> -<% for(MessageBean message : messages) { %> +<% int index = 0; + for(MessageBean message : messages) { %> <tr <%=(index%2 == 1)?"class=\"alt\"":"" %>> - <td><%= StringEscapeUtils.escapeHtml("" + ( action.getName(message.getTo()) )) %></td> - <td><%= StringEscapeUtils.escapeHtml("" + ( message.getSubject() )) %></td> - <td><%= StringEscapeUtils.escapeHtml("" + ( message.getSentDate() )) %></td> - <td><a href="viewMessageOutbox.jsp?msg=<%= StringEscapeUtils.escapeHtml("" + ( index )) %>">Read</a></td> - </tr> + <td><%= StringEscapeUtils.escapeHtml("" + ( action.getName(message.getTo()) )) %></td> + <td><%= StringEscapeUtils.escapeHtml("" + ( message.getSubject() )) %></td> + <td><%= StringEscapeUtils.escapeHtml("" + ( message.getSentDate() )) %></td> + <td><a href="viewMessageOutbox.jsp?msg=<%= StringEscapeUtils.escapeHtml("" + ( index )) %>">Read</a></td> + </tr> <% index ++; %> <% } %> </table> diff --git a/iTrust/WebRoot/auth/patient/menu.jsp b/iTrust/WebRoot/auth/patient/menu.jsp index cd613b69cc9327af60c185b4968e0295d9379d6e..e31d0313772566e1e85c1f60919994a5e3947257 100644 --- a/iTrust/WebRoot/auth/patient/menu.jsp +++ b/iTrust/WebRoot/auth/patient/menu.jsp @@ -78,8 +78,8 @@ <div class="panel-body" id="msg-menu"> <ul class="nav nav-sidebar"> <li><a href="/iTrust/auth/patient/sendMessage.jsp">Compose a Message</a> - <li><a href="/iTrust/auth/hcp-patient/messageInbox.jsp">Message Inbox</a> - <li><a href="/iTrust/auth/hcp-patient/messageOutbox.jsp">Message Outbox</a> + <li><a href="/iTrust/auth/patient/messageInbox.jsp">Message Inbox</a> + <li><a href="/iTrust/auth/patient/messageOutbox.jsp">Message Outbox</a> </ul> </div> </div> diff --git a/iTrust/WebRoot/auth/patient/messageInbox.jsp b/iTrust/WebRoot/auth/patient/messageInbox.jsp index 4eec68b03535e63ff95bf56208249b8b9f499c3e..241d029cbb711eae25a3ddaee066295a5a9b7bc0 100644 --- a/iTrust/WebRoot/auth/patient/messageInbox.jsp +++ b/iTrust/WebRoot/auth/patient/messageInbox.jsp @@ -5,6 +5,7 @@ <%@page import="edu.ncsu.csc.itrust.action.ViewMyMessagesAction"%> <%@page import="edu.ncsu.csc.itrust.action.EditPatientAction"%> <%@page import="edu.ncsu.csc.itrust.beans.MessageBean"%> +<%@page import="edu.ncsu.csc.itrust.beans.PatientBean"%> <%@page import="edu.ncsu.csc.itrust.dao.DAOFactory"%> <%@page import="edu.ncsu.csc.itrust.dao.mysql.PatientDAO"%> <%@page import="java.util.ArrayList"%> @@ -33,6 +34,7 @@ pageTitle = "iTrust - View My Message "; //Edit Filter backend boolean editing = false; String headerMessage = ""; + String filterMessage = ""; String[] fields = new String[6]; if(request.getParameter("edit") != null && request.getParameter("edit").equals("true")) { editing = true; @@ -54,8 +56,9 @@ pageTitle = "iTrust - View My Message "; nf += request.getParameter("startDate").replace(",","")+","; nf += request.getParameter("endDate"); + filterMessage = nf; + //Validate Filter - nf = action.validateAndCreateFilter(nf); if(nf.startsWith("Error")) { error = true; headerMessage = nf; @@ -63,16 +66,19 @@ pageTitle = "iTrust - View My Message "; if(!error) { if(request.getParameter("test") != null) { + filterMessage = nf; response.sendRedirect("messageInbox.jsp?edit=true&testFilter="+nf); } else if(request.getParameter("save") != null) { + filterMessage = nf; f_action.editMessageFilter(nf); - response.sendRedirect("messageInbox.jsp?filter=true"); + response.sendRedirect("messageInbox.jsp?filter=true&testFilter="+nf); } } } if(request.getParameter("testFilter") != null) { String filter = request.getParameter("testFilter"); + filterMessage = filter; String[] f = filter.split(",", -1); for(i=0; i<6; i++) { try { @@ -83,6 +89,7 @@ pageTitle = "iTrust - View My Message "; } } else { String filter = dao.getPatient(loggedInMID.longValue()).getMessageFilter(); + filterMessage = filter; if(!filter.equals("")) { String[] f = filter.split(",", -1); for(i=0; i<6; i++) { @@ -126,8 +133,10 @@ pageTitle = "iTrust - View My Message "; String filter = ""; if(request.getParameter("testFilter") != null) { filter = request.getParameter("testFilter"); + filterMessage = filter; } else { filter = dao.getPatient(loggedInMID.longValue()).getMessageFilter(); + filterMessage = filter; } if(!filter.equals("") && !filter.equals(",,,,,")) { List<MessageBean> filtered = action.filterMessages(messages, filter); @@ -219,7 +228,7 @@ pageTitle = "iTrust - View My Message "; </tr> <tr> <td><a href="messageInbox.jsp?edit=true" >Edit Filter</a></td> - <td><a href="messageInbox.jsp?filter=true" >Apply Filter</a></td> + <td><a href="messageInbox.jsp?filter=true&testFilter=<%=filterMessage%>" >Apply Filter</a></td> </tr> </table> </form> diff --git a/iTrust/WebRoot/auth/patient/messageOutbox.jsp b/iTrust/WebRoot/auth/patient/messageOutbox.jsp index 190b1515f12d01f102018a15f0f6f9b8d8bb2b4e..035ee28b7fc796673a89e7496e7a254f8bd655f9 100644 --- a/iTrust/WebRoot/auth/patient/messageOutbox.jsp +++ b/iTrust/WebRoot/auth/patient/messageOutbox.jsp @@ -3,15 +3,21 @@ <%@page import="java.util.List"%> <%@page import="edu.ncsu.csc.itrust.action.ViewMyMessagesAction"%> +<%@page import="edu.ncsu.csc.itrust.action.EditPatientAction"%> <%@page import="edu.ncsu.csc.itrust.beans.MessageBean"%> +<%@page import="edu.ncsu.csc.itrust.beans.PatientBean"%> <%@page import="edu.ncsu.csc.itrust.dao.DAOFactory"%> +<%@page import="edu.ncsu.csc.itrust.dao.mysql.PatientDAO"%> +<%@page import="java.util.ArrayList"%> +<%@page import="java.text.DateFormat"%> +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="java.util.Date"%> +<%@page import="java.util.Calendar"%> <%@include file="/global.jsp" %> <% pageTitle = "iTrust - View My Sent Messages"; - - %> <%@include file="/header.jsp" %> @@ -19,11 +25,98 @@ pageTitle = "iTrust - View My Sent Messages"; <div align=center> <h2>My Sent Messages</h2> <a href="/iTrust/auth/patient/sendMessage.jsp">Compose a Message</a><br /><br /> + + <% -loggingAction.logEvent(TransactionType.OUTBOX_VIEW, loggedInMID.longValue(), loggedInMID.longValue(), ""); ViewMyMessagesAction action = new ViewMyMessagesAction(prodDAO, loggedInMID.longValue()); + EditPatientAction f_action = new EditPatientAction(prodDAO, loggedInMID.longValue(), loggedInMID.toString()); + PatientDAO dao = new PatientDAO(prodDAO); List<MessageBean> messages = null; - if(request.getParameter("sortby") != null) { + + String filterMessage = ""; + + + //Edit Filter backend + boolean editing = false; + String headerMessage = ""; + String[] fields = new String[6]; + if(request.getParameter("edit") != null && request.getParameter("edit").equals("true")) { + editing = true; + + int i; + for(i=0; i<6; i++) { + fields[i] = ""; + } + + if(request.getParameter("cancel") != null) + response.sendRedirect("messageOutbox.jsp"); + else if(request.getParameter("test") != null || request.getParameter("save") != null) { + boolean error = false; + String nf = ""; + nf += request.getParameter("receiver").replace(",","")+","; + nf += request.getParameter("subject").replace(",","")+","; + nf += request.getParameter("hasWords").replace(",","")+","; + nf += request.getParameter("notWords").replace(",","")+","; + nf += request.getParameter("startDate").replace(",","")+","; + nf += request.getParameter("endDate"); + + //Validate Filter + if(nf.startsWith("Error")) { + error = true; + headerMessage = nf; + } + + if(!error) { + if(request.getParameter("test") != null) { + + filterMessage = nf; + + response.sendRedirect("messageOutbox.jsp?edit=true&testFilter="+nf); + + + } else if(request.getParameter("save") != null) { + + filterMessage = nf; + + f_action.editMessageFilter(nf); + response.sendRedirect("messageOutbox.jsp?filter=true&testFilter="+nf); + } + } + } + + if(request.getParameter("testFilter") != null) { + String filter = request.getParameter("testFilter"); + +filterMessage = filter; + + String[] f = filter.split(",", -1); + for(i=0; i<6; i++) { + try { + fields[i] = f[i]; + } catch(ArrayIndexOutOfBoundsException e) { + //do nothing + } + } + } else { + String filter = dao.getPatient(loggedInMID.longValue()).getMessageFilter(); + +filterMessage = filter; + + if(!filter.equals("")) { + String[] f = filter.split(",", -1); + for(i=0; i<6; i++) { + try { + fields[i] = f[i]; + } catch(ArrayIndexOutOfBoundsException e) { + //do nothing + } + } + } + } + } + + //Sorts messages + if(request.getParameter("sort") != null) { if(request.getParameter("sortby").equals("name")) { if(request.getParameter("sorthow").equals("asce")) { messages = action.getAllMySentMessagesNameAscending(); @@ -39,11 +132,99 @@ loggingAction.logEvent(TransactionType.OUTBOX_VIEW, loggedInMID.longValue(), log } } else { + if(request.getParameter("edit") == null && request.getParameter("filter") == null) { + //loggingAction.logEvent(TransactionType.OUTBOX_VIEW, loggedInMID, 0, ""); + loggingAction.logEvent(TransactionType.OUTBOX_VIEW, loggedInMID.longValue(), loggedInMID.longValue(), ""); + } + messages = action.getAllMySentMessages(); } - session.setAttribute("messages", messages); - if (messages.size() > 0) { %> - <form method="post" action="messageOutbox.jsp"> + + //Filters Messages + boolean is_filtered = false; + if((request.getParameter("filter") != null && request.getParameter("filter").equals("true")) || request.getParameter("testFilter") != null) { + String filter = ""; + if(request.getParameter("testFilter") != null) { + filter = request.getParameter("testFilter"); + +filterMessage = filter; + + } else { + filter = dao.getPatient(loggedInMID.longValue()).getMessageFilter(); + +filterMessage = filter; + } + if(!filter.equals("") && !filter.equals(",,,,,")) { + List<MessageBean> filtered = action.filterSentMessages(messages, filter); + messages = filtered; + is_filtered = true; + } + } + + session.setAttribute("messages", messages); + %> + + <% + + if(editing) { + %> + <div class="filterEdit"> + <div align="center"> + <span style="font-size: 13pt; font-weight: bold;">Edit Message Filter</span> + <%= headerMessage.equals("") ? "" : "<br /><span class=\"iTrustMessage\">"+headerMessage+"</span><br /><br />" %> + <form method="post" action="messageOutbox.jsp?edit=true"> + <table> + <tr style="text-align: right;"> + <td> + <label for="receiver">Receiver: </label> + <input type="text" name="receiver" id="receiver" value="<%= StringEscapeUtils.escapeHtml("" + (fields[0] )) %>" /> + </td> + <td style="padding-left: 10px; padding-right: 10px;"> + <label for="hasWords">Has the words: </label> + <input type="text" name="hasWords" id="hasWords" value="<%= StringEscapeUtils.escapeHtml("" + (fields[2] )) %>" /> + </td> + <td> + <label for="startDate">Start Date: </label> + <input type="text" name="startDate" id="startDate" value="<%= StringEscapeUtils.escapeHtml("" + (fields[4] )) %>" /> + <input type="button" value="Select Date" onclick="displayDatePicker('startDate');" /> + </td> + </tr> + <tr style="text-align: right;"> + <td> + <label for="subject">Subject: </label> + <input type="text" name="subject" id="subject" value="<%= StringEscapeUtils.escapeHtml("" + (fields[1] )) %>" /> + </td> + <td style="padding-left: 10px; padding-right: 10px;"> + <label for="notWords">Does not have the words: </label> + <input type="text" name="notWords" id="notWords" value="<%= StringEscapeUtils.escapeHtml("" + (fields[3] )) %>" /> + </td> + <td> + <label for="endDate">End Date: </label> + <input type="text" name="endDate" id="endDate" value="<%= StringEscapeUtils.escapeHtml("" + (fields[5] )) %>" /> + <input type="button" value="Select Date" onclick="displayDatePicker('endDate');" /> + </td> + </tr> + <tr style="text-align: center;"> + <td colspan="3"> + <input type="submit" name="test" value="Test Filter" /> + <input type="submit" name="save" value="Save" /> + <input type="submit" name="cancel" value="Cancel" /> + </td> + </tr> + </table> + </form> + </div> + </div> + <br /> + <% + } + + %> + + + + + <form method="post" action="messageOutbox.jsp<%= StringEscapeUtils.escapeHtml("" + (is_filtered?"?filter=true":"" )) %>"> <table> <tr> <td> @@ -61,27 +242,33 @@ loggingAction.logEvent(TransactionType.OUTBOX_VIEW, loggedInMID.longValue(), log </select> </td> <td> - <input type="submit" value="Sort" /> + <input type="submit" name="sort" value="Sort" /> </td> </tr> + <tr> + <td><a href="messageOutbox.jsp?edit=true" >Edit Filter</a></td> + <td><a href="messageOutbox.jsp?filter=true&testFilter=<%=filterMessage%>" >Apply Filter</a></td> + </tr> </table> </form> <br /> + + <%if(messages.size() > 0) { %> <table class="fancyTable"> <tr> <th>To</th> <th>Subject</th> <th>Received</th> - <th></th> + <th> </th> </tr> -<% int index = 0; %> -<% for(MessageBean message : messages) { %> +<% int index = 0; + for(MessageBean message : messages) { %> <tr <%=(index%2 == 1)?"class=\"alt\"":"" %>> - <td><%= StringEscapeUtils.escapeHtml("" + ( action.getName(message.getTo()) )) %></td> - <td><%= StringEscapeUtils.escapeHtml("" + ( message.getSubject() )) %></td> - <td><%= StringEscapeUtils.escapeHtml("" + ( message.getSentDate() )) %></td> - <td><a href="viewMessageOutbox.jsp?msg=<%= StringEscapeUtils.escapeHtml("" + ( index )) %>">Read</a></td> - </tr> + <td><%= StringEscapeUtils.escapeHtml("" + ( action.getName(message.getTo()) )) %></td> + <td><%= StringEscapeUtils.escapeHtml("" + ( message.getSubject() )) %></td> + <td><%= StringEscapeUtils.escapeHtml("" + ( message.getSentDate() )) %></td> + <td><a href="viewMessageOutbox.jsp?msg=<%= StringEscapeUtils.escapeHtml("" + ( index )) %>">Read</a></td> + </tr> <% index ++; %> <% } %> </table> @@ -93,4 +280,4 @@ loggingAction.logEvent(TransactionType.OUTBOX_VIEW, loggedInMID.longValue(), log <br /> </div> -<%@include file="/footer.jsp" %> +<%@include file="/footer.jsp" %> \ No newline at end of file diff --git a/iTrust/iTrust.iml b/iTrust/iTrust.iml deleted file mode 100644 index c1ff8d3cd59969e529825f9c34c90cd438d50356..0000000000000000000000000000000000000000 --- a/iTrust/iTrust.iml +++ /dev/null @@ -1,115 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> - <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> - <output url="file://$MODULE_DIR$/target/classes" /> - <output-test url="file://$MODULE_DIR$/target/test-classes" /> - <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> - <excludeFolder url="file://$MODULE_DIR$/target" /> - </content> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-java:2.25.0" level="project" /> - <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-android-driver:2.25.0" level="project" /> - <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-chrome-driver:2.25.0" level="project" /> - <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-htmlunit-driver:2.25.0" level="project" /> - <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:2.25.0" level="project" /> - <orderEntry type="library" name="Maven: org.json:json:20080701" level="project" /> - <orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit:2.9" level="project" /> - <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.1.2" level="project" /> - <orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit-core-js:2.9" level="project" /> - <orderEntry type="library" name="Maven: net.sourceforge.cssparser:cssparser:0.9.5" level="project" /> - <orderEntry type="library" name="Maven: org.w3c.css:sac:1.3" level="project" /> - <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.1.2" level="project" /> - <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.1.2" level="project" /> - <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-firefox-driver:2.25.0" level="project" /> - <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-ie-driver:2.25.0" level="project" /> - <orderEntry type="library" name="Maven: net.java.dev.jna:platform:3.4.0" level="project" /> - <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-iphone-driver:2.25.0" level="project" /> - <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:2.25.0" level="project" /> - <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:2.25.0" level="project" /> - <orderEntry type="library" name="Maven: org.webbitserver:webbit:0.4.6" level="project" /> - <orderEntry type="library" name="Maven: org.jboss.netty:netty:3.2.7.Final" level="project" /> - <orderEntry type="library" name="Maven: org.apache.james:apache-mime4j:0.6" level="project" /> - <orderEntry type="library" name="Maven: bsh:bsh:1.3.0" level="project" /> - <orderEntry type="library" name="Maven: cglib:cglib-nodep:2.2" level="project" /> - <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" /> - <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" /> - <orderEntry type="library" name="Maven: org.apache.commons:commons-exec:1.1" level="project" /> - <orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" /> - <orderEntry type="library" name="Maven: commons-jxpath:commons-jxpath:1.3" level="project" /> - <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.3.2" level="project" /> - <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.3" level="project" /> - <orderEntry type="library" name="Maven: cssparser:cssparser:0.9.4" level="project" /> - <orderEntry type="library" name="Maven: findbugs:findbugs:1.0.0" level="project" /> - <orderEntry type="library" name="Maven: findbugs:annotations:1.0.0" level="project" /> - <orderEntry type="library" name="Maven: bcel:bcel:5.1" level="project" /> - <orderEntry type="library" name="Maven: regexp:regexp:1.2" level="project" /> - <orderEntry type="library" name="Maven: findbugs:coreplugin:1.0.0" level="project" /> - <orderEntry type="library" name="Maven: findbugs:findbugs-ant:1.0.0" level="project" /> - <orderEntry type="library" name="Maven: findbugs:findbugsGUI:1.0.0" level="project" /> - <orderEntry type="library" name="Maven: com.google.code.gson:gson:2.3.1" level="project" /> - <orderEntry type="library" name="Maven: com.google.guava:guava:site:18.0" level="project" /> - <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> - <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" /> - <orderEntry type="library" name="Maven: org.ini4j:ini4j:0.5.2" level="project" /> - <orderEntry type="library" name="Maven: com.beust:jcommander:1.29" level="project" /> - <orderEntry type="library" name="Maven: org.eclipse.jetty.aggregate:jetty-websocket:8.1.8.v20121106" level="project" /> - <orderEntry type="library" name="Maven: net.java.dev.jna:jna:3.4.0" level="project" /> - <orderEntry type="library" name="Maven: net.java.dev.jna:jna-platform:4.0.0" level="project" /> - <orderEntry type="library" name="Maven: junit-addons:junit-addons:1.4" level="project" /> - <orderEntry type="library" name="Maven: xerces:xmlParserAPIs:2.6.2" level="project" /> - <orderEntry type="library" name="Maven: org.mockito:mockito-all:1.9.5" level="project" /> - <orderEntry type="library" name="Maven: net.sourceforge.nekohtml:nekohtml:1.9.21" level="project" /> - <orderEntry type="library" name="Maven: io.netty:netty:3.5.7.Final" level="project" /> - <orderEntry type="library" name="Maven: com.opera:operadriver:1.5" level="project" /> - <orderEntry type="library" name="Maven: com.opera:operalaunchers:1.1" level="project" /> - <orderEntry type="library" name="Maven: com.google.guava:guava:14.0" level="project" /> - <orderEntry type="library" name="Maven: com.codeborne:phantomjsdriver:1.2.1" level="project" /> - <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-remote-driver:2.44.0" level="project" /> - <orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:2.4.1" level="project" /> - <orderEntry type="library" name="Maven: milyn:sac:1.3" level="project" /> - <orderEntry type="library" name="Maven: org.eclipse.birt.runtime.3_7_1:org.apache.xml.serializer:2.7.1" level="project" /> - <orderEntry type="library" name="Maven: org.eclipse.birt.runtime.3_7_1:Tidy:1" level="project" /> - <orderEntry type="library" name="Maven: xalan:xalan:2.7.1" level="project" /> - <orderEntry type="library" name="Maven: xalan:serializer:2.7.1" level="project" /> - <orderEntry type="library" name="Maven: xerces:xercesImpl:2.11.0" level="project" /> - <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" /> - <orderEntry type="library" name="Maven: xml-apis:xmlParserAPIs:2.0.2" level="project" /> - <orderEntry type="library" name="Maven: commons-validator:commons-validator:1.3.0" level="project" /> - <orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.7.0" level="project" /> - <orderEntry type="library" name="Maven: commons-digester:commons-digester:1.6" level="project" /> - <orderEntry type="library" name="Maven: oro:oro:2.0.8" level="project" /> - <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" /> - <orderEntry type="library" name="Maven: org.jfree:jfreechart:1.0.19" level="project" /> - <orderEntry type="library" name="Maven: org.jfree:jcommon:1.0.23" level="project" /> - <orderEntry type="module-library"> - <library name="Maven: org.cewolf:cewolf:1.1"> - <CLASSES> - <root url="jar://$MODULE_DIR$/WebRoot/WEB-INF/lib/cewolf-1.1.jar!/" /> - </CLASSES> - <JAVADOC /> - <SOURCES /> - </library> - </orderEntry> - <orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:3.0.1" level="project" /> - <orderEntry type="library" name="Maven: net.jcip:jcip-annotations:1.0" level="project" /> - <orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.1" level="project" /> - <orderEntry type="library" name="Maven: httpunit:httpunit:1.7" level="project" /> - <orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.3" level="project" /> - <orderEntry type="library" name="Maven: jtidy:jtidy:4aug2000r7-dev" level="project" /> - <orderEntry type="library" name="Maven: org.easymock:easymock:2.5.2" level="project" /> - <orderEntry type="library" name="Maven: org.easymock:easymockclassextension:2.5.2" level="project" /> - <orderEntry type="library" name="Maven: org.objenesis:objenesis:1.2" level="project" /> - <orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-util:8.0.28" level="project" /> - <orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-juli:8.0.28" level="project" /> - <orderEntry type="library" name="Maven: tomcat:jasper-runtime:5.5.23" level="project" /> - <orderEntry type="library" name="Maven: commons-el:commons-el:1.0" level="project" /> - <orderEntry type="library" name="Maven: org.apache.tomcat:dbcp:6.0.44" level="project" /> - <orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.37" level="project" /> - <orderEntry type="library" name="Maven: junit:junit:4.12" level="project" /> - <orderEntry type="library" name="Maven: commons-fileupload:commons-fileupload:1.3" level="project" /> - <orderEntry type="library" name="Maven: net.tanesha.recaptcha4j:recaptcha4j:0.0.7" level="project" /> - </component> -</module> \ No newline at end of file diff --git a/iTrust/sql/createTables.sql b/iTrust/sql/createTables.sql index 7bea2bac04332e8a76c7722720f1d76bea19402e..9ea7d15c38a6ec9879e8359f5349e6d277a8ba8c 100644 --- a/iTrust/sql/createTables.sql +++ b/iTrust/sql/createTables.sql @@ -47,6 +47,7 @@ CREATE TABLE personnel( phone varchar(12) NOT NULL default '', specialty varchar(40) default NULL, email varchar(55) default '', + MessageFilter varchar(200) default '', PRIMARY KEY (MID) ) auto_increment=9000000000 ENGINE=MyISAM; @@ -88,6 +89,7 @@ CREATE TABLE patients( SpiritualPractices varchar(512) default '', AlternateName varchar(32) default '', DateOfDeactivation DATE default NULL, + MessageFilter varchar(200) default '', PRIMARY KEY (MID) ) ENGINE=MyISAM; @@ -132,6 +134,7 @@ CREATE TABLE historypatients( SpiritualPractices varchar(512) default '', AlternateName varchar(32) default '', DateOfDeactivation DATE default NULL, + MessageFilter varchar(200) default '', PRIMARY KEY (ID) ) ENGINE=MyISAM; diff --git a/iTrust/src/edu/ncsu/csc/itrust/action/EditPatientAction.java b/iTrust/src/edu/ncsu/csc/itrust/action/EditPatientAction.java index 5ceaefb0faa1696e2575d8d321fed8ff95d6464c..0a3ea13b6dd50212254c0767612ca1753a0c5940 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/action/EditPatientAction.java +++ b/iTrust/src/edu/ncsu/csc/itrust/action/EditPatientAction.java @@ -163,4 +163,16 @@ public class EditPatientAction extends PatientBaseAction { return true; } -} + + /** + * Updates patient info to filter + * @param nf The filter + * @throws ITrustException + * @throws FormValidationException + */ + public void editMessageFilter(String nf) throws ITrustException, FormValidationException { + PatientBean p = patientDAO.getPatient(this.getPid()); + p.setMessageFilter(nf); + this.updateInformation(p); + } +} \ No newline at end of file diff --git a/iTrust/src/edu/ncsu/csc/itrust/action/EditPersonnelAction.java b/iTrust/src/edu/ncsu/csc/itrust/action/EditPersonnelAction.java index 0d04d6e920b0bb185b497fe11062256c882a9684..01b6f147afedb2ef12240286e0f28f9431dc5bcb 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/action/EditPersonnelAction.java +++ b/iTrust/src/edu/ncsu/csc/itrust/action/EditPersonnelAction.java @@ -60,5 +60,17 @@ public class EditPersonnelAction extends PersonnelBaseAction { validator.validate(personnelForm); personnelDAO.editPersonnel(personnelForm); } + + /** + * Updates the personnel info to filter + * @param fn The filter + * @throws ITrustException + * @throws FormValidationException + */ + public void editMessageFilter(String nf) throws ITrustException, FormValidationException { + PersonnelBean p = personnelDAO.getPersonnel(this.getPid()); + p.setMessageFilter(nf); + this.updateInformation(p); + } } diff --git a/iTrust/src/edu/ncsu/csc/itrust/action/SendRemindersAction.java b/iTrust/src/edu/ncsu/csc/itrust/action/SendRemindersAction.java new file mode 100644 index 0000000000000000000000000000000000000000..ef8b0597ed3a9bfcdec4d7c3a3c92257ba418464 --- /dev/null +++ b/iTrust/src/edu/ncsu/csc/itrust/action/SendRemindersAction.java @@ -0,0 +1,67 @@ +package edu.ncsu.csc.itrust.action; + +import java.sql.SQLException; +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; + +import edu.ncsu.csc.itrust.beans.ApptBean; +import edu.ncsu.csc.itrust.beans.MessageBean; +import edu.ncsu.csc.itrust.beans.PersonnelBean; +import edu.ncsu.csc.itrust.dao.DAOFactory; +import edu.ncsu.csc.itrust.dao.mysql.ApptDAO; +import edu.ncsu.csc.itrust.dao.mysql.PersonnelDAO; +import edu.ncsu.csc.itrust.exception.DBException; +import edu.ncsu.csc.itrust.exception.FormValidationException; +import edu.ncsu.csc.itrust.exception.ITrustException; +import java.util.*; + +public class SendRemindersAction { + public final long systemReminderMID; + private long loggedInMID; + private ApptDAO apptDAO; + private SendMessageAction smAction; + + public SendRemindersAction(DAOFactory factory, long loggedInMID) throws DBException { + PersonnelDAO personnelDAO = factory.getPersonnelDAO(); + List<PersonnelBean> personnels = personnelDAO.searchForPersonnelWithName("System", "Reminder"); + this.systemReminderMID = personnels.get(0).getMID(); + this.loggedInMID = loggedInMID; + this.apptDAO = factory.getApptDAO(); + this.smAction = new SendMessageAction(factory, systemReminderMID); + } + + public void sendReminder(ApptBean aBean) throws ITrustException, SQLException, FormValidationException { + LocalDateTime now = LocalDateTime.now(); + LocalDateTime date = aBean.getDate().toLocalDateTime(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm, MMM d"); + + MessageBean message = new MessageBean(); + message.setTo(aBean.getPatient()); + message.setFrom(systemReminderMID); + message.setSubject(String.format("Reminder: upcoming appointment in %d day(s)", now.truncatedTo(ChronoUnit.DAYS).until(date.truncatedTo(ChronoUnit.DAYS), ChronoUnit.DAYS))); + message.setBody(String.format("You have an appointment on %s with Dr. %s", date.format(formatter), smAction.getPersonnelName(aBean.getHcp()))); + message.setSentDate(Timestamp.valueOf(now)); + + smAction.sendMessage(message); + } + + public int sendReminderForAppointments(int numDays) throws ITrustException { + List<ApptBean> appointments = null; + try { + appointments = apptDAO.getUpcomingAppts(numDays); + for (ApptBean appt : appointments) { + sendReminder(appt); + } + return appointments.size(); + } catch (DBException e) { + throw new ITrustException("DB Error in sending reminders."); + } catch (SQLException e) { + throw new ITrustException("SQL Error in sending reminders."); + } catch (FormValidationException e) { + throw new ITrustException("Form Validation Error in sending reminders."); + } + + } +} \ No newline at end of file diff --git a/iTrust/src/edu/ncsu/csc/itrust/action/ViewDiagnosisStatisticsAction.java b/iTrust/src/edu/ncsu/csc/itrust/action/ViewDiagnosisStatisticsAction.java index a6f01b269e3e19cbf648a58e302193fedb13b238..8b04b6b50040678b230f8ab4480197ba9caac70f 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/action/ViewDiagnosisStatisticsAction.java +++ b/iTrust/src/edu/ncsu/csc/itrust/action/ViewDiagnosisStatisticsAction.java @@ -182,36 +182,32 @@ public class ViewDiagnosisStatisticsAction { /** * Determines if an Influenza Epidemic is happening * - * @param curDateStr a date in the currently evaluated week + * @param weekDate a date in the currently evaluated week * @param zip the zip code to analyze * @return whether or not there is an epidemic * @throws ParseException * @throws DBException */ - public boolean isFluEpidemic(String curDateStr, String zip) throws ParseException, DBException { - new SimpleDateFormat("MM/dd/yyyy").parse("01/04/1998"); - Date curDate = new SimpleDateFormat("MM/dd/yyyy").parse(curDateStr); + public boolean isFluEpidemic(String weekDate, String zip) throws ParseException, DBException { + Date wkDate = new SimpleDateFormat("MM/dd/yyyy").parse(weekDate); Calendar cal = Calendar.getInstance(); - cal.setTime(curDate); + cal.setTime(wkDate); int weekOfYr = cal.get(Calendar.WEEK_OF_YEAR); - double threshold = calcThreshold(weekOfYr); - double thresholdL = calcThreshold(weekOfYr-1); - double thresholdN = calcThreshold(weekOfYr+1); - - DiagnosisStatisticsBean dbNow = diagnosesDAO.getCountForWeekOf(ICD_INFLUENZA, zip, cal.getTime()); - cal.add(Calendar.HOUR, -12*7); - DiagnosisStatisticsBean dbLast = diagnosesDAO.getCountForWeekOf(ICD_INFLUENZA, zip, cal.getTime()); - cal.add(Calendar.HOUR, 2*12*7); - DiagnosisStatisticsBean dbNext = diagnosesDAO.getCountForWeekOf(ICD_INFLUENZA, zip, cal.getTime()); - - double weekNow = (double) dbNow.getRegionStats(); - double weekL = (double) dbLast.getRegionStats(); - double weekN = (double) dbNext.getRegionStats(); - - return weekNow > threshold && (weekL > thresholdL || weekN > thresholdN); + double threshold = calcInfluenzaThreshold(weekOfYr); + + DiagnosisStatisticsBean prev1 = diagnosesDAO.getCountForWeekBefore(ICD_INFLUENZA, zip, cal.getTime()); + cal.add(Calendar.HOUR, -7*24); + DiagnosisStatisticsBean prev2 = diagnosesDAO.getCountForWeekBefore(ICD_INFLUENZA, zip, cal.getTime()); + + long weekL1 = prev1.getRegionStats(); + long weekL2 = prev2.getRegionStats(); + + boolean epidemicL1 = weekL1 > threshold; + boolean epidemicL2 = weekL2 > threshold; + return epidemicL1 && epidemicL2; } /** @@ -220,7 +216,7 @@ public class ViewDiagnosisStatisticsAction { * @param weekNumber the week of the year * @return the epidemic threshold for flu cases */ - private double calcThreshold(double weekNumber) { + private double calcInfluenzaThreshold(double weekNumber) { return 5.34 + 0.271 * weekNumber + 3.45 * Math.sin(2 * Math.PI * weekNumber / 52.0) + 8.41 * Math.cos(2 * Math.PI * weekNumber / 52.0); } diff --git a/iTrust/src/edu/ncsu/csc/itrust/action/ViewMyMessagesAction.java b/iTrust/src/edu/ncsu/csc/itrust/action/ViewMyMessagesAction.java index 9d5305774af378140785b598d32631d3b0909ee1..57c5f9d0aef86503ac5cb732bc0550e0c360a469 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/action/ViewMyMessagesAction.java +++ b/iTrust/src/edu/ncsu/csc/itrust/action/ViewMyMessagesAction.java @@ -135,7 +135,7 @@ public class ViewMyMessagesAction { /** - * Gets a list of messages for a user based on their filter criteria. + * Gets a list of received messages for a user based on their filter criteria. * * @param messages List of all of a user's MessageBeans * @param filter String containing a user's filter criteria. @@ -222,6 +222,94 @@ public class ViewMyMessagesAction { return filtered; } + /** + * Gets a list of Sent messages for a user based on their filter criteria. + * + * @param messages List of all of a user's MessageBeans + * @param filter String containing a user's filter criteria. + * @return a List of MessageBeans that meet the criteria of the filter. + * @throws ITrustException + * @throws ParseException + */ + public List<MessageBean> filterSentMessages(List<MessageBean> messages, String filter) throws ITrustException, ParseException { + List<MessageBean> filtered = new ArrayList<MessageBean>(); + String[] f = filter.split(",", -1); + for(MessageBean m : messages) { + /** + * Check the sender filter field. + * Exclude if this MessageBean does not match the + * requested sender, if one is specified. + */ + if(!f[0].equals("")) { + if(!this.getName(m.getTo()).equalsIgnoreCase(f[0])) + continue; + } + /** + * Check the subject filter field. + * Exclude if this MessageBean does not match the + * requested subject, if one is specified. + */ + if(!f[1].equals("")) { + if(!m.getSubject().equalsIgnoreCase(f[1])) + continue; + } + /** + * Check the body of the message for certain words. + * Exclude if this MessageBean if it does not contain + * those words in the message body. + */ + if(!f[2].equals("")) { + if(!m.getSubject().toLowerCase().contains(f[2].toLowerCase()) && !m.getBody().toLowerCase().contains(f[2].toLowerCase())) + continue; + } + /** + * Check the body of the message for certain words. + * Exclude if this MessageBean if it does contain + * those words in the message body. + */ + if(!f[3].equals("")) { + if(m.getSubject().toLowerCase().contains(f[3].toLowerCase()) || m.getBody().toLowerCase().contains(f[3].toLowerCase())) + continue; + } + /** + * Check the start date filter field. + * Exclude if this MessageBean was not sent after + * this date. + */ + if(!f[4].equals("")) { + DateFormat format = new SimpleDateFormat("MM/dd/yyyy"); + Date s = format.parse(f[4]); + if(s.after(m.getSentDate())) + continue; + + } + /** + * Check the end date filter field. + * Exclude if this MessageBean was not sent before + * this date. + */ + if(!f[5].equals("")) { + DateFormat format = new SimpleDateFormat("MM/dd/yyyy"); + Date s = format.parse(f[5]); + Calendar c = Calendar.getInstance(); + c.setTime(s); + c.add(Calendar.DAY_OF_MONTH, 1); + s = c.getTime(); + if(s.before(m.getSentDate())) + continue; + + } + /** + * If the message has not been eliminated by any + * of the filter fields, add it to the new list + * of messages. + */ + filtered.add(m); + } + + return filtered; + } + /** * Gets a patient's name from their MID * diff --git a/iTrust/src/edu/ncsu/csc/itrust/beans/PatientBean.java b/iTrust/src/edu/ncsu/csc/itrust/beans/PatientBean.java index 64b8b0f1321272964cf6c18a200b62e18bed5a38..a563644763999f613610fe249348658345eb9eed 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/beans/PatientBean.java +++ b/iTrust/src/edu/ncsu/csc/itrust/beans/PatientBean.java @@ -61,7 +61,15 @@ public class PatientBean implements Serializable, Comparable<PatientBean> { private String spiritualPractices = ""; private String alternateName = ""; private String dateOfDeactivationStr = ""; + private String messageFilter= ""; + public void setMessageFilter(String nf) { + this.messageFilter = nf; + } + + public String getMessageFilter(){ + return messageFilter; + } public BloodType getBloodType() { return bloodType; diff --git a/iTrust/src/edu/ncsu/csc/itrust/beans/PersonnelBean.java b/iTrust/src/edu/ncsu/csc/itrust/beans/PersonnelBean.java index a073981b3b15cf1e7c52cea3831bf2012aa5e97f..efc86b2db1ea0d599ce2b8f5c941b7c21d6a46c3 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/beans/PersonnelBean.java +++ b/iTrust/src/edu/ncsu/csc/itrust/beans/PersonnelBean.java @@ -32,6 +32,15 @@ public class PersonnelBean implements Serializable { private String phone = ""; private String email = ""; private String specialty = ""; + private String messageFilter= ""; + + public String getMessageFilter(){ + return messageFilter; + } + + public void setMessageFilter(String nf) { + this.messageFilter = nf; + } public String getEmail() { return email; diff --git a/iTrust/src/edu/ncsu/csc/itrust/beans/loaders/PatientLoader.java b/iTrust/src/edu/ncsu/csc/itrust/beans/loaders/PatientLoader.java index 8b6c152a65e6b8c4415ec2c9ce52506e72fc2677..ff90037c3b102b9cbae249ea09c4b37e39ddf84d 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/beans/loaders/PatientLoader.java +++ b/iTrust/src/edu/ncsu/csc/itrust/beans/loaders/PatientLoader.java @@ -80,6 +80,7 @@ public class PatientLoader implements BeanLoader<PatientBean> { if (dateOfDeactivation != null){ p.setDateOfDeactivationStr(DATE_FORMAT.format(dateOfDeactivation)); } + p.setMessageFilter(rs.getString("MessageFilter")); } /** @@ -188,6 +189,7 @@ public class PatientLoader implements BeanLoader<PatientBean> { } } ps.setDate(i++, date); + ps.setString(i++, p.getMessageFilter()); return ps; } } diff --git a/iTrust/src/edu/ncsu/csc/itrust/beans/loaders/PersonnelLoader.java b/iTrust/src/edu/ncsu/csc/itrust/beans/loaders/PersonnelLoader.java index 5cfa62a8945db1b783943796ed0dd228be7c1132..cf40b7b6db65b854836232d84834fb8095db25ff 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/beans/loaders/PersonnelLoader.java +++ b/iTrust/src/edu/ncsu/csc/itrust/beans/loaders/PersonnelLoader.java @@ -37,6 +37,7 @@ public class PersonnelLoader implements BeanLoader<PersonnelBean> { p.setZip((rs.getString("zip"))); p.setEmail(rs.getString("email")); p.setSpecialty(rs.getString("specialty")); + p.setMessageFilter(rs.getString("MessageFilter")); return p; } @@ -53,6 +54,7 @@ public class PersonnelLoader implements BeanLoader<PersonnelBean> { ps.setString(i++, p.getZip()); ps.setString(i++, p.getSpecialty()); ps.setString(i++, p.getEmail()); + ps.setString(i++, p.getMessageFilter()); return ps; } } diff --git a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/ApptDAO.java b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/ApptDAO.java index 056528376184ac2e813fc4b9af7f2361862398c6..7b91089e577109761c010f43d9c6ddbb65f0becf 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/ApptDAO.java +++ b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/ApptDAO.java @@ -328,5 +328,35 @@ public class ApptDAO { } + } + + /** + * Get all upcoming appointments within n days + * @param numDays Number of days after current date within which to find all appointments + * @return ApptBean List of upcoming appointments + */ + public List<ApptBean> getUpcomingAppts(int numDays) throws SQLException, DBException { + Connection conn = null; + PreparedStatement pstring = null; + try { + conn = factory.getConnection(); + + pstring = conn.prepareStatement( + "SELECT * FROM appointment WHERE " + /*" sched_date.after(?)=TRUE AND sched_date.before(?)=TRUE");*/ + "DATE(sched_date)<=DATE_ADD(CURRENT_DATE, INTERVAL ? DAY) AND " + //sched_date day is before or at (numDays) days from now + "sched_date>=CURRENT_DATE"); // sched_date is after today + + pstring.setInt(1, numDays); + + final ResultSet results = pstring.executeQuery(); + final List<ApptBean> abList = this.abloader.loadList(results); + results.close(); + pstring.close(); + return abList; + } catch (SQLException e) { + throw new DBException(e); + } finally { + DBUtil.closeConnection(conn, pstring); + } } } diff --git a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PatientDAO.java b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PatientDAO.java index c4ae1861a3b0dc1fc7e63b3028e9f1b35aeb6ec9..9b71f8658f824b65fa4d6661f4dc2a0e6b99335b 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PatientDAO.java +++ b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PatientDAO.java @@ -208,10 +208,10 @@ public class PatientDAO { + "DateOfDeath=?,CauseOfDeath=?,MotherMID=?,FatherMID=?," + "BloodType=?,Ethnicity=?,Gender=?,TopicalNotes=?, CreditCardType=?, CreditCardNumber=?, " + "DirectionsToHome=?, Religion=?, Language=?, SpiritualPractices=?, " - + "AlternateName=?, DateOfDeactivation=? WHERE MID=?"); + + "AlternateName=?, DateOfDeactivation=?, MessageFilter=? WHERE MID=?"); patientLoader.loadParameters(ps, p); - ps.setLong(37, p.getMID()); + ps.setLong(38, p.getMID()); ps.executeUpdate(); addHistory(p.getMID(), hcpid); diff --git a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PersonnelDAO.java b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PersonnelDAO.java index 126208df9b58ff12f8f1c7f1ed0a34ebf50cb19d..f727a316a9668dac8a6ad6c29f3c401f11ee63fd 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PersonnelDAO.java +++ b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PersonnelDAO.java @@ -195,10 +195,10 @@ public class PersonnelDAO { try { conn = factory.getConnection(); pstmt = conn.prepareStatement("UPDATE personnel SET AMID=?,firstName=?,lastName=?," - + "phone=?, address1=?,address2=?,city=?, state=?, zip=?, specialty=?, email=?" - + " WHERE MID=?"); + + "phone=?, address1=?,address2=?,city=?, state=?, zip=?, specialty=?, email=?, " + + "MessageFilter=? WHERE MID=?"); personnelLoader.loadParameters(pstmt, pBean); - pstmt.setLong(12, pBean.getMID()); + pstmt.setLong(13, pBean.getMID()); pstmt.executeUpdate(); pstmt.close(); } catch (SQLException e) { diff --git a/iTrust/test/edu/ncsu/csc/itrust/selenium/MessageFilterTest.java b/iTrust/test/edu/ncsu/csc/itrust/selenium/MessageFilterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..cf3a08d4823c01b0b9f056d6eb434248dd38999d --- /dev/null +++ b/iTrust/test/edu/ncsu/csc/itrust/selenium/MessageFilterTest.java @@ -0,0 +1,120 @@ +package edu.ncsu.csc.itrust.selenium; + +import edu.ncsu.csc.itrust.enums.TransactionType; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; + +import java.util.concurrent.TimeUnit; + +public class MessageFilterTest extends iTrustSeleniumTest { + private WebDriver driver; + private StringBuffer verificationErrors = new StringBuffer(); + + @Before + public void setUp() throws Exception { + super.setUp(); + gen.standardData(); + driver = new HtmlUnitDriver(); + driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); + } + + @Test + public void testEditFilter() throws Exception { + + // This logs us into iTrust and returns the HtmlUnitDriver for use in + HtmlUnitDriver driver = (HtmlUnitDriver)login("9000000000", "pw"); + + // Make sure we were able to log in + assertEquals("iTrust - HCP Home", driver.getTitle()); + driver.findElement(By.cssSelector("h2.panel-title")).click(); + driver.findElement(By.linkText("Message Inbox")).click(); + assertLogged(TransactionType.INBOX_VIEW, 9000000000L, 0L, ""); + String text = driver.findElement(By.cssSelector("table.fancyTable")).getText(); + assertTrue("Text not found!", text.contains("Random Person")); + assertTrue("Text not found!", text.contains("Andy Programmer")); + + driver.findElement(By.linkText("Edit Filter")).click(); + driver.findElementById("subject").sendKeys("Scratchy Throat"); + + driver.findElement(By.xpath("//input[@name='save']")).click(); + text = driver.findElement(By.cssSelector("table.fancyTable")).getText(); + assertTrue("Text not found!", text.contains("Scratchy Throat")); + assertFalse("Text found!", text.contains("Missed Appointment")); + + } + + @Test + public void testFilterPersistence() throws Exception { + + // This logs us into iTrust and returns the HtmlUnitDriver for use in + HtmlUnitDriver driver = (HtmlUnitDriver)login("9000000000", "pw"); + + // Make sure we were able to log in + assertEquals("iTrust - HCP Home", driver.getTitle()); + driver.findElement(By.cssSelector("h2.panel-title")).click(); + driver.findElement(By.linkText("Message Outbox")).click(); + assertLogged(TransactionType.OUTBOX_VIEW, 9000000000L, 0L, ""); + String text = driver.findElement(By.cssSelector("table.fancyTable")).getText(); + assertTrue("Text not found!", text.contains("Random Person")); + assertTrue("Text not found!", text.contains("Andy Programmer")); + + driver.findElement(By.linkText("Edit Filter")).click(); + driver.findElementById("subject").sendKeys("Scratchy Throat"); + + driver.findElement(By.xpath("//input[@name='save']")).click(); + driver.findElement(By.linkText("Edit Filter")).click(); + text = driver.findElementById("subject").getAttribute("value"); + assertTrue("Filters are not persistent from page to page", text.contains("Scratchy Throat")); + + driver.findElement(By.xpath("//a[@href='/iTrust/logout.jsp']")).click(); + assertEquals("iTrust - Login", driver.getTitle()); + + // Check if it's persistent between sessions + HtmlUnitDriver driver2 = (HtmlUnitDriver)login("9000000000", "pw"); + + assertEquals("iTrust - HCP Home", driver2.getTitle()); + driver2.findElement(By.cssSelector("h2.panel-title")).click(); + driver2.findElement(By.linkText("Message Outbox")).click(); + + // Don't insert anything, just check what's already inputted + driver2.findElement(By.linkText("Edit Filter")).click(); + text = driver2.findElementById("subject").getAttribute("value"); + assertTrue("Filters are not persistent between sessions", text.contains("Scratchy Throat")); + } + + @Test + public void testSortMessages() throws Exception { + + // This logs us into iTrust and returns the HtmlUnitDriver for use in + HtmlUnitDriver driver = (HtmlUnitDriver)login("9000000000", "pw"); + + // Make sure we were able to log in + assertEquals("iTrust - HCP Home", driver.getTitle()); + driver.findElement(By.cssSelector("h2.panel-title")).click(); + driver.findElement(By.linkText("Message Inbox")).click(); + assertLogged(TransactionType.INBOX_VIEW, 9000000000L, 0L, ""); + String text = driver.findElement(By.cssSelector("table.fancyTable")).getText(); + + assertTrue("Text not found!", text.contains("Random Person")); + assertTrue("Text not found!", text.contains("Andy Programmer")); + + driver.findElement(By.xpath("//option[text()='Name']")).click(); + driver.findElement(By.xpath("//option[text()='Ascending']")).click(); + driver.findElement(By.xpath("//input[@name='sort']")).click(); + + text = driver.findElement(By.cssSelector("table.fancyTable")).getText(); + String first = text.split("Read")[0]; + + // This should be the first in reverse alphabetical order + assertTrue("Text not found!", first.contains("Random Person")); + } + + @After + public void tearDown() throws Exception { + driver.quit(); + } +} diff --git a/iTrust/test/edu/ncsu/csc/itrust/selenium/SendRemindersTest.java b/iTrust/test/edu/ncsu/csc/itrust/selenium/SendRemindersTest.java new file mode 100644 index 0000000000000000000000000000000000000000..6dfa3c967de80820686df6ee01c8aa548772a4af --- /dev/null +++ b/iTrust/test/edu/ncsu/csc/itrust/selenium/SendRemindersTest.java @@ -0,0 +1,97 @@ +package edu.ncsu.csc.itrust.selenium; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +public class SendRemindersTest extends iTrustSeleniumTest{ + + protected WebDriver driver; + + @Override + protected void setUp() throws Exception { + super.setUp(); + gen.clearAllTables(); + gen.standardData(); + } + + // Test sending reminders + public void testSendReminder() throws Exception { + // Login as admin + driver = login("9000000001", "pw"); + assertEquals("iTrust - Admin Home", driver.getTitle()); + driver.findElement(By.linkText("Send Appointment Reminders")).click(); + + // Send reminders + driver.findElement(By.name("withinDays")).sendKeys("10"); + driver.findElement(By.name("withinDays")).submit(); + assertEquals("Reminders were successfully sent", + driver.findElement(By.className("iTrustMessage")).getText()); + + // Create timestamp + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + Date date = new Date(); + String stamp = dateFormat.format(date); + + // Check admin reminders outbox + driver.findElement(By.linkText("Reminder Message Outbox")).click(); + assertNotNull(driver.findElement(By.className("fancyTable"))); + assertTrue(driver.getPageSource().contains(stamp)); + + // Check a reminder message + driver.findElement(By.linkText("Read")).click(); + assertTrue(driver.getPageSource().contains(stamp)); + + // Logout admin and login as patient + List<WebElement> links = driver.findElements(By.tagName("a")); + int count = 0; + for(int i = 0; i < links.size(); i++) { + if(links.get(i).getAttribute("href").contains("logout")) + { + count = i; + break; + } + } + links.get(count).click(); + driver = login("5", "pw"); + + // Check patient inbox + driver.findElement(By.linkText("Message Inbox")).click(); + int index = 1; + WebElement baseTable = driver.findElement(By.cssSelector(".display.fTable")); + List<WebElement> tableRows = baseTable.findElements(By.tagName("tr")); + assertTrue(tableRows.get(index).getText().contains("System Reminder")); + assertTrue(tableRows.get(index).getText().contains("Reminder: upcoming appointment")); + index++; + assertTrue(tableRows.get(index).getText().contains("Reminder: upcoming appointment")); + assertTrue(tableRows.get(index).getText().contains(stamp)); + } + + // Test invalid number of days input for sending reminders + public void testInvalidSendReminder() throws Exception { + + // Login as admin + driver = login("9000000001", "pw"); + assertEquals("iTrust - Admin Home", driver.getTitle()); + driver.findElement(By.linkText("Send Appointment Reminders")).click(); + + // Send reminder with negative days + driver.findElement(By.name("withinDays")).sendKeys("-4"); + driver.findElement(By.name("withinDays")).submit(); + assertEquals("Provide a positive number", + driver.findElement(By.className("iTrustError")).getText()); + + // Send reminder with non-numberic days + driver.findElement(By.name("withinDays")).sendKeys("Hello"); + driver.findElement(By.name("withinDays")).submit(); + assertEquals("Reminders failed to send. Please provide a positive number", + driver.findElement(By.className("iTrustError")).getText()); + } + + + + +} \ No newline at end of file diff --git a/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewDiagnosisStatisticsTest.java b/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewDiagnosisStatisticsTest.java index 1dd3d14fdb8b11d7a1b72b34a8811c95583e7094..cc69e4c816b71efecf16b19d590356007cc3ab12 100644 --- a/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewDiagnosisStatisticsTest.java +++ b/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewDiagnosisStatisticsTest.java @@ -559,50 +559,61 @@ public class ViewDiagnosisStatisticsTest extends iTrustSeleniumTest { assertLogged(TransactionType.DIAGNOSIS_EPIDEMICS_VIEW, 9000000007L, 0L, ""); assertTrue(driver.getPageSource().contains("There is no epidemic occurring in the region.")); } - - public void testViewDiagnosisEpidemics_ErrorFlows() throws Exception { - driver = (HtmlUnitDriver)login("9000000007", "pw"); + + private void setupErrorFlow(String icd, String zip, String date, String threshold) throws Exception { + driver = (HtmlUnitDriver)login("9000000007", "pw"); // Click Diagnosis Trends driver.findElement(By.cssSelector("h2.panel-title")).click(); driver.findElement(By.xpath("//div[@class='panel-body']/ul/li[11]")).click(); driver.findElement(By.linkText("Diagnosis Trends")).click(); - // Epidemics + // Go to epidemics assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp-pha/viewDiagnosisStatistics.jsp")); new Select(driver.findElement(By.name("viewSelect"))).selectByValue("epidemics"); driver.findElement(By.id("select_View")).click(); - - // No ICD code - driver.findElement(By.name("zipCode")).clear(); - driver.findElement(By.name("zipCode")).sendKeys("27607"); - driver.findElement(By.name("startDate")).clear(); - driver.findElement(By.name("startDate")).sendKeys("02/15/2010"); - driver.findElement(By.name("threshold")).sendKeys("110"); + + // Fill provided fields + if (icd != null) { + new Select(driver.findElement(By.name("icdCode"))).selectByVisibleText(icd); + } + + if (zip != null) { + driver.findElement(By.name("zipCode")).clear(); + driver.findElement(By.name("zipCode")).sendKeys(zip); + } + + if (date != null) { + driver.findElement(By.name("startDate")).clear(); + driver.findElement(By.name("startDate")).sendKeys(date); + } + + if (threshold != null) { + driver.findElement(By.name("threshold")).clear(); + driver.findElement(By.name("threshold")).sendKeys(threshold); + } + + // Submit driver.findElement(By.id("select_diagnosis")).click(); + } + + public void testViewDiagnosisEpidemicsNoICD() throws Exception { + setupErrorFlow(null, "27607", "02/15/2010", "110"); assertTrue(driver.getPageSource().contains("Invalid ICD code.")); - - // Invalid zip - new Select(driver.findElement(By.name("icdCode"))).selectByVisibleText("84.50 - Malaria"); - driver.findElement(By.name("zipCode")).clear(); - driver.findElement(By.name("zipCode")).sendKeys("asdf"); - driver.findElement(By.id("select_diagnosis")).click(); + } + + public void testViewDiagnosisEpidemicsBadZip() throws Exception { + setupErrorFlow("84.50 - Malaria", "asdf", "02/15/2010", "110"); assertTrue(driver.getPageSource().contains("Zip Code must be 5 digits!")); + } - // Invalid date - driver.findElement(By.name("startDate")).clear(); - driver.findElement(By.name("startDate")).sendKeys("asdf"); - driver.findElement(By.name("zipCode")).clear(); - driver.findElement(By.name("zipCode")).sendKeys("27607"); - driver.findElement(By.id("select_diagnosis")).click(); + public void testViewDiagnosisEpidemicsInvalidDate() throws Exception { + setupErrorFlow("84.50 - Malaria", "12345", "asdf", "110"); assertTrue(driver.getPageSource().contains("Enter dates in MM/dd/yyyy")); + } - // Invalid threshold - driver.findElement(By.name("threshold")).clear(); - driver.findElement(By.name("threshold")).sendKeys("asdf"); - driver.findElement(By.name("startDate")).clear(); - driver.findElement(By.name("startDate")).sendKeys("02/15/2010"); - driver.findElement(By.id("select_diagnosis")).click(); + public void testViewDiagnosisEpidemicsBadThreshold() throws Exception { + setupErrorFlow("84.50 - Malaria", "12345", "02/15/2010", "asdf"); assertTrue(driver.getPageSource().contains("Threshold must be an integer.")); } } \ No newline at end of file diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/action/EditPatientActionTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/action/EditPatientActionTest.java index bfb5d9e6c329e7b979d641f9ebb3897f114d6ae2..15b1bde8e67276c4cca369bb0072e570b6589bd9 100644 --- a/iTrust/test/edu/ncsu/csc/itrust/unit/action/EditPatientActionTest.java +++ b/iTrust/test/edu/ncsu/csc/itrust/unit/action/EditPatientActionTest.java @@ -10,6 +10,7 @@ import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import edu.ncsu.csc.itrust.exception.FormValidationException; +import org.junit.Test; public class EditPatientActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); @@ -170,4 +171,20 @@ public class EditPatientActionTest extends TestCase { //Check that patient 2 is not a dependent assertFalse(authDAO.isDependent(2L)); } + + /** + * Test that the filter will persist at the database level + * + * @throws Exception + * + */ + public void testEditMessageFilter() throws Exception { + PatientDAO patientDAO = new PatientDAO(factory); + PatientBean p = patientDAO.getPatient(2); + assertEquals("", p.getMessageFilter()); + + String newFilter = "2,,,,,"; + action.editMessageFilter(newFilter); + assertEquals(newFilter, patientDAO.getPatient(2).getMessageFilter()); + } } diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/action/EditPersonnelActionTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/action/EditPersonnelActionTest.java index 5f6b403861ae8ae4f717dcd5fb062567feba533b..d984fab1a3ac2246797c6d0c28d03fb0be560ff6 100644 --- a/iTrust/test/edu/ncsu/csc/itrust/unit/action/EditPersonnelActionTest.java +++ b/iTrust/test/edu/ncsu/csc/itrust/unit/action/EditPersonnelActionTest.java @@ -1,5 +1,8 @@ package edu.ncsu.csc.itrust.unit.action; +import edu.ncsu.csc.itrust.beans.PatientBean; +import edu.ncsu.csc.itrust.dao.mysql.PatientDAO; +import edu.ncsu.csc.itrust.dao.mysql.PersonnelDAO; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.EditPersonnelAction; import edu.ncsu.csc.itrust.beans.PersonnelBean; @@ -77,6 +80,22 @@ public class EditPersonnelActionTest extends TestCase { j = factory.getPersonnelDAO().getPersonnel(8000000009l); assertEquals("second line", j.getStreetAddress2()); } - - + + /** + * Test that the filter will persist at the database level + * + * @throws Exception + * + */ + public void testEditMessageFilter() throws Exception { + gen.uap1(); + personnelEditor = new EditPersonnelAction(factory, 8000000009L, "8000000009"); + PersonnelDAO personnelDAO = new PersonnelDAO(factory); + PersonnelBean p = personnelDAO.getPersonnel(8000000009L); + assertEquals("", p.getMessageFilter()); + + String newFilter = "2,,,,,"; + personnelEditor.editMessageFilter(newFilter); + assertEquals(newFilter, personnelDAO.getPersonnel(8000000009L).getMessageFilter()); + } } diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/action/SendRemindersActionTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/action/SendRemindersActionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..a91f84a430de111b88d1f79c3fb46a51fb3b509c --- /dev/null +++ b/iTrust/test/edu/ncsu/csc/itrust/unit/action/SendRemindersActionTest.java @@ -0,0 +1,68 @@ +package edu.ncsu.csc.itrust.unit.action; + +import edu.ncsu.csc.itrust.action.SendRemindersAction; +import edu.ncsu.csc.itrust.beans.ApptBean; +import edu.ncsu.csc.itrust.beans.MessageBean; +import edu.ncsu.csc.itrust.dao.DAOFactory; +import edu.ncsu.csc.itrust.dao.mysql.MessageDAO; +import edu.ncsu.csc.itrust.exception.FormValidationException; +import edu.ncsu.csc.itrust.exception.ITrustException; +import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; +import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; +import junit.framework.TestCase; + +import java.sql.SQLException; +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.util.List; + + +public class SendRemindersActionTest extends TestCase { + + private DAOFactory factory; + private MessageDAO messageDAO; + private SendRemindersAction srAction; + private TestDataGenerator gen; + private long patientId; + private long hcpId; + + @Override + protected void setUp() throws Exception { + super.setUp(); + gen = new TestDataGenerator(); + gen.clearAllTables(); + gen.standardData(); + + this.patientId = 2L; + this.hcpId = 9000000000L; + this.factory = TestDAOFactory.getTestInstance(); + this.messageDAO = new MessageDAO(this.factory); + this.srAction = new SendRemindersAction(this.factory, this.hcpId); + } + + public void testSendRemindersAction() throws ITrustException + { + int numberOfAppts = srAction.sendReminderForAppointments(10); + assertTrue(numberOfAppts >= 5); + } + + public void testSendReminders() throws ITrustException, SQLException, FormValidationException { + ApptBean aBean = new ApptBean(); + + aBean.setApptType("TEST"); + aBean.setPatient(patientId); + aBean.setHcp(hcpId); + aBean.setDate(Timestamp.valueOf(LocalDateTime.now().plusDays(4))); + + List<MessageBean> mbListBefore = messageDAO.getMessagesFor(patientId); + + srAction.sendReminder(aBean); + + List<MessageBean> mbList = messageDAO.getMessagesFor(patientId); + + assertEquals(mbList.size(), mbListBefore.size() + 1); + MessageBean mBeanDB = mbList.get(0); + assertEquals("Reminder: upcoming appointment in 4 day(s)", mBeanDB.getSubject()); + } + +} \ No newline at end of file diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/action/ViewDiagnosisStatisticsActionTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/action/ViewDiagnosisStatisticsActionTest.java index 30600b38c3d14103ef71830275c354c1cbb5f97c..a23d9f0d90422ced565e1f011d6a90e471b212a6 100644 --- a/iTrust/test/edu/ncsu/csc/itrust/unit/action/ViewDiagnosisStatisticsActionTest.java +++ b/iTrust/test/edu/ncsu/csc/itrust/unit/action/ViewDiagnosisStatisticsActionTest.java @@ -130,13 +130,22 @@ public class ViewDiagnosisStatisticsActionTest extends TestCase { } public void testIsMalariaEpidemicNone() throws Exception { + gen.malaria_epidemic1(); assertFalse(action.isMalariaEpidemic("06/02/2010", "38201", "110")); } public void testIsFluEpidemic() throws Exception { gen.influenza_epidemic(); - assertTrue(action.isFluEpidemic("11/02/" + thisYear, "27606")); - assertFalse(action.isFluEpidemic("11/16/" + thisYear, "27606")); + assertTrue(action.isFluEpidemic("11/16/" + thisYear, "27606")); + assertFalse(action.isFluEpidemic("11/09/" + thisYear, "27606")); + } + + public void testIsFluEpidemicEdge() throws Exception { + gen.influenza_epidemic(); + // Test should pass since previous 14 days will have enough cases for epidemic + assertTrue(action.isFluEpidemic("11/15/" + thisYear, "27606")); + // Test should fail since previous 14 days will not have enough cases for epidemic + assertFalse(action.isFluEpidemic("11/17/" + thisYear, "27606")); } public void testGetEpidemicStatisticsInvalidThreshold(){ diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/action/ViewMyMessagesActionTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/action/ViewMyMessagesActionTest.java index dcfa853141e219e2c4a99aac0a409d11fd231aa0..f8fabb40def9637c48173678c0c7ea9460ca19ff 100644 --- a/iTrust/test/edu/ncsu/csc/itrust/unit/action/ViewMyMessagesActionTest.java +++ b/iTrust/test/edu/ncsu/csc/itrust/unit/action/ViewMyMessagesActionTest.java @@ -2,6 +2,8 @@ package edu.ncsu.csc.itrust.unit.action; import java.sql.SQLException; import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.List; import edu.ncsu.csc.itrust.action.ViewMyMessagesAction; @@ -299,4 +301,144 @@ public class ViewMyMessagesActionTest extends TestCase { assertNull(resultList); } } + + /** + * Test that filtering by MID works properly + * + * @throws Exception + */ + public void testFilterSentMessagesByMID() throws Exception { + // Check that we actually have messages to filter + List<MessageBean> unfilteredMessages = action.getAllMySentMessages(); + if (unfilteredMessages.size() == 0) { + fail("There are no messages to sort!"); + } + + // Check that the messages are filtered properly + List<MessageBean> filteredMessages = action.filterSentMessages(unfilteredMessages, "9000000000,,,,,"); + for (MessageBean m : filteredMessages) { + if (m.getTo() != 9000000000L) { + fail("This filter should not contain anything but MID 9000000000"); + } + } + } + + /** + * Test that filtering by subject works properly + * + * @throws Exception + */ + public void testFilterSentMessagesBySubject() throws Exception { + // Check that we actually have messages to filter + List<MessageBean> unfilteredMessages = action.getAllMySentMessages(); + if (unfilteredMessages.size() == 0) { + fail("There are no messages to sort!"); + } + + // Try a different filter method, ensure all work + List<MessageBean> filteredMessages = action.filterSentMessages(unfilteredMessages, ",Scratchy Throat,,,,"); + for (MessageBean m : filteredMessages) { + if (!m.getSubject().equalsIgnoreCase("Scratchy Throat")) { + fail("Subject name " + m.getSubject() + " was not filtered properly"); + } + } + } + + /** + * Test that the specified word is included within the body or the subject line + * + * @throws Exception + */ + public void testFilterSentMessagesByContentInclusion() throws Exception { + // Check that we actually have messages to filter + List<MessageBean> unfilteredMessages = action.getAllMySentMessages(); + if (unfilteredMessages.size() == 0) { + fail("There are no messages to sort!"); + } + + List<MessageBean> filteredMessages = action.filterSentMessages(unfilteredMessages, ",,throat,,,"); + for (MessageBean m : filteredMessages) { + if (!m.getSubject().toLowerCase().contains("throat") && !m.getBody().toLowerCase().contains("throat")) { + fail("Messages filtered should have the word throat in the body or subject"); + } + } + } + + /** + * Test that the specified word is not included within the body or subject line + * + * @throws Exception + */ + public void testFilterSentMessagesByContentExclusion() throws Exception { + // Check that we actually have messages to filter + List<MessageBean> unfilteredMessages = action.getAllMySentMessages(); + if (unfilteredMessages.size() == 0) { + fail("There are no messages to sort!"); + } + + List<MessageBean> filteredMessages = action.filterSentMessages(unfilteredMessages, ",,,prescription,,"); + assertTrue(filteredMessages.size() <= 2); + for (MessageBean m : filteredMessages) { + assertTrue(!m.getSubject().toLowerCase().contains("prescription") && !m.getBody().toLowerCase().contains("prescription")); + } + } + + /** + * Test that the messages selected have been sent after the starting date + * + * @throws Exception + */ + public void testFilterSentMessagesByStartingDate() throws Exception { + // Check that we actually have messages to filter + List<MessageBean> unfilteredMessages = action.getAllMySentMessages(); + if (unfilteredMessages.size() == 0) { + fail("There are no messages to sort!"); + } + + String now = new SimpleDateFormat("MM/dd/yyyy").format(Calendar.getInstance().getTime()); + List<MessageBean> filteredMessages = action.filterSentMessages(unfilteredMessages, ",,,,01/01/1900," + now); + + // Ensure that all messages are captured by a large interval + assertTrue(filteredMessages.size() == unfilteredMessages.size()); + + } + + /** + * Test that the messages selected have been sent before the end date + * + * @throws Exception + */ + public void testFilterSentMessagesByEndingDate() throws Exception { + // Check that we actually have messages to filter + List<MessageBean> unfilteredMessages = action.getAllMySentMessages(); + if (unfilteredMessages.size() == 0) { + fail("There are no messages to sort!"); + } + + List<MessageBean> filteredMessages = action.filterSentMessages(unfilteredMessages, ",,,,,02/01/2010"); + // We should lose the scratchy throat message + assertEquals(unfilteredMessages.size() - 1, filteredMessages.size()); + + } + + /** + * Test a bunch of complex queries with multiple filters + * + * @throws Exception + */ + public void testFilterSentMessagesComplexFilter() throws Exception { + // Check that we actually have messages to filter + List<MessageBean> unfilteredMessages = action.getAllMySentMessages(); + if (unfilteredMessages.size() == 0) { + fail("There are no messages to sort!"); + } + + // Do a complex filtering operation with including word throat + List<MessageBean> filteredMessages = action.filterSentMessages(unfilteredMessages, ",,throat,,,02/01/2010"); + assertEquals(0, filteredMessages.size()); + + // Same but excluding the word throat + filteredMessages = action.filterSentMessages(unfilteredMessages, ",,,throat,,02/01/2010"); + assertEquals(2, filteredMessages.size()); + } } diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/dao/appointment/ApptDAOTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/dao/appointment/ApptDAOTest.java index f20dd33a2d9a35329be32bef858fcd52fa2cca3c..77a4579abd8c080646cb858ae14b8fbbcf9903fc 100644 --- a/iTrust/test/edu/ncsu/csc/itrust/unit/dao/appointment/ApptDAOTest.java +++ b/iTrust/test/edu/ncsu/csc/itrust/unit/dao/appointment/ApptDAOTest.java @@ -17,6 +17,8 @@ public class ApptDAOTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private ApptDAO apptDAO = factory.getApptDAO(); + private ApptBean[] appts = null; + private ApptBean a1; private ApptBean a2; private ApptBean a3; @@ -30,8 +32,6 @@ public class ApptDAOTest extends TestCase { gen.clearAllTables(); gen.appointmentType(); - - a1 = new ApptBean(); a1.setDate(new Timestamp(new Date().getTime())); a1.setApptType("Ultrasound"); @@ -49,6 +49,7 @@ public class ApptDAOTest extends TestCase { a3.setApptType("Ultrasound"); a3.setHcp(doctorMID); a3.setPatient(patientMID); + } public void testAppointment() throws Exception { @@ -148,5 +149,20 @@ public class ApptDAOTest extends TestCase { assertEquals(30, type.getDuration()); assertEquals("Ultrasound", type.getName()); } + + // Test adding and retreiving upcoming appointments within n days + public void testGetUpcomingAppts() throws Exception { + // Edge case: empty database + List<ApptBean> upcomingAppts = apptDAO.getUpcomingAppts(30); + assertEquals(0, upcomingAppts.size()); + + // Test returning upcoming appts B + apptDAO.scheduleAppt(a1); + apptDAO.scheduleAppt(a2); + apptDAO.scheduleAppt(a3); + + upcomingAppts = apptDAO.getUpcomingAppts(1); + assertEquals(3, upcomingAppts.size()); + } }