Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paginated clinical table #10211

Merged
merged 10 commits into from
Jun 16, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@

public class ClinicalDataCollection {

/**
* Paginated resource
*/
private List<ClinicalData> sampleClinicalData = new ArrayList<>();
private List<ClinicalData> patientClinicalData = new ArrayList<>();

/**
* Patient info associated with paginated samples
*/
private List<ClinicalData> patientClinicalData = new ArrayList<>();

public List<ClinicalData> getSampleClinicalData() {
return sampleClinicalData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ BaseMeta fetchMetaClinicalDataInStudy(String studyId, List<String> ids, List<Str
List<ClinicalData> fetchClinicalData(List<String> studyIds, List<String> ids, List<String> attributeIds,
String clinicalDataType, String projection);

List<ClinicalData> fetchSampleClinicalDataClinicalTable(List<String> studyIds, List<String> ids,
Integer pageSize, Integer pageNumber, String searchTerm,
String sortBy, String direction);
List<ClinicalData> fetchSampleClinicalTable(List<String> studyIds, List<String> ids,
Integer pageSize, Integer pageNumber, String searchTerm,
String sortBy, String direction);

@Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()")
Integer fetchSampleClinicalTableCount(List<String> studyIds, List<String> ids, String searchTerm,
String sortBy, String direction);

@Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()")
BaseMeta fetchMetaClinicalData(List<String> studyIds, List<String> ids, List<String> attributeIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ List<ClinicalData> getPatientClinicalData(List<String> studyIds, List<String> pa
String projection, Integer limit, Integer offset, String sortby,
String direction);

List<ClinicalData> getSampleClinicalDataClinicalTable(List<String> studyIds, List<String> sampleIds, String projection,
Integer limit, Integer offset, String searchTerm,
String sortBy, String direction);
List<ClinicalData> getSampleClinicalTable(List<String> studyIds, List<String> sampleIds, String projection,
Integer limit, Integer offset, String searchTerm,
String sortBy, String direction);

Integer getSampleClinicalTableCount(List<String> studyIds, List<String> sampleIds, String projection,
String searchTerm, String sortBy, String direction);

BaseMeta getMetaPatientClinicalData(List<String> studyIds, List<String> patientIds, List<String> attributeIds);

Expand All @@ -33,5 +36,4 @@ List<ClinicalDataCount> fetchPatientClinicalDataCounts(List<String> studyIds, Li
List<ClinicalData> getPatientClinicalDataDetailedToSample(List<String> studyIds, List<String> patientIds,
List<String> attributeIds, String projection, Integer limit,
Integer offset, String sortBy, String direction);

}
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,24 @@ public List<ClinicalData> fetchClinicalData(List<String> studyIds, List<String>
}

@Override
public List<ClinicalData> fetchSampleClinicalDataClinicalTable(List<String> studyIds, List<String> ids,
Integer pageSize, Integer pageNumber, String searchTerm,
String sortBy, String direction) {
public List<ClinicalData> fetchSampleClinicalTable(List<String> studyIds, List<String> ids,
Integer pageSize, Integer pageNumber, String searchTerm,
String sortBy, String direction) {
if (ids.isEmpty()) {
return new ArrayList<>();
}
int offset = offsetCalculator.calculate(pageSize, pageNumber);
return clinicalDataMapper.getSampleClinicalDataClinicalTable(studyIds, ids,"SUMMARY", pageSize,
return clinicalDataMapper.getSampleClinicalTable(studyIds, ids,"SUMMARY", pageSize,
offset, searchTerm, sortBy, direction);
}

@Override
public Integer fetchSampleClinicalTableCount(List<String> studyIds, List<String> sampleIds,
String searchTerm, String sortBy, String direction) {
return clinicalDataMapper.getSampleClinicalTableCount(studyIds, sampleIds,"SUMMARY",
searchTerm, sortBy, direction);
}

@Override
public BaseMeta fetchMetaClinicalData(List<String> studyIds, List<String> ids, List<String> attributeIds,
String clinicalDataType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
INNER JOIN cancer_study ON patient.CANCER_STUDY_ID = cancer_study.CANCER_STUDY_ID
</sql>

<sql id="fromSampleAndClinicalPatient">
<include refid="fromSample"/>
LEFT JOIN clinical_patient ON clinical_patient.INTERNAL_ID = patient.INTERNAL_ID
</sql>

<sql id="fromPatient">
FROM clinical_patient
INNER JOIN patient ON clinical_patient.INTERNAL_ID = patient.INTERNAL_ID
Expand Down Expand Up @@ -221,7 +226,7 @@
GROUP BY clinical_patient.ATTR_ID, clinical_patient.ATTR_VALUE
</select>

<select id="getSampleClinicalDataClinicalTable" resultType="org.cbioportal.model.ClinicalData">
<select id="getSampleClinicalTable" resultType="org.cbioportal.model.ClinicalData">
SELECT
<include refid="selectSample">
<property name="prefix" value=""/>
Expand All @@ -230,28 +235,55 @@
<include refid="whereSampleSearchAndPagination"/>
</select>

<select id="getSampleClinicalTableCount" resultType="Integer">
SELECT count(DISTINCT clinical_sample.INTERNAL_ID)
<include refid="fromSample"/>
<include refid="whereSampleSearchAndPagination"/>
</select>

<sql id="whereSampleSearchAndPagination">
INNER JOIN
(SELECT DISTINCT clinical_sample.INTERNAL_ID
INNER JOIN (
SELECT DISTINCT clinical_sample.INTERNAL_ID
<if test="_parameter.containsKey('sortBy') and sortBy != null">
, clinical_sample.ATTR_ID, clinical_sample.ATTR_VALUE
<if test="sortBy == 'sampleId'">
, sample.STABLE_ID AS SORT_BY
</if>
<if test="sortBy == 'patientId'">
, patient.STABLE_ID AS SORT_BY
</if>
<!-- else: -->
<if test="sortBy != 'sampleId' and sortBy != 'patientId'">
<!-- Mark samples without the sort attribute as NULL: -->
, CASE
WHEN clinical_sample.ATTR_ID = #{sortBy} THEN clinical_sample.ATTR_VALUE
WHEN clinical_patient.ATTR_ID = #{sortBy} THEN clinical_patient.ATTR_VALUE
ELSE NULL
END AS SORT_BY
</if>
</if>
<include refid="fromSample"/>
<include refid="fromSampleAndClinicalPatient"/>
BasLee marked this conversation as resolved.
Show resolved Hide resolved
<include refid="whereSample"/>
<if test="_parameter.containsKey('searchTerm') and searchTerm != null and not searchTerm.isBlank()">
AND
clinical_sample.ATTR_VALUE LIKE CONCAT('%','${searchTerm}', '%')
clinical_sample.ATTR_VALUE LIKE CONCAT('%', #{searchTerm}, '%')
</if>
<if test="_parameter.containsKey('sortBy') and sortBy != null">
AND
clinical_sample.ATTR_ID = '${sortBy}'
ORDER BY clinical_sample.ATTR_VALUE ${direction}
<!-- Put 'NULL samples' last: -->
<choose>
<when test="_databaseId == 'mysql'">
ORDER BY ISNULL(SORT_BY), SORT_BY ${direction}
</when>
<when test="_databaseId == 'h2'">
ORDER BY SORT_BY ${direction} NULLS LAST
</when>
</choose>
</if>

<if test="_parameter.containsKey('limit') and limit != null and limit != 0">
LIMIT #{limit} OFFSET #{offset}
</if>
) as sample_id_subquery
ON clinical_sample.INTERNAL_ID = sample_id_subquery.INTERNAL_ID
) AS sample_id_subquery
ON clinical_sample.INTERNAL_ID = sample_id_subquery.INTERNAL_ID
</sql>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ public void fetchClinicalDataNullAttributeSummaryProjection() {
@Test
public void fetchClinicalSampleDataClinicalTabPagingSuccess() {

List<ClinicalData> resultFirstPage = clinicalDataMyBatisRepository.fetchSampleClinicalDataClinicalTable(studyIds,
List<ClinicalData> resultFirstPage = clinicalDataMyBatisRepository.fetchSampleClinicalTable(studyIds,
sampleIds, 1, 0, noSearch, noSort, "DESC");
List<ClinicalData> resultSecondPage = clinicalDataMyBatisRepository.fetchSampleClinicalDataClinicalTable(studyIds,
List<ClinicalData> resultSecondPage = clinicalDataMyBatisRepository.fetchSampleClinicalTable(studyIds,
sampleIds, 1, 1, noSearch, noSort, "DESC");

Assert.assertEquals(4, resultFirstPage.size());
Expand All @@ -380,7 +380,7 @@ public void fetchClinicalSampleDataClinicalTabPagingSuccess() {
public void fetchClinicalSampleDataClinicalTablePagingHandleNoneExistingPage() {

// There are only two patients in total. The second page (index 1) with pageSize 2 does not refer to any records.
List<ClinicalData> resultNonExistingPage = clinicalDataMyBatisRepository.fetchSampleClinicalDataClinicalTable(
List<ClinicalData> resultNonExistingPage = clinicalDataMyBatisRepository.fetchSampleClinicalTable(
studyIds, sampleIds, 2, 1, noSearch, noSort, "DESC");

Assert.assertEquals(0, resultNonExistingPage.size());
Expand All @@ -389,15 +389,15 @@ public void fetchClinicalSampleDataClinicalTablePagingHandleNoneExistingPage() {
@Test
public void fetchClinicalSampleDataClinicalTabSearchTermSuccess() {

List<ClinicalData> resultSample1 = clinicalDataMyBatisRepository.fetchSampleClinicalDataClinicalTable(
List<ClinicalData> resultSample1 = clinicalDataMyBatisRepository.fetchSampleClinicalTable(
studyIds, sampleIds, noPaging, noPaging, "5C631CE8", noSort, "DESC");

Assert.assertEquals(4, resultSample1.size());
List<String> observedSampleIds = resultSample1.stream().map(s -> s.getSampleId()).distinct().collect(Collectors.toList());
Assert.assertEquals(1, observedSampleIds.size());
Assert.assertEquals("TCGA-A1-A0SB-01", observedSampleIds.get(0));

List<ClinicalData> resultSample2 = clinicalDataMyBatisRepository.fetchSampleClinicalDataClinicalTable(
List<ClinicalData> resultSample2 = clinicalDataMyBatisRepository.fetchSampleClinicalTable(
studyIds, sampleIds, noPaging, noPaging, "F3408556-9259", noSort, "DESC");

Assert.assertEquals(4, resultSample2.size());
Expand All @@ -409,7 +409,7 @@ public void fetchClinicalSampleDataClinicalTabSearchTermSuccess() {
@Test
public void fetchClinicalSampleDataEClinicalTabEmptyStringSearchTerm() {

List<ClinicalData> result = clinicalDataMyBatisRepository.fetchSampleClinicalDataClinicalTable(
List<ClinicalData> result = clinicalDataMyBatisRepository.fetchSampleClinicalTable(
studyIds, sampleIds, noPaging, noPaging, "", noSort, "DESC");

Assert.assertEquals(8, result.size());
Expand All @@ -418,9 +418,9 @@ public void fetchClinicalSampleDataEClinicalTabEmptyStringSearchTerm() {
@Test
public void fetchClinicalSampleDataClinicalTabSortSuccess() {

List<ClinicalData> resultSortAsc = clinicalDataMyBatisRepository.fetchSampleClinicalDataClinicalTable(studyIds,
List<ClinicalData> resultSortAsc = clinicalDataMyBatisRepository.fetchSampleClinicalTable(studyIds,
sampleIds, 1, 0, noSearch, "SAMPLE_TYPE", "ASC");
List<ClinicalData> resultSortDesc = clinicalDataMyBatisRepository.fetchSampleClinicalDataClinicalTable(studyIds,
List<ClinicalData> resultSortDesc = clinicalDataMyBatisRepository.fetchSampleClinicalTable(studyIds,
sampleIds, 1, 0, noSearch, "SAMPLE_TYPE", "DESC");

Assert.assertEquals(4, resultSortAsc.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ BaseMeta fetchMetaClinicalData(List<String> studyIds, List<String> ids, List<Str
List<ClinicalData> getPatientClinicalDataDetailedToSample(List<String> studyIds, List<String> patientIds,
List<String> attributeIds);

List<ClinicalData> fetchSampleClinicalDataClinicalTable(List<String> studyIds, List<String> sampleIds, Integer pageSize,
Integer pageNumber, String searchTerm, String sortBy, String direction);
List<ClinicalData> fetchSampleClinicalTable(List<String> studyIds, List<String> sampleIds, Integer pageSize,
Integer pageNumber, String searchTerm, String sortBy, String direction);

Integer fetchSampleClinicalTableCount(List<String> studyIds, List<String> sampleIds, String searchTerm,
String sortBy, String direction);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.cbioportal.service.impl;

import org.apache.commons.collections4.list.UnmodifiableList;
import org.cbioportal.model.*;
import org.cbioportal.model.meta.BaseMeta;
import org.cbioportal.persistence.ClinicalDataRepository;
Expand Down Expand Up @@ -228,10 +227,17 @@ public List<ClinicalData> getPatientClinicalDataDetailedToSample(List<String> st
}

@Override
public List<ClinicalData> fetchSampleClinicalDataClinicalTable(List<String> studyIds, List<String> sampleIds, Integer pageSize,
Integer pageNumber, String searchTerm, String sortBy,
String direction) {
return clinicalDataRepository.fetchSampleClinicalDataClinicalTable(studyIds, sampleIds, pageSize, pageNumber, searchTerm,
public List<ClinicalData> fetchSampleClinicalTable(List<String> studyIds, List<String> sampleIds, Integer pageSize,
Integer pageNumber, String searchTerm, String sortBy,
String direction) {
return clinicalDataRepository.fetchSampleClinicalTable(studyIds, sampleIds, pageSize, pageNumber, searchTerm,
sortBy, direction);
}

@Override
public Integer fetchSampleClinicalTableCount(List<String> studyIds, List<String> sampleIds,
String searchTerm, String sortBy, String direction) {
return clinicalDataRepository.fetchSampleClinicalTableCount(studyIds, sampleIds, searchTerm,
sortBy, direction);
}
}
Loading