|
273 | 273 | ON clinical_sample.internal_id = sample_id_subquery.internal_id |
274 | 274 | </sql> |
275 | 275 |
|
| 276 | + <select id="getVisibleSampleInternalIdsForClinicalTable" resultType="Integer"> |
| 277 | + <bind name="doSearch" value="_parameter.containsKey('searchTerm') and searchTerm != null and not searchTerm.isBlank()" /> |
| 278 | + <bind name="doSort" value="_parameter.containsKey('sortAttrId') and sortAttrId != null" /> |
| 279 | + <bind name="doPaginate" value="_parameter.containsKey('limit') and limit != null and limit != 0" /> |
| 280 | + <bind name="sortBySampleId" value="sortAttrId == 'sampleId'" /> |
| 281 | + <bind name="sortByPatientId" value="sortAttrId == 'patientId'" /> |
| 282 | + <bind name="sortByAttribute" value="sortAttrId != 'sampleId' and sortAttrId != 'patientId'" /> |
| 283 | + SELECT sample.internal_id FROM sample |
| 284 | + INNER JOIN patient ON sample.patient_id = patient.internal_id |
| 285 | + INNER JOIN cancer_study ON patient.cancer_study_id = cancer_study.cancer_study_id |
| 286 | + <if test="doSort"> |
| 287 | + LEFT JOIN (<include refid="sortAttributeData"/>) as sortData |
| 288 | + ON sample.internal_id = sortData.sampleInternalId |
| 289 | + </if> |
| 290 | + <if test="doSearch"> |
| 291 | + INNER JOIN (<include refid="searchedAttributeData"/>) as searchData |
| 292 | + ON sample.internal_id = searchData.sampleInternalId |
| 293 | + </if> |
| 294 | + <include refid="whereSample"/> |
| 295 | + <if test="doSort"> |
| 296 | + <choose> |
| 297 | + <when test="sortBySampleId"> |
| 298 | + ORDER BY sample.stable_id ${direction} |
| 299 | + </when> |
| 300 | + <when test="sortByPatientId"> |
| 301 | + ORDER BY patient.stable_id ${direction} |
| 302 | + </when> |
| 303 | + <when test="sortByAttribute"> |
| 304 | + <choose> |
| 305 | + <when test="_databaseId == 'mysql'"> |
| 306 | + ORDER BY ISNULL(sortData.sortAttrValue), sortData.sortAttrValue ${direction} |
| 307 | + </when> |
| 308 | + <when test="_databaseId == 'h2'"> |
| 309 | + ORDER BY sortData.sortAttrValue ${direction} NULLS LAST |
| 310 | + </when> |
| 311 | + </choose> |
| 312 | + </when> |
| 313 | + <otherwise></otherwise> |
| 314 | + </choose> |
| 315 | + </if> |
| 316 | + <if test="doPaginate"> |
| 317 | + LIMIT #{limit} OFFSET #{offset} |
| 318 | + </if> |
| 319 | + </select> |
| 320 | + |
| 321 | + <sql id="searchedAttributeData"> |
| 322 | + SELECT |
| 323 | + DISTINCT sample.internal_id sampleInternalId |
| 324 | + FROM sample |
| 325 | + INNER JOIN patient ON patient.internal_id = sample.patient_id |
| 326 | + INNER JOIN cancer_study ON patient.cancer_study_id = cancer_study.cancer_study_id |
| 327 | + INNER JOIN clinical_sample cs on sample.internal_id = cs.internal_id |
| 328 | + INNER JOIN clinical_patient cp on patient.internal_id = cp.internal_id |
| 329 | + <include refid="whereSample"/> |
| 330 | + AND ( |
| 331 | + cs.ATTR_VALUE LIKE CONCAT('%', #{searchTerm}, '%') |
| 332 | + OR cp.ATTR_VALUE LIKE CONCAT('%', #{searchTerm}, '%') |
| 333 | + OR sample.STABLE_ID LIKE CONCAT('%', #{searchTerm}, '%') |
| 334 | + OR patient.STABLE_ID LIKE CONCAT('%', #{searchTerm}, '%') |
| 335 | + ) |
| 336 | + </sql> |
| 337 | + |
| 338 | + <sql id="sortAttributeData"> |
| 339 | + <choose> |
| 340 | + <when test="sortIsPatientAttr"> |
| 341 | + SELECT sample.internal_id sampleInternalId, sample.stable_id sampleId, patient.stable_id patientId, clinical_patient.attr_id sortAttrId, |
| 342 | + <choose> |
| 343 | + <when test="sortAttrIsNumber">CONVERT(clinical_patient.attr_value, DECIMAL) sortAttrValue |
| 344 | + </when> |
| 345 | + <otherwise> |
| 346 | + clinical_patient.attr_value sortAttrValue |
| 347 | + </otherwise> |
| 348 | + </choose> |
| 349 | + FROM sample |
| 350 | + INNER JOIN patient ON sample.patient_id = patient.internal_id |
| 351 | + INNER JOIN cancer_study ON patient.cancer_study_id = cancer_study.cancer_study_id |
| 352 | + LEFT JOIN clinical_patient ON patient.internal_id = clinical_patient.internal_id AND clinical_patient.attr_id = #{sortAttrId} |
| 353 | + </when> |
| 354 | + <otherwise> |
| 355 | + SELECT sample.internal_id sampleInternalId, sample.stable_id sampleId, patient.stable_id patientId, clinical_sample.attr_id sortAttrId, |
| 356 | + <choose> |
| 357 | + <when test="sortAttrIsNumber"> |
| 358 | + CONVERT(clinical_sample.attr_value, DECIMAL) sortAttrValue |
| 359 | + </when> |
| 360 | + <otherwise> |
| 361 | + clinical_sample.attr_value sortAttrValue |
| 362 | + </otherwise> |
| 363 | + </choose> |
| 364 | + FROM clinical_sample |
| 365 | + INNER JOIN sample ON clinical_sample.internal_id = sample.internal_id |
| 366 | + INNER JOIN patient ON sample.patient_id = patient.internal_id |
| 367 | + INNER JOIN cancer_study ON patient.cancer_study_id = cancer_study.cancer_study_id |
| 368 | + WHERE clinical_sample.attr_id = #{sortAttrId} |
| 369 | + </otherwise> |
| 370 | + </choose> |
| 371 | + </sql> |
| 372 | + |
| 373 | + <select id="getSampleClinicalDataBySampleInternalIds" resultType="org.cbioportal.legacy.model.ClinicalData"> |
| 374 | + <!-- Always 'SUMMARY' projection. 'DETAILED' not implemented. --> |
| 375 | + SELECT sample.internal_id internalId, sample.stable_id sampleId, patient.stable_id patientId, cancer_study.cancer_study_identifier studyId, clinical_sample.attr_id attrId, clinical_sample.attr_value attrValue |
| 376 | + FROM clinical_sample |
| 377 | + INNER JOIN sample ON clinical_sample.internal_id = sample.internal_id |
| 378 | + INNER JOIN patient ON sample.patient_id = patient.internal_id |
| 379 | + INNER JOIN cancer_study ON patient.cancer_study_id = cancer_study.cancer_study_id |
| 380 | + WHERE sample.internal_id IN |
| 381 | + <foreach item="item" collection="sampleInternalIds" open="(" separator="," close=")"> |
| 382 | + #{item} |
| 383 | + </foreach> |
| 384 | + </select> |
| 385 | + |
| 386 | + <select id="getPatientClinicalDataBySampleInternalIds" resultType="org.cbioportal.legacy.model.ClinicalData"> |
| 387 | + <!-- Always 'SUMMARY' projection. 'DETAILED' not implemented. --> |
| 388 | + SELECT sample.internal_id internalId, sample.stable_id sampleId, patient.stable_id patientId, cancer_study.cancer_study_identifier studyId, clinical_patient.attr_id attrId, clinical_patient.attr_value attrValue |
| 389 | + FROM clinical_patient |
| 390 | + INNER JOIN patient ON clinical_patient.internal_id = patient.internal_id |
| 391 | + INNER JOIN sample ON patient.internal_id = sample.patient_id |
| 392 | + INNER JOIN cancer_study ON patient.cancer_study_id = cancer_study.cancer_study_id |
| 393 | + WHERE sample.internal_id IN |
| 394 | + <foreach item="item" collection="sampleInternalIds" open="(" separator="," close=")"> |
| 395 | + #{item} |
| 396 | + </foreach> |
| 397 | + </select> |
| 398 | + |
276 | 399 | </mapper> |
0 commit comments