Search in sources :

Example 36 with SnomedConcept

use of com.b2international.snowowl.snomed.core.domain.SnomedConcept 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 37 with SnomedConcept

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

the class SnomedExtensionUpgradeTest method upgrade05DonatedConcept.

@Test
public void upgrade05DonatedConcept() {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    String extensionConceptId = createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId).with("namespaceId", Concepts.B2I_NAMESPACE));
    // put additional relationships and acceptable synonym on the concept
    String additionalSynonymId = createDescription(extension.getResourceURI(), createDescriptionRequestBody(extensionConceptId).with("moduleId", extensionModuleId).with("namespaceId", Concepts.B2I_NAMESPACE).with("term", "Additional Synonym"));
    String additionalRelationshipId = createRelationship(extension.getResourceURI(), createRelationshipRequestBody(extensionConceptId, Concepts.FINDING_SITE, Concepts.ROOT_CONCEPT).with("moduleId", extensionModuleId).with(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID, Concepts.ADDITIONAL_RELATIONSHIP).with("namespaceId", Concepts.B2I_NAMESPACE));
    SnomedConcept extensionConcept = getConcept(extension.getResourceURI(), extensionConceptId, "descriptions()", "relationships()", "fsn()", "pt()");
    // create new extension version
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    // simulate donation to SI and new version import
    String donatedConceptId = createConcept(SnomedContentRule.SNOMEDCT, createConceptRequestBody(Concepts.ROOT_CONCEPT, Concepts.MODULE_SCT_CORE).with("id", extensionConceptId));
    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 donatedConceptAfterUpgrade = getConcept(upgradeCodeSystem.getResourceURI(), donatedConceptId, "descriptions()", "relationships()", "fsn()", "pt()");
    // validate components of donated concept on extension branch
    assertEquals(extensionConcept.getId(), donatedConceptAfterUpgrade.getId());
    assertNotEquals(extensionConcept.getModuleId(), donatedConceptAfterUpgrade.getModuleId());
    // additional not donated extension content should remain on the concept
    assertTrue(donatedConceptAfterUpgrade.getDescriptions().stream().filter(desc -> additionalSynonymId.equals(desc.getId())).findFirst().isPresent());
    assertTrue(donatedConceptAfterUpgrade.getRelationships().stream().filter(rel -> additionalRelationshipId.equals(rel.getId())).findFirst().isPresent());
}
Also used : CodeSystemVersionRestRequests.getNextAvailableEffectiveDate(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.getNextAvailableEffectiveDate) MethodSorters(org.junit.runners.MethodSorters) BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) CodeSystemVersionRestRequests.createVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.createVersion) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Json(com.b2international.commons.json.Json) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RestExtensions.lastPathSegment(com.b2international.snowowl.test.commons.rest.RestExtensions.lastPathSegment) SnomedRestFixtures(com.b2international.snowowl.snomed.core.rest.SnomedRestFixtures) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) SnomedComponentType(com.b2international.snowowl.snomed.core.rest.SnomedComponentType) SnomedComponentRestRequests.getComponent(com.b2international.snowowl.snomed.core.rest.SnomedComponentRestRequests.getComponent) SnomedContentRule(com.b2international.snowowl.test.commons.SnomedContentRule) Map(java.util.Map) SnomedMergingRestRequests.createMerge(com.b2international.snowowl.snomed.core.rest.SnomedMergingRestRequests.createMerge) Before(org.junit.Before) ResourceURI(com.b2international.snowowl.core.ResourceURI) BranchState(com.b2international.index.revision.RevisionBranch.BranchState) BranchPathUtils(com.b2international.snowowl.core.branch.BranchPathUtils) SnomedApiTestConstants(com.b2international.snowowl.snomed.core.rest.SnomedApiTestConstants) CodeSystemRestRequests(com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) CodeSystemVersionRestRequests.getLatestVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.getLatestVersion) Set(java.util.Set) Merge(com.b2international.snowowl.core.merge.Merge) SnomedMergingRestRequests.waitForMergeJob(com.b2international.snowowl.snomed.core.rest.SnomedMergingRestRequests.waitForMergeJob) Test(org.junit.Test) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) Collectors(java.util.stream.Collectors) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) TimeUnit(java.util.concurrent.TimeUnit) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) LocalDate(java.time.LocalDate) IComponent(com.b2international.snowowl.core.domain.IComponent) CodeSystems(com.b2international.snowowl.core.codesystem.CodeSystems) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) ApplicationContext(com.b2international.snowowl.core.ApplicationContext) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 38 with SnomedConcept

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

the class SnomedExtensionUpgradeTest method upgrade13SemanticallySameChangesAppliedTwiceBeforeUpgradeAndAfterUpgrade.

@Test
public void upgrade13SemanticallySameChangesAppliedTwiceBeforeUpgradeAndAfterUpgrade() throws Exception {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    // create new extension version with one new concept and one member on INT concept
    String moduleId = createModule(extension);
    SnomedConcept concept = searchConcepts(baseInternationalCodeSystem, Map.of("module", Concepts.MODULE_SCT_CORE, "expand", "descriptions()"), 1).stream().findFirst().get();
    String descriptionId = concept.getDescriptions().stream().findFirst().get().getId();
    // create new inactivation indicator for one of the description, pending move
    createMember(extension.getResourceURI(), Map.of("moduleId", moduleId, "refsetId", Concepts.REFSET_DESCRIPTION_INACTIVITY_INDICATOR, "referencedComponentId", descriptionId, "valueId", Concepts.PENDING_MOVE));
    // version extension
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    // add another member on INT representing a change in INT and allow extension to upgrade
    createMember(SnomedContentRule.SNOMEDCT, Map.of("moduleId", Concepts.MODULE_SCT_CORE, "refsetId", Concepts.REFSET_DESCRIPTION_INACTIVITY_INDICATOR, "referencedComponentId", descriptionId, "valueId", Concepts.PENDING_MOVE));
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveTime).statusCode(201);
    ResourceURI upgradeVersion = CodeSystem.uri(SNOMEDCT, effectiveTime.toString());
    // start the upgrade
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), upgradeVersion);
    // add another extension member to the same int concept with same meaning to the original extension branch
    createMember(extension.getResourceURI(), Map.of("moduleId", moduleId, "refsetId", Concepts.REFSET_DESCRIPTION_INACTIVITY_INDICATOR, "referencedComponentId", descriptionId, "valueId", Concepts.AMBIGUOUS));
    // synchronize upgrade
    final String mergeLocation = createMerge(extension.getBranchPath(), upgradeCodeSystem.getBranchPath(), "Sync Upgrade CodeSystem", false).statusCode(202).extract().header("Location");
    waitForMergeJob(lastPathSegment(mergeLocation));
    // each component should have a single revision after successful sync
    getConcept(upgradeCodeSystem.getResourceURI(), concept.getId());
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 39 with SnomedConcept

use of com.b2international.snowowl.snomed.core.domain.SnomedConcept 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 40 with SnomedConcept

use of com.b2international.snowowl.snomed.core.domain.SnomedConcept 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)

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