use of com.b2international.snowowl.snomed.core.domain.refset.DataType in project snow-owl by b2ihealthcare.
the class SnomedRefSetApiTest method createConcreteDomainReferenceSets.
@Test
public void createConcreteDomainReferenceSets() {
createConcreteDomainParentConcept(branchPath);
for (DataType dataType : DataType.values()) {
System.out.println("Datatype: " + dataType);
createConcreteDomainRefSet(branchPath, dataType);
}
}
use of com.b2international.snowowl.snomed.core.domain.refset.DataType in project snow-owl by b2ihealthcare.
the class SnomedConcreteDomainMemberCreateDelegate method execute.
@Override
public String execute(SnomedReferenceSet refSet, TransactionContext context) {
checkRefSetType(refSet, SnomedRefSetType.CONCRETE_DATA_TYPE);
checkReferencedComponent(refSet);
checkNonEmptyProperty(SnomedRf2Headers.FIELD_VALUE);
checkNonEmptyProperty(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP);
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MODULE_ID, getModuleId());
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_REFERENCED_COMPONENT_ID, getReferencedComponentId());
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_TYPE_ID);
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID);
DataType dataType = refSet.getDataType();
String value = getProperty(SnomedRf2Headers.FIELD_VALUE);
try {
SnomedRefSetUtil.deserializeValue(dataType, value);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Couldn't deserialize value '%s' for data type '%s'.", value, dataType);
}
SnomedRefSetMemberIndexEntry member = SnomedComponents.newConcreteDomainReferenceSetMember().withId(getId()).withActive(isActive()).withCharacteristicTypeId(getComponentId(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID)).withGroup(getProperty(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP, Integer.class)).withModuleId(getModuleId()).withReferencedComponent(getReferencedComponentId()).withRefSet(getReferenceSetId()).withSerializedValue(getProperty(SnomedRf2Headers.FIELD_VALUE)).withTypeId(getComponentId(SnomedRf2Headers.FIELD_TYPE_ID)).addTo(context);
return member.getId();
}
use of com.b2international.snowowl.snomed.core.domain.refset.DataType in project snow-owl by b2ihealthcare.
the class SnomedRefSetMemberSearchRequest method prepareQuery.
@Override
protected Expression prepareQuery(BranchContext context) {
final Collection<String> referencedComponentIds = getCollection(OptionKey.REFERENCED_COMPONENT, String.class);
final Collection<SnomedRefSetType> refSetTypes = getCollection(OptionKey.REFSET_TYPE, SnomedRefSetType.class);
final Options propsFilter = getOptions(OptionKey.PROPS);
ExpressionBuilder queryBuilder = Expressions.builder();
addActiveClause(queryBuilder);
addReleasedClause(queryBuilder);
addEclFilter(context, queryBuilder, SnomedSearchRequest.OptionKey.MODULE, SnomedDocument.Expressions::modules);
addIdFilter(queryBuilder, RevisionDocument.Expressions::ids);
addEffectiveTimeClause(queryBuilder);
addEclFilter(context, queryBuilder, OptionKey.REFSET, SnomedRefSetMemberIndexEntry.Expressions::refsetIds);
addComponentClause(queryBuilder);
if (containsKey(OptionKey.REFERENCED_COMPONENT_TYPE)) {
queryBuilder.filter(referencedComponentTypes(getCollection(OptionKey.REFERENCED_COMPONENT_TYPE, String.class)));
}
if (!referencedComponentIds.isEmpty()) {
queryBuilder.filter(referencedComponentIds(referencedComponentIds));
}
if (!refSetTypes.isEmpty()) {
queryBuilder.filter(refSetTypes(refSetTypes));
}
if (!propsFilter.isEmpty()) {
final Set<String> propKeys = newHashSet(propsFilter.keySet());
if (propKeys.remove(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID)) {
queryBuilder.filter(acceptabilityIds(propsFilter.getCollection(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID, String.class)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP)) {
final String operatorKey = SearchResourceRequest.operator(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP);
SearchResourceRequest.Operator op;
if (propKeys.remove(operatorKey)) {
op = propsFilter.get(operatorKey, Operator.class);
} else {
op = SearchResourceRequest.Operator.EQUALS;
}
switch(op) {
case EQUALS:
queryBuilder.filter(relationshipGroup(propsFilter.get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP, Integer.class)));
break;
case NOT_EQUALS:
queryBuilder.mustNot(relationshipGroup(propsFilter.get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP, Integer.class)));
break;
default:
throw new NotImplementedException("Unsupported relationship group operator %s", op);
}
}
if (propKeys.remove(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::characteristicTypeIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_CORRELATION_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_CORRELATION_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::correlationIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_DESCRIPTION_FORMAT)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_DESCRIPTION_FORMAT, String.class), SnomedRefSetMemberIndexEntry.Expressions::descriptionFormats);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MAP_CATEGORY_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_MAP_CATEGORY_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::mapCategoryIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::targetComponentIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MAP_TARGET)) {
queryBuilder.filter(mapTargets(propsFilter.getCollection(SnomedRf2Headers.FIELD_MAP_TARGET, String.class)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MAP_TARGET_DESCRIPTION)) {
queryBuilder.filter(mapTargetDescriptions(propsFilter.getCollection(SnomedRf2Headers.FIELD_MAP_TARGET_DESCRIPTION, String.class)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MAP_GROUP)) {
queryBuilder.filter(mapGroups(propsFilter.getCollection(SnomedRf2Headers.FIELD_MAP_GROUP, Integer.class)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MAP_PRIORITY)) {
queryBuilder.filter(mapPriority(propsFilter.getCollection(SnomedRf2Headers.FIELD_MAP_PRIORITY, Integer.class)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MAP_BLOCK)) {
queryBuilder.filter(mapBlock(propsFilter.getCollection(SnomedRf2Headers.FIELD_MAP_BLOCK, Integer.class)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_VALUE_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_VALUE_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::valueIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_TYPE_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_TYPE_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::typeIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MRCM_DOMAIN_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_MRCM_DOMAIN_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::domainIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MRCM_CONTENT_TYPE_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_MRCM_CONTENT_TYPE_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::contentTypeIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MRCM_RULE_STRENGTH_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_MRCM_RULE_STRENGTH_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::ruleStrengthIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MRCM_RULE_REFSET_ID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRf2Headers.FIELD_MRCM_RULE_REFSET_ID, String.class), SnomedRefSetMemberIndexEntry.Expressions::ruleRefSetIds);
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MRCM_GROUPED)) {
queryBuilder.filter(grouped(propsFilter.getBoolean(SnomedRf2Headers.FIELD_MRCM_GROUPED)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_MRCM_RANGE_CONSTRAINT)) {
queryBuilder.filter(rangeConstraint(propsFilter.getString(SnomedRf2Headers.FIELD_MRCM_RANGE_CONSTRAINT)));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_OWL_EXPRESSION)) {
queryBuilder.filter(Expressions.exactMatch(SnomedRf2Headers.FIELD_OWL_EXPRESSION, propsFilter.getString(SnomedRf2Headers.FIELD_OWL_EXPRESSION)));
}
if (propKeys.remove(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_CONCEPTID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_CONCEPTID, String.class), SnomedRefSetMemberIndexEntry.Expressions::owlExpressionConcept);
}
if (propKeys.remove(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_DESTINATIONID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_DESTINATIONID, String.class), SnomedRefSetMemberIndexEntry.Expressions::owlExpressionDestination);
}
if (propKeys.remove(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_TYPEID)) {
addEclFilter(context, queryBuilder, propsFilter.getCollection(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_TYPEID, String.class), SnomedRefSetMemberIndexEntry.Expressions::owlExpressionType);
}
if (propKeys.remove(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_GCI)) {
queryBuilder.filter(gciAxiom(propsFilter.getBoolean(SnomedRefSetMemberSearchRequestBuilder.OWL_EXPRESSION_GCI)));
}
final Collection<DataType> dataTypes = propsFilter.getCollection(SnomedRefSetMemberIndexEntry.Fields.DATA_TYPE, DataType.class);
if (propKeys.remove(SnomedRefSetMemberIndexEntry.Fields.DATA_TYPE)) {
queryBuilder.filter(dataTypes(dataTypes));
}
if (propKeys.remove(SnomedRf2Headers.FIELD_VALUE)) {
if (dataTypes.size() != 1) {
throw new BadRequestException("DataType filter must be specified if filtering by value");
}
final DataType dataType = Iterables.getOnlyElement(dataTypes);
final String operatorKey = SearchResourceRequest.operator(SnomedRf2Headers.FIELD_VALUE);
SearchResourceRequest.Operator op;
if (propKeys.remove(operatorKey)) {
op = propsFilter.get(operatorKey, Operator.class);
} else {
op = SearchResourceRequest.Operator.EQUALS;
}
final Collection<Object> attributeValues = propsFilter.getCollection(SnomedRf2Headers.FIELD_VALUE, Object.class);
switch(op) {
case EQUALS:
queryBuilder.filter(values(dataType, attributeValues));
break;
case NOT_EQUALS:
queryBuilder.mustNot(values(dataType, attributeValues));
break;
case LESS_THAN:
checkRangeValue(attributeValues);
queryBuilder.filter(valueRange(dataType, null, Iterables.getOnlyElement(attributeValues), false, false));
break;
case LESS_THAN_EQUALS:
checkRangeValue(attributeValues);
queryBuilder.filter(valueRange(dataType, null, Iterables.getOnlyElement(attributeValues), false, true));
break;
case GREATER_THAN:
checkRangeValue(attributeValues);
queryBuilder.filter(valueRange(dataType, Iterables.getOnlyElement(attributeValues), null, false, false));
break;
case GREATER_THAN_EQUALS:
checkRangeValue(attributeValues);
queryBuilder.filter(valueRange(dataType, Iterables.getOnlyElement(attributeValues), null, true, false));
break;
default:
throw new NotImplementedException("Unsupported concrete domain value operator %s", op);
}
}
if (!propKeys.isEmpty()) {
throw new IllegalQueryParameterException("Unsupported property filter(s), %s", propKeys);
}
}
return queryBuilder.build();
}
use of com.b2international.snowowl.snomed.core.domain.refset.DataType in project snow-owl by b2ihealthcare.
the class DelegateOntology method addConcreteDomainMember.
private void addConcreteDomainMember(final ConcreteDomainFragment member, final Set<OWLClassExpression> intersection) {
final long typeId = member.getTypeId();
final String serializedValue = member.getSerializedValue();
final DataType sctDataType = SnomedRefSetUtil.getDataType(Long.toString(member.getRefSetId()));
final OWL2Datatype owl2Datatype = getOWL2Datatype(sctDataType);
final OWLDataProperty property = getConceptDataProperty(typeId);
final OWLLiteral owlLiteral = getOWLLiteral(serializedValue, owl2Datatype);
final OWLDataHasValue valueExpression = getOWLDataHasValue(property, owlLiteral);
intersection.add(valueExpression);
}
use of com.b2international.snowowl.snomed.core.domain.refset.DataType in project snow-owl by b2ihealthcare.
the class SnomedEclRefinementEvaluator method evalMembers.
private Promise<Collection<Property>> evalMembers(BranchContext context, Set<String> focusConceptIds, Collection<String> typeIds, DataTypeComparison comparison) {
final Object value;
final DataType type;
if (comparison instanceof BooleanValueComparison) {
value = ((BooleanValueComparison) comparison).isValue();
type = DataType.BOOLEAN;
} else if (comparison instanceof StringValueComparison) {
value = ((StringValueComparison) comparison).getValue();
type = DataType.STRING;
} else if (comparison instanceof IntegerValueComparison) {
value = ((IntegerValueComparison) comparison).getValue();
type = DataType.INTEGER;
} else if (comparison instanceof DecimalValueComparison) {
value = ((DecimalValueComparison) comparison).getValue();
type = DataType.DECIMAL;
} else {
return SnomedEclEvaluationRequest.throwUnsupported(comparison);
}
final SearchResourceRequest.Operator operator = toSearchOperator(comparison.getOp());
final Options propFilter = Options.builder().put(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID, getCharacteristicTypes(expressionForm)).put(SnomedRf2Headers.FIELD_TYPE_ID, typeIds).put(SnomedRefSetMemberIndexEntry.Fields.DATA_TYPE, type).put(SnomedRf2Headers.FIELD_VALUE, value).put(SearchResourceRequest.operator(SnomedRf2Headers.FIELD_VALUE), operator).build();
return SnomedRequests.prepareSearchMember().filterByActive(true).filterByRefSetType(SnomedRefSetType.CONCRETE_DATA_TYPE).filterByReferencedComponent(focusConceptIds).filterByProps(propFilter).setEclExpressionForm(expressionForm).setLimit(context.service(RepositoryConfiguration.class).getIndexConfiguration().getResultWindow()).<Property>transformAsync(context, req -> req.build(context.path()), members -> members.stream().map(input -> {
return new Property(input.getReferencedComponent().getId(), (String) input.getProperties().get(SnomedRf2Headers.FIELD_TYPE_ID), input.getProperties().get(SnomedRf2Headers.FIELD_VALUE), (Integer) input.getProperties().get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP));
}));
}
Aggregations