# W-SUDA Rule Implementation (JIRA ECARS-2202)

**HISTORY:**
###### 21/10/2025: ECARS-2202 - new rule W-SUDA
###### 19/03/2026: ECARS-2352 - update W-SUDA logic

## Overview
This document describes the implementation of the W-SUDA (Survival time not consistent with Date of Incidence and Date of Follow-up) validation rule for survival analysis in the QCS.

## Rule Description
**Rule Code**: W-SUDA  
**Rule Type**: WARNING  
**Description**: Survival time not consistent with Date of Incidence and Date of Follow-up (Tab. 14)  
**Protocol**: Incidence 2022 (39 var) (Protocol ID: 11)  
**JIRA Ticket**: ECARS-2202

### Notes
    
### Rule Logic
The W-SUDA message is produced only if:
- The variables Survival time in days (Surv_time), DoI (MoI, YoI) and DoF (MoF, YoF) are **in_range** AND **different from the Unknown value**
- **AND** Surv_time (days) is outside the interval **[minDays, maxDays]** where:
- **maxDays** is the exact number of days from the **1st day of DoI** to the **last day of DoF**
- **minDays** is the exact number of days from the **last day of DoI** to the **1st day of DoF**
```
Trigger W-SUDA when: Surv_time < minDays OR Surv_time > maxDays
```
Rule Does Not Apply When:
- Any field is missing/blank
- Any field is set to unknown value (99, 9999, 99999)
- Any field fails range validation
- Parsing integer value returns WRONG

### Calculation Formula
```
- **DoI first day** = day 1 of month/year (MoI, YoI)
- **DoI last day** = end of month/year (MoI, YoI)
- **DoF first day** = day 1 of month/year (MoF, YoF)
- **DoF last day** = end of month/year (MoF, YoF)
- **maxDays** = days between DoI first day and DoF last day (inclusive)
- **minDays** = days between DoI last day and DoF first day
- **Trigger W-SUDA** if: Surv_time < minDays OR Surv_time > maxDays
```

## Implementation Files

### 1. Java Implementation
**File**: `src/main/java/eu/europa/ec/jrc/qcs/engine/rule/crossfield/encr2020/SurvivalDateAnalysisRule.java`


## Testing

# TODO:

## Files Modified

### quality-check-software project:
1. `src/main/java/eu/europa/ec/jrc/qcs/engine/rule/crossfield/encr2020/SurvivalDateAnalysisRule.java` (NEW)
2. `src/main/java/eu/europa/ec/jrc/qcs/engine/preset/DefaultRuleID.java` (MODIFIED)
3. `src/main/resources/db/W-SUDA_rule_registration.sql` (NEW - SQL script)
4. `qcs.db` (TO BE UPDATED - see instructions above)


## Rule Positioning
The W-SUDA rule has been positioned:
- **Priority Level**: 7 (Cross-field validation rules)
- **Execution Order**: After W-SUMU (315), with E-AUVS (310), E-BDVS (311)
- **Before**: Cross-record validation rules (priority 8)





