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 416a2aad56db654b1a397eddaa66905c789d6887..597a64dcbe2b2e856551705c083a34510d2b6546 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PatientDAO.java +++ b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PatientDAO.java @@ -60,6 +60,44 @@ public class PatientDAO { this.procedureLoader = new ProcedureBeanLoader(true); } + /** + * Returns if the patient is registered + * + * @param mid The MID of the patient in question. + * @return A boolean representing if the patient is registered + * @throws ITrustException + * @throws DBException + */ + public boolean getRegistered(long mid) throws ITrustException, DBException { + Connection conn = null; + PreparedStatement ps = null; + try { + conn = factory.getConnection(); + ps = conn.prepareStatement("SELECT registered FROM patients WHERE MID=?"); + ps.setLong(1, mid); + ResultSet rs; + rs = ps.executeQuery(); + if (rs.next()) { + Integer b = rs.getObject("registered") != null ? rs.getInt("registered") : null; + if (b == 1) { + return true; + } else if (b == 0) { + return false; + } else { + throw new ITrustException("Number is not a boolean"); + } + } else { + rs.close(); + ps.close(); + throw new ITrustException("User does not exist"); + } + } catch (SQLException e) { + throw new DBException(e); + } finally { + DBUtil.closeConnection(conn, ps); + } + } + /** * Returns the name for the given MID *