diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetUtil.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetUtil.java index bd543b4..6944cab 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetUtil.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetUtil.java @@ -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 { @@ -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 ); @@ -32,6 +34,19 @@ public ContinuousConcept mapContinuous(ResultSet rs) throws SQLException { ); } + public List parseValues(String valuesArr) { + try { + ArrayList 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); diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetUtilTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetUtilTest.java new file mode 100644 index 0000000..8df3c5c --- /dev/null +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetUtilTest.java @@ -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 actual = new ConceptResultSetUtil().parseValues("[\"Look, I'm valid json\"]"); + List expected = List.of("Look, I'm valid json"); + + Assertions.assertEquals(expected, actual); + } +} \ No newline at end of file