src: |
  SELECT p_rsf_detail.rss_id,
      p_rsf_detail.finess,
      p_rsf_detail.no_rss,
      p_rsf_detail.nature,
      p_rsf_detail.mt,
      p_rsf_detail.dmt,
      p_rsf_detail.date_debut,
      p_rsf_detail.date_fin,
      p_rsf_detail.nombre,
      p_rsf_detail.coefficient,
      p_rsf_detail.prix_unitaire,
      p_rsf_detail.base_remboursement,
      p_rsf_detail.taux_remboursement,
      p_rsf_detail.prestation_id,
      t_prestations.code AS prestation_code,
      t_prestations.texte_court AS prestation_texte,
      t_prestations.texte_court AS prestation_compteur_rsf,
          CASE
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_1 AND p_rss.date_sortie <= t_prestations.date_fin_prive_1 THEN t_prestations.tarif_prive_1
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_2 AND p_rss.date_sortie <= t_prestations.date_fin_prive_2 THEN t_prestations.tarif_prive_2
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_3 AND p_rss.date_sortie <= t_prestations.date_fin_prive_3 THEN t_prestations.tarif_prive_3
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_4 AND p_rss.date_sortie <= t_prestations.date_fin_prive_4 THEN t_prestations.tarif_prive_4
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_5 AND p_rss.date_sortie <= t_prestations.date_fin_prive_5 THEN t_prestations.tarif_prive_5
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_6 AND p_rss.date_sortie <= t_prestations.date_fin_prive_6 THEN t_prestations.tarif_prive_6
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_7 AND p_rss.date_sortie <= t_prestations.date_fin_prive_7 THEN t_prestations.tarif_prive_7
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_8 AND p_rss.date_sortie <= t_prestations.date_fin_prive_8 THEN t_prestations.tarif_prive_8
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_9 AND p_rss.date_sortie <= t_prestations.date_fin_prive_9 THEN t_prestations.tarif_prive_9
              ELSE 0::numeric
          END AS tarif_prive,
          CASE
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_1 AND p_rss.date_sortie <= t_prestations.date_fin_prive_1 THEN t_prestations.tarif_prive_1 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_2 AND p_rss.date_sortie <= t_prestations.date_fin_prive_2 THEN t_prestations.tarif_prive_2 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_3 AND p_rss.date_sortie <= t_prestations.date_fin_prive_3 THEN t_prestations.tarif_prive_3 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_4 AND p_rss.date_sortie <= t_prestations.date_fin_prive_4 THEN t_prestations.tarif_prive_4 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_5 AND p_rss.date_sortie <= t_prestations.date_fin_prive_5 THEN t_prestations.tarif_prive_5 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_6 AND p_rss.date_sortie <= t_prestations.date_fin_prive_6 THEN t_prestations.tarif_prive_6 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_7 AND p_rss.date_sortie <= t_prestations.date_fin_prive_7 THEN t_prestations.tarif_prive_7 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_8 AND p_rss.date_sortie <= t_prestations.date_fin_prive_8 THEN t_prestations.tarif_prive_8 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_prive_9 AND p_rss.date_sortie <= t_prestations.date_fin_prive_9 THEN t_prestations.tarif_prive_9 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              ELSE 0::numeric
          END AS montant_prive,
          CASE
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_1 AND p_rss.date_sortie <= t_prestations.date_fin_public_1 THEN t_prestations.tarif_public_1
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_2 AND p_rss.date_sortie <= t_prestations.date_fin_public_2 THEN t_prestations.tarif_public_2
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_3 AND p_rss.date_sortie <= t_prestations.date_fin_public_3 THEN t_prestations.tarif_public_3
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_4 AND p_rss.date_sortie <= t_prestations.date_fin_public_4 THEN t_prestations.tarif_public_4
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_5 AND p_rss.date_sortie <= t_prestations.date_fin_public_5 THEN t_prestations.tarif_public_5
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_6 AND p_rss.date_sortie <= t_prestations.date_fin_public_6 THEN t_prestations.tarif_public_6
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_7 AND p_rss.date_sortie <= t_prestations.date_fin_public_7 THEN t_prestations.tarif_public_7
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_8 AND p_rss.date_sortie <= t_prestations.date_fin_public_8 THEN t_prestations.tarif_public_8
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_9 AND p_rss.date_sortie <= t_prestations.date_fin_public_9 THEN t_prestations.tarif_public_9
              ELSE 0::numeric
          END AS tarif_public,
          CASE
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_1 AND p_rss.date_sortie <= t_prestations.date_fin_public_1 THEN t_prestations.tarif_public_1 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_2 AND p_rss.date_sortie <= t_prestations.date_fin_public_2 THEN t_prestations.tarif_public_2 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_3 AND p_rss.date_sortie <= t_prestations.date_fin_public_3 THEN t_prestations.tarif_public_3 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_4 AND p_rss.date_sortie <= t_prestations.date_fin_public_4 THEN t_prestations.tarif_public_4 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_5 AND p_rss.date_sortie <= t_prestations.date_fin_public_5 THEN t_prestations.tarif_public_5 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_6 AND p_rss.date_sortie <= t_prestations.date_fin_public_6 THEN t_prestations.tarif_public_6 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_7 AND p_rss.date_sortie <= t_prestations.date_fin_public_7 THEN t_prestations.tarif_public_7 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_8 AND p_rss.date_sortie <= t_prestations.date_fin_public_8 THEN t_prestations.tarif_public_8 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              WHEN p_rss.date_sortie >= t_prestations.date_debut_public_9 AND p_rss.date_sortie <= t_prestations.date_fin_public_9 THEN t_prestations.tarif_public_9 * p_rsf_detail.nombre * p_rsf_detail.coefficient
              ELSE 0::numeric
          END AS montant_public
     FROM pmsi.p_rsf_detail,
      pmsi.p_rss,
      pmsi.t_prestations
    WHERE p_rsf_detail.rss_id = p_rss.oid AND p_rsf_detail.prestation_id = t_prestations.oid AND p_rsf_detail.type = 'B'::bpchar AND p_rsf_detail.est_ligne_rss = '1'::bpchar AND (t_prestations.code::text = ANY (ARRAY['NN1'::text, 'NN2'::text, 'NN3'::text, 'REA'::text, 'SRA'::text, 'SRC'::text, 'SSC'::text, 'STF'::text, 'REP'::text]));