Skip to content

Commit

Permalink
add comments to filter sql
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Lai authored and haynescd committed Aug 14, 2024
1 parent 096952e commit d46400f
Showing 1 changed file with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,49 +66,44 @@
'${sampleIdentifier.studyId}_${sampleIdentifier.sampleId}'
</foreach>
</if>
<!-- custom data filter -->
<if test="studyViewFilter.customDataFilters != null and !studyViewFilter.customDataFilters.isEmpty() and customDataSamples != null">
INTERSECT
SELECT sample_unique_id
FROM sample_derived
<!-- customDataSamples are samples filtered based on the customDataFilters -->
<!-- filter for samples in customDataSamples if customDataSamples isn't empty, else all samples are filtered out -->
<choose>
<when test="!customDataSamples.isEmpty()">
WHERE
<trim prefix="" prefixOverrides="AND">
<foreach item="customDataFilter" collection="studyViewFilter.customDataFilters">
AND
(
sample_unique_id IN (
'',
WHERE
<trim prefix="" prefixOverrides="AND">
<!-- filter for samples that pass all customDataFilters (using AND logic on samples passing each filter) -->
<foreach item="customDataFilter" collection="studyViewFilter.customDataFilters">
AND
(
<!-- filter for samples that pass the customDataFilter excluding NA logic -->
<!-- samples pass the customDataFilter if they are not filtered out (getIsFilteredOut() is false) -->
<!-- in the event customDataSamples is empty, all samples are filtered out -->
sample_unique_id IN (
'',
<foreach item="sampleIdentifier" collection="customDataSamples" separator=",">
<if test="customDataFilter.attributeId == sampleIdentifier.getAttributeId() and !sampleIdentifier.getIsFilteredOut()">
'${sampleIdentifier.studyId}_${sampleIdentifier.sampleId}'
</if>
</foreach>
)
<!-- if customDataFilter contains NA value, filter for samples that are not in the user submitted custom list (customDataSamples) -->
<!-- use OR logic to get the samples that pass the NA or non-NA logic of the customDataFilter -->
<foreach item="customDataFilterValue" collection="customDataFilter.values">
<if test="customDataFilterValue.value eq 'NA'">
OR
sample_unique_id NOT IN (
<foreach item="sampleIdentifier" collection="customDataSamples" separator=",">
<if test="customDataFilter.attributeId == sampleIdentifier.getAttributeId() and !sampleIdentifier.getIsFilteredOut()">
<if test="customDataFilter.attributeId == sampleIdentifier.getAttributeId()">
'${sampleIdentifier.studyId}_${sampleIdentifier.sampleId}'
</if>
</foreach>
)
<foreach item="customDataFilterValue" collection="customDataFilter.values">
<if test="customDataFilterValue.value eq 'NA'">
OR
sample_unique_id NOT IN (
'',
<foreach item="sampleIdentifier" collection="customDataSamples" separator=",">
<if test="customDataFilter.attributeId == sampleIdentifier.getAttributeId()">
'${sampleIdentifier.studyId}_${sampleIdentifier.sampleId}'
</if>
</foreach>
)
</if>
</foreach>
)
</if>
</foreach>
</trim>
</when>
<otherwise>
''
</otherwise>
</choose>
)
</foreach>
</trim>
</if>
<if test="studyViewFilter.geneFilters != null and !studyViewFilter.geneFilters.isEmpty()">
<foreach item="profileGroup" collection="studyViewFilter.geneFilters">
Expand Down

0 comments on commit d46400f

Please sign in to comment.