-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReasons for LTFU.sql
59 lines (51 loc) · 2.47 KB
/
Reasons for LTFU.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
select Provincia, Distrito, designacao
, pa.hdd, pa.nid
, sexo as gender
, datediff(yy,pa.datanasc,bu.date_LTFU) as Age
, cast(datainiciotarv as DATE) as ARTinitiationDate
, datediff(mm,pa.datainiciotarv,bu.date_LTFU) as timeARTtoLTU
, date_LTFU, Year_LTFU
, Quarter_LTFU
, CASE WHEN codmotivoabandono='DISTANCIA/DINHEIRO TRANSPORTE' THEN 'Distance/Transportation Cost'
WHEN codmotivoabandono='ESTA ACAMADO EM CASA' THEN 'Bedridden at Home'
WHEN codmotivoabandono='PROBLEMAS FAMILIARES' THEN 'Family Issues'
WHEN codmotivoabandono='INSATISFACCAO COM SERVICO NO HDD' THEN 'Unsatisfied with HF Services'
WHEN codmotivoabandono='DESMOTIVACAO' THEN 'No Motivation'
WHEN codmotivoabandono='TRATAMENTO TRADICIONAL' THEN 'Taking Traditional Medication'
WHEN codmotivoabandono='ESQUECEU A DATA' THEN 'Forgot the Date'
WHEN codmotivoabandono='PROBLEMAS DE ALIMENTACAO' THEN 'Lack of Food'
WHEN codmotivoabandono='EFEITOS SECUNDARIOS ARV' THEN 'Side Effects of ARVs'
WHEN codmotivoabandono='TRABALHO' THEN 'Work'
WHEN codmotivoabandono='OUTRO' THEN 'Other'
WHEN codmotivoabandono='VIAJOU' THEN 'Travel'
WHEN codmotivoabandono is null THEN 'No reason Specified'
END AS LTUreason
, codreferencia AS LTFUmoreinfo
, pa.AccessFilePath
Into Sandbox.dbo.LTFUreasons
From t_paciente pa
INNER JOIN
(
Select
nid, codmotivoabandono, codreferencia, AccessFilePath
, cast(datacomecoufaltar as date) AS date_LTFU
, datepart(yy,cast(datacomecoufaltar AS DATE)) AS Year_LTFU
, /*------FY19------*/
CASE
WHEN cast(datacomecoufaltar AS DATE) between '2018-09-21' AND '2018-12-20' THEN 1
WHEN cast(datacomecoufaltar AS DATE) between '2018-12-21' AND '2019-03-20' THEN 2
WHEN cast(datacomecoufaltar AS DATE) between '2019-03-21' AND '2019-06-20' THEN 3
WHEN cast(datacomecoufaltar AS DATE) between '2019-06-21' AND '2019-09-20' THEN 4
/*------FY18------*/
WHEN cast(datacomecoufaltar AS DATE) between '2017-09-21' AND '2017-12-20' THEN 1
WHEN cast(datacomecoufaltar AS DATE) between '2017-12-21' AND '2018-03-20' THEN 2
WHEN cast(datacomecoufaltar AS DATE) between '2018-03-21' AND '2018-06-20' THEN 3
WHEN cast(datacomecoufaltar AS DATE) between '2018-06-21' AND '2018-09-20' THEN 4
END AS Quarter_LTFU
from t_buscaactiva
Where cast(datacomecoufaltar AS DATE) between '2017-09-21' AND '2019-09-20'
) bu
on pa.nid=bu.nid AND pa.AccessFilepath=bu.AccessFilePath
LEFT JOIN
t_hdd hd
on pa.hdd=hd.HdD AND pa.AccessFilePath=hd.AccessFilePath