From 39a5b82d92f13cc5408df96f5d292ec7caef5b4c Mon Sep 17 00:00:00 2001
From: xuechen5 <xuechen5@illinois.edu>
Date: Sat, 21 Nov 2020 05:11:38 -0600
Subject: [PATCH] SQL: Added Function for Convert Pre-Registered Patient to
 Patient

---
 .../ncsu/csc/itrust/dao/mysql/PatientDAO.java | 50 ++++++++++++-------
 1 file changed, 31 insertions(+), 19 deletions(-)

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 6f189c3..ea6b170 100644
--- a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PatientDAO.java
+++ b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/PatientDAO.java
@@ -99,17 +99,19 @@ public class PatientDAO {
 	 * Returns the role of a particular patient - why is this in PatientDAO? It should be in AuthDAO
 	 * 
 	 * @param mid The MID of the patient in question.
+	 * @param role A String representing the role of the patient.
 	 * @return A String representing the patient's role.
 	 * @throws ITrustException
 	 * @throws DBException
 	 */
-	public String getRole(long mid) throws ITrustException, DBException {
+	public String getRole(long mid, String role) throws ITrustException, DBException {
 		Connection conn = null;
 		PreparedStatement ps = null;
 		try {
 			conn = factory.getConnection();
-			ps = conn.prepareStatement("SELECT role FROM users WHERE MID=?");
+			ps = conn.prepareStatement("SELECT role FROM users WHERE MID=? AND Role=?");
 			ps.setLong(1, mid);
+			ps.setString(2, role);
 			ResultSet rs;
 			rs = ps.executeQuery();
 			if (rs.next()) {
@@ -190,22 +192,6 @@ public class PatientDAO {
 		}
 	}
 
-	public void activatePatient(long mid) throws DBException {
-		Connection conn = null;
-		PreparedStatement ps = null;
-		try {
-			conn = factory.getConnection();
-			ps = conn.prepareStatement("UPDATE users SET role=? WHERE MID=?");
-			ps.setString(1, "patient");
-			ps.setLong(2, mid);
-
-		} catch (SQLException e) {
-			throw new DBException(e);
-		} finally {
-			DBUtil.closeConnection(conn, ps);
-		}
-	}
-
 	/**
 	 * Updates a patient's information for the given MID
 	 * 
@@ -241,6 +227,7 @@ public class PatientDAO {
 		}
 	}
 	
+	/*added for UC91 */
     public boolean isEmailInUse(String email) throws DBException {
         Connection conn = null;
 		PreparedStatement ps = null;
@@ -938,7 +925,7 @@ public class PatientDAO {
 	}
 	
 	/**
-	 * Lists every patient in the database.
+	 * Lists every Approved patient in the database.
 	 * 
 	 * @return A java.util.List of PatientBeans representing the patients.
 	 * @throws DBException
@@ -988,6 +975,31 @@ public class PatientDAO {
 		}
 	}
 	
+	/**
+	 * Convert a Pre-Registered patient to a regular patient upon HCP approval.
+	 * by change "role" column in "users" table.
+	 * 
+	 * @return void
+	 * @throws DBException
+	 */
+	public void ConvertPreRegisteredPatientsToPatient(long mid) throws DBException {		
+		Connection conn = null;
+		PreparedStatement ps = null;
+		try {
+			conn = factory.getConnection();
+			ps = conn.prepareStatement("UPDATE users SET role=? WHERE MID=?");
+			ps.setString(1, "patient");
+			ps.setLong(2, mid);
+
+			ps.executeUpdate();
+			ps.close();
+
+		} catch (SQLException e) {
+			throw new DBException(e);
+		} finally {
+			DBUtil.closeConnection(conn, ps);
+		}
+	}
 	
 	/**
 	 * Return a list of patients with a special-diagnosis-history who
-- 
GitLab