Search in sources :

Example 56 with SnomedConcept

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

the class SnomedComponentEffectiveTimeRestoreTest method restoreExtensionEffectiveTimeOnExtension.

@Test
public void restoreExtensionEffectiveTimeOnExtension() throws Exception {
    // create extension on the base SI VERSION
    final CodeSystem extension = createExtension(baseInternationalCodeSystem, branchPath.lastSegment());
    // create the module to represent the extension
    String moduleId = createModule(extension);
    // create an extension version, concept receives effective time
    createVersion(extension.getId(), EXT_VERSION, LocalDate.parse("2019-10-31")).statusCode(201);
    SnomedConcept concept = getConcept(extension.getResourceURI(), moduleId);
    assertEquals(EffectiveTimes.parse(EXT_VERSION), concept.getEffectiveTime());
    // create a change on the concept, like change the definition status
    updateConcept(extension.getResourceURI(), moduleId, Map.of("definitionStatusId", Concepts.FULLY_DEFINED));
    concept = getConcept(extension.getResourceURI(), moduleId);
    assertEquals(null, concept.getEffectiveTime());
    // revert the change, so it reverts the effective time to the EXT_VER effective time
    updateConcept(extension.getResourceURI(), moduleId, Map.of("definitionStatusId", Concepts.PRIMITIVE));
    concept = getConcept(extension.getResourceURI(), moduleId);
    assertEquals(EffectiveTimes.parse(EXT_VERSION), concept.getEffectiveTime());
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) CodeSystemRestRequests.createCodeSystem(com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests.createCodeSystem) Test(org.junit.Test)

Example 57 with SnomedConcept

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

the class SnomedComponentEffectiveTimeRestoreTest method restoreInternationalEffectiveTimeOnExtension.

@Test
public void restoreInternationalEffectiveTimeOnExtension() throws Exception {
    // create extension on the base SI VERSION
    CodeSystem extension = createExtension(baseInternationalCodeSystem, branchPath.lastSegment());
    // get the first concept from the Base SI version
    SnomedConcept concept = searchConcepts(baseInternationalCodeSystem, Map.of("module", Concepts.MODULE_SCT_CORE), 1).stream().findFirst().get();
    LocalDate lastReleasedEffectiveTime = concept.getEffectiveTime();
    String conceptId = concept.getId();
    // create a change on the concept, like change the definition status
    updateConcept(extension.getResourceURI(), concept.getId(), Map.of("definitionStatusId", Concepts.FULLY_DEFINED));
    concept = getConcept(extension.getResourceURI(), conceptId);
    assertEquals(null, concept.getEffectiveTime());
    // revert the change, so it reverts the effective time to the EXT_VER effective time
    updateConcept(extension.getResourceURI(), conceptId, Map.of("definitionStatusId", Concepts.PRIMITIVE));
    concept = getConcept(extension.getResourceURI(), conceptId);
    assertEquals(lastReleasedEffectiveTime, concept.getEffectiveTime());
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) CodeSystemRestRequests.createCodeSystem(com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests.createCodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 58 with SnomedConcept

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

the class SnomedExtensionUpgradeTest method upgrade12WithDonatedConceptAndDescriptionsAndRelationshipsWithExternalReference.

@Test
public void upgrade12WithDonatedConceptAndDescriptionsAndRelationshipsWithExternalReference() {
    // 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 intConceptId = 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))));
    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(), intConceptId, "descriptions()", "relationships()");
    SnomedConcept extensionConcept2OnUpgrade = getConcept(upgradeCodeSystem.getResourceURI(), extensionConceptId2, "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 external reference extension concept still has the reference relationship and all its content
    assertThat(extensionConcept2OnUpgrade.getDescriptions()).extracting(SnomedDescription::getId).containsOnly(extensionFsnId2, extensionPtId2, extensionSynonymId2);
    assertThat(extensionConcept2OnUpgrade.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 59 with SnomedConcept

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

the class SnomedExtensionUpgradeTest method upgrade27MultipleUpgradesAroundSameConcept.

@Test
public void upgrade27MultipleUpgradesAroundSameConcept() throws Exception {
    String intConceptId = "413858005";
    // prepare extension on latest int version
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    String inferredIntRelationship = createRelationship(SNOMEDCT_URI, createRelationshipRequestBody("409852006", Concepts.IS_A, Concepts.CONCEPT_MODEL_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()));
    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, "900000000000441003");
    Boolean success = CodeSystemRequests.prepareComplete(upgradeCodeSystem.getId()).buildAsync().execute(getBus()).getSync(1, TimeUnit.MINUTES);
    assertTrue(success);
    String secondInferredIntRelationship = createRelationship(SNOMEDCT_URI, createRelationshipRequestBody("409852006", Concepts.IS_A, Concepts.CONCEPT_MODEL_OBJECT_ATTRIBUTE, Concepts.INFERRED_RELATIONSHIP));
    // version INT again for new upgrade
    LocalDate secondSIVersion = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, secondSIVersion).statusCode(201);
    // upgrade again
    upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), SNOMEDCT_URI.withPath(secondSIVersion.toString()));
    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 60 with SnomedConcept

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

