Skip to content

Commit

Permalink
Add Categorical Clinical Attribute NA filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
haynescd committed Oct 7, 2024
1 parent fb8eaac commit 12d1454
Showing 1 changed file with 63 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,71 @@
</foreach>
</sql>

<sql id="selectAllCategoricalClinicalDataByAttribute">
SELECT sample_unique_id, patient_unique_id, attribute_value
FROM clinical_data_derived
WHERE attribute_name = '${clinicalDataFilter.attributeId}' AND type='${type}'
AND cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterHelper.studyViewFilter.studyIds" open="(" separator="," close=")">
#{studyId}
</foreach>
</sql>
<sql id="categoricalClinicalDataCountFilter">
SELECT ${unique_id}
FROM ${table_name}
WHERE attribute_name = '${clinicalDataFilter.attributeId}' AND
type='${type}'
<foreach item="dataFilterValue" collection="clinicalDataFilter.values" open=" AND ((" separator=") OR (" close="))">
<trim prefix="" prefixOverrides="AND">
AND (
<include refid="normalizeAttributeValue">
<property name="attribute_value" value="attribute_value"/>
</include>
) = '${dataFilterValue.value}'
</trim>
<!-- check if 'NA' is selected -->
<bind name="userSelectsNA" value="false" />
<bind name="userSelectsNumericalValue" value="false" />
<foreach item="dataFilterValue" collection="clinicalDataFilter.values">
<choose>
<when test="dataFilterValue.value == 'NA'">
<bind name="userSelectsNA" value="true" />
</when>
<otherwise>
<bind name="userSelectsNumericalValue" value="true" />
</otherwise>
</choose>
</foreach>
(
<!-- if 'NA' is selected, prepare NA samples -->
<if test="userSelectsNA">
SELECT DISTINCT ${unique_id}
FROM sample_derived sd
LEFT JOIN (<include refid="selectAllCategoricalClinicalDataByAttribute"/>) AS categorical_clinical_data
ON
<choose>
<when test="'${type}' == 'sample'">
sd.sample_unique_id = categorical_clinical_data.sample_unique_id
</when>
<otherwise>
sd.patient_unique_id = categorical_clinical_data.patient_unique_id
</otherwise>
</choose>
WHERE empty(attribute_value)
AND EXISTS (<include refid="selectAllCategoricalClinicalDataByAttribute"/>)
</if>

<!-- if both 'NA' and non-NA are selected, union them together -->
<if test="userSelectsNA and userSelectsNumericalValue">
UNION ALL
</if>

<!-- if non-NA is selected, prepare non-NA samples -->
<if test="userSelectsNumericalValue">
SELECT ${unique_id}
FROM ${table_name}
WHERE attribute_name = '${clinicalDataFilter.attributeId}' AND
type='${type}'
<foreach item="dataFilterValue" collection="clinicalDataFilter.values" open=" AND ((" separator=") OR ("
close="))">
<trim prefix="" prefixOverrides="AND">
AND (
<include refid="normalizeAttributeValue">
<property name="attribute_value" value="attribute_value"/>
</include>
) = '${dataFilterValue.value}'
</trim>
</foreach>
</if>
)
</sql>

<sql id="numericalGenomicDataFilter">
Expand Down

0 comments on commit 12d1454

Please sign in to comment.