DroolsDescriptionService implements DescriptionService { @Override public Set<Description> findMatchingDescriptionInHierarchy(Concept concept, Description description) { if(concept == null || concept.getId().equals(Constants.ROOT_CONCEPT)) { return Collections.emptySet(); } Set<Description> resultSet = new HashSet<>(); String languageCode = description.getLanguageCode(); String term = description.getTerm(); if(term == null || term.trim().isEmpty()) return Collections.emptySet(); ConceptService conceptService = new DroolsConceptService(repository); Set<String> conceptAncestorIds = conceptService.findStatedAncestorsOfConcept(concept); for (String conceptAncestorId : conceptAncestorIds) { Concept conceptAncestor = repository.getConcept(conceptAncestorId); for (Description ancestorsDescription : conceptAncestor.getDescriptions()) { if(ancestorsDescription.isActive() && ancestorsDescription.getLanguageCode().equals(languageCode) && ancestorsDescription.getTerm().equals(term)) { resultSet.add(ancestorsDescription); } } } return resultSet; } DroolsDescriptionService(SnomedDroolsComponentRepository repository, TestResourceProvider testResourceProvider); @Override Set<String> getFSNs(Set<String> conceptIds, String... languageRefsetIds); @Override Set<Description> findActiveDescriptionByExactTerm(String exactTerm); @Override Set<Description> findInactiveDescriptionByExactTerm(String exactTerm); @Override // FIXME: Currently only finds matching description in ancestors. // Should search all descendants of the second highest ancestor (the ancestor which is a direct child of root). Set<Description> findMatchingDescriptionInHierarchy(Concept concept, Description description); @Override String getCaseSensitiveWordsErrorMessage(Description description); @Override String getLanguageSpecificErrorMessage(Description description); @Override Set<String> findParentsNotContainingSemanticTag(Concept concept, String termSematicTag, String... languageRefsetIds); @Override boolean isRecognisedSemanticTag(String termSemanticTag); DroolsDescriptionIndex getDroolsDescriptionIndex();  }
@Test public void testFindMatchingDescriptionsInHierachy() throws FileNotFoundException { repository.addConcept(FileLoaderTestUtils.fileToObject("data/1234567890.json", DroolsConcept.class)); DroolsConcept testConcept = repository.getConcept("1234567890"); DroolsDescription testDescription = null; for (DroolsDescription droolsDescription : testConcept.getDescriptions()) { testDescription = droolsDescription; } Set<Description> results = droolsDescriptionService.findMatchingDescriptionInHierarchy(testConcept, testDescription); Assert.assertEquals(1, results.size()); for (Description result : results) { Assert.assertEquals("1204236014", result.getId()); } }