-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Jean-Baptiste-N/Dev
big work
- Loading branch information
Showing
14 changed files
with
533 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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, | ||
espic as code_espic, | ||
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, | ||
FROM {{ref("stg_capacite_services_h__capacite_2022_par_etablissement")}} | ||
WHERE an >= 2018 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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, | ||
t1.nom_etablissement AS nom_etablissement, | ||
t1.statut_juridique AS statut_juridique, | ||
t1.categ_etablissement AS categ_etablissement, | ||
t1.departement AS departement, | ||
t1.code_departement AS code_departement, | ||
t1.nom_departement AS nom_departement, | ||
t1.region AS region, | ||
t1.code_region AS code_region, | ||
t1.nom_region AS nom_region, | ||
t1.code_espic AS code_espic, | ||
t2.lit_hospi_complete AS lit_hospi_complete_detail, | ||
t2.sejour_hospi_complete AS sejour_hospi_complete_detail, | ||
t2.journee_hospi_complete AS journee_hospi_complete_detail, | ||
t2.place_hospi_partielle AS place_hospi_partielle_detail, | ||
t2.sejour_hospi_partielle AS sejour_hospi_partielle_detail, | ||
t2.passage_urgence AS passage_urgence_detail, | ||
t2.sejour_accouchement AS sejour_accouchement_detail, | ||
t2.seance_hemodyalise AS seance_hemodyalise_detail, | ||
t2.seance_radiotherapie AS seance_radiotherapie_detail, | ||
t2.seance_chimio AS seance_chimio_detail, | ||
t1.lit_hospi_complete AS total_lit_hospi_complete, | ||
t1.sejour_hospi_complete AS total_sejour_hospi_complete, | ||
t1.journee_hospi_complete AS total_journee_hospi_complete, | ||
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 | ||
JOIN | ||
{{ref("int_capacite_service")}} AS t2 | ||
ON | ||
t1.id_etablissement = t2.id_etablissement | ||
AND t1.annee = t2.annee | ||
) | ||
|
||
SELECT *, | ||
CASE | ||
WHEN service_medical = 'Soins de suite et réadaptation' THEN 'SSR' | ||
WHEN service_medical = 'Gynéco-Obstétrique' THEN 'O' | ||
WHEN service_medical = 'Médecine' THEN 'M' | ||
WHEN service_medical = 'Chirurgie' THEN 'C' | ||
WHEN service_medical = 'Soins de longue durée' THEN 'ESND' | ||
WHEN service_medical = 'Psychiatrie' THEN 'PSY' | ||
WHEN service_medical = 'Hospitalisation à domicile' THEN NULL | ||
END AS service_classification , | ||
FROM `join_capacite` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
-- 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, | ||
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_services')}} | ||
WHERE an >= 2018 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
WITH dpt as ( | ||
SELECT | ||
id_etablissement, | ||
annee, | ||
year, | ||
service_medical, | ||
service_classification, | ||
nom_etablissement, | ||
statut_juridique, | ||
categ_etablissement, | ||
departement as region, | ||
code_departement as code_region, | ||
nom_departement as nom_region, | ||
code_espic, | ||
lit_hospi_complete_detail, | ||
sejour_hospi_complete_detail, | ||
journee_hospi_complete_detail, | ||
place_hospi_partielle_detail, | ||
sejour_hospi_partielle_detail, | ||
passage_urgence_detail, | ||
sejour_accouchement_detail, | ||
seance_hemodyalise_detail, | ||
seance_radiotherapie_detail, | ||
seance_chimio_detail, | ||
total_lit_hospi_complete, | ||
total_sejour_hospi_complete, | ||
total_journee_hospi_complete, | ||
total_place_hospi_partielle, | ||
total_sejour_hospi_partielle, | ||
FROM {{ref("int_capacite_etablissement_join")}} | ||
), | ||
reg as ( | ||
SELECT | ||
id_etablissement, | ||
annee, | ||
year, | ||
service_medical, | ||
service_classification, | ||
nom_etablissement, | ||
statut_juridique, | ||
categ_etablissement, | ||
region, | ||
code_region, | ||
nom_region, | ||
code_espic, | ||
lit_hospi_complete_detail, | ||
sejour_hospi_complete_detail, | ||
journee_hospi_complete_detail, | ||
place_hospi_partielle_detail, | ||
sejour_hospi_partielle_detail, | ||
passage_urgence_detail, | ||
sejour_accouchement_detail, | ||
seance_hemodyalise_detail, | ||
seance_radiotherapie_detail, | ||
seance_chimio_detail, | ||
total_lit_hospi_complete, | ||
total_sejour_hospi_complete, | ||
total_journee_hospi_complete, | ||
total_place_hospi_partielle, | ||
total_sejour_hospi_partielle, | ||
FROM {{ref("int_capacite_etablissement_join")}} | ||
), | ||
union1 as ( | ||
SELECT * | ||
FROM dpt | ||
UNION ALL | ||
SELECT * | ||
FROM reg | ||
) | ||
|
||
SELECT | ||
annee, | ||
year, | ||
region, | ||
code_region, | ||
nom_region, | ||
service_medical, | ||
service_classification, | ||
SUM(lit_hospi_complete_detail) as lit_hospi_complete, | ||
SUM(sejour_hospi_complete_detail) as sejour_hospi_complete, | ||
SUM(journee_hospi_complete_detail) as journee_hospi_complete, | ||
SUM(place_hospi_partielle_detail) as place_hospi_partielle, | ||
SUM(sejour_hospi_partielle_detail) as sejour_hospi_partielle, | ||
SUM(passage_urgence_detail) as passage_urgence, | ||
SUM(sejour_accouchement_detail) as sejour_accouchement, | ||
SUM(seance_hemodyalise_detail) as seance_hemodyalise, | ||
SUM(seance_radiotherapie_detail) as seance_radiotherapie, | ||
SUM(seance_chimio_detail) as seance_chimio, | ||
FROM union1 | ||
GROUP BY | ||
annee, | ||
year, | ||
region, | ||
code_region, | ||
nom_region, | ||
service_medical, | ||
service_classification | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
WITH base_data AS ( | ||
SELECT | ||
annee, | ||
year, | ||
region, | ||
code_region, | ||
nom_region, | ||
service_medical, | ||
service_classification, | ||
lit_hospi_complete, | ||
sejour_hospi_complete, | ||
journee_hospi_complete, | ||
place_hospi_partielle, | ||
sejour_hospi_partielle, | ||
passage_urgence | ||
,AVG(lit_hospi_complete) OVER (PARTITION BY annee, region, code_region, nom_region, service_medical, service_classification) AS lit_hospi_complete1 | ||
,AVG(sejour_hospi_complete) OVER (PARTITION BY annee, region, code_region, nom_region, service_medical, service_classification) AS sejour_hospi_complete1 | ||
,AVG(journee_hospi_complete) OVER (PARTITION BY annee, region, code_region, nom_region, service_medical, service_classification) AS journee_hospi_complete1 | ||
,AVG(place_hospi_partielle) OVER (PARTITION BY annee, region, code_region, nom_region, service_medical, service_classification) AS place_hospi_partielle1 | ||
,AVG(sejour_hospi_partielle) OVER (PARTITION BY annee, region, code_region, nom_region, service_medical, service_classification) AS sejour_hospi_partielle1 | ||
,AVG(passage_urgence) OVER (PARTITION BY annee, region, code_region, nom_region, service_medical, service_classification) AS passage_urgence1 | ||
FROM {{ref("mart_capacite_dpt_reg")}} | ||
), | ||
evolution_data AS ( | ||
SELECT | ||
bd1.*, | ||
round(bd1.lit_hospi_complete1 - COALESCE(bd2.lit_hospi_complete1, 0),2) AS evolution_lit_hospi_complete1, | ||
CASE | ||
WHEN COALESCE(bd2.lit_hospi_complete1, 0) = 0 THEN NULL | ||
ELSE Round(safe_divide((bd1.lit_hospi_complete1 - bd2.lit_hospi_complete1) , bd2.lit_hospi_complete1), 2) | ||
END AS evolution_percent_lit_hospi_complete1, | ||
round(bd1.sejour_hospi_complete1 - COALESCE(bd2.sejour_hospi_complete1, 0),2) AS evolution_sejour_hospi_complete1, | ||
CASE | ||
WHEN COALESCE(bd2.sejour_hospi_complete1, 0) = 0 THEN NULL | ||
ELSE Round(safe_divide((bd1.sejour_hospi_complete1 - bd2.sejour_hospi_complete1) , bd2.sejour_hospi_complete1), 2) | ||
END AS evolution_percent_sejour_hospi_complete1, | ||
round(bd1.journee_hospi_complete1 - COALESCE(bd2.journee_hospi_complete1, 0),2) AS evolution_journee_hospi_complete1, | ||
CASE | ||
WHEN COALESCE(bd2.journee_hospi_complete1, 0) = 0 THEN NULL | ||
ELSE Round(safe_divide((bd1.journee_hospi_complete1 - bd2.journee_hospi_complete1) , bd2.journee_hospi_complete1), 2) | ||
END AS evolution_percent_journee_hospi_complete1, | ||
round(bd1.place_hospi_partielle1 - COALESCE(bd2.place_hospi_partielle1, 0),2) AS evolution_place_hospi_partielle1, | ||
CASE | ||
WHEN COALESCE(bd2.place_hospi_partielle1, 0) = 0 THEN NULL | ||
ELSE Round(safe_divide((bd1.place_hospi_partielle1 - bd2.place_hospi_partielle1) , bd2.place_hospi_partielle1), 2) | ||
END AS evolution_percent_place_hospi_partielle1, | ||
round(bd1.sejour_hospi_partielle1 - COALESCE(bd2.sejour_hospi_partielle1, 0),2) AS evolution_sejour_hospi_partielle1, | ||
CASE | ||
WHEN COALESCE(bd2.sejour_hospi_partielle1, 0) = 0 THEN NULL | ||
ELSE Round(safe_divide((bd1.sejour_hospi_partielle1 - bd2.sejour_hospi_partielle1) , bd2.sejour_hospi_partielle1), 2) | ||
END AS evolution_percent_sejour_hospi_partielle1, | ||
round(bd1.passage_urgence1 - COALESCE(bd2.passage_urgence1, 0),2) AS evolution_passage_urgence1, | ||
CASE | ||
WHEN COALESCE(bd2.passage_urgence1, 0) = 0 THEN NULL | ||
ELSE Round(safe_divide((bd1.passage_urgence1 - bd2.passage_urgence1) , bd2.passage_urgence1), 2) | ||
END AS evolution_percent_passage_urgence1 | ||
FROM base_data bd1 | ||
LEFT JOIN base_data bd2 | ||
ON bd1.region = bd2.region | ||
AND bd1.code_region = bd2.code_region | ||
AND bd1.nom_region = bd2.nom_region | ||
AND bd1.service_medical = bd2.service_medical | ||
AND bd1.service_classification = bd2.service_classification | ||
AND bd1.annee = bd2.annee + 1 | ||
) | ||
SELECT *, | ||
CONCAT(region , "_" , annee , "_" , service_classification) as cle_unique | ||
FROM evolution_data | ||
ORDER BY region, annee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 25 additions & 21 deletions
46
models/join_total_morbidite/class_join_total_morbidite_population.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
WITH population as ( | ||
WITH | ||
join_dpt AS ( | ||
SELECT | ||
CAST(code_departement as INT64) as code_region | ||
,nom_departement as region | ||
,CONCAT(code_departement ," - ", nom_departement) as cle_region | ||
,annee | ||
,population | ||
FROM {{ref("stg_pop_departement__population_departement")}} | ||
UNION ALL | ||
t1.*, | ||
t2.population AS population | ||
FROM {{ ref("class_join_total_morbidite") }} 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 | ||
code_region | ||
,region | ||
,CONCAT(code_region ," - ", region) as cle_region | ||
,annee | ||
,population | ||
FROM {{ref("stg_pop_departement__population_region")}} | ||
) | ||
SELECT | ||
t1.* | ||
,t2.population | ||
FROM {{ref("class_join_total_morbidite")}} t1 | ||
LEFT JOIN population as t2 | ||
ON t1.annee = t2.annee AND t1.region = t2.cle_region | ||
t1.*, | ||
t2.population AS population | ||
FROM {{ ref("class_join_total_morbidite") }} 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 |
Oops, something went wrong.