Skip to content

Commit

Permalink
Add Numerical Clinical Data NA Filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
haynescd committed Oct 7, 2024
1 parent 12d1454 commit 257cb6f
Showing 1 changed file with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,46 @@
</sql>

<sql id="numericalClinicalDataCountFilter">

<!-- 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="selectAllClinicalDataByAttribute"/>) 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="selectAllClinicalDataByAttribute"/>)
</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
Expand Down Expand Up @@ -368,9 +408,11 @@
</if>
</trim>
</foreach>
</if>
)
</sql>

<sql id="selectAllCategoricalClinicalDataByAttribute">
<sql id="selectAllClinicalDataByAttribute">
SELECT sample_unique_id, patient_unique_id, attribute_value
FROM clinical_data_derived
WHERE attribute_name = '${clinicalDataFilter.attributeId}' AND type='${type}'
Expand All @@ -379,17 +421,18 @@
#{studyId}
</foreach>
</sql>

<sql id="categoricalClinicalDataCountFilter">
<!-- check if 'NA' is selected -->
<bind name="userSelectsNA" value="false" />
<bind name="userSelectsNumericalValue" value="false" />
<bind name="userSelectsValue" 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" />
<bind name="userSelectsValue" value="true" />
</otherwise>
</choose>
</foreach>
Expand All @@ -398,7 +441,7 @@
<if test="userSelectsNA">
SELECT DISTINCT ${unique_id}
FROM sample_derived sd
LEFT JOIN (<include refid="selectAllCategoricalClinicalDataByAttribute"/>) AS categorical_clinical_data
LEFT JOIN (<include refid="selectAllClinicalDataByAttribute"/>) AS categorical_clinical_data
ON
<choose>
<when test="'${type}' == 'sample'">
Expand All @@ -409,16 +452,16 @@
</otherwise>
</choose>
WHERE empty(attribute_value)
AND EXISTS (<include refid="selectAllCategoricalClinicalDataByAttribute"/>)
AND EXISTS (<include refid="selectAllClinicalDataByAttribute"/>)
</if>

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

<!-- if non-NA is selected, prepare non-NA samples -->
<if test="userSelectsNumericalValue">
<if test="userSelectsValue">
SELECT ${unique_id}
FROM ${table_name}
WHERE attribute_name = '${clinicalDataFilter.attributeId}' AND
Expand Down

0 comments on commit 257cb6f

Please sign in to comment.