Search in sources :

Example 1 with Description

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;
}
Also used : Description(org.snomed.snowstorm.core.data.domain.Description) LanguageDialect(org.snomed.snowstorm.core.pojo.LanguageDialect) PageWithBucketAggregations(org.snomed.snowstorm.core.data.services.pojo.PageWithBucketAggregations) BrowserDescriptionSearchResult(org.snomed.snowstorm.rest.pojo.BrowserDescriptionSearchResult) PageRequest(org.springframework.data.domain.PageRequest) ConceptMini(org.snomed.snowstorm.core.data.domain.ConceptMini) DescriptionCriteria(org.snomed.snowstorm.core.data.services.pojo.DescriptionCriteria) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView)

Example 2 with Description

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.");
        }
    }
}
Also used : Concept(org.snomed.snowstorm.core.data.domain.Concept) BranchCriteria(io.kaicode.elasticvc.api.BranchCriteria) Description(org.snomed.snowstorm.core.data.domain.Description) Commit(io.kaicode.elasticvc.domain.Commit) ReferenceSetMember(org.snomed.snowstorm.core.data.domain.ReferenceSetMember)

Example 3 with Description

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);
                    }
                }
            }
        }
    }
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent) Concept(org.snomed.snowstorm.core.data.domain.Concept) ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) Description(org.snomed.snowstorm.core.data.domain.Description) ConceptMini(org.snomed.snowstorm.core.data.domain.ConceptMini)

Example 4 with Description

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());
}
Also used : DroolsConcept(org.snomed.snowstorm.validation.domain.DroolsConcept) Concept(org.snomed.snowstorm.core.data.domain.Concept) Description(org.snomed.snowstorm.core.data.domain.Description) DroolsDescription(org.snomed.snowstorm.validation.domain.DroolsDescription) DroolsDescription(org.snomed.snowstorm.validation.domain.DroolsDescription) Relationship(org.snomed.snowstorm.core.data.domain.Relationship) DroolsConcept(org.snomed.snowstorm.validation.domain.DroolsConcept) AbstractTest(org.snomed.snowstorm.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 5 with Description

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);
}
Also used : Concept(org.snomed.snowstorm.core.data.domain.Concept) Description(org.snomed.snowstorm.core.data.domain.Description)

Aggregations

Description (org.snomed.snowstorm.core.data.domain.Description)25 Concept (org.snomed.snowstorm.core.data.domain.Concept)14 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)6 ConceptMini (org.snomed.snowstorm.core.data.domain.ConceptMini)5 ReferenceSetMember (org.snomed.snowstorm.core.data.domain.ReferenceSetMember)5 JsonView (com.fasterxml.jackson.annotation.JsonView)4 ApiOperation (io.swagger.annotations.ApiOperation)4 Test (org.junit.jupiter.api.Test)4 PageWithBucketAggregations (org.snomed.snowstorm.core.data.services.pojo.PageWithBucketAggregations)4 LanguageDialect (org.snomed.snowstorm.core.pojo.LanguageDialect)4 DroolsDescription (org.snomed.snowstorm.validation.domain.DroolsDescription)4 BranchCriteria (io.kaicode.elasticvc.api.BranchCriteria)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 AbstractTest (org.snomed.snowstorm.AbstractTest)3 CodeSystem (org.snomed.snowstorm.core.data.domain.CodeSystem)3 Relationship (org.snomed.snowstorm.core.data.domain.Relationship)3 ConceptService (org.snomed.snowstorm.core.data.services.ConceptService)3 DescriptionCriteria (org.snomed.snowstorm.core.data.services.pojo.DescriptionCriteria)3 BrowserDescriptionSearchResult (org.snomed.snowstorm.rest.pojo.BrowserDescriptionSearchResult)3 PageRequest (org.springframework.data.domain.PageRequest)3