-- SQL statements to register the W-SUMU rule in the QCS database
-- This file should be executed against both qcs.db files in quality-check-software and qcs-admin projects
-- ECARS-2201

-- Step 1: Add validation message for W-SUMU
INSERT INTO validationMessage(id,code,type,reference,description) VALUES 
('211','W-SUMU','WARNING','Table 13, page 33 of QC report','Surv time+Followup Date/Month of Incidence not valid (Tab. 13)');

-- Step 2: Add rule definition for W-SUMU
INSERT INTO ruledefinition(ID,NAME,DESCRIPTION,POSITIVE,CASESENSITIVITY,LOCATION,IMPLEMENTATION,VALIDATIONMESSAGE_ID,RULETYPE_ID) VALUES 
(315,'Survival Time Unknown','Survival Time Unknown',true,'INSENSITIVE','eu.europa.ec.jrc.qcs.engine.rule.crossfield.encr2020','SurvivalTimeFollowDateUnknown',211,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
(369,11,7,0,315);

-- Step 4: Configure rule parameters (ruletofield) - mapping fields to the rule
INSERT INTO ruletofield(id,protocol_id,ruledefinition_id,target_id,position,key,field_id) VALUES
--(1630,11,315,3,1,0,88), -- Position 1: Surv_time (field_id=88 - INCIDENCE_SURVIVAL)
--(1631,11,315,3,2,0,86), -- Position 2: MoF - Month of Follow-up (field_id=86 - INCIDENCE_MONTH_FU)
--(1632,11,315,3,3,0,87), -- Position 3: YoF - Year of Follow-up (field_id=87 - INCIDENCE_YEAR_FU)
(1633,11,315,3,4,0,77); -- Position 4: MoI - Month of Incidence (field_id=77 - INCIDENCE_MONTH_DOI)