src: |
  SELECT p_rsf_detail_h.rss_id,
      p_rsf_detail_h.finess,
      p_rsf_detail_h.no_rss,
      p_rsf_detail_h.date_acte,
      t_medecins_c.specialite_id AS specialite_medecin_id,
      t_medecins_c.specialite_medecin_code,
      t_medecins_c.specialite_medecin_texte,
      t_medecins_c.specialite_interne_id AS specialite_interne_medecin_id,
      t_medecins_c.specialite_interne_medecin_code,
      t_medecins_c.specialite_interne_medecin_texte,
      p_rsf_detail_h.medecin_id,
      t_medecins_c.code AS medecin_code,
      t_medecins_c.nom_prenom AS medecin_nom,
      t_medecins_c.specialite_medecin_reference_id,
      t_medecins_c.specialite_medecin_code AS specialite_medecin_reference_code,
      t_medecins_c.specialite_medecin_texte AS specialite_medecin_reference_texte,
      t_medecins_c.specialite_interne_id AS specialite_interne_medecin_reference_id,
      t_medecins_c.specialite_interne_medecin_code AS specialite_interne_medecin_reference_code,
      t_medecins_c.specialite_interne_medecin_texte AS specialite_interne_medecin_reference_texte,
      t_medecins_c.medecin_reference_id,
      t_medecins_c.code AS medecin_reference_code,
      t_medecins_c.nom_prenom AS medecin_reference_nom,
      p_rsf_detail_h.acte_id,
      t_actes.code AS acte_code,
      t_actes.texte_court AS acte_texte,
      t_actes.nomenclature AS acte_nomenclature,
      t_actes.geste_marqueur_id,
      t_gestes_marqueurs.code AS geste_marqueur_code,
      t_gestes_marqueurs.texte_court AS geste_marqueur_texte,
          CASE
              WHEN p_rsf_detail_h.activite_ccam <> '4'::bpchar THEN t_actes.ccam_regroupement_id_1
              ELSE t_actes.ccam_regroupement_id_4
          END AS acte_regroupement_id,
          CASE
              WHEN p_rsf_detail_h.activite_ccam <> '4'::bpchar THEN t_ccam_regroupements_1.code
              ELSE t_ccam_regroupements_4.code
          END AS acte_regroupement_code,
          CASE
              WHEN p_rsf_detail_h.activite_ccam <> '4'::bpchar THEN t_ccam_regroupements_1.texte_court
              ELSE t_ccam_regroupements_4.texte_court
          END AS acte_regroupement_texte,
      t_actes.classant AS acte_classant,
      t_actes.marqueur AS acte_marqueur,
      p_rsf_detail_h.nombre,
          CASE
              WHEN p_rsf_detail_h.activite_ccam <> '4'::bpchar THEN p_rsf_detail_h.nombre
              ELSE 0::numeric
          END AS nombre_activite_1,
          CASE
              WHEN p_rsf_detail_h.activite_ccam = '4'::bpchar THEN p_rsf_detail_h.nombre
              ELSE 0::numeric
          END AS nombre_activite_4,
      p_rsf_detail_h.coefficient,
      p_rsf_detail_h.prix_unitaire,
      p_rsf_detail_h.base_remboursement,
          CASE
              WHEN p_rsf_detail_h.activite_ccam <> '4'::bpchar THEN p_rsf_detail_h.base_remboursement
              ELSE 0::numeric
          END AS base_remboursement_1,
          CASE
              WHEN p_rsf_detail_h.activite_ccam = '4'::bpchar THEN p_rsf_detail_h.base_remboursement
              ELSE 0::numeric
          END AS base_remboursement_4,
      p_rsf_detail_h.montant_facture,
      p_rsf_detail_h.montant_depassement,
          CASE
              WHEN p_rsf_detail_h.activite_ccam <> '4'::bpchar THEN t_actes.icr_1
              ELSE t_actes.icr_4
          END AS icr,
          CASE
              WHEN p_rsf_detail_h.activite_ccam <> '4'::bpchar THEN t_actes.icr_1
              ELSE 0::numeric
          END AS icr_activite_1,
          CASE
              WHEN p_rsf_detail_h.activite_ccam = '4'::bpchar THEN t_actes.icr_4
              ELSE 0::numeric
          END AS icr_activite_4,
      p_rsf_detail_h.phase_ccam,
      p_rsf_detail_h.activite_ccam,
      p_rsf_detail_h.extension_ccam,
      p_rsf_detail_h.modificateur_ccam_1,
      p_rsf_detail_h.modificateur_ccam_2,
      p_rsf_detail_h.modificateur_ccam_3,
      p_rsf_detail_h.modificateur_ccam_4,
      p_rsf_detail_h.remboursement_excp_ccam,
      p_rsf_detail_h.association_nonprevue_ccam
     FROM pmsi.p_rsf_detail_h p_rsf_detail_h,
      pmsi.t_actes,
      pmsi.t_gestes_marqueurs,
      pmsi.t_medecins_c,
      pmsi.t_specialites_medecin,
      pmsi.t_ccam_regroupements t_ccam_regroupements_1,
      pmsi.t_ccam_regroupements t_ccam_regroupements_4
    WHERE p_rsf_detail_h.acte_id = t_actes.oid AND t_gestes_marqueurs.oid = t_actes.geste_marqueur_id AND p_rsf_detail_h.medecin_id = t_medecins_c.oid AND t_actes.ccam_regroupement_id_1 = t_ccam_regroupements_1.oid AND t_actes.ccam_regroupement_id_4 = t_ccam_regroupements_4.oid;