Skip to content
Snippets Groups Projects
Commit 5b2a9452 authored by mjw11's avatar mjw11
Browse files

Revert Registered bool, now use DateOfDeactivation

parent fbb68636
No related branches found
No related tags found
1 merge request!22Merge UC92 into Master
...@@ -73,18 +73,15 @@ public class PatientDAO { ...@@ -73,18 +73,15 @@ public class PatientDAO {
PreparedStatement ps = null; PreparedStatement ps = null;
try { try {
conn = factory.getConnection(); conn = factory.getConnection();
ps = conn.prepareStatement("SELECT Registered FROM patients WHERE MID=?"); ps = conn.prepareStatement("SELECT DateOfDeactivation FROM patients WHERE MID=?");
ps.setLong(1, mid); ps.setLong(1, mid);
ResultSet rs; ResultSet rs;
rs = ps.executeQuery(); rs = ps.executeQuery();
if (rs.next()) { if (rs.next()) {
Integer b = rs.getObject("Registered") != null ? rs.getInt("Registered") : null; if (rs.getDate("DateOfDeactivation") == null) {
if (b == 1) {
return true; return true;
} else if (b == 0) {
return false;
} else { } else {
throw new ITrustException("Number is not a boolean"); return false;
} }
} else { } else {
rs.close(); rs.close();
...@@ -111,9 +108,8 @@ public class PatientDAO { ...@@ -111,9 +108,8 @@ public class PatientDAO {
PreparedStatement ps = null; PreparedStatement ps = null;
try { try {
conn = factory.getConnection(); conn = factory.getConnection();
ps = conn.prepareStatement("UPDATE patients SET Registered = ? WHERE mid = ?"); ps = conn.prepareStatement("UPDATE patients SET DateOfDeactivation = NULL WHERE mid = ?");
ps.setByte(1, 1); ps.setLong(1, mid);
ps.setLong(2, mid);
ps.executeUpdate(); ps.executeUpdate();
ps.close(); ps.close();
return true; return true;
...@@ -139,11 +135,10 @@ public class PatientDAO { ...@@ -139,11 +135,10 @@ public class PatientDAO {
PreparedStatement ps = null; PreparedStatement ps = null;
try { try {
conn = factory.getConnection(); conn = factory.getConnection();
ps = conn.prepareStatement("UPDATE patients SET DateofDeactivation = ?, Registered = ? WHERE mid = ?"); ps = conn.prepareStatement("UPDATE patients SET DateofDeactivation = ? WHERE mid = ?");
Date date = new Date(Calendar.getInstance().getTime().getTime()); Date date = new Date(Calendar.getInstance().getTime().getTime());
ps.setDate(1, date); ps.setDate(1, date);
ps.setByte(2, 0); ps.setLong(2, mid);
ps.setLong(3, mid);
ps.executeUpdate(); ps.executeUpdate();
ps.close(); ps.close();
return true; return true;
...@@ -239,7 +234,9 @@ public class PatientDAO { ...@@ -239,7 +234,9 @@ public class PatientDAO {
PreparedStatement ps = null; PreparedStatement ps = null;
try { try {
conn = factory.getConnection(); conn = factory.getConnection();
ps = conn.prepareStatement("INSERT INTO patients(MID) VALUES(NULL)"); ps = conn.prepareStatement("INSERT INTO patients(DateOfDeactivation) VALUES(?)");
Date date = new Date(Calendar.getInstance().getTime().getTime());
ps.setDate(1, date);
ps.executeUpdate(); ps.executeUpdate();
long a = DBUtil.getLastInsert(conn); long a = DBUtil.getLastInsert(conn);
ps.close(); ps.close();
...@@ -1015,6 +1012,31 @@ public class PatientDAO { ...@@ -1015,6 +1012,31 @@ public class PatientDAO {
DBUtil.closeConnection(conn, ps); DBUtil.closeConnection(conn, ps);
} }
} }
/**
* Lists every preregistered patient in the database.
*
* @return A java.util.List of PatientBeans representing the preregistered patients.
* @throws DBException
*/
public List<PatientBean> getAllPreregisteredPatients() throws DBException {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = factory.getConnection();
ps = conn.prepareStatement("SELECT * FROM patients WHERE DateOfDeactivation IS NOT NULL");
ResultSet rs = ps.executeQuery();
List<PatientBean> loadlist = patientLoader.loadList(rs);
rs.close();
ps.close();
return loadlist;
} catch (SQLException e) {
throw new DBException(e);
} finally {
DBUtil.closeConnection(conn, ps);
}
}
/** /**
* Lists every patient in the database. * Lists every patient in the database.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment