Skip to content

Commit

Permalink
Rfc80/add na clinical data filtering (#11050)
Browse files Browse the repository at this point in the history
* Add Categorical Clinical Attribute NA filtering

* add api tests

---------

Co-authored-by: alisman <lisman.aaron@gmail.com>
  • Loading branch information
haynescd and alisman authored Oct 8, 2024
1 parent d37dcfa commit b58a18c
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 14 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,23 +408,53 @@
</if>
</trim>
</foreach>
</if>
)
</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>
) ILIKE '${dataFilterValue.value}'
</trim>
<sql id="selectAllClinicalDataByAttribute">
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 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
<foreach item="dataFilterValue" collection="clinicalDataFilter.values" open=" ((" separator=") OR (" close="))">
<choose>
<when test="dataFilterValue.value == 'NA'">
empty(attribute_value)
</when>
<otherwise>
(
<include refid="normalizeAttributeValue">
<property name="attribute_value" value="attribute_value"/>
</include>
) ILIKE '${dataFilterValue.value}'
</otherwise>
</choose>
</foreach>
AND EXISTS (<include refid="selectAllClinicalDataByAttribute"/>)
)
</sql>

<sql id="numericalGenomicDataFilter">
<!-- check if 'NA' is selected -->
Expand Down
Loading

0 comments on commit b58a18c

Please sign in to comment.