SELECT rtf.id, rtf.ruledefinition_id, rd."name", rd.implementation, vM."code", ptr.enabled
FROM ruletofield rtf
LEFT JOIN ruledefinition rd ON rd.id = rtf.ruledefinition_id
INNER JOIN validationMessage vM ON vM.id = rd.validationMessage_id
INNER JOIN protocolToRule ptr ON ptr.ruleDefinition_id = rd.id AND ptr.protocol_id = 11
WHERE rtf.field_id = 83;


------------------------------------------------------------------------------------------------------

INSERT INTO validationMessage(id,code,type,reference,description) VALUES (120,'W-BDpN','WARNING','Other additional checks on the extent of the disease, page 33','pN + BoD not valid');

INSERT INTO ruletofield(id,protocol_id,ruledefinition_id,target_id,position,key,field_id) VALUES ((SELECT next_val FROM ruleToField_SEQ),11,217,3,3,false,82); -- Beh (field_id=82)
UPDATE ruleToField_SEQ SET next_val = next_val + 1;



INSERT INTO ruletofield(id,protocol_id,ruledefinition_id,target_id,position,key,field_id) VALUES ((SELECT next_val FROM ruleToField_SEQ),11,216,3,3,false,82); -- Beh (field_id=82)
UPDATE ruleToField_SEQ SET next_val = next_val + 1;