Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHORE] - values always JSON array #28

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class ConceptResultSetUtil {
Expand All @@ -17,7 +19,7 @@ public CategoricalConcept mapCategorical(ResultSet rs) throws SQLException {
return new CategoricalConcept(
rs.getString("concept_path"), rs.getString("name"),
rs.getString("display"), rs.getString("dataset"), rs.getString("description"),
rs.getString("values") == null ? List.of() : List.of(rs.getString("values").split(",")),
rs.getString("values") == null ? List.of() : parseValues(rs.getString("values")),
null,
null
);
Expand All @@ -32,6 +34,19 @@ public ContinuousConcept mapContinuous(ResultSet rs) throws SQLException {
);
}

public List<String> parseValues(String valuesArr) {
try {
ArrayList<String> vals = new ArrayList<>();
JSONArray arr = new JSONArray(valuesArr);
for (int i = 0; i < arr.length(); i++) {
vals.add(arr.getString(i));
}
return vals;
} catch (JSONException ex) {
return List.of();
}
}

public Integer parseMin(String valuesArr) {
try {
JSONArray arr = new JSONArray(valuesArr);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package edu.harvard.dbmi.avillach.dictionary.concept;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

class ConceptResultSetUtilTest {

@Test
void shouldParseValues() {
List<String> actual = new ConceptResultSetUtil().parseValues("[\"Look, I'm valid json\"]");
List<String> expected = List.of("Look, I'm valid json");

Assertions.assertEquals(expected, actual);
}
}