use of com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType in project snow-owl by b2ihealthcare.
the class SnomedConceptCreateRequest method checkParent.
private void checkParent(TransactionContext context) {
final SnomedRefSetType refSetType = refSetRequest.getRefSetType();
final String refSetTypeRootParent = SnomedRefSetUtil.getParentConceptId(refSetType);
final Set<String> parents = getParents();
if (!isValidParentage(context, refSetTypeRootParent, parents)) {
throw new BadRequestException("'%s' type reference sets should be subtype of '%s' concept.", refSetType, refSetTypeRootParent);
}
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType in project snow-owl by b2ihealthcare.
the class SnomedConceptMapSearchRequestEvaluator method getEquivalence.
private MappingCorrelation getEquivalence(SnomedReferenceSetMember conceptMapMember) {
SnomedRefSetType snomedRefSetType = conceptMapMember.type();
if (snomedRefSetType == SnomedRefSetType.SIMPLE_MAP || snomedRefSetType == SnomedRefSetType.SIMPLE_MAP_WITH_DESCRIPTION) {
// probably true
return MappingCorrelation.EXACT_MATCH;
}
Map<String, Object> properties = conceptMapMember.getProperties();
if (properties == null || properties.isEmpty()) {
return MappingCorrelation.NOT_SPECIFIED;
}
String correlationId = (String) properties.getOrDefault(SnomedRf2Headers.FIELD_CORRELATION_ID, "");
switch(correlationId) {
case Concepts.MAP_CORRELATION_EXACT_MATCH:
return MappingCorrelation.EXACT_MATCH;
case Concepts.MAP_CORRELATION_BROAD_TO_NARROW:
return MappingCorrelation.BROAD_TO_NARROW;
case Concepts.MAP_CORRELATION_NARROW_TO_BROAD:
return MappingCorrelation.NARROW_TO_BROAD;
case Concepts.MAP_CORRELATION_PARTIAL_OVERLAP:
return MappingCorrelation.PARTIAL_OVERLAP;
case Concepts.MAP_CORRELATION_NOT_MAPPABLE:
return MappingCorrelation.NOT_MAPPABLE;
case Concepts.MAP_CORRELATION_NOT_SPECIFIED:
return MappingCorrelation.NOT_SPECIFIED;
default:
return MappingCorrelation.NOT_SPECIFIED;
}
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType 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.SnomedRefSetType in project snow-owl by b2ihealthcare.
the class MapTypeRefSetUpdateRequest method execute.
@Override
public Boolean execute(TransactionContext context) {
// fail fast if refset identifier concept does not exist
SnomedConceptDocument conceptDocument = context.lookup(referenceSetId, SnomedConceptDocument.class);
SnomedRefSetType refSetType = conceptDocument.getRefSetType();
if (!SnomedRefSetUtil.isMapping(refSetType)) {
throw new BadRequestException("Map target codesystem can be set only for map-type reference sets, reference set: '%s' reference set type: '%s'.", referenceSetId, refSetType);
}
Builder conceptBuilder = SnomedConceptDocument.builder(conceptDocument);
boolean changed = false;
if (conceptDocument.getMapTargetComponentType() != null) {
String currentMapTargetComponent = conceptDocument.getMapTargetComponentType();
if (!mapTargetComponent.equals(currentMapTargetComponent)) {
conceptBuilder.mapTargetComponentType(mapTargetComponent).build();
changed = true;
}
} else {
conceptBuilder.mapTargetComponentType(mapTargetComponent).build();
changed = true;
}
if (changed) {
context.update(conceptDocument, conceptBuilder.build());
}
return changed;
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType in project snow-owl by b2ihealthcare.
the class SnomedReferenceSetRestService method getRefSetTypes.
private Collection<SnomedRefSetType> getRefSetTypes(String[] refSetTypes) {
if (refSetTypes == null) {
return null;
}
final Set<String> unresolvedRefSetTypes = Sets.newTreeSet();
final Set<SnomedRefSetType> resolvedRefSetTypes = newHashSetWithExpectedSize(refSetTypes.length);
for (String refSetTypeString : refSetTypes) {
final SnomedRefSetType refSetType = SnomedRefSetType.get(refSetTypeString.toUpperCase());
if (refSetType != null) {
resolvedRefSetTypes.add(refSetType);
} else {
unresolvedRefSetTypes.add(refSetTypeString);
}
}
if (!unresolvedRefSetTypes.isEmpty()) {
throw new BadRequestException("Unknown reference set types: '%s'", unresolvedRefSetTypes).withDeveloperMessage("Available reference set types are: " + SnomedRefSetType.VALUES);
}
return resolvedRefSetTypes;
}
Aggregations