use of com.b2international.commons.json.Json in project snow-owl by b2ihealthcare.
the class SnomedRelationshipApiTest method createInactiveRelationship.
private void createInactiveRelationship(String typeId) {
Json requestBody = createRelationshipRequestBody(Concepts.ROOT_CONCEPT, typeId, Concepts.NAMESPACE_ROOT).with("active", false).with("commitComment", "Created inactive relationship");
String relationshipId = assertCreated(createComponent(branchPath, SnomedComponentType.RELATIONSHIP, requestBody));
getComponent(branchPath, SnomedComponentType.RELATIONSHIP, relationshipId).statusCode(200).body("active", equalTo(false));
}
use of com.b2international.commons.json.Json 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);
}
use of com.b2international.commons.json.Json 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));
}
use of com.b2international.commons.json.Json 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());
}
use of com.b2international.commons.json.Json 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);
}
Aggregations