src: |
  SELECT p_rss.oid AS rss_id,
          CASE
              WHEN p_rss_actes.rss_id IS NULL THEN - 1::bigint
              WHEN (p_rss_gm.gm_principal_id IS NULL OR p_rss_gm.gm_principal_id = 0) AND t_ghm_c.mco <> '*'::bpchar THEN - 2::bigint
              WHEN t_ghm_c.mco = '*'::bpchar THEN 0::bigint
              ELSE p_rss_gm.gm_principal_id
          END AS gm_id,
          CASE
              WHEN p_rss_actes.rss_id IS NULL THEN '**'::character varying::text
              WHEN (p_rss_gm.gm_principal_id IS NULL OR p_rss_gm.gm_principal_id = 0) AND t_ghm_c.mco <> '*'::bpchar THEN '***'::character varying::text
              WHEN t_ghm_c.mco = '*'::bpchar THEN '****'::character varying::text
              ELSE tcs1.code
          END AS gm_code,
          CASE
              WHEN p_rss_actes.rss_id IS NULL THEN 'Aucun Acte saisi'::character varying::text
              WHEN (p_rss_gm.gm_principal_id IS NULL OR p_rss_gm.gm_principal_id = 0) AND t_ghm_c.mco <> '*'::bpchar THEN 'Aucun Geste marqueur'::character varying::text
              WHEN t_ghm_c.mco = '*'::bpchar THEN 'Hors PMSI'::character varying::text
              ELSE tcs1.texte
          END AS gm_texte
     FROM pmsi.p_rss
       LEFT JOIN pmsi.p_rss_actes ON p_rss_actes.rss_id = p_rss.oid
       JOIN pmsi.t_ghm_c ON p_rss.ghm_id = t_ghm_c.oid
       LEFT JOIN pmsi.p_rss_gm ON p_rss_gm.rss_id = p_rss.oid
       LEFT JOIN pmsi.t_classes_sections tcs1 ON tcs1.oid = p_rss_gm.gm_principal_id
    GROUP BY p_rss.oid, p_rss_actes.rss_id, t_ghm_c.mco, p_rss_gm.gm_principal_id, tcs1.code, tcs1.texte
    ORDER BY (
          CASE
              WHEN p_rss_actes.rss_id IS NULL THEN - 1::bigint
              WHEN (p_rss_gm.gm_principal_id IS NULL OR p_rss_gm.gm_principal_id = 0) AND t_ghm_c.mco <> '*'::bpchar THEN - 2::bigint
              WHEN t_ghm_c.mco = '*'::bpchar THEN 0::bigint
              ELSE p_rss_gm.gm_principal_id
          END);