Search in sources :

Example 26 with SnomedConcept

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

the class SnomedExtensionUpgradeTest method upgrade26InferredOnlyAncestorChangesBothSides.

@Test
public void upgrade26InferredOnlyAncestorChangesBothSides() throws Exception {
    // prepare extension on latest int version
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    // alphaproteobacteria
    String intConceptId = "413858005";
    // direct parent 409852006 proteobacteria receives a new inferred parent on both the int and extension branches
    String inferredIntRelationship = createRelationship(SNOMEDCT_URI, createRelationshipRequestBody("409852006", Concepts.IS_A, Concepts.CONCEPT_MODEL_ATTRIBUTE, Concepts.INFERRED_RELATIONSHIP));
    String inferredExtensionRelationship = createRelationship(extension.getResourceURI(), createRelationshipRequestBody("409852006", Concepts.IS_A, Concepts.CONCEPT_MODEL_OBJECT_ATTRIBUTE, Concepts.INFERRED_RELATIONSHIP));
    // version INT
    LocalDate newSIVersion = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, newSIVersion).statusCode(201);
    // create upgrade to the new SI version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), SNOMEDCT_URI.withPath(newSIVersion.toString()));
    // on the upgade branch, the new INT concept should not have duplicate revisions, and its parentage info should be correct
    SnomedConcept conceptOnUpgradeBranch = getConcept(upgradeCodeSystem.getResourceURI(), intConceptId);
    assertThat(conceptOnUpgradeBranch.getParentIdsAsString()).containsOnly("409852006");
    assertThat(conceptOnUpgradeBranch.getAncestorIdsAsString()).containsOnly(IComponent.ROOT_ID, "41146007", "81325006", "106237007", Concepts.ROOT_CONCEPT, "246061005", "409822003", "410607006", Concepts.CONCEPT_MODEL_ATTRIBUTE, Concepts.CONCEPT_MODEL_OBJECT_ATTRIBUTE, "900000000000441003");
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 27 with SnomedConcept

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

the class SnomedExtensionUpgradeTest method upgrade11DonatedConceptAndDescriptionsAndRelationshipsWithCrossReference.

