src: |
  SELECT p_rss_actes.rss_id,
      p_rss_actes.activite_ccam,
      p_rss.en_cours,
          CASE
              WHEN t_listes.code = ANY (ARRAY['CTI000016A'::text, 'CTI000017A'::text, 'CTI000018A'::text]) THEN 'Activité interventionnelle sous imagerie médicale'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000019A'::text, 'CTI000020A'::text, 'CTI000021A'::text]) THEN 'Cardiopathies de l ’enfant ou cardiopathies congénitales'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000022A'::text, 'CTI000023A'::text, 'CTI000024A'::text]) THEN 'Autres cardiopathies de l’ adulte'::text
              ELSE ''::text
          END AS chapitre_texte,
          CASE
              WHEN t_listes.code = ANY (ARRAY['CTI000016A'::text, 'CTI000017A'::text, 'CTI000018A'::text]) THEN 'CTI000016A'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000019A'::text, 'CTI000020A'::text, 'CTI000021A'::text]) THEN 'CTI000019A'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000022A'::text, 'CTI000023A'::text, 'CTI000024A'::text]) THEN 'CTI000022A'::text
              ELSE ''::text
          END AS liste,
          CASE
              WHEN t_listes.code = ANY (ARRAY['CTI000016A'::text, 'CTI000017A'::text, 'CTI000018A'::text]) THEN 'CTI000017A'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000019A'::text, 'CTI000020A'::text, 'CTI000021A'::text]) THEN 'CTI000020A'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000022A'::text, 'CTI000023A'::text, 'CTI000024A'::text]) THEN 'CTI000023A'::text
              ELSE ''::text
          END AS listex,
          CASE
              WHEN t_listes.code = ANY (ARRAY['CTI000016A'::text, 'CTI000017A'::text, 'CTI000018A'::text]) THEN 'CTI000018A'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000019A'::text, 'CTI000020A'::text, 'CTI000021A'::text]) THEN 'CTI000021A'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000022A'::text, 'CTI000023A'::text, 'CTI000024A'::text]) THEN 'CTI000024A'::text
              ELSE ''::text
          END AS listenx,
      count(*) AS count
     FROM pmsi.p_rss
       JOIN pmsi.p_rss_actes ON p_rss_actes.rss_id = p_rss.oid
       JOIN pmsi.t_listes_contenu ON p_rss_actes.acte_id = t_listes_contenu.to_id
       JOIN pmsi.t_listes ON t_listes_contenu.liste_id = t_listes.oid AND (t_listes.code = ANY (ARRAY['CTI000016A'::text, 'CTI000017A'::text, 'CTI000018A'::text, 'CTI000019A'::text, 'CTI000020A'::text, 'CTI000021A'::text, 'CTI000022A'::text, 'CTI000023A'::text, 'CTI000024A'::text]))
    WHERE p_rss.en_cours = '0'::bpchar AND p_rss_actes.activite_ccam <> '4'::bpchar
    GROUP BY p_rss_actes.rss_id, p_rss_actes.activite_ccam, p_rss.en_cours, (
          CASE
              WHEN t_listes.code = ANY (ARRAY['CTI000016A'::text, 'CTI000017A'::text, 'CTI000018A'::text]) THEN 'Activité interventionnelle sous imagerie médicale'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000019A'::text, 'CTI000020A'::text, 'CTI000021A'::text]) THEN 'Cardiopathies de l ’enfant ou cardiopathies congénitales'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000022A'::text, 'CTI000023A'::text, 'CTI000024A'::text]) THEN 'Autres cardiopathies de l’ adulte'::text
              ELSE ''::text
          END), (
          CASE
              WHEN t_listes.code = ANY (ARRAY['CTI000016A'::text, 'CTI000017A'::text, 'CTI000018A'::text]) THEN 'CTI000016A'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000019A'::text, 'CTI000020A'::text, 'CTI000021A'::text]) THEN 'CTI000019A'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000022A'::text, 'CTI000023A'::text, 'CTI000024A'::text]) THEN 'CTI000022A'::text
              ELSE ''::text
          END), (
          CASE
              WHEN t_listes.code = ANY (ARRAY['CTI000016A'::text, 'CTI000017A'::text, 'CTI000018A'::text]) THEN 'CTI000017A'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000019A'::text, 'CTI000020A'::text, 'CTI000021A'::text]) THEN 'CTI000020A'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000022A'::text, 'CTI000023A'::text, 'CTI000024A'::text]) THEN 'CTI000023A'::text
              ELSE ''::text
          END), (
          CASE
              WHEN t_listes.code = ANY (ARRAY['CTI000016A'::text, 'CTI000017A'::text, 'CTI000018A'::text]) THEN 'CTI000018A'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000019A'::text, 'CTI000020A'::text, 'CTI000021A'::text]) THEN 'CTI000021A'::text
              WHEN t_listes.code = ANY (ARRAY['CTI000022A'::text, 'CTI000023A'::text, 'CTI000024A'::text]) THEN 'CTI000024A'::text
              ELSE ''::text
          END);