diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardColumn.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardColumn.java index f481eb7..f8a59fb 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardColumn.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardColumn.java @@ -1,4 +1,4 @@ package edu.harvard.dbmi.avillach.dictionary.dashboard; -public record DashboardColumn(String label, String dataElement) { +public record DashboardColumn(String dataElement, String label) { } diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardRepository.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardRepository.java index a302d85..532aec2 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardRepository.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardRepository.java @@ -45,7 +45,7 @@ dataset_meta.KEY IN (:keys) ORDER BY name ASC, abbreviation ASC """; List keys = columns.stream() - .map(DashboardColumn::label) + .map(DashboardColumn::dataElement) .filter(Predicate.not(nonMetaColumns::contains)) .toList(); MapSqlParameterSource params = new MapSqlParameterSource().addValue("keys", keys); diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardRowResultSetExtractor.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardRowResultSetExtractor.java index e2f2654..83b5245 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardRowResultSetExtractor.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardRowResultSetExtractor.java @@ -28,23 +28,38 @@ public DashboardRowResultSetExtractor(List columns) { @Override public List> extractData(ResultSet rs) throws SQLException, DataAccessException { - String currentRow = ""; + String currentName = ""; + String currentAbbreviation = ""; + boolean beforeStart = true; Map row = new HashMap<>(template); List> rows = new ArrayList<>(); while (rs.next()) { String abbreviation = rs.getString("abbreviation"); String name = rs.getString("name"); - if (!currentRow.equals(name + abbreviation)) { - currentRow = name + abbreviation; - if (!row.isEmpty()) { - row.put("abbreviation", abbreviation); - row.put("name", name); - rows.add(row); - row = new HashMap<>(template); - } + if (beforeStart) { + currentName = name; + currentAbbreviation = abbreviation; + beforeStart = false; + } + // start of new row + if (!currentAbbreviation.equals(abbreviation) || !currentName.equals(name)) { + // finish up the old row by adding non-meta fields + row.put("abbreviation", currentAbbreviation); + row.put("name", currentName); + rows.add(row); + // start new row + currentName = name; + currentAbbreviation = abbreviation; + row = new HashMap<>(template); } row.put(rs.getString("key"), rs.getString("value")); } + // add the last row to the response only if there has been at least one set in the result set + if (!beforeStart) { + row.put("abbreviation", currentAbbreviation); + row.put("name", currentName); + rows.add(row); + } return rows; } }