Skip to content

Commit a2ad148

Browse files
Luke SikinaLuke-Sikina
Luke Sikina
authored andcommitted
[BAD] - Temporary hack for BDC. Evil query for Dashboard
1 parent 2687570 commit a2ad148

File tree

7 files changed

+93
-10
lines changed

7 files changed

+93
-10
lines changed

db/schema.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ CREATE TABLE dict.consent (
2424
DATASET_ID INT NOT NULL,
2525
CONSENT_CODE VARCHAR(512) NOT NULL,
2626
DESCRIPTION VARCHAR(512) NOT NULL,
27-
PARTICIPANT_COUNT INT NOT NULL,
28-
VARIABLE_COUNT INT NOT NULL,
29-
SAMPLE_COUNT INT NOT NULL,
27+
PARTICIPANT_COUNT INT NOT NULL DEFAULT 12,
28+
VARIABLE_COUNT INT NOT NULL DEFAULT 99,
29+
SAMPLE_COUNT INT NOT NULL DEFAULT 14,
3030
AUTHZ VARCHAR(512) NOT NULL,
3131
PRIMARY KEY (CONSENT_ID),
3232
UNIQUE (CONSENT_CODE, DATASET_ID)

src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardRepository.java

+48-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import org.springframework.beans.factory.annotation.Autowired;
44
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.dao.DataAccessException;
6+
import org.springframework.jdbc.core.ResultSetExtractor;
57
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
68
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
79
import org.springframework.stereotype.Repository;
810

9-
import java.util.List;
10-
import java.util.Map;
11-
import java.util.Set;
11+
import java.sql.ResultSet;
12+
import java.sql.SQLException;
13+
import java.util.*;
1214
import java.util.function.Predicate;
1315

1416
@Repository
@@ -31,6 +33,49 @@ public DashboardRepository(
3133
this.extractor = extractor;
3234
}
3335

36+
private static final class ListMapExtractor implements ResultSetExtractor<List<Map<String,String>>> {
37+
38+
@Override
39+
public List<Map<String, String>> extractData(ResultSet rs) throws SQLException, DataAccessException {
40+
List<Map<String, String>> rows = new ArrayList<>();
41+
while (rs.next()) {
42+
Map<String, String> row = new HashMap<>();
43+
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
44+
String key = rs.getMetaData().getColumnName(i + 1);
45+
row.put(key, rs.getString(key));
46+
}
47+
rows.add(row);
48+
}
49+
return rows;
50+
}
51+
}
52+
53+
public List<Map<String, String>> getHackyBDCRows() {
54+
String sql = """
55+
SELECT
56+
dataset.abbreviation AS abbreviation,
57+
dataset.full_name AS name,
58+
consent.variable_count AS clinvars,
59+
consent.participant_count AS participants,
60+
consent.sample_count AS samples,
61+
CASE
62+
WHEN consent.consent_code <> NULL THEN concat(study_accession_meta.value, '.', consent.consent_code)
63+
ELSE study_accession_meta.value
64+
END
65+
AS accession,
66+
study_focus_meta.value AS study_focus,
67+
additional_info_meta.value AS additional_info_link
68+
FROM
69+
dataset
70+
LEFT JOIN consent ON consent.dataset_id = dataset.dataset_id
71+
LEFT JOIN dataset_meta AS study_focus_meta ON study_focus_meta.dataset_id = dataset.dataset_id AND study_focus_meta.KEY = 'study_focus'
72+
LEFT JOIN dataset_meta AS study_accession_meta ON study_accession_meta.dataset_id = dataset.dataset_id AND study_accession_meta.KEY = 'study_accession'
73+
LEFT JOIN dataset_meta AS additional_info_meta ON additional_info_meta.dataset_id = dataset.dataset_id AND additional_info_meta.KEY = 'additional_info_link'
74+
ORDER BY name ASC, abbreviation ASC
75+
""";
76+
return template.query(sql, new ListMapExtractor());
77+
}
78+
3479
public List<Map<String, String>> getRows() {
3580
String sql = """
3681
SELECT

src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardService.java

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package edu.harvard.dbmi.avillach.dictionary.dashboard;
22

3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.beans.factory.annotation.Value;
35
import org.springframework.stereotype.Service;
46

57
import java.util.List;
@@ -10,17 +12,42 @@ public class DashboardService {
1012

1113
private final DashboardRepository repository;
1214
private final List<DashboardColumn> columns;
15+
private final boolean bdcHack;
1316

14-
public DashboardService(DashboardRepository repository, List<DashboardColumn> columns) {
17+
@Autowired
18+
public DashboardService(
19+
DashboardRepository repository,
20+
List<DashboardColumn> columns,
21+
@Value("${dashboard.enable.bdc_hack}") boolean bdcHack
22+
) {
1523
this.repository = repository;
1624
this.columns = columns;
25+
this.bdcHack = bdcHack;
1726
}
1827

1928
public Dashboard getDashboard() {
29+
if (bdcHack) {
30+
List<Map<String, String>> rows = repository.getHackyBDCRows();
31+
return new Dashboard(
32+
hackyBDCColumns,
33+
rows
34+
);
35+
}
2036
List<Map<String, String>> rows = repository.getRows();
2137
return new Dashboard(
2238
columns,
2339
rows
2440
);
2541
}
42+
43+
private static final List<DashboardColumn> hackyBDCColumns = List.of(
44+
new DashboardColumn("abbreviation", "Abbreviation"),
45+
new DashboardColumn("name", "Name"),
46+
new DashboardColumn("study_focus", "Study Focus"),
47+
new DashboardColumn("clinvars", "Clinical Variables"),
48+
new DashboardColumn("participants", "Participants"),
49+
new DashboardColumn("samples", "Samples Sequenced"),
50+
new DashboardColumn("accession", "Accession"),
51+
new DashboardColumn("additional_info_link", "Study Link")
52+
);
2653
}

src/main/resources/application.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ server.port=80
88
dashboard.columns={abbreviation:'Abbreviation',name:'Name',clinvars:'Clinical Variables'}
99
dashboard.column-order=abbreviation,name,clinvars
1010
dashboard.nonmeta-columns=abbreviation,name
11-
dashboard.enable.extra_details=true
11+
dashboard.enable.extra_details=true
12+
dashboard.enable.bdc_hack=true

src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardRepositoryTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ void shouldGetDashboardRows() {
5353
);
5454
Assertions.assertEquals(expected, actual);
5555
}
56+
57+
@Test
58+
void shouldDoBDCHack() {
59+
List<Map<String, String>> rows = subject.getHackyBDCRows();
60+
Assertions.assertNotNull(rows);
61+
}
5662
}

src/test/resources/application.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ dashboard.columns={abbreviation:'Abbreviation',melast:'This one goes last',name:
88
dashboard.column-order=abbreviation,name,clinvars
99
dashboard.nonmeta-columns=abbreviation,name
1010

11-
dashboard.enable.extra_details=true
11+
dashboard.enable.extra_details=true
12+
dashboard.enable.bdc_hack=false

src/test/resources/seed.sql

+4-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ CREATE TABLE public.consent (
103103
dataset_id integer NOT NULL,
104104
consent_code character varying(512) NOT NULL,
105105
description character varying(512) NOT NULL,
106-
authz character varying(512) NOT NULL
106+
authz character varying(512) NOT NULL,
107+
PARTICIPANT_COUNT INT NOT NULL DEFAULT 12,
108+
VARIABLE_COUNT INT NOT NULL DEFAULT 99,
109+
SAMPLE_COUNT INT NOT NULL DEFAULT 14
107110
);
108111

109112
--

0 commit comments

Comments
 (0)