src: |
  (
          (
                   SELECT '-8'::text AS oid,
                      'Listes paramétrées établissement'::character varying AS texte,
                      ''::text AS code,
                      '1'::text AS level,
                      '0'::text || chr(1) AS tri,
                      '0'::character(1) AS is_cti
                     FROM rh.t_listes_tables
                    WHERE t_listes_tables.code = 'ETS'::text AND (t_listes_tables.oid IN ( SELECT t_listes.table_id
                             FROM rh.t_listes
                            WHERE t_listes.is_cti::text <> 1::text AND (substr(t_listes.code, 1, 4) <> ALL (ARRAY['VIT_'::text, 'VED_'::text, 'HPM_'::text]))))
                  UNION
                   SELECT 'LI'::text || t_listes.oid::text AS oid,
                      t_listes.texte,
                      ''::text AS code,
                      '2'::text AS level,
                      '0I'::text || t_listes.texte AS tri,
                          CASE
                              WHEN t_listes.is_cti::text = '1'::text OR t_listes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                              ELSE '0'::character(1)
                          END AS is_cti
                     FROM rh.t_listes,
                      rh.t_listes_tables
                    WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'ETS'::text AND t_listes.is_cti::text <> 1::text AND (substr(t_listes.code, 1, 4) <> ALL (ARRAY['VIT_'::text, 'VED_'::text, 'HPM_'::text]))
                  UNION
                   SELECT 'SL'::text || t_listes.oid::text AS oid,
                      'Sauf '::text || t_listes.texte AS texte,
                      ''::text AS code,
                      '2'::text AS level,
                      '0S'::text || t_listes.texte AS tri,
                          CASE
                              WHEN t_listes.is_cti::text = '1'::text OR t_listes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                              ELSE '0'::character(1)
                          END AS is_cti
                     FROM rh.t_listes,
                      rh.t_listes_tables
                    WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'ETS'::text AND t_listes.is_cti::text <> 1::text AND (substr(t_listes.code, 1, 4) <> ALL (ARRAY['VIT_'::text, 'VED_'::text, 'HPM_'::text])) AND (t_listes.show_omit::text <> '0'::text OR t_listes.show_omit::text IS NULL)
                  UNION
                   SELECT '-8'::text AS oid,
                      'Listes paramétrées VITALIA'::character varying AS texte,
                      ''::text AS code,
                      '1'::text AS level,
                      '1'::text || chr(1) AS tri,
                      '0'::character(1) AS is_cti
                     FROM rh.t_listes_tables
                    WHERE t_listes_tables.code = 'ETS'::text AND (t_listes_tables.oid IN ( SELECT t_listes.table_id
                             FROM rh.t_listes
                            WHERE t_listes.is_cti::text <> 1::text AND substr(t_listes.code, 1, 4) = 'VIT_'::text))
                  UNION
                   SELECT 'LI'::text || t_listes.oid::text AS oid,
                      t_listes.texte,
                      ''::text AS code,
                      '2'::text AS level,
                      '1I'::text || t_listes.texte AS tri,
                          CASE
                              WHEN t_listes.is_cti::text = '1'::text OR t_listes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                              ELSE '0'::character(1)
                          END AS is_cti
                     FROM rh.t_listes,
                      rh.t_listes_tables
                    WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'ETS'::text AND t_listes.is_cti::text <> 1::text AND substr(t_listes.code, 1, 4) = 'VIT_'::text
                  UNION
                   SELECT 'SL'::text || t_listes.oid::text AS oid,
                      'Sauf '::text || t_listes.texte AS texte,
                      ''::text AS code,
                      '2'::text AS level,
                      '1S'::text || t_listes.texte AS tri,
                          CASE
                              WHEN t_listes.is_cti::text = '1'::text OR t_listes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                              ELSE '0'::character(1)
                          END AS is_cti
                     FROM rh.t_listes,
                      rh.t_listes_tables
                    WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'ETS'::text AND t_listes.is_cti::text <> 1::text AND substr(t_listes.code, 1, 4) = 'VIT_'::text AND (t_listes.show_omit::text <> '0'::text OR t_listes.show_omit::text IS NULL)
                  UNION
                   SELECT '-8'::text AS oid,
                      'Listes paramétrées VEDICI'::character varying AS texte,
                      ''::text AS code,
                      '1'::text AS level,
                      '1'::text || chr(1) AS tri,
                      '0'::character(1) AS is_cti
                     FROM rh.t_listes_tables
                    WHERE t_listes_tables.code = 'ETS'::text AND (t_listes_tables.oid IN ( SELECT t_listes.table_id
                             FROM rh.t_listes
                            WHERE t_listes.is_cti::text <> 1::text AND substr(t_listes.code, 1, 4) = 'VED_'::text))
                  UNION
                   SELECT 'LI'::text || t_listes.oid::text AS oid,
                      t_listes.texte,
                      ''::text AS code,
                      '2'::text AS level,
                      '1I'::text || t_listes.texte AS tri,
                          CASE
                              WHEN t_listes.is_cti::text = '1'::text OR t_listes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                              ELSE '0'::character(1)
                          END AS is_cti
                     FROM rh.t_listes,
                      rh.t_listes_tables
                    WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'ETS'::text AND t_listes.is_cti::text <> 1::text AND substr(t_listes.code, 1, 4) = 'VED_'::text
                  UNION
                   SELECT 'SL'::text || t_listes.oid::text AS oid,
                      'Sauf '::text || t_listes.texte AS texte,
                      ''::text AS code,
                      '2'::text AS level,
                      '1S'::text || t_listes.texte AS tri,
                          CASE
                              WHEN t_listes.is_cti::text = '1'::text OR t_listes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                              ELSE '0'::character(1)
                          END AS is_cti
                     FROM rh.t_listes,
                      rh.t_listes_tables
                    WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'ETS'::text AND t_listes.is_cti::text <> 1::text AND substr(t_listes.code, 1, 4) = 'VED_'::text AND (t_listes.show_omit::text <> '0'::text OR t_listes.show_omit::text IS NULL)
                  UNION
                   SELECT '-8'::text AS oid,
                      'Listes paramétrées HPM'::character varying AS texte,
                      ''::text AS code,
                      '1'::text AS level,
                      '1'::text || chr(1) AS tri,
                      '0'::character(1) AS is_cti
                     FROM rh.t_listes_tables
                    WHERE t_listes_tables.code = 'ETS'::text AND (t_listes_tables.oid IN ( SELECT t_listes.table_id
                             FROM rh.t_listes
                            WHERE t_listes.is_cti::text <> 1::text AND substr(t_listes.code, 1, 4) = 'HPM_'::text))
                  UNION
                   SELECT 'LI'::text || t_listes.oid::text AS oid,
                      t_listes.texte,
                      t_listes.code,
                      '2'::text AS level,
                      '1I'::text || t_listes.texte AS tri,
                          CASE
                              WHEN t_listes.is_cti::text = '1'::text OR t_listes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                              ELSE '0'::character(1)
                          END AS is_cti
                     FROM rh.t_listes,
                      rh.t_listes_tables
                    WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'ETS'::text AND t_listes.is_cti::text <> 1::text AND substr(t_listes.code, 1, 4) = 'HPM_'::text
                  UNION
                   SELECT 'SL'::text || t_listes.oid::text AS oid,
                      'Sauf '::text || t_listes.texte AS texte,
                      ''::text AS code,
                      '2'::text AS level,
                      '1S'::text || t_listes.texte AS tri,
                          CASE
                              WHEN t_listes.is_cti::text = '1'::text OR t_listes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                              ELSE '0'::character(1)
                          END AS is_cti
                     FROM rh.t_listes,
                      rh.t_listes_tables
                    WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'ETS'::text AND t_listes.is_cti::text <> 1::text AND substr(t_listes.code, 1, 4) = 'HPM_'::text AND (t_listes.show_omit::text <> '0'::text OR t_listes.show_omit::text IS NULL)
                  UNION
                   SELECT '-8'::text AS oid,
                      'Listes paramétrées CTI'::character varying AS texte,
                      ''::text AS code,
                      '1'::text AS level,
                      '3'::text AS tri,
                      '0'::character(1) AS is_cti
                     FROM rh.t_listes_tables
                    WHERE t_listes_tables.code = 'ETS'::text AND (t_listes_tables.oid IN ( SELECT t_listes.table_id
                             FROM rh.t_listes
                            WHERE t_listes.is_cti::text = 1::text))
                  UNION
                   SELECT 'LI'::text || t_listes.oid::text AS oid,
                      t_listes.texte,
                      t_listes.code,
                      '2'::text AS level,
                      '3I'::text || t_listes.texte AS tri,
                          CASE
                              WHEN t_listes.is_cti::text = '1'::text OR t_listes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                              ELSE '0'::character(1)
                          END AS is_cti
                     FROM rh.t_listes,
                      rh.t_listes_tables
                    WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'ETS'::text AND t_listes.is_cti::text = 1::text
                  UNION
                   SELECT 'SL'::text || t_listes.oid::text AS oid,
                      'Sauf '::text || t_listes.texte AS texte,
                      ''::text AS code,
                      '2'::text AS level,
                      '3S'::text || t_listes.texte AS tri,
                          CASE
                              WHEN t_listes.is_cti::text = '1'::text OR t_listes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                              ELSE '0'::character(1)
                          END AS is_cti
                     FROM rh.t_listes,
                      rh.t_listes_tables
                    WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'ETS'::text AND t_listes.is_cti::text = 1::text AND (t_listes.show_omit::text <> '0'::text OR t_listes.show_omit::text IS NULL)
                  UNION
                   SELECT ('LC'::text || lpad(t_classes.sequence::text, 2, '0'::text)) || t_classes.oid::text AS oid,
                      t_classes.texte,
                      t_classes.code,
                      '1'::text AS level,
                      '5'::text || btrim(rpad(lpad(t_classes.sequence::text, 2, '0'::text), 10, ' '::text)) AS tri,
                          CASE
                              WHEN t_classes.is_cti = '1'::bpchar OR t_classes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                              ELSE '0'::character(1)
                          END AS is_cti
                     FROM rh.t_classes,
                      rh.t_listes_tables
                    WHERE t_classes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'ETS'::text
          ) UNION ALL
           SELECT ('LS'::text || lpad(t_classes.sequence::text, 2, '0'::text)) || t_classes_sections.oid::text AS oid,
              t_classes_sections.texte,
              t_classes_sections.code,
              '2'::text AS level,
              '5'::text || btrim(rpad(lpad(t_classes.sequence::text, 2, '0'::text), 10, ' '::text) || t_classes_sections.code) AS tri,
                  CASE
                      WHEN t_classes.is_cti = '1'::bpchar OR t_classes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                      ELSE '0'::character(1)
                  END AS is_cti
             FROM rh.t_classes,
              rh.t_classes_sections,
              rh.t_listes_tables
            WHERE t_classes.table_id = t_listes_tables.oid AND t_classes_sections.classe_id = t_classes.oid AND t_listes_tables.code = 'ETS'::text
          UNION ALL
           SELECT ('LS'::text || lpad(t_classes.sequence::text, 2, '0'::text)) || '0'::text AS oid,
              'Section non attribuée'::character varying AS texte,
              ''::text AS code,
              '2'::text AS level,
              '5'::text || btrim(rpad(lpad(t_classes.sequence::text, 2, '0'::text), 10, ' '::text) || chr(255)) AS tri,
                  CASE
                      WHEN t_classes.is_cti = '1'::bpchar OR t_classes.code ~~ 'CTI_%'::text THEN '1'::character(1)
                      ELSE '0'::character(1)
                  END AS is_cti
             FROM rh.t_classes,
              rh.t_listes_tables
            WHERE t_classes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'ETS'::text
  ) UNION
   SELECT 'DT'::text || t_entreprises.oid::text AS oid,
      (t_entreprises.code || ' '::text) || t_entreprises.texte_court::text AS texte,
      t_entreprises.code,
      '1'::text AS level,
      ('9'::text || t_entreprises.code) || chr(1) AS tri,
      '0'::character(1) AS is_cti
     FROM rh.t_entreprises
       JOIN rh.t_etablissements ON t_etablissements.entreprise_id = t_entreprises.oid
    WHERE t_entreprises.oid <> 0
    GROUP BY ('DT'::text || t_entreprises.oid::text), ((t_entreprises.code || ' '::text) || t_entreprises.texte_court::text), t_entreprises.code, '1'::text, (('9'::text || t_entreprises.code) || chr(1))
  UNION
   SELECT 'D2'::text || t_etablissements.oid::text AS oid,
      (t_etablissements.code || ' '::text) || t_etablissements.texte_court::text AS texte,
      t_entreprises.code,
      '2'::text AS level,
      (('9'::text || t_entreprises.code) || chr(1)) || t_etablissements.code AS tri,
      '0'::character(1) AS is_cti
     FROM rh.t_etablissements
       JOIN rh.t_entreprises ON t_etablissements.entreprise_id = t_entreprises.oid
    WHERE t_etablissements.oid <> 0 AND t_entreprises.oid <> 0
    ORDER BY 5;
comment: La jointure sur les établissements pour la partie sur les entreprises, bien que superflue au premier abord, est nécessaire pour que la mécanique de data_profile puisse fonctionner.