the class SnomedExtensionUpgradeTest method upgrade25UpgradeAndSyncOverInactivatedInferredRelationship.

@Test
public void upgrade25UpgradeAndSyncOverInactivatedInferredRelationship() throws Exception {
    // create a new SI parent concept which points to the ROOT and version it
    String intParentConceptId = createConcept(SNOMEDCT_URI, createConceptRequestBody(Concepts.ROOT_CONCEPT, Concepts.MODULE_SCT_CORE));
    // also create the inferred relationship, which will be inactivated
    String intRelationshipIdToInactivate = createRelationship(SNOMEDCT_URI, createRelationshipRequestBody(intParentConceptId, Concepts.IS_A, Concepts.ROOT_CONCEPT, Concepts.INFERRED_RELATIONSHIP));
    LocalDate firstSIVersion = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, firstSIVersion).statusCode(201);
    // create extension, a concept pointing to the INT parent concept and a version
    CodeSystem extension = createExtension(SNOMEDCT_URI.withPath(firstSIVersion.toString()), branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    String extensionConceptId = createConcept(extension.getResourceURI(), createConceptRequestBody(intParentConceptId, extensionModuleId));
    String extensionInferredRelationshipId = createRelationship(extension.getResourceURI(), createRelationshipRequestBody(extensionConceptId, Concepts.IS_A, intParentConceptId, extensionModuleId, Concepts.INFERRED_RELATIONSHIP));
    // verify that extension concept has correct parent/ancestor arrays
    SnomedConcept extensionConceptAfterFirstVersion = getConcept(extension.getResourceURI(), extensionConceptId);
    assertThat(extensionConceptAfterFirstVersion.getParentIdsAsString()).containsOnly(intParentConceptId);
    assertThat(extensionConceptAfterFirstVersion.getAncestorIdsAsString()).containsOnly(IComponent.ROOT_ID, Concepts.ROOT_CONCEPT);
    // inactivate INT inferred relationship
    updateRelationship(SNOMEDCT_URI, intRelationshipIdToInactivate, Json.object(SnomedRf2Headers.FIELD_ACTIVE, false, "commitComment", "Inactivate INT inferred relationship"));
    LocalDate secondSIVersion = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, secondSIVersion).statusCode(201);
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), SNOMEDCT_URI.withPath(secondSIVersion.toString()));
    // verify that extension concept on upgrade branch, does not have parent info of inactivated things
    SnomedConcept extensionConceptOnUpgrade = getConcept(upgradeCodeSystem.getResourceURI(), extensionConceptId);
    assertThat(extensionConceptOnUpgrade.getParentIdsAsString()).containsOnly(intParentConceptId);
    assertThat(extensionConceptOnUpgrade.getAncestorIdsAsString()).containsOnly(IComponent.ROOT_ID);
    // version the extension and sync the upgrade branch
    LocalDate firstExtensionVersion = getNextAvailableEffectiveDate(extension.getId());
    createVersion(extension.getId(), firstExtensionVersion).statusCode(201);
    Boolean result = CodeSystemRequests.prepareUpgradeSynchronization(upgradeCodeSystem.getResourceURI(), extension.getResourceURI()).buildAsync().execute(getBus()).getSync(1, TimeUnit.MINUTES);
    assertTrue(result);
    // verify that after sync everything looks normal
    SnomedConcept extensionConceptOnUpgradeAfterSync = getConcept(upgradeCodeSystem.getResourceURI(), extensionConceptId);
    assertThat(extensionConceptOnUpgradeAfterSync.getParentIdsAsString()).containsOnly(intParentConceptId);
    assertThat(extensionConceptOnUpgradeAfterSync.getAncestorIdsAsString()).containsOnly(Concepts.ROOT_CONCEPT, IComponent.ROOT_ID);
    assertThat(extensionConceptOnUpgradeAfterSync.getEffectiveTime()).isEqualTo(firstExtensionVersion);
    assertThat(extensionConceptOnUpgradeAfterSync.isReleased()).isTrue();
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) LocalDate(java.time.LocalDate) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) Test(org.junit.Test)

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