-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_groups.R
114 lines (94 loc) · 3.42 KB
/
update_groups.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
# update_groups.R
# Each year, new service codes and revenue codes may be added
# and these need to be appended to the service groupings
library(tidyverse); library(lubridate)
# So we start with the existing groupings
groups <- read_csv("data/clean/svc_grps.csv")
# groups <- arrow::read_feather("data/clean/svc_grps.feather")
# Load reference data sets to map codes to descriptions
# These are drawn from the Medicare Coverage Database
# filtering for "Current and Retired LCDs"
# and may not contain all Medicaid codes
# URL: "https://www.cms.gov/medicare-coverage-database/downloads/downloadable-databases.aspx"
# Using the 'lcd_x_hcpc_code.csv' file
hcpc_ref <-
read_csv("data/hcpc_code_lookup.csv") %>%
group_by(hcpc_code_id) %>%
filter(hcpc_code_version == max(hcpc_code_version)) %>%
select(
code = hcpc_code_id,
short_desc = short_description,
long_desc = long_description
) %>%
distinct(code, .keep_all = T)
# Using the 'lcd_x_revenue code.csv' file
rev_ref <-
read_csv("data/rev_code_lookup.csv") %>%
group_by(revenue_code_id) %>%
filter(revenue_code_version == max(revenue_code_version)) %>%
select(
code = revenue_code_id,
rev_desc = description
) %>%
distinct(code, .keep_all = T) %>%
ungroup() %>%
mutate(code = as.character(code))
ref_404 <-
df_404 %>%
group_by(code,service_description) %>%
summarize() %>%
group_by(code) %>%
filter(n_distinct(service_description) == 1) %>%
rename(desc_404 = service_description)
# Now test whether any codes are missing
tst <-
df_404 %>%
group_by(fy,code) %>%
summarize(n = n()) %>%
ungroup() %>%
# Allow view across years
spread(fy,n) %>%
left_join(groups, by = "code") %>%
# Missing group or code is all letters
filter(is.na(svc_grp) | str_detect(code,"^[A-Za-z]+$")) %>%
# Don't worry about codes previously mapped
filter(!str_detect(code,"xxx$"))
print(paste("There are ", nrow(tst), " codes requiring review"))
# Resolve these in .csv file, test, and then write final
# as both .csv and .feather files
arrow::write_feather(groups, "data/clean/svc_grps.feather")
write_csv(groups,"data/clean/svc_grps.csv")
rm(list = c("ref_404", "hcpc_ref", "rev_ref", "tst"))
# Create ref for CMHs
cmhsps <-
df_404 %>%
group_by(cmhsp) %>%
summarize() %>% ungroup() %>%
mutate(
pihp = recode(
cmhsp, 'Copper Country'='1','Network180'='3',
'Gogebic'='1','Hiawatha'='1','Northpointe'='1',
'Pathways'='1','AuSable Valley'='2',
'Manistee-Benzie'='2','North Country'='2',
'Northeast Michigan'='2','Northern Lakes'='2',
'Allegan'='3','Muskegon'='3','Network180'='3',
'Ottawa'='3','West Michigan'='3','Barry'='4',
'Berrien'='4','Kalamazoo'='4','Pines'='4',
'St. Joseph'='4','Summit Pointe'='4','Van Buren'='4',
'Woodlands'='4','Bay-Arenac'='5','Clinton Eaton Ingham'='5',
'CMH for Central Michigan'='5','Gratiot'='5','Huron'='5',
'Ionia'='5','Lifeways'='5','Montcalm'='5','Newaygo'='5',
'Saginaw'='5','Shiawassee'='5','Tuscola'='5',
'Lenawee'='6','Livingston'='6','Monroe'='6',
'Washtenaw'='6','Detroit-Wayne'='7','Oakland'='8',
'Macomb'='9','Genesee'='10','Lapeer'='10',
'Sanilac'='10','St. Clair'='10'
),
pihp_name = recode(
pihp, '1'='Northcare','2'='NMRE',
'3'='LRE','4'='SWMBH','5'='MSHN',
'6'='CMHPSM','7'='DWMHA','8'='OCCMHA',
'9'='MCMHS','10'='Region10'
)
)
write_csv(cmhsps,"data/clean/cmh_ref.csv")