-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoharm-test.sql
71 lines (58 loc) · 1.65 KB
/
noharm-test.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
INSERT INTO demo_test.hospital
SELECT *
FROM demo.hospital;
INSERT INTO demo_test.setor
SELECT *
FROM demo.setor;
INSERT INTO demo_test.segmento
SELECT *
FROM demo.segmento;
INSERT INTO demo_test.segmentosetor
SELECT *
FROM demo.segmentosetor;
INSERT INTO demo_test.frequencia
SELECT *
FROM demo.frequencia;
INSERT INTO demo_test.unidademedida
SELECT *
FROM demo.unidademedida;
INSERT INTO demo_test.unidadeconverte
SELECT *
FROM demo.unidadeconverte;
INSERT INTO demo_test.medicamento
SELECT *
FROM demo.medicamento;
INSERT INTO demo_test.prescricao
SELECT fkhospital, fksetor, fkprescricao, fkpessoa, nratendimento, idsegmento, dtprescricao + INTERVAL '1 month'
FROM demo.prescricao
WHERE dtprescricao > current_date - 2 and idsegmento = 1;
INSERT INTO demo_test.pessoa
SELECT fkhospital, fkpessoa, nratendimento, dtnascimento, dtinternacao + INTERVAL '1 month', NULL, NULL, cor, sexo, peso
FROM demo.pessoa p
WHERE EXISTS (
SELECT *
FROM demo_test.prescricao pre
WHERE p.fkpessoa = pre.fkpessoa
AND p.nratendimento = pre.nratendimento
);
INSERT INTO demo_test.exame
SELECT fkexame, fkpessoa, nratendimento, fkprescricao, dtexame + INTERVAL '1 month', tpexame, resultado, unidade
FROM demo.exame e
WHERE EXISTS (
SELECT *
FROM demo_test.pessoa p
WHERE p.fkpessoa = e.fkpessoa
AND p.nratendimento = e.nratendimento
);
INSERT INTO demo_test.presmed
SELECT *
FROM demo.presmed p
WHERE p.fkprescricao IN (
SELECT fkprescricao FROM demo_test.prescricao
);
INSERT INTO demo_test.outlier
SELECT *
FROM demo.outlier where idsegmento = 1;
INSERT INTO demo_test.prescricaoagg
SELECT *
FROM demo.prescricaoagg where idsegmento = 1;