use of org.snomed.snowstorm.core.data.services.pojo.DescriptionCriteria in project snowstorm by IHTSDO.
the class DescriptionController method findBrowserDescriptions.
@ApiOperation(value = "Search for concept descriptions.", notes = "The Accept-Language header is used to specify the user's preferred language, 'en' is always added as a fallback if not already included in the list. " + "Each language is used as an optional clause for matching and will include the correct character folding behaviour for that language. " + "The Accept-Language header list is also used to chose the best translated FSN and PT values in the response.")
@RequestMapping(value = "browser/{branch}/descriptions", method = RequestMethod.GET)
@JsonView(value = View.Component.class)
public Page<BrowserDescriptionSearchResult> findBrowserDescriptions(@PathVariable String branch, @RequestParam(required = false) String term, @RequestParam(required = false) Boolean active, @RequestParam(required = false) Set<String> module, @ApiParam(value = "Set of two character language codes to match. " + "The English language code 'en' will not be added automatically, in contrast to the Accept-Language header which always includes it. " + "Accept-Language header still controls result FSN and PT language selection.") @RequestParam(required = false) Set<String> language, @ApiParam(value = "Set of description type ids to use include. Defaults to any. " + "Pick descendants of '900000000000446008 | Description type (core metadata concept) |'. " + "Examples: 900000000000003001 (FSN), 900000000000013009 (Synonym), 900000000000550004 (Definition)") @RequestParam(required = false) Set<Long> type, @Deprecated @RequestParam(required = false) String semanticTag, @ApiParam(value = "Set of semantic tags.") @RequestParam(required = false) Set<String> semanticTags, @ApiParam(value = "Set of description language reference sets. The description must be preferred in at least one of these to match.") @RequestParam(required = false) Set<Long> preferredIn, @ApiParam(value = "Set of description language reference sets. The description must be acceptable in at least one of these to match.") @RequestParam(required = false) Set<Long> acceptableIn, @ApiParam(value = "Set of description language reference sets. The description must be preferred OR acceptable in at least one of these to match.") @RequestParam(required = false) Set<Long> preferredOrAcceptableIn, @RequestParam(required = false) Boolean conceptActive, @RequestParam(required = false) String conceptRefset, @RequestParam(defaultValue = "false") boolean groupByConcept, @RequestParam(defaultValue = "STANDARD") DescriptionService.SearchMode searchMode, @RequestParam(defaultValue = "0") int offset, @RequestParam(defaultValue = "50") int limit, @RequestHeader(value = "Accept-Language", defaultValue = Config.DEFAULT_ACCEPT_LANG_HEADER) String acceptLanguageHeader) throws TooCostlyException {
branch = BranchPathUriUtil.decodePath(branch);
PageRequest pageRequest = ControllerHelper.getPageRequest(offset, limit);
List<LanguageDialect> languageDialects = ControllerHelper.parseAcceptLanguageHeaderWithDefaultFallback(acceptLanguageHeader);
PageWithBucketAggregations<Description> page = descriptionService.findDescriptionsWithAggregations(branch, new DescriptionCriteria().term(term).active(active).modules(module).searchLanguageCodes(language).type(type).semanticTag(semanticTag).semanticTags(semanticTags).preferredIn(preferredIn).acceptableIn(acceptableIn).preferredOrAcceptableIn(preferredOrAcceptableIn).conceptActive(conceptActive).conceptRefset(conceptRefset).groupByConcept(groupByConcept).searchMode(searchMode), // Page
pageRequest);
Set<String> conceptIds = page.getContent().stream().map(Description::getConceptId).collect(Collectors.toSet());
Map<String, ConceptMini> conceptMinis = conceptService.findConceptMinis(branch, conceptIds, languageDialects).getResultsMap();
List<BrowserDescriptionSearchResult> results = new ArrayList<>();
page.getContent().forEach(d -> results.add(new BrowserDescriptionSearchResult(d.getTerm(), d.isActive(), d.getLanguageCode(), d.getModuleId(), conceptMinis.get(d.getConceptId()))));
PageWithBucketAggregations<BrowserDescriptionSearchResult> pageWithBucketAggregations = new PageWithBucketAggregations<>(results, page.getPageable(), page.getTotalElements(), page.getBuckets());
addBucketConcepts(branch, languageDialects, pageWithBucketAggregations);
addLanguageNames(pageWithBucketAggregations);
return pageWithBucketAggregations;
}
use of org.snomed.snowstorm.core.data.services.pojo.DescriptionCriteria in project snowstorm by IHTSDO.
the class DescriptionServiceTest method testDescriptionSearchAggregationsSemanticTagFilter.
@Test
void testDescriptionSearchAggregationsSemanticTagFilter() throws ServiceException {
String path = "MAIN";
Concept root = new Concept(SNOMEDCT_ROOT);
Concept food_1 = new Concept("100002").addRelationship(new Relationship(ISA, SNOMEDCT_ROOT)).addFSN("Food (food)");
Concept food_2 = new Concept("100006").addRelationship(new Relationship(ISA, SNOMEDCT_ROOT)).addFSN("Food 2 (food)");
Concept cheesePizza_3 = new Concept("100003").addRelationship(new Relationship(ISA, food_1.getId())).addFSN("Cheese Pizza (pizza)");
Concept reallyCheesyPizza_4 = new Concept("100004").addRelationship(new Relationship(ISA, cheesePizza_3.getId())).addFSN("Really Cheesy Pizza (pizza)");
Concept reallyCheesyPizza_5 = new Concept("100005").addRelationship(new Relationship(ISA, reallyCheesyPizza_4.getId())).addFSN("So Cheesy Pizza (pizza)");
List<Concept> concepts = newArrayList(root, food_1, food_2, cheesePizza_3, reallyCheesyPizza_4, reallyCheesyPizza_5);
setModulesAndLanguage(concepts);
conceptService.batchCreate(concepts, path);
referenceSetMemberService.createMembers(path, Sets.newHashSet(new ReferenceSetMember(Concepts.CORE_MODULE, Concepts.REFSET_MRCM_DOMAIN, "100003"), new ReferenceSetMember(Concepts.CORE_MODULE, Concepts.REFSET_MRCM_DOMAIN, "100004"), new ReferenceSetMember(Concepts.CORE_MODULE, Concepts.REFSET_MRCM_ATTRIBUTE_RANGE, "100005")));
DescriptionCriteria descriptionCriteria = new DescriptionCriteria().active(true);
Map<String, Map<String, Long>> allAggregations = descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria, PageRequest.of(0, 10)).getBuckets();
assertEquals("{900000000000207008=5}", getAggregationString("module", allAggregations));
assertEquals("{en=5}", getAggregationString("language", allAggregations));
assertEquals("{pizza=3, food=2}", getAggregationString("semanticTags", allAggregations));
assertEquals("{723592007=1, 723589008=2}", getAggregationString("membership", allAggregations));
descriptionCriteria.semanticTag("pizza");
Map<String, Map<String, Long>> pizzaFilteredAggregations = descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria, PageRequest.of(0, 10)).getBuckets();
assertEquals("{900000000000207008=3}", getAggregationString("module", pizzaFilteredAggregations));
assertEquals("{en=3}", getAggregationString("language", pizzaFilteredAggregations));
assertEquals("{pizza=3}", getAggregationString("semanticTags", pizzaFilteredAggregations));
assertEquals("{723592007=1, 723589008=2}", getAggregationString("membership", pizzaFilteredAggregations));
descriptionCriteria.semanticTag(null);
Set<String> semanticTags = new HashSet<>();
semanticTags.add("food");
semanticTags.add("pizza");
descriptionCriteria.semanticTags(semanticTags);
Map<String, Map<String, Long>> multipleSemanticTagsFilteredAggregations = descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria, PageRequest.of(0, 10)).getBuckets();
assertEquals("{900000000000207008=5}", getAggregationString("module", multipleSemanticTagsFilteredAggregations));
assertEquals("{en=5}", getAggregationString("language", multipleSemanticTagsFilteredAggregations));
assertEquals("{pizza=3, food=2}", getAggregationString("semanticTags", multipleSemanticTagsFilteredAggregations));
assertEquals("{723592007=1, 723589008=2}", getAggregationString("membership", multipleSemanticTagsFilteredAggregations));
}
use of org.snomed.snowstorm.core.data.services.pojo.DescriptionCriteria in project snowstorm by IHTSDO.
the class DescriptionServiceTest method testDescriptionSearchMatchingWord.
@Test
void testDescriptionSearchMatchingWord() throws ServiceException {
String path = "MAIN";
Concept root = new Concept(SNOMEDCT_ROOT);
Concept concept_1 = new Concept("100002").addRelationship(new Relationship(ISA, SNOMEDCT_ROOT)).addFSN("Place (environment)");
Concept concept_2 = new Concept("100003").addRelationship(new Relationship(ISA, SNOMEDCT_ROOT)).addFSN("Placental structure (body structure)").addDescription(new Description("Placenta"));
Concept concept_3 = new Concept("100004").addRelationship(new Relationship(ISA, SNOMEDCT_ROOT)).addFSN("Place of accident (attribute)").addDescription(new Description("The origin place of accident"));
Concept concept_4 = new Concept("100005").addRelationship(new Relationship(ISA, SNOMEDCT_ROOT)).addFSN("Place of origin (observable entity)");
List<Concept> concepts = newArrayList(root, concept_1, concept_2, concept_3, concept_4);
conceptService.batchCreate(concepts, path);
DescriptionCriteria descriptionCriteria = new DescriptionCriteria().searchMode(WHOLE_WORD).groupByConcept(false);
assertEquals(4, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria.term("place"), PageRequest.of(0, 10)).getTotalElements());
assertEquals(4, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria.term("Place"), PageRequest.of(0, 10)).getTotalElements());
assertEquals(1, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria.term("Placenta"), PageRequest.of(0, 10)).getTotalElements());
assertEquals(2, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria.term("place origin"), PageRequest.of(0, 10)).getTotalElements());
assertEquals(2, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria.term("origin place"), PageRequest.of(0, 10)).getTotalElements());
}
use of org.snomed.snowstorm.core.data.services.pojo.DescriptionCriteria in project snowstorm by IHTSDO.
the class DescriptionServiceTest method testDescriptionSearchWithRegex.
@Test
void testDescriptionSearchWithRegex() throws ServiceException {
String path = "MAIN";
Concept root = new Concept(SNOMEDCT_ROOT);
Concept pizza_2 = new Concept("100002").addRelationship(new Relationship(ISA, SNOMEDCT_ROOT)).addFSN("Food (food)");
Concept cheesePizza_3 = new Concept("100003").addRelationship(new Relationship(ISA, pizza_2.getId())).addFSN("Cheese Pizza (pizza)").addDescription(new Description("Cheese"));
Concept reallyCheesyPizza_4 = new Concept("100004").addRelationship(new Relationship(ISA, cheesePizza_3.getId())).addFSN("Really Cheesy Pizza (pizza)");
Concept reallyCheesyPizza_5 = new Concept("100005").addRelationship(new Relationship(ISA, reallyCheesyPizza_4.getId())).addFSN("So Cheesy Pizza (pizza)");
List<Concept> concepts = newArrayList(root, pizza_2, cheesePizza_3, reallyCheesyPizza_4, reallyCheesyPizza_5);
conceptService.batchCreate(concepts, path);
DescriptionCriteria descriptionCriteria = new DescriptionCriteria().searchMode(REGEX).groupByConcept(false);
assertEquals(2, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria.term("Cheese.*"), PageRequest.of(0, 10)).getTotalElements());
assertEquals(2, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria.term("Che{2}se.*"), PageRequest.of(0, 10)).getTotalElements());
assertEquals(1, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria.term("^Cheese$"), PageRequest.of(0, 10)).getTotalElements());
assertEquals(2, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria.term("Chees.*"), PageRequest.of(0, 10)).getTotalElements());
assertEquals(1, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria.term("Chees.*piz.*"), PageRequest.of(0, 10)).getTotalElements());
descriptionCriteria.groupByConcept(true);
assertEquals(1, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria.term("Chees.*"), PageRequest.of(0, 10)).getTotalElements());
}
use of org.snomed.snowstorm.core.data.services.pojo.DescriptionCriteria in project snowstorm by IHTSDO.
the class DescriptionServiceTest method testDescriptionSearchAggregationsActiveConcept.
@Test
void testDescriptionSearchAggregationsActiveConcept() throws ServiceException {
String path = "MAIN";
Concept root = new Concept(SNOMEDCT_ROOT);
Concept pizza_2 = new Concept("100002").addRelationship(new Relationship(ISA, SNOMEDCT_ROOT)).addFSN("Food (food)");
Concept cheesePizza_3 = new Concept("100003").addRelationship(new Relationship(ISA, pizza_2.getId())).addFSN("Cheese Pizza (pizza)");
Concept reallyCheesyPizza_4 = new Concept("100004").addRelationship(new Relationship(ISA, cheesePizza_3.getId())).addFSN("Really Cheesy Pizza (pizza)");
Concept reallyCheesyPizza_5 = new Concept("100005").addRelationship(new Relationship(ISA, reallyCheesyPizza_4.getId())).addFSN("So Cheesy Pizza (pizza)");
List<Concept> concepts = newArrayList(root, pizza_2, cheesePizza_3, reallyCheesyPizza_4, reallyCheesyPizza_5);
setModulesAndLanguage(concepts);
conceptService.batchCreate(concepts, path);
// Make one pizza concept inactive
reallyCheesyPizza_5.setActive(false);
conceptService.update(reallyCheesyPizza_5, path);
Concept concept = conceptService.find(reallyCheesyPizza_5.getId(), path);
assertFalse(concept.isActive());
DescriptionCriteria descriptionCriteria = new DescriptionCriteria().active(true).term("pizza");
descriptionCriteria.conceptActive(null);
assertEquals("Should find all three pizza concepts", 3, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria, PageRequest.of(0, 10)).getTotalElements());
descriptionCriteria.conceptActive(true);
assertEquals("Should find the two active pizza concepts", 2, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria, PageRequest.of(0, 10)).getTotalElements());
descriptionCriteria.conceptActive(false);
assertEquals("Should find the one inactive pizza concept", 1, descriptionService.findDescriptionsWithAggregations(path, descriptionCriteria, PageRequest.of(0, 10)).getTotalElements());
}
Aggregations