Skip to content

Commit

Permalink
Merge pull request #1340 from b2ihealthcare/feature/SO-6036-associati…
Browse files Browse the repository at this point in the history
…on-refset-shortening

Make association reference set names less verbose for UI display purposes
  • Loading branch information
cmark authored Nov 22, 2024
2 parents fde9f84 + 322adfd commit 7a14b76
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
SnomedQueryValidationRuleEvaluatorTest.class,
SnomedOWLExpressionConverterTest.class,
SnomedOWLRelationshipConverterTest.class,
//
SnomedRefSetUtilTest.class,
})
public class AllSnomedDatastoreTests {

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,40 +15,26 @@
*/
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;
import com.b2international.snowowl.snomed.common.SnomedRF2Folder;
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.
Expand Down Expand Up @@ -260,8 +246,38 @@ public static <T> 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
}

}

0 comments on commit 7a14b76

Please sign in to comment.