|
5 | 5 |
|
6 | 6 | <select id="getSampleClinicalDataFromStudyViewFilter" resultMap="clinicalDataSummaryResultMap"> |
7 | 7 | SELECT |
8 | | - internal_id as internalId, |
9 | | - replaceOne(sample_unique_id, concat(cancer_study_identifier, '_'), '') as sampleId, |
10 | | - replaceOne(patient_unique_id, concat(cancer_study_identifier, '_'), '') as patientId, |
11 | | - attribute_name as attrId, |
12 | | - attribute_value as attrValue, |
13 | | - cancer_study_identifier as studyId |
| 8 | + internal_id as internalId, |
| 9 | + replaceOne(sample_unique_id, concat(cancer_study_identifier, '_'), '') as sampleId, |
| 10 | + replaceOne(patient_unique_id, concat(cancer_study_identifier, '_'), '') as patientId, |
| 11 | + attribute_name as attrId, |
| 12 | + attribute_value as attrValue, |
| 13 | + cancer_study_identifier as studyId |
14 | 14 | FROM clinical_data_derived |
15 | 15 | <where> |
16 | 16 | <include refid="org.cbioportal.infrastructure.repository.clickhouse.studyview.ClickhouseStudyViewFilterMapper.applyStudyViewFilterUsingSampleId"/> |
17 | 17 | </where> |
| 18 | + <if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()"> |
| 19 | + AND cancer_study_identifier IN |
| 20 | + <foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")"> |
| 21 | + #{studyId} |
| 22 | + </foreach> |
| 23 | + </if> |
18 | 24 | <if test="attributeIds != null and !attributeIds.isEmpty()"> |
19 | 25 | AND attribute_name IN |
20 | 26 | <foreach item="attributeId" collection="attributeIds" open="(" separator="," close=")"> |
|
26 | 32 |
|
27 | 33 | <select id="getPatientClinicalDataFromStudyViewFilter" resultMap="clinicalDataSummaryResultMap"> |
28 | 34 | SELECT |
29 | | - internal_id as internalId, |
30 | | - replaceOne(patient_unique_id, concat(cancer_study_identifier, '_'), '') as patientId, |
31 | | - NULL as sampleId, |
32 | | - attribute_name as attrId, |
33 | | - attribute_value as attrValue, |
34 | | - cancer_study_identifier as studyId |
| 35 | + internal_id as internalId, |
| 36 | + replaceOne(patient_unique_id, concat(cancer_study_identifier, '_'), '') as patientId, |
| 37 | + NULL as sampleId, |
| 38 | + attribute_name as attrId, |
| 39 | + attribute_value as attrValue, |
| 40 | + cancer_study_identifier as studyId |
35 | 41 | FROM clinical_data_derived |
36 | 42 | <where> |
37 | 43 | <include refid="org.cbioportal.infrastructure.repository.clickhouse.studyview.ClickhouseStudyViewFilterMapper.applyStudyViewFilterUsingPatientId"/> |
38 | 44 | </where> |
| 45 | + <if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()"> |
| 46 | + AND cancer_study_identifier IN |
| 47 | + <foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")"> |
| 48 | + #{studyId} |
| 49 | + </foreach> |
| 50 | + </if> |
39 | 51 | <if test="attributeIds != null and !attributeIds.isEmpty()"> |
40 | 52 | AND attribute_name IN |
41 | 53 | <foreach item="attributeId" collection="attributeIds" open="(" separator="," close=")"> |
|
107 | 119 |
|
108 | 120 | <sql id="fetchClinicalDataWhereClause"> |
109 | 121 | WHERE cd.type = #{clinicalDataType} |
| 122 | + <if test="studyIds != null and !studyIds.isEmpty()"> |
| 123 | + AND cd.cancer_study_identifier IN |
| 124 | + <foreach item="studyId" collection="studyIds" open="(" separator="," close=")"> |
| 125 | + #{studyId} |
| 126 | + </foreach> |
| 127 | + </if> |
110 | 128 | <if test="uniqueIds != null and !uniqueIds.isEmpty()"> |
111 | 129 | AND |
112 | 130 | <choose> |
|
134 | 152 | SELECT COUNT(*) |
135 | 153 | FROM clinical_data_derived cd |
136 | 154 | WHERE cd.type = #{clinicalDataType} |
| 155 | + <if test="studyIds != null and !studyIds.isEmpty()"> |
| 156 | + AND cd.cancer_study_identifier IN |
| 157 | + <foreach item="studyId" collection="studyIds" open="(" separator="," close=")"> |
| 158 | + #{studyId} |
| 159 | + </foreach> |
| 160 | + </if> |
137 | 161 | <if test="uniqueIds != null and !uniqueIds.isEmpty()"> |
138 | 162 | AND |
139 | 163 | <choose> |
|
191 | 215 | ( |
192 | 216 | WITH clinical_data_query AS ( |
193 | 217 | SELECT |
194 | | - attribute_name AS attributeId, |
195 | | - attribute_value AS value, |
196 | | - cast(count(*) AS INTEGER) as count |
| 218 | + attribute_name AS attributeId, |
| 219 | + attribute_value AS value, |
| 220 | + cast(count(*) AS INTEGER) as count |
197 | 221 | FROM clinical_data_derived cdd |
198 | 222 | <if test="'${isConflicting}' == 'true'"> |
199 | 223 | <!-- JOIN patient data with sample table to map patient-level attributes to sample-level counts --> |
200 | 224 | LEFT JOIN sample_derived sd ON cdd.patient_unique_id = sd.patient_unique_id |
201 | 225 | </if> |
202 | 226 | <where> |
| 227 | + <if test="studyViewFilterContext.customDataFilterCancerStudies != null and !studyViewFilterContext.customDataFilterCancerStudies.isEmpty()"> |
| 228 | + AND cdd.cancer_study_identifier IN |
| 229 | + <foreach item="studyId" collection="studyViewFilterContext.customDataFilterCancerStudies" open="(" separator="," close=")"> |
| 230 | + #{studyId} |
| 231 | + </foreach> |
| 232 | + </if> |
203 | 233 | AND <!-- Table creation in clickhouse.sql has ensured no NA values but extra caution is always appreciated --> |
204 | 234 | <include refid="org.cbioportal.infrastructure.repository.clickhouse.studyview.ClickhouseStudyViewFilterMapper.normalizeAttributeValue"> |
205 | 235 | <property name="attribute_value" value="value"/> |
|
0 commit comments