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
c24ad373
Commit
c24ad373
authored
4 years ago
by
ahmada4
Browse files
Options
Downloads
Patches
Plain Diff
Delete duplicate CauseOfDeathTrendsReportDAO.java
parent
d27f3445
No related branches found
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
CauseOfDeathTrendsReportDAO.java
+0
-204
0 additions, 204 deletions
CauseOfDeathTrendsReportDAO.java
with
0 additions
and
204 deletions
CauseOfDeathTrendsReportDAO.java
deleted
100644 → 0
+
0
−
204
View file @
d27f3445
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 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"
);
if
(!
patient
.
isEmpty
())
{
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 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
<
Long
>
patients
=
this
.
getPatientsForHCP
(
hcpMID
);
List
<
String
>
causes
=
new
ArrayList
<
String
>();
try
{
conn
=
factory
.
getConnection
();
if
(
gender
.
equalsIgnoreCase
(
"All"
)){
String
query
=
"SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients WHERE MID IN ("
;
for
(
int
i
=
0
;
i
<
patients
.
size
();
i
++)
{
query
+=
patients
.
get
(
i
)
+
","
;
}
query
+=
") AND DateOfDeath IS NOT NULL AND YEAR(?) >= YEAR(DateOfDeath) AND YEAR(?) <= YEAR(DateOfDeath)"
+
"GROUP BY CauseOfDeath ORDER BY COUNT(CauseOfDeath) DESC"
;
stmt
=
conn
.
prepareStatement
(
query
);
stmt
.
setDate
(
1
,
startDate
);
stmt
.
setDate
(
2
,
endDate
);
}
else
{
String
query
=
"SELECT DISTINCT CauseOfDeath, COUNT(CauseOfDeath) FROM patients WHERE MID IN ("
;
for
(
int
i
=
0
;
i
<
patients
.
size
();
i
++)
{
query
+=
patients
.
get
(
i
)
+
","
;
}
query
+=
") AND DateOfDeath IS NOT NULL AND Gender = ? AND YEAR(?) >= YEAR(DateOfDeath) AND YEAR(?) <= YEAR(DateOfDeath)"
+
"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"
);
int
deaths
=
rs
.
getString
(
"COUNT(CauseOfDeath)"
);
if
(!
cause
.
isEmpty
())
{
String
name
=
this
.
getCodeName
(
cause
);
causes
.
add
(
"Name: "
+
name
+
", Code: "
+
cause
+
", Deaths: "
+
deaths
);
count
++;
}
}
rs
.
close
();
}
catch
(
SQLException
e
)
{
throw
new
DBException
(
e
);
}
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 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
>
causes
=
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
cause
=
rs
.
getString
(
"CauseOfDeath"
);
int
deaths
=
rs
.
getString
(
"COUNT(CauseOfDeath)"
);
if
(!
cause
.
isEmpty
())
{
String
name
=
this
.
getCodeName
(
cause
);
causes
.
add
(
"Name: "
+
name
+
", Code: "
+
cause
+
", Deaths: "
+
deaths
);
count
++;
}
}
rs
.
close
();
}
catch
(
SQLException
e
)
{
throw
new
DBException
(
e
);
}
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
();
result
=
rs
.
getString
(
"Description"
);
rs
.
close
();
}
catch
(
SQLException
e
)
{
throw
new
DBException
(
e
);
}
finally
{
DBUtil
.
closeConnection
(
conn
,
stmt
);
}
return
result
;
}
}
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