-- SQL statements to register the W-SUDA rule in the QCS database
-- This file should be executed against both qcs.db files in quality-check-software and qcs-admin projects
-- ECARS-2202: Survival time not consistent with Date of Incidence and Date of Follow-up

-- Step 1: Add validation message for W-SUDA
INSERT INTO validationMessage(id,code,type,reference,description) VALUES 
('212','W-SUDA','WARNING','Table 14, page 34 of QC report','Survival time not consistent with Date of Incidence and Date of Follow-up (Tab. 14)');

-- Step 2: Add rule definition for W-SUDA
INSERT INTO ruledefinition(ID,NAME,DESCRIPTION,POSITIVE,CASESENSITIVITY,LOCATION,IMPLEMENTATION,VALIDATIONMESSAGE_ID,RULETYPE_ID) VALUES 
(316,'Survival Date Analysis','Survival Date Analysis',true,'INSENSITIVE','eu.europa.ec.jrc.qcs.engine.rule.crossfield.encr2020','SurvivalDateAnalysisRule',212,8);

-- Step 3: Add rule to ENCR 2020 protocol (protocol_id=11) with priority 7 (cross-field rules level)
INSERT INTO protocolToRule(id,protocol_id,priority,block,ruleDefinition_id) VALUES 
(370,11,7,0,316);

-- Step 4: Rule-to-Field Mappings (5 fields)
INSERT INTO ruletofield(id,protocol_id,ruledefinition_id,target_id,position,key,field_id) VALUES
(1640,11,316,3,1,0,88),  -- Surv_time (field_id=88 - INCIDENCE_SURVIVAL)
(1641,11,316,3,2,0,77),  -- MoI - Month of Incidence (field_id=77 - INCIDENCE_MONTH_DOI)
(1642,11,316,3,3,0,78),  -- YoI - Year of Incidence (field_id=78 - INCIDENCE_YEAR_DOI)
(1643,11,316,3,4,0,86),  -- MoF - Month of Follow-up (field_id=86 - INCIDENCE_MONTH_FU)
(1644,11,316,3,5,0,87);  -- YoF - Year of Follow-up (field_id=87 - INCIDENCE_YEAR_FU)
