Search in sources :

Example 1 with RelationshipValueType

use of com.b2international.snowowl.snomed.core.domain.RelationshipValueType in project snow-owl by b2ihealthcare.

the class SnomedRelationshipSearchRequest method prepareQuery.

@Override
protected Expression prepareQuery(BranchContext context) {
    final ExpressionBuilder queryBuilder = Expressions.builder();
    addActiveClause(queryBuilder);
    addReleasedClause(queryBuilder);
    addIdFilter(queryBuilder, RevisionDocument.Expressions::ids);
    addEclFilter(context, queryBuilder, SnomedSearchRequest.OptionKey.MODULE, SnomedDocument.Expressions::modules);
    addNamespaceFilter(queryBuilder);
    addNamespaceConceptIdFilter(context, queryBuilder);
    addEffectiveTimeClause(queryBuilder);
    addActiveMemberOfClause(context, queryBuilder);
    addMemberOfClause(context, queryBuilder);
    addEclFilter(context, queryBuilder, OptionKey.SOURCE, SnomedRelationshipIndexEntry.Expressions::sourceIds);
    addEclFilter(context, queryBuilder, OptionKey.TYPE, SnomedRelationshipIndexEntry.Expressions::typeIds);
    addEclFilter(context, queryBuilder, OptionKey.DESTINATION, SnomedRelationshipIndexEntry.Expressions::destinationIds);
    addEclFilter(context, queryBuilder, OptionKey.CHARACTERISTIC_TYPE, SnomedRelationshipIndexEntry.Expressions::characteristicTypeIds);
    addEclFilter(context, queryBuilder, OptionKey.MODIFIER, SnomedRelationshipIndexEntry.Expressions::modifierIds);
    if (containsKey(OptionKey.GROUP_MIN) || containsKey(OptionKey.GROUP_MAX)) {
        final int from = containsKey(OptionKey.GROUP_MIN) ? get(OptionKey.GROUP_MIN, Integer.class) : 0;
        final int to = containsKey(OptionKey.GROUP_MAX) ? get(OptionKey.GROUP_MAX, Integer.class) : Integer.MAX_VALUE;
        queryBuilder.filter(relationshipGroup(from, to));
    }
    if (containsKey(OptionKey.UNION_GROUP)) {
        queryBuilder.filter(unionGroup(get(OptionKey.UNION_GROUP, Integer.class)));
    }
    if (containsKey(OptionKey.HAS_DESTINATION_ID)) {
        // No need to check the value for the option key here, as it can only be set to "true" in the builder
        queryBuilder.filter(hasDestinationId());
    }
    if (containsKey(OptionKey.VALUE_TYPE)) {
        final Collection<RelationshipValueType> valueTypes = getCollection(OptionKey.VALUE_TYPE, RelationshipValueType.class);
        queryBuilder.filter(valueTypes(valueTypes));
    }
    if (containsKey(OptionKey.VALUE)) {
        final SearchResourceRequest.Operator op = get(OptionKey.OPERATOR, SearchResourceRequest.Operator.class);
        final Collection<RelationshipValue> values = getCollection(OptionKey.VALUE, RelationshipValue.class);
        switch(op) {
            case EQUALS:
                queryBuilder.filter(values(values));
                break;
            case NOT_EQUALS:
                queryBuilder.mustNot(values(values));
                break;
            case LESS_THAN:
                checkRangeValue(values);
                queryBuilder.filter(valueLessThan(Iterables.getOnlyElement(values), false));
                break;
            case LESS_THAN_EQUALS:
                checkRangeValue(values);
                queryBuilder.filter(valueLessThan(Iterables.getOnlyElement(values), true));
                break;
            case GREATER_THAN:
                checkRangeValue(values);
                queryBuilder.filter(valueGreaterThan(Iterables.getOnlyElement(values), false));
                break;
            case GREATER_THAN_EQUALS:
                checkRangeValue(values);
                queryBuilder.filter(valueGreaterThan(Iterables.getOnlyElement(values), true));
                break;
            default:
                throw new NotImplementedException("Unsupported concrete value operator %s", op);
        }
    }
    return queryBuilder.build();
}
Also used : RelationshipValueType(com.b2international.snowowl.snomed.core.domain.RelationshipValueType) NotImplementedException(com.b2international.commons.exceptions.NotImplementedException) Expressions(com.b2international.index.query.Expressions) Expressions(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions) RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest)

Example 2 with RelationshipValueType

use of com.b2international.snowowl.snomed.core.domain.RelationshipValueType in project snow-owl by b2ihealthcare.

the class RelationshipWriter method indexChange.

@Override
public void indexChange(final String conceptId, final StatementFragment fragment, final ChangeNature nature) {
    final RelationshipChangeDocument.Builder builder = RelationshipChangeDocument.builder().nature(nature).classificationId(classificationId).sourceId(conceptId);
    if (fragment instanceof StatementFragmentWithDestination) {
        final long destinationId = ((StatementFragmentWithDestination) fragment).getDestinationId();
        builder.destinationId(Long.toString(destinationId));
    } else {
        final StatementFragmentWithValue fragmentWithValue = (StatementFragmentWithValue) fragment;
        final RelationshipValueType valueType = fragmentWithValue.getValueType();
        final String rawValue = fragmentWithValue.getRawValue();
        builder.valueType(valueType);
        builder.rawValue(rawValue);
    }
    switch(nature) {
        case NEW:
            builder.group(fragment.getGroup());
            builder.unionGroup(fragment.getUnionGroup());
            builder.characteristicTypeId(Concepts.INFERRED_RELATIONSHIP);
            builder.released(Boolean.FALSE);
            if (fragment.getStatementId() != -1L) {
                builder.relationshipId(Long.toString(fragment.getStatementId()));
            } else {
                builder.typeId(Long.toString(fragment.getTypeId()));
            }
            break;
        case UPDATED:
            builder.group(fragment.getGroup());
            builder.released(fragment.isReleased());
            builder.relationshipId(Long.toString(fragment.getStatementId()));
            break;
        case REDUNDANT:
            builder.released(fragment.isReleased());
            builder.relationshipId(Long.toString(fragment.getStatementId()));
            break;
        default:
            throw new IllegalStateException(String.format("Unexpected relationship change '%s' found with SCTID '%s'.", nature, fragment.getStatementId()));
    }
    indexChange(builder.build());
}
Also used : RelationshipChangeDocument(com.b2international.snowowl.snomed.reasoner.index.RelationshipChangeDocument) RelationshipValueType(com.b2international.snowowl.snomed.core.domain.RelationshipValueType) StatementFragmentWithValue(com.b2international.snowowl.snomed.datastore.StatementFragmentWithValue) StatementFragmentWithDestination(com.b2international.snowowl.snomed.datastore.StatementFragmentWithDestination)

Aggregations

RelationshipValueType (com.b2international.snowowl.snomed.core.domain.RelationshipValueType)2 NotImplementedException (com.b2international.commons.exceptions.NotImplementedException)1 Expressions (com.b2international.index.query.Expressions)1 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)1 SearchResourceRequest (com.b2international.snowowl.core.request.SearchResourceRequest)1 RelationshipValue (com.b2international.snowowl.snomed.core.domain.RelationshipValue)1 StatementFragmentWithDestination (com.b2international.snowowl.snomed.datastore.StatementFragmentWithDestination)1 StatementFragmentWithValue (com.b2international.snowowl.snomed.datastore.StatementFragmentWithValue)1 Expressions (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions)1 RelationshipChangeDocument (com.b2international.snowowl.snomed.reasoner.index.RelationshipChangeDocument)1