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);
}
});
}
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;
}
Aggregations