Skip to content

Commit

Permalink
Concept Set Source Code Evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena committed Apr 20, 2016
1 parent c3c007c commit aca171e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/ohdsi/webapi/service/ConceptSetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public ConceptSetExpression getConceptSetExpression(@PathParam("id") final int i
expression.items = new ConceptSetExpression.ConceptSetItem[map.size()];

// lookup the concepts we need information for
String[] identifiers = new String[map.size()];
long[] identifiers = new long[map.size()];
int identifierIndex = 0;
for (Long identifier : map.keySet()) {
identifiers[identifierIndex] = identifier.toString();
identifiers[identifierIndex] = identifier;
identifierIndex++;
}

Expand Down
30 changes: 5 additions & 25 deletions src/main/java/org/ohdsi/webapi/service/VocabularyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,17 @@ public Concept mapRow(final ResultSet resultSet, final int arg1) throws SQLExcep
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Collection<Concept> executeIdentifierLookup(@PathParam("sourceKey") String sourceKey, String[] identifiers) {
public Collection<Concept> executeIdentifierLookup(@PathParam("sourceKey") String sourceKey, long[] identifiers) {
if (identifiers.length == 0) {
return new ArrayList<>();
}

int[] intIdentifiers =new int[identifiers.length];
int i=0;
for(String identifier:identifiers){
try {
intIdentifiers[i]=Integer.parseInt(identifier);
i++;
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Not a number: " + identifier + " at index " + i, e);
}
}

Source source = getSourceRepository().findBySourceKey(sourceKey);
String tableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.Vocabulary);

String sql_statement = ResourceHelper.GetResourceAsString("/resources/vocabulary/sql/lookupIdentifiers.sql");
sql_statement = SqlRender.renderSql(sql_statement, new String[]{"identifiers", "CDM_schema"}, new String[]{
JoinArray(intIdentifiers), tableQualifier});
JoinArray(identifiers), tableQualifier});
sql_statement = SqlTranslate.translateSql(sql_statement, "sql server", source.getSourceDialect());

return getSourceJdbcTemplate(source).query(sql_statement, this.rowMapper);
Expand Down Expand Up @@ -146,7 +135,7 @@ public Collection<Concept> executeSourcecodeLookup(@PathParam("sourceKey") Strin
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Collection<Concept> executeMappedLookup(@PathParam("sourceKey") String sourceKey, String[] identifiers) {
public Collection<Concept> executeMappedLookup(@PathParam("sourceKey") String sourceKey, long[] identifiers) {
if (identifiers.length == 0) {
return new ArrayList<>();
}
Expand Down Expand Up @@ -511,16 +500,7 @@ public Collection<Concept> getRelatedConcepts(@PathParam("sourceKey") String sou

ArrayList<String> filterList = new ArrayList<String>();

int[] conceptIds =new int[search.conceptId.length];
int i=0;
for (String conceptId : search.conceptId) {
try {
conceptIds[i] = Integer.parseInt(conceptId);
i++;
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Not a number: " + conceptId + " at index " + i, e);
}
}
long[] conceptIds = search.conceptId;

if (search.vocabularyId != null && search.vocabularyId.length > 0) {
filterList.add("VOCABULARY_ID IN (" + JoinArray(search.vocabularyId) + ")");
Expand Down Expand Up @@ -565,7 +545,7 @@ public Void mapRow(ResultSet resultSet, int arg1) throws SQLException {
return concepts.values();
}

private String JoinArray(final int[] array) {
private String JoinArray(final long[] array) {
String result = "";

for (int i = 0; i < array.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public RelatedConceptSearch() {
public String[] conceptClassId;

@JsonProperty("CONCEPT_ID")
public String[] conceptId;
public long[] conceptId;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
-- get all of the concepts that were part of the list of concepts provided

Select concept_id, concept_name, ISNULL(standard_concept, 'N') standard_concept, ISNULL(invalid_reason, 'V') INVALID_REASON,
CONCEPT_CODE, CONCEPT_CLASS_ID, DOMAIN_ID, VOCABULARY_ID
from concept
where concept_id in (@identifiers)

UNION

--get all source codes that map to the list of concepts provided

select CONCEPT_ID, CONCEPT_NAME, ISNULL(STANDARD_CONCEPT,'N') STANDARD_CONCEPT, ISNULL(c.INVALID_REASON,'V') INVALID_REASON, CONCEPT_CODE, CONCEPT_CLASS_ID, DOMAIN_ID, VOCABULARY_ID
from @CDM_schema.concept_relationship cr
join @CDM_schema.concept c on c.concept_id = cr.concept_id_1
where cr.concept_id_2 in (@identifiers)
and cr.INVALID_REASON is null
and relationship_id in ('Maps to')
and standard_concept IS NULL

UNION

--get anything that may be stashed in the source-to-concept-map table

select 0 as CONCEPT_ID, SOURCE_CODE_DESCRIPTION as CONCEPT_NAME, 'N' as STANDARD_CONCEPT, ISNULL(INVALID_REASON,'V') INVALID_REASON,
SOURCE_CODE as CONCEPT_CODE, NULL as CONCEPT_CLASS_ID, NULL as DOMAIN_ID, SOURCE_VOCABULARY_ID as VOCABULARY_ID
from @CDM_schema.SOURCE_TO_CONCEPT_MAP
where TARGET_CONCEPT_ID in (@identifiers)
and INVALID_REASON is null
order by domain_id, vocabulary_id

0 comments on commit aca171e

Please sign in to comment.