Search in sources :

Example 6 with SnomedDescription

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

the class SnomedExtensionUpgradeTest method upgrade09DonatedConceptAndDescriptions.

@Test
public void upgrade09DonatedConceptAndDescriptions() {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    String extensionFsnTerm = "FSN of concept";
    String extensionPtTerm = "PT of concept";
    String extensionSynonymTerm = "Synonym of extension concept";
    Json fsnRequestBody = Json.object("typeId", Concepts.FULLY_SPECIFIED_NAME, "term", extensionFsnTerm, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.UK_PREFERRED_MAP);
    Json ptRequestBody = Json.object("typeId", Concepts.SYNONYM, "term", extensionPtTerm, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.UK_PREFERRED_MAP);
    Json synonymRequestBody = Json.object("typeId", Concepts.SYNONYM, "term", extensionSynonymTerm, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.UK_ACCEPTABLE_MAP);
    Json statedIsa = Json.object("typeId", Concepts.IS_A, "destinationId", Concepts.ROOT_CONCEPT, "characteristicTypeId", Concepts.STATED_RELATIONSHIP);
    Json inferredIsa = Json.object("typeId", Concepts.IS_A, "destinationId", Concepts.ROOT_CONCEPT, "characteristicTypeId", Concepts.INFERRED_RELATIONSHIP);
    Json extensionConceptRequestBody = Json.object("namespaceId", Concepts.B2I_NAMESPACE, "moduleId", extensionModuleId, "descriptions", Json.array(fsnRequestBody, ptRequestBody, synonymRequestBody), "relationships", Json.array(statedIsa, inferredIsa));
    String extensionConceptId = createConcept(extension.getResourceURI(), extensionConceptRequestBody);
    // create new extension version
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    SnomedConcept extensionConcept = getConcept(extension.getResourceURI(), extensionConceptId, "descriptions()", "relationships()");
    String extensionFsnId = getFirstMatchingDescription(extensionConcept, extensionFsnTerm).getId();
    String extensionPtId = getFirstMatchingDescription(extensionConcept, extensionPtTerm).getId();
    String extensionSynonymId = getFirstMatchingDescription(extensionConcept, extensionSynonymTerm).getId();
    String extensionStatedIsaId = getFirstRelationshipId(extensionConcept, Concepts.STATED_RELATIONSHIP);
    String extensionInferredIsaId = getFirstRelationshipId(extensionConcept, Concepts.INFERRED_RELATIONSHIP);
    // simulate donation via concept create and versioning
    // create INT concept with same ID and with same description and relationship IDs
    String intConceptId = createConcept(SnomedContentRule.SNOMEDCT, Json.object("id", extensionConceptId, "moduleId", Concepts.MODULE_SCT_CORE, "descriptions", Json.array(fsnRequestBody.with("id", extensionFsnId), ptRequestBody.with("id", extensionPtId)), "relationships", Json.array(statedIsa, inferredIsa)));
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveTime).statusCode(201);
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), CodeSystem.uri(SNOMEDCT, effectiveTime.toString()));
    SnomedConcept donatedConceptInExtension = getConcept(upgradeCodeSystem.getResourceURI(), intConceptId, "descriptions()", "relationships()");
    // validate components of donated concept on extension branch
    // same ID, different module
    assertNotEquals(donatedConceptInExtension.getModuleId(), extensionConcept.getModuleId());
    SnomedDescription donatedFsn = getFirstMatchingDescription(donatedConceptInExtension, extensionFsnTerm);
    assertEquals(extensionFsnId, donatedFsn.getId());
    assertEquals(Concepts.MODULE_SCT_CORE, donatedFsn.getModuleId());
    SnomedDescription donatedPt = getFirstMatchingDescription(donatedConceptInExtension, extensionPtTerm);
    assertEquals(extensionPtId, donatedPt.getId());
    assertEquals(Concepts.MODULE_SCT_CORE, donatedPt.getModuleId());
    Set<String> descriptionIds = donatedConceptInExtension.getDescriptions().getItems().stream().map(SnomedDescription::getId).collect(Collectors.toSet());
    assertThat(descriptionIds).hasSize(3).contains(extensionSynonymId);
    Set<String> relationshipIds = donatedConceptInExtension.getRelationships().getItems().stream().map(SnomedRelationship::getId).collect(Collectors.toSet());
    assertThat(relationshipIds).hasSize(4).contains(extensionStatedIsaId, extensionInferredIsaId);
}
Also used : SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) Json(com.b2international.commons.json.Json) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 7 with SnomedDescription

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

