Fix Clinical Attribute NA Filtering #11901
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



This is duplicated from #11822 due to some core tests constraints
Fix #11808
Fix Clinical Attribute NA Filtering
Summary
This PR fixes a issue in NA filtering for clinical attributes introduced by PR #11603 . The fix ensures studies without an attribute definition are properly treated as NA while preserving the attribute level conflict resolution.
Problem
When PR #11603 added logic to handle attribute level conflicts (sample vs patient level), it inadvertently broke NA filtering. Samples from studies that completely lack an attribute definition were incorrectly excluded from NA filter results.
Solution
Core NA Filtering Logic
This PR implements a comprehensive three-tier conditional logic for handling clinical attribute filtering:
1. IF study has NO attribute definition:
→ All samples treated as NA via
study_without_attributeCTE andUNION ALL2. ELSE IF study HAS the attribute at different level (sample vs patient):
→ Use data from the corresponding level only
→ Sample queries skip patient-level attributes, vice versa
→ Prevents attribute level conflicts (preserves #11603 fix)
3. ELSE IF study HAS the attribute at matching level:
→ LEFT JOIN to retrieve data
→ IF attribute_value IS NULL or empty → treated as NA
→ ELSE filter by actual value
Changes
Modified Files
ClickhouseStudyViewFilterMapper.xml
studyAttributeFilterCTEsandsamplesFromStudiesWithoutAttributeAsNASQL fragmentsnumericalClinicalDataCountFilterto use shared fragments and handle studies without attributescategoricalClinicalDataCountFilterwith same improvementsClickhouseSampleMapperTest.java
acc_tcgastudy samples (4 samples with no AGE/DEAD attributes) now correctly included in NA filters