Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs427fa20team22
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
htmoss2
cs427fa20team22
Commits
ee08c5fa
Commit
ee08c5fa
authored
4 years ago
by
ahmada4
Browse files
Options
Downloads
Patches
Plain Diff
added CauseOfDeathTrendsReportDAO.java file
parent
aae21b9d
No related branches found
Branches containing commit
No related tags found
2 merge requests
!7
Uc20
,
!2
UC20 Data Access Object Completed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
iTrust/src/edu/ncsu/csc/itrust/dao/mysql/CauseOfDeathTrendsReportDAO.java
+159
-0
159 additions, 0 deletions
...csu/csc/itrust/dao/mysql/CauseOfDeathTrendsReportDAO.java
with
159 additions
and
0 deletions
iTrust/src/edu/ncsu/csc/itrust/dao/mysql/CauseOfDeathTrendsReportDAO.java
0 → 100644
+
159
−
0
View file @
ee08c5fa
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.util.Date
;
import
java.util.List
;
import
java.util.ArrayList
;
import
edu.ncsu.csc.itrust.DBUtil
;
import
edu.ncsu.csc.itrust.dao.DAOFactory
;
import
edu.ncsu.csc.itrust.exception.DBException
;
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 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 startDate Start date of search.
* @param endDate End date of search.
* @return A java.util.List of TopTwoDeathsForHCP.
* @throws DBException
*/
public
List
<
String
>
getTopTwoDeathsForHCP
(
long
hcpMID
,
String
gender
,
Date
startDate
,
Date
endDate
)
throws
DBException
{
Connection
conn
=
null
;
PreparedStatement
stmt
=
null
;
List
<
String
>
results
=
new
ArrayList
<
String
>();
try
{
conn
=
factory
.
getConnection
();
if
(
gender
.
equalsIgnoreCase
(
"All"
)){
stmt
=
conn
.
prepareStatement
(
"SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients"
+
"WHERE HCPID = ? AND DateOfDeath IS NOT NULL AND YEAR(?) >= YEAR(DateOfDeath) AND YEAR(?) <= YEAR(DateOfDeath)"
+
"GROUP BY CauseOfDeath ORDER BY COUNT(CauseOfDeath) DESC"
);
stmt
.
setDate
(
1
,
startDate
);
stmt
.
setDate
(
2
,
endDate
);
}
else
{
stmt
=
conn
.
prepareStatement
(
"SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients"
+
"WHERE HCPID = ? AND DateOfDeath IS NOT NULL AND Gender = ? AND YEAR(?) >= YEAR(DateOfDeath) AND YEAR(?) <= YEAR(DateOfDeath)"
+
"GROUP BY CauseOfDeath ORDER BY COUNT(CauseOfDeath) DESC"
);
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
result
=
rs
.
getString
(
"CauseOfDeath"
);
if
(!
result
.
isEmpty
())
{
String
name
=
this
.
getCodeName
(
result
);
results
.
add
(
"Name: "
+
name
+
", Code: "
+
result
+
", Number of Deaths: "
+
rs
.
getString
(
"COUNT(CauseOfDeath)"
));
count
++;
}
}
rs
.
close
();
}
catch
(
SQLException
e
)
{
throw
new
DBException
(
e
);
}
finally
{
DBUtil
.
closeConnection
(
conn
,
stmt
);
}
return
results
;
}
/**
* Returns a list of the top two causes of deaths for a all HCPs
*
* @param gender Gender of the patients - All, Female, Male
* @param startDate Start date of search.
* @param endDate End date of search.
* @return A java.util.List of TopTwoDeathsForAll.
* @throws DBException
*/
public
List
<
String
>
getTopTwoDeathsForAll
(
String
gender
,
Date
startDate
,
Date
endDate
)
throws
DBException
{
Connection
conn
=
null
;
PreparedStatement
stmt
=
null
;
List
<
String
>
results
=
new
ArrayList
<
String
>();
try
{
conn
=
factory
.
getConnection
();
if
(
gender
.
equalsIgnoreCase
(
"All"
)){
stmt
=
conn
.
prepareStatement
(
"SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients"
+
"WHERE YEAR(?) >= YEAR(DateOfDeath) AND YEAR(?) <= YEAR(DateOfDeath)"
+
"GROUP BY CauseOfDeath ORDER BY COUNT(CauseOfDeath) DESC"
);
stmt
.
setDate
(
1
,
startDate
);
stmt
.
setDate
(
2
,
endDate
);
}
else
{
stmt
=
conn
.
prepareStatement
(
"SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients"
+
"WHERE Gender = ? AND YEAR(?) >= YEAR(DateOfDeath) AND YEAR(?) <= YEAR(DateOfDeath)"
+
"GROUP BY CauseOfDeath ORDER BY COUNT(CauseOfDeath) DESC"
);
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
result
=
rs
.
getString
(
"CauseOfDeath"
);
if
(!
result
.
isEmpty
())
{
String
name
=
this
.
getCodeName
(
result
);
results
.
add
(
"Name: "
+
name
+
", Code: "
+
result
+
", Number of Deaths: "
+
rs
.
getString
(
"COUNT(CauseOfDeath)"
));
count
++;
}
}
rs
.
close
();
}
catch
(
SQLException
e
)
{
throw
new
DBException
(
e
);
}
finally
{
DBUtil
.
closeConnection
(
conn
,
stmt
);
}
return
results
;
}
/**
* 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
;
try
{
conn
=
factory
.
getConnection
();
stmt
=
conn
.
prepareStatement
(
"SELECT Description FROM icdcodes WHERE Code = ?"
);
stmt
.
setString
(
1
,
code
);
ResultSet
rs
=
stmt
.
executeQuery
();
if
(
rs
.
next
())
{
String
result
=
rs
.
getString
(
"Description"
);
rs
.
close
();
return
result
;
}
rs
.
close
();
return
null
;
}
catch
(
SQLException
e
)
{
throw
new
DBException
(
e
);
}
finally
{
DBUtil
.
closeConnection
(
conn
,
stmt
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment