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);
}
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());
}
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());
}
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;
}
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);
}
}
Aggregations