From dd37c8e752c86f94c4bede46c7ef1d01ff37b96c Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Nez Date: Wed, 4 Dec 2024 10:13:21 +0000 Subject: [PATCH] end dbt --- models/capacite/int_capacite_service.sql | 2 +- .../int_taux_recours_dpt_intermediate.sql | 2 +- .../class_join_total_morbidite_sexe.sql | 96 ------------------- ...s_join_total_morbidite_sexe_population.sql | 17 ++++ ...lass_join_total_morbidite_capacite_kpi.sql | 10 +- 5 files changed, 28 insertions(+), 99 deletions(-) delete mode 100644 models/join_total_morbidite/class_join_total_morbidite_sexe.sql diff --git a/models/capacite/int_capacite_service.sql b/models/capacite/int_capacite_service.sql index eebfe9b..04dbc9f 100644 --- a/models/capacite/int_capacite_service.sql +++ b/models/capacite/int_capacite_service.sql @@ -25,5 +25,5 @@ SEHEM as seance_hemodyalise, SERAD as seance_radiotherapie, SECHI as seance_chimio, cle_unique -FROM {{ref('stg_capacite_services_h__capacite_2022_par_service')}} +FROM {{ref('stg_capacite_services_h__capacite_2022_par_service1')}} WHERE an >= 2018 \ No newline at end of file diff --git a/models/interrmediate/int_taux_recours_dpt_intermediate.sql b/models/interrmediate/int_taux_recours_dpt_intermediate.sql index 55933d9..b2b2432 100644 --- a/models/interrmediate/int_taux_recours_dpt_intermediate.sql +++ b/models/interrmediate/int_taux_recours_dpt_intermediate.sql @@ -23,7 +23,7 @@ SPLIT(region, " - ")[SAFE_OFFSET(1)] AS nom_departement, SAFE_CAST(NULLIF(tx_brut_tt_age_pour_mille, 'ND') AS FLOAT64) AS tx_brut_tt_age_pour_mille, SAFE_CAST(NULLIF(tx_standard_tt_age_pour_mille, 'ND') AS FLOAT64) AS tx_standard_tt_age_pour_mille, SAFE_CAST(NULLIF(indice_comparatif_tt_age_percent, 'ND') AS FLOAT64) AS indice_comparatif_tt_age_percent - FROM {{ref("stg_morbidite_h__taux_recours")}} + FROM {{ref("stg_morbidite_h__taux_recours2")}} WHERE NOT (region LIKE '3 - France%' OR region LIKE '1 - France%') AND niveau LIKE "Départements" AND nom_pathologie != 'TOTAL TOUTES CAUSES' diff --git a/models/join_total_morbidite/class_join_total_morbidite_sexe.sql b/models/join_total_morbidite/class_join_total_morbidite_sexe.sql deleted file mode 100644 index 9d82801..0000000 --- a/models/join_total_morbidite/class_join_total_morbidite_sexe.sql +++ /dev/null @@ -1,96 +0,0 @@ -WITH mega_join AS ( - SELECT - t1.niveau - ,t1.cle_unique - ,t1.sexe - ,t1.year - ,t1.annee - ,t1.pathologie - ,t1.code_pathologie - ,t1.nom_pathologie - ,t1.region - ,t1.code_region - ,t1.nom_region - ,t1.nbr_hospi - ,t1.evolution_nbr_hospi1 as evolution_nbr_hospi - ,t1.evolution_percent_nbr_hospi1 as evolution_percent_nbr_hospi - - ,t2.AVG_duree_hospi - ,t2.evolution_hospi_total_24h1 as evolution_hospi_total_24h - ,t2.evolution_percent_hospi_total_24h1 as evolution_percent_hospi_total_24h - ,t2.evolution_hospi_total_jj1 as evolution_hospi_total_jj - ,t2.evolution_percent_hospi_total_jj1 as evolution_percent_hospi_total_jj - ,t2.evolution_total_hospi2 as evolution_total_hospi - ,t2.evolution_percent_total_hospi2 as evolution_percent_total_hospi - ,t2.evolution_AVG_duree_hospi1 as evolution_AVG_duree_hospi - ,t2.evolution_percent_AVG_duree_hospi1 as evolution_percent_AVG_duree_hospi - - ,t3.tranche_age_0_1 - ,t3.tranche_age_1_4 - ,t3.tranche_age_5_14 - ,t3.tranche_age_15_24 - ,t3.tranche_age_25_34 - ,t3.tranche_age_35_44 - ,t3.tranche_age_45_54 - ,t3.tranche_age_55_64 - ,t3.tranche_age_65_74 - ,t3.tranche_age_75_84 - ,t3.tranche_age_85_et_plus - ,t3.tx_brut_tt_age_pour_mille - ,t3.tx_standard_tt_age_pour_mille - ,t3.indice_comparatif_tt_age_percent - ,t3.evolution_tx_brut_tt_age_pour_mille1 as evolution_tx_brut_tt_age_pour_mille - ,t3.evolution_percent_tx_brut_tt_age_pour_mille1 as evolution_percent_tx_brut_tt_age_pour_mille - ,t3.evolution_tx_standard_tt_age_pour_mille2 as evolution_tx_standard_tt_age_pour_mille - ,t3.evolution_percent_tx_standard_tt_age_pour_mille2 as evolution_percent_tx_standard_tt_age_pour_mille - ,t3.evolution_indice_comparatif_tt_age_percent1 as evolution_indice_comparatif_tt_age_percent - ,t3.evolution_percent_indice_comparatif_tt_age_percent1 as evolution_percent_indice_comparatif_tt_age_percent - - FROM - {{ref("mart_nbr_hospi_total_evol")}} t1 - LEFT JOIN - {{ref("mart_duree_sejours_total_evol")}} t2 - ON t1.cle_unique = t2.cle_unique - INNER JOIN - {{ref("mart_taux_recours_total_evol")}} t3 - ON t1.cle_unique = t3.cle_unique - AND t1.sexe = t3.sexe - WHERE - t1.tranche_age = 'Tous âges confondus' -), -mega_join_class as ( -SELECT - t1.* - ,classification -FROM mega_join AS t1 -LEFT JOIN {{ref("stg_morbidite_h__class_services")}} c2 -ON t1.nom_pathologie = c2.pathologie -ORDER BY cle_unique -), -join_dpt AS ( - SELECT - t1.*, - t2.population AS population - FROM mega_join_class t1 - LEFT JOIN {{ ref("stg_pop_departement__population_departement") }} t2 - ON t1.annee = t2.annee - AND t1.nom_region = t2.nom_departement - WHERE t1.niveau = 'Départements' -), -join_reg AS ( - SELECT - t1.*, - t2.population AS population - FROM mega_join_class t1 - LEFT JOIN {{ ref("stg_pop_departement__population_region") }} t2 - ON t1.annee = t2.annee - AND t1.nom_region = t2.region - WHERE t1.niveau = 'Régions' -) - -SELECT * -FROM join_dpt -UNION ALL -SELECT * -FROM join_reg - diff --git a/models/join_total_morbidite/class_join_total_morbidite_sexe_population.sql b/models/join_total_morbidite/class_join_total_morbidite_sexe_population.sql index 9d82801..1d99693 100644 --- a/models/join_total_morbidite/class_join_total_morbidite_sexe_population.sql +++ b/models/join_total_morbidite/class_join_total_morbidite_sexe_population.sql @@ -15,6 +15,23 @@ WITH mega_join AS ( ,t1.evolution_nbr_hospi1 as evolution_nbr_hospi ,t1.evolution_percent_nbr_hospi1 as evolution_percent_nbr_hospi + ,t2.hospi_prog_24h + ,t2.hospi_autres_24h + ,t2.hospi_total_24h + ,t2.hospi_1J + ,t2.hospi_2J + ,t2.hospi_3J + ,t2.hospi_4J + ,t2.hospi_5J + ,t2.hospi_6J + ,t2.hospi_7J + ,t2.hospi_8J + ,t2.hospi_9J + ,t2.hospi_10J_19J + ,t2.hospi_20J_29J + ,t2.hospi_30J + ,t2.hospi_total_jj + ,t2.total_hospi ,t2.AVG_duree_hospi ,t2.evolution_hospi_total_24h1 as evolution_hospi_total_24h ,t2.evolution_percent_hospi_total_24h1 as evolution_percent_hospi_total_24h diff --git a/models/join_total_morbidite_capacite/class_join_total_morbidite_capacite_kpi.sql b/models/join_total_morbidite_capacite/class_join_total_morbidite_capacite_kpi.sql index 01e4529..57baa85 100644 --- a/models/join_total_morbidite_capacite/class_join_total_morbidite_capacite_kpi.sql +++ b/models/join_total_morbidite_capacite/class_join_total_morbidite_capacite_kpi.sql @@ -77,12 +77,15 @@ SELECT IFNULL(CAST(evolution_percent_sejour_hospi_partielle AS FLOAT64), 0) AS evolution_percent_sejour_hospi_partielle, IFNULL(CAST(evolution_passage_urgence AS FLOAT64), 0) AS evolution_passage_urgence, IFNULL(CAST(evolution_percent_passage_urgence AS FLOAT64), 0) AS evolution_percent_passage_urgence, - ROUND(safe_divide((nbr_hospi * AVG_duree_hospi) , (journee_hospi_complete + sejour_hospi_partielle)),2) as taux_occupation + ROUND(safe_divide((nbr_hospi * AVG_duree_hospi) , (journee_hospi_complete + sejour_hospi_partielle)),2) as taux_occupation, + ROUND(safe_divide((lit_hospi_complete + place_hospi_partielle), population)*1000,2) as taux_equipement + FROM {{ref("class_join_total_morbidite_capacite")}} ), base_data as ( SELECT * ,AVG(taux_occupation) OVER (PARTITION BY annee, region, classification) AS taux_occupation1 + ,AVG(taux_equipement) OVER (PARTITION BY annee, region, classification) AS taux_equipement1 FROM nullval ) SELECT @@ -92,6 +95,11 @@ base_data as ( WHEN COALESCE(bd2.taux_occupation1, 0) = 0 THEN NULL ELSE Round(safe_divide((bd1.taux_occupation1 - bd2.taux_occupation1) , bd2.taux_occupation1), 2) END AS evolution_percent_taux_occupation1, + round(bd1.taux_equipement1 - COALESCE(bd2.taux_equipement1, 0),2) AS evolution_taux_equipement1, + CASE + WHEN COALESCE(bd2.taux_equipement1, 0) = 0 THEN NULL + ELSE Round(safe_divide((bd1.taux_equipement1 - bd2.taux_equipement1) , bd2.taux_equipement1), 2) + END AS evolution_percent_taux_equipement1, FROM base_data bd1 LEFT JOIN base_data bd2 ON bd1.region = bd2.region