-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdmtest_pcornet3.R
227 lines (173 loc) · 16.3 KB
/
dmtest_pcornet3.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
################ PCORnet V3 Data Model Orphan Keys test
# Reference means that the column value is reference for all other tables that have the same column
DQTBL_KEYS$Index <- ifelse(((DQTBL_KEYS$TabNam == "demographic" & DQTBL_KEYS$ColNam == "patid") |
(DQTBL_KEYS$TabNam == "prescribing" & DQTBL_KEYS$ColNam == "prescribingid") |
(DQTBL_KEYS$TabNam == "encounter" & DQTBL_KEYS$ColNam == "encounterid") |
(DQTBL_KEYS$TabNam == "encounter" & DQTBL_KEYS$ColNam == "enc_type") |
(DQTBL_KEYS$TabNam == "encounter" & DQTBL_KEYS$ColNam == "providerid")),
"Reference",
DQTBL_KEYS$Index)
#Copy the data frame to store not counted ids (the ones that are not available in the reference coulumn)
DQTBL_KEYS2 <- subset(DQTBL_KEYS, DQTBL_KEYS$Index != "Reference")
DQTBL_KEYS2$Index <- "Count_Out"
DQTBL_KEYS2$UNIQFRQ <- 0
DQTBL_KEYS <- rbind(DQTBL_KEYS,DQTBL_KEYS2);rm(DQTBL_KEYS2)
### Now let's count the number of unique ids that do not exist in the reference column and assign related values to them
## and then subtracting the number of counted outs from the number of counted ins
########## ##### ##### ########## ##### #####
########## ##### #####
########## ##### ##### ########## ##### #####
#patid
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "enrollment" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "enrollment", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "enrollment" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "enrollment" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "enrollment" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
####
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "encounter" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "encounter", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "encounter" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "encounter" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "encounter" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "diagnosis", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "procedures", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "vital" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "vital", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "vital" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "vital" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "vital" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "dispensing" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "dispensing", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "dispensing" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "dispensing" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "dispensing" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "lab_result_cm" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "lab_result_cm", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "lab_result_cm" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "lab_result_cm" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "lab_result_cm" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "condition" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "condition", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "condition" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "condition" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "condition" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "pro_cm" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "pro_cm", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "pro_cm" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "pro_cm" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "pro_cm" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "prescribing" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "prescribing", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "prescribing" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "prescribing" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "prescribing" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "pcornet_trial" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "pcornet_trial", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "pcornet_trial" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "pcornet_trial" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "pcornet_trial" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "death" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "death", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "death" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "death" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "death" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "death_condition" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "demographic", table2 = "death_condition", col = "patid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "death_condition" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "death_condition" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "death_condition" & DQTBL_KEYS$ColNam == "patid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
########## ##### ##### ########## ##### #####
########## ##### #####
########## ##### ##### ########## ##### #####
#enc_type
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "enc_type" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "encounter", table2 = "diagnosis", col = "enc_type")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "enc_type" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "enc_type" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "enc_type" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "enc_type" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "encounter", table2 = "procedures", col = "enc_type")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "enc_type" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "enc_type" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "enc_type" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
########## ##### ##### ########## ##### #####
########## ##### #####
########## ##### ##### ########## ##### #####
#encounterid
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "encounter", table2 = "diagnosis", col = "encounterid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "encounter", table2 = "procedures", col = "encounterid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "vital" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "encounter", table2 = "vital", col = "encounterid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "vital" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "vital" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "vital" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "lab_result_cm" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "encounter", table2 = "lab_result_cm", col = "encounterid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "lab_result_cm" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "lab_result_cm" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "lab_result_cm" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "condition" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "encounter", table2 = "condition", col = "encounterid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "condition" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "condition" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "condition" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "pro_cm" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "encounter", table2 = "pro_cm", col = "encounterid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "pro_cm" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "pro_cm" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "pro_cm" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "prescribing" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "encounter", table2 = "prescribing", col = "encounterid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "prescribing" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "prescribing" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "prescribing" & DQTBL_KEYS$ColNam == "encounterid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
########## ##### ##### ########## ##### #####
########## ##### #####
########## ##### ##### ########## ##### #####
# providerid
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "providerid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "encounter", table2 = "diagnosis", col = "providerid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "providerid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "providerid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "diagnosis" & DQTBL_KEYS$ColNam == "providerid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
###
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "providerid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"] <-
orphankeys(table1 = "encounter", table2 = "procedures", col = "providerid")
DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "providerid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"] <-
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "providerid" & DQTBL_KEYS$Index == "Count_In"),"UNIQFRQ"]) -
as.numeric(DQTBL_KEYS[(DQTBL_KEYS$TabNam == "procedures" & DQTBL_KEYS$ColNam == "providerid" & DQTBL_KEYS$Index == "Count_Out"),"UNIQFRQ"])
write.csv(DQTBL_KEYS, file = paste("reports/DM_",CDM,"_",org,"_",as.character(format(Sys.Date(),"%d-%m-%Y")),".csv", sep=""))