Search in sources :

Example 26 with CodeSystem

use of com.b2international.snowowl.core.codesystem.CodeSystem in project snow-owl by b2ihealthcare.

the class CodeSystemUpgradeRestService method sync.

@Operation(summary = "Synchronize upgrade codesystem with the original codesystem (EXPERIMENTAL)", description = "Synchronize any changes on the original code system with the upgrade code system.")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "Upgrade code system synchronized"), @ApiResponse(responseCode = "400", description = "Code system could not be synchronized with the downstream code system") })
@PostMapping(value = "/sync/", consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(HttpStatus.NO_CONTENT)
public void sync(@RequestBody final CodeSystemUpgradeSyncRestInput body) {
    final String codeSystemId = body.getCodeSystemId();
    final ResourceURI source = body.getSource();
    final CodeSystem codeSystem = CodeSystemRequests.prepareSearchCodeSystem().filterById(codeSystemId).buildAsync().execute(getBus()).getSync(1, TimeUnit.MINUTES).first().orElseThrow(() -> new NotFoundException("Code System", codeSystemId));
    CodeSystemRequests.prepareUpgradeSynchronization(codeSystem.getResourceURI(), source).buildAsync().execute(getBus());
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) NotFoundException(com.b2international.commons.exceptions.NotFoundException) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 27 with CodeSystem

use of com.b2international.snowowl.core.codesystem.CodeSystem 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 28 with CodeSystem

use of com.b2international.snowowl.core.codesystem.CodeSystem 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 29 with CodeSystem

use of com.b2international.snowowl.core.codesystem.CodeSystem in project snow-owl by b2ihealthcare.

the class SnomedExtensionUpgradeTest method upgrade19UpgradeFromCodeSystemVersionWithUnpublishedAndPublishedChanges.

@Test
public void upgrade19UpgradeFromCodeSystemVersionWithUnpublishedAndPublishedChanges() {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    // new SI concept
    String newConceptId = createConcept(SnomedContentRule.SNOMEDCT, createConceptRequestBody(Concepts.ROOT_CONCEPT, Concepts.MODULE_SCT_CORE));
    // create a new INT version
    LocalDate effectiveDate = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveDate).statusCode(201);
    ResourceURI upgradeVersion = CodeSystem.uri(SNOMEDCT, effectiveDate.toString());
    // new SE concept
    String extensionModuleId = createModule(extension);
    String newConceptId2 = createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId));
    // version extension
    LocalDate effectiveDate2 = LocalDate.now();
    createVersion(extension.getId(), effectiveDate2).statusCode(201);
    ResourceURI extensionVersion = CodeSystem.uri(extension.getId(), effectiveDate2.toString());
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extensionVersion, upgradeVersion);
    assertEquals(upgradeVersion, upgradeCodeSystem.getExtensionOf());
    // new SE concept
    String newConceptId3 = createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId));
    getComponent(upgradeCodeSystem.getResourceURI(), SnomedComponentType.CONCEPT, newConceptId).statusCode(200);
    getComponent(upgradeCodeSystem.getResourceURI(), SnomedComponentType.CONCEPT, newConceptId2).statusCode(200);
    getComponent(upgradeCodeSystem.getResourceURI(), SnomedComponentType.CONCEPT, newConceptId3).statusCode(404);
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 30 with CodeSystem

use of com.b2international.snowowl.core.codesystem.CodeSystem 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)

Aggregations

CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)45 Test (org.junit.Test)34 LocalDate (java.time.LocalDate)33 ResourceURI (com.b2international.snowowl.core.ResourceURI)21 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)14 Json (com.b2international.commons.json.Json)8 CodeSystemRestRequests.createCodeSystem (com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests.createCodeSystem)6 CodeSystems (com.b2international.snowowl.core.codesystem.CodeSystems)5 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)5 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)4 TimeUnit (java.util.concurrent.TimeUnit)4 Collectors (java.util.stream.Collectors)4 BadRequestException (com.b2international.commons.exceptions.BadRequestException)3 NotFoundException (com.b2international.commons.exceptions.NotFoundException)3 TerminologyResource (com.b2international.snowowl.core.TerminologyResource)3 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)3 Attachment (com.b2international.snowowl.core.attachments.Attachment)3 AttachmentRegistry (com.b2international.snowowl.core.attachments.AttachmentRegistry)3 DateFormats (com.b2international.snowowl.core.date.DateFormats)3 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)3