# E-AGEC Rule Implementation

## Overview
This document describes the implementation of the E-AGEC (Age invalid + impossible to calculate age from DoI - DoB) validation rule. 
The rule ensures that when Age is not valid, the system can still determine whether an approximate age could be calculated from Year of Incidence (YoI) and Year of Birth (YoB).

## Rule Description
**Rule Code**: E-AGEC  
**Rule Type**: ERROR  
**Description**: Age is invalid + impossible to calculate age from DoI - DoB  
**Reference**: ENCR Protocol 2014, page 16  
**JIRA**: ECARS-2308 (CancerWatch T7.1 / EUROCARE request, January 2026)

### Rule Logic
The E-AGEC message is produced when:

1. **Age is not in range** (Age fails the configured range check or is otherwise invalid),  
   **AND**

2. **At least one** of:
   - **YoI OR YoB are not in range**, **OR**
   - **(YoI − YoB)** is **greater than the maximum allowed age** as defined in the **Age** field range  
     (i.e. `(YoI − YoB) > maxAge`, where `maxAge` is taken from the `toValue` of the Age field range; typically 120).

## Implementation Files
### 1. Java Implementation (ENCR 2020)
**File**: `src/main/java/eu/europa/ec/jrc/qcs/engine/rule/crossfield/encr2020/AgeBirthIncidenceRule4.java`

- **Protocol**: Incidence 2020 (Protocol ID: 11)
- **Rule definition ID**: 301 (Age birth incidence 4)
- **Fields used**: Age (position 1), YoB (position 3), YoI (position 5)

## Testing

### Expected Behavior

#### Case 1 – TRIGGER E-AGEC (incidence_1.csv)
ECARS-2308_E-AGEC-trigger1
ECARS-2308_E-AGEC-trigger2
ECARS-2308_E-AGEC-trigger3

#### Case 2 – DO NOT TRIGGER E-AGEC (incidence_1.csv)
ECARS-2308_E-AGEC-NOT-trigger1
ECARS-2308_E-AGEC-NOT-trigger2
ECARS-2308_E-AGEC-NOT-trigger3

