Search in sources :

Example 16 with ConceptMini

use of org.snomed.snowstorm.core.data.domain.ConceptMini in project snowstorm by IHTSDO.

the class ReferenceSetMemberController method joinReferencedComponents.

private void joinReferencedComponents(List<ReferenceSetMember> members, List<LanguageDialect> languageDialects, String branch) {
    Set<String> conceptIds = members.stream().map(ReferenceSetMember::getReferencedComponentId).filter(IdentifierService::isConceptId).collect(Collectors.toSet());
    Set<String> descriptionIds = members.stream().map(ReferenceSetMember::getReferencedComponentId).filter(IdentifierService::isDescriptionId).collect(Collectors.toSet());
    Map<String, ConceptMini> conceptMinis = conceptService.findConceptMinis(branch, conceptIds, languageDialects).getResultsMap();
    Map<String, Description> descriptions;
    if (!descriptionIds.isEmpty()) {
        Page<Description> descriptionsPage = descriptionService.findDescriptions(branch, null, descriptionIds, null, PageRequest.of(0, descriptionIds.size()));
        descriptions = descriptionsPage.stream().collect(Collectors.toMap(Description::getId, Function.identity()));
    } else {
        descriptions = new HashMap<>();
    }
    members.forEach(member -> {
        ConceptMini conceptMini = conceptMinis.get(member.getReferencedComponentId());
        if (conceptMini != null) {
            member.setReferencedComponentConceptMini(conceptMini);
        }
        Description description = descriptions.get(member.getReferencedComponentId());
        if (description != null) {
            member.setReferencedComponentSnomedComponent(description);
        }
    });
}
Also used : Description(org.snomed.snowstorm.core.data.domain.Description) ReferenceSetMember(org.snomed.snowstorm.core.data.domain.ReferenceSetMember) ConceptMini(org.snomed.snowstorm.core.data.domain.ConceptMini)

Example 17 with ConceptMini

use of org.snomed.snowstorm.core.data.domain.ConceptMini in project snowstorm by IHTSDO.

the class ContentReportService method findInactiveConceptsWithNoHistoricalAssociationByInactivationType.

