# W-SUMU Rule Implementation (ECARS-2201)

## Overview
This document describes the implementation of the W-SUMU (Surv time+Followup Date/Month of Incidence not valid) validation rule for survival analysis in the QCS (Quality Check Software) system.

## Rule Description
**Rule Code**: W-SUMU  
**Rule Type**: WARNING  
**Description**: Surv time+Followup Date/Month of Incidence not valid (Tab. 13)  
**Protocol**: Incidence 2022 (39 var) (Protocol ID: 11)  

### Notes


### Rule Logic
The W-SUMU message is produced only if:
- Survival time (Surv_time) is unknown (99999) OR missing (blank) OR invalid **AND**
- (Date of the last known vital status (MoF, YoF) is unknown (MoF=99 AND/OR YoF=9999) OR missing OR invalid  
  **OR** Month of Incidence (MoI) is unknown (MoI=99) OR missing (MoI=blank) OR invalid)

### Rule Positioning
The W-SUMU rule has been positioned:
- **Priority Level**: 7 (Cross-field validation rules)
- **Execution Order**: After E-AUVS (310), E-BDVS (311), E-VSBD (312), W-SUBD (313), W-SUpT (314)
- **Before**: BEFORE Cross-record validation rules (priority 8)


## Implementation Files

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

This is the main rule implementation class that extends `CrossFieldRule` and implements the validation logic.

**Key features**:
- Checks if Surv_time is missing or set to unknown value (99999)
- Checks if MoF and/or YoF are missing or set to unknown values (99, 9999)
- Produces W-SUMU warning when both conditions are met
- Uses default field IDs from `DefaultFieldIDencr2020` enum


## Database Update Instructions

**Files involved**:
- `/src/main/resources/qcs.sql` (master SQL file)
- `/qcs.sql` (copy in project root)

The SQL changes must be applied to the `qcs.sql` file ( master ). To apply them to the actual database file:

#### Option 1: Rebuild from SQL 

1. **Backup existing databases**:
   a) copy item `/src/main/resources/qcs.sql` to `/src/main/resources/qcs-backup.sql`

2. **Apply SQL updates using DB Browser for SQLite** (or similar tool):
   - Open the qcs.db file
   - Execute the SQL statements from `/docs/rules/W-SUMU/W-SUMU_rule_registration.sql`
   - Save changes
   - Repeat for both projects' qcs.db files


## Compilation and Build

### Compile Java Files
Navigate to the quality-check-software project and compile:

### Build the Project
```powershell
mvn clean package
```

This will:
- Compile all Java classes including the new `SurvivalTimeUnknownRule`
- Run tests (if any)
- Package the application

## Testing

### Test Data Requirements
**File**: src/test/resources/test-data/input/encr/2022/incidence/incidence_1.csv
According to the specifications, test with the provided input file where:
- **PAT ECARS_2201_3 - ECARS_2201_8** should trigger the W-SUMU warning

### Manual Test Examples

#### Should Trigger W-SUMU:
- Surv_time = blank, MoF = blank, YoF = 2020
- Surv_time = 99999, MoF = 99, YoF = 2020
- Surv_time = blank, MoF = 12, YoF = 9999
- Surv_time = 99999, MoF = blank, YoF = blank

### Running Tests 

# TODO:

## Files Modified

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

### qcs-admin project:
1. `src/main/resources/qcs.sql` 
2. `qcs.db`



