Skip to content

Commit

Permalink
Merge pull request #15 from Jean-Baptiste-N/Dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Jean-Baptiste-N authored Dec 3, 2024
2 parents cd593aa + 5b83b91 commit 2425ffc
Show file tree
Hide file tree
Showing 28 changed files with 534 additions and 85 deletions.
25 changes: 0 additions & 25 deletions models/capacite/int_capacite_etablissement.sql

This file was deleted.

7 changes: 3 additions & 4 deletions models/capacite/int_capacite_etablissement_join.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
With join_capacite as (
SELECT
t2.id_etablissement,
t2.annee as annee,
DATE(CAST(t2.annee AS STRING) || "-12-31") as year,
t2.service_medical,
Expand Down Expand Up @@ -30,11 +29,11 @@ With join_capacite as (
t1.place_hospi_partielle AS total_place_hospi_partielle,
t1.sejour_hospi_partielle AS total_sejour_hospi_partielle,
FROM
{{ref("int_capacite_etablissement")}} AS t1
{{ref("stg_capacite_services_h__capacite_2022_par_etablissement1")}} AS t1
JOIN
{{ref("int_capacite_service")}} AS t2
{{ref("stg_capacite_services_h__capacite_2022_par_service1")}} AS t2
ON
t1.id_etablissement = t2.id_etablissement
t1.nom_etablissement = t2.nom_etablissement
AND t1.annee = t2.annee
)

Expand Down
56 changes: 28 additions & 28 deletions models/capacite/int_capacite_service.sql
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
SELECT
fi as id_etablissement,
an as annee,
rs as nom_etablissement,
stj as statut_juridique,
cat as categ_etablissement,
dep as departement,
SPLIT(dep, " - ")[SAFE_OFFSET(0)] AS code_departement,
SPLIT(dep, " - ")[SAFE_OFFSET(1)] AS nom_departement,
reg as region,
SPLIT(reg, " - ")[SAFE_OFFSET(0)] AS code_region,
SPLIT(reg, " - ")[SAFE_OFFSET(1)] AS nom_region,
-- stjr as statut_entite,
espic as code_espic,
DISCI as discipline_equipement,
DISCIPLINE as service_medical,
LIT as lit_hospi_complete,
SEJHC as sejour_hospi_complete,
JOU as journee_hospi_complete,
PLA as place_hospi_partielle,
SEJHP as sejour_hospi_partielle,
PAS as passage_urgence,
SEJACC as sejour_accouchement,
SEHEM as seance_hemodyalise,
SERAD as seance_radiotherapie,
SECHI as seance_chimio,
cle_unique
FROM {{ref('stg_capacite_services_h__capacite_2022_par_service')}}
SELECT
fi as id_etablissement,
an as annee,
rs as nom_etablissement,
stj as statut_juridique,
cat as categ_etablissement,
dep as departement,
SPLIT(dep, " - ")[SAFE_OFFSET(0)] AS code_departement,
SPLIT(dep, " - ")[SAFE_OFFSET(1)] AS nom_departement,
reg as region,
SPLIT(reg, " - ")[SAFE_OFFSET(0)] AS code_region,
SPLIT(reg, " - ")[SAFE_OFFSET(1)] AS nom_region,
-- stjr as statut_entite,
espic as code_espic,
DISCI as discipline_equipement,
DISCIPLINE as service_medical,
LIT as lit_hospi_complete,
SEJHC as sejour_hospi_complete,
JOU as journee_hospi_complete,
PLA as place_hospi_partielle,
SEJHP as sejour_hospi_partielle,
PAS as passage_urgence,
SEJACC as sejour_accouchement,
SEHEM as seance_hemodyalise,
SERAD as seance_radiotherapie,
SECHI as seance_chimio,
cle_unique
FROM {{ref('stg_capacite_services_h__capacite_2022_par_service')}}
WHERE an >= 2018
2 changes: 0 additions & 2 deletions models/capacite_agg/mart_capacite_dpt_reg.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
WITH dpt as (
SELECT
id_etablissement,
annee,
year,
service_medical,
Expand Down Expand Up @@ -31,7 +30,6 @@ WITH dpt as (
),
reg as (
SELECT
id_etablissement,
annee,
year,
service_medical,
Expand Down
30 changes: 27 additions & 3 deletions models/capacite_agg/mart_capacite_dpt_reg_evol.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,32 @@ evolution_data AS (
AND bd1.service_medical = bd2.service_medical
AND bd1.service_classification = bd2.service_classification
AND bd1.annee = bd2.annee + 1
)
), corr_region as (
SELECT *,
CONCAT(region , "_" , annee , "_" , service_classification) as cle_unique
CASE
WHEN region = '04 - Réunion' THEN '04 - La Réunion'
WHEN region = '06 - Alpes Maritimes' THEN '06 - Alpes-Maritimes'
WHEN region = '06 - Mayotte' THEN '06 - Mayotte'
WHEN region = '11 - Ile-de-France' THEN '11 - Ile de France'
WHEN region = '17 - Charente Maritime' THEN '17 - Charente-Maritime'
WHEN region = '19 - Correze' THEN '19 - Corrèze'
WHEN region = "21 - Côte d'Or" THEN "21 - Côte-d'Or"
WHEN region = "22 - Côtes d'Armor" THEN "22 - Côtes-d'Armor"
WHEN region = '28 - Eure et Loir' THEN '28 - Eure-et-Loir'
WHEN region = '2A - Corse du Sud' THEN '2A - Corse-du-Sud'
WHEN region = '44 - Loire Atlantique' THEN '44 - Loire-Atlantique'
WHEN region = '93 - Seine-St-Denis' THEN '93 - Seine-Saint-Denis'
WHEN region = "95 - Val-D'Oise" THEN "95 - Val-d'Oise"
WHEN region = '9A - Guadeloupe' THEN '971 - Guadeloupe'
WHEN region = '9B - Martinique' THEN '972 - Martinique'
WHEN region = '9C - Guyane' THEN '973 - Guyane'
WHEN region = '9D - Réunion' THEN '974 - Réunion'
WHEN region = '9F - Mayotte' THEN '976 - Mayotte'
ELSE region
END AS region1
FROM evolution_data
ORDER BY region, annee
)
SELECT *,
CONCAT(region1 , "_" , annee , "_" , service_classification) as cle_unique,
FROM corr_region
ORDER BY region1, annee
4 changes: 2 additions & 2 deletions models/duree_sejours_découpé/int_duree_sejours_dpt_ens.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ SELECT niveau,
hospi_10J_19J,
hospi_20J_29J,
hospi_30J,
(total_hospi - hospi_total_24h) AS hospi_total_jj,
(Cast(total_hospi as INT) - Cast(hospi_total_24h as INT)) AS hospi_total_jj,
total_hospi,
AVG_duree_hospi

FROM {{ref("stg_morbidite_h__duree_sejours")}}
FROM {{ref("stg_morbidite_h__duree_sejours2")}}
WHERE NOT (region LIKE '3 - France%' OR region LIKE '1 - France%')
AND niveau LIKE "Départements"
AND nom_pathologie != 'TOTAL TOUTES CAUSES'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SELECT niveau,
total_hospi,
AVG_duree_hospi

FROM {{ref("stg_morbidite_h__duree_sejours")}}
FROM {{ref("stg_morbidite_h__duree_sejours2")}}
WHERE NOT (region LIKE '3 - France%' OR region LIKE '1 - France%')
AND niveau LIKE "Régions"
AND nom_pathologie != 'TOTAL TOUTES CAUSES'
Expand Down
4 changes: 2 additions & 2 deletions models/duree_sejours_total/int_duree_sejours_total.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT niveau,
CONCAT(region , "_" , code_pathologie ,"_" , annee) as cle_unique,
CONCAT(region,"_",code_pathologie,"_",annee) as cle_unique,
annee,
year,
pathologie,
Expand Down Expand Up @@ -27,7 +27,7 @@ SELECT niveau,
total_hospi,
AVG_duree_hospi

FROM {{ref("stg_morbidite_h__duree_sejours")}}
FROM {{ref("stg_morbidite_h__duree_sejours2")}}
WHERE NOT (region LIKE '3 - France%' OR region LIKE '1 - France%')
AND niveau NOT LIKE "France"
AND nom_pathologie != 'TOTAL TOUTES CAUSES'
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@ SELECT
FROM agg_class t1
LEFT JOIN {{ref("mart_capacite_dpt_reg_evol")}} t2
ON t1.cle_unique = t2.cle_unique
ORDER BY lit_hospi_complete



Loading

0 comments on commit 2425ffc

Please sign in to comment.