src: |
  SELECT p_accident_travail.oid AS accident_travail_id,
      p_accident_travail.oid AS accident_travail_code,
      (p_salaries.nom::text || ' '::text) || p_salaries.prenom::text AS accident_travail_texte,
      p_accident_travail.mois_activite AS mois_accident_travail,
      p_accident_travail.date AS date_accident_travail,
      p_accident_travail.accident_circonstance_id AS rhp_accident_circonstance_id,
      p_accident_travail.accident_lieu_id AS rhp_accident_lieu_id,
      p_accident_travail.accident_nature_id AS rhp_accident_nature_id,
      p_accident_travail.accident_siege_id AS rhp_accident_siege_id,
      p_salaries.finess,
      p_contrats_mois.etablissement_id AS rhp_etablissement_id,
      p_salaries.oid AS salarie_id,
      p_salaries.matricule AS salarie_code,
      (p_salaries.nom::text || ' '::text) || p_salaries.prenom::text AS salarie_texte,
      p_salaries.nom,
      p_salaries.nom_naissance,
      p_salaries.prenom,
      p_salaries.date_naissance,
          CASE
              WHEN p_salaries.sexe = 'F'::bpchar THEN 2
              ELSE 1
          END AS sexe_id,
      p_salaries.sexe AS sexe_code,
          CASE
              WHEN p_salaries.sexe = 'F'::bpchar THEN 'Féminin'::text
              ELSE 'Masculin'::text
          END AS sexe_texte,
      p_salaries.situation_famille_id AS rhp_situation_famille_id,
      p_salaries.code_original,
      p_salaries.entreprise_id AS rhp_entreprise_id,
      p_salaries.nationalite_id AS rhp_nationalite_id,
      p_salaries.code_postal_id AS rhp_code_postal_id,
      p_salaries.personne_id AS rhp_personne_id,
      p_profil_contrat_mois.profil_id AS rhp_profil_id,
      p_contrats_mois.anciennete_mois,
      p_contrats_mois.anciennete_reprise_mois,
      p_contrats_mois.anciennete_annee_id AS rhp_anciennete_annee_id,
      p_contrats_mois.anciennete_reprise_annee_id AS rhp_anciennete_reprise_annee_id,
      p_contrats_mois.age_id AS rhp_age_id,
      p_contrats_mois.age_jours,
      p_contrats_mois.mois_activite::bigint AS annee_mois_activite_id,
      p_contrats_mois.mois_activite::text AS annee_mois_activite_code,
      (base.cti_to_french(to_char(p_contrats_mois.date_fin::timestamp with time zone, 'Month'::text)) || ' '::text) || substr(p_contrats_mois.mois_activite::text, 1, 4) AS annee_mois_activite_texte,
      (substr(p_contrats_mois.mois_activite::text, 1, 4) || date_part('quarter'::text, p_contrats_mois.date_fin)::text)::bigint AS annee_trimestre_activite_id,
      substr(p_contrats_mois.mois_activite::text, 1, 4) || date_part('quarter'::text, p_contrats_mois.date_fin)::text AS annee_trimestre_activite_code,
      (('T'::text || date_part('quarter'::text, p_contrats_mois.date_fin)::text) || ' '::text) || substr(p_contrats_mois.mois_activite::text, 1, 4) AS annee_trimestre_activite_texte,
      substr(p_contrats_mois.mois_activite::text, 5, 2)::bigint AS mois_only_activite_id,
      substr(p_contrats_mois.mois_activite::text, 5, 2) AS mois_only_activite_code,
      base.cti_to_french(to_char(p_contrats_mois.date_fin::timestamp with time zone, 'Month'::text)) AS mois_only_activite_texte,
      date_part('quarter'::text, p_contrats_mois.date_fin)::bigint AS trimestre_activite_id,
      date_part('quarter'::text, p_contrats_mois.date_fin)::text AS trimestre_activite_code,
      'T'::text || date_part('quarter'::text, p_contrats_mois.date_fin)::text AS trimestre_activite_texte,
      p_contrats_mois.oid AS contrat_mois_id,
      p_contrats_mois.mois_activite AS mois_activite_id,
      p_contrats_mois.mois_activite AS mois_activite_code,
      (
          CASE
              WHEN date_part('month'::text, p_contrats_mois.date_fin) = 1::double precision THEN 'Janvier'::text
              WHEN date_part('month'::text, p_contrats_mois.date_fin) = 2::double precision THEN 'Février'::text
              WHEN date_part('month'::text, p_contrats_mois.date_fin) = 3::double precision THEN 'Mars'::text
              WHEN date_part('month'::text, p_contrats_mois.date_fin) = 4::double precision THEN 'Avril'::text
              WHEN date_part('month'::text, p_contrats_mois.date_fin) = 5::double precision THEN 'Mai'::text
              WHEN date_part('month'::text, p_contrats_mois.date_fin) = 6::double precision THEN 'Juin'::text
              WHEN date_part('month'::text, p_contrats_mois.date_fin) = 7::double precision THEN 'Juillet'::text
              WHEN date_part('month'::text, p_contrats_mois.date_fin) = 8::double precision THEN 'Aout'::text
              WHEN date_part('month'::text, p_contrats_mois.date_fin) = 9::double precision THEN 'Septembre'::text
              WHEN date_part('month'::text, p_contrats_mois.date_fin) = 10::double precision THEN 'Octobre'::text
              WHEN date_part('month'::text, p_contrats_mois.date_fin) = 11::double precision THEN 'Novembre'::text
              WHEN date_part('month'::text, p_contrats_mois.date_fin) = 12::double precision THEN 'Décembre'::text
              ELSE date_part('month'::text, p_contrats_mois.date_fin)::text
          END || ' '::text) || date_part('year'::text, p_contrats_mois.date_fin)::text AS mois_activite_texte,
      date_part('year'::text, p_contrats_mois.date_fin) AS annee_activite_id,
      date_part('year'::text, p_contrats_mois.date_fin) AS annee_activite_code,
      date_part('year'::text, p_contrats_mois.date_fin) AS annee_activite_texte,
      p_contrats_mois.date_debut AS date_debut_activite,
      p_contrats_mois.date_fin AS date_fin_activite,
      p_contrats.oid AS contrat_id,
      p_contrats.numero_contrat AS contrat_code,
      (p_salaries.nom::text || ' '::text) || p_salaries.prenom::text AS contrat_texte,
      p_contrats.date_debut AS date_debut_contrat,
      p_contrats.date_fin AS date_fin_contrat,
      p_contrats_mois.effectif_permanent,
      p_contrats_mois.present_debut_mois,
      p_contrats_mois.present_fin_mois,
      p_salaries.date_entree_ets,
      p_salaries.date_entree_fp,
      p_salaries.date_entree_fph,
      p_contrats_mois.anciennete_fp_mois,
      p_contrats_mois.anciennete_fp_annee_id,
      p_contrats_mois.anciennete_fph_mois,
      p_contrats_mois.anciennete_fph_annee_id,
      p_contrats.salarie_remplace_id AS rhp_salarie_remplace_id,
      p_salaries.no_adeli,
      p_salaries.matricule_retraite,
      p_salaries.code_cotisation_id AS rhp_code_cotisation_id,
      p_salaries.section_id AS salarie_section_id,
      p_salaries.section_code AS salarie_section_code,
      p_salaries.section_texte AS salarie_section_texte,
      p_profil_contrat_mois.pole_id AS rhp_pole_id,
      p_profil_contrat_mois.population_id[1] AS rhp_population_id,
      p_profil_contrat_mois.budget_cle_id AS rhp_budget_cle_id
     FROM rh.p_salaries
       JOIN rh.p_accident_travail ON p_accident_travail.salarie_id = p_salaries.oid
       JOIN rh.p_contrats ON p_contrats.oid = p_accident_travail.contrat_id
       JOIN rh.p_contrats_mois ON p_contrats_mois.oid = p_accident_travail.contrat_mois_id
       JOIN rh.p_profil_contrat_mois ON p_profil_contrat_mois.contrat_mois_id = p_contrats_mois.oid;