Search in sources :

Example 1 with SnomedConceptSearchRequestBuilder

use of com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder in project snow-owl by b2ihealthcare.

the class SnomedRf2ExportRequest method getIdentifierConcepts.

private List<SnomedConcept> getIdentifierConcepts(final RepositoryContext context, final String currentVersion) {
    final Collection<String> refSetsToLoad;
    if (refSets == null) {
        // Retrieve all reference sets if refSets is null
        final Request<BranchContext, SnomedReferenceSets> refSetRequest = SnomedRequests.prepareSearchRefSet().all().build();
        final SnomedReferenceSets allReferenceSets = execute(context, currentVersion, refSetRequest);
        refSetsToLoad = allReferenceSets.stream().map(r -> r.getId()).collect(Collectors.toSet());
    } else {
        refSetsToLoad = refSets;
    }
    final SnomedConceptSearchRequestBuilder refSetRequestBuilder = SnomedRequests.prepareSearchConcept().all().filterByIds(refSetsToLoad).setExpand("pt(),referenceSet()").setLocales(locales());
    final Request<BranchContext, SnomedConcepts> request = refSetRequestBuilder.build();
    final SnomedConcepts referenceSets = execute(context, currentVersion, request);
    // Return only the identifier concepts which have an existing reference set on this branch
    return referenceSets.stream().filter(c -> c.getReferenceSet() != null).collect(Collectors.toList());
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) SnomedConceptSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) SnomedReferenceSets(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets) RepositoryRequests(com.b2international.snowowl.core.repository.RepositoryRequests) Sets.newTreeSet(com.google.common.collect.Sets.newTreeSet) Collections.singleton(java.util.Collections.singleton) AccessControl(com.b2international.snowowl.core.authorization.AccessControl) LocalTime(java.time.LocalTime) RevisionIndex(com.b2international.index.revision.RevisionIndex) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) AttachmentRegistry(com.b2international.snowowl.core.attachments.AttachmentRegistry) Branches(com.b2international.snowowl.core.branch.Branches) Permission(com.b2international.snowowl.core.identity.Permission) CompareUtils(com.b2international.commons.CompareUtils) Path(java.nio.file.Path) com.google.common.collect(com.google.common.collect) Collectors.toSet(java.util.stream.Collectors.toSet) ResourceURI(com.b2international.snowowl.core.ResourceURI) com.b2international.snowowl.core.request(com.b2international.snowowl.core.request) Version(com.b2international.snowowl.core.version.Version) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Request(com.b2international.snowowl.core.events.Request) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Instant(java.time.Instant) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Stream(java.util.stream.Stream) VersionDocument(com.b2international.snowowl.core.version.VersionDocument) LocalDate(java.time.LocalDate) Sort(com.b2international.snowowl.core.request.SearchResourceRequest.Sort) Entry(java.util.Map.Entry) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Builder(com.google.common.collect.ImmutableList.Builder) FileUtils(com.b2international.commons.FileUtils) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) EffectiveTimes(com.b2international.snowowl.core.date.EffectiveTimes) java.util(java.util) TerminologyResource(com.b2international.snowowl.core.TerminologyResource) LocalDateTime(java.time.LocalDateTime) com.b2international.snowowl.snomed.datastore.request.rf2.exporter(com.b2international.snowowl.snomed.datastore.request.rf2.exporter) com.b2international.snowowl.snomed.core.domain(com.b2international.snowowl.snomed.core.domain) Branch(com.b2international.snowowl.core.branch.Branch) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) Strings(com.google.common.base.Strings) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Attachment(com.b2international.snowowl.core.attachments.Attachment) SnomedRefSetMemberSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRefSetMemberSearchRequestBuilder) BadRequestException(com.b2international.commons.exceptions.BadRequestException) BranchPathUtils(com.b2international.snowowl.core.branch.BranchPathUtils) DateFormats(com.b2international.snowowl.core.date.DateFormats) Files(java.nio.file.Files) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ChronoUnit(java.time.temporal.ChronoUnit) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) NotEmpty(org.hibernate.validator.constraints.NotEmpty) DateTimeFormatter(java.time.format.DateTimeFormatter) IComponent(com.b2international.snowowl.core.domain.IComponent) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) Versions(com.b2international.snowowl.core.version.Versions) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) BranchContext(com.b2international.snowowl.core.domain.BranchContext) SnomedReferenceSets(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets) SnomedConceptSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder)

Example 2 with SnomedConceptSearchRequestBuilder

use of com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder in project snow-owl by b2ihealthcare.

the class SnomedConceptSearchRequestEvaluator method evaluate.

