DroolsConceptService implements ConceptService { @Override public Set<String> findTopLevelHierarchiesOfConcept(Concept concept) { DroolsConcept droolsConcept = repository.getConcept(concept.getId()); Set<String> resultSet = new HashSet<>(); for (DroolsRelationship relationship : droolsConcept.getRelationships()) { if(relationship.isActive() && Constants.IS_A.equals(relationship.getTypeId()) && Constants.STATED_RELATIONSHIP.equals(relationship.getCharacteristicTypeId())) { if(Constants.ROOT_CONCEPT.equals(relationship.getDestinationId())) { resultSet.add(relationship.getSourceId()); } else { resultSet.addAll(findTopLevelHierarchiesOfConcept(repository.getConcept(relationship.getDestinationId()))); } } } return resultSet; } DroolsConceptService(SnomedDroolsComponentRepository repository); @Override boolean isActive(String conceptId); @Override Concept findById(String conceptId); @Override Set<String> getAllTopLevelHierarchies(); @Override Set<String> findStatedAncestorsOfConcept(Concept concept); @Override Set<String> findTopLevelHierarchiesOfConcept(Concept concept); @Override Set<String> findStatedAncestorsOfConcepts(List<String> conceptIds);  }
@Test public void testFindTopLevelHierachiesOfConcept() { Concept concept = new DroolsConcept("1263005", true, "900000000000207008", "900000000000073002", true, true); Set<String> results = droolsConceptService.findTopLevelHierarchiesOfConcept(concept); Assert.assertEquals(1, results.size()); Assert.assertTrue(results.contains("123037004")); }