Skip to content

Commit 5e67ca7

Browse files
chen-regenanthonysena
authored andcommitted
Cohort reporting additions (#230)
Cohort reporting additions #223
1 parent a064b5b commit 5e67ca7

File tree

7 files changed

+1113
-2
lines changed

7 files changed

+1113
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.ohdsi.webapi.cohortresults;
2+
3+
4+
/**
5+
*
6+
*/
7+
public class DataCompletenessAttr {
8+
private String covariance;
9+
private float genderP;
10+
private float raceP;
11+
private float ethP;
12+
13+
/**
14+
* @return the covariance
15+
*/
16+
public String getCovariance() {
17+
return covariance;
18+
}
19+
20+
/**
21+
* @param covariance the covariance to set
22+
*/
23+
public void setCovariance(String covariance) {
24+
this.covariance = covariance;
25+
}
26+
27+
/**
28+
* @return the genderP
29+
*/
30+
public float getGenderP() {
31+
return genderP;
32+
}
33+
34+
/**
35+
* @param genderP the genderP to set
36+
*/
37+
public void setGenderP(float genderP) {
38+
this.genderP = genderP;
39+
}
40+
41+
/**
42+
* @return the raceP
43+
*/
44+
public float getRaceP() {
45+
return raceP;
46+
}
47+
48+
/**
49+
* @param raceP the raceP to set
50+
*/
51+
public void setRaceP(float raceP) {
52+
this.raceP = raceP;
53+
}
54+
55+
/**
56+
* @return the ethP
57+
*/
58+
public float getEthP() {
59+
return ethP;
60+
}
61+
62+
/**
63+
* @param ethP the ethP to set
64+
*/
65+
public void setEthP(float ethP) {
66+
this.ethP = ethP;
67+
}
68+
69+
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.ohdsi.webapi.cohortresults;
2+
3+
/**
4+
*
5+
*/
6+
public class EntropyAttr {
7+
8+
private String date;
9+
10+
private float entropy;
11+
12+
private String insitution;
13+
14+
/**
15+
* @return the date
16+
*/
17+
public String getDate() {
18+
return date;
19+
}
20+
21+
/**
22+
* @param date the date to set
23+
*/
24+
public void setDate(String date) {
25+
this.date = date;
26+
}
27+
28+
/**
29+
* @return the entropy
30+
*/
31+
public float getEntropy() {
32+
return entropy;
33+
}
34+
35+
/**
36+
* @param entropy the entropy to set
37+
*/
38+
public void setEntropy(float entropy) {
39+
this.entropy = entropy;
40+
}
41+
42+
/**
43+
* @return the insitution
44+
*/
45+
public String getInsitution() {
46+
return insitution;
47+
}
48+
49+
/**
50+
* @param insitution the insitution to set
51+
*/
52+
public void setInsitution(String insitution) {
53+
this.insitution = insitution;
54+
}
55+
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.ohdsi.webapi.cohortresults.mapper;
2+
3+
import java.sql.ResultSet;
4+
import java.sql.SQLException;
5+
6+
import org.ohdsi.webapi.model.results.AnalysisResults;
7+
import org.springframework.jdbc.core.RowMapper;
8+
9+
10+
/**
11+
*
12+
*/
13+
public class AnalysisResultsMapper implements RowMapper<AnalysisResults> {
14+
15+
/**
16+
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
17+
*/
18+
@Override
19+
public AnalysisResults mapRow(ResultSet rs, int rowNum) throws SQLException {
20+
AnalysisResults ar = new AnalysisResults();
21+
ar.setAnalysisId(rs.getInt("ANALYSIS_ID"));
22+
ar.setCohortDefinitionId(rs.getInt("COHORT_DEFINITION_ID"));
23+
ar.setStratum1(rs.getString("STRATUM_1"));
24+
ar.setStratum2(rs.getString("STRATUM_2"));
25+
ar.setStratum3(rs.getString("STRATUM_3"));
26+
ar.setStratum4(rs.getString("STRATUM_4"));
27+
ar.setStratum5(rs.getString("STRATUM_5"));
28+
ar.setCountValue(rs.getInt("count_value"));
29+
30+
return ar;
31+
}
32+
33+
}

src/main/java/org/ohdsi/webapi/service/CohortResultsService.java

+128
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.sql.SQLException;
55
import java.util.ArrayList;
66
import java.util.Collection;
7+
import java.util.HashMap;
78
import java.util.HashSet;
89
import java.util.List;
910
import java.util.Map;
@@ -44,12 +45,16 @@
4445
import org.ohdsi.webapi.cohortresults.CohortSpecificSummary;
4546
import org.ohdsi.webapi.cohortresults.CohortSpecificTreemap;
4647
import org.ohdsi.webapi.cohortresults.CohortVisitsDrilldown;
48+
import org.ohdsi.webapi.cohortresults.DataCompletenessAttr;
49+
import org.ohdsi.webapi.cohortresults.EntropyAttr;
4750
import org.ohdsi.webapi.cohortresults.HierarchicalConceptRecord;
4851
import org.ohdsi.webapi.cohortresults.ScatterplotRecord;
4952
import org.ohdsi.webapi.cohortresults.VisualizationData;
5053
import org.ohdsi.webapi.cohortresults.VisualizationDataRepository;
54+
import org.ohdsi.webapi.cohortresults.mapper.AnalysisResultsMapper;
5155
import org.ohdsi.webapi.helper.ResourceHelper;
5256
import org.ohdsi.webapi.model.results.Analysis;
57+
import org.ohdsi.webapi.model.results.AnalysisResults;
5358
import org.ohdsi.webapi.source.Source;
5459
import org.ohdsi.webapi.source.SourceDaimon;
5560
import org.ohdsi.webapi.util.SessionUtils;
@@ -1595,7 +1600,130 @@ public List<CohortAttribute> getHeraclesHeel(@PathParam("id") final int id,
15951600

15961601
return attrs;
15971602
}
1603+
1604+
public List<AnalysisResults> getCohortAnalysesForDataCompleteness(@PathParam("id") final int id,
1605+
@PathParam("sourceKey") String sourceKey) {
1606+
1607+
String sql = null;
1608+
sql = ResourceHelper.GetResourceAsString("/resources/cohortresults/sql/datacompleteness/getCohortDataCompleteness.sql");
1609+
1610+
Source source = getSourceRepository().findBySourceKey(sourceKey);
1611+
String resultsTableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.Results);
1612+
1613+
sql = SqlRender.renderSql(sql, new String[]{"tableQualifier", "cohortDefinitionId"},
1614+
new String[]{resultsTableQualifier, String.valueOf(id)});
1615+
sql = SqlTranslate.translateSql(sql, getSourceDialect(), source.getSourceDialect());
1616+
1617+
1618+
AnalysisResultsMapper arm = new AnalysisResultsMapper();
1619+
1620+
return getSourceJdbcTemplate(source).query(sql, arm);
1621+
}
15981622

1623+
@GET
1624+
@Path("{sourceKey}/{id}/datacompleteness")
1625+
@Produces(MediaType.APPLICATION_JSON)
1626+
public List<DataCompletenessAttr> getDataCompleteness(@PathParam("id") final int id,
1627+
@PathParam("sourceKey") String sourceKey) {
1628+
List<AnalysisResults> arl = this.getCohortAnalysesForDataCompleteness(id, sourceKey);
1629+
1630+
List<DataCompletenessAttr> dcal = new ArrayList<DataCompletenessAttr>();
1631+
1632+
Map<Integer, AnalysisResults> resultMap = new HashMap<Integer, AnalysisResults>();
1633+
1634+
for(AnalysisResults ar : arl){
1635+
resultMap.put(ar.getAnalysisId(), ar);
1636+
}
1637+
1638+
DataCompletenessAttr aca = new DataCompletenessAttr();
1639+
aca.setCovariance("0~10");
1640+
aca.setGenderP(Float.parseFloat(resultMap.get(2001).getStratum1()));
1641+
aca.setRaceP(Float.parseFloat(resultMap.get(2011).getStratum1()));
1642+
aca.setEthP(Float.parseFloat(resultMap.get(2021).getStratum1()));
1643+
dcal.add(aca);
1644+
1645+
aca = new DataCompletenessAttr();
1646+
aca.setCovariance("10~20");
1647+
aca.setGenderP(Float.parseFloat(resultMap.get(2002).getStratum1()));
1648+
aca.setRaceP(Float.parseFloat(resultMap.get(2012).getStratum1()));
1649+
aca.setEthP(Float.parseFloat(resultMap.get(2022).getStratum1()));
1650+
dcal.add(aca);
1651+
1652+
aca = new DataCompletenessAttr();
1653+
aca.setCovariance("20~30");
1654+
aca.setGenderP(Float.parseFloat(resultMap.get(2003).getStratum1()));
1655+
aca.setRaceP(Float.parseFloat(resultMap.get(2013).getStratum1()));
1656+
aca.setEthP(Float.parseFloat(resultMap.get(2023).getStratum1()));
1657+
dcal.add(aca);
1658+
1659+
aca = new DataCompletenessAttr();
1660+
aca.setCovariance("30~40");
1661+
aca.setGenderP(Float.parseFloat(resultMap.get(2004).getStratum1()));
1662+
aca.setRaceP(Float.parseFloat(resultMap.get(2014).getStratum1()));
1663+
aca.setEthP(Float.parseFloat(resultMap.get(2024).getStratum1()));
1664+
dcal.add(aca);
1665+
1666+
aca = new DataCompletenessAttr();
1667+
aca.setCovariance("40~50");
1668+
aca.setGenderP(Float.parseFloat(resultMap.get(2005).getStratum1()));
1669+
aca.setRaceP(Float.parseFloat(resultMap.get(2015).getStratum1()));
1670+
aca.setEthP(Float.parseFloat(resultMap.get(2025).getStratum1()));
1671+
dcal.add(aca);
1672+
1673+
aca = new DataCompletenessAttr();
1674+
aca.setCovariance("50~60");
1675+
aca.setGenderP(Float.parseFloat(resultMap.get(2006).getStratum1()));
1676+
aca.setRaceP(Float.parseFloat(resultMap.get(2016).getStratum1()));
1677+
aca.setEthP(Float.parseFloat(resultMap.get(2026).getStratum1()));
1678+
dcal.add(aca);
1679+
1680+
aca = new DataCompletenessAttr();
1681+
aca.setCovariance("60+");
1682+
aca.setGenderP(Float.parseFloat(resultMap.get(2007).getStratum1()));
1683+
aca.setRaceP(Float.parseFloat(resultMap.get(2017).getStratum1()));
1684+
aca.setEthP(Float.parseFloat(resultMap.get(2027).getStratum1()));
1685+
dcal.add(aca);
1686+
1687+
return dcal;
1688+
}
1689+
1690+
public List<AnalysisResults> getCohortAnalysesEntropy(final int id, String sourceKey) {
1691+
1692+
String sql = null;
1693+
sql = ResourceHelper
1694+
.GetResourceAsString("/resources/cohortresults/sql/entropy/getEntropy.sql");
1695+
1696+
Source source = getSourceRepository().findBySourceKey(sourceKey);
1697+
String resultsTableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.Results);
1698+
1699+
sql = SqlRender.renderSql(sql, new String[] { "tableQualifier", "cohortDefinitionId" },
1700+
new String[] { resultsTableQualifier, String.valueOf(id) });
1701+
sql = SqlTranslate.translateSql(sql, getSourceDialect(), source.getSourceDialect());
1702+
1703+
AnalysisResultsMapper arm = new AnalysisResultsMapper();
1704+
1705+
return getSourceJdbcTemplate(source).query(sql, arm);
1706+
}
1707+
1708+
@GET
1709+
@Path("{sourceKey}/{id}/entropy")
1710+
@Produces(MediaType.APPLICATION_JSON)
1711+
public List<EntropyAttr> getEntropy(@PathParam("id") final int id,
1712+
@PathParam("sourceKey") String sourceKey) {
1713+
List<AnalysisResults> arl = this.getCohortAnalysesEntropy(id, sourceKey);
1714+
1715+
List<EntropyAttr> el = new ArrayList<EntropyAttr>();
1716+
1717+
for(AnalysisResults ar : arl){
1718+
EntropyAttr ea = new EntropyAttr();
1719+
ea.setDate(ar.getStratum1());
1720+
ea.setEntropy(Float.parseFloat(ar.getStratum2()));
1721+
el.add(ea);
1722+
}
1723+
1724+
return el;
1725+
}
1726+
15991727
private String JoinArray(final String[] array) {
16001728
String result = "";
16011729

0 commit comments

Comments
 (0)