Skip to content

Commit

Permalink
Merge pull request #125 from KPMP/KPMP-4861_update_getatlassummaryrows
Browse files Browse the repository at this point in the history
KPMP-4861: Update endpoint to return counts for tissue type
  • Loading branch information
rlreamy authored Feb 22, 2024
2 parents c54cd4a + 168a0b6 commit 0d22891
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 108 deletions.
46 changes: 28 additions & 18 deletions src/main/java/org/kpmp/dataSummary/AtlasRepoSummaryRow.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,56 @@
package org.kpmp.dataSummary;

public class AtlasRepoSummaryRow {
private int openCount;
private int controlledCount;
private String omicsType;
private AtlasRepositoryLinkInformation linkInformation;
private Long akiCount;
private Long ckdCount;
private Long hrtCount;
private Long dmrCount;

public AtlasRepoSummaryRow(String omicsType, AtlasRepositoryLinkInformation linkInformation) {
this.omicsType = omicsType;
this.linkInformation = linkInformation;
}

public int getOpenCount() {
return openCount;
public Long getAkiCount() {
return this.akiCount;
}

public void setOpenCount(int openCount) {
this.openCount = openCount;
public void setAkiCount(Long akiCount) {
this.akiCount = akiCount;
}

public int getControlledCount() {
return controlledCount;
public Long getCkdCount() {
return this.ckdCount;
}

public void setControlledCount(int controlledCount) {
this.controlledCount = controlledCount;
public void setCkdCount(Long ckdCount) {
this.ckdCount = ckdCount;
}

public String getOmicsType() {
return omicsType;
public Long getHrtCount() {
return this.hrtCount;
}

public void setOmicsType(String omicsType) {
this.omicsType = omicsType;
public void setHrtCount(Long hrtCount) {
this.hrtCount = hrtCount;
}

public Long getDmrCount() {
return this.dmrCount;
}

public void addToControlledCount(int count) {
this.controlledCount = this.controlledCount + count;
public void setDmrCount(Long dmrCount) {
this.dmrCount = dmrCount;
}

public void addToOpenCount(int count) {
this.openCount = this.openCount + count;
public String getOmicsType() {
return omicsType;
}

public void setOmicsType(String omicsType) {
this.omicsType = omicsType;
}

public AtlasRepositoryLinkInformation getLinkInformation() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/kpmp/dataSummary/DataSummaryRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public interface DataSummaryRepository extends CrudRepository<DataSummaryValue,
+ "join file f on f.file_id= fp.file_id " + "join sv_file_info sv on sv.file_id = f.file_id "
+ "where sv.config_type = :data_type " + "and p.tissue_type = :tissue_type", nativeQuery = true)
Long getDataSummaryCount(@Param("tissue_type") String tissue_type, @Param("data_type") String data_type);

@Cacheable("repoDataSummaryCount")
@Query(value = "select count(distinct(dl_file_id)) from repo_file_v where experimental_strategy = :exp_strat and tissue_type = :tissue_type", nativeQuery = true)
Long getRepoDataSummaryCount(@Param("tissue_type") String tissue_type, @Param("exp_strat") String exp_strat);

@Cacheable("dataSummaryLinkCount")
@Query(value = "select count(distinct(redcap_id)) " + "from sv_link_v " + "where data_type = :data_type "
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/org/kpmp/dataSummary/DataSummaryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,30 @@ private AtlasRepositoryLinkInformation getLinkInformation(ExperimentalStrategyVa

private void setCounts(ExperimentalStrategyValue experimentalStrategyValue, AtlasRepoSummaryRow atlasRepoSummaryRow)
throws Exception {
if (experimentalStrategyValue.getAccess().equalsIgnoreCase(OPEN_ACCESS)) {
atlasRepoSummaryRow.addToOpenCount(experimentalStrategyValue.getCount());
} else if (experimentalStrategyValue.getAccess().equalsIgnoreCase(CONTROLLED_ACCESS)) {
atlasRepoSummaryRow.addToControlledCount(experimentalStrategyValue.getCount());
} else {
throw new Exception(
"Unexpected access value while getting summary counts: " + experimentalStrategyValue.getAccess());
}
atlasRepoSummaryRow.setAkiCount(
dataSummaryRepository.getRepoDataSummaryCount(
TissueTypeEnum.AKI.getParticipantTissueType(),
experimentalStrategyValue.getExperimentalStrategy()
)
);
atlasRepoSummaryRow.setCkdCount(
dataSummaryRepository.getRepoDataSummaryCount(
TissueTypeEnum.CKD.getParticipantTissueType(),
experimentalStrategyValue.getExperimentalStrategy()
)
);
atlasRepoSummaryRow.setHrtCount(
dataSummaryRepository.getRepoDataSummaryCount(
TissueTypeEnum.HEALTHY_REFERENCE.getParticipantTissueType(),
experimentalStrategyValue.getExperimentalStrategy()
)
);
atlasRepoSummaryRow.setDmrCount(
dataSummaryRepository.getRepoDataSummaryCount(
TissueTypeEnum.DMR.getParticipantTissueType(),
experimentalStrategyValue.getExperimentalStrategy()
)
);
}

public List<DataTypeSummary> getSummaryData() {
Expand Down
12 changes: 7 additions & 5 deletions src/main/resources/knowledge_environment.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ type AtlasRepoSummaryResult {
}

type AtlasRepoSummaryRow {
openCount: Int
controlledCount: Int
akiCount: Long
ckdCount: Long
hrtCount: Long
dmrCount: Long
omicsType: String
linkInformation: AtlasRepoSummaryLinkInformation
linkInformation: AtlasRepositoryLinkInformationInformation
}

type AtlasRepoSummaryLinkInformation {
type AtlasRepositoryLinkInformationInformation {
linkType: String
linkValue: String
}
Expand Down Expand Up @@ -72,7 +74,7 @@ type ParticipantRepoDataTypeSummary {
type ParticipantRepoDataTypeInformation {
dataType: String
count: Long
linkInformation: AtlasRepoSummaryLinkInformation
linkInformation: AtlasRepositoryLinkInformationInformation
}

type DataTypeSummaryInformation {
Expand Down
36 changes: 16 additions & 20 deletions src/test/java/org/kpmp/dataSummary/AtlasRepoSummaryRowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,40 @@ public void testConstructor() throws Exception {

assertEquals("stuff", rowToTest.getOmicsType());
assertEquals(expectedLinkInformation, rowToTest.getLinkInformation());
assertEquals(0, rowToTest.getOpenCount());
assertEquals(0, rowToTest.getControlledCount());
}

@Test
public void testSetOpenCount() {
row.setOpenCount(43);
public void testSetAkiCount() {
row.setAkiCount(Long.valueOf(43));

assertEquals(43, row.getOpenCount());
assertEquals(Long.valueOf(43), row.getAkiCount());
}

@Test
public void testSetControlledCount() {
row.setControlledCount(44);
public void testSetCkdCount() {
row.setCkdCount(Long.valueOf(44));

assertEquals(44, row.getControlledCount());
assertEquals(Long.valueOf(44), row.getCkdCount());
}

@Test
public void testSetOmicsType() {
row.setOmicsType("omicsType 2");
assertEquals("omicsType 2", row.getOmicsType());
public void testSetHrtCount() {
row.setHrtCount(Long.valueOf(45));

assertEquals(Long.valueOf(45), row.getHrtCount());
}

@Test
public void testAddToControlledCount() {
row.setControlledCount(2);
row.addToControlledCount(30);
public void testSetDmrCount() {
row.setDmrCount(Long.valueOf(46));

assertEquals(32, row.getControlledCount());
assertEquals(Long.valueOf(46), row.getDmrCount());
}

@Test
public void testAddToOpenCount() {
row.setOpenCount(5);
row.addToOpenCount(5);

assertEquals(10, row.getOpenCount());
public void testSetOmicsType() {
row.setOmicsType("omicsType 2");
assertEquals("omicsType 2", row.getOmicsType());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.junit.Before;
import org.junit.Test;

public class AtlasRepoSummaryLinkInformationTest {
public class AtlasRepositoryLinkInformationTest {

@Before
public void setUp() throws Exception {
Expand Down
143 changes: 87 additions & 56 deletions src/test/java/org/kpmp/dataSummary/DataSummaryServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;

import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -43,63 +44,93 @@ public void tearDown() throws Exception {

@Test
public void testGetAtlasRepoSummary() throws Exception {
ExperimentalStrategyValue clinicalData = new ExperimentalStrategyValue();
clinicalData.setDataCategory("stuff");
clinicalData.setExperimentalStrategy("");
clinicalData.setDataType("Clinical Study Data");
clinicalData.setCount(1);
clinicalData.setAccess("open");
ExperimentalStrategyValue biomarker1 = new ExperimentalStrategyValue();
biomarker1.setDataCategory("Biomarker");
biomarker1.setExperimentalStrategy("something");
biomarker1.setDataType("stuff");
biomarker1.setDataCategory("Biomarker");
biomarker1.setCount(5);
biomarker1.setAccess("open");
ExperimentalStrategyValue biomarker2 = new ExperimentalStrategyValue();
biomarker2.setDataCategory("Biomarker");
biomarker2.setDataType("more stuff");
biomarker2.setExperimentalStrategy("something else");
biomarker2.setDataCategory("Biomarker");
biomarker2.setCount(10);
biomarker2.setAccess("open");
ExperimentalStrategyValue other1 = new ExperimentalStrategyValue();
other1.setDataCategory("data category");
other1.setDataType("different stuff");
other1.setExperimentalStrategy("strategy1");
other1.setCount(10);
other1.setAccess("open");
ExperimentalStrategyValue other2 = new ExperimentalStrategyValue();
other2.setDataCategory("data category2");
other2.setDataType("even more different stuff");
other2.setExperimentalStrategy("strategy1");
other2.setCount(10);
other2.setAccess("controlled");
List<ExperimentalStrategyValue> strategyValues = Arrays.asList(clinicalData, biomarker1, biomarker2, other1,
other2);
when(atlasRepoSummaryRepository.findAll()).thenReturn(strategyValues);
when(fileInfoService.getRepositoryTotalFileCount()).thenReturn(36l);

AtlasRepoSummaryResult result = dataSummaryService.getAtlasRepoSummary();
List<AtlasRepoSummaryRow> summaryRows = result.getSummaryRows();
assertEquals(3, summaryRows.size());
assertEquals("Biomarkers", summaryRows.get(0).getOmicsType());
assertEquals(0, summaryRows.get(0).getControlledCount());
assertEquals(15, summaryRows.get(0).getOpenCount());
assertEquals(new AtlasRepositoryLinkInformation("data_category", "Biomarker"),
summaryRows.get(0).getLinkInformation());
assertEquals("Clinical Study Data", summaryRows.get(1).getOmicsType());
assertEquals(0, summaryRows.get(1).getControlledCount());
assertEquals(1, summaryRows.get(1).getOpenCount());
assertEquals(new AtlasRepositoryLinkInformation("data_category", "stuff"),
summaryRows.get(1).getLinkInformation());
assertEquals("strategy1", summaryRows.get(2).getOmicsType());
assertEquals(10, summaryRows.get(2).getControlledCount());
assertEquals(10, summaryRows.get(2).getOpenCount());
assertEquals(new AtlasRepositoryLinkInformation("experimental_strategy", "strategy1"),
summaryRows.get(2).getLinkInformation());
assertEquals(Long.valueOf(36), result.getTotalFiles());
List<ExperimentalStrategyValue> strategies = new ArrayList<>(
Arrays.asList(
new ExperimentalStrategyValue(),
new ExperimentalStrategyValue(),
new ExperimentalStrategyValue(),
new ExperimentalStrategyValue()
)
);

strategies.get(0).setExperimentalStrategy("abcd");
strategies.get(0).setDataCategory("Biomarker");
strategies.get(0).setDataType("datatype");

strategies.get(1).setExperimentalStrategy("");
strategies.get(1).setDataCategory("category");
strategies.get(1).setDataType("Clinical Study Data");

strategies.get(2).setExperimentalStrategy("strategy1");
strategies.get(2).setDataCategory("category1");
strategies.get(2).setDataType("datatype");

strategies.get(3).setExperimentalStrategy("strategy2");
strategies.get(3).setDataCategory("category2");
strategies.get(3).setDataType("datatype");

when(atlasRepoSummaryRepository.findAll()).thenReturn(strategies);
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.AKI.getParticipantTissueType(),
"abcd")).thenReturn(Long.valueOf(1));
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.CKD.getParticipantTissueType(),
"abcd")).thenReturn(Long.valueOf(2));
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.HEALTHY_REFERENCE.getParticipantTissueType(),
"abcd")).thenReturn(Long.valueOf(3));
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.DMR.getParticipantTissueType(),
"abcd")).thenReturn(4l);

when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.AKI.getParticipantTissueType(),
"")).thenReturn(Long.valueOf(5));
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.CKD.getParticipantTissueType(),
"")).thenReturn(Long.valueOf(6));
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.HEALTHY_REFERENCE.getParticipantTissueType(),
"")).thenReturn(Long.valueOf(7));
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.DMR.getParticipantTissueType(),
"")).thenReturn(8l);

when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.AKI.getParticipantTissueType(),
"strategy1")).thenReturn(Long.valueOf(9));
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.CKD.getParticipantTissueType(),
"strategy1")).thenReturn(Long.valueOf(10));
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.HEALTHY_REFERENCE.getParticipantTissueType(),
"strategy1")).thenReturn(Long.valueOf(11));
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.DMR.getParticipantTissueType(),
"strategy1")).thenReturn(12l);

when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.AKI.getParticipantTissueType(),
"strategy2")).thenReturn(Long.valueOf(13));
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.CKD.getParticipantTissueType(),
"strategy2")).thenReturn(Long.valueOf(14));
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.HEALTHY_REFERENCE.getParticipantTissueType(),
"strategy2")).thenReturn(Long.valueOf(15));
when(dataSummaryRepository.getRepoDataSummaryCount(TissueTypeEnum.DMR.getParticipantTissueType(),
"strategy2")).thenReturn(16l);

