diff --git a/iTrust/WebRoot/auth/preRegisteredPatient/.gitkeep b/iTrust/WebRoot/auth/preRegisteredPatient/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/iTrust/WebRoot/auth/preRegisteredPatient/home.jsp b/iTrust/WebRoot/auth/preRegisteredPatient/home.jsp new file mode 100644 index 0000000000000000000000000000000000000000..3baa477e3bc0cc8f7b64d5570357dea69ee320de --- /dev/null +++ b/iTrust/WebRoot/auth/preRegisteredPatient/home.jsp @@ -0,0 +1,9 @@ +<%@include file="/global.jsp" %> + +<% + pageTitle = "iTrust - Pre-Registered Patient Home"; +%> + +<%@include file="/header.jsp" %> + +<%@include file="/footer.jsp" %> diff --git a/iTrust/WebRoot/auth/preRegisteredPatient/menu.jsp b/iTrust/WebRoot/auth/preRegisteredPatient/menu.jsp new file mode 100644 index 0000000000000000000000000000000000000000..35e0a9d285cd2523a996da1de3f7170de5a296e8 --- /dev/null +++ b/iTrust/WebRoot/auth/preRegisteredPatient/menu.jsp @@ -0,0 +1,6 @@ +<div class="panel panel-default"> + <div class="panel-heading" anim-type="collapse" anim-target="#edit-menu"> + <h2 class="panel-title">Please wait for HCP approval to access account features.</h2> + </div> +</div> + diff --git a/iTrust/WebRoot/loginMenu.jsp b/iTrust/WebRoot/loginMenu.jsp index 1760757f3c8f57fd476c0eb73ce6d59083cf37e2..38d20c40b23567559c35875466f36538da721d76 100644 --- a/iTrust/WebRoot/loginMenu.jsp +++ b/iTrust/WebRoot/loginMenu.jsp @@ -43,7 +43,7 @@ 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> + <a style="font-size: 80%;" href="/iTrust/util/PreRegisterPatient.jsp" id="preregister_link">Pre-Register</a> </form> <% diff --git a/iTrust/WebRoot/util/PreRegisterPatient.jsp b/iTrust/WebRoot/util/PreRegisterPatient.jsp index 17637e9c71f00f7c7178bfe258060bf6496afd1d..03ecc8872140027f5c5d785530af380e59b220b2 100755 --- a/iTrust/WebRoot/util/PreRegisterPatient.jsp +++ b/iTrust/WebRoot/util/PreRegisterPatient.jsp @@ -1,147 +1,196 @@ -<%@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" %> +<%@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.exception.FormValidationException"%> +<%@page import="edu.ncsu.csc.itrust.exception.ITrustException"%> + +<%@include file="/global.jsp" %> + +<% +pageTitle = "iTrust - PreRegister Patient"; +%> + +<%@include file="/header.jsp" %> + +<% +boolean formIsFilled = request.getParameter("formIsFilled") != null && request.getParameter("formIsFilled").equals("true"); + +if (formIsFilled) { + //This page is not actually a "page", it just adds a user and forwards. + + + PatientBean p = new BeanBuilder<PatientBean>().build(request.getParameterMap(), new PatientBean()); + + try { + long newMID = 021700L; + + newMID = new AddPreRegisteredPatientAction(DAOFactory.getProductionInstance(), newMID).addPatient(p); + + session.setAttribute("pid", Long.toString(newMID)); + String fullname; + String password; + password = p.getPassword(); + fullname = p.getFullName(); + + loggingAction.logEvent(TransactionType.PATIENT_CREATE, newMID, newMID, ""); +%> + + <div align=center> + <span class="iTrustMessage">New Pre-registered Prepatient <%= StringEscapeUtils.escapeHtml("" + (fullname)) %> successfully added!</span> + <br /><br /> + <table class="fTable"> + <tr> + <th colspan=2>New Pre-registered Patient Information</th> + </tr> + <tr> + <td class="subHeaderVertical">MID:</td> + <td><%= StringEscapeUtils.escapeHtml("" + (newMID)) %></td> + <td></td> + </tr> + <tr> + <td class="subHeaderVertical">Temporary Password:</td> + <td><%= StringEscapeUtils.escapeHtml("" + (password)) %></td> + <td></td> + </tr> + </table> + <br />Please get this information to <b><%= StringEscapeUtils.escapeHtml("" + (fullname)) %></b>! + + </div> + +<% + + + } catch(FormValidationException e){ +%> + <div align=center> + <span class="iTrustError"> <%= StringEscapeUtils.escapeHtml(e.getMessage()) %></span> + <!-- StringEscapeUtils.escapeHtml(e.getMessage()) --> + </div> +<% + } catch (ITrustException e) { +%> + <div align=center> + <span class="iTrustError"> <%= StringEscapeUtils.escapeHtml(e.getMessage()) %></span> + <!-- StringEscapeUtils.escapeHtml(e.getMessage()) --> + </div> +<% + } +} +%> + +<div align=center> +<form action="PreRegisterPatient.jsp" method="post"> <!-- Which page DIRECT to --> + + <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"></td> + </tr> + <tr> + <td class="subHeaderVertical">Weight:</td> + <td><input type="text" name="weight"></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" id="submit_preregister"> +</form> +<br /> +</div> +<%@include file="/footer.jsp" %> diff --git a/iTrust/src/edu/ncsu/csc/itrust/action/AddPreRegisteredPatientAction.java b/iTrust/src/edu/ncsu/csc/itrust/action/AddPreRegisteredPatientAction.java index 54dcbd3b88b409046b2f9823292d73f03bd87e52..639ffd0fdf83bf48f66cefadc24d0c9d879bf898 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/action/AddPreRegisteredPatientAction.java +++ b/iTrust/src/edu/ncsu/csc/itrust/action/AddPreRegisteredPatientAction.java @@ -49,7 +49,12 @@ public class AddPreRegisteredPatientAction { public long addPatient(PatientBean p) throws FormValidationException, ITrustException { - new AddPatientValidator().validate(p); + new AddPatientValidator().validate(p); + + // Make sure the email is unique + if (patientDAO.isEmailInUse(p.getEmail())) { + throw new ITrustException("This email is already in use. Please use another email address."); + } long newMID = patientDAO.addEmptyPatient(); // the new added row id in the database p.setMID(newMID); 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 0b9ed80a75084f03381cc12ccd06489c66624081..416a2aad56db654b1a397eddaa66905c789d6887 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PatientDAO.java +++ b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PatientDAO.java @@ -222,7 +222,29 @@ public class PatientDAO { } finally { DBUtil.closeConnection(conn, ps); } - } + } + + public boolean isEmailInUse(String email) throws DBException { + Connection conn = null; + PreparedStatement ps = null; + boolean emailInUse = false; + try { + conn = factory.getConnection(); + ps = conn.prepareStatement("SELECT * FROM patients WHERE email=?"); + ps.setString(1, email); + ResultSet rs; + rs = ps.executeQuery(); + emailInUse = rs.next(); + rs.close(); + ps.close(); + } catch (SQLException e) { + + throw new DBException(e); + } finally { + DBUtil.closeConnection(conn, ps); + } + return emailInUse; + } public void addHistory(long pid, long hcpid) throws DBException { Connection conn = null; diff --git a/iTrust/test/edu/ncsu/csc/itrust/selenium/PreRegisterPatientTest.java b/iTrust/test/edu/ncsu/csc/itrust/selenium/PreRegisterPatientTest.java new file mode 100644 index 0000000000000000000000000000000000000000..0633b193d6621d963adeb3fed20042521dbd0ed5 --- /dev/null +++ b/iTrust/test/edu/ncsu/csc/itrust/selenium/PreRegisterPatientTest.java @@ -0,0 +1,103 @@ +package edu.ncsu.csc.itrust.selenium; + +import org.openqa.selenium.*; +import java.util.concurrent.TimeUnit; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; + + + +import edu.ncsu.csc.itrust.enums.TransactionType; + +public class PreRegisterPatientTest extends iTrustSeleniumTest { + + protected WebDriver driver; + + @Override + protected void setUp() throws Exception { + super.setUp(); + gen.clearAllTables(); + gen.standardData(); + + driver = new HtmlUnitDriver(); + driver.manage().timeouts().implicitlyWait(DEFAULT_TIMEOUT, TimeUnit.SECONDS); + } + + private void goToPreRegister() { + // Go to preregister page + driver.get(ADDRESS); + driver.findElement(By.id("preregister_link")).click(); + } + + public void testPreRegisterPatientButton() throws Exception { + goToPreRegister(); + assertEquals("iTrust - PreRegister Patient", driver.getTitle()); + } + + public void testPreRegisterPatientSuccessRequired() throws Exception { + goToPreRegister(); + + // Fill the form + driver.findElement(By.xpath("//input[@name='firstName']")).sendKeys("fname"); + driver.findElement(By.xpath("//input[@name='lastName']")).sendKeys("lname"); + driver.findElement(By.xpath("//input[@name='email']")).sendKeys("name@email.com"); + driver.findElement(By.xpath("//input[@name='password']")).sendKeys("Password123"); + driver.findElement(By.xpath("//input[@name='verifyPassword']")).sendKeys("Password123"); + + // Submit + driver.findElement(By.id("submit_preregister")).click(); + + assertTrue(driver.findElement(By.xpath("//body")).getText().contains("New Pre-registered Patient Information")); + } + + public void testMissingElements() { + goToPreRegister(); + + // Check that all elements have the required attribute + assertTrue( + Boolean.parseBoolean(driver.findElement(By.xpath("//input[@name='firstName']")).getAttribute("required")) + && Boolean.parseBoolean(driver.findElement(By.xpath("//input[@name='lastName']")).getAttribute("required")) + && Boolean.parseBoolean(driver.findElement(By.xpath("//input[@name='email']")).getAttribute("required")) + && Boolean.parseBoolean(driver.findElement(By.xpath("//input[@name='password']")).getAttribute("required")) + && Boolean.parseBoolean(driver.findElement(By.xpath("//input[@name='verifyPassword']")).getAttribute("required")) + ); + + // Make sure that the form does not submit + driver.findElement(By.xpath("//input[@name='firstName']")).sendKeys(""); + driver.findElement(By.xpath("//input[@name='lastName']")).sendKeys("lname"); + driver.findElement(By.xpath("//input[@name='email']")).sendKeys("name@email.com"); + driver.findElement(By.xpath("//input[@name='password']")).sendKeys("Password123"); + driver.findElement(By.xpath("//input[@name='verifyPassword']")).sendKeys("Password123"); + + driver.findElement(By.id("submit_preregister")).click(); + + assertFalse(driver.findElement(By.xpath("//body")).getText().contains("New Pre-registered Patient Information")); + } + + public void testInvalidName() { + goToPreRegister(); + + driver.findElement(By.xpath("//input[@name='firstName']")).sendKeys("123abc"); + driver.findElement(By.xpath("//input[@name='lastName']")).sendKeys("lname"); + driver.findElement(By.xpath("//input[@name='email']")).sendKeys("name@email.com"); + driver.findElement(By.xpath("//input[@name='password']")).sendKeys("Password123"); + driver.findElement(By.xpath("//input[@name='verifyPassword']")).sendKeys("Password123"); + + driver.findElement(By.id("submit_preregister")).click(); + + assertTrue(driver.findElement(By.xpath("//body")).getText().contains("This form has not been validated correctly")); + } + + public void testInvalidEmail() { + goToPreRegister(); + + driver.findElement(By.xpath("//input[@name='firstName']")).sendKeys("fname"); + driver.findElement(By.xpath("//input[@name='lastName']")).sendKeys("lname"); + driver.findElement(By.xpath("//input[@name='email']")).sendKeys("not-an-email"); + driver.findElement(By.xpath("//input[@name='password']")).sendKeys("Password123"); + driver.findElement(By.xpath("//input[@name='verifyPassword']")).sendKeys("Password123"); + + driver.findElement(By.id("submit_preregister")).click(); + + assertTrue(driver.findElement(By.xpath("//body")).getText().contains("This form has not been validated correctly")); + } +} \ No newline at end of file diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/action/AddPreRegisterPatientActionTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/action/AddPreRegisterPatientActionTest.java index f7d9d1b20cd4ad1b7dc72c340dd0dd1f34e243d8..c5cf6099ea011acadb1c337a6e2cbb54fc27c9b4 100644 --- a/iTrust/test/edu/ncsu/csc/itrust/unit/action/AddPreRegisterPatientActionTest.java +++ b/iTrust/test/edu/ncsu/csc/itrust/unit/action/AddPreRegisterPatientActionTest.java @@ -95,4 +95,35 @@ public class AddPreRegisterPatientActionTest extends TestCase { } } + + /** + * Ensure that duplicate emails are not allowed + */ + public void testPreRegisterPatientDuplicateEmail() throws Exception { + PatientBean p2 = new PatientBean(); + p2.setFirstName("Jiminy"); + p2.setLastName("Cricket"); + p2.setEmail("make.awish@gmail.com"); + p2.setPassword("password"); + + action.addPatient(p2); + + PatientBean p3 = new PatientBean(); + p3.setFirstName("Make"); + p3.setLastName("AWish"); + p3.setEmail("make.awish@gmail.com"); + p3.setPassword("password"); + + try { + action.addPatient(p3); + fail("Duplicate email"); + } catch (ITrustException e) { } + } + + /** + * Check that invalid names are not allowed + */ + public void testPreRegisterPatientInvalidName() throws Exception { + + } }