use of com.b2international.snomed.ecl.ecl in project snow-owl by b2ihealthcare.
the class SnomedEclEvaluationRequest method eval.
/**
* Handles (possibly) filtered expression constraints by evaluating them along
* with the primary ECL expression, and adding the resulting query expressions as
* extra required clauses.
*
* @param context
* @param filtered
* @return
*/
protected Promise<Expression> eval(BranchContext context, final FilteredExpressionConstraint filtered) {
final ExpressionConstraint constraint = filtered.getConstraint();
final FilterConstraint filterConstraint = filtered.getFilter();
final Domain filterDomain = Ecl.getDomain(filterConstraint);
final Filter filter = filterConstraint.getFilter();
final Promise<Expression> evaluatedConstraint = evaluate(context, constraint);
Promise<Expression> evaluatedFilter = evaluate(context, filter);
if (Domain.DESCRIPTION.equals(filterDomain)) {
// Find concepts that match the description expression, then use the resulting concept IDs as the expression
evaluatedFilter = evaluatedFilter.then(ex -> executeDescriptionSearch(context, ex));
}
if (isAnyExpression(constraint)) {
// No need to combine "match all" with the filter query expression, return it directly
return evaluatedFilter;
}
return Promise.all(evaluatedConstraint, evaluatedFilter).then(results -> {
final Expressions.ExpressionBuilder builder = Expressions.builder();
results.forEach(f -> builder.filter((Expression) f));
return builder.build();
});
}
use of com.b2international.snomed.ecl.ecl in project snow-owl by b2ihealthcare.
the class SnomedEclRefinementEvaluator method evalRefinement.
/**
* Evaluates an {@link AttributeConstraint} refinement on the given focusConceptId set on the given {@link BranchContext}.
* Grouped parameter can
*/
private Promise<Collection<Property>> evalRefinement(final BranchContext context, final AttributeConstraint refinement, final boolean grouped, final Set<String> focusConceptIds) {
final Comparison comparison = refinement.getComparison();
final Collection<String> typeConceptFilter = evalToConceptIds(context, refinement.getAttribute(), expressionForm).getSync(1, TimeUnit.MINUTES);
if (comparison instanceof AttributeComparison) {
// resolve non-* focusConcept ECLs to IDs, so we can filter relationships by source/destination
// filterByType and filterByDestination accepts ECL expressions as well, so serialize them into ECL and pass as String when required
// if reversed refinement, then we are interested in the destinationIds otherwise we need the sourceIds
final Collection<String> destinationConceptFilter = evalToConceptIds(context, ((AttributeComparison) comparison).getValue(), expressionForm).getSync(1, TimeUnit.MINUTES);
final Collection<String> focusConceptFilter = refinement.isReversed() ? destinationConceptFilter : focusConceptIds;
final Collection<String> valueConceptFilter = refinement.isReversed() ? focusConceptIds : destinationConceptFilter;
return evalStatements(context, focusConceptFilter, typeConceptFilter, valueConceptFilter, grouped, expressionForm);
} else if (comparison instanceof DataTypeComparison) {
if (refinement.isReversed()) {
throw new BadRequestException("Reversed flag is not supported in data type based comparison (string/numeric)");
} else {
final Promise<Collection<Property>> statementsWithValue = evalStatementsWithValue(context, focusConceptIds, typeConceptFilter, (DataTypeComparison) comparison);
final Promise<Collection<Property>> members = evalMembers(context, focusConceptIds, typeConceptFilter, (DataTypeComparison) comparison);
return Promise.all(statementsWithValue, members).then(results -> {
final Collection<Property> s = (Collection<Property>) results.get(0);
final Collection<Property> m = (Collection<Property>) results.get(1);
return FluentIterable.concat(s, m).toSet();
});
}
} else {
return SnomedEclEvaluationRequest.throwUnsupported(comparison);
}
}
Aggregations