-- SQL statements to register the W-BDpM rule in the QCS database

-- Step 1: Add validation message for W-BDpM
INSERT INTO validationMessage(id,code,type,reference,description) VALUES
(121,'W-BDpM','WARNING','Other additional checks on the extent of the disease, page 33','pM + BoD/c,pT not valid');

-- Step 2: Add rule definition (RuleDefinition ID = 218)
INSERT INTO ruledefinition(ID,NAME,DESCRIPTION,POSITIVE,CASESENSITIVITY,LOCATION,IMPLEMENTATION,VALIDATIONMESSAGE_ID,RULETYPE_ID) VALUES
(218,'Disease extent 5','Disease extent 5',true,'INSENSITIVE','eu.europa.ec.jrc.qcs.engine.rule.crossfield.encr2014','DiseaseExtentRule5',121,8);

-- Step 3: Add rule to protocols
INSERT INTO protocolToRule(id,protocol_id,priority,block,ruleDefinition_id,enabled) VALUES
(54,1,7,false,218,true),
(339,11,7,false,218,true);

-- Step 4: Rule-to-Field mappings
-- Protocol 1 (ENCR 2014): BoD=12, pM=32, cT=33, pT=30, Beh=15
INSERT INTO ruletofield(id,protocol_id,ruledefinition_id,target_id,position,key,field_id) VALUES
(259,1,218,3,1,false,12),
(260,1,218,3,2,false,32),
(261,1,218,3,3,false,33),
(262,1,218,3,4,false,30),
(279,1,218,3,5,false,15);

-- Protocol 11 (ENCR 2020): BoD=79, pM=97, cT=92, pT=95, Beh=82
INSERT INTO ruletofield(id,protocol_id,ruledefinition_id,target_id,position,key,field_id) VALUES
(1240,11,218,3,1,false,79),
(1241,11,218,3,2,false,97),
(1242,11,218,3,3,false,92),
(1243,11,218,3,4,false,95),
(1244,11,218,3,5,false,82);
