From 4733114318c39ebad7d49faa68cbcea157e67033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20P=C3=A9teri?= Date: Tue, 19 Nov 2024 14:48:32 +0100 Subject: [PATCH 1/2] feat(snomed.datastore): Add utility method to shorten the display... ...name of association type reference sets --- .../datastore/AllSnomedDatastoreTests.java | 2 + .../datastore/SnomedRefSetUtilTest.java | 72 +++++++++++++++++++ .../snomed/datastore/SnomedRefSetUtil.java | 56 +++++++++------ 3 files changed, 110 insertions(+), 20 deletions(-) create mode 100644 snomed/com.b2international.snowowl.snomed.datastore.tests/src/com/b2international/snowowl/snomed/datastore/SnomedRefSetUtilTest.java diff --git a/snomed/com.b2international.snowowl.snomed.datastore.tests/src/com/b2international/snowowl/snomed/datastore/AllSnomedDatastoreTests.java b/snomed/com.b2international.snowowl.snomed.datastore.tests/src/com/b2international/snowowl/snomed/datastore/AllSnomedDatastoreTests.java index 84c0ac85079..f20a3636692 100644 --- a/snomed/com.b2international.snowowl.snomed.datastore.tests/src/com/b2international/snowowl/snomed/datastore/AllSnomedDatastoreTests.java +++ b/snomed/com.b2international.snowowl.snomed.datastore.tests/src/com/b2international/snowowl/snomed/datastore/AllSnomedDatastoreTests.java @@ -86,6 +86,8 @@ SnomedQueryValidationRuleEvaluatorTest.class, SnomedOWLExpressionConverterTest.class, SnomedOWLRelationshipConverterTest.class, + // + SnomedRefSetUtilTest.class, }) public class AllSnomedDatastoreTests { diff --git a/snomed/com.b2international.snowowl.snomed.datastore.tests/src/com/b2international/snowowl/snomed/datastore/SnomedRefSetUtilTest.java b/snomed/com.b2international.snowowl.snomed.datastore.tests/src/com/b2international/snowowl/snomed/datastore/SnomedRefSetUtilTest.java new file mode 100644 index 00000000000..89b189bcbd1 --- /dev/null +++ b/snomed/com.b2international.snowowl.snomed.datastore.tests/src/com/b2international/snowowl/snomed/datastore/SnomedRefSetUtilTest.java @@ -0,0 +1,72 @@ +/* + * Copyright 2024 B2i Healthcare, https://b2ihealthcare.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.b2international.snowowl.snomed.datastore; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +/** + * @since 7.24.5 + */ +@RunWith(Parameterized.class) +public class SnomedRefSetUtilTest { + + // Close-to-but-not-quite-production reference set labels + private static final Object[][] INPUT = { + { "FORMERLY association reference set", "Formerly" }, + { "IDENTICAL TO association reference set", "Identical to" }, + { "RELOCATED TO association reference set", "Relocated to" }, + { "Archival association reference set", "Archival" }, + { "RELOCATED FROM association reference set", "Relocated from" }, + { "ANALOGOUS TO association reference set", "Analogous to" }, + { "SUBSTITUTED BY association reference set", "Substituted by" }, + { "Was bundle of association reference set", "Was bundle of" }, + { "OPTIONAL association reference set", "Optional" }, + { "POINTS TO concept association reference set", "Points to" }, + { "POTENTIALLY SUBSTITUTED BY association reference set", "Potentially substituted by" }, + { "POTENTIALLY IDENTICAL TO association reference set", "Potentially identical to" }, + { "XHS Health Record Component association reference set", "XHS Health Record Component" }, + { "PARTIALLY IDENTICAL TO association reference set", "Partially identical to" }, + { "Frame and segment association reference set", "Frame and segment" }, + { "Frame and whole association reference set", "Frame and whole" }, + { "Had real medicinal product association reference set", "Had real medicinal product" }, + { "Had hypothetical medicinal product association reference set", "Had hypothetical medicinal product" }, + { "XHS catalog of medicines and devices association type reference set", "XHS catalog of medicines and devices" }, + { "European Blood Filtering Association reference set", "European Blood Filtering Association" }, + { "XHS catalog of medicines and devices Virtual Therapeutic Moiety revision association reference set", "XHS catalog of medicines and devices Virtual Therapeutic Moiety revision" }, + }; + + @Parameters(name = "{0}") + public static Object[][] data() { + return INPUT; + } + + @Parameter(0) + public String refSetName; + + @Parameter(1) + public String shortenedName; + + @Test + public void testRefSetNameShortening() { + assertEquals(shortenedName, SnomedRefSetUtil.shortenAssociationRefSetName(refSetName)); + } +} diff --git a/snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/datastore/SnomedRefSetUtil.java b/snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/datastore/SnomedRefSetUtil.java index 30f413569cb..245edbb2ac5 100644 --- a/snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/datastore/SnomedRefSetUtil.java +++ b/snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/datastore/SnomedRefSetUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2020 B2i Healthcare Pte Ltd, http://b2i.sg + * Copyright 2011-2024 B2i Healthcare Pte Ltd, http://b2i.sg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,26 +15,18 @@ */ package com.b2international.snowowl.snomed.datastore; -import static com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType.COMPLEX_BLOCK_MAP; -import static com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType.COMPLEX_MAP; -import static com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType.EXTENDED_MAP; -import static com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType.SIMPLE_MAP; -import static com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType.SIMPLE_MAP_TO_SNOMEDCT; -import static com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType.SIMPLE_MAP_FROM_SNOMEDCT; -import static com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType.SIMPLE_MAP_WITH_DESCRIPTION; +import static com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType.*; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toMap; import java.math.BigDecimal; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Set; import com.b2international.commons.BooleanUtils; +import com.b2international.commons.StringUtils; import com.b2international.snowowl.core.ApplicationContext; import com.b2international.snowowl.core.config.SnowOwlConfiguration; import com.b2international.snowowl.snomed.common.SnomedConstants.Concepts; @@ -42,13 +34,7 @@ import com.b2international.snowowl.snomed.core.domain.refset.DataType; import com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType; import com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration; -import com.google.common.collect.BiMap; -import com.google.common.collect.ImmutableBiMap; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableListMultimap; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Multimap; +import com.google.common.collect.*; /** * Utility class collecting commons operations related to SNOMED CT reference sets. @@ -260,8 +246,38 @@ public static String serializeValue(final DataType dataType, final T value) } } + public static String shortenAssociationRefSetName(String refsetName) { + if (StringUtils.isEmpty(refsetName)) { + return refsetName; + } + + // Remove various suffixes to shorten the label + refsetName = removeSuffix(refsetName, " reference set"); + refsetName = removeSuffix(refsetName, " association type"); + refsetName = removeSuffix(refsetName, " association"); + refsetName = removeSuffix(refsetName, " concept"); + + if (refsetName.chars().allMatch(ch -> Character.isUpperCase(ch) || Character.isWhitespace(ch))) { + // All-caps terms "POSSIBLY EQUIVALENT TO" are modified by changing letters to lower case, then title-casing the first letter + return StringUtils.capitalizeFirstLetter(refsetName.toLowerCase(Locale.ENGLISH)); + } + + return refsetName; + } + + private static String removeSuffix(String s, String suffix) { + if (StringUtils.isEmpty(s) || StringUtils.isEmpty(suffix)) { + return s; + } + + if (s.endsWith(suffix)) { + return s.substring(0, s.length() - suffix.length()); + } + + return s; + } + private SnomedRefSetUtil() { // Suppress instantiation } - } From 322adfdc3deed3eb49ac6cd95051792ab842fab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20P=C3=A9teri?= Date: Tue, 19 Nov 2024 14:48:54 +0100 Subject: [PATCH 2/2] chore(snomed.datastore.tests): Fix header in SnomedDescriptionUtilsTest --- .../datastore/SnomedDescriptionUtilsTest.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/snomed/com.b2international.snowowl.snomed.datastore.tests/src/com/b2international/snowowl/snomed/datastore/SnomedDescriptionUtilsTest.java b/snomed/com.b2international.snowowl.snomed.datastore.tests/src/com/b2international/snowowl/snomed/datastore/SnomedDescriptionUtilsTest.java index 14ba3cf522b..10ee9c3509a 100644 --- a/snomed/com.b2international.snowowl.snomed.datastore.tests/src/com/b2international/snowowl/snomed/datastore/SnomedDescriptionUtilsTest.java +++ b/snomed/com.b2international.snowowl.snomed.datastore.tests/src/com/b2international/snowowl/snomed/datastore/SnomedDescriptionUtilsTest.java @@ -1,6 +1,18 @@ -/******************************************************************************* - * Copyright (c) 2020 B2i Healthcare. All rights reserved. - *******************************************************************************/ +/* + * Copyright 2020 B2i Healthcare, https://b2ihealthcare.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.b2international.snowowl.snomed.datastore; import static com.b2international.snowowl.snomed.datastore.SnomedDescriptionUtils.indexBestPreferredByConceptId;