Search in sources :

Example 86 with SnomedConcept

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

the class SnomedDescriptionConverter method toResource.

@Override
protected SnomedDescription toResource(final SnomedDescriptionIndexEntry input) {
    final SnomedDescription result = new SnomedDescription();
    result.setAcceptabilityMap(input.getAcceptabilityMap());
    result.setActive(input.isActive());
    result.setCaseSignificanceId(input.getCaseSignificanceId());
    result.setConceptId(input.getConceptId());
    result.setEffectiveTime(toEffectiveTime(input.getEffectiveTime()));
    result.setId(input.getId());
    result.setLanguageCode(input.getLanguageCode());
    result.setModuleId(input.getModuleId());
    result.setIconId(input.getIconId());
    result.setReleased(input.isReleased());
    result.setTerm(input.getTerm());
    result.setSemanticTag(input.getSemanticTag());
    result.setTypeId(input.getTypeId());
    result.setType(new SnomedConcept(input.getTypeId()));
    result.setScore(input.getScore());
    if (input.getMemberOf() != null) {
        result.setMemberOf(ImmutableSortedSet.copyOf(input.getMemberOf()));
    }
    if (input.getActiveMemberOf() != null) {
        result.setActiveMemberOf(ImmutableSortedSet.copyOf(input.getActiveMemberOf()));
    }
    return result;
}
Also used : SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Example 87 with SnomedConcept

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

the class EquivalentConceptSetConverter method toResource.

@Override
protected EquivalentConceptSet toResource(final EquivalentConceptSetDocument entry) {
    final EquivalentConceptSet resource = new EquivalentConceptSet();
    resource.setClassificationId(entry.getClassificationId());
    resource.setUnsatisfiable(entry.isUnsatisfiable());
    final List<SnomedConcept> items = newArrayList();
    for (final LongIterator itr = entry.getConceptIds().iterator(); itr.hasNext(); ) /* empty */
    {
        items.add(new SnomedConcept(Long.toString(itr.next())));
    }
    final SnomedConcepts equivalentConcepts = new SnomedConcepts(items, null, items.size(), items.size());
    resource.setEquivalentConcepts(equivalentConcepts);
    return resource;
}
Also used : SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) EquivalentConceptSet(com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) LongIterator(com.b2international.collections.longs.LongIterator)

Example 88 with SnomedConcept

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

the class SnomedFhirCodeSystemLookupConverter method expandProperties.

@Override
public List<Property> expandProperties(ServiceProvider context, CodeSystem codeSystem, Concept concept, LookupRequest lookupRequest) {
    SnomedConcept snomedConcept = concept.getInternalConceptAs();
    List<Property> properties = new ArrayList<>();
    // add basic SNOMED properties
    if (lookupRequest.isPropertyRequested(CoreSnomedConceptProperties.INACTIVE)) {
        properties.add(CoreSnomedConceptProperties.INACTIVE.propertyOf(!snomedConcept.isActive()));
    }
    if (lookupRequest.isPropertyRequested(CoreSnomedConceptProperties.MODULE_ID)) {
        properties.add(CoreSnomedConceptProperties.MODULE_ID.propertyOf(snomedConcept.getModuleId()));
    }
    if (lookupRequest.isPropertyRequested(CoreSnomedConceptProperties.SUFFICIENTLY_DEFINED)) {
        properties.add(CoreSnomedConceptProperties.SUFFICIENTLY_DEFINED.propertyOf(!snomedConcept.isPrimitive()));
    }
    if (lookupRequest.isPropertyRequested(CoreSnomedConceptProperties.EFFECTIVE_TIME)) {
        properties.add(CoreSnomedConceptProperties.EFFECTIVE_TIME.propertyOf(EffectiveTimes.format(snomedConcept.getEffectiveTime(), DateFormats.SHORT)));
    }
    // Optionally requested properties
    boolean requestedChild = lookupRequest.containsProperty(CommonConceptProperties.CHILD.getCode());
    boolean requestedParent = lookupRequest.containsProperty(CommonConceptProperties.PARENT.getCode());
    if (requestedChild && snomedConcept.getDescendants() != null) {
        for (SnomedConcept child : snomedConcept.getDescendants()) {
            properties.add(CommonConceptProperties.CHILD.propertyOf(child.getId(), SnomedDisplayTermType.PT.getLabel(child)));
        }
    }
    if (requestedParent && snomedConcept.getAncestors() != null) {
        for (SnomedConcept parent : snomedConcept.getAncestors()) {
            properties.add(CommonConceptProperties.PARENT.propertyOf(parent.getId(), SnomedDisplayTermType.PT.getLabel(parent)));
        }
    }
    // Relationship Properties
    Set<String> relationshipTypeIds = lookupRequest.getPropertyCodes().stream().map(p -> {
        if (p.startsWith(SnomedTerminologyComponentConstants.SNOMED_URI_BASE)) {
            // URI prefixed properties
            return p.substring(p.lastIndexOf('/') + 1, p.length());
        } else {
            // use as is, so users won't need to define full URI for each SNOMED CT property, ID is enough
            return p;
        }
    }).filter(// only SNOMED CT Concept IDs
    SnomedIdentifiers::isConceptIdentifier).collect(Collectors.toSet());
    if (!relationshipTypeIds.isEmpty()) {
        SnomedRequests.prepareSearchRelationship().all().filterByActive(true).filterByCharacteristicType(Concepts.INFERRED_RELATIONSHIP).filterBySource(concept.getId()).filterByTypes(relationshipTypeIds).build(codeSystem.getResourceURI()).getRequest().execute(context).forEach(r -> {
            Property.Builder propertyBuilder = Property.builder().code(r.getTypeId());
            if (r.hasValue()) {
                RelationshipValue value = r.getValueAsObject();
                value.map(i -> propertyBuilder.valueInteger(i), d -> propertyBuilder.valueDecimal(d.doubleValue()), s -> propertyBuilder.valueString(s));
            } else {
                propertyBuilder.valueCode(r.getDestinationId());
            }
            properties.add(propertyBuilder.build());
        });
    }
    if (properties.isEmpty()) {
        return null;
    } else {
        return properties;
    }
}
Also used : ArrayList(java.util.ArrayList) RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Property(com.b2international.snowowl.fhir.core.model.codesystem.Property)

