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;