the class SnomedValidationIssueDetailExtension method getAffectedComponentLabels.

@SuppressWarnings("unchecked")
private Map<String, String> getAffectedComponentLabels(BranchContext context, Map<String, Object> ruleParameters, final Set<String> conceptIds) {
    boolean useFsn = ruleParameters.containsKey(ValidationConfiguration.USE_FSN) ? (boolean) ruleParameters.get(ValidationConfiguration.USE_FSN) : false;
    Set<String> types;
    if (useFsn) {
        types = Set.of(Concepts.FULLY_SPECIFIED_NAME);
    } else {
        types = SnomedRequests.prepareGetSynonyms().build().execute(context).stream().map(SnomedConcept::getId).collect(Collectors.toSet());
    }
    List<ExtendedLocale> locales;
    if (ruleParameters.containsKey(ValidationConfiguration.LOCALES)) {
        locales = (List<ExtendedLocale>) ruleParameters.get(ValidationConfiguration.LOCALES);
    } else {
        locales = List.of();
    }
    final Map<String, String> affectedComponentLabelsByConcept = new HashMap<>();
    for (List<String> partition : Iterables.partition(conceptIds, SCROLL_SIZE)) {
        SnomedDescriptions descriptions = SnomedRequests.prepareSearchDescription().all().filterByActive(true).filterByConcepts(partition).filterByType(types).build().execute(context);
        Map<String, SnomedDescription> preferredDescriptions = SnomedDescriptionUtils.indexBestPreferredByConceptId(context, descriptions, locales);
        preferredDescriptions.forEach((id, description) -> affectedComponentLabelsByConcept.put(id, description.getTerm()));
    }
    return affectedComponentLabelsByConcept;
}
Also used : SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedDescriptions(com.b2international.snowowl.snomed.core.domain.SnomedDescriptions) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Example 8 with SnomedDescription

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

the class SnomedFhirCodeSystemLookupConverter method expandDesignations.

@Override
public List<Designation> expandDesignations(ServiceProvider context, CodeSystem codeSystem, Concept concept, LookupRequest request, String acceptLanguage) {
    SnomedConcept snomedConcept = concept.getInternalConceptAs();
    if (request.isPropertyRequested(SupportedCodeSystemRequestProperties.DESIGNATION)) {
        List<Designation> designations = new ArrayList<>();
        for (SnomedDescription description : snomedConcept.getDescriptions()) {
            Coding coding = Coding.builder().system(codeSystem.getUrl().getUriValue()).code(description.getTypeId()).display(SnomedDisplayTermType.PT.getLabel(description.getType())).build();
            designations.add(Designation.builder().languageCode(description.getLanguageCode()).use(coding).value(description.getTerm()).build());
        }
        return designations;
    } else {
        return FhirCodeSystemLookupConverter.super.expandDesignations(context, codeSystem, concept, request, acceptLanguage);
    }
}
Also used : Designation(com.b2international.snowowl.fhir.core.model.Designation) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) ArrayList(java.util.ArrayList) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Example 9 with SnomedDescription

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

the class DescriptionChangeConverter method expand.

