Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa tarde,
No banco de dados tenho as informações a seguir, em diferentes tabelas: Acesso, Dose prescrita, tempo e volume. Preciso, de acordo com essas informações, calcular dois valores chamados bolus e rate seguindo uma condicional. O problema é como vou retornar estes dois valores, se não tem atributo onde eu possa inseri-los?
Eu deveria criar uma nova tabela pra eles? Existe como retornar estes atributos sem ter de mexer em nenhuma tabela?
O código atual que tenho, é:
select
a.nr_atendimento ATENDIMENTO,
obter_nome_pf_atend(a.nr_atendimento) NOME,
obter_data_nascto_pac_atend(a.nr_atendimento) NASCIMENTO,
'DOSE: ' || decode(a.qt_dose,',5','2.500 UI','1','5.000 UI','1,5','7.500 UI','2','10.000 UI','2,5','12.500 UI','3','15.000 UI','3,5','17.500 UI',
'4','20.000 UI','4,5','22.500 UI','5','25.000 UI','5,5','27.500 UI','6','30.000 UI') DOSE,
'VOLUME: ' || a.qt_volume || ' ml' VOLUME,
obter_desc_material(a.cd_material) MEDICAMENTO,
d.qt_hora_min_sessao TEMPO,
e.nr_seq_tecnica ACESSO
-- Inserir aqui condicionais para cálculo de BOLUS e RATE
from
CPOE_material a, atend_paciente_unidade b, hd_escala_dialise c, cpoe_dialise d, hd_acesso e
where
a.cd_material = 49749 and
a.nr_atendimento = b.nr_atendimento and
d.nr_atendimento = b.nr_atendimento and
obter_cd_pes_fis_atend(b.nr_atendimento) = c.cd_pessoa_fisica and
b.dt_saida_unidade is null and
a.dt_liberacao is not null and
a.dt_suspensao is null and
d.dt_liberacao is not null and
d.dt_suspensao is null and
c.dt_fim is null and
e.cd_pessoa_fisica = obter_pessoa_atendimento(b.nr_atendimento,'C') and
e.ie_adequado = 'S' and
e.dt_perda_retirada is null and
c.nr_seq_turno = :turno and
c.nr_seq_escala = :escala
E as condicionais que quero inserir é mais ou menos assim:
SE acesso arteriovenoso então:
se dose_prescrita = 2500 então bolus = volume e rate = '-'
se dose_prescrita = 5000 então:
se tempo = 2:00h, 2:05h, 2:30h ou 2:35h então Bolus = volume e rate = '-'
se tempo = 3:00h ou 3:05 então Bolus = 6,0 e rate = 1,6
se tempo = 3:30h ou 3:35 então Bolus = 6,0 e rate = 1,3
se tempo = 4:00 ou 4:05h então bolus = 6,0 e rate = 1,1
se dose_prescrita = 7500 então
se tempo = 2:00h, 2:05h, 2:30h ou 2:35h então Bolus = volume e rate = '-'
se tempo = 3:00h ou 3:05 então Bolus = 8,0 e rate = 2,8
se tempo = 3:30h ou 3:35 então Bolus = 8,0 e rate = 2,3
se tempo = 4:00 ou 4:05h então bolus = 8,0 e rate = 2,0
se dose_prescrita = 10000 então
se tempo = 2:00h, 2:05h, 2:30h ou 2:35h então Bolus = volume e rate = '-'
se tempo = 3:00h ou 3:05 então Bolus = 10,0 e rate = 4,0
se tempo = 3:30h ou 3:35 então Bolus = 10,0 e rate = 3,3
se tempo = 4:00 ou 4:05h então bolus = 10,0 e rate = 2,9
se dose_prescrita = 12500 então
se tempo = 2:00h, 2:05h, 2:30h ou 2:35h então Bolus = volume e rate = '-'
se tempo = 3:00h ou 3:05 então Bolus = 11,0 e rate = 5,6
se tempo = 3:30h ou 3:35 então Bolus = 11,0 e rate = 4,7
se tempo = 4:00 ou 4:05h então bolus = 11,0 e rate = 4,0
se dose_prescrita = 15000 então
se tempo = 2:00h, 2:05h, 2:30h ou 2:35h então Bolus = volume e rate = '-'
se tempo = 3:00h ou 3:05 então Bolus = 13,0 e rate = 6,8
se tempo = 3:30h ou 3:35 então Bolus = 13,0 e rate = 5,7
se tempo = 4:00 ou 4:05h então bolus = 13,0 e rate = 4,9
se dose_prescrita = 30000 então
se tempo = 2:00h, 2:05h, 2:30h ou 2:35h então Bolus = volume e rate = '-'
se tempo = 3:00h ou 3:05 então Bolus = 23,0 e rate = 14,8
se tempo = 3:30h ou 3:35 então Bolus = 23,0 e rate = 12,3
se tempo = 4:00 ou 4:05h então bolus = 23,0 e rate = 10,6
se não
então null
SE acesso cateter então:
se dose_prescrita = 2500 então bolus = volume e rate = '-'
se dose_prescrita = 5000 então:
se tempo = 2:00h, 2:05h, 2:30h ou 2:35h então Bolus = volume e rate = '-'
se tempo = 3:00h ou 3:05 então Bolus = 6,0 e rate = 1,3
se tempo = 3:30h ou 3:35 então Bolus = 6,0 e rate = 1,1
se tempo = 4:00 ou 4:05h então bolus = 6,0 e rate = 1,0
se dose_prescrita = 7500 então
se tempo = 2:00h, 2:05h, 2:30h ou 2:35h então Bolus = volume e rate = '-'
se tempo = 3:00h ou 3:05 então Bolus = 8,0 e rate = 2,3
se tempo = 3:30h ou 3:35 então Bolus = 8,0 e rate = 2,0
se tempo = 4:00 ou 4:05h então bolus = 8,0 e rate = 1,8
se dose_prescrita = 10000 então
se tempo = 2:00h, 2:05h, 2:30h ou 2:35h então Bolus = volume e rate = '-'
se tempo = 3:00h ou 3:05 então Bolus = 10,0 e rate = 3,3
se tempo = 3:30h ou 3:35 então Bolus = 10,0 e rate = 2,9
se tempo = 4:00 ou 4:05h então bolus = 10,0 e rate = 2,5
se dose_prescrita = 12500 então
se tempo = 2:00h, 2:05h, 2:30h ou 2:35h então Bolus = volume e rate = '-'
se tempo = 3:00h ou 3:05 então Bolus = 11,0 e rate = 4,7
se tempo = 3:30h ou 3:35 então Bolus = 11,0 e rate = 4,0
se tempo = 4:00 ou 4:05h então bolus = 11,0 e rate = 3,5
se dose_prescrita = 15000 então
se tempo = 2:00h, 2:05h, 2:30h ou 2:35h então Bolus = volume e rate = '-'
se tempo = 3:00h ou 3:05 então Bolus = 13,0 e rate = 5,7
se tempo = 3:30h ou 3:35 então Bolus = 13,0 e rate = 4,9
se tempo = 4:00 ou 4:05h então bolus = 13,0 e rate = 4,3
se dose_prescrita = 30000 então
se tempo = 2:00h, 2:05h, 2:30h ou 2:35h então Bolus = volume e rate = '-'
se tempo = 3:00h ou 3:05 então Bolus = 23,0 e rate = 12,3
se tempo = 3:30h ou 3:35 então Bolus = 23,0 e rate = 10,6
se tempo = 4:00 ou 4:05h então bolus = 23,0 e rate = 9,3
Atenciosamente,
Igor
>
Agora, Motta disse:
Em principio eu faria uma FUNCTION ,
Estes valores da dose_prescrita são assim mesmos discretos (2500 , 5000 etc) ?
Isso, são padronizados... 2500, 5000, 7500, 10.000 e 12.5000.
Vou ter que pesquisar como funciona a criação de função, nunca fiz uma antes
Relativanente simples
Estou tentando criar minha primeira function, já fucei em muito fórum e vídeo aula de ontem pra hoje, mas por algum motivo parece que está sempre faltando alguma coisa pra compilar certinho.
No caso, agora, ele está dando erro no fim do código. ele diz que espera um 'case' depois do end. Mas eu só quero terminar o código e acredito que já dei fim em todos os cases e ifs.
Abaixo o código (um pouco extenso, mas é repetitivo):
create or replace function calcular_bolus_rate(nr_seq_tecnica number,
qt_dose number,
qt_hora_min_sessao varchar2,
qt_volume number, valor_opcao varchar2)
return varchar2 is
valor_bolus varchar2(5); -- Se valor_opcao = 'b' ou 'B'
valor_rate varchar2(5); -- Se valor opcao = 'r' ou 'R'
valor varchar2(5);
BEGIN
case when nr_seq_tecnica in (4,5,6,8) then
-- se dose prescrita = 2.500UI
if qt_dose = ',5' then
valor_bolus := to_char(qt_volume, '999');
valor_rate := '-';
end if;
-- se dose prescrita = 5.000UI
if qt_dose = '1' then
case
when qt_hora_min_sessao in ('02:00','02:05','02:30','02:35') then
valor_bolus := to_char(qt_volume, '999');
valor_rate := '-';
when qt_hora_min_sessao in ('03:00','03:05') then
valor_bolus := '6,0';
valor_rate := '1,6';
when qt_hora_min_sessao in ('03:30','03:35') then
valor_bolus := '6,0';
valor_rate := '1,3';
when qt_hora_min_sessao in ('04:00','04:05') then
valor_bolus := '6,0';
valor_rate := '1,1';
else
return null;
end case;
end if;
-- se dose prescrita = 7.500UI
if qt_dose = '1,5' then
case
when qt_hora_min_sessao in ('02:00','02:05','02:30','02:35') then
valor_bolus := to_char(qt_volume, '999');
valor_rate := '-';
when qt_hora_min_sessao in ('03:00','03:05') then
valor_bolus := '8,0';
valor_rate := '2,8';
when qt_hora_min_sessao in ('03:30','03:35') then
valor_bolus := '8,0';
valor_rate := '2,3';
when qt_hora_min_sessao in ('04:00','04:05') then
valor_bolus := '8,0';
valor_rate := '2,0';
else
return null;
end case;
end if;
-- se dose prescrita = 10.00UI
if qt_dose = '2' then
case
when qt_hora_min_sessao in ('02:00','02:05','02:30','02:35') then
valor_bolus := to_char(qt_volume, '999');
valor_rate := '-';
when qt_hora_min_sessao in ('03:00','03:05') then
valor_bolus := '10,0';
valor_rate := '4,0';
when qt_hora_min_sessao in ('03:30','03:35') then
valor_bolus := '10,0';
valor_rate := '3,3';
when qt_hora_min_sessao in ('04:00','04:05') then
valor_bolus := '10,0';
valor_rate := '2,9';
else
return null;
end case;
end if; valor_bolus := to_char(qt_volume, '999');
valor_rate := '-';
when qt_hora_min_sessao in ('03:00','03:05') then
valor_bolus := '11,0';
valor_rate := '5,6';
when qt_hora_min_sessao in ('03:30','03:35') then
valor_bolus := '11,0';
valor_rate := '4,7';
when qt_hora_min_sessao in ('04:00','04:05') then
valor_bolus := '11,0';
valor_rate := '4,0';
else
return null;
end case;
end if;
-- se dose prescrita = 15.000UI
if qt_dose = 3 then
case
when qt_hora_min_sessao in ('02:00','02:05','02:30','02:35') then
valor_bolus := to_char(qt_volume, '999');
valor_rate := '-';
when qt_hora_min_sessao in ('03:00','03:05') then
valor_bolus := '13,0';
valor_rate := '6,8';
when qt_hora_min_sessao in ('03:30','03:35') then
valor_bolus := '13,0';
valor_rate := '5,7';
when qt_hora_min_sessao in ('04:00','04:05') then
valor_bolus := '13,0';
valor_rate := '4,9';
else
return null;
end case;
end if;
-- se dose prescrita = 30.000UI
if qt_dose = '6' then
case
when qt_hora_min_sessao in ('02:00','02:05','02:30','02:35') then
valor_bolus := to_char(qt_volume, '999');
valor_rate := '-';
when qt_hora_min_sessao in ('03:00','03:05') then
valor_bolus := '23,0';
valor_rate := '14,8';
when qt_hora_min_sessao in ('03:30','03:35') then
valor_bolus := '23,0';
valor_rate := '12,3';
when qt_hora_min_sessao in ('04:00','04:05') then
valor_bolus := '23,0';
valor_rate := '10,6';
else
return null;
end case;
end if; valor := valor_bolus;
return valor;
when valor_opcao = 'r' or valor_opcao = 'R' then
valor := valor_rate;
return valor;
else
return null;
end case;
return valor;
end;Eu trocaria estes "cases" por
If xxxx then
Elsif then
Else
End if;
[https://www.techonthenet.com/oracle/loops/if_then.php](https://www.techonthenet.com/oracle/loops/if_then.php)>
1 hora atrás, Motta disse:
Eu trocaria estes "cases" por
If xxxx then
Elsif then
Else
End if;
[https://www.techonthenet.com/oracle/loops/if_then.php](https://www.techonthenet.com/oracle/loops/if_then.php)
Obrigado Motta!
Na verdade, eu descobri que o problema foi que eu não tinha fechado o primeiro case e resolvi.
Tentei colocar tudo com if, mas alguns estavam dando alguns problemas no elsif, mas vou tentar novamente depois...
Muito obrigado pelo suporte! Eu estava receoso de tentar algo novo, como functions, mas agora evolui um pouco nos meus conhecimentos de DB e vou praticar mais!
Valeu! São úteis em alguns casos e são reutilizáveis.
Em principio eu faria uma FUNCTION ,
Estes valores da dose_prescrita são assim mesmos discretos (2500 , 5000 etc) ?