HumanPhenotypeOntologyDao implements OntologyDao { public Map<String, PhenotypeTerm> getIdToPhenotypeTerms() { String query = "SELECT alt.alt_id, alt.primary_id, hp.lcname AS term " + "FROM hp_alt_ids alt, hpo hp " + "WHERE hp.id = alt.primary_id"; Map<String, PhenotypeTerm> primaryIdToPhenotypeTerms = new HashMap<>(); ImmutableMap.Builder<String, PhenotypeTerm> alternateIdToPhenotypeTerms = ImmutableMap.builder(); try ( Connection connection = dataSource.getConnection(); PreparedStatement ontologyTermsStatement = connection.prepareStatement(query); ResultSet rs = ontologyTermsStatement.executeQuery()) { while(rs.next()) { String altId = rs.getString("alt_id"); String primaryId = rs.getString("primary_id"); String term = rs.getString("term"); PhenotypeTerm phenotypeTerm = primaryIdToPhenotypeTerms.computeIfAbsent(primaryId, key -> PhenotypeTerm.of(primaryId, term)); alternateIdToPhenotypeTerms.put(altId, phenotypeTerm); } } catch (SQLException e) { logger.error("Unable to execute query '{}' for HPO terms", query, e); } return alternateIdToPhenotypeTerms.build(); } HumanPhenotypeOntologyDao(DataSource phenotypeDataSource); @Override Set<PhenotypeTerm> getAllTerms(); @Override Set<PhenotypeMatch> getPhenotypeMatchesForHpoTerm(PhenotypeTerm hpoTerm); Map<String, PhenotypeTerm> getIdToPhenotypeTerms();  }
@Test void testGetIdToPhenotypeTerms() { PhenotypeTerm modeOfInheritance = PhenotypeTerm.of("HP:0000005", "Mode of inheritance"); PhenotypeTerm adInheritance = PhenotypeTerm.of("HP:0000006", "Autosomal dominant inheritance"); ImmutableMap.Builder<String, PhenotypeTerm> expected = ImmutableMap.builder(); expected.put("HP:0000003", multicysticKidneyDysplasia); expected.put("HP:0004715", multicysticKidneyDysplasia); expected.put("HP:0000005", modeOfInheritance); expected.put("HP:0001453", modeOfInheritance); expected.put("HP:0001461", modeOfInheritance); expected.put("HP:0000006", adInheritance); expected.put("HP:0001415", adInheritance); expected.put("HP:0001447", adInheritance); expected.put("HP:0001448", adInheritance); expected.put("HP:0001451", adInheritance); expected.put("HP:0001455", adInheritance); expected.put("HP:0001456", adInheritance); expected.put("HP:0001463", adInheritance); assertThat(instance.getIdToPhenotypeTerms(), equalTo(expected.build())); }