use of com.b2international.snowowl.core.codesystem.CodeSystem in project snow-owl by b2ihealthcare.
the class CodeSystemsCommand method run.
@Override
public void run(CommandLineStream out) {
if (Strings.isNullOrEmpty(codeSystem)) {
out.println(Joiner.on("\n\n").join(getCodeSystems().map(this::getCodeSystemInfo).iterator()));
} else {
CodeSystem cs = getCodeSystemById(codeSystem);
if (cs == null) {
out.println(String.format("Unknown or invalid code system with identifier '%s'", codeSystem));
return;
}
out.println(getCodeSystemInfo(cs));
}
}
use of com.b2international.snowowl.core.codesystem.CodeSystem in project snow-owl by b2ihealthcare.
the class SnomedRf2ExportRequest method execute.
@Override
public Attachment execute(final BranchContext context) {
final String referenceBranch = context.path();
if (referenceBranch.contains(RevisionIndex.AT_CHAR) && !Rf2ReleaseType.SNAPSHOT.equals(releaseType)) {
throw new BadRequestException("Only snapshot export is allowed for point-in-time branch path '%s'.", referenceBranch);
}
if (referenceBranch.contains(RevisionIndex.REV_RANGE)) {
if (!Rf2ReleaseType.DELTA.equals(releaseType) || needsVersionBranchesForDeltaExport()) {
throw new BadRequestException("Only unpublished delta export is allowed for branch path range '%s'.", referenceBranch);
}
}
// register export start time for later use
final long exportStartTime = Instant.now().toEpochMilli();
// Step 1: check if the export reference branch is a working branch path descendant
final CodeSystem referenceCodeSystem = (CodeSystem) context.service(TerminologyResource.class);
if (!CompareUtils.isEmpty(referenceCodeSystem.getSettings())) {
if (Strings.isNullOrEmpty(countryNamespaceElement)) {
if (maintainerType == null) {
String maintainerType = (String) referenceCodeSystem.getSettings().get(SnomedTerminologyComponentConstants.CODESYSTEM_MAINTAINER_TYPE_CONFIG_KEY);
String nrcCountryCode = (String) referenceCodeSystem.getSettings().get(SnomedTerminologyComponentConstants.CODESYSTEM_NRC_COUNTRY_CODE_CONFIG_KEY);
if (!Strings.isNullOrEmpty(maintainerType)) {
String customCountryNamespaceElement = getCountryNamespaceElement(context, referenceCodeSystem, Rf2MaintainerType.getByNameIgnoreCase(maintainerType), Strings.nullToEmpty(nrcCountryCode));
countryNamespaceElement = customCountryNamespaceElement;
}
} else {
countryNamespaceElement = getCountryNamespaceElement(context, referenceCodeSystem, maintainerType, Strings.nullToEmpty(nrcCountryCode));
}
}
if (refSetExportLayout == null && referenceCodeSystem.getSettings().containsKey(SnomedTerminologyComponentConstants.CODESYSTEM_RF2_EXPORT_LAYOUT_CONFIG_KEY)) {
String refSetLayout = (String) referenceCodeSystem.getSettings().get(SnomedTerminologyComponentConstants.CODESYSTEM_RF2_EXPORT_LAYOUT_CONFIG_KEY);
Rf2RefSetExportLayout rf2RefSetExportLayout = Rf2RefSetExportLayout.getByNameIgnoreCase(refSetLayout);
refSetExportLayout = rf2RefSetExportLayout;
}
}
if (Strings.isNullOrEmpty(countryNamespaceElement)) {
countryNamespaceElement = getCountryNamespaceElement(context, referenceCodeSystem, DEFAULT_MAINTAINER_TYPE, "");
}
if (refSetExportLayout == null) {
refSetExportLayout = DEFAULT_RF2_EXPORT_LAYOUT;
}
// Step 2: retrieve code system versions that are visible from the reference branch
final TreeSet<Version> versionsToExport = getAllExportableCodeSystemVersions(context, referenceCodeSystem);
// Step 3: compute branches to export
final List<String> branchesToExport = computeBranchesToExport(referenceBranch, versionsToExport);
// Step 4: compute possible language codes
Multimap<String, String> availableLanguageCodes = getLanguageCodes(context, branchesToExport);
Path exportDirectory = null;
try {
final UUID exportId = UUID.randomUUID();
// create temporary export directory
exportDirectory = createExportDirectory(exportId);
// get archive effective time based on latest version effective / transient effective time / current date
final LocalDateTime archiveEffectiveDate = getArchiveEffectiveTime(context, versionsToExport);
final String archiveEffectiveDateShort = EffectiveTimes.format(archiveEffectiveDate.toLocalDate(), DateFormats.SHORT);
// create main folder including release status and archive effective date
final Path releaseDirectory = createReleaseDirectory(exportDirectory, archiveEffectiveDate);
final Set<String> visitedComponentEffectiveTimes = newHashSet();
final long effectiveTimeStart = startEffectiveTime != null ? EffectiveTimes.getEffectiveTime(startEffectiveTime) : 0;
final long effectiveTimeEnd = endEffectiveTime != null ? EffectiveTimes.getEffectiveTime(endEffectiveTime) : Long.MAX_VALUE;
// export content from the pre-computed version branches
for (String branch : branchesToExport) {
exportBranch(releaseDirectory, context, branch, archiveEffectiveDateShort, effectiveTimeStart, effectiveTimeEnd, visitedComponentEffectiveTimes, availableLanguageCodes.get(branch));
}
// export content from reference branch
if (includePreReleaseContent) {
// If a special branch path was given, use it directly
final String referenceBranchToExport = containsSpecialCharacter(referenceBranch) ? referenceBranch : RevisionIndex.toBranchAtPath(referenceBranch, exportStartTime);
exportBranch(releaseDirectory, context, referenceBranchToExport, archiveEffectiveDateShort, EffectiveTimes.UNSET_EFFECTIVE_TIME, EffectiveTimes.UNSET_EFFECTIVE_TIME, visitedComponentEffectiveTimes, availableLanguageCodes.get(referenceBranch));
}
// Step 6: compress to archive and upload to the file registry
final AttachmentRegistry fileRegistry = context.service(AttachmentRegistry.class);
registerResult(fileRegistry, exportId, exportDirectory);
final String fileName = releaseDirectory.getFileName() + ".zip";
return new Attachment(exportId, fileName);
} catch (final Exception e) {
throw new SnowowlRuntimeException("Failed to export terminology content to RF2.", e);
} finally {
if (exportDirectory != null) {
FileUtils.deleteDirectory(exportDirectory.toFile());
}
}
}
use of com.b2international.snowowl.core.codesystem.CodeSystem in project snow-owl by b2ihealthcare.
the class SnomedRf2ImportRequest method updateCodeSystemSettings.
private void updateCodeSystemSettings(final BranchContext context, final ResourceURI codeSystemUri) throws Exception {
SnomedReferenceSets languageReferenceSets = SnomedRequests.prepareSearchRefSet().all().filterByType(SnomedRefSetType.LANGUAGE).filterByActive(true).setFields(SnomedConceptDocument.Fields.ID).sortBy(Sort.fieldAsc(SnomedConceptDocument.Fields.ID)).build().execute(context);
/*
* XXX: The default language in locales is always "en", as there is no
* machine-readable information about what language code each language type
* reference set is associated with.
*/
final List<ExtendedLocale> locales = languageReferenceSets.stream().map(refSet -> new ExtendedLocale("en", "", refSet.getId())).collect(Collectors.toList());
// fetch codesystem again to get the latest settings
CodeSystem currentSnomedCodeSystem = CodeSystemRequests.prepareGetCodeSystem(codeSystemUri.getResourceId()).buildAsync().get(context);
Map<String, SnomedLanguageConfig> mergedLanguagesConfiguration = Maps.newLinkedHashMap();
SnomedDescriptionUtils.getLanguagesConfiguration(context.service(ObjectMapper.class), currentSnomedCodeSystem).forEach(config -> {
mergedLanguagesConfiguration.put(config.getLanguageTag(), config);
});
languageReferenceSets.stream().map(SnomedReferenceSet::getId).filter(SnomedTerminologyComponentConstants.LANG_REFSET_DIALECT_ALIASES::containsKey).forEach(langRefsetId -> {
final String dialect = SnomedTerminologyComponentConstants.LANG_REFSET_DIALECT_ALIASES.get(langRefsetId);
// ignore any aliases that are already defined by using computeIfAbsent
mergedLanguagesConfiguration.computeIfAbsent(dialect, languageTag -> new SnomedLanguageConfig(languageTag, langRefsetId));
});
CodeSystemRequests.prepareUpdateCodeSystem(codeSystemUri.getResourceId()).setSettings(Map.of(CodeSystem.CommonSettings.LOCALES, locales, SnomedTerminologyComponentConstants.CODESYSTEM_LANGUAGE_CONFIG_KEY, mergedLanguagesConfiguration.values())).build(context.service(User.class).getUsername(), String.format("Update '%s' settings based on RF2 import", codeSystemUri.getResourceId())).execute(context.service(IEventBus.class)).getSync(2, TimeUnit.MINUTES);
}
use of com.b2international.snowowl.core.codesystem.CodeSystem in project snow-owl by b2ihealthcare.
the class SnomedExtensionUpgradeTest method upgrade18UpgradeFromCodeSystemVersionWithUnpublishedChanges.
@Test
public void upgrade18UpgradeFromCodeSystemVersionWithUnpublishedChanges() {
// 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());
// version extension
LocalDate effectiveDate2 = LocalDate.now();
createVersion(extension.getId(), effectiveDate2).statusCode(201);
ResourceURI extensionVersion = CodeSystem.uri(extension.getId(), effectiveDate2.toString());
// new SE concept
String extensionModuleId = createModule(extension);
String newConceptId2 = createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId));
// start upgrade to the new available upgrade version
CodeSystem upgradeCodeSystem = createExtensionUpgrade(extensionVersion, upgradeVersion);
assertEquals(upgradeVersion, upgradeCodeSystem.getExtensionOf());
getComponent(upgradeCodeSystem.getResourceURI(), SnomedComponentType.CONCEPT, newConceptId).statusCode(200);
getComponent(upgradeCodeSystem.getResourceURI(), SnomedComponentType.CONCEPT, newConceptId2).statusCode(404);
}
use of com.b2international.snowowl.core.codesystem.CodeSystem 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");
}
Aggregations