-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Remume itens do Vitacare and Vitai
- Loading branch information
1 parent
a6295f1
commit 38abb64
Showing
8 changed files
with
234 additions
and
43 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
59 changes: 53 additions & 6 deletions
59
models/intermediate/core/int_estoque__posicao_hoje_vitacare_com_zerados_remume.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,13 +1,60 @@ | ||
-- posicao do dia de hoje adicionado os materiais remume que estão zerados | ||
|
||
with | ||
-- source | ||
posicao_atual as (select * from {{ ref('raw_prontuario_vitacare__estoque_posicao') }} where | ||
data_particao = current_date()) | ||
-- source | ||
posicao_atual as ( | ||
select * | ||
from {{ ref("raw_prontuario_vitacare__estoque_posicao") }} | ||
where data_particao = current_date() | ||
), | ||
|
||
materiais as (select * from {{ ref("dim_material") }}), | ||
|
||
-- relacão de unidades que posição de estoque na data atual | ||
unidades_vitacare_com_posicao_atual as ( | ||
select distinct id_cnes from posicao_atual | ||
), | ||
|
||
-- remume | ||
-- relação de itens remume por estabelecimento | ||
remume as ( | ||
select remume.* | ||
from | ||
{{ ref("int_estoque__material_relacao_remume_por_estabelecimento") }} | ||
as remume | ||
left join unidades_vitacare_com_posicao_atual as est on remume.id_cnes = est.id_cnes | ||
where est.id_cnes is not null | ||
), | ||
|
||
-- Filtra as posições zeradas | ||
posicao_zeradas as ( | ||
select remume.id_material, remume.id_cnes, 0 as material_quantidade, | ||
from remume | ||
left join posicao_atual on remume.id_material = posicao_atual.id_material | ||
where posicao_atual.id_material is null | ||
), | ||
|
||
-- Transforma as posições zeradas na mesma estrutura da posição atual | ||
posicao_zeradas_estruturada as ( | ||
select | ||
"" as id_estoque_posicao, | ||
"" as area_programatica, | ||
pz.id_cnes, | ||
"" as id_lote, | ||
pz.id_material, | ||
"" as id_atc, | ||
"" as estabelecimento_nome, | ||
cast(null as date) as lote_data_cadastro, | ||
cast(null as date) as lote_data_vencimento, | ||
mat.nome as material_descricao, | ||
pz.material_quantidade, | ||
current_date() as data_particao, | ||
current_datetime() as data_ingestao, | ||
from posicao_zeradas as pz | ||
left join materiais as mat on pz.id_material = mat.id_material | ||
) | ||
|
||
select * from posicao_atual | ||
-- Une os itens zerados com a posição atual | ||
select * | ||
from posicao_atual | ||
union all | ||
select * | ||
from posicao_zeradas_estruturada |
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,62 @@ | ||
-- posicao do dia de hoje adicionado os materiais remume que estão zerados | ||
|
||
with | ||
-- source | ||
posicao_atual as ( | ||
select * | ||
from {{ ref("raw_prontuario_vitai__estoque_posicao") }} | ||
where data_particao = current_date() | ||
), | ||
|
||
materiais as (select * from {{ ref("dim_material") }}), | ||
|
||
-- relacão de unidades que posição de estoque na data atual | ||
unidades_vitai_com_posicao_atual as ( | ||
select distinct id_cnes from posicao_atual | ||
), | ||
|
||
-- relação de itens remume por estabelecimento | ||
remume as ( | ||
select remume.* | ||
from | ||
{{ ref("int_estoque__material_relacao_remume_por_estabelecimento") }} | ||
as remume | ||
left join unidades_vitai_com_posicao_atual as est on remume.id_cnes = est.id_cnes | ||
where est.id_cnes is not null | ||
), | ||
|
||
-- Filtra as posições zeradas | ||
posicao_zeradas as ( | ||
select remume.id_material, remume.id_cnes, 0 as material_quantidade, | ||
from remume | ||
left join posicao_atual on remume.id_material = posicao_atual.id_material | ||
where posicao_atual.id_material is null | ||
), | ||
|
||
-- Transforma as posições zeradas na mesma estrutura da posição atual | ||
posicao_zeradas_estruturada as ( | ||
select | ||
pz.id_cnes, | ||
"" as id_lote, | ||
pz.id_material, | ||
"" as estoque_secao, | ||
mat.nome as material_descricao, | ||
mat.unidade as material_unidade, | ||
cast(null as date) as lote_data_vencimento, | ||
pz.material_quantidade, | ||
0 as material_valor_unitario, | ||
0 as material_valor_total, | ||
current_date() as data_particao, | ||
current_datetime() as data_snapshot, | ||
current_datetime() as data_carga, | ||
from posicao_zeradas as pz | ||
left join materiais as mat on pz.id_material = mat.id_material | ||
) | ||
|
||
-- Une os itens zerados com a posição atual | ||
select * | ||
from posicao_atual | ||
union all | ||
select * | ||
from posicao_zeradas_estruturada | ||
where lote_data_vencimento is not null |
2 changes: 1 addition & 1 deletion
2
models/intermediate/estoque/int_estoque__dispensacao_media_mensal.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,5 +1,5 @@ | ||
select id_cnes, id_material, avg(quantidade_dispensada) as quantidade, | ||
from {{ ref("int_estoque__dispensacao_serie_historica_com_outliers_identificados") }} | ||
where outlier = "nao" | ||
where outlier = "nao" | ||
group by id_cnes, id_material | ||
order by id_cnes, id_material |
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
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
Oops, something went wrong.