@Test
public void upgrade11DonatedConceptAndDescriptionsAndRelationshipsWithCrossReference() {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    String extensionFsnTerm1 = "FSN of concept";
    String extensionPtTerm1 = "PT of concept";
    String extensionSynonymTerm1 = "Synonym of extension concept";
    Json fsnRequestBody1 = Json.object("typeId", Concepts.FULLY_SPECIFIED_NAME, "term", extensionFsnTerm1, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.UK_PREFERRED_MAP);
    Json ptRequestBody1 = Json.object("typeId", Concepts.SYNONYM, "term", extensionPtTerm1, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.UK_PREFERRED_MAP);
    Json synonymRequestBody1 = Json.object("typeId", Concepts.SYNONYM, "term", extensionSynonymTerm1, "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(fsnRequestBody1, ptRequestBody1, synonymRequestBody1), "relationships", Json.array(statedIsa, inferredIsa));
    String extensionConceptId1 = createConcept(extension.getResourceURI(), extensionConceptRequestBody);
    // create another extension concept which references the previous one
    String extensionFsnTerm2 = "FSN of concept 2";
    String extensionPtTerm2 = "PT of concept 2";
    String extensionSynonymTerm2 = "Synonym of extension concept 2";
    Json referenceToExtensionConcept1 = Json.object("typeId", Concepts.PART_OF, "destinationId", extensionConceptId1, "characteristicTypeId", Concepts.ADDITIONAL_RELATIONSHIP);
    String extensionConceptId2 = createConcept(extension.getResourceURI(), extensionConceptRequestBody.with(Json.object("descriptions", Json.array(fsnRequestBody1.with("term", extensionFsnTerm2), ptRequestBody1.with("term", extensionPtTerm2), synonymRequestBody1.with("term", extensionSynonymTerm2)), "relationships", Json.array(statedIsa, inferredIsa, referenceToExtensionConcept1))));
    // create new extension version
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    SnomedConcept extensionConcept1 = getConcept(extension.getResourceURI(), extensionConceptId1, "descriptions()", "relationships()");
    String extensionFsnId1 = getFirstMatchingDescription(extensionConcept1, extensionFsnTerm1).getId();
    String extensionPtId1 = getFirstMatchingDescription(extensionConcept1, extensionPtTerm1).getId();
    String extensionSynonymId1 = getFirstMatchingDescription(extensionConcept1, extensionSynonymTerm1).getId();
    String extensionStatedIsaId1 = getFirstRelationshipId(extensionConcept1, Concepts.STATED_RELATIONSHIP);
    String extensionInferredIsaId1 = getFirstRelationshipId(extensionConcept1, Concepts.INFERRED_RELATIONSHIP);
    SnomedConcept extensionConcept2 = getConcept(extension.getResourceURI(), extensionConceptId2, "descriptions()", "relationships()");
    String extensionFsnId2 = getFirstMatchingDescription(extensionConcept2, extensionFsnTerm2).getId();
    String extensionPtId2 = getFirstMatchingDescription(extensionConcept2, extensionPtTerm2).getId();
    String extensionSynonymId2 = getFirstMatchingDescription(extensionConcept2, extensionSynonymTerm2).getId();
    String extensionStatedIsaId2 = getFirstRelationshipId(extensionConcept2, Concepts.STATED_RELATIONSHIP);
    String extensionInferredIsaId2 = getFirstRelationshipId(extensionConcept2, Concepts.INFERRED_RELATIONSHIP);
    String referenceToExtensionConcept1RelationshipId = getFirstRelationshipId(extensionConcept2, Concepts.ADDITIONAL_RELATIONSHIP);
    // simulate donation via concept create and versioning
    // donate both concepts without the PART OF relationship reference between them
    String intConceptId1 = createConcept(SnomedContentRule.SNOMEDCT, Json.object("id", extensionConceptId1, "moduleId", Concepts.MODULE_SCT_CORE, "descriptions", Json.array(fsnRequestBody1.with("id", extensionFsnId1), ptRequestBody1.with("id", extensionPtId1)), "relationships", Json.array(statedIsa.with("id", extensionStatedIsaId1), inferredIsa.with("id", extensionInferredIsaId1))));
    String intConceptId2 = createConcept(SnomedContentRule.SNOMEDCT, Json.object("id", extensionConceptId2, "moduleId", Concepts.MODULE_SCT_CORE, "descriptions", Json.array(fsnRequestBody1.with("id", extensionFsnId2), ptRequestBody1.with("id", extensionPtId2)), "relationships", Json.array(statedIsa.with("id", extensionStatedIsaId2), inferredIsa.with("id", extensionInferredIsaId2))));
    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 donatedConceptInExtension1 = getConcept(upgradeCodeSystem.getResourceURI(), intConceptId1, "descriptions()", "relationships()");
    SnomedConcept donatedConceptInExtension2 = getConcept(upgradeCodeSystem.getResourceURI(), intConceptId2, "descriptions()", "relationships()");
    // validate components of donated concepts on extension branch
    // same IDs, different modules
    assertEquals(donatedConceptInExtension1.getId(), extensionConcept1.getId());
    assertNotEquals(donatedConceptInExtension1.getModuleId(), extensionConcept1.getModuleId());
    assertThat(donatedConceptInExtension1.getDescriptions()).extracting(SnomedDescription::getId).containsOnly(extensionFsnId1, extensionPtId1, extensionSynonymId1);
    assertThat(donatedConceptInExtension1.getRelationships()).extracting(SnomedRelationship::getId).containsOnly(extensionStatedIsaId1, extensionInferredIsaId1);
    // check if the other donated extension concept still has the reference relationship
    assertEquals(donatedConceptInExtension2.getId(), extensionConcept2.getId());
    assertNotEquals(donatedConceptInExtension2.getModuleId(), extensionConcept2.getModuleId());
    assertThat(donatedConceptInExtension2.getDescriptions()).extracting(SnomedDescription::getId).containsOnly(extensionFsnId2, extensionPtId2, extensionSynonymId2);
    assertThat(donatedConceptInExtension2.getRelationships()).extracting(SnomedRelationship::getId).containsOnly(extensionStatedIsaId2, extensionInferredIsaId2, referenceToExtensionConcept1RelationshipId);
}
Also used : 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 28 with SnomedConcept

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

the class SnomedImportApiTest method import28ImportConceptAsInactive.

@Test
public void import28ImportConceptAsInactive() throws Exception {
    getComponent(branchPath, SnomedComponentType.CONCEPT, "100005").statusCode(404);
    importArchive("SnomedCT_Release_INT_20150131_concept_as_inactive.zip");
    SnomedConcept concept = getComponent(branchPath, SnomedComponentType.CONCEPT, "100005").statusCode(200).extract().as(SnomedConcept.class);
    assertArrayEquals(new long[] { IComponent.ROOT_IDL }, concept.getParentIds());
    assertArrayEquals(new long[0], concept.getAncestorIds());
    assertArrayEquals(new long[] { IComponent.ROOT_IDL }, concept.getStatedParentIds());
    assertArrayEquals(new long[0], concept.getStatedAncestorIds());
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 29 with SnomedConcept

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

the class SnomedImportApiTest method import26OWLExpressionReferenceSetMembers.

@Test
public void import26OWLExpressionReferenceSetMembers() throws Exception {
    SnomedConcept oldRoot = getComponent(branchPath, SnomedComponentType.CONCEPT, Concepts.ROOT_CONCEPT, "members()").extract().as(SnomedConcept.class);
    assertTrue(oldRoot.getMembers().getItems().stream().noneMatch(m -> m.getRefsetId().equals(Concepts.REFSET_OWL_AXIOM) || m.getRefsetId().equals(Concepts.REFSET_OWL_ONTOLOGY)));
    importArchive("SnomedCT_Release_INT_20170731_new_owl_expression_members.zip");
    SnomedConcept root = getComponent(branchPath, SnomedComponentType.CONCEPT, Concepts.ROOT_CONCEPT, "members()").extract().as(SnomedConcept.class);
    Optional<SnomedReferenceSetMember> axiomMember = root.getMembers().getItems().stream().filter(m -> m.getRefsetId().equals(Concepts.REFSET_OWL_AXIOM)).findFirst();
    assertTrue(axiomMember.isPresent());
    assertEquals("ec2cc6be-a10b-44b1-a2cc-42a3f11d406e", axiomMember.get().getId());
    assertEquals(Concepts.MODULE_SCT_CORE, axiomMember.get().getModuleId());
    assertEquals(Concepts.REFSET_OWL_AXIOM, axiomMember.get().getRefsetId());
    assertEquals(Concepts.ROOT_CONCEPT, axiomMember.get().getReferencedComponent().getId());
    assertEquals(OWL_EXPRESSION, axiomMember.get().getProperties().get(SnomedRf2Headers.FIELD_OWL_EXPRESSION));
    Optional<SnomedReferenceSetMember> ontologyMember = root.getMembers().getItems().stream().filter(m -> m.getRefsetId().equals(Concepts.REFSET_OWL_ONTOLOGY)).findFirst();
    assertTrue(ontologyMember.isPresent());
    assertEquals("f81c24fb-c40a-4b28-9adb-85f748f71395", ontologyMember.get().getId());
    assertEquals(Concepts.MODULE_SCT_CORE, ontologyMember.get().getModuleId());
    assertEquals(Concepts.REFSET_OWL_ONTOLOGY, ontologyMember.get().getRefsetId());
    assertEquals(Concepts.ROOT_CONCEPT, ontologyMember.get().getReferencedComponent().getId());
    assertEquals("Ontology(<http://snomed.info/sct/900000000000207008>)", ontologyMember.get().getProperties().get(SnomedRf2Headers.FIELD_OWL_EXPRESSION));
}
Also used : MethodSorters(org.junit.runners.MethodSorters) EffectiveTimes(com.b2international.snowowl.core.date.EffectiveTimes) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) RemoteJobState(com.b2international.snowowl.core.jobs.RemoteJobState) ValidatableResponse(io.restassured.response.ValidatableResponse) CodeSystemVersionRestRequests.createVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.createVersion) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) RestExtensions.lastPathSegment(com.b2international.snowowl.test.commons.rest.RestExtensions.lastPathSegment) 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) Map(java.util.Map) RestExtensions.givenAuthenticatedRequest(com.b2international.snowowl.test.commons.rest.RestExtensions.givenAuthenticatedRequest) StreamSupport(java.util.stream.StreamSupport) NotFoundException(com.b2international.commons.exceptions.NotFoundException) Rf2ReleaseType(com.b2international.snowowl.snomed.core.domain.Rf2ReleaseType) CodeSystemVersionRestRequests.assertGetVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.assertGetVersion) BranchPathUtils(com.b2international.snowowl.core.branch.BranchPathUtils) SnomedApiTestConstants(com.b2international.snowowl.snomed.core.rest.SnomedApiTestConstants) DateFormats(com.b2international.snowowl.core.date.DateFormats) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) SnomedImportRestRequests.doImport(com.b2international.snowowl.snomed.core.rest.SnomedImportRestRequests.doImport) CodeSystemRestRequests.createCodeSystem(com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests.createCodeSystem) TimeUnit(java.util.concurrent.TimeUnit) SnomedImportRestRequests.waitForImportJob(com.b2international.snowowl.snomed.core.rest.SnomedImportRestRequests.waitForImportJob) List(java.util.List) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) IComponent(com.b2international.snowowl.core.domain.IComponent) Optional(java.util.Optional) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) Collections(java.util.Collections) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 30 with SnomedConcept

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

the class SnomedImportApiTest method import04NewConcept.

@Test
public void import04NewConcept() throws Exception {
    getComponent(branchPath, SnomedComponentType.CONCEPT, "63961392103").statusCode(404);
    importArchive("SnomedCT_Release_INT_20150131_new_concept.zip");
    SnomedConcept concept = getComponent(branchPath, SnomedComponentType.CONCEPT, "63961392103", "pt()").statusCode(200).body("pt.id", equalTo("13809498114")).extract().as(SnomedConcept.class);
    // assert proper parent/ancestor array updates
    assertArrayEquals(new long[] { IComponent.ROOT_IDL }, concept.getParentIds());
    assertArrayEquals(new long[0], concept.getAncestorIds());
    assertArrayEquals(new long[] { Long.valueOf(Concepts.ROOT_CONCEPT) }, concept.getStatedParentIds());
    assertArrayEquals(new long[] { IComponent.ROOT_IDL }, concept.getStatedAncestorIds());
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

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