@Override
public void expand(final List<DescriptionChange> results) {
    if (!expand().containsKey(DescriptionChange.Expand.DESCRIPTION)) {
        return;
    }
    /*
		 * Depending on the CD member change search request, we might need to issue
		 * SNOMED CT searches against multiple branches; find out which ones we have.
		 */
    final Multimap<String, DescriptionChange> itemsByBranch = getItemsByBranch(results);
    // Check if we only need to load inferred CD members in their entirety
    final Options expandOptions = expand().getOptions(DescriptionChange.Expand.DESCRIPTION);
    final boolean inferredOnly = expandOptions.getBoolean("inferredOnly");
    final Options descriptionExpandOptions = expandOptions.getOptions("expand");
    final Options conceptOptions = descriptionExpandOptions.getOptions("concept");
    final boolean needsConcept = descriptionExpandOptions.keySet().contains("concept");
    for (final String branch : itemsByBranch.keySet()) {
        final Collection<DescriptionChange> itemsForCurrentBranch = itemsByBranch.get(branch);
        /*
			 * Expand concept on "new" descriptions via a separate search request, they will
			 * be different from the concept on the "origin" description.
			 */
        if (needsConcept) {
            final List<ReasonerDescription> blankDescriptions = itemsForCurrentBranch.stream().filter(c -> ChangeNature.NEW.equals(c.getChangeNature())).map(DescriptionChange::getDescription).collect(Collectors.toList());
            final Multimap<String, ReasonerDescription> descriptionsByConceptId = FluentIterable.from(blankDescriptions).index(ReasonerDescription::getConceptId);
            final Set<String> conceptIds = descriptionsByConceptId.keySet();
            final Request<BranchContext, SnomedConcepts> conceptSearchRequest = SnomedRequests.prepareSearchConcept().filterByIds(conceptIds).setLimit(conceptIds.size()).setExpand(conceptOptions.get("expand", Options.class)).setLocales(locales()).build();
            final SnomedConcepts concepts = new BranchRequest<>(branch, new RevisionIndexReadRequest<>(conceptSearchRequest)).execute(context());
            for (final SnomedConcept concept : concepts) {
                final String conceptId = concept.getId();
                final Collection<ReasonerDescription> descriptionsForConcept = descriptionsByConceptId.get(conceptId);
                for (final ReasonerDescription description : descriptionsForConcept) {
                    description.setConcept(concept);
                }
            }
        }
        /*
			 * Then fetch all the required descriptions. Note that the same "origin"
			 * description might be used for multiple eg. "new" counterparts.
			 */
        final Set<String> descriptionIds = itemsForCurrentBranch.stream().filter(c -> !inferredOnly || ChangeNature.NEW.equals(c.getChangeNature())).map(c -> c.getDescription().getOriginDescriptionId()).collect(Collectors.toSet());
        final Request<BranchContext, SnomedDescriptions> descriptionSearchRequest = SnomedRequests.prepareSearchDescription().filterByIds(descriptionIds).setLimit(descriptionIds.size()).setExpand(descriptionExpandOptions).setLocales(locales()).build();
        final SnomedDescriptions descriptions = new BranchRequest<>(branch, new RevisionIndexReadRequest<>(descriptionSearchRequest)).execute(context());
        final Map<String, SnomedDescription> descriptionsById = Maps.uniqueIndex(descriptions, SnomedDescription::getId);
        for (final DescriptionChange item : itemsForCurrentBranch) {
            final ReasonerDescription reasonerDescription = item.getDescription();
            final String descriptionId = reasonerDescription.getOriginDescriptionId();
            switch(item.getChangeNature()) {
                case NEW:
                    {
                        final SnomedDescription expandedDescription = descriptionsById.get(descriptionId);
                        reasonerDescription.setAcceptabilityMap(expandedDescription.getAcceptabilityMap());
                        reasonerDescription.setCaseSignificanceId(expandedDescription.getCaseSignificanceId());
                        // reasonerDescription.setConcept(...) is already set earlier (or expanded)
                        reasonerDescription.setLanguageCode(expandedDescription.getLanguageCode());
                        // reasonerMember.setReleased(...) is already set
                        reasonerDescription.setTerm(expandedDescription.getTerm());
                        reasonerDescription.setType(expandedDescription.getType());
                    }
                    break;
                case REDUNDANT:
                    if (!inferredOnly) {
                        final SnomedDescription expandedDescription = descriptionsById.get(descriptionId);
                        reasonerDescription.setAcceptabilityMap(expandedDescription.getAcceptabilityMap());
                        reasonerDescription.setCaseSignificanceId(expandedDescription.getCaseSignificanceId());
                        reasonerDescription.setConcept(expandedDescription.getConcept());
                        reasonerDescription.setLanguageCode(expandedDescription.getLanguageCode());
                        // reasonerMember.setReleased(...) is already set
                        reasonerDescription.setTerm(expandedDescription.getTerm());
                        reasonerDescription.setType(expandedDescription.getType());
                    }
                    break;
                default:
                    throw new IllegalStateException(String.format("Unexpected description change '%s' found with SCTID '%s'.", item.getChangeNature(), item.getDescription().getOriginDescriptionId()));
            }
        }
    }
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) BranchRequest(com.b2international.snowowl.core.request.BranchRequest) com.b2international.snowowl.snomed.reasoner.domain(com.b2international.snowowl.snomed.reasoner.domain) Multimap(com.google.common.collect.Multimap) Multimaps(com.google.common.collect.Multimaps) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) DescriptionChangeDocument(com.b2international.snowowl.snomed.reasoner.index.DescriptionChangeDocument) SnomedDescriptions(com.b2international.snowowl.snomed.core.domain.SnomedDescriptions) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) 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) Set(java.util.Set) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) RevisionIndexReadRequest(com.b2international.snowowl.core.request.RevisionIndexReadRequest) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) List(java.util.List) BranchContext(com.b2international.snowowl.core.domain.BranchContext) BaseResourceConverter(com.b2international.snowowl.core.request.BaseResourceConverter) Options(com.b2international.commons.options.Options) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedDescriptions(com.b2international.snowowl.snomed.core.domain.SnomedDescriptions) 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 10 with SnomedDescription

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

