Skip to content
Snippets Groups Projects
Commit 9da70c99 authored by adityab3's avatar adityab3
Browse files
parents 1e8572f1 11255812
No related branches found
No related tags found
1 merge request!26UC14
Showing
with 945 additions and 17 deletions
DELETE FROM users WHERE MID = 90;
DELETE FROM officevisits WHERE PatientID = 90;
DELETE FROM patients WHERE MID = 90;
INSERT INTO users(MID, password, role, sQuestion, sAnswer)
VALUES (90, '30c952fab122c3f9759f02a6d95c3758b246b4fee239957b2d4fee46e26170c4', 'patient', 'what is your favorite color?', 'blue')
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO patients (MID, Gender, DateOfDeath, CauseOfDeath)
VALUES (90,'Male','2019-01-01',487.00)
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO officevisits(id,visitDate,HCPID,notes,HospitalID,PatientID)
VALUES (20780,'2019-01-01',9000000003,'died','1',90)
ON DUPLICATE KEY UPDATE id = id;
\ No newline at end of file
DELETE FROM users WHERE MID = 82;
DELETE FROM officevisits WHERE PatientID = 82;
DELETE FROM patients WHERE MID = 82;
INSERT INTO users(MID, password, role, sQuestion, sAnswer)
VALUES (82, '30c952fab122c3f9759f02a6d95c3758b246b4fee239957b2d4fee46e26170c4', 'patient', 'what is your favorite color?', 'blue')
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO patients (MID, Gender, DateOfDeath, CauseOfDeath)
VALUES (82,'Male','2018-07-01',11.40)
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO officevisits(id,visitDate,HCPID,notes,HospitalID,PatientID)
VALUES (20772,'2018-07-01',9000000000,'died','1',82)
ON DUPLICATE KEY UPDATE id = id;
\ No newline at end of file
DELETE FROM users WHERE MID = 83;
DELETE FROM officevisits WHERE PatientID = 83;
DELETE FROM patients WHERE MID = 83;
INSERT INTO users(MID, password, role, sQuestion, sAnswer)
VALUES (83, '30c952fab122c3f9759f02a6d95c3758b246b4fee239957b2d4fee46e26170c4', 'patient', 'what is your favorite color?', 'blue')
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO patients (MID, Gender, DateOfDeath, CauseOfDeath)
VALUES (83,'Female','2018-07-01',11.40)
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO officevisits(id,visitDate,HCPID,notes,HospitalID,PatientID)
VALUES (20773,'2018-07-01',9000000000,'died','1',83)
ON DUPLICATE KEY UPDATE id = id;
\ No newline at end of file
DELETE FROM users WHERE MID = 84;
DELETE FROM officevisits WHERE PatientID = 84;
DELETE FROM patients WHERE MID = 84;
INSERT INTO users(MID, password, role, sQuestion, sAnswer)
VALUES (84, '30c952fab122c3f9759f02a6d95c3758b246b4fee239957b2d4fee46e26170c4', 'patient', 'what is your favorite color?', 'blue')
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO patients (MID, Gender, DateOfDeath, CauseOfDeath)
VALUES (84,'Male','2018-12-01',11.40)
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO officevisits(id,visitDate,HCPID,notes,HospitalID,PatientID)
VALUES (20774,'2018-12-01',9000000000,'died','1',84)
ON DUPLICATE KEY UPDATE id = id;
\ No newline at end of file
DELETE FROM users WHERE MID = 85;
DELETE FROM officevisits WHERE PatientID = 85;
DELETE FROM patients WHERE MID = 85;
INSERT INTO users(MID, password, role, sQuestion, sAnswer)
VALUES (85, '30c952fab122c3f9759f02a6d95c3758b246b4fee239957b2d4fee46e26170c4', 'patient', 'what is your favorite color?', 'blue')
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO patients (MID, Gender, DateOfDeath, CauseOfDeath)
VALUES (85,'Male','2020-01-01',84.50)
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO officevisits(id,visitDate,HCPID,notes,HospitalID,PatientID)
VALUES (20775,'2020-01-01',9000000000,'died','1',85)
ON DUPLICATE KEY UPDATE id = id;
\ No newline at end of file
DELETE FROM users WHERE MID = 86;
DELETE FROM officevisits WHERE PatientID = 86;
DELETE FROM patients WHERE MID = 86;
INSERT INTO users(MID, password, role, sQuestion, sAnswer)
VALUES (86, '30c952fab122c3f9759f02a6d95c3758b246b4fee239957b2d4fee46e26170c4', 'patient', 'what is your favorite color?', 'blue')
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO patients (MID, Gender, DateOfDeath, CauseOfDeath)
VALUES (86,'Male','2018-12-01',487.00)
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO officevisits(id,visitDate,HCPID,notes,HospitalID,PatientID)
VALUES (20776,'2018-12-01',9000000000,'died','1',86)
ON DUPLICATE KEY UPDATE id = id;
\ No newline at end of file
DELETE FROM users WHERE MID = 87;
DELETE FROM officevisits WHERE PatientID = 87;
DELETE FROM patients WHERE MID = 87;
INSERT INTO users(MID, password, role, sQuestion, sAnswer)
VALUES (87, '30c952fab122c3f9759f02a6d95c3758b246b4fee239957b2d4fee46e26170c4', 'patient', 'what is your favorite color?', 'blue')
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO patients (MID, Gender, DateOfDeath, CauseOfDeath)
VALUES (87,'Female','2019-12-01',487.00)
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO officevisits(id,visitDate,HCPID,notes,HospitalID,PatientID)
VALUES (20777,'2019-12-01',9000000003,'died','1',87)
ON DUPLICATE KEY UPDATE id = id;
DELETE FROM users WHERE MID = 88;
DELETE FROM officevisits WHERE PatientID = 88;
DELETE FROM patients WHERE MID = 88;
INSERT INTO users(MID, password, role, sQuestion, sAnswer)
VALUES (88, '30c952fab122c3f9759f02a6d95c3758b246b4fee239957b2d4fee46e26170c4', 'patient', 'what is your favorite color?', 'blue')
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO patients (MID, Gender, DateOfDeath, CauseOfDeath)
VALUES (88,'Female','2020-07-01',487.00)
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO officevisits(id,visitDate,HCPID,notes,HospitalID,PatientID)
VALUES (20778,'2020-07-01',9000000003,'died','1',88)
ON DUPLICATE KEY UPDATE id = id;
\ No newline at end of file
DELETE FROM users WHERE MID = 89;
DELETE FROM officevisits WHERE PatientID = 89;
DELETE FROM patients WHERE MID = 89;
INSERT INTO users(MID, password, role, sQuestion, sAnswer)
VALUES (89, '30c952fab122c3f9759f02a6d95c3758b246b4fee239957b2d4fee46e26170c4', 'patient', 'what is your favorite color?', 'blue')
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO patients (MID, Gender, DateOfDeath, CauseOfDeath)
VALUES (89,'Male','2020-01-01',487.00)
ON DUPLICATE KEY UPDATE MID = MID;
INSERT INTO officevisits(id,visitDate,HCPID,notes,HospitalID,PatientID)
VALUES (20779,'2020-01-01',9000000003,'died','1',89)
ON DUPLICATE KEY UPDATE id = id;
\ No newline at end of file
package edu.ncsu.csc.itrust.action;
import edu.ncsu.csc.itrust.RandomPassword;
import edu.ncsu.csc.itrust.beans.PatientBean;
import java.io.PrintWriter;
import java.io.StringWriter;
import edu.ncsu.csc.itrust.beans.HealthRecord;
import edu.ncsu.csc.itrust.beans.forms.HealthRecordForm;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.dao.mysql.AuthDAO;
import edu.ncsu.csc.itrust.dao.mysql.HealthRecordsDAO;
import edu.ncsu.csc.itrust.enums.Role;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.validate.AddPatientValidator;
import edu.ncsu.csc.itrust.validate.HealthRecordFormValidator;
/**
* Used for Add Pre-registered Patient page (PreRegisterPatient.jsp). This just adds an empty patient, creates an entered password for
......@@ -22,7 +29,8 @@ import edu.ncsu.csc.itrust.validate.AddPatientValidator;
public class AddPreRegisteredPatientAction {
private PatientDAO patientDAO;
private AuthDAO authDAO;
private long loggedInMID;
private long loggedInMID;
private HealthRecordsDAO healthDAO;
/**
* Just the factory and logged in MID
......@@ -33,7 +41,8 @@ public class AddPreRegisteredPatientAction {
public AddPreRegisteredPatientAction(DAOFactory factory, long loggedInMID) {
this.patientDAO = factory.getPatientDAO();
this.loggedInMID = loggedInMID;
this.authDAO = factory.getAuthDAO();
this.authDAO = factory.getAuthDAO();
this.healthDAO = factory.getHealthRecordsDAO();
}
/**
......@@ -47,9 +56,9 @@ public class AddPreRegisteredPatientAction {
*/
public long addPatient(PatientBean p) throws FormValidationException, ITrustException {
public long addPatient(PatientBean p, HealthRecordForm h) throws FormValidationException, ITrustException {
new AddPatientValidator().validate(p);
new HealthRecordFormValidator().validatePreregistration(h);
// Make sure the email is unique
if (patientDAO.isEmailInUse(p.getEmail())) {
......@@ -62,7 +71,24 @@ public class AddPreRegisteredPatientAction {
String pwd = authDAO.addUser(newMID, Role.PREREGISTEREDPATIENT, p.getPassword());
p.setPassword(pwd);
patientDAO.editPatient(p, loggedInMID);
return newMID;
}
patientDAO.editPatient(p, loggedInMID);
// Convert the HealthRecordForm into a HeathRecord
HealthRecord r = formToRecord(h, newMID);
healthDAO.add(r);
return newMID;
}
// TODO: this is taken directly from EditHealthAction.java (DRY)
private HealthRecord formToRecord(HealthRecordForm form, long pid) {
HealthRecord record = new HealthRecord();
record.setPatientID(pid);
if (!"".equals(form.getHeight()))
record.setHeight(Double.parseDouble(form.getHeight()));
if (!"".equals(form.getWeight()))
record.setWeight(Double.parseDouble(form.getWeight()));
record.setSmoker(Integer.parseInt(form.getIsSmoker()));
return record;
}
}
package edu.ncsu.csc.itrust.action;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import edu.ncsu.csc.itrust.beans.ApptBean;
import edu.ncsu.csc.itrust.beans.MessageBean;
import edu.ncsu.csc.itrust.beans.PersonnelBean;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.ApptDAO;
import edu.ncsu.csc.itrust.dao.mysql.PersonnelDAO;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.exception.ITrustException;
import java.util.*;
public class SendRemindersAction {
public final long systemReminderMID;
private long loggedInMID;
private ApptDAO apptDAO;
private SendMessageAction smAction;
public SendRemindersAction(DAOFactory factory, long loggedInMID) throws DBException {
PersonnelDAO personnelDAO = factory.getPersonnelDAO();
List<PersonnelBean> personnels = personnelDAO.searchForPersonnelWithName("System", "Reminder");
this.systemReminderMID = personnels.get(0).getMID();
this.loggedInMID = loggedInMID;
this.apptDAO = factory.getApptDAO();
this.smAction = new SendMessageAction(factory, systemReminderMID);
}
public void sendReminder(ApptBean aBean) throws ITrustException, SQLException, FormValidationException {
LocalDateTime now = LocalDateTime.now();
LocalDateTime date = aBean.getDate().toLocalDateTime();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm, MMM d");
MessageBean message = new MessageBean();
message.setTo(aBean.getPatient());
message.setFrom(systemReminderMID);
message.setSubject(String.format("Reminder: upcoming appointment in %d day(s)", now.truncatedTo(ChronoUnit.DAYS).until(date.truncatedTo(ChronoUnit.DAYS), ChronoUnit.DAYS)));
message.setBody(String.format("You have an appointment on %s with Dr. %s", date.format(formatter), smAction.getPersonnelName(aBean.getHcp())));
message.setSentDate(Timestamp.valueOf(now));
smAction.sendMessage(message);
}
public int sendReminderForAppointments(int numDays) throws ITrustException {
List<ApptBean> appointments = null;
try {
appointments = apptDAO.getUpcomingAppts(numDays);
for (ApptBean appt : appointments) {
sendReminder(appt);
}
return appointments.size();
} catch (DBException e) {
throw new ITrustException("DB Error in sending reminders.");
} catch (SQLException e) {
throw new ITrustException("SQL Error in sending reminders.");
} catch (FormValidationException e) {
throw new ITrustException("Form Validation Error in sending reminders.");
}
}
}
\ No newline at end of file
package edu.ncsu.csc.itrust.beans;
public class CauseOfDeathTrendsReportBean {
/** The name of the diagnosis cause of death */
String cause;
/** The code of the diagnosis cause of death */
String code;
/** The quantity of the deaths */
String deaths;
/**
* Constructor for an empty bean
*/
public CauseOfDeathTrendsReportBean() {
}
/**
* Constructor for the bean. Accepts cause of death name, cause of death code, and quantity of deaths
* @param cause The cause of death name
* @param code The cause of death code
* @param deaths The quantity of deaths for the chosen death code
*/
public CauseOfDeathTrendsReportBean(String cause, String code, String deaths) {
this.cause = cause;
this.code = code;
this.deaths = deaths;
}
/**
* Getter for cause of death name
* @return The stored cause of death name
*/
public String getCause() {
return cause;
}
/**
* Setter for cause of death name
* @param cause The cause of death name to be stored
*/
public void setCause(String cause) {
this.cause = cause;
}
/**
* Getter for cause of death code
* @return The stored cause of death code
*/
public String getCode() {
return code;
}
/**
* Setter for cause of death name
* @param code The cause of death name to be stored
*/
public void setCode(String code) {
this.code = code;
}
/**
* Getter for quantity of deaths
* @return The stored quantity of deaths
*/
public String getDeaths() {
return deaths;
}
/**
* Setter for quantity of deaths
* @param deaths The stored quantity of deaths
*/
public void setDeaths(String deaths) {
this.deaths = deaths;
}
}
......@@ -499,4 +499,4 @@ public class PatientBean implements Serializable, Comparable<PatientBean> {
return 42; // any arbitrary constant will do
}
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package edu.ncsu.csc.itrust.beans.loaders;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
......@@ -39,8 +40,12 @@ public class HealthRecordsBeanLoader implements BeanLoader<HealthRecord> {
ps.setInt(i++, bean.getCholesterolHDL());
ps.setInt(i++, bean.getCholesterolLDL());
ps.setInt(i++, bean.getCholesterolTri());
ps.setLong(i++, bean.getPersonnelID());
ps.setDate(i++, new java.sql.Date(bean.getVisitDate().getTime()));
ps.setLong(i++, bean.getPersonnelID());
if (bean.getVisitDate() != null) {
ps.setDate(i++, new java.sql.Date(bean.getVisitDate().getTime()));
} else {
ps.setDate(i++, new java.sql.Date(0));
}
ps.setDouble(i++, bean.getBodyMassIndex());
return ps;
......
......@@ -328,5 +328,35 @@ public class ApptDAO {
}
}
/**
* Get all upcoming appointments within n days
* @param numDays Number of days after current date within which to find all appointments
* @return ApptBean List of upcoming appointments
*/
public List<ApptBean> getUpcomingAppts(int numDays) throws SQLException, DBException {
Connection conn = null;
PreparedStatement pstring = null;
try {
conn = factory.getConnection();
pstring = conn.prepareStatement(
"SELECT * FROM appointment WHERE " + /*" sched_date.after(?)=TRUE AND sched_date.before(?)=TRUE");*/
"DATE(sched_date)<=DATE_ADD(CURRENT_DATE, INTERVAL ? DAY) AND " + //sched_date day is before or at (numDays) days from now
"sched_date>=CURRENT_DATE"); // sched_date is after today
pstring.setInt(1, numDays);
final ResultSet results = pstring.executeQuery();
final List<ApptBean> abList = this.abloader.loadList(results);
results.close();
pstring.close();
return abList;
} catch (SQLException e) {
throw new DBException(e);
} finally {
DBUtil.closeConnection(conn, pstring);
}
}
}
......@@ -134,7 +134,8 @@ public class AuthDAO {
case ER:
case LT:
uName = factory.getPersonnelDAO().getName(mid);
break;
break;
case PREREGISTEREDPATIENT:
case PATIENT:
uName = factory.getPatientDAO().getName(mid);
break;
......
package edu.ncsu.csc.itrust.dao.mysql;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Date;
import java.time.format.DateTimeFormatter;
import java.time.LocalDate;
import java.util.List;
import java.util.ArrayList;
import edu.ncsu.csc.itrust.DBUtil;
import edu.ncsu.csc.itrust.beans.CauseOfDeathTrendsReportBean;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.exception.ITrustException;
import java.time.format.DateTimeParseException;
public class CauseOfDeathTrendsReportDAO {
private DAOFactory factory;
/**
* The typical constructor.
* @param factory The {@link DAOFactory} associated with this DAO, which is used for obtaining SQL connections, etc.
*/
public CauseOfDeathTrendsReportDAO(DAOFactory factory) {
this.factory = factory;
}
/**
* Returns a list of patients for a particular HCP
*
* @param hcpMID The MID of the HCP to look up.
* @return A java.util.List of PatientsForHCP.
* @throws DBException
*/
public List<Long> getPatientsForHCP(long hcpMID) throws DBException {
Connection conn = null;
PreparedStatement stmt = null;
List<Long> patients = new ArrayList<Long>();
try {
conn = factory.getConnection();
stmt = conn.prepareStatement("SELECT DISTINCT PatientID FROM officevisits WHERE HCPID = ?");
stmt.setLong(1, hcpMID);
ResultSet rs = stmt.executeQuery();
while(rs.next()) {
Long patient = rs.getLong("PatientID");
patients.add(patient);
}
rs.close();
} catch (SQLException e) {
throw new DBException(e);
} finally {
DBUtil.closeConnection(conn, stmt);
}
return patients;
}
/**
* Returns a list of the top two causes of deaths for a particular HCP
*
* @param hcpMID The MID of the HCP to look up.
* @param gender Gender of the patients - All, Female, Male
* @param startingDate Start date of search.
* @param endingDate End date of search.
* @return A java.util.List of TopTwoDeathsForHCP.
* @throws DBException
*/
public ArrayList<CauseOfDeathTrendsReportBean> getTopTwoDeathsForHCP(long hcpMID, String gender, String startingDate, String endingDate) throws FormValidationException, ITrustException {
Connection conn = null;
PreparedStatement stmt = null;
List<Long> patients = this.getPatientsForHCP(hcpMID);
ArrayList<CauseOfDeathTrendsReportBean> causes;
String query = null;
java.sql.Date startDate;
java.sql.Date endDate;
try {
if (startingDate == null || endingDate == null)
return null;
causes = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String lower = LocalDate.parse(startingDate, formatter).format(formatter2);
String upper = LocalDate.parse(endingDate, formatter).format(formatter2);
startDate = Date.valueOf(lower);
endDate = Date.valueOf(upper);
if (startDate.after(endDate))
throw new FormValidationException("Start date must be before end date!");
conn = factory.getConnection();
if(gender.equalsIgnoreCase("All")){
query = "SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients WHERE MID IN (";
for(int i = 0; i < patients.size(); i++)
{
if (i+1 == patients.size()){
query += patients.get(i);
}
else{
query += patients.get(i) + ",";
}
}
query += ") AND DateOfDeath IS NOT NULL AND YEAR(DateOfDeath) >= YEAR(?) AND YEAR(DateOfDeath) <= YEAR(?)"
+ "GROUP BY CauseOfDeath ORDER BY COUNT(CauseOfDeath) DESC";
stmt = conn.prepareStatement(query);
stmt.setDate(1, startDate);
stmt.setDate(2, endDate);
}
else{
query = "SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients WHERE MID IN (";
for(int i = 0; i < patients.size(); i++)
{
if (i+1 == patients.size()){
query += patients.get(i);
}
else{
query += patients.get(i) + ",";
}
}
query += ") AND DateOfDeath IS NOT NULL AND Gender = ? AND YEAR(DateOfDeath) >= YEAR(?) AND YEAR(DateOfDeath) <= YEAR(?)"
+ "GROUP BY CauseOfDeath ORDER BY COUNT(CauseOfDeath) DESC";
stmt = conn.prepareStatement(query);
stmt.setString(1, gender);
stmt.setDate(2, startDate);
stmt.setDate(3, endDate);
}
ResultSet rs = stmt.executeQuery();
int count = 0;
while(rs.next() && count < 2) {
String cause = rs.getString("CauseOfDeath");
String deaths = rs.getString("COUNT(CauseOfDeath)");
String name = this.getCodeName(cause);
causes.add(new CauseOfDeathTrendsReportBean(name, cause, deaths));
count++;
}
if (causes.isEmpty())
throw new FormValidationException("No results returned");
rs.close();
stmt.close();
} catch (SQLException e) {
throw new DBException(e);
} catch (DateTimeParseException e) {
throw new FormValidationException("Enter dates in MM/dd/yyyy");
} finally {
DBUtil.closeConnection(conn, stmt);
}
return causes;
}
/**
* Returns a list of the top two causes of deaths for a all HCPs
*
* @param gender Gender of the patients - All, Female, Male
* @param startingDate Start date of search.
* @param endingDate End date of search.
* @return A java.util.List of TopTwoDeathsForAll.
* @throws DBException
*/
public ArrayList<CauseOfDeathTrendsReportBean> getTopTwoDeathsForAll(String gender, String startingDate, String endingDate) throws FormValidationException, ITrustException {
Connection conn = null;
PreparedStatement stmt = null;
ArrayList<CauseOfDeathTrendsReportBean> causes;
String query = null;
java.sql.Date startDate;
java.sql.Date endDate;
try {
if (startingDate == null || endingDate == null)
return null;
causes = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String lower = LocalDate.parse(startingDate, formatter).format(formatter2);
String upper = LocalDate.parse(endingDate, formatter).format(formatter2);
startDate = Date.valueOf(lower);
endDate = Date.valueOf(upper);
if (startDate.after(endDate))
throw new FormValidationException("Start date must be before end date!");
conn = factory.getConnection();
if(gender.equalsIgnoreCase("All")){
query = "SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients"
+ " WHERE DateOfDeath IS NOT NULL AND YEAR(DateOfDeath) >= YEAR(?) AND YEAR(DateOfDeath) <= YEAR(?)"
+ "GROUP BY CauseOfDeath ORDER BY COUNT(CauseOfDeath) DESC";
stmt = conn.prepareStatement(query);
stmt.setDate(1, startDate);
stmt.setDate(2, endDate);
}
else{
query = "SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients"
+ " WHERE DateOfDeath IS NOT NULL AND Gender = ? AND YEAR(DateOfDeath) >= YEAR(?) AND YEAR(DateOfDeath) <= YEAR(?)"
+ "GROUP BY CauseOfDeath ORDER BY COUNT(CauseOfDeath) DESC";
stmt = conn.prepareStatement(query);
stmt.setString(1, gender);
stmt.setDate(2, startDate);
stmt.setDate(3, endDate);
}
ResultSet rs = stmt.executeQuery();
int count = 0;
while(rs.next() && count < 2) {
String cause = rs.getString("CauseOfDeath");
String deaths = rs.getString("COUNT(CauseOfDeath)");
String name = this.getCodeName(cause);
causes.add(new CauseOfDeathTrendsReportBean(name, cause, deaths));
count++;
}
if (causes.isEmpty())
throw new FormValidationException("No results returned");
rs.close();
stmt.close();
} catch (SQLException e) {
throw new DBException(e);
} catch (DateTimeParseException e) {
throw new FormValidationException("Enter dates in MM/dd/yyyy");
} finally {
DBUtil.closeConnection(conn, stmt);
}
return causes;
}
/**
* Returns the code name for a particular ICD-9CM code.
*
* @param code ICD-9CM code.
* @return the name of the ICD-9CM code.
* @throws DBException
*/
public String getCodeName(String code) throws DBException {
Connection conn = null;
PreparedStatement stmt = null;
String result = null;
try {
conn = factory.getConnection();
stmt = conn.prepareStatement("SELECT Description FROM icdcodes WHERE Code = ?");
stmt.setString(1, code);
ResultSet rs = stmt.executeQuery();
if(rs.next()){
result = rs.getString("Description");
rs.close();
stmt.close();
}
else{
rs.close();
stmt.close();
return null;
}
} catch (SQLException e) {
throw new DBException(e);
} finally {
DBUtil.closeConnection(conn, stmt);
}
return result;
}
}
......@@ -162,10 +162,13 @@ abstract public class BeanValidator<T> {
else
return name + " must be either 'true' or 'false'";
}
protected String checkNotZero(String name, String value, ValidationFormat format, boolean isNullable) {
String s = checkFormat(name, value, format, isNullable);
if (s.equals("")) {
String s = checkFormat(name, value, format, isNullable);
if (s.equals("")) {
if (isNullable && (value == null || "".equals(value))) {
return s;
}
if (Double.valueOf(value) < 0.1) {
return name + " must be greater than 0";
}
......
......@@ -56,6 +56,13 @@ public class HealthRecordFormValidator extends BeanValidator<HealthRecordForm> {
throw new FormValidationException(errorList);
}
public void validatePreregistration(HealthRecordForm bean) throws FormValidationException {
ErrorList errorList = new ErrorList();
errorList.addIfNotNull(checkNotZero("Height", bean.getHeight(), ValidationFormat.Height, true));
errorList.addIfNotNull(checkNotZero("Weight", bean.getWeight(), ValidationFormat.Weight, true));
errorList.addIfNotNull(checkInt("Smoker", bean.getIsSmoker(), 0, 10, false));
if (errorList.hasErrors())
throw new FormValidationException(errorList);
}
}
package edu.ncsu.csc.itrust.selenium;
import edu.ncsu.csc.itrust.enums.TransactionType;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.ui.Select;
public class CauseOfDeathTrendsReportSeleniumTest extends iTrustSeleniumTest {
private HtmlUnitDriver driver;
@Override
protected void setUp() throws Exception {
super.setUp();
gen.clearAllTables();
gen.standardData();
}
public void testViewCODTrendsReports_AllPatientsAllGenders() throws Exception {
driver = (HtmlUnitDriver)login("9000000000", "pw");
// Click Diagnosis Trends
driver.findElement(By.cssSelector("h2.panel-title")).click();
driver.findElement(By.xpath("//div[@class='panel-body']/ul/li[11]")).click();
driver.findElement(By.linkText("Cause-Of-Death Trends Report")).click();
// View Cause of Death Trends Report
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
driver.findElement(By.name("startDate")).clear();
driver.findElement(By.name("startDate")).sendKeys("01/01/2000");
driver.findElement(By.name("endDate")).sendKeys("12/31/2020");
driver.findElement(By.id("view_report")).click();
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
assertLogged(TransactionType.DEATH_TRENDS_VIEW, 9000000000L, 0L,
"View cause-of-death trends report");
WebElement table = driver.findElement(By.id("causeOfDeathTrendsTable"));
String cause1 = table.findElements(By.tagName("td")).get(0).getText();
double code1 = Double.parseDouble(table.findElements(By.tagName("td")).get(1).getText());
int deaths1 = Integer.parseInt(table.findElements(By.tagName("td")).get(2).getText());
assertEquals(cause1, "Influenza");
assertEquals(code1, 487.00);
assertEquals(deaths1, 5);
String cause2 = table.findElements(By.tagName("td")).get(3).getText();
double code2 = Double.parseDouble(table.findElements(By.tagName("td")).get(4).getText());
int deaths2 = Integer.parseInt(table.findElements(By.tagName("td")).get(5).getText());
assertEquals(cause2, "Tuberculosis of the lung");
assertEquals(code2, 11.40);
assertEquals(deaths2, 3);
}
public void testViewCODTrendsReports_AllPatientsOnlyMale() throws Exception {
driver = (HtmlUnitDriver)login("9000000000", "pw");
// Click Diagnosis Trends
driver.findElement(By.cssSelector("h2.panel-title")).click();
driver.findElement(By.xpath("//div[@class='panel-body']/ul/li[11]")).click();
driver.findElement(By.linkText("Cause-Of-Death Trends Report")).click();
// View Cause of Death Trends Report
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
new Select(driver.findElement(By.name("gender"))).selectByVisibleText("Male");
driver.findElement(By.name("startDate")).clear();
driver.findElement(By.name("startDate")).sendKeys("01/01/2000");
driver.findElement(By.name("endDate")).sendKeys("12/31/2020");
driver.findElement(By.id("view_report")).click();
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
assertLogged(TransactionType.DEATH_TRENDS_VIEW, 9000000000L, 0L,
"View cause-of-death trends report");
WebElement table = driver.findElement(By.id("causeOfDeathTrendsTable"));
String cause1 = table.findElements(By.tagName("td")).get(0).getText();
double code1 = Double.parseDouble(table.findElements(By.tagName("td")).get(1).getText());
int deaths1 = Integer.parseInt(table.findElements(By.tagName("td")).get(2).getText());
assertEquals(cause1, "Influenza");
assertEquals(code1, 487.00);
assertEquals(deaths1, 3);
String cause2 = table.findElements(By.tagName("td")).get(3).getText();
double code2 = Double.parseDouble(table.findElements(By.tagName("td")).get(4).getText());
int deaths2 = Integer.parseInt(table.findElements(By.tagName("td")).get(5).getText());
assertEquals(cause2, "Malaria");
assertEquals(code2, 84.50);
assertEquals(deaths2, 2);
}
public void testViewCODTrendsReports_AllPatientsOnlyFemale() throws Exception {
driver = (HtmlUnitDriver)login("9000000003", "pw");
// Click Diagnosis Trends
driver.findElement(By.cssSelector("h2.panel-title")).click();
driver.findElement(By.xpath("//div[@class='panel-body']/ul/li[11]")).click();
driver.findElement(By.linkText("Cause-Of-Death Trends Report")).click();
// View Cause of Death Trends Report
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
new Select(driver.findElement(By.name("gender"))).selectByVisibleText("Female");
driver.findElement(By.name("startDate")).clear();
driver.findElement(By.name("startDate")).sendKeys("01/01/2000");
driver.findElement(By.name("endDate")).sendKeys("12/31/2020");
driver.findElement(By.id("view_report")).click();
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
assertLogged(TransactionType.DEATH_TRENDS_VIEW, 9000000003L, 0L,
"View cause-of-death trends report");
WebElement table = driver.findElement(By.id("causeOfDeathTrendsTable"));
String cause1 = table.findElements(By.tagName("td")).get(0).getText();
double code1 = Double.parseDouble(table.findElements(By.tagName("td")).get(1).getText());
int deaths1 = Integer.parseInt(table.findElements(By.tagName("td")).get(2).getText());
assertEquals(cause1, "Influenza");
assertEquals(code1, 487.00);
assertEquals(deaths1, 2);
String cause2 = table.findElements(By.tagName("td")).get(3).getText();
double code2 = Double.parseDouble(table.findElements(By.tagName("td")).get(4).getText());
int deaths2 = Integer.parseInt(table.findElements(By.tagName("td")).get(5).getText());
assertEquals(cause2, "Tuberculosis of the lung");
assertEquals(code2, 11.40);
assertEquals(deaths2, 1);
}
public void testViewCODTrendsReports_MyPatientsAllGenders() throws Exception {
driver = (HtmlUnitDriver)login("9000000003", "pw");
// Click Diagnosis Trends
driver.findElement(By.cssSelector("h2.panel-title")).click();
driver.findElement(By.xpath("//div[@class='panel-body']/ul/li[11]")).click();
driver.findElement(By.linkText("Cause-Of-Death Trends Report")).click();
// View Cause of Death Trends Report
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
new Select(driver.findElement(By.name("patients"))).selectByVisibleText("My Patients");
driver.findElement(By.name("startDate")).clear();
driver.findElement(By.name("startDate")).sendKeys("01/01/2000");
driver.findElement(By.name("endDate")).sendKeys("12/31/2020");
driver.findElement(By.id("view_report")).click();
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
assertLogged(TransactionType.DEATH_TRENDS_VIEW, 9000000003L, 0L,
"View cause-of-death trends report");
WebElement table = driver.findElement(By.id("causeOfDeathTrendsTable"));
String cause1 = table.findElements(By.tagName("td")).get(0).getText();
double code1 = Double.parseDouble(table.findElements(By.tagName("td")).get(1).getText());
int deaths1 = Integer.parseInt(table.findElements(By.tagName("td")).get(2).getText());
assertEquals(cause1, "Influenza");
assertEquals(code1, 487.00);
assertEquals(deaths1, 4);
String cause2 = table.findElements(By.tagName("td")).get(3).getText();
double code2 = Double.parseDouble(table.findElements(By.tagName("td")).get(4).getText());
int deaths2 = Integer.parseInt(table.findElements(By.tagName("td")).get(5).getText());
assertEquals(cause2, "Diabetes with ketoacidosis");
assertEquals(code2, 250.10);
assertEquals(deaths2, 1);
}
public void testViewCODTrendsReports_MyPatientsOnlyMale() throws Exception {
driver = (HtmlUnitDriver)login("9000000003", "pw");
// Click Diagnosis Trends
driver.findElement(By.cssSelector("h2.panel-title")).click();
driver.findElement(By.xpath("//div[@class='panel-body']/ul/li[11]")).click();
driver.findElement(By.linkText("Cause-Of-Death Trends Report")).click();
// View Cause of Death Trends Report
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
new Select(driver.findElement(By.name("patients"))).selectByVisibleText("My Patients");
new Select(driver.findElement(By.name("gender"))).selectByVisibleText("Male");
driver.findElement(By.name("startDate")).clear();
driver.findElement(By.name("startDate")).sendKeys("01/01/2000");
driver.findElement(By.name("endDate")).sendKeys("12/31/2020");
driver.findElement(By.id("view_report")).click();
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
assertLogged(TransactionType.DEATH_TRENDS_VIEW, 9000000003L, 0L,
"View cause-of-death trends report");
WebElement table = driver.findElement(By.id("causeOfDeathTrendsTable"));
String cause1 = table.findElements(By.tagName("td")).get(0).getText();
double code1 = Double.parseDouble(table.findElements(By.tagName("td")).get(1).getText());
int deaths1 = Integer.parseInt(table.findElements(By.tagName("td")).get(2).getText());
assertEquals(cause1, "Influenza");
assertEquals(code1, 487.00);
assertEquals(deaths1, 2);
String cause2 = table.findElements(By.tagName("td")).get(3).getText();
double code2 = Double.parseDouble(table.findElements(By.tagName("td")).get(4).getText());
int deaths2 = Integer.parseInt(table.findElements(By.tagName("td")).get(5).getText());
assertEquals(cause2, "Diabetes with ketoacidosis");
assertEquals(code2, 250.10);
assertEquals(deaths2, 1);
}
public void testViewCODTrendsReports_MyPatientsOnlyFemale() throws Exception {
driver = (HtmlUnitDriver)login("9000000003", "pw");
// Click Diagnosis Trends
driver.findElement(By.cssSelector("h2.panel-title")).click();
driver.findElement(By.xpath("//div[@class='panel-body']/ul/li[11]")).click();
driver.findElement(By.linkText("Cause-Of-Death Trends Report")).click();
// View Cause of Death Trends Report
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
new Select(driver.findElement(By.name("patients"))).selectByVisibleText("My Patients");
new Select(driver.findElement(By.name("gender"))).selectByVisibleText("Female");
driver.findElement(By.name("startDate")).clear();
driver.findElement(By.name("startDate")).sendKeys("01/01/2000");
driver.findElement(By.name("endDate")).sendKeys("12/31/2020");
driver.findElement(By.id("view_report")).click();
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
assertLogged(TransactionType.DEATH_TRENDS_VIEW, 9000000003L, 0L,
"View cause-of-death trends report");
WebElement table = driver.findElement(By.id("causeOfDeathTrendsTable"));
String cause1 = table.findElements(By.tagName("td")).get(0).getText();
double code1 = Double.parseDouble(table.findElements(By.tagName("td")).get(1).getText());
int deaths1 = Integer.parseInt(table.findElements(By.tagName("td")).get(2).getText());
assertEquals(cause1, "Influenza");
assertEquals(code1, 487.00);
assertEquals(deaths1, 2);
}
public void testViewCODTrendsReports_EmptyDates() throws Exception {
driver = (HtmlUnitDriver)login("9000000003", "pw");
// Click Diagnosis Trends
driver.findElement(By.cssSelector("h2.panel-title")).click();
driver.findElement(By.xpath("//div[@class='panel-body']/ul/li[11]")).click();
driver.findElement(By.linkText("Cause-Of-Death Trends Report")).click();
// View Cause of Death Trends Report
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
driver.findElement(By.name("startDate")).clear();
driver.findElement(By.name("startDate")).sendKeys("");
driver.findElement(By.name("endDate")).sendKeys("");
driver.findElement(By.id("view_report")).click();
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
assertLogged(TransactionType.DEATH_TRENDS_VIEW, 9000000003L, 0L,
"View cause-of-death trends report");
assertTrue(driver.getPageSource().contains("Enter dates in MM/dd/yyyy"));
}
public void testViewCODTrendsReports_InvalidDateFormat() throws Exception {
driver = (HtmlUnitDriver)login("9000000003", "pw");
// Click Diagnosis Trends
driver.findElement(By.cssSelector("h2.panel-title")).click();
driver.findElement(By.xpath("//div[@class='panel-body']/ul/li[11]")).click();
driver.findElement(By.linkText("Cause-Of-Death Trends Report")).click();
// View Cause of Death Trends Report
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
driver.findElement(By.name("startDate")).clear();
driver.findElement(By.name("startDate")).sendKeys("01-01-2000");
driver.findElement(By.name("endDate")).sendKeys("12-31-2020");
driver.findElement(By.id("view_report")).click();
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
assertLogged(TransactionType.DEATH_TRENDS_VIEW, 9000000003L, 0L,
"View cause-of-death trends report");
assertTrue(driver.getPageSource().contains("Enter dates in MM/dd/yyyy"));
}
public void testViewCODTrendsReports_StartDateAfterEndDate() throws Exception {
driver = (HtmlUnitDriver)login("9000000003", "pw");
// Click Diagnosis Trends
driver.findElement(By.cssSelector("h2.panel-title")).click();
driver.findElement(By.xpath("//div[@class='panel-body']/ul/li[11]")).click();
driver.findElement(By.linkText("Cause-Of-Death Trends Report")).click();
// View Cause of Death Trends Report
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
driver.findElement(By.name("startDate")).clear();
driver.findElement(By.name("startDate")).sendKeys("01/01/2021");
driver.findElement(By.name("endDate")).sendKeys("12/31/2020");
driver.findElement(By.id("view_report")).click();
assertTrue(driver.getCurrentUrl().equals(ADDRESS + "auth/hcp/causeOfDeathTrendsReport.jsp"));
assertLogged(TransactionType.DEATH_TRENDS_VIEW, 9000000003L, 0L,
"View cause-of-death trends report");
assertTrue(driver.getPageSource().contains("Start date must be before end date!"));
}
}
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