From ae0270e26c5b0d0619b91e279ca81688895202d4 Mon Sep 17 00:00:00 2001 From: mjw11 <mjw11@illinois.edu> Date: Mon, 16 Nov 2020 22:30:11 -0600 Subject: [PATCH] Add activate and deactivate patient functions --- .../ncsu/csc/itrust/dao/mysql/PatientDAO.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) 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 597a64d..569f823 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PatientDAO.java +++ b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PatientDAO.java @@ -98,6 +98,64 @@ public class PatientDAO { } } + /** + * Sets that a patient is registered + * + * @param mid The MID of the patient in question. + * @return A boolean representing if the transaction completed successfully + * @throws ITrustException + * @throws DBException + */ + public boolean activatePreregisteredPatient(long mid) { + Connection conn = null; + PreparedStatement ps = null; + try { + conn = factory.getConnection(); + ps = conn.prepareStatement("UPDATE PATIENTS SET registered = ? WHERE mid = ?"); + ps.setByte(1, 1); + ps.setLong(2, mid); + ps.executeUpdate(); + ps.close(); + return true; + + } catch (SQLException e) { + + throw new DBException(e); + } finally { + DBUtil.closeConnection(conn, ps); + } + } + + /** + * Sets that a patient is not registered + * + * @param mid The MID of the patient in question. + * @return A boolean representing if the transaction completed successfully + * @throws ITrustException + * @throws DBException + */ + public boolean deactivatePreregisteredPatient(long mid) { + Connection conn = null; + PreparedStatement ps = null; + try { + conn = factory.getConnection(); + ps = conn.prepareStatement("UPDATE PATIENTS SET DateofDeactivation = ?, registered = ? WHERE mid = ?"); + Date date = new Date(Calendar.getInstance().getTime().getTime()); + ps.setDate(1, date); + ps.setByte(2, 0); + ps.setLong(3, mid); + ps.executeUpdate(); + ps.close(); + return true; + + } catch (SQLException e) { + + throw new DBException(e); + } finally { + DBUtil.closeConnection(conn, ps); + } + } + /** * Returns the name for the given MID * -- GitLab