From da695d5b20aabbbcddf61441c0d6f9892a1e52c2 Mon Sep 17 00:00:00 2001 From: Quyen Ly Date: Thu, 25 Jan 2024 16:01:18 +0700 Subject: [PATCH] MAINT-2023 Updated logic to get attribute values for IS-A attribute --- .../snomed/snowstorm/mrcm/MRCMService.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/snomed/snowstorm/mrcm/MRCMService.java b/src/main/java/org/snomed/snowstorm/mrcm/MRCMService.java index afeef9532..ba07b0a5a 100644 --- a/src/main/java/org/snomed/snowstorm/mrcm/MRCMService.java +++ b/src/main/java/org/snomed/snowstorm/mrcm/MRCMService.java @@ -25,6 +25,7 @@ import org.springframework.data.elasticsearch.core.query.FetchSourceFilter; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import java.util.*; import java.util.function.Function; @@ -164,8 +165,11 @@ private void addAttributeRangesToExtraConceptMiniFields(final ConceptMini attrib } public Collection retrieveAttributeValues(ContentType contentType, String attributeId, String termPrefix, String branchPath, List languageDialects) throws ServiceException { - BranchCriteria branchCriteria = versionControlHelper.getBranchCriteria(branchPath); - MRCM branchMRCM = mrcmLoader.loadActiveMRCM(branchPath, branchCriteria); + MRCM branchMRCM = null; + if (!Concepts.ISA.equals(attributeId)) { + BranchCriteria branchCriteria = versionControlHelper.getBranchCriteria(branchPath); + branchMRCM = mrcmLoader.loadActiveMRCM(branchPath, branchCriteria); + } return retrieveAttributeValues(contentType, attributeId, termPrefix, branchPath, languageDialects, branchMRCM); } @@ -184,21 +188,26 @@ public Collection retrieveAttributeValueIds(ContentType contentType, Strin } private QueryService.ConceptQueryBuilder createAttributeValuesQuery(ContentType contentType, String attributeId, String termPrefix, List languageDialects, MRCM branchMRCM) { - Set attributeRanges = branchMRCM.getMandatoryAttributeRanges(attributeId, contentType); + AttributeRange attributeRange = null; + if (!Concepts.ISA.equals(attributeId)) { + Set attributeRanges = branchMRCM.getMandatoryAttributeRanges(attributeId, contentType); + + if (attributeRanges.isEmpty()) { + throw new IllegalArgumentException("No MRCM Attribute Range found with Mandatory rule strength for given content type and attributeId."); + } else if (attributeRanges.size() > 1) { + logger.warn("Multiple Attribute Ranges found with Mandatory rule strength for content type {} and attribute {} : {}.", + contentType, attributeId, attributeRanges.stream().map(AttributeRange::getId).collect(Collectors.toSet())); + } - if (attributeRanges.isEmpty()) { - throw new IllegalArgumentException("No MRCM Attribute Range found with Mandatory rule strength for given content type and attributeId."); - } else if (attributeRanges.size() > 1) { - logger.warn("Multiple Attribute Ranges found with Mandatory rule strength for content type {} and attribute {} : {}.", - contentType, attributeId, attributeRanges.stream().map(AttributeRange::getId).collect(Collectors.toSet())); + attributeRange = attributeRanges.iterator().next(); } - AttributeRange attributeRange = attributeRanges.iterator().next(); - QueryService.ConceptQueryBuilder conceptQuery = queryService.createQueryBuilder(Relationship.CharacteristicType.inferred) - .ecl(attributeRange.getRangeConstraint()) .resultLanguageDialects(languageDialects); + if (attributeRange != null) { + conceptQuery.ecl(attributeRange.getRangeConstraint()); + } if (IdentifierService.isConceptId(termPrefix)) { conceptQuery.conceptIds(Collections.singleton(termPrefix)); } else {