the class BranchCompareRequestTest method prepareBranchWithNewChanges.

private Set<ComponentIdentifier> prepareBranchWithNewChanges(String branchPath) {
    final IBranchPath branch = BranchPathUtils.createPath(branchPath);
    final String newConceptId = createNewConcept(branch);
    final SnomedConcept concept = getComponent(branch, SnomedComponentType.CONCEPT, newConceptId, "descriptions(expand(members())),relationships()").extract().as(SnomedConcept.class);
    final Set<ComponentIdentifier> newIds = newHashSet();
    newIds.add(ComponentIdentifier.of(SnomedConcept.TYPE, concept.getId()));
    for (SnomedDescription description : concept.getDescriptions()) {
        newIds.add(ComponentIdentifier.of(SnomedDescription.TYPE, description.getId()));
        for (SnomedReferenceSetMember member : description.getMembers()) {
            newIds.add(ComponentIdentifier.of(SnomedReferenceSetMember.TYPE, member.getId()));
        }
    }
    for (SnomedRelationship relationship : concept.getRelationships()) {
        newIds.add(ComponentIdentifier.of(SnomedRelationship.TYPE, relationship.getId()));
    }
    return newIds;
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) ComponentIdentifier(com.b2international.snowowl.core.ComponentIdentifier) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) IBranchPath(com.b2international.snowowl.core.api.IBranchPath)

Aggregations

SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)25 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)14 Test (org.junit.Test)8 Json (com.b2international.commons.json.Json)7 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)6 LocalDate (java.time.LocalDate)6 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)5 Options (com.b2international.commons.options.Options)4 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)4 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)4 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)4 SnomedRequests (com.b2international.snowowl.snomed.datastore.request.SnomedRequests)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)3 BranchContext (com.b2international.snowowl.core.domain.BranchContext)3 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)3 InactivationProperties (com.b2international.snowowl.snomed.core.domain.InactivationProperties)3 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)3 SnomedConceptRequestCache (com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)3