src: |
  SELECT p_rsf_total.finess,
      p_rsf_total.rss_id,
      p_rsf_total.taux_remboursement,
      p_rsf_total.type_contrat_oc_id,
      t_type_contrat_oc.code AS type_contrat_oc_code,
      t_type_contrat_oc.texte AS type_contrat_oc_texte,
      p_rsf_total.motif_non_facturation_id,
      t_motif_non_facturation.code AS motif_non_facturation_code,
      t_motif_non_facturation.texte AS motif_non_facturation_texte,
      p_rsf_total.regime_id,
      t_grands_regimes.code AS regime_code,
      t_grands_regimes.texte AS regime_texte,
      p_rsf_total.exoneration_tm_id,
      t_exoneration_tm.code AS exoneration_tm_code,
      t_exoneration_tm.texte AS exoneration_tm_texte,
      p_rsf_total.code_pec_fj_id,
      t_pec_fj.code AS code_pec_fj_code,
      t_pec_fj.texte AS code_pec_fj_texte,
      p_rsf_total.nature_pec_id,
      t_nature_assurance.code AS nature_pec_code,
      t_nature_assurance.texte AS nature_pec_texte,
      p_rsf_total.code_pec_id,
      t_pec.code AS code_pec_code,
      t_pec.texte AS code_pec_texte,
      p_rsf_total.facturation_18euros_id,
      t_facturation_18euros.code AS facturation_18euros_code,
      t_facturation_18euros.texte AS facturation_18euros_texte,
      p_rsf_total.pat_benef_cmu,
          CASE
              WHEN p_rsf_total.pat_benef_cmu IS NULL THEN 9
              ELSE p_rsf_total.pat_benef_cmu
          END AS pat_benef_cmu_id,
          CASE
              WHEN p_rsf_total.pat_benef_cmu IS NULL THEN 'X'::text
              ELSE p_rsf_total.pat_benef_cmu::text
          END AS pat_benef_cmu_code,
          CASE
              WHEN p_rsf_total.pat_benef_cmu IS NULL THEN 'Pas d''information sur la CMU'::text
              WHEN p_rsf_total.pat_benef_cmu = 1 THEN 'Patient bénéficiaire de la CMU'::text
              ELSE 'Patient non bénéficiaire de la CMU'::text
          END AS pat_benef_cmu_texte,
      p_rsf_total.valorise_fides AS valorise_fides_id,
      p_rsf_total.valorise_fides::text AS valorise_fides_code,
          CASE
              WHEN p_rsf_total.valorise_fides = 1 THEN 'Valorisé FIDES'::text
              WHEN p_rsf_total.valorise_fides = 0 THEN 'Non Valorisé FIDES'::text
              ELSE 'Non renseigné'::text
          END AS valorise_fides_texte,
      p_rsf_total.ca_ghs_sans_coefficient
     FROM pmsi.p_rsf_total
       JOIN base.t_grands_regimes ON t_grands_regimes.oid = p_rsf_total.regime_id
       JOIN base.t_nature_assurance ON t_nature_assurance.oid = p_rsf_total.nature_pec_id
       JOIN base.t_exoneration_tm ON t_exoneration_tm.oid = p_rsf_total.exoneration_tm_id
       JOIN base.t_pec ON t_pec.oid = p_rsf_total.code_pec_id
       JOIN base.t_pec_fj ON t_pec_fj.oid = p_rsf_total.code_pec_fj_id
       JOIN base.t_type_contrat_oc ON t_type_contrat_oc.oid = p_rsf_total.type_contrat_oc_id
       JOIN base.t_motif_non_facturation ON t_motif_non_facturation.oid = p_rsf_total.motif_non_facturation_id
       JOIN base.t_facturation_18euros ON t_facturation_18euros.oid = p_rsf_total.facturation_18euros_id;