Skip to content

Commit

Permalink
remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
haynescd committed Jul 7, 2023
1 parent 9178c29 commit 4fa24f1
Showing 1 changed file with 15 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@

<!-- for /clinical-data-counts/fetch (returns ClinicalData) which will then be converted to clinicalDataCountItems -->
<select id="getClinicalDataCounts" resultType="org.cbioportal.model.ClinicalDataCount">
<include refid="getPatientClinicalDataCountsQuery"/>
<include refid="getCategoricalClinicalDataCountsQuery">
<property name="table_name_prefix" value="patient"/>
</include>
UNION ALL
<include refid="getSampleClinicalDataCountsQuery"/>
<include refid="getCategoricalClinicalDataCountsQuery">
<property name="table_name_prefix" value="sample"/>
</include>
</select>
<sql id="getPatientClinicalDataCountsQuery">
<sql id="getCategoricalClinicalDataCountsQuery">
SELECT
attribute_name as attributeId,
CASE WHEN attribute_value = 'NULL' THEN 'NA' ELSE attribute_value END AS value,
Count(*) as count
FROM patient_clinical_attribute_categorical
FROM ${table_name_prefix}_clinical_attribute_categorical
<where>
patient_unique_id IN ( <include refid="getPatientIdsFromSampleIdFilters"/>
<if test="applyPatientIdFilters == true">
Expand All @@ -72,38 +76,18 @@
</foreach>
</where>
GROUP BY attribute_name,
attribute_value
attribute_value
</sql>
<select id="getPatientClinicalDataCounts" resultType="org.cbioportal.model.ClinicalDataCount">
<include refid="getPatientClinicalDataCountsQuery"/>
<include refid="getCategoricalClinicalDataCountsQuery">
<property name="table_name_prefix" value="patient"/>
</include>
</select>
<select id="getSampleClinicalDataCounts" resultType="org.cbioportal.model.ClinicalDataCount">
<include refid="getSampleClinicalDataCountsQuery"/>
<include refid="getCategoricalClinicalDataCountsQuery">
<property name="table_name_prefix" value="sample"/>
</include>
</select>
<sql id="getSampleClinicalDataCountsQuery">
SELECT
attribute_name as attributeId,
CASE WHEN attribute_value = 'NULL' THEN 'NA' ELSE attribute_value END AS value,
Count(*) as count
FROM sample_clinical_attribute_categorical
<where>
patient_unique_id IN ( <include refid="getPatientIdsFromSampleIdFilters"/>
<if test="applyPatientIdFilters == true">
INTERSECT <include refid="patientUniqueIdsFromStudyViewFilter"/>
</if>
)
AND UPPER(attribute_value) NOT IN
<foreach item="filteredAttributeValue" collection="filteredAttributeValues" open="(" separator="," close=")">
#{filteredAttributeValue}
</foreach>
AND attribute_name IN
<foreach item="attributeId" collection="attributeIds" open="(" separator="," close=")">
#{attributeId}
</foreach>
</where>
GROUP BY attribute_name,
attribute_value
</sql>

<!-- This block represents the Study View Filter -->
<sql id="sampleUniqueIdsFromStudyViewFilter">
Expand Down

0 comments on commit 4fa24f1

Please sign in to comment.