-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconceptDiagnosis.R
78 lines (68 loc) · 2.56 KB
/
conceptDiagnosis.R
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
72
73
74
75
76
77
# Last updated: 09-14-2021
# Author: Cong Liu
# checked version: No
source("./cohortCharacterization.R")
conceptList = fread("./eTable1.csv")
colnames(conceptList)[4] = 'domain_id'
personList = bind_rows(breakthroughCovidRefined %>% dplyr::select(person_id),
nonBreakthroughPcrCovidRefined %>% dplyr::select(person_id),
preVaccinePcrPositiveCovidRefined %>% dplyr::select(person_id),
preVaccinePcrNegativeCovidRefined %>% dplyr::select(person_id),
postVaccinePcrPositiveCovidRefined %>% dplyr::select(person_id),
postVaccinePcrNegativeCovidRefined %>% dplyr::select(person_id)
) %>% distinct()
writeToSqlTempdb(con,name = '#conceptList',value = conceptList)
writeToSqlTempdb(con,name = '#personList',value = personList)
sql = "
select ce.condition_concept_id,cl.concept_name, count(distinct ce.person_id) as person_count
from #conceptList cl
left join [dbo].[condition_era] ce
on ce.condition_concept_id = cl.concept_id
right join #personList pl
on ce.person_id = pl.person_id
where cl.domain_id = 'Condition'
group by ce.condition_concept_id,cl.concept_name
"
countCondition = dbGetQuery(con,sql)
sql = "
select ce.drug_concept_id,cl.concept_name, count(distinct ce.person_id) as person_count
from #conceptList cl
left join [dbo].[drug_era] ce
on ce.drug_concept_id = cl.concept_id
right join #personList pl
on ce.person_id = pl.person_id
where cl.domain_id = 'Drug'
group by ce.drug_concept_id,cl.concept_name
"
countDrug = dbGetQuery(con,sql)
sql = "
select ce.measurement_concept_id,cl.concept_name, count(distinct ce.person_id) as person_count
from #conceptList cl
left join [dbo].[measurement] ce
on ce.measurement_concept_id = cl.concept_id
right join #personList pl
on ce.person_id = pl.person_id
where cl.domain_id = 'Measurement'
group by ce.measurement_concept_id,cl.concept_name
"
countMeasurement = dbGetQuery(con,sql)
sql = "
select ce.procedure_concept_id,cl.concept_name, count(distinct ce.person_id) as person_count
from #conceptList cl
left join [dbo].[procedure_occurrence] ce
on ce.procedure_concept_id = cl.concept_id
right join #personList pl
on ce.person_id = pl.person_id
where cl.domain_id = 'Procedure'
group by ce.procedure_concept_id,cl.concept_name
"
countProcedure = dbGetQuery(con,sql)
sql = "
select ce.visit_source_value,count(distinct ce.person_id) as person_count
from #personList pl
left join [dbo].[visit_occurrence] ce
on ce.person_id = pl.person_id
where ce.visit_start_date > '2020-01-01'
group by ce.visit_source_value
"
countVisit = dbGetQuery(con,sql)