use of org.snomed.snowstorm.core.data.domain.Description 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.domain.Description in project snowstorm by IHTSDO.
the class DupeLangRefsetFixService method fixConcepts.
public void fixConcepts(String path, Set<Long> conceptIds) {
try (final Commit commit = branchService.openCommit(path)) {
final BranchCriteria branchCriteria = versionControlHelper.getBranchCriteria(path);
final Collection<Concept> concepts = conceptService.find(branchCriteria, path, conceptIds, Config.DEFAULT_LANGUAGE_DIALECTS);
List<ReferenceSetMember> membersToSave = new ArrayList<>();
for (Concept concept : concepts) {
for (Description description : concept.getDescriptions()) {
for (Map.Entry<String, Set<ReferenceSetMember>> langRefsetEntry : description.getLangRefsetMembersMap().entrySet()) {
if (langRefsetEntry.getValue().size() > 1) {
List<ReferenceSetMember> langRefsets = new ArrayList<>(langRefsetEntry.getValue());
langRefsets.sort(Comparator.comparing(ReferenceSetMember::isReleased).thenComparing(ReferenceSetMember::isActive).reversed());
for (int i = 0; i < langRefsets.size(); i++) {
boolean active = i == 0;
final ReferenceSetMember member = langRefsets.get(i);
if (member.isActive() != active) {
member.setActive(active);
member.markChanged();
membersToSave.add(member);
}
}
}
}
}
}
if (!membersToSave.isEmpty()) {
logger.info("Saving {} corrected language refset members.", membersToSave.size());
referenceSetMemberService.doSaveBatchMembers(membersToSave, commit);
commit.markSuccessful();
} else {
logger.info("No language refset members found to correct.");
}
}
}
use of org.snomed.snowstorm.core.data.domain.Description in project snowstorm by IHTSDO.
the class HapiValueSetMapper method addExpansion.
private void addExpansion(ValueSet vs, List<ConceptMini> concepts, Map<String, Concept> conceptDetails, List<LanguageDialect> designations, Boolean includeDesignations) {
// Will autocreate
ValueSetExpansionComponent expansion = vs.getExpansion();
for (ConceptMini concept : concepts) {
ValueSetExpansionContainsComponent component = expansion.addContains().setCode(concept.getConceptId()).setSystem(SNOMED_URI);
if (conceptDetails != null && conceptDetails.containsKey(concept.getConceptId())) {
Concept c = conceptDetails.get(concept.getConceptId());
for (Description d : c.getActiveDescriptions()) {
if (includeDesignations && d.hasAcceptability(designations)) {
component.addDesignation(asDesignation(d));
}
// Use the preferred term in the specified display language.
if (!designations.isEmpty() && d.hasAcceptability(Concepts.PREFERRED, designations.get(0)) && d.getTypeId().equals(Concepts.SYNONYM)) {
component.setDisplay(d.getTerm());
boolean inactive = !c.isActive();
if (inactive) {
component.setInactive(inactive);
}
}
}
}
}
}
use of org.snomed.snowstorm.core.data.domain.Description in project snowstorm by IHTSDO.
the class DescriptionDroolsValidationServiceTest method findMatchingDescriptionInHierarchy.
@Test
void findMatchingDescriptionInHierarchy() {
Concept concept = new Concept("1760555000");
concept.addAxiom(new Relationship(ISA, bodyStructureDescendant1.getId()));
Description description = new Description("5582049016", null, true, "900000000000207008", "1760555000", "en", "900000000000013009", "Entire heart", "900000000000448009");
org.ihtsdo.drools.domain.Concept droolConcept = new DroolsConcept(concept);
org.ihtsdo.drools.domain.Description droolDescription = new DroolsDescription(description);
Set<org.ihtsdo.drools.domain.Description> descriptions = validationService.findMatchingDescriptionInHierarchy(droolConcept, droolDescription);
assertEquals(1, descriptions.size());
}
use of org.snomed.snowstorm.core.data.domain.Description in project snowstorm by IHTSDO.
the class ServiceTestUtil method createConceptWithPathIdAndTermWithLang.
public Concept createConceptWithPathIdAndTermWithLang(String path, String conceptId, String term, String languageCode) throws ServiceException {
final Concept concept = new Concept(conceptId);
concept.addDescription(new Description(term).setLang(languageCode));
return conceptService.create(concept, path);
}
Aggregations