return: text
lang: plpgsql
src: |
  DECLARE	
  	
  	sqlcmd text;
  	def_cursor refcursor;
  	_schemaname text;
  	result TEXT;
  BEGIN
  
  	-- Entreprises
  	DROP TABLE IF EXISTS w_indicateur_condition;
  	CREATE TEMP TABLE w_indicateur_condition AS
  	SELECT 
  		'CTI_ENTREPRISE#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_ENTREPRISE#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Entreprise. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'rhp_entreprise_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'ETABLISSEMENT='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'D2%' THEN COALESCE('D2#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		]::text[] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  				
  		]::text[] AS arbre_texte
  	FROM rh.v_etablissements_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  			t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_entreprises t_source ON v_source.oid LIKE 'D2%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid LIKE 'D2%' AND
  		v_source.oid <> '-1'
  	;
  
  	-- Etablissement
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_ETABLISSEMENT#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_ETABLISSEMENT#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Etablissement. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'rhp_etablissement_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'ETABLISSEMENT='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  				
  		] AS arbre_texte
  	FROM rh.v_etablissements_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  			t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_etablissements t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid NOT LIKE 'D2%' AND
  		v_source.oid <> '-1'
  	;
  
  	-- Service
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_SERVICE#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  		'CTI_SERVICE#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Service. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'service_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'SERVICE='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_services_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_services t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1' 
    ;
    
  -- Groupe de grille
  INSERT INTO w_indicateur_condition
  SELECT 
  	'CTI_GRILLE_GROUPE#' || v_source.oid::text AS code,
  	v_source.code as condition_code,
  		'CTI_GRILLE_GROUPE#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  	COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Grille groupe. ' || v_source.texte::text) AS texte,
  	v_source.texte AS texte_court,
  	'grille_groupe_id'::text AS column_name,
  	''::text AS rule,
  	v_source.oid::text AS value,
  	'GRILLE GROUPE='||v_source.oid AS view_select_rule,
  	ARRAY[
  		CASE 
  			WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  			WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  			WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  			ELSE '9' END,
  		CASE 
  			WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  			WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  			WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  			WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  			ELSE '###'||v_source.oid END
  			
  	] AS arbre_code,
  	ARRAY[
  		CASE 
  			WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  			WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  			WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  			ELSE 'Valeurs' END,
  		CASE 
  			WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  			ELSE v_source.texte END
  	] AS arbre_texte
  FROM rh.v_grilles_groupes_1 v_source
  	LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  	t_classes_sections.oid::text = substr(v_source.oid,5)
  	LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  	LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  	LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  		t_listes.oid::text = substr(v_source.oid,3) 
  	LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  	LEFT JOIN rh.t_grilles_groupes t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  WHERE v_source.oid NOT LIKE 'LC%' AND
  	(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  	v_source.oid <> '-1' 
  ;
  
  -- Grille
  INSERT INTO w_indicateur_condition
  SELECT 
  	'CTI_GRILLE#' || v_source.oid::text AS code,
  	v_source.code as condition_code,
  		'CTI_GRILLE#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  	COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Grille. ' || v_source.texte::text) AS texte,
  	v_source.texte AS texte_court,
  	'grille_id'::text AS column_name,
  	''::text AS rule,
  	v_source.oid::text AS value,
  	'GRILLE='||v_source.oid AS view_select_rule,
  	ARRAY[
  		CASE 
  			WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  			WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  			WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  			ELSE '9' END,
  		CASE 
  			WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  			WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  			WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  			WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  			ELSE '###'||v_source.oid END
  			
  	] AS arbre_code,
  	ARRAY[
  		CASE 
  			WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  			WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  			WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  			ELSE 'Valeurs' END,
  		CASE 
  			WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  			ELSE v_source.texte END
  	] AS arbre_texte
  FROM rh.v_grilles_1 v_source
  	LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  	t_classes_sections.oid::text = substr(v_source.oid,5)
  	LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  	LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  	LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  		t_listes.oid::text = substr(v_source.oid,3) 
  	LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  	LEFT JOIN rh.t_grilles t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  WHERE v_source.oid NOT LIKE 'LC%' AND
  	(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  	v_source.oid <> '-1' 
  ;
  
    -- Population
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_POPULATION#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_POPULATION#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Population. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'population_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'POPULATION='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_population_2 v_source
      LEFT JOIN rh.t_classes_sections ON true
        AND v_source.oid LIKE 'LS%'
  		  AND t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
      LEFT JOIN rh.t_listes ON true
        AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%')
  			AND t_listes.oid::text = substr(v_source.oid,3)
  		LEFT JOIN rh.t_listes_tables AS t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_population t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
    WHERE true
      AND v_source.oid NOT LIKE 'LC%'
      AND (false
        OR v_source.oid NOT LIKE 'LS%'
        OR substr(v_source.oid,5) <> '0')
  		AND v_source.oid <> '-1'
  		
  	;
  
  	-- Service
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_POLE#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_POLE#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Pole. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'rhp_pole_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'POLE='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_pole_2 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_pole t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1' 
  	;
  
  	-- Clé budget
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_BUD#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  		'CTI_BUD#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Clé budgetaire. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'rhp_budget_cle_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'BUD='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_budget_cle_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_budget_cle t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1' 
  	;
  
  
  	
  	-- Service planning
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_PLANNINGSERVICESOURCE#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_PLANNINGSERVICESOURCE#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Service source Planning. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'rhp_planning_service_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'PLANNING_SERVICE_SOURCE='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_planning_service_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_planning_service t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
  	-- Qualifications
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_QUALIFICATION#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_QUALIFICATION#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Qualification. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'qualification_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'QUALIFICATION='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_qualifications_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_qualifications t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
  	-- Qualifications planning
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_PLANNINGQUALIFICATIONSOURCE#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_PLANNINGQUALIFICATIONSOURCE#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Service source Planning. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'rhp_planning_qualification_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'PLANNING_SERVICE_SOURCE='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_planning_qualification_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_planning_qualification t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1' 
  	;
  
    -- PLANNING - Type d'absence.
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_PLANNINGTYPEABSENCE#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_PLANNINGTYPEABSENCE#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Type absence Planning. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'rhp_planning_type_absence_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'PLANNING_TYPE_ABSENCE='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_planning_type_absence_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_motifs_debut_contrat t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
  	-- Types de contrat
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_TYPECONTRAT#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_TYPECONTRAT#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Type contrat. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'type_contrat_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'TYPE_CONTRAT='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_types_contrat_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_types_contrat t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
  	-- Codes emploi
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_CODEEMPLOI#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_CODEEMPLOI#' ||  
  		CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  				ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Code emploi. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'code_emploi_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'CODE_EMPLOI='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_codes_emploi_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_codes_emploi t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
    -- Type temps de travail.
  	INSERT INTO w_indicateur_condition
        SELECT 
            'CTI_TYPETEMPSW#' || v_source.oid::text AS code,
  					v_source.code as condition_code,
  				'CTI_TYPETEMPSW#' ||  
  				CASE 
  					WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  					WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  					WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  					WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  					ELSE '###' END AS category_id,
            COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Type tps trav.. ' || v_source.texte::text) AS texte,
            v_source.texte AS texte_court,
            'type_temps_travail_id'::text AS column_name,
            ''::text AS rule,
            v_source.oid::text AS value,
            'TYPE_TEMPS_TRAVAIL='||v_source.oid AS view_select_rule,
            ARRAY[
                CASE 
                    WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
                    WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
                    WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
                    ELSE '9' END,
                CASE 
                    WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
                    WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
                    WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
                    WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
                    ELSE '###'||v_source.oid END
                    
            ] AS arbre_code,
            ARRAY[
                CASE 
                    WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
                    WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
                    WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
                    ELSE 'Valeurs' END,
                CASE 
                    WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
                    ELSE v_source.texte END
            ] AS arbre_texte
        FROM rh.v_types_temps_travail_1 v_source
            LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
            t_classes_sections.oid::text = substr(v_source.oid,5)
            LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
            LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
            LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
                t_listes.oid::text = substr(v_source.oid,3) 
            LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
            LEFT JOIN rh.t_types_temps_travail t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
        WHERE v_source.oid NOT LIKE 'LC%' AND
            (v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
            v_source.oid <> '-1'
    ;
  
  	-- Types horaire
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_TYPEHORAIRE#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_TYPEHORAIRE#' ||  
  	CASE 
  		WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  		WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  		ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Type horaire. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'type_horaire_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'TYPE_HORAIRE='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_types_horaire_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_types_horaire t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
  	-- Spécialités
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_SPECIALITE#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_SPECIALITE#' ||  
  	CASE 
  		WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  		WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  		ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Spécialité. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'specialite_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'SPECIALITE='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_specialites_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_specialites t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
  -- Salarié
    INSERT INTO w_indicateur_condition
    SELECT 
        'CTI_SALARIE#' || v_source.oid::text AS code,
  			v_source.code as condition_code,
  		'CTI_SALARIE#' ||  
  	CASE 
  		WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  		WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  		ELSE '###' END AS category_id,
        COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Salarié. ' || v_source.texte::text) AS texte,
        v_source.texte AS texte_court,
        'salarie_id'::text AS column_name,
        ''::text AS rule,
        v_source.oid::text AS value,
        'SALARIE='||v_source.oid AS view_select_rule,
        ARRAY[
            CASE 
                WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
                WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
                WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
                ELSE '9' END,
            CASE 
                WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_classes_sections.code
                WHEN v_source.oid LIKE 'LI%' THEN COALESCE('LI#'||t_listes.code,v_source.oid)
                WHEN v_source.oid LIKE 'SL%' THEN COALESCE('SL#'||t_listes.code,v_source.oid)
                WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
                ELSE '###'||v_source.oid END
                
        ] AS arbre_code,
        ARRAY[
            CASE 
                WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
                WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
                WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
                ELSE 'Valeurs' END,
            CASE 
                WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
                ELSE v_source.texte END
        ] AS arbre_texte
    FROM rh.v_salaries_2 v_source
        LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
        t_classes_sections.oid::text = substr(v_source.oid,5)
        LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
        LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
            t_listes.oid::text = substr(v_source.oid,3) AND
            t_listes.code <> ''
        LEFT JOIN rh.p_salaries t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
    WHERE 1=1
      AND v_source.oid NOT LIKE 'LC%'
      AND v_source.oid NOT LIKE 'DT%'
      AND (1!=1
          OR v_source.oid NOT LIKE 'LS%'
          OR substr(v_source.oid, 5) != '0')
      AND v_source.oid != '-1'
    ;
  
  	-- Sexe
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_SEXE#DT1'::text AS code,
  		'CTI_SEXE#DT1'::text AS condition_code,
  		'CTI_SEXE#'::text AS category_id,
  		'Sexe masculin' AS texte,
  		'Sexe masculin'::text AS texte_court,
  		'sexe_id'::text AS column_name,
  		''::text AS rule,
  		'DT1'::text AS value,
  		'SEXE=DT1' AS view_select_rule,
  		ARRAY[
  			'9' ,
  			'DT#1'
  		] AS arbre_code,
  		ARRAY[
  			'Valeurs',
  			'Sexe masculin'
  		] AS arbre_texte
  	
  	;
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_SEXE#DT2'::text AS code,
  		'CTI_SEXE#DT2'::text AS condition_code,
  		'CTI_SEXE#'::text AS category_id,
  		'Sexe féminin' AS texte,
  		'Sexe féminin'::text AS texte_court,
  		'sexe_id'::text AS column_name,
  		''::text AS rule,
  		'DT2'::text AS value,
  		'SEXE=DT2' AS view_select_rule,
  		ARRAY[
  			'9' ,
  			'DT#2'
  		] AS arbre_code,
  		ARRAY[
  			'Valeurs',
  			'Sexe féminin'
  		] AS arbre_texte
  	
  	;
  
  	-- Ages
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_AGE#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_AGE#' ||  
  	CASE 
  		WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  		WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  		ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Age. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'age_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'AGE='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_ages_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN base.t_ages t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
  	-- Ancienneté
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_ANCIENNETE#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_ANCIENNETE#' ||  
  	CASE 
  		WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  		WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  		ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Ancienneté. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'rhp_anciennete_annee_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'ANCIENNETE='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_anciennetes_annee_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_anciennetes_annee t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
  	-- nationalité
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_NATIONALITE#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_NATIONALITE#' ||  
  	CASE 
  		WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  		WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  		ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Nationalité. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'nationalite_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'NATIONALITE='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_nationalites_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_nationalites t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
  	-- Motif début
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_MOTIFDEBUTCONTRAT#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_MOTIFDEBUTCONTRAT#' ||  
  	CASE 
  		WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  		WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  		ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Motif début de contrat. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'motif_debut_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'MOTIF_DEBUT_CONTRAT='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_motifs_debut_contrat_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_motifs_debut_contrat t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
  	-- Motif fin
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_MOTIFFINCONTRAT#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_MOTIFFINCONTRAT#' ||  
  	CASE 
  		WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  		WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  		ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Motif fin de contrat. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'motif_fin_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'MOTIF_FIN_CONTRAT='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_motifs_fin_contrat_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_motifs_fin_contrat t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
  	-- Rubriques
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_RUBRIQUE#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_RUBRIQUE#' ||  
  	CASE 
  		WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  		WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  		ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Rubrique. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'rubrique_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'RUBRIQUE='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			v_source.texte
  		] AS arbre_texte
  	FROM rh.v_rubriques_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_rubriques t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1' 
  	;
  
  
  	-- motifs arret
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_MOTIF_ARRET#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_MOTIF_ARRET#' ||  
  	CASE 
  		WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  		WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  		ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Motif. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'motif_arret_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'MOTIF_ARRET='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			v_source.texte
  		] AS arbre_texte
  	FROM rh.v_motifs_arret_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_motifs_arret t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1' 
  	;
  
    -- Statuts
  	INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_STATUT#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_STATUT#' ||  
  	CASE 
  		WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  		WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  		ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'Statut. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'statut_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'STATUT='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_statuts_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_statuts t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1'
  	;
  
    -- CSP
  
    INSERT INTO w_indicateur_condition
  	SELECT 
  		'CTI_CSP#' || v_source.oid::text AS code,
  		v_source.code as condition_code,
  	'CTI_CSP#' ||  
  	CASE 
  		WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END
  		WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  		WHEN v_source.oid LIKE 'DT%' THEN 'DT#'
  		ELSE '###' END AS category_id,
  		COALESCE(t_classes.texte || '. ' || t_classes_sections.texte,'CSP. ' || v_source.texte::text) AS texte,
  		v_source.texte AS texte_court,
  		'categorie_socio_professionnelle_id'::text AS column_name,
  		''::text AS rule,
  		v_source.oid::text AS value,
  		'CSP='||v_source.oid AS view_select_rule,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN '1-Classe' || substr(v_source.oid,3,2)
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '2-Liste CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN '3-Liste CTI' 
  				ELSE '9' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN 'LS#'||t_listes_tables_classes.code||':'||CASE WHEN t_classes.code <> '' THEN t_classes.code ELSE '*CLS'||to_char(t_classes.sequence,'FM00') END||':'||t_classes_sections.code
  				WHEN v_source.oid LIKE 'LI%' THEN 'LI#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'SL%' THEN 'SL#'||t_listes_tables_listes.code||':'||CASE WHEN t_listes.code <> '' THEN t_listes.code ELSE '*TXT:'||upper(t_listes.texte) END
  				WHEN v_source.oid LIKE 'DT%' THEN COALESCE('DT#'||t_source.code,v_source.oid)
  				ELSE '###'||v_source.oid END
  				
  		] AS arbre_code,
  		ARRAY[
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes.texte
  				WHEN v_source.is_cti = '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes CTI' 
  				WHEN v_source.is_cti <> '1' AND (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') THEN 'Listes Etablissement' 
  				ELSE 'Valeurs' END,
  			CASE 
  				WHEN v_source.oid LIKE 'LS%' THEN t_classes_sections.texte
  				ELSE v_source.texte END
  		] AS arbre_texte
  	FROM rh.v_categories_socio_professionnelle_1 v_source
  		LEFT JOIN rh.t_classes_sections ON v_source.oid LIKE 'LS%' AND
  		t_classes_sections.oid::text = substr(v_source.oid,5)
  		LEFT JOIN rh.t_classes ON t_classes.oid = t_classes_sections.classe_id
  		LEFT JOIN rh.t_listes_tables t_listes_tables_classes ON t_classes.table_id = t_listes_tables_classes.oid
  		LEFT JOIN rh.t_listes ON (v_source.oid LIKE 'LI%' OR v_source.oid LIKE 'SL%') AND
  			t_listes.oid::text = substr(v_source.oid,3) 
  		LEFT JOIN rh.t_listes_tables t_listes_tables_listes ON t_listes.table_id = t_listes_tables_listes.oid
  		LEFT JOIN rh.t_categories_socio_professionnelle t_source ON v_source.oid LIKE 'DT%' AND t_source.oid = substr(v_source.oid,3)
  	WHERE v_source.oid NOT LIKE 'LC%' AND
  		(v_source.oid NOT LIKE 'LS%' OR substr(v_source.oid,5) <> '0') AND
  		v_source.oid <> '-1' 
    ;
  
  	INSERT INTO rh.t_indicateur_condition(code, texte,texte_court,column_name,rule,value,view_select_rule, arbre_code, arbre_texte, condition_code, category_id)
  	SELECT code, texte,texte_court,column_name,rule,value,view_select_rule, arbre_code, arbre_texte, condition_code, category_id
  	FROM w_indicateur_condition
  	WHERE code NOT IN (SELECT code FROM rh.t_indicateur_condition WHERE code IS NOT NULL)
  	;
  
  	UPDATE rh.t_indicateur_condition SET
  		texte = w_indicateur_condition.texte,
  		texte_court = w_indicateur_condition.texte_court,
  		column_name = w_indicateur_condition.column_name,
  		rule = w_indicateur_condition.rule,
  		value = w_indicateur_condition.value,
  		view_select_rule = w_indicateur_condition.view_select_rule,
  		arbre_code = w_indicateur_condition.arbre_code,
  		arbre_texte = w_indicateur_condition.arbre_texte,
  		condition_code = w_indicateur_condition.condition_code,
  		category_id = w_indicateur_condition.category_id
  	FROM w_indicateur_condition
  	WHERE w_indicateur_condition.code = t_indicateur_condition.code AND
  		(
  		t_indicateur_condition.texte IS DISTINCT FROM w_indicateur_condition.texte OR
  		t_indicateur_condition.texte_court IS DISTINCT FROM w_indicateur_condition.texte_court OR
  		t_indicateur_condition.column_name IS DISTINCT FROM w_indicateur_condition.column_name OR
  		t_indicateur_condition.rule IS DISTINCT FROM w_indicateur_condition.rule OR
  		t_indicateur_condition.value IS DISTINCT FROM w_indicateur_condition.value OR
  		t_indicateur_condition.view_select_rule IS DISTINCT FROM w_indicateur_condition.view_select_rule OR
  		t_indicateur_condition.arbre_code IS DISTINCT FROM w_indicateur_condition.arbre_code OR
  		t_indicateur_condition.arbre_texte IS DISTINCT FROM w_indicateur_condition.arbre_texte OR
  		t_indicateur_condition.condition_code IS DISTINCT FROM w_indicateur_condition.condition_code OR
  		t_indicateur_condition.category_id IS DISTINCT FROM w_indicateur_condition.category_id
  		)
  	;
  
  	WITH toto as (
      SELECT
        oid,
        split_part(code, '#', 1)
          ||'#'
          ||arbre_code[2]
          as new_external_code
      FROM rh.t_indicateur_condition
    )
    UPDATE rh.t_indicateur_condition SET
      external_code = new_external_code
    FROM toto
    WHERE 1=1
      and t_indicateur_condition.oid = toto.oid
      and external_code IS DISTINCT FROM new_external_code
    ;
  
  WITH external_code2 as (
      SELECT
        oid,
        split_part(code, '#', 1)
          ||'#'
          ||arbre_code[2]
          as new_external_code2
      FROM rh.t_indicateur_condition
    )
    UPDATE rh.t_indicateur_condition SET
      external_code2 = new_external_code2
    FROM external_code2
    WHERE 1=1
      and t_indicateur_condition.oid = external_code2.oid
      and external_code2 IS DISTINCT FROM new_external_code2
    ;
  
  	DELETE FROM rh.t_indicateur_condition
  	WHERE code LIKE 'CTI%' AND
  		code NOT IN (SELECT code FROM w_indicateur_condition)
  		;
  
  	UPDATE rh.t_indicateur_condition SET
  		column_texte = CASE column_name
  			WHEN 'rhp_entreprise_id' THEN 'Entreprise'
  			WHEN 'rhp_etablissement_id' THEN 'Etablissement'
  			ELSE replace(Upper(substr(split_part(column_name,'_id',1),1,1)) || substr(split_part(column_name,'_id',1),2),'_',' ') END
  	WHERE 
  		column_texte IS DISTINCT FROM 
  			CASE column_name
  			WHEN 'rhp_entreprise_id' THEN 'Entreprise'
  			WHEN 'rhp_etablissement_id' THEN 'Etablissement'
  			ELSE replace(Upper(substr(split_part(column_name,'_id',1),1,1)) || substr(split_part(column_name,'_id',1),2),'_',' ') END
  	;
  	
  	DROP TABLE IF EXISTS w_indicateur_condition_table;
  	CREATE TEMP TABLE w_indicateur_condition_table AS
  	SELECT t_indicateur_condition.oid AS indicateur_condition_id,
  		''::text As table_name,
  		t_indicateur_condition.column_name || ' ' ||
  		CASE 
  			WHEN t_indicateur_condition.value LIKE 'LS%' THEN '= ANY(ARRAY'
  			WHEN t_indicateur_condition.value LIKE 'LI%' THEN '= ANY(ARRAY'
  			WHEN t_indicateur_condition.value LIKE 'SL%' THEN '<> ALL(ARRAY'
  			WHEN t_indicateur_condition.value LIKE 'DT%' THEN '='
  			ELSE '='
  		END || ' ' ||
  		CASE 
  			WHEN t_indicateur_condition.value LIKE 'LS%' THEN 
  				'(SELECT to_id FROM rh.t_classes_sections_elements WHERE section_id = ' || substr(value,5) || ')'
  			WHEN t_indicateur_condition.value LIKE 'LI%' THEN 
  				'(SELECT to_id FROM rh.t_listes_contenu WHERE liste_id = ' || substr(value,3) || ')'
  			WHEN t_indicateur_condition.value LIKE 'SL%' THEN 
  				'(SELECT to_id FROM rh.t_listes_contenu WHERE liste_id = ' || substr(value,3) || ')'
  			WHEN t_indicateur_condition.value LIKE 'DT%' THEN 
  				substr(value,3)
  			ELSE substr(value,3)
  		END || ' ' ||
  		CASE 
  			WHEN t_indicateur_condition.value LIKE 'LS%' THEN ')'
  			WHEN t_indicateur_condition.value LIKE 'LI%' THEN ')'
  			WHEN t_indicateur_condition.value LIKE 'SL%' THEN ')'
  			ELSE ''
  		END AS check_where
  	FROM rh.t_indicateur_condition
  	WHERE t_indicateur_condition.code LIKE 'CTI%' 
  	;
  
  	INSERT INTO w_indicateur_condition_table
  	SELECT t_indicateur_condition.oid AS indicateur_condition_id,
  		'v_arrets_travail_mois_1'::text As table_name,
  		''::text AS check_where
  	FROM rh.t_indicateur_condition
  	WHERE t_indicateur_condition.code LIKE 'CTI%' AND
  		column_name IN ('rubrique_id')
  	;
  	INSERT INTO w_indicateur_condition_table
  	SELECT t_indicateur_condition.oid AS indicateur_condition_id,
  		'v_contrats_mois_1'::text As table_name,
  		''::text AS check_where
  	FROM rh.t_indicateur_condition
  	WHERE t_indicateur_condition.code LIKE 'CTI%' AND
  		column_name IN ('rubrique_id')
  	;
  	INSERT INTO w_indicateur_condition_table
  	SELECT t_indicateur_condition.oid AS indicateur_condition_id,
  		'v_contrats_mois_1'::text As table_name,
  		''::text AS check_where
  	FROM rh.t_indicateur_condition
  	WHERE t_indicateur_condition.code LIKE 'CTI%' AND
  		column_name IN ('rhp_planning_qualification_id', 'rhp_planning_service_id')
  	;
  	INSERT INTO w_indicateur_condition_table
  	SELECT t_indicateur_condition.oid AS indicateur_condition_id,
  		'v_arrets_travail_mois_1'::text As table_name,
  		''::text AS check_where
  	FROM rh.t_indicateur_condition
  	WHERE t_indicateur_condition.code LIKE 'CTI%' AND
  		column_name IN ('rhp_planning_qualification_id', 'rhp_planning_service_id')
  	;
  	INSERT INTO w_indicateur_condition_table
  	SELECT t_indicateur_condition.oid AS indicateur_condition_id,
  		'v_historique_paie_1'::text As table_name,
  		''::text AS check_where
  	FROM rh.t_indicateur_condition
  	WHERE t_indicateur_condition.code LIKE 'CTI%' AND
  		column_name IN ('rhp_planning_qualification_id', 'rhp_planning_service_id')
  	;
  	INSERT INTO w_indicateur_condition_table
  	SELECT t_indicateur_condition.oid AS indicateur_condition_id,
  		'CALENDRIER'::text As table_name,
  		''::text AS check_where
  	FROM rh.t_indicateur_condition
  	;
  	INSERT INTO w_indicateur_condition_table
  	SELECT t_indicateur_condition.oid AS indicateur_condition_id,
  		'BUDGET_RH'::text As table_name,
  		'1<>1' AS check_where
  	FROM rh.t_indicateur_condition
  	WHERE t_indicateur_condition.code LIKE 'CTI%' AND
  		column_name NOT IN ('rhp_budget_cle_id')
  	;
  
  	ANALYSE w_indicateur_condition_table
  	;
  
  
  	INSERT INTO rh.t_indicateur_condition_table(indicateur_condition_id, table_name, check_where)
  	SELECT w_indicateur_condition_table.indicateur_condition_id, w_indicateur_condition_table.table_name, w_indicateur_condition_table.check_where
  	FROM w_indicateur_condition_table
  	LEFT JOIN rh.t_indicateur_condition_table ON
  		w_indicateur_condition_table.indicateur_condition_id = t_indicateur_condition_table.indicateur_condition_id AND
  		w_indicateur_condition_table.table_name = t_indicateur_condition_table.table_name
  	WHERE t_indicateur_condition_table.indicateur_condition_id IS NULL
  	;
  
  	
  	UPDATE rh.t_indicateur_condition_table SET
  		check_where = w_indicateur_condition_table.check_where
  	FROM w_indicateur_condition_table
  	WHERE t_indicateur_condition_table.indicateur_condition_id = w_indicateur_condition_table.indicateur_condition_id AND
  		t_indicateur_condition_table.table_name = w_indicateur_condition_table.table_name AND
  		(
  		t_indicateur_condition_table.check_where IS DISTINCT FROM w_indicateur_condition_table.check_where 
  		)
  	;
  
  	DELETE FROM rh.t_indicateur_condition_table
  	USING
  	(
  	SELECT t_indicateur_condition_table.indicateur_condition_id, t_indicateur_condition_table.table_name, t_indicateur_condition_table.check_where
  	FROM rh.t_indicateur_condition_table
  	LEFT JOIN w_indicateur_condition_table ON
  		w_indicateur_condition_table.indicateur_condition_id = t_indicateur_condition_table.indicateur_condition_id AND
  		w_indicateur_condition_table.table_name = t_indicateur_condition_table.table_name
  	WHERE w_indicateur_condition_table.indicateur_condition_id IS NULL
  	) subview
  	WHERE t_indicateur_condition_table.indicateur_condition_id = subview.indicateur_condition_id AND
  		t_indicateur_condition_table.table_name = subview.table_name
  	;
  	
  
  
  	RETURN 'OK';
  
  END;