Skip to content

Commit

Permalink
Delete concept sets per OHDSI/Atlas#87
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena committed Sep 16, 2016
1 parent 9d833a0 commit 7857c9c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.ohdsi.webapi.evidence;

import java.util.Collection;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
Expand All @@ -17,4 +18,8 @@
public interface NegativeControlRepository extends CrudRepository<NegativeControlRecord, Integer> {
@Query("SELECT n FROM NegativeControlRecord n WHERE n.sourceId = :sourceId AND n.conceptSetId = :conceptSetId")
Collection<NegativeControlRecord> findAllBySourceIdAndConceptId(@Param("sourceId") int sourceId, @Param("conceptSetId") int conceptSetId);

@Modifying
@Query("DELETE FROM NegativeControlRecord n WHERE n.conceptSetId = :conceptSetId")
void deleteAllByConceptSetId(@Param("conceptSetId") int conceptSetId);
}
59 changes: 56 additions & 3 deletions src/main/java/org/ohdsi/webapi/service/ConceptSetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
import org.ohdsi.webapi.conceptset.ConceptSetGenerationInfoRepository;
import org.ohdsi.webapi.conceptset.ConceptSetItem;
import org.ohdsi.webapi.conceptset.ExportUtil;
import org.ohdsi.webapi.evidence.NegativeControlRepository;
import org.ohdsi.webapi.source.SourceInfo;
import org.ohdsi.webapi.vocabulary.Concept;
import org.ohdsi.webapi.vocabulary.ConceptSetExpression;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Component;

/**
Expand All @@ -62,9 +64,11 @@
@Component
public class ConceptSetService extends AbstractDaoService {

@Autowired
private ConceptSetGenerationInfoRepository conceptSetGenerationInfoRepository;

@Autowired
private ConceptSetGenerationInfoRepository conceptSetGenerationInfoRepository;

@Autowired
private NegativeControlRepository negativeControlRepository;

@Autowired
private VocabularyService vocabService;
Expand Down Expand Up @@ -243,4 +247,53 @@ private ConceptSetExport getConceptSetForExport(int conceptSetId, SourceInfo voc
public Collection<ConceptSetGenerationInfo> getConceptSetGenerationInfo(@PathParam("id") final int id) {
return this.conceptSetGenerationInfoRepository.findAllByConceptSetId(id);
}

@POST
@Transactional(rollbackOn = Exception.class, dontRollbackOn = EmptyResultDataAccessException.class)
@Path("{id}/delete")
public void deleteConceptSet(@PathParam("id") final int id) throws Exception {
// Remove the concept set
try {
getConceptSetRepository().delete(id);
} catch (EmptyResultDataAccessException e) {
// Ignore - there may be no data
log.debug(e.getMessage());
}
catch (Exception e) {
throw e;
}

// Remove the concept set items
try {
getConceptSetItemRepository().deleteByConceptSetId(id);
} catch (EmptyResultDataAccessException e) {
// Ignore - there may be no data
log.debug(e.getMessage());
}
catch (Exception e) {
throw e;
}

// Remove any generation info
try {
this.conceptSetGenerationInfoRepository.deleteByConceptSetId(id);
} catch (EmptyResultDataAccessException e) {
// Ignore - there may be no data
log.debug(e.getMessage());
}
catch (Exception e) {
throw e;
}

// Remove any evidence
try {
this.negativeControlRepository.deleteAllByConceptSetId(id);
} catch (EmptyResultDataAccessException e) {
// Ignore - there may be no data
log.debug(e.getMessage());
}
catch (Exception e) {
throw e;
}
}
}
9 changes: 9 additions & 0 deletions src/main/java/org/ohdsi/webapi/service/VocabularyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,16 @@ public ConceptSetOptimizationResult optimizeConceptSet(@PathParam("sourceKey") S
Hashtable<String, ConceptSetExpression.ConceptSetItem> allConceptSetItems = new Hashtable<String, ConceptSetExpression.ConceptSetItem>();
ArrayList<String> includedConcepts = new ArrayList<String>();
ArrayList<String> descendantConcepts = new ArrayList<String>();
ArrayList<String> allOtherConcepts = new ArrayList<String>();
for(ConceptSetExpression.ConceptSetItem item : conceptSetExpression.items) {
allConceptSetItems.put(item.concept.conceptId.toString(), item);
if (!item.isExcluded) {
includedConcepts.add(item.concept.conceptId.toString());
if (item.includeDescendants) {
descendantConcepts.add(item.concept.conceptId.toString());
}
} else {
allOtherConcepts.add(item.concept.conceptId.toString());
}
}

Expand Down Expand Up @@ -696,6 +699,12 @@ public ConceptSetOptimizationResult optimizeConceptSet(@PathParam("sourceKey") S
removedExpressionItems.add(csi);
}
}
// Re-add back the other concepts that are not considered
// as part of the optimizatin process
for(String conceptId : allOtherConcepts) {
ConceptSetExpression.ConceptSetItem csi = allConceptSetItems.get(conceptId);
optimzedExpressionItems.add(csi);
}
returnVal.optimizedConceptSet.items = optimzedExpressionItems.toArray(new ConceptSetExpression.ConceptSetItem[optimzedExpressionItems.size()]);
returnVal.removedConceptSet.items = removedExpressionItems.toArray(new ConceptSetExpression.ConceptSetItem[removedExpressionItems.size()]);

Expand Down

0 comments on commit 7857c9c

Please sign in to comment.