use of com.b2international.snowowl.core.terminology.ComponentCategory in project snow-owl by b2ihealthcare.
the class ReservationImplTest method whenReservingRangeOfIDs_ThenItShouldConflictWithAllIDsInThatRangeIncludingBoundaries.
@Test
public void whenReservingRangeOfIDs_ThenItShouldConflictWithAllIDsInThatRangeIncludingBoundaries() throws Exception {
final Index store = Indexes.createIndex(UUID.randomUUID().toString(), new ObjectMapper(), new Mappings(SctId.class));
store.admin().create();
final ISnomedIdentifierService identifierService = new DefaultSnomedIdentifierService(store, new ItemIdGenerationStrategy() {
int counter = 200;
@Override
public Set<String> generateItemIds(String namespace, ComponentCategory category, int quantity, int attempt) {
return IntStream.range(counter, counter + quantity).mapToObj(String::valueOf).collect(Collectors.toSet());
}
}, new SnomedIdentifierReservationServiceImpl(), new SnomedIdentifierConfiguration());
final Set<ComponentCategory> components = Collections.singleton(ComponentCategory.CONCEPT);
final Reservation range = Reservations.range(200, 300, "", components);
final Set<String> componentIds = identifierService.generate(null, ComponentCategory.CONCEPT, 300 - 200 + 1);
for (String id : componentIds) {
final SnomedIdentifier identifier = SnomedIdentifiers.create(id);
assertTrue(range.includes(identifier));
}
store.admin().delete();
}
use of com.b2international.snowowl.core.terminology.ComponentCategory in project snow-owl by b2ihealthcare.
the class SnomedValidationIssueDetailExtension method extendIssueDetails.
private void extendIssueDetails(BranchContext context, Collection<ValidationIssue> issues) {
final RevisionSearcher searcher = context.service(RevisionSearcher.class);
final Multimap<String, ValidationIssue> issuesByComponentId = Multimaps.index(issues, issue -> issue.getAffectedComponent().getComponentId());
final Multimap<ComponentCategory, String> issueComponentIdsByComponentCategory = HashMultimap.create();
issues.stream().forEach(issue -> {
final ComponentCategory componentCategory = getComponentCategory(issue.getAffectedComponent().getComponentType());
issueComponentIdsByComponentCategory.put(componentCategory, issue.getAffectedComponent().getComponentId());
});
final Multimap<String, String> issueIdsByConceptIds = HashMultimap.create();
final Set<String> alreadyFetchedConceptIds = Sets.newHashSet();
for (ComponentCategory category : issueComponentIdsByComponentCategory.keySet()) {
final Query<String[]> query = buildQuery(category, issueComponentIdsByComponentCategory.get(category));
query.stream(searcher).forEachOrdered(hits -> {
for (String[] hit : hits) {
String id = hit[0];
String status = hit[1];
String moduleId = hit[2];
issuesByComponentId.get(id).forEach(validationIssue -> {
validationIssue.setDetails(COMPONENT_STATUS, status);
validationIssue.setDetails(COMPONENT_MODULE_ID, moduleId);
if (CONCEPT == category) {
validationIssue.setDetails(CONCEPT_STATUS, status);
validationIssue.setDetails(SnomedDocument.Fields.EFFECTIVE_TIME, Long.parseLong(hit[3]));
alreadyFetchedConceptIds.add(id);
} else if (DESCRIPTION == category || RELATIONSHIP == category || SET_MEMBER == category) {
validationIssue.setDetails(SnomedDocument.Fields.EFFECTIVE_TIME, Long.parseLong(hit[3]));
final String containerConceptId = hit[4];
if (!Strings.isNullOrEmpty(containerConceptId) && (!issueIdsByConceptIds.containsKey(containerConceptId) || !alreadyFetchedConceptIds.contains(containerConceptId))) {
issueIdsByConceptIds.put(containerConceptId, id);
}
// in case of description just add the already fetched term as label to the issue, concepts and relationship will get their
if (DESCRIPTION == category) {
validationIssue.setAffectedComponentLabels(Collections.singletonList(hit[5]));
}
}
});
}
});
}
if (!issueIdsByConceptIds.isEmpty()) {
final Query<String[]> conceptStatusQuery = Query.select(String[].class).from(SnomedConceptDocument.class).fields(SnomedConceptDocument.Fields.ID, SnomedConceptDocument.Fields.ACTIVE).where(SnomedConceptDocument.Expressions.ids(issueIdsByConceptIds.keySet())).limit(SCROLL_SIZE).build();
conceptStatusQuery.stream(searcher).flatMap(Hits::stream).forEachOrdered(hit -> {
Collection<String> issueIds = issueIdsByConceptIds.get(hit[0]);
issueIds.stream().forEach(id -> {
issuesByComponentId.get(id).forEach(validationIssue -> validationIssue.setDetails(CONCEPT_STATUS, hit[1]));
});
});
}
}
use of com.b2international.snowowl.core.terminology.ComponentCategory in project snow-owl by b2ihealthcare.
the class SnomedConceptSearchRequest method prepareQuery.
@Override
protected Expression prepareQuery(BranchContext context) {
ExpressionBuilder queryBuilder = Expressions.builder();
addActiveClause(queryBuilder);
addReleasedClause(queryBuilder);
addIdFilter(queryBuilder, RevisionDocument.Expressions::ids);
addEclFilter(context, queryBuilder, SnomedSearchRequest.OptionKey.MODULE, SnomedDocument.Expressions::modules);
addEclFilter(context, queryBuilder, OptionKey.DEFINITION_STATUS, SnomedConceptDocument.Expressions::definitionStatusIds);
addNamespaceFilter(queryBuilder);
addNamespaceConceptIdFilter(context, queryBuilder);
addEffectiveTimeClause(queryBuilder);
addActiveMemberOfClause(context, queryBuilder);
addMemberOfClause(context, queryBuilder);
addFilter(queryBuilder, OptionKey.PARENT, String.class, SnomedConceptDocument.Expressions::parents);
addFilter(queryBuilder, OptionKey.STATED_PARENT, String.class, SnomedConceptDocument.Expressions::statedParents);
if (containsKey(OptionKey.ANCESTOR)) {
final Collection<String> ancestorIds = getCollection(OptionKey.ANCESTOR, String.class);
queryBuilder.filter(Expressions.builder().should(parents(ancestorIds)).should(ancestors(ancestorIds)).build());
}
if (containsKey(OptionKey.STATED_ANCESTOR)) {
final Collection<String> ancestorIds = getCollection(OptionKey.STATED_ANCESTOR, String.class);
queryBuilder.filter(Expressions.builder().should(statedParents(ancestorIds)).should(statedAncestors(ancestorIds)).build());
}
if (containsKey(OptionKey.ECL)) {
final String ecl = getString(OptionKey.ECL);
Expression eclExpression = EclExpression.of(ecl, Trees.INFERRED_FORM).resolveToExpression(context).getSync(3, TimeUnit.MINUTES);
if (eclExpression.isMatchNone()) {
throw new NoResultException();
} else if (!eclExpression.isMatchAll()) {
queryBuilder.filter(eclExpression);
}
}
if (containsKey(OptionKey.STATED_ECL)) {
final String ecl = getString(OptionKey.STATED_ECL);
Expression statedEclExpression = EclExpression.of(ecl, Trees.STATED_FORM).resolveToExpression(context).getSync(3, TimeUnit.MINUTES);
if (statedEclExpression.isMatchNone()) {
throw new NoResultException();
} else if (!statedEclExpression.isMatchAll()) {
queryBuilder.filter(statedEclExpression);
}
}
Expression searchProfileQuery = null;
final Expression queryExpression;
if (containsKey(OptionKey.SEMANTIC_TAG)) {
queryBuilder.filter(SnomedConceptDocument.Expressions.semanticTags(getCollection(OptionKey.SEMANTIC_TAG, String.class)));
}
if (containsKey(OptionKey.TERM)) {
final ExpressionBuilder bq = Expressions.builder();
// nest current query
bq.filter(queryBuilder.build());
queryBuilder = bq;
final TermFilter termFilter = containsKey(OptionKey.TERM) ? get(OptionKey.TERM, TermFilter.class) : null;
final Map<String, Float> conceptScoreMap = executeDescriptionSearch(context, termFilter);
if (termFilter != null) {
try {
final ComponentCategory category = SnomedIdentifiers.getComponentCategory(termFilter.getTerm());
if (category == ComponentCategory.CONCEPT) {
conceptScoreMap.put(termFilter.getTerm(), Float.MAX_VALUE);
}
} catch (IllegalArgumentException e) {
// ignored
}
}
if (conceptScoreMap.isEmpty()) {
throw new NoResultException();
}
queryBuilder.filter(RevisionDocument.Expressions.ids(conceptScoreMap.keySet()));
final Expression q = addSearchProfile(searchProfileQuery, queryBuilder.build());
queryExpression = Expressions.scriptScore(q, "doiFactor", Map.of("termScores", conceptScoreMap, "useDoi", containsKey(OptionKey.USE_DOI), "minDoi", MIN_DOI_VALUE, "maxDoi", MAX_DOI_VALUE));
} else if (containsKey(OptionKey.USE_DOI)) {
final Expression q = addSearchProfile(searchProfileQuery, queryBuilder.build());
queryExpression = Expressions.scriptScore(q, "doi");
} else {
queryExpression = addSearchProfile(searchProfileQuery, queryBuilder.build());
}
return queryExpression;
}
use of com.b2international.snowowl.core.terminology.ComponentCategory in project snow-owl by b2ihealthcare.
the class IdRequest method collectComponentCreateRequests.
private static void collectComponentCreateRequests(Request<?, ?> request, ImmutableMultimap.Builder<ComponentCategory, SnomedComponentCreateRequest> resultBuilder) {
if (request instanceof DelegatingRequest) {
collectComponentCreateRequests(((DelegatingRequest<?, ?, ?>) request).next(), resultBuilder);
} else if (request instanceof TransactionalRequest) {
collectComponentCreateRequests(((TransactionalRequest) request).getNext(), resultBuilder);
} else if (request instanceof BaseSnomedComponentCreateRequest) {
final BaseSnomedComponentCreateRequest createRequest = (BaseSnomedComponentCreateRequest) request;
for (SnomedCoreComponentCreateRequest nestedRequest : Iterables.filter(createRequest.getNestedRequests(), SnomedCoreComponentCreateRequest.class)) {
ComponentCategory category = getComponentCategory(nestedRequest);
resultBuilder.put(category, (BaseSnomedComponentCreateRequest) nestedRequest);
// XXX: we could recurse here, but only concept creation requests have actual nested requests at the moment
}
} else if (request instanceof SnomedRefSetMemberCreateRequest) {
final SnomedRefSetMemberCreateRequest createRequest = (SnomedRefSetMemberCreateRequest) request;
final ComponentCategory category = getComponentCategory(createRequest);
resultBuilder.put(category, createRequest);
} else if (request instanceof BulkRequest) {
final BulkRequest<?> bulkRequest = (BulkRequest<?>) request;
for (Request<?, ?> bulkRequestItem : bulkRequest.getRequests()) {
collectComponentCreateRequests(bulkRequestItem, resultBuilder);
}
}
}
use of com.b2international.snowowl.core.terminology.ComponentCategory in project snow-owl by b2ihealthcare.
the class SnomedReferenceSetMemberConverter method expandTargetComponent.
private void expandTargetComponent(List<SnomedReferenceSetMember> results) {
if (expand().containsKey(SnomedReferenceSetMember.Expand.TARGET_COMPONENT)) {
final Options expandOptions = expand().get(SnomedReferenceSetMember.Expand.TARGET_COMPONENT, Options.class);
final Multimap<String, SnomedReferenceSetMember> membersByTargetComponent = HashMultimap.create();
for (SnomedReferenceSetMember member : results) {
final Map<String, Object> props = member.getProperties();
if (props.containsKey(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID)) {
membersByTargetComponent.put(((String) props.get(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID)), member);
}
}
final Multimap<ComponentCategory, String> targetComponentIdsByCategory = Multimaps.index(membersByTargetComponent.keySet(), new Function<String, ComponentCategory>() {
@Override
public ComponentCategory apply(String id) {
return SnomedIdentifiers.getComponentCategory(id);
}
});
for (ComponentCategory category : targetComponentIdsByCategory.keySet()) {
final Collection<String> targetComponentIds = targetComponentIdsByCategory.get(category);
final Map<String, ? extends SnomedCoreComponent> componentsById = Maps.uniqueIndex(getComponents(category, targetComponentIds, expandOptions.get("expand", Options.class)), IComponent::getId);
for (String targetComponentId : targetComponentIds) {
final SnomedCoreComponent targetComponent = componentsById.get(targetComponentId);
if (targetComponent != null) {
for (SnomedReferenceSetMember member : membersByTargetComponent.get(targetComponentId)) {
final Map<String, Object> newProps = newHashMap(member.getProperties());
newProps.put(SnomedReferenceSetMember.Expand.TARGET_COMPONENT, targetComponent);
((SnomedReferenceSetMember) member).setProperties(newProps);
}
}
}
}
}
}
Aggregations