Example 89 with SnomedConcept

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

the class ConceptChangeConverter method expand.

@Override
public void expand(final List<ConceptChange> results) {
    if (!expand().containsKey(ConceptChange.Expand.CONCEPT)) {
        return;
    }
    /*
		 * Depending on the concept change search request, we might need to issue
		 * SNOMED CT searches against multiple branches; find out which ones we have.
		 */
    final Multimap<String, ConceptChange> itemsByBranch = getItemsByBranch(results);
    // Check if we only need to load inferred concepts in their entirety
    final Options expandOptions = expand().getOptions(ConceptChange.Expand.CONCEPT);
    // pt() and fsn() are the only useful options here
    final Options conceptExpandOptions = expandOptions.getOptions("expand");
    conceptExpandOptions.keySet().retainAll(CONCEPT_EXPAND_OPTIONS);
    for (final String branch : itemsByBranch.keySet()) {
        final Collection<ConceptChange> itemsForCurrentBranch = itemsByBranch.get(branch);
        final Set<String> conceptIds = itemsForCurrentBranch.stream().map(c -> c.getConcept().getOriginConceptId()).collect(Collectors.toSet());
        final Request<BranchContext, SnomedConcepts> conceptSearchRequest = SnomedRequests.prepareSearchConcept().filterByIds(conceptIds).setLimit(conceptIds.size()).setExpand(conceptExpandOptions).setLocales(locales()).build();
        final SnomedConcepts concepts = new BranchRequest<>(branch, new RevisionIndexReadRequest<>(conceptSearchRequest)).execute(context());
        final Map<String, SnomedConcept> conceptsById = Maps.uniqueIndex(concepts, SnomedConcept::getId);
        for (final ConceptChange item : itemsForCurrentBranch) {
            final ReasonerConcept reasonerConcept = item.getConcept();
            final String conceptId = reasonerConcept.getOriginConceptId();
            final SnomedConcept expandedConcept = conceptsById.get(conceptId);
            reasonerConcept.setDefinitionStatusId(expandedConcept.getDefinitionStatusId());
            reasonerConcept.setPt(expandedConcept.getPt());
            reasonerConcept.setFsn(expandedConcept.getFsn());
        // reasonerConcept.setReleased(...) is already set
        }
    }
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) BranchRequest(com.b2international.snowowl.core.request.BranchRequest) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) ImmutableSet(com.google.common.collect.ImmutableSet) ClassificationRequests(com.b2international.snowowl.snomed.reasoner.request.ClassificationRequests) Collection(java.util.Collection) Request(com.b2international.snowowl.core.events.Request) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) com.b2international.snowowl.snomed.reasoner.domain(com.b2international.snowowl.snomed.reasoner.domain) Set(java.util.Set) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) RevisionIndexReadRequest(com.b2international.snowowl.core.request.RevisionIndexReadRequest) Multimaps(com.google.common.collect.Multimaps) List(java.util.List) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) Map(java.util.Map) ConceptChangeDocument(com.b2international.snowowl.snomed.reasoner.index.ConceptChangeDocument) BranchContext(com.b2international.snowowl.core.domain.BranchContext) BaseResourceConverter(com.b2international.snowowl.core.request.BaseResourceConverter) Options(com.b2international.commons.options.Options) RevisionIndexReadRequest(com.b2international.snowowl.core.request.RevisionIndexReadRequest) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) BranchContext(com.b2international.snowowl.core.domain.BranchContext)

Example 90 with SnomedConcept

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

the class Rf2MRCMAttributeDomainRefSetContentType method resolve.

@Override
public void resolve(SnomedReferenceSetMember component, String[] values) {
    component.setType(SnomedRefSetType.MRCM_ATTRIBUTE_DOMAIN);
    component.setRefsetId(values[4]);
    // XXX actual type is not relevant here
    component.setReferencedComponent(new SnomedConcept(values[5]));
    component.setProperties(ImmutableMap.<String, Object>builder().put(FIELD_MRCM_DOMAIN_ID, values[6]).put(FIELD_MRCM_GROUPED, BooleanUtils.valueOf(values[7])).put(FIELD_MRCM_ATTRIBUTE_CARDINALITY, values[8]).put(FIELD_MRCM_ATTRIBUTE_IN_GROUP_CARDINALITY, values[9]).put(FIELD_MRCM_RULE_STRENGTH_ID, values[10]).put(FIELD_MRCM_CONTENT_TYPE_ID, values[11]).build());
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Aggregations

SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)90 Test (org.junit.Test)42 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)17 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)15 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)15 LocalDate (java.time.LocalDate)15 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)12 SnomedConcepts (com.b2international.snowowl.snomed.core.domain.SnomedConcepts)12 Options (com.b2international.commons.options.Options)10 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)10 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)9 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)8 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)8 CodeSystemRestRequests.createCodeSystem (com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests.createCodeSystem)8 List (java.util.List)8 Map (java.util.Map)8 Collectors (java.util.stream.Collectors)8 Json (com.b2international.commons.json.Json)7 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)7 SnomedRequests (com.b2international.snowowl.snomed.datastore.request.SnomedRequests)5