@Override
public Concepts evaluate(ResourceURI uri, ServiceProvider context, Options search) {
    final String preferredDisplay = search.getString(OptionKey.DISPLAY);
    SnomedDisplayTermType displayTermType;
    if (preferredDisplay != null) {
        displayTermType = SnomedDisplayTermType.getEnum(preferredDisplay);
    } else {
        displayTermType = SnomedDisplayTermType.PT;
    }
    final SnomedConceptSearchRequestBuilder req = SnomedRequests.prepareSearchConcept();
    evaluateTermFilterOptions(req, search);
    if (search.containsKey(OptionKey.ID)) {
        req.filterByIds(search.getCollection(OptionKey.ID, String.class));
    }
    if (search.containsKey(OptionKey.ACTIVE)) {
        req.filterByActive(search.getBoolean(OptionKey.ACTIVE));
    }
    if (search.containsKey(OptionKey.PARENT)) {
        req.filterByParents(search.getCollection(OptionKey.PARENT, String.class));
    }
    if (search.containsKey(OptionKey.ANCESTOR)) {
        req.filterByAncestors(search.getCollection(OptionKey.ANCESTOR, String.class));
    }
    if (search.containsKey(OptionKey.TERM_TYPE)) {
        req.filterByDescriptionType(search.getString(OptionKey.TERM_TYPE));
    }
    if (search.containsKey(OptionKey.QUERY) || search.containsKey(OptionKey.MUST_NOT_QUERY)) {
        StringBuilder query = new StringBuilder();
        if (search.containsKey(OptionKey.QUERY)) {
            query.append("(").append(Ecl.or(search.getCollection(OptionKey.QUERY, String.class))).append(")");
        } else {
            query.append(Ecl.ANY);
        }
        if (search.containsKey(OptionKey.MUST_NOT_QUERY)) {
            query.append(" MINUS (").append(Ecl.or(search.getCollection(OptionKey.MUST_NOT_QUERY, String.class))).append(")");
        }
        req.filterByEcl(query.toString());
    }
    boolean requestedExpand = search.containsKey(OptionKey.EXPAND);
    // make sure preferredDescriptions() and displayTermType expansion data are always loaded
    Options expand = ExpandParser.parse("preferredDescriptions()").merge(requestedExpand ? search.getOptions(OptionKey.EXPAND) : Options.empty());
    if (!Strings.isNullOrEmpty(displayTermType.getExpand())) {
        expand = ExpandParser.parse(displayTermType.getExpand()).merge(expand);
    }
    SnomedConcepts matches = req.setLocales(search.getList(OptionKey.LOCALES, ExtendedLocale.class)).setSearchAfter(search.getString(OptionKey.AFTER)).setLimit(search.get(OptionKey.LIMIT, Integer.class)).setFields(search.getList(OptionKey.FIELDS, String.class)).setExpand(expand).sortBy(search.containsKey(SearchResourceRequest.OptionKey.SORT_BY) ? search.getList(SearchResourceRequest.OptionKey.SORT_BY, SearchResourceRequest.Sort.class) : null).build(uri).execute(context);
    return new Concepts(matches.stream().map(concept -> toConcept(uri, concept, displayTermType.getLabel(concept), requestedExpand)).collect(Collectors.toList()), matches.getSearchAfter(), matches.getLimit(), matches.getTotal());
}
Also used : Options(com.b2international.commons.options.Options) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) Concepts(com.b2international.snowowl.core.domain.Concepts) SnomedDisplayTermType(com.b2international.snowowl.snomed.core.SnomedDisplayTermType) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) SnomedConceptSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest)

Example 3 with SnomedConceptSearchRequestBuilder

use of com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder in project snow-owl by b2ihealthcare.

the class SnomedSimpleTypeRefSetDSVExporter method writeValues.

private void writeValues(IProgressMonitor monitor, BufferedWriter writer) throws IOException {
    SearchResourceRequestIterator<SnomedConceptSearchRequestBuilder, SnomedConcepts> conceptIterator = getMemberConceptIterator(DATA_EXPAND);
    while (conceptIterator.hasNext()) {
        SnomedConcepts chunk = conceptIterator.next();
        writeValues(writer, chunk);
        monitor.worked(chunk.getItems().size());
    }
}
Also used : SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) SnomedConceptSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder)

Aggregations

SnomedConceptSearchRequestBuilder (com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder)3 SnomedConcepts (com.b2international.snowowl.snomed.core.domain.SnomedConcepts)2 CompareUtils (com.b2international.commons.CompareUtils)1 FileUtils (com.b2international.commons.FileUtils)1 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 Options (com.b2international.commons.options.Options)1 RevisionIndex (com.b2international.index.revision.RevisionIndex)1 ResourceURI (com.b2international.snowowl.core.ResourceURI)1 TerminologyResource (com.b2international.snowowl.core.TerminologyResource)1 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1 Attachment (com.b2international.snowowl.core.attachments.Attachment)1 AttachmentRegistry (com.b2international.snowowl.core.attachments.AttachmentRegistry)1 AccessControl (com.b2international.snowowl.core.authorization.AccessControl)1 Branch (com.b2international.snowowl.core.branch.Branch)1 BranchPathUtils (com.b2international.snowowl.core.branch.BranchPathUtils)1 Branches (com.b2international.snowowl.core.branch.Branches)1 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)1 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)1 DateFormats (com.b2international.snowowl.core.date.DateFormats)1 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)1