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