Skip to content
Snippets Groups Projects

UC20 Data Access Object Completed

Closed ahmada4 requested to merge UC20 into master

Data Access Object for UC20 completed and can be found at: src/edu/ncsu/csc/itrust/dao/mysql/CauseOfDeathTrendsReportDAO.java

All JUnit tests pass with a code coverage of 91%. Test file can be found at: test/edu/ncsu/csc/itrust/unit/dao/deaths/CauseOfDeathTrendsReportTest.java

To test:

Repopulate the database, as dead patients are created specifically for testing:

java -cp "$(mvn -q dependency:build-classpath -Dmdep.outputFile=/dev/stdout)":target/classes:target/test-classes edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator

Then run the unit test file:

mvn -Dtest=CauseOfDeathTrendsReportTest test

Output should be:

Tests run: 9, Failures: 0, Errors: 0, Skipped: 0

Code coverage:

UC20CodeCoverage

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
62 * @param endDate End date of search.
63 * @return A java.util.List of TopTwoDeathsForHCP.
64 * @throws DBException
65 */
66 public List<String> getTopTwoDeathsForHCP(long hcpMID, String gender, Date startDate, Date endDate) throws DBException {
67 Connection conn = null;
68 PreparedStatement stmt = null;
69 List<Long> patients = this.getPatientsForHCP(hcpMID);
70 List<String> causes = new ArrayList<String>();
71 String query = null;
72
73 try {
74 conn = factory.getConnection();
75
76 if(gender.equalsIgnoreCase("All")){
77 query = "SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients WHERE MID IN (";
  • adityab3
    adityab3 @adityab3 started a thread on the diff
  • 64 * @throws DBException
    65 */
    66 public List<String> getTopTwoDeathsForHCP(long hcpMID, String gender, Date startDate, Date endDate) throws DBException {
    67 Connection conn = null;
    68 PreparedStatement stmt = null;
    69 List<Long> patients = this.getPatientsForHCP(hcpMID);
    70 List<String> causes = new ArrayList<String>();
    71 String query = null;
    72
    73 try {
    74 conn = factory.getConnection();
    75
    76 if(gender.equalsIgnoreCase("All")){
    77 query = "SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients WHERE MID IN (";
    78 for(int i = 0; i < patients.size(); i++)
    79 {
  • adityab3
    adityab3 @adityab3 started a thread on the diff
  • 80 if (i+1 == patients.size()){
    81 query += patients.get(i);
    82 }
    83 else{
    84 query += patients.get(i) + ",";
    85 }
    86
    87 }
    88 query += ") AND DateOfDeath IS NOT NULL AND YEAR(DateOfDeath) >= YEAR(?) AND YEAR(DateOfDeath) <= YEAR(?)"
    89 + "GROUP BY CauseOfDeath ORDER BY COUNT(CauseOfDeath) DESC";
    90 stmt = conn.prepareStatement(query);
    91 stmt.setDate(1, startDate);
    92 stmt.setDate(2, endDate);
    93 }
    94
    95 else{
    • A lot of the code in this if-else is duplicated. Consider pulling the for loop out of the if-else and just having the gender part in the if else.

    • Please register or sign in to reply
  • adityab3
    adityab3 @adityab3 started a thread on the diff
  • 144 List<String> causes = new ArrayList<String>();
    145 String query = null;
    146
    147 try {
    148 conn = factory.getConnection();
    149
    150 if(gender.equalsIgnoreCase("All")){
    151 query = "SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients"
    152 + " WHERE DateOfDeath IS NOT NULL AND YEAR(DateOfDeath) >= YEAR(?) AND YEAR(DateOfDeath) <= YEAR(?)"
    153 + "GROUP BY CauseOfDeath ORDER BY COUNT(CauseOfDeath) DESC";
    154 stmt = conn.prepareStatement(query);
    155 stmt.setDate(1, startDate);
    156 stmt.setDate(2, endDate);
    157 }
    158
    159 else{
  • adityab3
    adityab3 @adityab3 started a thread on the diff
  • 8 import edu.ncsu.csc.itrust.dao.mysql.CauseOfDeathTrendsReportDAO;
    9 import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
    10 import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
    11 import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory;
    12 import edu.ncsu.csc.itrust.exception.DBException;
    13
    14
    15 public class CauseOfDeathTrendsReportTest extends TestCase {
    16
    17 private TestDataGenerator gen = new TestDataGenerator();
    18 private CauseOfDeathTrendsReportDAO cod;
    19
    20 private CauseOfDeathTrendsReportDAO evilDAO = new CauseOfDeathTrendsReportDAO(EvilDAOFactory.getEvilInstance());
    21
    22 @Override
    23 protected void setUp() throws Exception {
  • Overall this looks good to me and the logic seems solid. The tests are passing when I run them locally. I have added some suggestions to improve efficiency and style.

  • sbobo3 added 1 commit

    added 1 commit

    • 63a6dc53 - Updated cause-of-death trends report to return report results (dates are...

    Compare with previous version

  • sbobo3 added 1 commit

    added 1 commit

    • 7281eda4 - Modified CauseOfDeathTrendsReportDAO getTopTwoDeaths methods to format dates in proper format

    Compare with previous version

  • sbobo3 added 1 commit

    added 1 commit

    • 010f0b92 - Updated causeOfDeathTrendsReport jsp to pass field values (patient, gender,...

    Compare with previous version

  • sbobo3 added 1 commit

    added 1 commit

    • 201a4f98 - Updated patients 1-8 to add death date and cause of death data. Also updated...

    Compare with previous version

  • sbobo3 added 1 commit

    added 1 commit

    • 208d6acb - Added event logging for CauseOfDeathTrendsReport jsp file.

    Compare with previous version

  • ahmada4 added 1 commit

    added 1 commit

    • 44d02901 - Updated unit tests to get results from CauseOfDeathTrendsReportBean

    Compare with previous version

  • ahmada4 added 1 commit

    added 1 commit

    • 76889cca - reverted patient1-8 sql files to original entry and updated deadPatient sql files

    Compare with previous version

  • ahmada4 added 1 commit

    added 1 commit

    • 38ab3386 - Updated testFilterByGender unit test to reflect the addition of three dead...

    Compare with previous version

  • sbobo3 added 2 commits

    added 2 commits

    • 046f2f79 - Added new FormValidationException to throw "no results returned" when database...
    • 5fba6658 - Added new FormValidationException to throw "no results returned" when database...

    Compare with previous version

  • sbobo3 added 1 commit

    added 1 commit

    • 57e4959c - Added Selenium tests for different combinations of selections on screen, as...

    Compare with previous version

  • ahmada4 added 1 commit

    added 1 commit

    • 5e04f75c - updated deadPatient SQL files and updated...

    Compare with previous version

  • sbobo3 added 1 commit

    added 1 commit

    • 5fc64694 - Fixed Selenium tests that were failing.

    Compare with previous version

  • ahmada4 added 2 commits

    added 2 commits

    Compare with previous version

  • ahmada4 added 1 commit

    added 1 commit

    • 9475e137 - returning PatientBean.java to original form with no code smells and pushing...

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading