Search in sources :

Example 16 with SnomedDescription

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

the class SnomedDescriptionUtilsTest method createDescription.

@SuppressWarnings("deprecation")
private static SnomedDescription createDescription(String id, String term, Map<String, Acceptability> acceptabilityMap) {
    SnomedDescription description = new SnomedDescription(id);
    description.setTerm(term);
    description.setActive(true);
    description.setConceptId(Concepts.ROOT_CONCEPT);
    description.setAcceptabilityMap(acceptabilityMap);
    return description;
}
Also used : SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription)

Example 17 with SnomedDescription

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

the class SnomedConceptSearchRequest method executeDescriptionSearch.

private Map<String, Float> executeDescriptionSearch(BranchContext context, TermFilter termFilter) {
    final SnomedDescriptionSearchRequestBuilder requestBuilder = SnomedRequests.prepareSearchDescription().all().filterByActive(true).setFields(SnomedDescriptionIndexEntry.Fields.ID, SnomedDescriptionIndexEntry.Fields.CONCEPT_ID).sortBy(SCORE);
    if (containsKey(SnomedConceptSearchRequest.OptionKey.LANGUAGE_REFSET)) {
        List<ExtendedLocale> extendedLocales = getList(SnomedDescriptionSearchRequest.OptionKey.LANGUAGE_REFSET, ExtendedLocale.class);
        requestBuilder.filterByLanguageRefSets(SnomedDescriptionUtils.getLanguageRefSetIds(context, extendedLocales));
    }
    applyIdFilter(requestBuilder, (rb, ids) -> rb.filterByConcepts(ids));
    if (containsKey(OptionKey.DESCRIPTION_TYPE)) {
        final String type = getString(OptionKey.DESCRIPTION_TYPE);
        requestBuilder.filterByType(type);
    }
    if (termFilter != null) {
        requestBuilder.filterByTerm(termFilter);
    }
    final Collection<SnomedDescription> items = requestBuilder.build().execute(context).getItems();
    final Map<String, Float> conceptMap = newHashMap();
    for (SnomedDescription description : items) {
        if (!conceptMap.containsKey(description.getConceptId())) {
            conceptMap.put(description.getConceptId(), description.getScore());
        }
    }
    return conceptMap;
}
Also used : SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) ExtendedLocale(com.b2international.commons.http.ExtendedLocale)

Example 18 with SnomedDescription

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

the class SnomedExtensionUpgradeTest method upgrade06DonatedDescription.

@Test
public void upgrade06DonatedDescription() throws Exception {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    String descriptionTerm = "Donated synonym of root concept";
    Json extensionDescriptionRequest = Json.object("conceptId", Concepts.ROOT_CONCEPT, "namespaceId", Concepts.B2I_NAMESPACE, "moduleId", extensionModuleId, "typeId", Concepts.SYNONYM, "term", descriptionTerm, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.US_ACCEPTABLE_MAP, "caseSignificanceId", Concepts.ONLY_INITIAL_CHARACTER_CASE_INSENSITIVE, "commitComment", "Created new extension synonym");
    String extensionDescriptionId = createDescription(extension.getResourceURI(), extensionDescriptionRequest);
    // create new extension version
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    // simulate donation to SI with same ID but with slightly different properties
    Json donatedDescriptionRequest = Json.assign(extensionDescriptionRequest, Json.object("id", extensionDescriptionId, "moduleId", Concepts.MODULE_SCT_CORE, "languageCode", "en", "acceptability", SnomedApiTestConstants.UK_ACCEPTABLE_MAP, "caseSignificanceId", Concepts.ENTIRE_TERM_CASE_SENSITIVE, "commitComment", "Created new donated synonym"));
    String donatedDescriptionId = createDescription(SnomedContentRule.SNOMEDCT, donatedDescriptionRequest);
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveTime).statusCode(201);
    assertEquals(extensionDescriptionId, donatedDescriptionId);
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), CodeSystem.uri(SNOMEDCT, effectiveTime.toString()));
    SnomedDescription donatedDescriptionOnUpgrade = getDescription(upgradeCodeSystem.getResourceURI(), donatedDescriptionId);
    assertEquals(Concepts.MODULE_SCT_CORE, donatedDescriptionOnUpgrade.getModuleId());
    assertEquals(Concepts.ENTIRE_TERM_CASE_SENSITIVE, donatedDescriptionOnUpgrade.getCaseSignificanceId());
    // acceptability should come from both INT
    assertThat(donatedDescriptionOnUpgrade.getAcceptabilityMap().containsKey(Concepts.REFSET_LANGUAGE_TYPE_UK));
    assertEquals(Acceptability.ACCEPTABLE, donatedDescriptionOnUpgrade.getAcceptabilityMap().get(Concepts.REFSET_LANGUAGE_TYPE_UK));
    // and EXT should keep its acceptability values
    assertThat(donatedDescriptionOnUpgrade.getAcceptabilityMap().containsKey(Concepts.REFSET_LANGUAGE_TYPE_US));
    assertEquals(Acceptability.ACCEPTABLE, donatedDescriptionOnUpgrade.getAcceptabilityMap().get(Concepts.REFSET_LANGUAGE_TYPE_US));
}
Also used : SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) Json(com.b2international.commons.json.Json) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 19 with SnomedDescription

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

the class SnomedExtensionUpgradeTest method upgrade08WithBackAndForthDonatedConcept.

@Test
public void upgrade08WithBackAndForthDonatedConcept() {
    // create new version on INT with core module and initial char case insensitive case significance
    String descriptionTerm = "Description term";
    Json initialInternationalDescriptionRequest = Json.object("conceptId", Concepts.ROOT_CONCEPT, "moduleId", Concepts.MODULE_SCT_CORE, "typeId", Concepts.SYNONYM, "term", descriptionTerm, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.UK_ACCEPTABLE_MAP, "caseSignificanceId", Concepts.ONLY_INITIAL_CHARACTER_CASE_INSENSITIVE, "commitComment", "Created new synonym");
    String internationalDescriptionId = createDescription(SnomedContentRule.SNOMEDCT, initialInternationalDescriptionRequest);
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveTime).statusCode(201);
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(CodeSystem.uri(SNOMEDCT, effectiveTime.toString()), branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    // update international description on extension, changing module and case significance
    Json extensionDescriptionUpdateRequest = Json.object("moduleId", extensionModuleId, "caseSignificanceId", Concepts.ENTIRE_TERM_CASE_SENSITIVE, "commitComment", "Changed case significance on description");
    updateDescription(extension.getResourceURI(), internationalDescriptionId, extensionDescriptionUpdateRequest);
    SnomedDescription updatedInternationalDescription = getDescription(extension.getResourceURI(), internationalDescriptionId);
    assertEquals(true, updatedInternationalDescription.isReleased());
    assertEquals(null, updatedInternationalDescription.getEffectiveTime());
    assertEquals(extensionModuleId, updatedInternationalDescription.getModuleId());
    assertEquals(Concepts.ENTIRE_TERM_CASE_SENSITIVE, updatedInternationalDescription.getCaseSignificanceId());
    // create new extension version
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    // donate extension changes to international via RF2 update simulation
    Json descriptionDonateRequest = Json.object("caseSignificanceId", Concepts.ENTIRE_TERM_CASE_SENSITIVE, "commitComment", "Changed case significance on description");
    updateDescription(SnomedContentRule.SNOMEDCT, internationalDescriptionId, descriptionDonateRequest);
    LocalDate donationEffectiveDate = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, donationEffectiveDate).statusCode(201);
    // upgrade extension to new INT version with donations
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), CodeSystem.uri(SNOMEDCT, donationEffectiveDate.toString()));
    SnomedDescription updatedInternationalDescriptionOnUpgrade = getDescription(upgradeCodeSystem.getResourceURI(), internationalDescriptionId);
    assertEquals(true, updatedInternationalDescriptionOnUpgrade.isReleased());
    assertEquals(donationEffectiveDate, updatedInternationalDescriptionOnUpgrade.getEffectiveTime());
    assertEquals(Concepts.MODULE_SCT_CORE, updatedInternationalDescriptionOnUpgrade.getModuleId());
    assertEquals(Concepts.ENTIRE_TERM_CASE_SENSITIVE, updatedInternationalDescriptionOnUpgrade.getCaseSignificanceId());
}
Also used : SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) Json(com.b2international.commons.json.Json) LocalDate(java.time.LocalDate) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) Test(org.junit.Test)

Example 20 with SnomedDescription

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

the class SnomedExtensionUpgradeTest method upgrade10DonatedConceptAndDescriptionsAndRelationships.

@Test
public void upgrade10DonatedConceptAndDescriptionsAndRelationships() {
    // 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.with("id", extensionStatedIsaId), inferredIsa.with("id", extensionInferredIsaId))));
    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
    assertEquals(donatedConceptInExtension.getId(), extensionConcept.getId());
    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(2).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)

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