diff --git a/models/capacite/int_capacite_service.sql b/models/capacite/int_capacite_service.sql index 4fcf46e..3862f62 100644 --- a/models/capacite/int_capacite_service.sql +++ b/models/capacite/int_capacite_service.sql @@ -1,37 +1,3 @@ --- With stjr1 as ( --- SELECT --- t1.*, --- t2.stjr --- FROM {{ref('stg_capacite_services_h__capacite_2022_par_services')}} t1 --- LEFT JOIN ( --- SELECT DISTINCT FI, AN, stjr --- FROM {{ref('stg_capacite_services_h__capacite_2021_service_stjr')}} --- WHERE AN = 2021 --- ) t2 --- ON t1.fi = t2.FI --- WHERE t1.an >= 2018 AND t1.an < 2022 --- ), --- stjr2 as ( --- SELECT --- t1.*, --- t2.stjr --- FROM {{ref('stg_capacite_services_h__capacite_2022_par_services')}} t1 --- LEFT JOIN ( --- SELECT DISTINCT fi, an, stjr --- FROM {{ref('stg_capacite_services_h__capacite_2022_etablissement_stjr')}} --- WHERE AN = 2022 --- ) t2 --- ON CAST(t1.fi AS STRING) = t2.fi --- WHERE t1.an = 2022 --- ), --- join_stjr as ( --- SELECT * --- FROM stjr1 --- UNION ALL --- SELECT * --- FROM stjr2 --- ) - SELECT fi as id_etablissement, an as annee, @@ -59,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_services')}} +FROM {{ref('stg_capacite_services_h__capacite_2022_par_service')}} WHERE an >= 2018 \ No newline at end of file diff --git a/models/duree_sejours_total/int_duree_sejours_total.sql b/models/duree_sejours_total/int_duree_sejours_total.sql index bf25054..7822174 100644 --- a/models/duree_sejours_total/int_duree_sejours_total.sql +++ b/models/duree_sejours_total/int_duree_sejours_total.sql @@ -1,5 +1,5 @@ SELECT niveau, - cle_unique, + CONCAT(region , "_" , code_pathologie ,"_" , annee) as cle_unique, annee, year, pathologie, diff --git a/models/join_total_morbidite/class_join_total_morbidite_sexe.sql b/models/join_total_morbidite/class_join_total_morbidite_sexe.sql new file mode 100644 index 0000000..9d82801 --- /dev/null +++ b/models/join_total_morbidite/class_join_total_morbidite_sexe.sql @@ -0,0 +1,96 @@ +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/schema.yml b/models/schema.yml index 9a51246..8f13128 100644 --- a/models/schema.yml +++ b/models/schema.yml @@ -4,14 +4,14 @@ sources: - name: morbidite_h schema: morbidite_h tables: - - name: taux_recours - identifier: tranche_age_hospi_clean + - name: taux_recours3 + identifier: tableau_3_ren description: "test" - - name: duree_sejours - identifier: duree_hospi_clean + - name: duree_sejours2 + identifier: tableau_2_ren description: "test" - - name: nombre_hospit - identifier: nbr_hospi_clean + - name: nombre_hospit1 + identifier: tableau_1_ren description: 'test' - name: class_services @@ -32,17 +32,11 @@ sources: - name: capacite_services_h schema: capacite_services_h tables: - - name: capacite_2022_par_services - identifier: capacite_2022_par_services - description: "Test" - - name: capacite_2022_par_etablissement - identifier: capacite_2022_par_etablissement - description: "Test" - - name: capacite_2022_etablissement_stjr - identifier: capacite_2022_etablissement_stjr - description: "Test" - - name: capacite_2021_service_stjr - identifier: capacite_2021_service_stjr + - name: capacite_2022_par_service_clean + identifier: capacite_2022_par_service_clean + description: "Tebrfbest" + - name: capacite_2022_par_etablissement_clean + identifier: capacite_2022_par_etablissement_clean description: "Test" - name: capacite_services_dpt_region identifier: capacite_services_dpt_region diff --git a/models/staging/capacite_services_h/stg_capacite_services_h__capacite_2021_service_stjr.sql b/models/staging/capacite_services_h/stg_capacite_services_h__capacite_2021_service_stjr.sql deleted file mode 100644 index 0352a9f..0000000 --- a/models/staging/capacite_services_h/stg_capacite_services_h__capacite_2021_service_stjr.sql +++ /dev/null @@ -1,34 +0,0 @@ -with - -source as ( - - select * from {{ source('capacite_services_h', 'capacite_2021_service_stjr') }} - -), - -renamed as ( - - select - an, - fi, - fi_ej, - stjr, - disci, - lit, - sejhc, - jou, - pla, - sejhp, - pas, - sejacc, - ivg, - sehem, - serad, - sechi, - discipline - - from source - -) - -select * from renamed diff --git a/models/staging/capacite_services_h/stg_capacite_services_h__capacite_2022_etablissement_stjr.sql b/models/staging/capacite_services_h/stg_capacite_services_h__capacite_2022_etablissement_stjr.sql deleted file mode 100644 index 6060f15..0000000 --- a/models/staging/capacite_services_h/stg_capacite_services_h__capacite_2022_etablissement_stjr.sql +++ /dev/null @@ -1,41 +0,0 @@ -with - -source as ( - - select * from {{ source('capacite_services_h', 'capacite_2022_etablissement_stjr') }} - -), - -renamed as ( - - select - fi, - an, - fi_ej, - rs, - grp, - stjr, - cat, - dep, - reg, - espic, - cominsee, - disci, - discipline, - lit, - sejhc, - jou, - pla, - sejhp, - pas, - sejacc, - ivg, - sehem, - serad, - sechi - - from source - -) - -select * from renamed diff --git a/models/staging/capacite_services_h/stg_capacite_services_h__capacite_2022_par_etablissement.sql b/models/staging/capacite_services_h/stg_capacite_services_h__capacite_2022_par_etablissement.sql deleted file mode 100644 index 189995d..0000000 --- a/models/staging/capacite_services_h/stg_capacite_services_h__capacite_2022_par_etablissement.sql +++ /dev/null @@ -1,39 +0,0 @@ -with - -source as ( - - select * from {{ source('capacite_services_h', 'capacite_2022_par_etablissement') }} - -), - -renamed as ( - - select - fi, - an, - fi_ej, - rs, - stj, - cat, - dep, - reg, - anc_reg, - espic, - cominsee, - grp, - lit, - sejhc, - jou, - pla, - sejhp, - pas, - sejacc, - sehem, - serad, - sechi - - from source - -) - -select * from renamed diff --git a/models/staging/capacite_services_h/stg_capacite_services_h__capacite_2022_par_services.sql b/models/staging/capacite_services_h/stg_capacite_services_h__capacite_2022_par_services.sql deleted file mode 100644 index 6b48d6a..0000000 --- a/models/staging/capacite_services_h/stg_capacite_services_h__capacite_2022_par_services.sql +++ /dev/null @@ -1,42 +0,0 @@ -with - -source as ( - - select * from {{ source('capacite_services_h', 'capacite_2022_par_services') }} - -), - -renamed as ( - - select - fi, - an, - fi_ej, - rs, - stj, - cat, - dep, - reg, - anc_reg, - espic, - cominsee, - grp, - disci, - discipline, - lit, - sejhc, - jou, - pla, - sejhp, - pas, - sejacc, - sehem, - serad, - sechi, - cle_unique - - from source - -) - -select * from renamed diff --git a/models/staging/morbidite_h/stg_morbidite_h__duree_sejours.sql b/models/staging/morbidite_h/stg_morbidite_h__duree_sejours.sql deleted file mode 100644 index 0b3102c..0000000 --- a/models/staging/morbidite_h/stg_morbidite_h__duree_sejours.sql +++ /dev/null @@ -1,44 +0,0 @@ -with - -source as ( - - select * from {{ source('morbidite_h', 'duree_sejours') }} - -), - -renamed as ( - - select - departement as niveau, - annee, - year, - pathologie, - code_pathologie, - nom_pathologie, - region, - code_region, - nom_region, - hospi_prog_24h, - hospi_autres_24h, - hospi_total_24h, - hospi_1j, - hospi_2j, - hospi_3j, - hospi_4j, - hospi_5j, - hospi_6j, - hospi_7j, - hospi_8j, - hospi_9j, - hospi_10j_19j, - hospi_20j_29j, - hospi_30j, - total_hospi, - avg_duree_hospi, - cle_unique - - from source - -) - -select * from renamed diff --git a/models/staging/morbidite_h/stg_morbidite_h__nombre_hospit.sql b/models/staging/morbidite_h/stg_morbidite_h__nombre_hospit.sql deleted file mode 100644 index 7304704..0000000 --- a/models/staging/morbidite_h/stg_morbidite_h__nombre_hospit.sql +++ /dev/null @@ -1,28 +0,0 @@ -with - - source as (select * from {{ source("morbidite_h", "nombre_hospit") }}), - - renamed as ( - - select - departement as niveau, - sexe, - year, - pathologie, - code_pathologie, - nom_pathologie, - region, - code_region, - nom_region, - age, - code_age, - tranche_age, - nbr_hospi, - cle_unique - - from source - - ) - -select * -from renamed diff --git a/models/staging/morbidite_h/stg_morbidite_h__taux_recours.sql b/models/staging/morbidite_h/stg_morbidite_h__taux_recours.sql deleted file mode 100644 index 4241318..0000000 --- a/models/staging/morbidite_h/stg_morbidite_h__taux_recours.sql +++ /dev/null @@ -1,38 +0,0 @@ -with - -source as ( - - select * from {{ source('morbidite_h', 'taux_recours') }} - -), - -renamed as ( - - select - niveau, - sexe, - pathologie, - code_pathologie, - nom_pathologie, - annee, - region, - tranche_age_0_1, - tranche_age_1_4, - tranche_age_5_14, - tranche_age_15_24, - tranche_age_25_34, - tranche_age_35_44, - tranche_age_45_54, - tranche_age_55_64, - tranche_age_65_74, - tranche_age_75_84, - tranche_age_85_et_plus, - tx_brut_tt_age_pour_mille, - tx_standard_tt_age_pour_mille, - indice_comparatif_tt_age_percent - - from source - -) - -select * from renamed