From 69fad8f7fb6a74a4310f7ca3a1eabba07fcf2229 Mon Sep 17 00:00:00 2001 From: tricktx Date: Thu, 16 May 2024 11:41:26 -0300 Subject: [PATCH 1/8] table approve --- models/br_ms_sinan/br_ms_sinan__dicionario.sql | 2 +- models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/br_ms_sinan/br_ms_sinan__dicionario.sql b/models/br_ms_sinan/br_ms_sinan__dicionario.sql index 17e5c78e..ec11d1b7 100644 --- a/models/br_ms_sinan/br_ms_sinan__dicionario.sql +++ b/models/br_ms_sinan/br_ms_sinan__dicionario.sql @@ -10,4 +10,4 @@ select safe_cast(chave as string) chave, safe_cast(replace(cobertura_temporal, '-1', '(1)') as string) cobertura_temporal, safe_cast(valor as string) valor -from `basedosdados-staging.br_ms_sinan_staging.dicionario` as t +from `basedosdados-staging.br_ms_sinan_staging.dicionario` as t \ No newline at end of file diff --git a/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql b/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql index 02c94347..dab6d4bb 100644 --- a/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql +++ b/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql @@ -1009,4 +1009,4 @@ select {% endif %} {% if not loop.last %}, {% endif %} {% endfor %} -from table_final +from table_final \ No newline at end of file From 53294304bcd9be1e1ecfdf1cf08d85f00873bcc4 Mon Sep 17 00:00:00 2001 From: tricktx Date: Thu, 16 May 2024 11:45:36 -0300 Subject: [PATCH 2/8] table-approve sinan microdados_dengue --- models/br_ms_sinan/br_ms_sinan__dicionario.sql | 2 +- models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/br_ms_sinan/br_ms_sinan__dicionario.sql b/models/br_ms_sinan/br_ms_sinan__dicionario.sql index ec11d1b7..17e5c78e 100644 --- a/models/br_ms_sinan/br_ms_sinan__dicionario.sql +++ b/models/br_ms_sinan/br_ms_sinan__dicionario.sql @@ -10,4 +10,4 @@ select safe_cast(chave as string) chave, safe_cast(replace(cobertura_temporal, '-1', '(1)') as string) cobertura_temporal, safe_cast(valor as string) valor -from `basedosdados-staging.br_ms_sinan_staging.dicionario` as t \ No newline at end of file +from `basedosdados-staging.br_ms_sinan_staging.dicionario` as t diff --git a/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql b/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql index dab6d4bb..02c94347 100644 --- a/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql +++ b/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql @@ -1009,4 +1009,4 @@ select {% endif %} {% if not loop.last %}, {% endif %} {% endfor %} -from table_final \ No newline at end of file +from table_final From f03700c90561cee2a6c28b61e8174fb0c46f5cb1 Mon Sep 17 00:00:00 2001 From: tricktx Date: Thu, 16 May 2024 11:55:16 -0300 Subject: [PATCH 3/8] table-approve sinan microdados_dengue --- models/br_ms_sinan/br_ms_sinan__dicionario.sql | 1 + models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/models/br_ms_sinan/br_ms_sinan__dicionario.sql b/models/br_ms_sinan/br_ms_sinan__dicionario.sql index 17e5c78e..1aba45ab 100644 --- a/models/br_ms_sinan/br_ms_sinan__dicionario.sql +++ b/models/br_ms_sinan/br_ms_sinan__dicionario.sql @@ -11,3 +11,4 @@ select safe_cast(replace(cobertura_temporal, '-1', '(1)') as string) cobertura_temporal, safe_cast(valor as string) valor from `basedosdados-staging.br_ms_sinan_staging.dicionario` as t + diff --git a/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql b/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql index 02c94347..54a78705 100644 --- a/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql +++ b/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql @@ -1010,3 +1010,4 @@ select {% if not loop.last %}, {% endif %} {% endfor %} from table_final + From 2b0f8ca30233799eb765c682d9acf7be0042467c Mon Sep 17 00:00:00 2001 From: tricktx Date: Thu, 16 May 2024 16:34:09 -0300 Subject: [PATCH 4/8] table approve in sinan --- .../br_ms_sinan/br_ms_sinan__dicionario.sql | 4 +- .../br_ms_sinan__microdados_dengue.sql | 102 +++++++++++++++++- 2 files changed, 99 insertions(+), 7 deletions(-) diff --git a/models/br_ms_sinan/br_ms_sinan__dicionario.sql b/models/br_ms_sinan/br_ms_sinan__dicionario.sql index 1aba45ab..b6bafc79 100644 --- a/models/br_ms_sinan/br_ms_sinan__dicionario.sql +++ b/models/br_ms_sinan/br_ms_sinan__dicionario.sql @@ -4,11 +4,11 @@ schema="br_ms_sinan", ) }} + select safe_cast(id_tabela as string) id_tabela, safe_cast(coluna as string) nome_coluna, safe_cast(chave as string) chave, safe_cast(replace(cobertura_temporal, '-1', '(1)') as string) cobertura_temporal, safe_cast(valor as string) valor -from `basedosdados-staging.br_ms_sinan_staging.dicionario` as t - +from `basedosdados-staging.br_ms_sinan_staging.dicionario` as t \ No newline at end of file diff --git a/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql b/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql index 54a78705..11a64c60 100644 --- a/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql +++ b/models/br_ms_sinan/br_ms_sinan__microdados_dengue.sql @@ -9,7 +9,7 @@ "range": {"start": 2000, "end": 2025, "interval": 1}, }, cluster_by=["sigla_uf_notificacao", "sigla_uf_residencia"], - labels={"project_id": "basedosdados"}, + labels={"tema": "saude"}, ) }} {%- set columns = adapter.get_columns_in_relation(this) -%} @@ -310,6 +310,19 @@ with safe_cast(outros as string) apresenta_sintoma_outro, safe_cast(sin_out as string) apresenta_qual_sintoma, safe_cast(laco_n as string) prova_laco, + case + when dt_choque = '' + then null + else + safe_cast( + format_date( + '%Y-%m-%d', + safe.parse_date( + '%Y%m%d', regexp_replace(dt_choque, r'[^0-9]', '') + ) + ) as date + ) + end data_choque, safe_cast(hospitaliz as string) internacao, case when dt_interna = '' @@ -324,7 +337,6 @@ with ) as date ) end data_internacao, - case when uf = '11' then 'RO' @@ -427,6 +439,19 @@ with safe_cast(grav_mioc as string) grave_miocardite, safe_cast(grav_consc as string) grave_consciencia, safe_cast(grav_orgao as string) grave_orgaos, + case + when dt_grav = '' + then null + else + safe_cast( + format_date( + '%Y-%m-%d', + safe.parse_date( + '%Y%m%d', regexp_replace(dt_grav, r'[^0-9]', '') + ) + ) as date + ) + end data_sinais_gravidade, case when dt_col_hem = '' then null @@ -518,17 +543,54 @@ with ) as date ) end data_resultado_sorologia1_chikungunya, - + case + when dt_soror2 = '' + then null + else + safe_cast( + format_date( + '%Y-%m-%d', + safe.parse_date( + '%Y%m%d', regexp_replace(dt_soror2, r'[^0-9]', '') + ) + ) as date + ) + end data_resultado_sorologia2_chikungunya, safe_cast(res_chiks1 as string) resultado_sorologia1_chikungunya, safe_cast(s1_igm as string) sorologia1_igm, safe_cast(s1_igg as string) sorologia1_igg, safe_cast(s1_tit1 as string) sorologia1_tit1, + case + when dt_chik_s2 = '' + then null + else + safe_cast( + format_date( + '%Y-%m-%d', + safe.parse_date( + '%Y%m%d', regexp_replace(dt_chik_s2, r'[^0-9]', '') + ) + ) as date + ) + end data_sorologia2_chikungunya, safe_cast(res_chiks2 as string) resultado_sorologia2_chikungunya, safe_cast(s2_igm as string) sorologia2_igm, safe_cast(s2_igg as string) sorologia2_igg, safe_cast(s2_tit1 as string) sorologia2_tit1, safe_cast(resul_prnt as string) resultado_prnt, - + case + when dt_prnt = '' + then null + else + safe_cast( + format_date( + '%Y-%m-%d', + safe.parse_date( + '%Y%m%d', regexp_replace(dt_prnt, r'[^0-9]', '') + ) + ) as date + ) + end data_prnt, case when dt_ns1 = '' then null @@ -879,6 +941,11 @@ with apresenta_sintoma_outro, apresenta_qual_sintoma, prova_laco, + case + when extract(year from data_choque) > extract(year from current_date) + then null + else data_choque + end data_choque, internacao, data_internacao, sigla_uf_internacao, @@ -913,6 +980,13 @@ with grave_consciencia, grave_orgaos, data_hematocrito, + case + when + extract(year from data_sinais_gravidade) + > extract(year from current_date) + then null + else data_sinais_gravidade + end data_sinais_gravidade, hematocrito_maior, case when extract(year from data_plaquetas) > extract(year from current_date) @@ -941,10 +1015,29 @@ with sorologia1_igg, sorologia1_tit1, resultado_sorologia2_chikungunya, + case + when + extract(year from data_sorologia2_chikungunya) + > extract(year from current_date) + then null + else data_sorologia2_chikungunya + end data_sorologia2_chikungunya, + case + when + extract(year from data_resultado_sorologia2_chikungunya) + > extract(year from current_date) + then null + else data_resultado_sorologia2_chikungunya + end data_resultado_sorologia2_chikungunya, sorologia2_igm, sorologia2_igg, sorologia2_tit1, resultado_prnt, + case + when extract(year from data_prnt) > extract(year from current_date) + then null + else data_prnt + end data_prnt, data_ns1, resultado_ns1, data_viral, @@ -1010,4 +1103,3 @@ select {% if not loop.last %}, {% endif %} {% endfor %} from table_final - From e09e8bbf872c5ebe70af87c0d50998df06178f87 Mon Sep 17 00:00:00 2001 From: tricktx Date: Thu, 16 May 2024 16:49:04 -0300 Subject: [PATCH 5/8] lint dicionario --- models/br_ms_sinan/br_ms_sinan__dicionario.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/br_ms_sinan/br_ms_sinan__dicionario.sql b/models/br_ms_sinan/br_ms_sinan__dicionario.sql index b6bafc79..90d7a74e 100644 --- a/models/br_ms_sinan/br_ms_sinan__dicionario.sql +++ b/models/br_ms_sinan/br_ms_sinan__dicionario.sql @@ -11,4 +11,5 @@ select safe_cast(chave as string) chave, safe_cast(replace(cobertura_temporal, '-1', '(1)') as string) cobertura_temporal, safe_cast(valor as string) valor -from `basedosdados-staging.br_ms_sinan_staging.dicionario` as t \ No newline at end of file + +from `basedosdados-dev.br_ms_sinan_staging.dicionario` as t \ No newline at end of file From f8b583d3d4b057cc25511d15f852b27a72a02192 Mon Sep 17 00:00:00 2001 From: tricktx Date: Thu, 16 May 2024 16:49:45 -0300 Subject: [PATCH 6/8] lint dicionario --- models/br_ms_sinan/br_ms_sinan__dicionario.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/br_ms_sinan/br_ms_sinan__dicionario.sql b/models/br_ms_sinan/br_ms_sinan__dicionario.sql index 90d7a74e..f4aff6e8 100644 --- a/models/br_ms_sinan/br_ms_sinan__dicionario.sql +++ b/models/br_ms_sinan/br_ms_sinan__dicionario.sql @@ -12,4 +12,4 @@ select safe_cast(replace(cobertura_temporal, '-1', '(1)') as string) cobertura_temporal, safe_cast(valor as string) valor -from `basedosdados-dev.br_ms_sinan_staging.dicionario` as t \ No newline at end of file +from `basedosdados-staging.br_ms_sinan_staging.dicionario` as t \ No newline at end of file From a215725fc9818a8eef6939aef5fcfa0afe5ffce0 Mon Sep 17 00:00:00 2001 From: tricktx Date: Thu, 16 May 2024 16:56:30 -0300 Subject: [PATCH 7/8] lint dicionario --- models/br_ms_sinan/br_ms_sinan__dicionario.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/br_ms_sinan/br_ms_sinan__dicionario.sql b/models/br_ms_sinan/br_ms_sinan__dicionario.sql index f4aff6e8..0a9e2918 100644 --- a/models/br_ms_sinan/br_ms_sinan__dicionario.sql +++ b/models/br_ms_sinan/br_ms_sinan__dicionario.sql @@ -12,4 +12,4 @@ select safe_cast(replace(cobertura_temporal, '-1', '(1)') as string) cobertura_temporal, safe_cast(valor as string) valor -from `basedosdados-staging.br_ms_sinan_staging.dicionario` as t \ No newline at end of file +from `basedosdados-dev.br_ms_sinan_staging.dicionario` as t From 5c31110d1d93e5e549ea56e1e579da3721618b9c Mon Sep 17 00:00:00 2001 From: tricktx Date: Thu, 16 May 2024 16:56:41 -0300 Subject: [PATCH 8/8] lint dicionario --- models/br_ms_sinan/br_ms_sinan__dicionario.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/br_ms_sinan/br_ms_sinan__dicionario.sql b/models/br_ms_sinan/br_ms_sinan__dicionario.sql index 0a9e2918..235cd38f 100644 --- a/models/br_ms_sinan/br_ms_sinan__dicionario.sql +++ b/models/br_ms_sinan/br_ms_sinan__dicionario.sql @@ -12,4 +12,4 @@ select safe_cast(replace(cobertura_temporal, '-1', '(1)') as string) cobertura_temporal, safe_cast(valor as string) valor -from `basedosdados-dev.br_ms_sinan_staging.dicionario` as t +from `basedosdados-staging.br_ms_sinan_staging.dicionario` as t