public List<InactivationTypeAndConceptIdList> findInactiveConceptsWithNoHistoricalAssociationByInactivationType(String branchPath, String conceptEffectiveTime) {
    BranchCriteria branchCriteria = versionControlHelper.getBranchCriteria(branchPath);
    List<InactivationTypeAndConceptIdList> results = new ArrayList<>();
    // Gather ids of inactive concepts
    BoolQueryBuilder boolQueryBuilder = boolQuery().must(branchCriteria.getEntityBranchCriteria(Concept.class)).must(termQuery(Concept.Fields.ACTIVE, false));
    if (!Strings.isNullOrEmpty(conceptEffectiveTime)) {
        boolQueryBuilder.must(termQuery(Concept.Fields.EFFECTIVE_TIME, conceptEffectiveTime));
    }
    List<Long> conceptIds = new LongArrayList();
    try (SearchHitsIterator<Concept> conceptStream = elasticsearchOperations.searchForStream(new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withFields(Concept.Fields.CONCEPT_ID).withPageable(LARGE_PAGE).build(), Concept.class)) {
        conceptStream.forEachRemaining(hit -> conceptIds.add(hit.getContent().getConceptIdAsLong()));
    }
    if (conceptIds.isEmpty()) {
        return results;
    }
    // Gather ids of concepts with historical associations
    List<Long> conceptsWithAssociations = new LongArrayList();
    List<Long> allHistoricalAssociations = eclQueryService.selectConceptIds("<" + Concepts.REFSET_HISTORICAL_ASSOCIATION, branchCriteria, branchPath, true, LARGE_PAGE).getContent();
    for (List<Long> batch : Iterables.partition(conceptIds, CLAUSE_LIMIT)) {
        try (SearchHitsIterator<ReferenceSetMember> memberStream = elasticsearchOperations.searchForStream(new NativeSearchQueryBuilder().withQuery(boolQuery().must(branchCriteria.getEntityBranchCriteria(ReferenceSetMember.class)).must(termQuery(ReferenceSetMember.Fields.ACTIVE, true)).must(termsQuery(ReferenceSetMember.Fields.REFSET_ID, allHistoricalAssociations)).filter(termsQuery(ReferenceSetMember.Fields.REFERENCED_COMPONENT_ID, batch))).withFields(ReferenceSetMember.Fields.REFERENCED_COMPONENT_ID).withPageable(LARGE_PAGE).build(), ReferenceSetMember.class)) {
            memberStream.forEachRemaining(hit -> conceptsWithAssociations.add(parseLong(hit.getContent().getReferencedComponentId())));
        }
    }
    List<Long> conceptsWithoutAssociations = new LongArrayList(conceptIds);
    conceptsWithoutAssociations.removeAll(conceptsWithAssociations);
    if (conceptsWithoutAssociations.isEmpty()) {
        return results;
    }
    // Inactivation indicators
    Map<Long, List<Long>> conceptsByIndicator = new Long2ObjectOpenHashMap<>();
    for (List<Long> batch : Iterables.partition(conceptsWithoutAssociations, CLAUSE_LIMIT)) {
        try (SearchHitsIterator<ReferenceSetMember> memberStream = elasticsearchOperations.searchForStream(new NativeSearchQueryBuilder().withQuery(boolQuery().must(branchCriteria.getEntityBranchCriteria(ReferenceSetMember.class)).must(termQuery(ReferenceSetMember.Fields.REFSET_ID, Concepts.CONCEPT_INACTIVATION_INDICATOR_REFERENCE_SET)).must(termQuery(ReferenceSetMember.Fields.ACTIVE, true)).filter(termsQuery(ReferenceSetMember.Fields.REFERENCED_COMPONENT_ID, batch))).withPageable(LARGE_PAGE).build(), ReferenceSetMember.class)) {
            memberStream.forEachRemaining(hit -> conceptsByIndicator.computeIfAbsent(parseLong(hit.getContent().getAdditionalField("valueId")), key -> new LongArrayList()).add(parseLong(hit.getContent().getReferencedComponentId())));
        }
    }
    Map<String, ConceptMini> minis = conceptService.findConceptMinis(branchCriteria, conceptsByIndicator.keySet(), DEFAULT_LANGUAGE_DIALECTS).getResultsMap();
    for (Long indicator : conceptsByIndicator.keySet()) {
        results.add(new InactivationTypeAndConceptIdList(minis.get(indicator.toString()), new LongOpenHashSet(conceptsByIndicator.get(indicator))));
    }
    List<Long> conceptsWithNoIndicator = new LongArrayList(conceptsWithoutAssociations);
    for (List<Long> longs : conceptsByIndicator.values()) {
        conceptsWithNoIndicator.removeAll(longs);
    }
    if (!conceptsWithNoIndicator.isEmpty()) {
        results.add(new InactivationTypeAndConceptIdList(new ConceptMini("0", DEFAULT_LANGUAGE_DIALECTS), new LongOpenHashSet(conceptsWithNoIndicator)));
    }
    return results;
}
Also used : Concept(org.snomed.snowstorm.core.data.domain.Concept) BranchCriteria(io.kaicode.elasticvc.api.BranchCriteria) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) ReferenceSetMember(org.snomed.snowstorm.core.data.domain.ReferenceSetMember) ConceptMini(org.snomed.snowstorm.core.data.domain.ConceptMini) Long.parseLong(java.lang.Long.parseLong) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)

Aggregations

ConceptMini (org.snomed.snowstorm.core.data.domain.ConceptMini)17 Concept (org.snomed.snowstorm.core.data.domain.Concept)7 Description (org.snomed.snowstorm.core.data.domain.Description)6 LanguageDialect (org.snomed.snowstorm.core.pojo.LanguageDialect)6 PageRequest (org.springframework.data.domain.PageRequest)6 ApiOperation (io.swagger.annotations.ApiOperation)5 ReferenceSetMember (org.snomed.snowstorm.core.data.domain.ReferenceSetMember)5 TimerUtil (org.snomed.snowstorm.core.util.TimerUtil)5 PageImpl (org.springframework.data.domain.PageImpl)5 JsonView (com.fasterxml.jackson.annotation.JsonView)4 BranchCriteria (io.kaicode.elasticvc.api.BranchCriteria)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 Config (org.snomed.snowstorm.config.Config)4 ConceptService (org.snomed.snowstorm.core.data.services.ConceptService)4 DescriptionCriteria (org.snomed.snowstorm.core.data.services.pojo.DescriptionCriteria)4 PageWithBucketAggregations (org.snomed.snowstorm.core.data.services.pojo.PageWithBucketAggregations)4 BrowserDescriptionSearchResult (org.snomed.snowstorm.rest.pojo.BrowserDescriptionSearchResult)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Api (io.swagger.annotations.Api)3