diff --git a/iTrust/WebRoot/WEB-INF/web.xml b/iTrust/WebRoot/WEB-INF/web.xml index 85aff0ab1c637402e0409a0140cb726a5754dc5e..aa258d6cab4e7c258a1c7429be34407b3ad79c4a 100644 --- a/iTrust/WebRoot/WEB-INF/web.xml +++ b/iTrust/WebRoot/WEB-INF/web.xml @@ -84,7 +84,11 @@ </security-role> <security-role> <role-name>tester</role-name> - </security-role> + </security-role> + + <security-role> + <role-name>preRegisteredPatient</role-name> + </security-role> <!-- Define all role-based authorization folders @@ -95,6 +99,7 @@ /auth/admin/* - JSPs for Administrators only /auth/staff/* - JSPs for only hospital staff (hcps, uaps, admin, lt) /auth/patient/* - JSPs for patients only + /auth/preRegisteredPatient/* - JSPs for preRegisteredPatients only /auth/lt/* - JSPs for LTs only If any user attempts to access a folder that their role is not authorized for, @@ -126,6 +131,9 @@ <role-name>tester</role-name> <role-name>pha</role-name> <role-name>lt</role-name> + + <role-name>preRegisteredPatient</role-name> + </auth-constraint> </security-constraint> @@ -278,6 +286,23 @@ </auth-constraint> </security-constraint> + + <security-constraint> + <display-name>PreRegisteredPatient Only</display-name> + <web-resource-collection> + <web-resource-name> + Only PreRegisteredPatient are Allowed + </web-resource-name> + <!-- Define the context-relative URL(s) to be protected --> + <url-pattern>/auth/preRegisteredPatient/*</url-pattern> + </web-resource-collection> + <auth-constraint> + <!-- Anyone with one of the listed roles may access this area --> + <role-name>preRegisteredPatient</role-name> + </auth-constraint> + </security-constraint> + + <security-constraint> <display-name>PHA Only</display-name> <web-resource-collection> diff --git a/iTrust/WebRoot/auth/forwardUser.jsp b/iTrust/WebRoot/auth/forwardUser.jsp index a3bfd776e93c125faf05939a63cbff4f45d45328..72e75a9a43574c8618442c068c4c31b13575b051 100644 --- a/iTrust/WebRoot/auth/forwardUser.jsp +++ b/iTrust/WebRoot/auth/forwardUser.jsp @@ -17,10 +17,17 @@ if(request.getUserPrincipal() != null) { long mid = Long.valueOf(request.getUserPrincipal().getName()); + if (request.isUserInRole("patient")) { response.sendRedirect("patient/home.jsp"); return; } + + else if (request.isUserInRole("preRegisteredPatient")) { + response.sendRedirect("preRegisteredPatient/home.jsp"); + return; + } + else if (request.isUserInRole("uap")) { response.sendRedirect("uap/home.jsp"); return; @@ -53,14 +60,13 @@ if(request.getUserPrincipal() != null) { session.invalidate(); response.sendRedirect("/iTrust/"); } - else if (mid == 0) - { + else if (mid == 0) { session.invalidate(); } - else { - + else { response.sendRedirect("errors/noaccess.jsp"); } } %> + diff --git a/iTrust/WebRoot/global.jsp b/iTrust/WebRoot/global.jsp index cd4c16c3e8149c8db84a4db41e6d62ec5684408e..6c7089591f1b739e4bf18ce94203cf7ea7878fee 100644 --- a/iTrust/WebRoot/global.jsp +++ b/iTrust/WebRoot/global.jsp @@ -34,6 +34,10 @@ try { userRole = (String) session.getAttribute("userRole"); if (userRole == null) { + + if (request.isUserInRole("preRegisteredPatient")) { + userRole = "preRegisteredPatient"; + } if (request.isUserInRole("patient")) { userRole = "patient"; } diff --git a/iTrust/WebRoot/loginMenu.jsp b/iTrust/WebRoot/loginMenu.jsp index 4f3fb4b94beb3eb30b6d560bb0a7372224b44a89..1760757f3c8f57fd476c0eb73ce6d59083cf37e2 100644 --- a/iTrust/WebRoot/loginMenu.jsp +++ b/iTrust/WebRoot/loginMenu.jsp @@ -42,6 +42,8 @@ function fillLoginFields(u,p) { <br /><br /> <a style="font-size: 80%;" href="/iTrust/util/resetPassword.jsp">Reset Password</a> + <a> </a> + <a style="font-size: 80%;" href="/iTrust/util/PreRegisterPatient.jsp">Pre-Register</a> </form> <% @@ -61,6 +63,8 @@ function fillLoginFields(u,p) { <input type="submit" value="Login"><br /><br /> <a style="font-size: 80%;" href="/iTrust/util/resetPassword.jsp">Reset Password</a> + <a> </a> + <a style="font-size: 80%;" href="/iTrust/util/PreRegisterPatient.jsp">Pre-Register</a> </form> <% diff --git a/iTrust/WebRoot/util/PreRegisterPatient.jsp b/iTrust/WebRoot/util/PreRegisterPatient.jsp new file mode 100755 index 0000000000000000000000000000000000000000..17637e9c71f00f7c7178bfe258060bf6496afd1d --- /dev/null +++ b/iTrust/WebRoot/util/PreRegisterPatient.jsp @@ -0,0 +1,147 @@ +<%@taglib prefix="itrust" uri="/WEB-INF/tags.tld"%> +<%@page errorPage="/auth/exceptionHandler.jsp"%> + +<%@page import="edu.ncsu.csc.itrust.action.AddPreRegisteredPatientAction"%> +<%@page import="edu.ncsu.csc.itrust.BeanBuilder"%> +<%@page import="edu.ncsu.csc.itrust.beans.PatientBean"%> +<%@page import="edu.ncsu.csc.itrust.beans.forms.HealthRecordForm"%> +<%@page import="edu.ncsu.csc.itrust.exception.FormValidationException"%> +<%@include file="/global.jsp" %> + +<% +pageTitle = "iTrust - Add Patient"; +%> + +<%@include file="/header.jsp" %> + +<% +boolean formIsFilled = request.getParameter("formIsFilled") != null && request.getParameter("formIsFilled").equals("true"); + +if (formIsFilled) { + PatientBean p = new BeanBuilder<PatientBean>().build(request.getParameterMap(), new PatientBean()); + HealthRecordForm h = new BeanBuilder<HealthRecordForm>().build(request.getParameterMap(), new HealthRecordForm()); + + long mid = new PreRegisterPatientAction(prodDAO).addPatient(p); + + String name = "<Name>"; + if (p != null) { + name = p.getFullName(); + } +%> +<div><%=s%></div> +<% + +} +%> + +<div align=center> +<form action="PreRegisterPatient.jsp" method="post"> + <input type="hidden" name="formIsFilled" value="true"> <br /> +<br /> +<div style="width: 50%; text-align:left;">Please enter in the name of the Pre-registered +patient, with a valid email address. If the user does not have an email +address, use the hospital's email address, [insert pre-defined email], +to recover the password.</div> +<br /> +<br /> +<table class="fTable"> + <tr> + <th colspan=2 style="text-align:center">Pre-registered Patient Information</th> + </tr> + <tr> + <td class="subHeaderVertical">First name:</td> + <td><input type="text" name="firstName" required> *</td> + </tr> + <tr> + <td class="subHeaderVertical">Last Name:</td> + <td><input type="text" name="lastName" required> *</td>> + </tr> + <tr> + <td class="subHeaderVertical">Email:</td> + <td><input type="text" name="email" required> *</td> + </tr> + <tr> + <td class="subHeaderVertical">Password:</td> + <td><input type="password" name="password" required> *</td> + </tr> + <tr> + <td class="subHeaderVertical">Verify Password:</td> + <td><input type="password" name="verifyPassword" required> *</td> + </tr> + <tr> + <td class="subHeaderVertical">Address:</td> + <td> <input name="streetAddress1" type="text"><br /> + <input name="streetAddress2" type="text"></td> + </tr> + <tr> + <td class="subHeaderVertical">City:</td> + <td> <input name="city" type="text"></td> + </tr> + <tr> + <td class="subHeaderVertical">State:</td> + <td><itrust:state name="state" value="AK" /></td> + </tr> + <tr> + <td class="subHeaderVertical">Zip:</td> + <td> <input type="text" name="zip" maxlength="10" size="10"></td> + </tr> + <tr> + <td class="subHeaderVertical">Phone:</td> + <td> <input type="text" name="phone" size="12" maxlength="12"></td> + </tr> + <tr> + <td class="subHeaderVertical">Height:</td> + <td><input type="text" name="height" value="0"></td> + </tr> + <tr> + <td class="subHeaderVertical">Weight:</td> + <td><input type="text" name="weight" value="0"></td> + </tr> + <tr> + <td class="subHeaderVertical">Smoker:</td> + <td><input type="radio" id="smoker_yes" name="isSmoker" value="true"> + <label for="smoker_yes">Yes</label> + <br> + <input type="radio" id="smoker_no" name="isSmoker" value="false"> + <label for="smoker_no">No</label><br></td> + </tr> + + <br/> + <tr> + <th colspan=2 style="text-align:center">Insurance Information</th> + </tr> + + <tr> + <td class="subHeaderVertical">Insurance Provider Name:</td> + <td> <input type="text" name="icName"></td> + </tr> + <tr> + <td class="subHeaderVertical">Insurance Provider Address:</td> + <td><input name="icAddress1" type="text"><br /> + <input name="icAddress2" type="text"></td> + </tr> + <tr> + <td class="subHeaderVertical">City:</td> + <td> <input name="icCity" type="text"></td> + </tr> + <tr> + <td class="subHeaderVertical">State:</td> + <td><itrust:state name="icState" value="AK" /></td> + </tr> + <tr> + <td class="subHeaderVertical">Zip:</td> + <td> <input type="text" name="icZip" maxlength="10" size="10"></td> + </tr> + <tr> + <td class="subHeaderVertical">Insurance Provider Phone:</td> + <td><input type="text" name="icPhone"></td> + </tr> +</table> + +<br /> + +<input type="submit" style="font-size: 16pt; font-weight: bold;" value="Patient Pre-Register"> +</form> +<br /> +</div> +<%@include file="/footer.jsp" %> diff --git a/iTrust/sql/createTables.sql b/iTrust/sql/createTables.sql index e4e85b692229f59b15cadb8aa74f958551a5bd9e..38a757b4532fa349f9cc39fe692d0719ba79ffd7 100644 --- a/iTrust/sql/createTables.sql +++ b/iTrust/sql/createTables.sql @@ -4,7 +4,7 @@ CREATE TABLE users( Password VARCHAR(200), Salt VARCHAR(200) DEFAULT '', openID VARCHAR(200), - Role enum('patient','admin','hcp','uap','er','tester','pha', 'lt') NOT NULL DEFAULT 'admin', + Role enum('patient','admin','hcp','uap','er','tester','pha', 'lt', 'preRegisteredPatient') NOT NULL DEFAULT 'admin', sQuestion VARCHAR(100) DEFAULT '', sAnswer VARCHAR(30) DEFAULT '', isDependent tinyint(1) unsigned NOT NULL default '0', diff --git a/iTrust/src/edu/ncsu/csc/itrust/action/AddPreRegisteredPatientAction.java b/iTrust/src/edu/ncsu/csc/itrust/action/AddPreRegisteredPatientAction.java new file mode 100644 index 0000000000000000000000000000000000000000..54dcbd3b88b409046b2f9823292d73f03bd87e52 --- /dev/null +++ b/iTrust/src/edu/ncsu/csc/itrust/action/AddPreRegisteredPatientAction.java @@ -0,0 +1,63 @@ +package edu.ncsu.csc.itrust.action; + + +import edu.ncsu.csc.itrust.RandomPassword; +import edu.ncsu.csc.itrust.beans.PatientBean; +import edu.ncsu.csc.itrust.dao.DAOFactory; +import edu.ncsu.csc.itrust.dao.mysql.PatientDAO; +import edu.ncsu.csc.itrust.dao.mysql.AuthDAO; +import edu.ncsu.csc.itrust.enums.Role; +import edu.ncsu.csc.itrust.exception.FormValidationException; +import edu.ncsu.csc.itrust.exception.ITrustException; +import edu.ncsu.csc.itrust.validate.AddPatientValidator; + +/** + * Used for Add Pre-registered Patient page (PreRegisterPatient.jsp). This just adds an empty patient, creates an entered password for + * that patient. + * + * Very similar to {@link AddOfficeVisitAction} + * + * + */ +public class AddPreRegisteredPatientAction { + private PatientDAO patientDAO; + private AuthDAO authDAO; + private long loggedInMID; + + /** + * Just the factory and logged in MID + * + * @param factory + * @param loggedInMID + */ + public AddPreRegisteredPatientAction(DAOFactory factory, long loggedInMID) { + this.patientDAO = factory.getPatientDAO(); + this.loggedInMID = loggedInMID; + this.authDAO = factory.getAuthDAO(); + } + + /** + * Creates a new patient, returns the new MID. Adds a new user to the table with a + * preRegisteredPatient role + * + * @param p patient to be created + * @return the new MID of the patient + * @throws FormValidationException if the patient is not successfully validated + * @throws ITrustException + */ + + + public long addPatient(PatientBean p) throws FormValidationException, ITrustException { + + new AddPatientValidator().validate(p); + + long newMID = patientDAO.addEmptyPatient(); // the new added row id in the database + p.setMID(newMID); + + String pwd = authDAO.addUser(newMID, Role.PREREGISTEREDPATIENT, p.getPassword()); + + p.setPassword(pwd); + patientDAO.editPatient(p, loggedInMID); + return newMID; + } +} diff --git a/iTrust/src/edu/ncsu/csc/itrust/enums/Role.java b/iTrust/src/edu/ncsu/csc/itrust/enums/Role.java index 7449b84ac51590834bf992d93efce89a0868a4af..4e22329ffd81d838743918f18a79ba59303e772e 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/enums/Role.java +++ b/iTrust/src/edu/ncsu/csc/itrust/enums/Role.java @@ -1,10 +1,12 @@ package edu.ncsu.csc.itrust.enums; /** - * The iTrust user roles: Patient, ER, HCP, UAP, LT, PHA, Administrator and Tester. + * The iTrust user roles: Pre-registered Patient, Patient, ER, HCP, UAP, LT, PHA, Administrator and Tester. * Consult the requirements for the contextual meanings of these individual choices. */ public enum Role { + /**PRE-REGISTERED PATIENT*/ + PREREGISTEREDPATIENT("preRegisteredPatient", "Patients", 0L), /**PATIENT*/ PATIENT("patient", "Patients", 0L), /**ER*/ diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/action/AddPreRegisterPatientActionTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/action/AddPreRegisterPatientActionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f7d9d1b20cd4ad1b7dc72c340dd0dd1f34e243d8 --- /dev/null +++ b/iTrust/test/edu/ncsu/csc/itrust/unit/action/AddPreRegisterPatientActionTest.java @@ -0,0 +1,98 @@ +/** + * Tests for AddPatientAction + */ + +package edu.ncsu.csc.itrust.unit.action; + +import junit.framework.TestCase; +import edu.ncsu.csc.itrust.action.AddPreRegisteredPatientAction; +import edu.ncsu.csc.itrust.beans.PatientBean; +import edu.ncsu.csc.itrust.dao.DAOFactory; +import edu.ncsu.csc.itrust.dao.mysql.AuthDAO; +import edu.ncsu.csc.itrust.dao.mysql.PatientDAO; +import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; +import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; +import edu.ncsu.csc.itrust.exception.FormValidationException; +import edu.ncsu.csc.itrust.exception.ITrustException; +import edu.ncsu.csc.itrust.enums.Role; + + +public class AddPreRegisterPatientActionTest extends TestCase { + private DAOFactory factory = TestDAOFactory.getTestInstance(); + private PatientDAO patientDAO = TestDAOFactory.getTestInstance().getPatientDAO(); + private AuthDAO authDAO = TestDAOFactory.getTestInstance().getAuthDAO(); + private TestDataGenerator gen = new TestDataGenerator(); + private AddPreRegisteredPatientAction action; + +/** + * Sets up defaults + */ + @Override + protected void setUp() throws Exception { + gen.clearAllTables(); + action = new AddPreRegisteredPatientAction(factory, 0L); + } + + /** + * Test adding a patient with correct information. + */ + public void testPreRegisterPatientAction() throws Exception { + PatientBean p = new PatientBean(); + p.setFirstName("Jiminy"); + p.setLastName("Cricket"); + p.setEmail("make.awish@gmail.com"); + p.setPassword("password"); + p.setStreetAddress1("SA1"); + p.setStreetAddress2("SA2"); + p.setZip("12345"); + p.setCity("Champaign"); + p.setState("IL"); + p.setPhone("1234567890"); + p.setIcAddress1("ICA1"); + p.setIcAddress2("ICA2"); + p.setIcZip("54321"); + p.setIcCity("Urbana"); + p.setIcState("AK"); + p.setIcPhone("1122334455"); + + long mid = action.addPatient(p); + + PatientBean p2 = patientDAO.getPatient(mid); + assertEquals(p.getFirstName(), p2.getFirstName()); + assertEquals(p.getLastName(), p2.getLastName()); + assertEquals(p.getEmail(), p2.getEmail()); + assertEquals(p.getStreetAddress1(), p2.getStreetAddress1()); + assertEquals(p.getStreetAddress2(), p2.getStreetAddress2()); + assertEquals(p.getZip(), p2.getZip()); + assertEquals(p.getCity(), p2.getCity()); + assertEquals(p.getState(), p2.getState()); + assertEquals(p.getPhone(), p2.getPhone()); + assertEquals(p.getIcAddress1(), p2.getIcAddress1()); + assertEquals(p.getIcAddress2(), p2.getIcAddress2()); + assertEquals(p.getIcZip(), p2.getIcZip()); + assertEquals(p.getIcCity(), p2.getIcCity()); + assertEquals(p.getIcState(), p.getIcState()); + assertEquals(p.getIcPhone(), p.getIcPhone()); + + assertEquals(Role.PREREGISTEREDPATIENT, authDAO.getUserRole(mid)); + } + + /** + * Ensure that invalid emails are not allowed + */ + public void testPreRegisterPatientInvalidEmail() throws Exception { + PatientBean p = new PatientBean(); + p.setFirstName("Jiminy"); + p.setLastName("Cricket"); + p.setEmail("1234"); + p.setPassword("password"); + + // maybe not needed + try { + action.addPatient(p); + fail("Invalid email"); + } catch (FormValidationException e) { + + } + } +}