src: |
  SELECT 'I**'::text AS code,
      'Aucun acte saisi'::text AS texte,
      t_classes.texte AS nom_version,
      1 AS level,
      10 AS tri
     FROM pmsi.t_classes
    WHERE lower(t_classes.texte) ~~ '%msap%'::text AND lower(t_classes.texte) ~~ '%2015%'::text
    GROUP BY 'I**'::text, 'Aucun acte saisi'::text, t_classes.texte, 1::integer, 10::integer
  UNION
   SELECT 'I***'::text AS code,
      'Aucun geste marqueur'::text AS texte,
      t_classes.texte AS nom_version,
      1 AS level,
      20 AS tri
     FROM pmsi.t_classes
    WHERE lower(t_classes.texte) ~~ '%msap%'::text AND lower(t_classes.texte) ~~ '%2015%'::text
    GROUP BY 'I***'::text, 'Aucun geste marqueur'::text, t_classes.texte, 1::integer, 20::integer
  UNION
   SELECT 'S****'::text AS code,
      'Au moins un geste marqueur'::text AS texte,
      t_classes.texte AS nom_version,
      1 AS level,
      30 AS tri
     FROM pmsi.t_classes
    WHERE lower(t_classes.texte) ~~ '%msap%'::text AND lower(t_classes.texte) ~~ '%2015%'::text
    GROUP BY 'S****'::text, 'Au moins un geste marqueur'::text, t_classes.texte, 1::integer, 30::integer
  UNION
   SELECT 'X****'::text AS code,
      'Acte Principal différent de Geste Marqueur principal'::text AS texte,
      t_classes.texte AS nom_version,
      1 AS level,
      31 AS tri
     FROM pmsi.t_classes
    WHERE lower(t_classes.texte) ~~ '%msap%'::text AND lower(t_classes.texte) ~~ '%2015%'::text
    GROUP BY 'X****'::text, 'Acte Principal différent de Geste Marqueur principal'::text, t_classes.texte, 1::integer, 31::integer
  UNION
   SELECT 'I****'::text AS code,
      'Hors PMSI'::text AS texte,
      t_classes.texte AS nom_version,
      1 AS level,
      40 AS tri
     FROM pmsi.t_classes
    WHERE lower(t_classes.texte) ~~ '%msap%'::text AND lower(t_classes.texte) ~~ '%2015%'::text
    GROUP BY 'I****'::text, 'Hors PMSI'::text, t_classes.texte, 1::integer, 40::integer
  UNION
   SELECT 'I'::text || t_classes_sections.code AS code,
      (t_classes_sections.code || ' - '::text) || t_classes_sections.texte AS texte,
      t_classes.texte AS nom_version,
      1 AS level,
      50 AS tri
     FROM pmsi.t_classes_sections
       JOIN pmsi.t_classes ON t_classes.oid = t_classes_sections.classe_id
    WHERE lower(t_classes.texte) ~~ '%msap%'::text AND lower(t_classes.texte) ~~ '%2015%'::text
  UNION
   SELECT 'S'::text || t_classes_sections.code AS code,
      (('SAUF '::text || t_classes_sections.code) || ' - '::text) || t_classes_sections.texte AS texte,
      t_classes.texte AS nom_version,
      1 AS level,
      60 AS tri
     FROM pmsi.t_classes_sections
       JOIN pmsi.t_classes ON t_classes.oid = t_classes_sections.classe_id
    WHERE lower(t_classes.texte) ~~ '%msap%'::text AND lower(t_classes.texte) ~~ '%2015%'::text
    ORDER BY 5, 1;