List<AtlasRepoSummaryRow> result = dataSummaryService.getAtlasRepoSummary().getSummaryRows();

assertEquals("Biomarkers", result.get(0).getOmicsType());
assertEquals(Long.valueOf(1), result.get(0).getAkiCount());
assertEquals(Long.valueOf(2), result.get(0).getCkdCount());
assertEquals(Long.valueOf(3), result.get(0).getHrtCount());
assertEquals(Long.valueOf(4), result.get(0).getDmrCount());

assertEquals("Clinical Study Data", result.get(1).getOmicsType());
assertEquals(Long.valueOf(5), result.get(1).getAkiCount());
assertEquals(Long.valueOf(6), result.get(1).getCkdCount());
assertEquals(Long.valueOf(7), result.get(1).getHrtCount());
assertEquals(Long.valueOf(8), result.get(1).getDmrCount());

assertEquals("strategy1", result.get(2).getOmicsType());
assertEquals(Long.valueOf(9), result.get(2).getAkiCount());
assertEquals(Long.valueOf(10), result.get(2).getCkdCount());
assertEquals(Long.valueOf(11), result.get(2).getHrtCount());
assertEquals(Long.valueOf(12), result.get(2).getDmrCount());

assertEquals("strategy2", result.get(3).getOmicsType());
assertEquals(Long.valueOf(13), result.get(3).getAkiCount());
assertEquals(Long.valueOf(14), result.get(3).getCkdCount());
assertEquals(Long.valueOf(15), result.get(3).getHrtCount());
assertEquals(Long.valueOf(16), result.get(3).getDmrCount());
}

@Test
Expand Down

0 comments on commit 0d22891

Please sign in to comment.