#Subsample of metrics from MHSDS data
CAMHS_data <- MHSDS_main_pooled_dashboard %>%
  filter(PRIMARY_LEVEL_DESCRIPTION=="England",
         MEASURE_ID %in% c("CYP01","MHS61a","CYP23","MHS30d","MHS32a","CYP32")) %>%
  filter(.,!(MEASURE_ID=="MHS32a"&BREAKDOWN!="England")) %>% 
  mutate(MEASURE_KEY=case_when(
           MEASURE_ID=="MHS30d" ~ "Attended contacts (<18)",
           MEASURE_ID=="CYP01" ~ "People in contact",
           MEASURE_ID=="MHS61a" ~ "First contacts (<18)",
           MEASURE_ID=="CYP23" ~ "Open referrals",
           MEASURE_ID=="MHS32a" ~ "New referrals (<18)",
           MEASURE_ID=="CYP32" ~ "New referrals to CYPMHS",
           TRUE ~ "NA"
         )) %>% 
  select(.,start_date,end_date,month_year,PRIMARY_LEVEL_DESCRIPTION,MEASURE_ID,MEASURE_KEY,MEASURE_VALUE) %>% 
  mutate(.,MEASURE_VALUE=as.numeric(MEASURE_VALUE),
         timing=ifelse(start_date<ymd("2020-04-01"),"Pre-COVID","Post-COVID"),
         month_num=lubridate::month(start_date)) %>%
  mutate(.,timing=fct_relevel(timing, c("Pre-COVID","Post-COVID"))) %>% 
  arrange(.,start_date) %>%
  as_tibble()

#Percentage change compared to a year ago
#For example, for March 2020 show the % change between March 2019 and March 2020

CAMHS_yearly_changes <- CAMHS_data %>%
  select(.,PRIMARY_LEVEL_DESCRIPTION,MEASURE_ID,MEASURE_KEY,MEASURE_VALUE,start_date,month_year,timing) %>%
  mutate(start_date=lubridate::ymd(start_date)) %>%
  mutate(.,start_date_l1=start_date-years(1)) #Adds a new column with the month a year before

#Auxiliary dataset with data points from a year before
CAMHS_data_l1 <- CAMHS_yearly_changes %>%
  select(.,start_date,MEASURE_VALUE,PRIMARY_LEVEL_DESCRIPTION,MEASURE_ID,MEASURE_KEY) %>%
  rename(.,MEASURE_VALUE_l1=MEASURE_VALUE,start_date_l1=start_date)

#Merge auxiliary data back in
CAMHS_yearly_changes <- left_join(CAMHS_yearly_changes,
                                          CAMHS_data_l1,
                                          by=c("start_date_l1","PRIMARY_LEVEL_DESCRIPTION","MEASURE_ID","MEASURE_KEY")) %>%
  arrange(.,MEASURE_ID,start_date) %>%
  mutate(pct_change_l1=(MEASURE_VALUE-MEASURE_VALUE_l1)/MEASURE_VALUE_l1*100) %>%
  filter(.,!is.na(pct_change_l1))
rm(CAMHS_data_l1)
flourish_data_mhsds <- CAMHS_data %>%
  filter(.,MEASURE_ID %in% c("CYP01","MHS61a","CYP23","MHS32a")) %>%
  select(.,start_date,end_date,month_year,PRIMARY_LEVEL_DESCRIPTION,MEASURE_ID,MEASURE_KEY,MEASURE_VALUE) %>%
  mutate(.,month=lubridate::month(start_date, label = TRUE),
         year=lubridate::year(start_date)) %>%
  select(.,month,year,MEASURE_ID,MEASURE_KEY,MEASURE_VALUE) %>%
  pivot_wider(.,
    names_from = year,
    names_sep = ".",
    values_from = c(MEASURE_VALUE)
  ) %>%
  arrange(.,MEASURE_ID,month)

#fwrite(flourish_data_mhsds,paste0(onedrive_charts_data,"Fig2alt.csv"))

Performance against 18 week target in Scottish CAMHS

Raw time series

#Data
CAMHS_Scotland_18wks <- scotland_camhs_appended %>%
  filter(.,Metric %in% c("TotalPatientsSeen","NumberOfPatientsSeen0To18Weeks"),
         HB=="S92000003") %>%
  pivot_wider(names_from = Metric,
              names_sep = ".",
              values_from = c(Count)) %>%
  mutate(.,pct_within_18wks=as.numeric(NumberOfPatientsSeen0To18Weeks)/
           as.numeric(TotalPatientsSeen)*100,
         year_month=ymd(year_month))

#Time series chart
CAMHS_Scotland_18wks_chart <- CAMHS_Scotland_18wks %>% 
  ggplot(., aes(x=year_month, y=pct_within_18wks)) +
  geom_line(size=1) +
  scale_x_date(date_labels = "%b %Y",date_breaks = "3 months") +
  scale_y_continuous(labels = scales::comma, limits=c(0,100)) +
  geom_hline(yintercept=90, linetype="dashed", color = "red") +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="") +
  scale_color_brewer(palette = "Set1") +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))
  
ggplotly(CAMHS_Scotland_18wks_chart)
#Underlying data
CAMHS_Scotland_18wks %>%
  arrange(.,year_month) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
HB Month year month year_month TotalPatientsSeen NumberOfPatientsSeen0To18Weeks pct_within_18wks
S92000003 201,207 2,012 7 2012-07-01 751 611 81.35819
S92000003 201,208 2,012 8 2012-08-01 840 653 77.73810
S92000003 201,209 2,012 9 2012-09-01 807 633 78.43866
S92000003 201,210 2,012 10 2012-10-01 1083 858 79.22438
S92000003 201,211 2,012 11 2012-11-01 1236 1023 82.76699
S92000003 201,212 2,012 12 2012-12-01 847 707 83.47107
S92000003 201,301 2,013 1 2013-01-01 1190 986 82.85714
S92000003 201,302 2,013 2 2013-02-01 1264 1077 85.20570
S92000003 201,303 2,013 3 2013-03-01 1057 933 88.26869
S92000003 201,304 2,013 4 2013-04-01 1153 993 86.12316
S92000003 201,305 2,013 5 2013-05-01 1273 1093 85.86017
S92000003 201,306 2,013 6 2013-06-01 1024 885 86.42578
S92000003 201,307 2,013 7 2013-07-01 997 847 84.95486
S92000003 201,308 2,013 8 2013-08-01 976 788 80.73770
S92000003 201,309 2,013 9 2013-09-01 983 840 85.45270
S92000003 201,310 2,013 10 2013-10-01 1180 991 83.98305
S92000003 201,311 2,013 11 2013-11-01 1241 983 79.21031
S92000003 201,312 2,013 12 2013-12-01 909 773 85.03850
S92000003 201,401 2,014 1 2014-01-01 1342 1126 83.90462
S92000003 201,402 2,014 2 2014-02-01 1277 1055 82.61551
S92000003 201,403 2,014 3 2014-03-01 1114 949 85.18851
S92000003 201,404 2,014 4 2014-04-01 1153 965 83.69471
S92000003 201,405 2,014 5 2014-05-01 1359 1129 83.07579
S92000003 201,406 2,014 6 2014-06-01 1048 831 79.29389
S92000003 201,407 2,014 7 2014-07-01 993 795 80.06042
S92000003 201,408 2,014 8 2014-08-01 997 764 76.62989
S92000003 201,409 2,014 9 2014-09-01 1333 1036 77.71943
S92000003 201,410 2,014 10 2014-10-01 1442 1111 77.04577
S92000003 201,411 2,014 11 2014-11-01 1464 1140 77.86885
S92000003 201,412 2,014 12 2014-12-01 1266 1040 82.14850
S92000003 201,501 2,015 1 2015-01-01 1466 1155 78.78581
S92000003 201,502 2,015 2 2015-02-01 1391 1069 76.85119
S92000003 201,503 2,015 3 2015-03-01 1412 1145 81.09065
S92000003 201,504 2,015 4 2015-04-01 1445 1134 78.47751
S92000003 201,505 2,015 5 2015-05-01 1476 1120 75.88076
S92000003 201,506 2,015 6 2015-06-01 1542 1170 75.87549
S92000003 201,507 2,015 7 2015-07-01 1415 1072 75.75972
S92000003 201,508 2,015 8 2015-08-01 1335 965 72.28464
S92000003 201,509 2,015 9 2015-09-01 1489 1060 71.18872
S92000003 201,510 2,015 10 2015-10-01 1534 1114 72.62060
S92000003 201,511 2,015 11 2015-11-01 1680 1243 73.98810
S92000003 201,512 2,015 12 2015-12-01 1291 1077 83.42370
S92000003 201,601 2,016 1 2016-01-01 1416 1200 84.74576
S92000003 201,602 2,016 2 2016-02-01 1516 1282 84.56464
S92000003 201,603 2,016 3 2016-03-01 1564 1313 83.95141
S92000003 201,604 2,016 4 2016-04-01 1494 1211 81.05756
S92000003 201,605 2,016 5 2016-05-01 1636 1224 74.81663
S92000003 201,606 2,016 6 2016-06-01 1606 1246 77.58406
S92000003 201,607 2,016 7 2016-07-01 1204 946 78.57143
S92000003 201,608 2,016 8 2016-08-01 1512 1175 77.71164
S92000003 201,609 2,016 9 2016-09-01 1444 1150 79.63989
S92000003 201,610 2,016 10 2016-10-01 1411 1173 83.13253
S92000003 201,611 2,016 11 2016-11-01 1665 1319 79.21922
S92000003 201,612 2,016 12 2016-12-01 1277 1099 86.06108
S92000003 201,701 2,017 1 2017-01-01 1307 1102 84.31523
S92000003 201,702 2,017 2 2017-02-01 1468 1211 82.49319
S92000003 201,703 2,017 3 2017-03-01 1558 1308 83.95379
S92000003 201,704 2,017 4 2017-04-01 1157 933 80.63959
S92000003 201,705 2,017 5 2017-05-01 1550 1256 81.03226
S92000003 201,706 2,017 6 2017-06-01 1385 1115 80.50542
S92000003 201,707 2,017 7 2017-07-01 1008 777 77.08333
S92000003 201,708 2,017 8 2017-08-01 1299 930 71.59353
S92000003 201,709 2,017 9 2017-09-01 1105 791 71.58371
S92000003 201,710 2,017 10 2017-10-01 1263 897 71.02138
S92000003 201,711 2,017 11 2017-11-01 1656 1143 69.02174
S92000003 201,712 2,017 12 2017-12-01 1108 824 74.36823
S92000003 201,801 2,018 1 2018-01-01 1367 989 72.34821
S92000003 201,802 2,018 2 2018-02-01 1318 930 70.56146
S92000003 201,803 2,018 3 2018-03-01 1310 921 70.30534
S92000003 201,804 2,018 4 2018-04-01 1451 957 65.95451
S92000003 201,805 2,018 5 2018-05-01 1712 1146 66.93925
S92000003 201,806 2,018 6 2018-06-01 1531 1067 69.69301
S92000003 201,807 2,018 7 2018-07-01 1314 923 70.24353
S92000003 201,808 2,018 8 2018-08-01 1548 1027 66.34367
S92000003 201,809 2,018 9 2018-09-01 1377 973 70.66086
S92000003 201,810 2,018 10 2018-10-01 1630 1189 72.94479
S92000003 201,811 2,018 11 2018-11-01 1662 1135 68.29122
S92000003 201,812 2,018 12 2018-12-01 1231 967 78.55402
S92000003 201,901 2,019 1 2019-01-01 1493 1076 72.06966
S92000003 201,902 2,019 2 2019-02-01 1414 1038 73.40877
S92000003 201,903 2,019 3 2019-03-01 1330 1006 75.63910
S92000003 201,904 2,019 4 2019-04-01 1384 957 69.14740
S92000003 201,905 2,019 5 2019-05-01 1453 1009 69.44253
S92000003 201,906 2,019 6 2019-06-01 1175 834 70.97872
S92000003 201,907 2,019 7 2019-07-01 1262 792 62.75753
S92000003 201,908 2,019 8 2019-08-01 1333 850 63.76594
S92000003 201,909 2,019 9 2019-09-01 1307 875 66.94721
S92000003 201,910 2,019 10 2019-10-01 1374 890 64.77438
S92000003 201,911 2,019 11 2019-11-01 1437 922 64.16145
S92000003 201,912 2,019 12 2019-12-01 1073 767 71.48183
S92000003 202,001 2,020 1 2020-01-01 1399 945 67.54825
S92000003 202,002 2,020 2 2020-02-01 1448 957 66.09116
S92000003 202,003 2,020 3 2020-03-01 1284 848 66.04361
S92000003 202,004 2,020 4 2020-04-01 955 724 75.81152
S92000003 202,005 2,020 5 2020-05-01 1238 746 60.25848
S92000003 202,006 2,020 6 2020-06-01 1355 720 53.13653
S92000003 202,007 2,020 7 2020-07-01 1297 751 57.90285
S92000003 202,008 2,020 8 2020-08-01 1249 714 57.16573
S92000003 202,009 2,020 9 2020-09-01 1486 979 65.88156
S92000003 202,010 2,020 10 2020-10-01 1309 961 73.41482
S92000003 202,011 2,020 11 2020-11-01 1511 1102 72.93183
S92000003 202,012 2,020 12 2020-12-01 1271 927 72.93470
S92000003 202,101 2,021 1 2021-01-01 1275 901 70.66667
S92000003 202,102 2,021 2 2021-02-01 1315 986 74.98099
S92000003 202,103 2,021 3 2021-03-01 1506 1079 71.64675
S92000003 202,104 2,021 4 2021-04-01 1533 1093 71.29811
S92000003 202,105 2,021 5 2021-05-01 1530 1099 71.83007
S92000003 202,106 2,021 6 2021-06-01 1489 1114 74.81531
S92000003 202,107 2,021 7 2021-07-01 1203 913 75.89360
S92000003 202,108 2,021 8 2021-08-01 1252 969 77.39617
S92000003 202,109 2,021 9 2021-09-01 1337 1098 82.12416
S92000003 202,110 2,021 10 2021-10-01 1440 1029 71.45833
S92000003 202,111 2,021 11 2021-11-01 1749 1233 70.49743
S92000003 202,112 2,021 12 2021-12-01 1355 933 68.85609

Monthly average, per year

#Average per calendar year
CAMHS_Scotland_18wks %>%
  mutate(.,year=lubridate::year(year_month)) %>% 
  group_by(year) %>%
  summarise(average=mean(pct_within_18wks,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==12) %>%
  knitr::kable(., align = "lccrr")
year average months_included
2013 84.50981 12
2014 80.77049 12
2015 76.35224 12
2016 80.92132 12
2017 77.30095 12
2018 70.23666 12
2019 68.71454 12
2020 65.76009 12
2021 73.45530 12

People still receiving treatment in Scottish CAMHS

Raw time series

#Data
CAMHS_Scotland_open <- scotland_camhs_appended %>%
  filter(.,Metric %in% c("OpenCases"),
         HB=="S92000003") %>%
  mutate(.,Count=as.numeric(Count),
         year_month=ymd(year_month))

#Time series chart
CAMHS_Scotland_open_chart <- CAMHS_Scotland_open %>% 
  ggplot(., aes(x=year_month, y=Count, group= Metric)) +
  geom_line(aes(color= Metric),
            size=1) +
  scale_x_date(date_labels = "%b %Y",date_breaks = "3 months") +
  scale_y_continuous(labels = scales::comma) +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="") +
  scale_color_brewer(palette = "Set1") +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))
  
ggplotly(CAMHS_Scotland_open_chart)
#Underlying data
CAMHS_Scotland_open %>%
  arrange(.,year_month) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
HB Month Metric Count year month year_month
S92000003 201,901 OpenCases 27,936 2,019 1 2019-01-01
S92000003 201,902 OpenCases 27,077 2,019 2 2019-02-01
S92000003 201,903 OpenCases 27,332 2,019 3 2019-03-01
S92000003 201,904 OpenCases 27,217 2,019 4 2019-04-01
S92000003 201,905 OpenCases 26,006 2,019 5 2019-05-01
S92000003 201,906 OpenCases 25,675 2,019 6 2019-06-01
S92000003 201,907 OpenCases 25,496 2,019 7 2019-07-01
S92000003 201,908 OpenCases 28,702 2,019 8 2019-08-01
S92000003 201,909 OpenCases 29,326 2,019 9 2019-09-01
S92000003 201,910 OpenCases 30,233 2,019 10 2019-10-01
S92000003 201,911 OpenCases 30,744 2,019 11 2019-11-01
S92000003 201,912 OpenCases 30,431 2,019 12 2019-12-01
S92000003 202,001 OpenCases 31,246 2,020 1 2020-01-01
S92000003 202,002 OpenCases 30,836 2,020 2 2020-02-01
S92000003 202,003 OpenCases 29,504 2,020 3 2020-03-01
S92000003 202,004 OpenCases 28,985 2,020 4 2020-04-01
S92000003 202,005 OpenCases 28,819 2,020 5 2020-05-01
S92000003 202,006 OpenCases 28,662 2,020 6 2020-06-01
S92000003 202,007 OpenCases 27,981 2,020 7 2020-07-01
S92000003 202,008 OpenCases 28,056 2,020 8 2020-08-01
S92000003 202,009 OpenCases 28,302 2,020 9 2020-09-01
S92000003 202,010 OpenCases 28,425 2,020 10 2020-10-01
S92000003 202,011 OpenCases 29,029 2,020 11 2020-11-01
S92000003 202,012 OpenCases 28,771 2,020 12 2020-12-01
S92000003 202,101 OpenCases 28,767 2,021 1 2021-01-01
S92000003 202,102 OpenCases 28,883 2,021 2 2021-02-01
S92000003 202,103 OpenCases 28,995 2,021 3 2021-03-01
S92000003 202,104 OpenCases 28,927 2,021 4 2021-04-01
S92000003 202,105 OpenCases 29,750 2,021 5 2021-05-01
S92000003 202,106 OpenCases 28,988 2,021 6 2021-06-01
S92000003 202,107 OpenCases 28,209 2,021 7 2021-07-01
S92000003 202,108 OpenCases 28,156 2,021 8 2021-08-01
S92000003 202,109 OpenCases 28,310 2,021 9 2021-09-01
S92000003 202,110 OpenCases 28,536 2,021 10 2021-10-01
S92000003 202,111 OpenCases 29,127 2,021 11 2021-11-01
S92000003 202,112 OpenCases 26,032 2,021 12 2021-12-01

Monthly average, per year

#Average per calendar year
CAMHS_Scotland_open %>%
  mutate(.,year=lubridate::year(year_month)) %>% 
  group_by(Metric,year) %>%
  summarise(average=mean(Count,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==12) %>%
  knitr::kable(., align = "lccrr")
Metric year average months_included
OpenCases 2019 28014.58 12
OpenCases 2020 29051.33 12
OpenCases 2021 28556.67 12

People waiting for treatment in Scottish CAMHS

Raw time series

#Data
CAMHS_Scotland_waiting <- scotland_camhs_appended %>%
  filter(.,Metric %in% c("TotalPatientsWaiting"),
         HB=="S92000003") %>%
  mutate(.,Count=as.numeric(Count),
         year_month=ymd(year_month))

#Time series chart
CAMHS_Scotland_waiting_chart <- CAMHS_Scotland_waiting %>% 
  ggplot(., aes(x=year_month, y=Count, group= Metric)) +
  geom_line(aes(color= Metric),
            size=1) +
  scale_x_date(date_labels = "%b %Y",date_breaks = "3 months") +
  scale_y_continuous(labels = scales::comma) +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="") +
  scale_color_brewer(palette = "Set1") +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))
  
ggplotly(CAMHS_Scotland_waiting_chart)
#Underlying data
CAMHS_Scotland_waiting %>%
  arrange(.,year_month) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
HB Month Metric Count year month year_month
S92000003 201,207 TotalPatientsWaiting 3,638 2,012 7 2012-07-01
S92000003 201,208 TotalPatientsWaiting 3,196 2,012 8 2012-08-01
S92000003 201,209 TotalPatientsWaiting 3,369 2,012 9 2012-09-01
S92000003 201,210 TotalPatientsWaiting 3,820 2,012 10 2012-10-01
S92000003 201,211 TotalPatientsWaiting 3,966 2,012 11 2012-11-01
S92000003 201,212 TotalPatientsWaiting 4,147 2,012 12 2012-12-01
S92000003 201,301 TotalPatientsWaiting 4,055 2,013 1 2013-01-01
S92000003 201,302 TotalPatientsWaiting 4,181 2,013 2 2013-02-01
S92000003 201,303 TotalPatientsWaiting 4,584 2,013 3 2013-03-01
S92000003 201,304 TotalPatientsWaiting 4,332 2,013 4 2013-04-01
S92000003 201,305 TotalPatientsWaiting 4,393 2,013 5 2013-05-01
S92000003 201,306 TotalPatientsWaiting 4,770 2,013 6 2013-06-01
S92000003 201,307 TotalPatientsWaiting 4,546 2,013 7 2013-07-01
S92000003 201,308 TotalPatientsWaiting 4,391 2,013 8 2013-08-01
S92000003 201,309 TotalPatientsWaiting 4,818 2,013 9 2013-09-01
S92000003 201,310 TotalPatientsWaiting 5,641 2,013 10 2013-10-01
S92000003 201,311 TotalPatientsWaiting 5,900 2,013 11 2013-11-01
S92000003 201,312 TotalPatientsWaiting 6,405 2,013 12 2013-12-01
S92000003 201,401 TotalPatientsWaiting 6,606 2,014 1 2014-01-01
S92000003 201,402 TotalPatientsWaiting 6,980 2,014 2 2014-02-01
S92000003 201,403 TotalPatientsWaiting 7,086 2,014 3 2014-03-01
S92000003 201,404 TotalPatientsWaiting 6,876 2,014 4 2014-04-01
S92000003 201,405 TotalPatientsWaiting 6,972 2,014 5 2014-05-01
S92000003 201,406 TotalPatientsWaiting 5,261 2,014 6 2014-06-01
S92000003 201,407 TotalPatientsWaiting 4,453 2,014 7 2014-07-01
S92000003 201,408 TotalPatientsWaiting 5,979 2,014 8 2014-08-01
S92000003 201,409 TotalPatientsWaiting 6,146 2,014 9 2014-09-01
S92000003 201,410 TotalPatientsWaiting 6,232 2,014 10 2014-10-01
S92000003 201,411 TotalPatientsWaiting 6,205 2,014 11 2014-11-01
S92000003 201,412 TotalPatientsWaiting 6,573 2,014 12 2014-12-01
S92000003 201,501 TotalPatientsWaiting 6,409 2,015 1 2015-01-01
S92000003 201,502 TotalPatientsWaiting 6,565 2,015 2 2015-02-01
S92000003 201,503 TotalPatientsWaiting 6,867 2,015 3 2015-03-01
S92000003 201,504 TotalPatientsWaiting 6,649 2,015 4 2015-04-01
S92000003 201,505 TotalPatientsWaiting 6,604 2,015 5 2015-05-01
S92000003 201,506 TotalPatientsWaiting 6,519 2,015 6 2015-06-01
S92000003 201,507 TotalPatientsWaiting 5,990 2,015 7 2015-07-01
S92000003 201,508 TotalPatientsWaiting 5,834 2,015 8 2015-08-01
S92000003 201,509 TotalPatientsWaiting 6,141 2,015 9 2015-09-01
S92000003 201,510 TotalPatientsWaiting 6,159 2,015 10 2015-10-01
S92000003 201,511 TotalPatientsWaiting 6,355 2,015 11 2015-11-01
S92000003 201,512 TotalPatientsWaiting 6,513 2,015 12 2015-12-01
S92000003 201,601 TotalPatientsWaiting 6,337 2,016 1 2016-01-01
S92000003 201,602 TotalPatientsWaiting 6,618 2,016 2 2016-02-01
S92000003 201,603 TotalPatientsWaiting 6,624 2,016 3 2016-03-01
S92000003 201,604 TotalPatientsWaiting 6,785 2,016 4 2016-04-01
S92000003 201,605 TotalPatientsWaiting 6,819 2,016 5 2016-05-01
S92000003 201,606 TotalPatientsWaiting 6,568 2,016 6 2016-06-01
S92000003 201,607 TotalPatientsWaiting 6,040 2,016 7 2016-07-01
S92000003 201,608 TotalPatientsWaiting 5,520 2,016 8 2016-08-01
S92000003 201,609 TotalPatientsWaiting 5,702 2,016 9 2016-09-01
S92000003 201,610 TotalPatientsWaiting 5,717 2,016 10 2016-10-01
S92000003 201,611 TotalPatientsWaiting 5,884 2,016 11 2016-11-01
S92000003 201,612 TotalPatientsWaiting 6,279 2,016 12 2016-12-01
S92000003 201,701 TotalPatientsWaiting 6,422 2,017 1 2017-01-01
S92000003 201,702 TotalPatientsWaiting 6,492 2,017 2 2017-02-01
S92000003 201,703 TotalPatientsWaiting 6,932 2,017 3 2017-03-01
S92000003 201,704 TotalPatientsWaiting 6,677 2,017 4 2017-04-01
S92000003 201,705 TotalPatientsWaiting 6,873 2,017 5 2017-05-01
S92000003 201,706 TotalPatientsWaiting 6,964 2,017 6 2017-06-01
S92000003 201,707 TotalPatientsWaiting 5,902 2,017 7 2017-07-01
S92000003 201,708 TotalPatientsWaiting 5,537 2,017 8 2017-08-01
S92000003 201,709 TotalPatientsWaiting 5,939 2,017 9 2017-09-01
S92000003 201,710 TotalPatientsWaiting 6,099 2,017 10 2017-10-01
S92000003 201,711 TotalPatientsWaiting 7,271 2,017 11 2017-11-01
S92000003 201,712 TotalPatientsWaiting 7,620 2,017 12 2017-12-01
S92000003 201,801 TotalPatientsWaiting 7,684 2,018 1 2018-01-01
S92000003 201,802 TotalPatientsWaiting 7,965 2,018 2 2018-02-01
S92000003 201,803 TotalPatientsWaiting 8,370 2,018 3 2018-03-01
S92000003 201,804 TotalPatientsWaiting 8,277 2,018 4 2018-04-01
S92000003 201,805 TotalPatientsWaiting 8,240 2,018 5 2018-05-01
S92000003 201,806 TotalPatientsWaiting 8,510 2,018 6 2018-06-01
S92000003 201,807 TotalPatientsWaiting 7,908 2,018 7 2018-07-01
S92000003 201,808 TotalPatientsWaiting 7,653 2,018 8 2018-08-01
S92000003 201,809 TotalPatientsWaiting 7,860 2,018 9 2018-09-01
S92000003 201,810 TotalPatientsWaiting 8,296 2,018 10 2018-10-01
S92000003 201,811 TotalPatientsWaiting 8,827 2,018 11 2018-11-01
S92000003 201,812 TotalPatientsWaiting 9,337 2,018 12 2018-12-01
S92000003 201,901 TotalPatientsWaiting 9,661 2,019 1 2019-01-01
S92000003 201,902 TotalPatientsWaiting 9,891 2,019 2 2019-02-01
S92000003 201,903 TotalPatientsWaiting 10,609 2,019 3 2019-03-01
S92000003 201,904 TotalPatientsWaiting 9,974 2,019 4 2019-04-01
S92000003 201,905 TotalPatientsWaiting 10,263 2,019 5 2019-05-01
S92000003 201,906 TotalPatientsWaiting 10,445 2,019 6 2019-06-01
S92000003 201,907 TotalPatientsWaiting 10,059 2,019 7 2019-07-01
S92000003 201,908 TotalPatientsWaiting 9,926 2,019 8 2019-08-01
S92000003 201,909 TotalPatientsWaiting 10,034 2,019 9 2019-09-01
S92000003 201,910 TotalPatientsWaiting 10,083 2,019 10 2019-10-01
S92000003 201,911 TotalPatientsWaiting 10,475 2,019 11 2019-11-01
S92000003 201,912 TotalPatientsWaiting 10,820 2,019 12 2019-12-01
S92000003 202,001 TotalPatientsWaiting 11,030 2,020 1 2020-01-01
S92000003 202,002 TotalPatientsWaiting 11,449 2,020 2 2020-02-01
S92000003 202,003 TotalPatientsWaiting 11,455 2,020 3 2020-03-01
S92000003 202,004 TotalPatientsWaiting 10,578 2,020 4 2020-04-01
S92000003 202,005 TotalPatientsWaiting 9,734 2,020 5 2020-05-01
S92000003 202,006 TotalPatientsWaiting 9,347 2,020 6 2020-06-01
S92000003 202,007 TotalPatientsWaiting 8,996 2,020 7 2020-07-01
S92000003 202,008 TotalPatientsWaiting 9,181 2,020 8 2020-08-01
S92000003 202,009 TotalPatientsWaiting 9,699 2,020 9 2020-09-01
S92000003 202,010 TotalPatientsWaiting 10,151 2,020 10 2020-10-01
S92000003 202,011 TotalPatientsWaiting 10,756 2,020 11 2020-11-01
S92000003 202,012 TotalPatientsWaiting 11,166 2,020 12 2020-12-01
S92000003 202,101 TotalPatientsWaiting 10,711 2,021 1 2021-01-01
S92000003 202,102 TotalPatientsWaiting 10,744 2,021 2 2021-02-01
S92000003 202,103 TotalPatientsWaiting 11,008 2,021 3 2021-03-01
S92000003 202,104 TotalPatientsWaiting 10,911 2,021 4 2021-04-01
S92000003 202,105 TotalPatientsWaiting 11,531 2,021 5 2021-05-01
S92000003 202,106 TotalPatientsWaiting 11,722 2,021 6 2021-06-01
S92000003 202,107 TotalPatientsWaiting 11,323 2,021 7 2021-07-01
S92000003 202,108 TotalPatientsWaiting 11,332 2,021 8 2021-08-01
S92000003 202,109 TotalPatientsWaiting 11,816 2,021 9 2021-09-01
S92000003 202,110 TotalPatientsWaiting 12,083 2,021 10 2021-10-01
S92000003 202,111 TotalPatientsWaiting 12,107 2,021 11 2021-11-01
S92000003 202,112 TotalPatientsWaiting 10,452 2,021 12 2021-12-01

Monthly average, per year

#Average per calendar year
CAMHS_Scotland_waiting %>%
  mutate(.,year=lubridate::year(year_month)) %>% 
  group_by(Metric,year) %>%
  summarise(average=mean(Count,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==12) %>%
  knitr::kable(., align = "lccrr")
Metric year average months_included
TotalPatientsWaiting 2013 4834.667 12
TotalPatientsWaiting 2014 6280.750 12
TotalPatientsWaiting 2015 6383.750 12
TotalPatientsWaiting 2016 6241.083 12
TotalPatientsWaiting 2017 6560.667 12
TotalPatientsWaiting 2018 8243.917 12
TotalPatientsWaiting 2019 10186.667 12
TotalPatientsWaiting 2020 10295.167 12
TotalPatientsWaiting 2021 11311.667 12

People in contact with CAMHS

Raw time series

#Data
CAMHS_data_cyp01 <- CAMHS_data %>%
  filter(.,MEASURE_ID=="CYP01")
CAMHS_reldata_cyp01 <- CAMHS_yearly_changes %>%
  filter(.,MEASURE_ID=="CYP01")

#Time series chart
CAMHS_raw_chart_cyp01 <- CAMHS_data_cyp01 %>% 
  ggplot(., aes(x=start_date, y=MEASURE_VALUE, group= MEASURE_KEY)) +
  geom_line(aes(color= MEASURE_KEY),
            size=1) +
  scale_x_date(date_labels = "%b %Y",date_breaks = "3 months") +
  scale_y_continuous(labels = scales::comma) +
  facet_wrap(~timing, scales = "free_x") +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="") +
  scale_color_brewer(palette = "Set1") +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))
  
ggplotly(CAMHS_raw_chart_cyp01)
#Underlying data
CAMHS_data_cyp01 %>%
  select(.,start_date,MEASURE_KEY,MEASURE_VALUE) %>%
  arrange(.,start_date) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
start_date MEASURE_KEY MEASURE_VALUE
2018-05-01 People in contact 222,156
2018-06-01 People in contact 225,407
2018-07-01 People in contact 218,557
2018-08-01 People in contact 213,702
2018-09-01 People in contact 218,764
2018-10-01 People in contact 227,845
2018-11-01 People in contact 223,744
2018-12-01 People in contact 227,679
2019-01-01 People in contact 229,217
2019-02-01 People in contact 233,831
2019-03-01 People in contact 241,926
2019-04-01 People in contact 218,678
2019-05-01 People in contact 230,443
2019-06-01 People in contact 225,480
2019-07-01 People in contact 226,647
2019-08-01 People in contact 218,826
2019-09-01 People in contact 221,428
2019-10-01 People in contact 225,507
2019-11-01 People in contact 230,739
2019-12-01 People in contact 231,056
2020-01-01 People in contact 236,396
2020-02-01 People in contact 240,401
2020-03-01 People in contact 237,088
2020-04-01 People in contact 281,199
2020-05-01 People in contact 273,706
2020-06-01 People in contact 272,529
2020-07-01 People in contact 275,439
2020-08-01 People in contact 271,462
2020-09-01 People in contact 286,880
2020-10-01 People in contact 296,414
2020-11-01 People in contact 309,311
2020-12-01 People in contact 311,119
2021-01-01 People in contact 307,335
2021-02-01 People in contact 306,997
2021-03-01 People in contact 317,845
2021-04-01 People in contact 323,240
2021-05-01 People in contact 337,426
2021-06-01 People in contact 340,694
2021-07-01 People in contact 342,565
2021-08-01 People in contact 331,912
2021-09-01 People in contact 337,080
2021-10-01 People in contact 349,449
2021-11-01 People in contact 357,802
2021-12-01 People in contact 355,807

Monthly average, per year

#Average per calendar year
CAMHS_data_cyp01 %>%
  mutate(.,year=lubridate::year(start_date)) %>% 
  group_by(MEASURE_ID,MEASURE_KEY,year) %>%
  summarise(average=mean(MEASURE_VALUE,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==12) %>%
  knitr::kable(., align = "lccrr")
MEASURE_ID MEASURE_KEY year average months_included
CYP01 People in contact 2019 227814.8 12
CYP01 People in contact 2020 274328.7 12
CYP01 People in contact 2021 334012.7 12

Monthly average, per year (Jan to Sep)

#Average per calendar year
CAMHS_data_cyp01 %>%
  mutate(.,year=lubridate::year(start_date)) %>%
  filter(.,month_num>=1&month_num<=9) %>%
  group_by(MEASURE_ID,MEASURE_KEY,year) %>%
  summarise(average=mean(MEASURE_VALUE,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==9) %>%
  knitr::kable(., align = "lccrr")
MEASURE_ID MEASURE_KEY year average months_included
CYP01 People in contact 2019 227386.2 9
CYP01 People in contact 2020 263900.0 9
CYP01 People in contact 2021 327232.7 9

Relative changes compared to last year

#Relative changes chart
CAMHS_changes_chart_cyp01 <- CAMHS_reldata_cyp01 %>%
  ggplot(., aes(x=start_date, y=pct_change_l1, group= MEASURE_KEY)) +
  facet_wrap(~timing, scales = "free_x") +
  geom_line(aes(color= MEASURE_KEY),size=1) +
  geom_hline(yintercept=0, linetype="dashed", color = "red") +
  scale_x_date(date_labels = "%b %Y",date_breaks = "1 month") +
  theme_ipsum() +
  xlab("") +
  ylab("% change") +
  labs(col="") +
  scale_color_manual(values=c("Open referrals" = "aquamarine4",
                              "People in contact" = "tomato3",
                              "First contactsn (<18)" = "olivedrab4",
                              "Attended contacts (<18)" = "violetred",
                              "New referrals (<18)" = "magenta1")) +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))

ggplotly(CAMHS_changes_chart_cyp01)
#Underlying data
CAMHS_reldata_cyp01 %>%
  select(.,start_date,MEASURE_KEY,pct_change_l1) %>%
  arrange(.,start_date) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
start_date MEASURE_KEY pct_change_l1
2019-05-01 People in contact 3.7302616
2019-06-01 People in contact 0.0323859
2019-07-01 People in contact 3.7015515
2019-08-01 People in contact 2.3977314
2019-09-01 People in contact 1.2177506
2019-10-01 People in contact -1.0261362
2019-11-01 People in contact 3.1263408
2019-12-01 People in contact 1.4832286
2020-01-01 People in contact 3.1319667
2020-02-01 People in contact 2.8097216
2020-03-01 People in contact -1.9997851
2020-04-01 People in contact 28.5904389
2020-05-01 People in contact 18.7738400
2020-06-01 People in contact 20.8661522
2020-07-01 People in contact 21.5277502
2020-08-01 People in contact 24.0538144
2020-09-01 People in contact 29.5590440
2020-10-01 People in contact 31.4433698
2020-11-01 People in contact 34.0523275
2020-12-01 People in contact 34.6509071
2021-01-01 People in contact 30.0085450
2021-02-01 People in contact 27.7020478
2021-03-01 People in contact 34.0620360
2021-04-01 People in contact 14.9506222
2021-05-01 People in contact 23.2804542
2021-06-01 People in contact 25.0120171
2021-07-01 People in contact 24.3705503
2021-08-01 People in contact 22.2683101
2021-09-01 People in contact 17.4986057
2021-10-01 People in contact 17.8922048
2021-11-01 People in contact 15.6771017
2021-12-01 People in contact 14.3636358

New referrals (<18)

Raw time series

#Data
CAMHS_data_cyp32a <- CAMHS_data %>%
  filter(.,MEASURE_ID=="MHS32a")
CAMHS_reldata_cyp32a <- CAMHS_yearly_changes %>%
  filter(.,MEASURE_ID=="MHS32a")

#Time series chart
CAMHS_raw_chart_cyp32a <- CAMHS_data_cyp32a %>% 
  ggplot(., aes(x=start_date, y=MEASURE_VALUE, group= MEASURE_KEY)) +
  geom_line(aes(color= MEASURE_KEY),
            size=1) +
  scale_x_date(date_labels = "%b %Y",date_breaks = "3 months") +
  scale_y_continuous(labels = scales::comma) +
  facet_wrap(~timing, scales = "free_x") +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="") +
  scale_color_brewer(palette = "Set1") +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))
  
ggplotly(CAMHS_raw_chart_cyp32a)
#Underlying data
CAMHS_data_cyp32a %>%
  select(.,start_date,MEASURE_KEY,MEASURE_VALUE) %>%
  arrange(.,start_date) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
start_date MEASURE_KEY MEASURE_VALUE
2019-04-01 New referrals (<18) 64,095
2019-05-01 New referrals (<18) 71,119
2019-06-01 New referrals (<18) 67,449
2019-07-01 New referrals (<18) 71,743
2019-08-01 New referrals (<18) 46,403
2019-09-01 New referrals (<18) 64,284
2019-10-01 New referrals (<18) 83,290
2019-11-01 New referrals (<18) 79,100
2019-12-01 New referrals (<18) 65,547
2020-01-01 New referrals (<18) 84,624
2020-02-01 New referrals (<18) 80,555
2020-03-01 New referrals (<18) 72,532
2020-04-01 New referrals (<18) 41,411
2020-05-01 New referrals (<18) 46,262
2020-06-01 New referrals (<18) 60,370
2020-07-01 New referrals (<18) 67,967
2020-08-01 New referrals (<18) 51,357
2020-09-01 New referrals (<18) 75,222
2020-10-01 New referrals (<18) 88,523
2020-11-01 New referrals (<18) 92,228
2020-12-01 New referrals (<18) 75,841
2021-01-01 New referrals (<18) 68,149
2021-02-01 New referrals (<18) 70,169
2021-03-01 New referrals (<18) 98,112
2021-04-01 New referrals (<18) 85,598
2021-05-01 New referrals (<18) 101,421
2021-06-01 New referrals (<18) 98,037
2021-07-01 New referrals (<18) 85,801
2021-08-01 New referrals (<18) 57,289
2021-09-01 New referrals (<18) 84,264
2021-10-01 New referrals (<18) 89,264
2021-11-01 New referrals (<18) 103,865
2021-12-01 New referrals (<18) 82,908

Monthly average, per year

#Average per calendar year
CAMHS_data_cyp32a %>%
  mutate(.,year=lubridate::year(start_date)) %>% 
  group_by(MEASURE_ID,MEASURE_KEY,year) %>%
  summarise(average=mean(MEASURE_VALUE,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==12) %>%
  knitr::kable(., align = "lccrr")
MEASURE_ID MEASURE_KEY year average months_included
MHS32a New referrals (<18) 2020 69741.00 12
MHS32a New referrals (<18) 2021 85406.42 12

Monthly average, per year (Apr to Dec)

#Average per calendar year
CAMHS_data_cyp32a %>%
  mutate(.,year=lubridate::year(start_date)) %>%
  filter(.,month_num>=4&month_num<=12) %>%
  group_by(MEASURE_ID,MEASURE_KEY,year) %>%
  summarise(average=mean(MEASURE_VALUE,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==9) %>%
  knitr::kable(., align = "lccrr")
MEASURE_ID MEASURE_KEY year average months_included
MHS32a New referrals (<18) 2019 68114.44 9
MHS32a New referrals (<18) 2020 66575.67 9
MHS32a New referrals (<18) 2021 87605.22 9

Relative changes compared to last year

#Relative changes chart
CAMHS_changes_chart_cyp32a <- CAMHS_reldata_cyp32a %>%
  ggplot(., aes(x=start_date, y=pct_change_l1, group= MEASURE_KEY)) +
  facet_wrap(~timing, scales = "free_x") +
  geom_line(aes(color= MEASURE_KEY),size=1) +
  geom_hline(yintercept=0, linetype="dashed", color = "red") +
  scale_x_date(date_labels = "%b %Y",date_breaks = "1 month") +
  theme_ipsum() +
  xlab("") +
  ylab("% change") +
  labs(col="") +
  scale_color_manual(values=c("Open referrals" = "aquamarine4",
                              "People in contact" = "tomato3",
                              "First contacts (<18)" = "olivedrab4",
                              "Attended contacts (<18)" = "violetred",
                              "New referrals (<18)" = "magenta1")) +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))

ggplotly(CAMHS_changes_chart_cyp32a)
#Underlying data
CAMHS_reldata_cyp32a %>%
  select(.,start_date,MEASURE_KEY,pct_change_l1) %>%
  arrange(.,start_date) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
start_date MEASURE_KEY pct_change_l1
2020-04-01 New referrals (<18) -35.3912162
2020-05-01 New referrals (<18) -34.9512788
2020-06-01 New referrals (<18) -10.4953372
2020-07-01 New referrals (<18) -5.2632313
2020-08-01 New referrals (<18) 10.6760339
2020-09-01 New referrals (<18) 17.0151204
2020-10-01 New referrals (<18) 6.2828671
2020-11-01 New referrals (<18) 16.5967130
2020-12-01 New referrals (<18) 15.7047615
2021-01-01 New referrals (<18) -19.4684723
2021-02-01 New referrals (<18) -12.8930544
2021-03-01 New referrals (<18) 35.2671924
2021-04-01 New referrals (<18) 106.7035329
2021-05-01 New referrals (<18) 119.2317669
2021-06-01 New referrals (<18) 62.3935730
2021-07-01 New referrals (<18) 26.2392043
2021-08-01 New referrals (<18) 11.5505189
2021-09-01 New referrals (<18) 12.0204196
2021-10-01 New referrals (<18) 0.8370706
2021-11-01 New referrals (<18) 12.6176432
2021-12-01 New referrals (<18) 9.3181788

New referrals to CYPMHS

Raw time series

#Data
CAMHS_data_cyp32 <- CAMHS_data %>%
  filter(.,MEASURE_ID=="CYP32")

#Time series chart
CAMHS_raw_chart_cyp32 <- CAMHS_data_cyp32 %>% 
  ggplot(., aes(x=start_date, y=MEASURE_VALUE, group= MEASURE_KEY)) +
  geom_line(aes(color= MEASURE_KEY),
            size=1) +
  scale_x_date(date_labels = "%b %Y",date_breaks = "3 months") +
  scale_y_continuous(labels = scales::comma) +
  facet_wrap(~timing, scales = "free_x") +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="") +
  scale_color_brewer(palette = "Set1") +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))

ggplotly(CAMHS_raw_chart_cyp32)
#Underlying data
CAMHS_data_cyp32 %>%
  select(.,start_date,MEASURE_KEY,MEASURE_VALUE) %>%
  arrange(.,start_date) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
start_date MEASURE_KEY MEASURE_VALUE
2019-04-01 New referrals to CYPMHS 31,720
2019-05-01 New referrals to CYPMHS 35,911
2019-06-01 New referrals to CYPMHS 33,440
2019-07-01 New referrals to CYPMHS 36,383
2019-08-01 New referrals to CYPMHS 22,183
2019-09-01 New referrals to CYPMHS 31,203
2019-10-01 New referrals to CYPMHS 39,751
2019-11-01 New referrals to CYPMHS 37,604
2019-12-01 New referrals to CYPMHS 31,260
2020-01-01 New referrals to CYPMHS 38,604
2020-02-01 New referrals to CYPMHS 37,432
2020-03-01 New referrals to CYPMHS 32,784
2020-04-01 New referrals to CYPMHS 21,296
2020-05-01 New referrals to CYPMHS 25,712
2020-06-01 New referrals to CYPMHS 36,178
2020-07-01 New referrals to CYPMHS 43,268
2020-08-01 New referrals to CYPMHS 29,954
2020-09-01 New referrals to CYPMHS 52,857
2020-10-01 New referrals to CYPMHS 62,692
2020-11-01 New referrals to CYPMHS 65,453
2020-12-01 New referrals to CYPMHS 53,876
2021-01-01 New referrals to CYPMHS 45,639
2021-02-01 New referrals to CYPMHS 47,222
2021-03-01 New referrals to CYPMHS 67,551
2021-04-01 New referrals to CYPMHS 58,124
2021-05-01 New referrals to CYPMHS 70,991
2021-06-01 New referrals to CYPMHS 66,813
2021-07-01 New referrals to CYPMHS 59,115
2021-08-01 New referrals to CYPMHS 35,097
2021-09-01 New referrals to CYPMHS 57,092
2021-10-01 New referrals to CYPMHS 62,115
2021-11-01 New referrals to CYPMHS 72,526
2021-12-01 New referrals to CYPMHS 59,055

Monthly average, per year

#Average per calendar year
CAMHS_data_cyp32 %>%
  mutate(.,year=lubridate::year(start_date)) %>% 
  group_by(MEASURE_ID,MEASURE_KEY,year) %>%
  summarise(average=mean(MEASURE_VALUE,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==12) %>%
  knitr::kable(., align = "lccrr")
MEASURE_ID MEASURE_KEY year average months_included
CYP32 New referrals to CYPMHS 2020 41675.5 12
CYP32 New referrals to CYPMHS 2021 58445.0 12

Monthly average, per year (Apr to Dec)

#Average per calendar year
CAMHS_data_cyp32 %>%
  mutate(.,year=lubridate::year(start_date)) %>%
  filter(.,month_num>=4&month_num<=12) %>%
  group_by(MEASURE_ID,MEASURE_KEY,year) %>%
  summarise(average=mean(MEASURE_VALUE,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==9) %>%
  knitr::kable(., align = "lccrr")
MEASURE_ID MEASURE_KEY year average months_included
CYP32 New referrals to CYPMHS 2019 33272.78 9
CYP32 New referrals to CYPMHS 2020 43476.22 9
CYP32 New referrals to CYPMHS 2021 60103.11 9

First contacts (<18)

Raw time series

#Data
CAMHS_data_cyp61a <- CAMHS_data %>%
  filter(.,MEASURE_ID=="MHS61a")
CAMHS_reldata_cyp61a <- CAMHS_yearly_changes %>%
  filter(.,MEASURE_ID=="MHS61a")

#Time series chart
CAMHS_raw_chart_cyp61a <- CAMHS_data_cyp61a %>% 
  ggplot(., aes(x=start_date, y=MEASURE_VALUE, group= MEASURE_KEY)) +
  geom_line(aes(color= MEASURE_KEY),
            size=1) +
  scale_x_date(date_labels = "%b %Y",date_breaks = "3 months") +
  scale_y_continuous(labels = scales::comma) +
  facet_wrap(~timing, scales = "free_x") +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="") +
  scale_color_brewer(palette = "Set1") +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))
  
ggplotly(CAMHS_raw_chart_cyp61a)
#Underlying data
CAMHS_data_cyp61a %>%
  select(.,start_date,MEASURE_KEY,MEASURE_VALUE) %>%
  arrange(.,start_date) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
start_date MEASURE_KEY MEASURE_VALUE
2019-04-01 First contacts (<18) 51,694
2019-05-01 First contacts (<18) 49,335
2019-06-01 First contacts (<18) 47,035
2019-07-01 First contacts (<18) 48,293
2019-08-01 First contacts (<18) 36,352
2019-09-01 First contacts (<18) 45,982
2019-10-01 First contacts (<18) 54,568
2019-11-01 First contacts (<18) 54,309
2019-12-01 First contacts (<18) 41,945
2020-01-01 First contacts (<18) 56,823
2020-02-01 First contacts (<18) 52,305
2020-03-01 First contacts (<18) 51,555
2020-04-01 First contacts (<18) 43,246
2020-05-01 First contacts (<18) 38,816
2020-06-01 First contacts (<18) 46,559
2020-07-01 First contacts (<18) 47,685
2020-08-01 First contacts (<18) 39,035
2020-09-01 First contacts (<18) 49,839
2020-10-01 First contacts (<18) 56,951
2020-11-01 First contacts (<18) 60,651
2020-12-01 First contacts (<18) 49,468
2021-01-01 First contacts (<18) 50,832
2021-02-01 First contacts (<18) 48,337
2021-03-01 First contacts (<18) 59,245
2021-04-01 First contacts (<18) 57,734
2021-05-01 First contacts (<18) 62,337
2021-06-01 First contacts (<18) 63,397
2021-07-01 First contacts (<18) 55,473
2021-08-01 First contacts (<18) 43,083
2021-09-01 First contacts (<18) 56,285
2021-10-01 First contacts (<18) 59,256
2021-11-01 First contacts (<18) 64,298
2021-12-01 First contacts (<18) 51,273

Monthly average, per year

#Average per calendar year
CAMHS_data_cyp61a %>%
  mutate(.,year=lubridate::year(start_date)) %>% 
  group_by(MEASURE_ID,MEASURE_KEY,year) %>%
  summarise(average=mean(MEASURE_VALUE,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==12) %>%
  knitr::kable(., align = "lccrr")
MEASURE_ID MEASURE_KEY year average months_included
MHS61a First contacts (<18) 2020 49411.08 12
MHS61a First contacts (<18) 2021 55962.50 12

Monthly average, per year (Jan to Sep)

#Average per calendar year
CAMHS_data_cyp61a %>%
  mutate(.,year=lubridate::year(start_date)) %>%
  filter(.,month_num>=1&month_num<=9) %>%
  group_by(MEASURE_ID,MEASURE_KEY,year) %>%
  summarise(average=mean(MEASURE_VALUE,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==9) %>%
  knitr::kable(., align = "lccrr")
MEASURE_ID MEASURE_KEY year average months_included
MHS61a First contacts (<18) 2020 47318.11 9
MHS61a First contacts (<18) 2021 55191.44 9

Relative changes compared to last year

#Relative changes chart
CAMHS_changes_chart_cyp61a <- CAMHS_reldata_cyp61a %>%
  ggplot(., aes(x=start_date, y=pct_change_l1, group= MEASURE_KEY)) +
  facet_wrap(~timing, scales = "free_x") +
  geom_line(aes(color= MEASURE_KEY),size=1) +
  geom_hline(yintercept=0, linetype="dashed", color = "red") +
  scale_x_date(date_labels = "%b %Y",date_breaks = "1 month") +
  theme_ipsum() +
  xlab("") +
  ylab("% change") +
  labs(col="") +
  scale_color_manual(values=c("Open referrals" = "aquamarine4",
                              "People in contact" = "tomato3",
                              "First contacts (<18)" = "olivedrab4",
                              "Attended contacts (<18)" = "violetred",
                              "New referrals (<18)" = "magenta1")) +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))

ggplotly(CAMHS_changes_chart_cyp61a)
#Underlying data
CAMHS_reldata_cyp61a %>%
  select(.,start_date,MEASURE_KEY,pct_change_l1) %>%
  arrange(.,start_date) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
start_date MEASURE_KEY pct_change_l1
2020-04-01 First contacts (<18) -16.342322
2020-05-01 First contacts (<18) -21.321577
2020-06-01 First contacts (<18) -1.012012
2020-07-01 First contacts (<18) -1.258982
2020-08-01 First contacts (<18) 7.380612
2020-09-01 First contacts (<18) 8.388065
2020-10-01 First contacts (<18) 4.367028
2020-11-01 First contacts (<18) 11.677623
2020-12-01 First contacts (<18) 17.935392
2021-01-01 First contacts (<18) -10.543266
2021-02-01 First contacts (<18) -7.586273
2021-03-01 First contacts (<18) 14.916109
2021-04-01 First contacts (<18) 33.501364
2021-05-01 First contacts (<18) 60.596146
2021-06-01 First contacts (<18) 36.164866
2021-07-01 First contacts (<18) 16.332180
2021-08-01 First contacts (<18) 10.370181
2021-09-01 First contacts (<18) 12.933646
2021-10-01 First contacts (<18) 4.047339
2021-11-01 First contacts (<18) 6.013091
2021-12-01 First contacts (<18) 3.648824

Attended contacts (<18)

Raw time series

#Data
CAMHS_data_cyp30d <- CAMHS_data %>%
  filter(.,MEASURE_ID=="MHS30d")
CAMHS_reldata_cyp30d <- CAMHS_yearly_changes %>%
  filter(.,MEASURE_ID=="MHS30d")

#Time series chart
CAMHS_raw_chart_cyp30d <- CAMHS_data_cyp30d %>% 
  ggplot(., aes(x=start_date, y=MEASURE_VALUE, group= MEASURE_KEY)) +
  geom_line(aes(color= MEASURE_KEY),
            size=1) +
  scale_x_date(date_labels = "%b %Y",date_breaks = "3 months") +
  scale_y_continuous(labels = scales::comma) +
  facet_wrap(~timing, scales = "free_x") +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="") +
  scale_color_brewer(palette = "Set1") +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))
  
ggplotly(CAMHS_raw_chart_cyp30d)
#Underlying data
CAMHS_data_cyp30d %>%
  select(.,start_date,MEASURE_KEY,MEASURE_VALUE) %>%
  arrange(.,start_date) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
start_date MEASURE_KEY MEASURE_VALUE
2019-04-01 Attended contacts (<18) 307,328
2019-05-01 Attended contacts (<18) 346,997
2019-06-01 Attended contacts (<18) 337,476
2019-07-01 Attended contacts (<18) 363,594
2019-08-01 Attended contacts (<18) 274,323
2019-09-01 Attended contacts (<18) 335,775
2019-10-01 Attended contacts (<18) 388,130
2019-11-01 Attended contacts (<18) 383,387
2019-12-01 Attended contacts (<18) 305,574
2020-01-01 Attended contacts (<18) 402,520
2020-02-01 Attended contacts (<18) 361,178
2020-03-01 Attended contacts (<18) 384,011
2020-04-01 Attended contacts (<18) 365,212
2020-05-01 Attended contacts (<18) 360,525
2020-06-01 Attended contacts (<18) 424,827
2020-07-01 Attended contacts (<18) 425,810
2020-08-01 Attended contacts (<18) 336,675
2020-09-01 Attended contacts (<18) 419,474
2020-10-01 Attended contacts (<18) 435,613
2020-11-01 Attended contacts (<18) 473,103
2020-12-01 Attended contacts (<18) 397,443
2021-01-01 Attended contacts (<18) 426,820
2021-02-01 Attended contacts (<18) 412,003
2021-03-01 Attended contacts (<18) 488,234
2021-04-01 Attended contacts (<18) 437,736
2021-05-01 Attended contacts (<18) 463,893
2021-06-01 Attended contacts (<18) 469,830
2021-07-01 Attended contacts (<18) 443,801
2021-08-01 Attended contacts (<18) 350,766
2021-09-01 Attended contacts (<18) 437,555
2021-10-01 Attended contacts (<18) 419,382
2021-11-01 Attended contacts (<18) 479,458
2021-12-01 Attended contacts (<18) 382,887

Monthly average, per year

#Average per calendar year
CAMHS_data_cyp30d %>%
  mutate(.,year=lubridate::year(start_date)) %>% 
  group_by(MEASURE_ID,MEASURE_KEY,year) %>%
  summarise(average=mean(MEASURE_VALUE,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==12) %>%
  knitr::kable(., align = "lccrr")
MEASURE_ID MEASURE_KEY year average months_included
MHS30d Attended contacts (<18) 2020 398865.9 12
MHS30d Attended contacts (<18) 2021 434363.8 12

Monthly average, per year (Jan to Sep)

#Average per calendar year
CAMHS_data_cyp30d %>%
  mutate(.,year=lubridate::year(start_date)) %>% 
  filter(.,month_num>=1&month_num<=9) %>%
  group_by(MEASURE_ID,MEASURE_KEY,year) %>%
  summarise(average=mean(MEASURE_VALUE,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==9) %>%
  knitr::kable(., align = "lccrr")
MEASURE_ID MEASURE_KEY year average months_included
MHS30d Attended contacts (<18) 2020 386692.4 9
MHS30d Attended contacts (<18) 2021 436737.6 9

Relative changes compared to last year

#Relative changes chart
CAMHS_changes_chart_cyp30d <- CAMHS_reldata_cyp30d %>%
  ggplot(., aes(x=start_date, y=pct_change_l1, group= MEASURE_KEY)) +
  facet_wrap(~timing, scales = "free_x") +
  geom_line(aes(color= MEASURE_KEY),size=1) +
  geom_hline(yintercept=0, linetype="dashed", color = "red") +
  scale_x_date(date_labels = "%b %Y",date_breaks = "1 month") +
  theme_ipsum() +
  xlab("") +
  ylab("% change") +
  labs(col="") +
  scale_color_manual(values=c("Open referrals" = "aquamarine4",
                              "People in contact" = "tomato3",
                              "First contacts (<18)" = "olivedrab4",
                              "Attended contacts (<18)" = "violetred",
                              "New referrals (<18)" = "magenta1")) +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))

ggplotly(CAMHS_changes_chart_cyp30d)
#Underlying data
CAMHS_reldata_cyp30d %>%
  select(.,start_date,MEASURE_KEY,pct_change_l1) %>%
  arrange(.,start_date) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
start_date MEASURE_KEY pct_change_l1
2020-04-01 Attended contacts (<18) 18.834600
2020-05-01 Attended contacts (<18) 3.898593
2020-06-01 Attended contacts (<18) 25.883618
2020-07-01 Attended contacts (<18) 17.111393
2020-08-01 Attended contacts (<18) 22.729410
2020-09-01 Attended contacts (<18) 24.927109
2020-10-01 Attended contacts (<18) 12.233788
2020-11-01 Attended contacts (<18) 23.400898
2020-12-01 Attended contacts (<18) 30.064403
2021-01-01 Attended contacts (<18) 6.036967
2021-02-01 Attended contacts (<18) 14.072009
2021-03-01 Attended contacts (<18) 27.140629
2021-04-01 Attended contacts (<18) 19.858055
2021-05-01 Attended contacts (<18) 28.671521
2021-06-01 Attended contacts (<18) 10.593253
2021-07-01 Attended contacts (<18) 4.225124
2021-08-01 Attended contacts (<18) 4.185342
2021-09-01 Attended contacts (<18) 4.310398
2021-10-01 Attended contacts (<18) -3.726014
2021-11-01 Attended contacts (<18) 1.343259
2021-12-01 Attended contacts (<18) -3.662412

Open referrals

Raw time series

#Data
CAMHS_data_cyp23 <- CAMHS_data %>%
  filter(.,MEASURE_ID=="CYP23")
CAMHS_reldata_cyp23 <- CAMHS_yearly_changes %>%
  filter(.,MEASURE_ID=="CYP23")

#Time series chart
CAMHS_raw_chart_cyp23 <- CAMHS_data_cyp23 %>% 
  ggplot(., aes(x=start_date, y=MEASURE_VALUE, group= MEASURE_KEY)) +
  geom_line(aes(color= MEASURE_KEY),
            size=1) +
  scale_x_date(date_labels = "%b %Y",date_breaks = "3 months") +
  scale_y_continuous(labels = scales::comma) +
  facet_wrap(~timing, scales = "free_x") +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="") +
  scale_color_brewer(palette = "Set1") +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))
  
ggplotly(CAMHS_raw_chart_cyp23)
#Underlying data
CAMHS_data_cyp23 %>%
  select(.,start_date,MEASURE_KEY,MEASURE_VALUE) %>%
  arrange(.,start_date) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
start_date MEASURE_KEY MEASURE_VALUE
2018-05-01 Open referrals 247,499
2018-06-01 Open referrals 251,573
2018-07-01 Open referrals 243,916
2018-08-01 Open referrals 238,803
2018-09-01 Open referrals 245,003
2018-10-01 Open referrals 255,855
2018-11-01 Open referrals 252,726
2018-12-01 Open referrals 256,644
2019-01-01 Open referrals 258,525
2019-02-01 Open referrals 264,305
2019-03-01 Open referrals 272,605
2019-04-01 Open referrals 248,038
2019-05-01 Open referrals 260,485
2019-06-01 Open referrals 255,950
2019-07-01 Open referrals 257,152
2019-08-01 Open referrals 248,313
2019-09-01 Open referrals 251,483
2019-10-01 Open referrals 256,252
2019-11-01 Open referrals 262,299
2019-12-01 Open referrals 261,939
2020-01-01 Open referrals 268,184
2020-02-01 Open referrals 272,482
2020-03-01 Open referrals 267,871
2020-04-01 Open referrals 307,837
2020-05-01 Open referrals 302,241
2020-06-01 Open referrals 301,012
2020-07-01 Open referrals 304,491
2020-08-01 Open referrals 300,469
2020-09-01 Open referrals 318,375
2020-10-01 Open referrals 329,392
2020-11-01 Open referrals 344,178
2020-12-01 Open referrals 345,569
2021-01-01 Open referrals 340,421
2021-02-01 Open referrals 340,218
2021-03-01 Open referrals 352,551
2021-04-01 Open referrals 358,282
2021-05-01 Open referrals 374,401
2021-06-01 Open referrals 379,079
2021-07-01 Open referrals 380,738
2021-08-01 Open referrals 368,610
2021-09-01 Open referrals 374,946
2021-10-01 Open referrals 388,237
2021-11-01 Open referrals 397,857
2021-12-01 Open referrals 397,147

Monthly average, per year

#Average per calendar year
CAMHS_data_cyp23 %>%
  mutate(.,year=lubridate::year(start_date)) %>% 
  group_by(MEASURE_ID,MEASURE_KEY,year) %>%
  summarise(average=mean(MEASURE_VALUE,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==12) %>%
  knitr::kable(., align = "lccrr")
MEASURE_ID MEASURE_KEY year average months_included
CYP23 Open referrals 2019 258112.2 12
CYP23 Open referrals 2020 305175.1 12
CYP23 Open referrals 2021 371040.6 12

Monthly average, per year (Jan to Sep)

#Average per calendar year
CAMHS_data_cyp23 %>%
  mutate(.,year=lubridate::year(start_date)) %>%
  filter(.,month_num>=1&month_num<=9) %>%
  group_by(MEASURE_ID,MEASURE_KEY,year) %>%
  summarise(average=mean(MEASURE_VALUE,na.rm = TRUE),
            months_included= n()) %>% 
  ungroup() %>%
  filter(.,months_included==9) %>%
  knitr::kable(., align = "lccrr")
MEASURE_ID MEASURE_KEY year average months_included
CYP23 Open referrals 2019 257428.4 9
CYP23 Open referrals 2020 293662.4 9
CYP23 Open referrals 2021 363249.6 9

Relative changes compared to last year

#Relative changes chart
CAMHS_changes_chart_cyp23 <- CAMHS_reldata_cyp23 %>%
  ggplot(., aes(x=start_date, y=pct_change_l1, group= MEASURE_KEY)) +
  facet_wrap(~timing, scales = "free_x") +
  geom_line(aes(color= MEASURE_KEY),size=1) +
  geom_hline(yintercept=0, linetype="dashed", color = "red") +
  scale_x_date(date_labels = "%b %Y",date_breaks = "1 month") +
  theme_ipsum() +
  xlab("") +
  ylab("% change") +
  labs(col="") +
  scale_color_manual(values=c("Open referrals" = "aquamarine4",
                              "People in contact" = "tomato3",
                              "First contacts (<18)" = "olivedrab4",
                              "Attended contacts (<18)" = "violetred",
                              "New referrals (<18)" = "magenta1")) +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))

ggplotly(CAMHS_changes_chart_cyp23)
#Underlying data
CAMHS_reldata_cyp23 %>%
  select(.,start_date,MEASURE_KEY,pct_change_l1) %>%
  arrange(.,start_date) %>% 
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
start_date MEASURE_KEY pct_change_l1
2019-05-01 Open referrals 5.246890
2019-06-01 Open referrals 1.739853
2019-07-01 Open referrals 5.426458
2019-08-01 Open referrals 3.982362
2019-09-01 Open referrals 2.644866
2019-10-01 Open referrals 0.155166
2019-11-01 Open referrals 3.787897
2019-12-01 Open referrals 2.063169
2020-01-01 Open referrals 3.736196
2020-02-01 Open referrals 3.093774
2020-03-01 Open referrals -1.736579
2020-04-01 Open referrals 24.108806
2020-05-01 Open referrals 16.030098
2020-06-01 Open referrals 17.605782
2020-07-01 Open referrals 18.408957
2020-08-01 Open referrals 21.004136
2020-09-01 Open referrals 26.599015
2020-10-01 Open referrals 28.542216
2020-11-01 Open referrals 31.215902
2020-12-01 Open referrals 31.927281
2021-01-01 Open referrals 26.935611
2021-02-01 Open referrals 24.858890
2021-03-01 Open referrals 31.612231
2021-04-01 Open referrals 16.386919
2021-05-01 Open referrals 23.874987
2021-06-01 Open referrals 25.934846
2021-07-01 Open referrals 25.040806
2021-08-01 Open referrals 22.678213
2021-09-01 Open referrals 17.768669
2021-10-01 Open referrals 17.864733
2021-11-01 Open referrals 15.596290
2021-12-01 Open referrals 14.925529

People with eating disorders being seen within target times (<18)

#Eating disorders data
target_time_ed_data_new <- MHSDS_main_pooled_dashboard %>%
  filter(.,PRIMARY_LEVEL_DESCRIPTION=="England",
         MEASURE_ID %in% c("ED86e","ED87e")) %>%
  select(.,start_date,end_date,PRIMARY_LEVEL_DESCRIPTION,MEASURE_ID,MEASURE_VALUE)

target_time_ed_data <- MHSDS_ED_pooled_dashboard %>%
  filter(.,PRIMARY_LEVEL_DESCRIPTION=="England",
         MEASURE_ID %in% c("ED86e","ED87e")) %>%
  select(.,start_date,end_date,PRIMARY_LEVEL_DESCRIPTION,MEASURE_ID,MEASURE_VALUE) %>%
  plyr::rbind.fill(.,target_time_ed_data_new) %>% 
  mutate(.,MEASURE_VALUE=as.numeric(MEASURE_VALUE),
         Type=case_when(MEASURE_ID=="ED86e" ~ "Urgent",
                        MEASURE_ID=="ED87e" ~ "Routine",
                        TRUE ~ "NA"),
         Metric="Starting within target time",
         time_window=ymd(end_date)-ymd(start_date))

#Eating disorders chart
target_time_ed_chart <- target_time_ed_data %>%
  ggplot(., aes(x=end_date, y=MEASURE_VALUE, group=Type)) +
  geom_line(aes(color=Type),size=1) +
  scale_x_date(date_labels = "%b %Y",date_breaks = "1 month") +
  scale_y_continuous(labels = scales::comma) +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="", title="") +
  scale_colour_manual(values=
                        c("Urgent" = "brown", "Routine" = "darkseagreen4")) +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))

ggplotly(target_time_ed_chart)
target_time_ed_data %>%
  arrange(.,end_date) %>% 
  select(.,MEASURE_ID,Type,start_date,end_date,time_window,MEASURE_VALUE) %>%
  filter(.,start_date %in% ymd(c("2021-01-01","2021-04-01","2021-07-01","2021-10-01"))) %>%
  group_by(MEASURE_ID,Type) %>%
  summarise(.,MEASURE_VALUE=mean(MEASURE_VALUE)) %>% 
  ungroup() %>%
  knitr::kable(., align = "lccrr",format.args = list(big.mark = ","))
MEASURE_ID Type MEASURE_VALUE
ED86e Urgent 39.05812
ED87e Routine 48.96245

New referrals into eating disorder services (<18)

#Eating disorders data
ref_ed_data_new <- MHSDS_main_pooled_dashboard %>%
  filter(.,PRIMARY_LEVEL_DESCRIPTION=="England",
         MEASURE_ID %in% c("ED89","ED90")) %>%
  select(.,start_date,end_date,PRIMARY_LEVEL_DESCRIPTION,MEASURE_ID,MEASURE_VALUE)

ref_ed_data_new <- MHSDS_ED_pooled_dashboard %>%
  filter(.,PRIMARY_LEVEL_DESCRIPTION=="England",
         MEASURE_ID %in% c("ED89","ED90")) %>%
  select(.,start_date,end_date,PRIMARY_LEVEL_DESCRIPTION,MEASURE_ID,MEASURE_VALUE) %>%
  plyr::rbind.fill(.,ref_ed_data_new) %>% 
  mutate(.,MEASURE_VALUE=as.numeric(MEASURE_VALUE),
         Type=case_when(MEASURE_ID=="ED89" ~ "Urgent",
                        MEASURE_ID=="ED90" ~ "Routine",
                        TRUE ~ "NA"),
         Metric="Waiting for treatment",
         time_window=ymd(end_date)-ymd(start_date))

#Eating disorders chart 2
ref_ed_chart <- ref_ed_data_new %>%
  ggplot(., aes(x=end_date, y=MEASURE_VALUE, group=Type)) +
  geom_line(aes(color=Type),size=1) +
  scale_x_date(date_labels = "%b %Y",date_breaks = "1 month") +
  scale_y_continuous(labels = scales::comma) +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="", title="") +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))

ggplotly(ref_ed_chart)
#Crisis referrals
crisis_referrals_data <- MHSDS_main_pooled_dashboard %>%
  filter(.,PRIMARY_LEVEL_DESCRIPTION=="England",
         MEASURE_ID %in% c("CCR70b","CCR71b")) %>%
  select(.,start_date,end_date,PRIMARY_LEVEL_DESCRIPTION,MEASURE_ID,MEASURE_VALUE) %>% 
  mutate(.,MEASURE_VALUE=as.numeric(MEASURE_VALUE),
         Type=case_when(MEASURE_ID=="CCR71b" ~ "Urgent",
                        MEASURE_ID=="CCR70b" ~ "Emergency",
                        TRUE ~ "NA"),
         Metric="New referrals",
         time_window=ymd(end_date)-ymd(start_date))

#Eating disorders chart 2
crisis_referrals_chart <- crisis_referrals_data %>%
  ggplot(., aes(x=end_date, y=MEASURE_VALUE, group=Type)) +
  geom_line(aes(color=Type),size=1) +
  scale_x_date(date_labels = "%b %Y",date_breaks = "1 month") +
  scale_y_continuous(labels = scales::comma) +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="", title="") +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm"),size = 8),
        axis.title.y = element_text(size = 8))

ggplotly(crisis_referrals_chart)
crisis_referrals_data_flourish <- crisis_referrals_data %>% 
  select(.,end_date,time_window,MEASURE_VALUE,Metric,Type) %>%
  pivot_wider(
    names_from = "Type",
    names_sep = ".",
    values_from = c(MEASURE_VALUE)
  ) %>%
  arrange(.,end_date)

#fwrite(crisis_referrals_data_flourish,paste0(onedrive_charts_data,"crisis_charts.csv"))
#ED referrals
ED_referrals_data <- MHSDS_main_pooled_dashboard %>%
  filter(.,PRIMARY_LEVEL_DESCRIPTION=="England",
         MEASURE_ID %in% c("ED32")) %>%
  select(.,start_date,end_date,PRIMARY_LEVEL_DESCRIPTION,MEASURE_ID,MEASURE_VALUE) %>% 
  mutate(.,MEASURE_VALUE=as.numeric(MEASURE_VALUE),
         Metric="New referrals",
         time_window=ymd(end_date)-ymd(start_date))

#Eating disorders chart 3
ED_referrals_chart <- ED_referrals_data %>%
  ggplot(., aes(x=end_date, y=MEASURE_VALUE)) +
  geom_line() +
  scale_x_date(date_labels = "%b %Y",date_breaks = "1 month") +
  scale_y_continuous(labels = scales::comma) +
  theme_ipsum() +
  xlab("") +
  ylab("") +
  labs(col="", title="") +
  theme(legend.position="bottom",
        panel.border = element_blank(),
        strip.text = element_text(size=8),
        text = element_text(size = 8),
        legend.title=element_text(size=8),
        legend.text=element_text(size=8),
        axis.text = element_text(size = 8),
        axis.text.y = element_text(size = 8),
        axis.text.x = element_text(angle = 45, hjust = 1,size = 8),
        axis.title.y = element_text(size = 8))

#ggplotly(ED_referrals_chart)

ED_referrals_data_flourish <- ED_referrals_data %>% 
  select(.,end_date,time_window,MEASURE_VALUE,Metric) %>%
  arrange(.,end_date)

#fwrite(ED_referrals_data_flourish,paste0(onedrive_charts_data,"EDref_charts.csv"))

Health Education England data on workforce (compared to activity levels from NHS England)

#NHS Digital on people in contact with CAMHS service
CAMHS_contacts <- MHSDS_main_pooled_dashboard %>%
  filter(.,PRIMARY_LEVEL_DESCRIPTION=="England",
         MEASURE_ID=="CYP01") %>%
  select(.,start_date,MEASURE_VALUE) %>%
  mutate(.,date_ymd=lubridate::ymd(start_date)) %>%
  mutate(.,date_ymd=floor_date(date_ymd, "month"),
         measure="People in contact CAMHS",
         MEASURE_VALUE=as.numeric(MEASURE_VALUE)) %>%
  select(.,-"start_date") %>%
  arrange(.,date_ymd)

#Turn into indexed data
CAMHS_contacts_index <- CAMHS_contacts %>%
  mutate(.,MEASURE_VALUE_MA=zoo::rollmean(MEASURE_VALUE,k=7,fill=NA)) %>% #Use a moving average to compute the mean
  mutate(.,Jan2019=filter(.,date_ymd=="2019-01-01")$MEASURE_VALUE_MA) %>%
  filter(.,date_ymd>=ymd("2019-01-01"),!is.na(MEASURE_VALUE_MA)) %>%
  mutate(.,index=MEASURE_VALUE_MA/Jan2019*100)

#HEE data (copied over from report)
HEE_staff_index <- data.frame(measure="CYP MH staff",
  date_ymd=as.Date(c("2019-01-01","2021-04-01")),
  MEASURE_VALUE=as.numeric(c("14857","20626"))) %>%
  mutate(.,Jan2019=filter(.,date_ymd=="2019-01-01")$MEASURE_VALUE) %>%
  mutate(.,index=MEASURE_VALUE/Jan2019*100)

#Append two sources together
CAMHS_and_HEE_staff <- plyr::rbind.fill(CAMHS_contacts_index,HEE_staff_index)

#Show data
CAMHS_and_HEE_staff %>%
  knitr::kable(., align = "lccrr")
MEASURE_VALUE date_ymd measure MEASURE_VALUE_MA Jan2019 index
229217 2019-01-01 People in contact CAMHS 228988.6 228988.6 100.00000
233831 2019-02-01 People in contact CAMHS 229359.7 228988.6 100.16208
241926 2019-03-01 People in contact CAMHS 229607.7 228988.6 100.27038
218678 2019-04-01 People in contact CAMHS 229460.3 228988.6 100.20600
230443 2019-05-01 People in contact CAMHS 227975.9 228988.6 99.55774
225480 2019-06-01 People in contact CAMHS 226204.0 228988.6 98.78397
226647 2019-07-01 People in contact CAMHS 223858.4 228988.6 97.75965
218826 2019-08-01 People in contact CAMHS 225581.4 228988.6 98.51209
221428 2019-09-01 People in contact CAMHS 225669.0 228988.6 98.55033
225507 2019-10-01 People in contact CAMHS 227228.4 228988.6 99.23134
230739 2019-11-01 People in contact CAMHS 229193.3 228988.6 100.08940
231056 2019-12-01 People in contact CAMHS 231802.1 228988.6 101.22870
236396 2020-01-01 People in contact CAMHS 240340.9 228988.6 104.95758
240401 2020-02-01 People in contact CAMHS 247226.4 228988.6 107.96453
237088 2020-03-01 People in contact CAMHS 253196.4 228988.6 110.57164
281199 2020-04-01 People in contact CAMHS 259536.9 228988.6 113.34053
273706 2020-05-01 People in contact CAMHS 264546.3 228988.6 115.52816
272529 2020-06-01 People in contact CAMHS 271186.1 228988.6 118.42781
275439 2020-07-01 People in contact CAMHS 279661.3 228988.6 122.12893
271462 2020-08-01 People in contact CAMHS 283677.3 228988.6 123.88273
286880 2020-09-01 People in contact CAMHS 289022.0 228988.6 126.21678
296414 2020-10-01 People in contact CAMHS 293994.3 228988.6 128.38819
309311 2020-11-01 People in contact CAMHS 298502.6 228988.6 130.35697
311119 2020-12-01 People in contact CAMHS 305128.7 228988.6 133.25063
307335 2021-01-01 People in contact CAMHS 310323.0 228988.6 135.51899
306997 2021-02-01 People in contact CAMHS 316181.9 228988.6 138.07757
317845 2021-03-01 People in contact CAMHS 320665.1 228988.6 140.03544
323240 2021-04-01 People in contact CAMHS 325157.4 228988.6 141.99723
337426 2021-05-01 People in contact CAMHS 328668.4 228988.6 143.53049
340694 2021-06-01 People in contact CAMHS 332966.0 228988.6 145.40726
342565 2021-07-01 People in contact CAMHS 337480.9 228988.6 147.37891
331912 2021-08-01 People in contact CAMHS 342418.3 228988.6 149.53510
337080 2021-09-01 People in contact CAMHS 345044.1 228988.6 150.68182
14857 2019-01-01 CYP MH staff NA 14857.0 100.00000
20626 2021-04-01 CYP MH staff NA 14857.0 138.83018

NHS England data on workforce (child and adolescent psychiatry only)

#NHS data
NHS_workforce_doctors %>%
  mutate(.,date_ymd=lubridate::ymd(Date)) %>%
  mutate(.,date_ymd=floor_date(date_ymd, "month"),
         measure="FTE doctors") %>%
  rename(.,MEASURE_VALUE=FTE) %>%
  filter(Specialty %in% c("Child and adolescent psychiatry")) %>%
  group_by(date_ymd,measure,Specialty) %>%
  summarise(MEASURE_VALUE=sum(MEASURE_VALUE,na.rm=TRUE)) %>% #Aggregate over categories
  ungroup() %>%
  filter(., date_ymd %in% c(ymd("2019-01-01"),ymd("2021-04-01"))) %>%
  pivot_wider(
    names_from = date_ymd,
    names_sep = ".",
    values_from = MEASURE_VALUE
  ) %>%
  mutate(.,pct_change=(`2021-04-01`-`2019-01-01`)/`2019-01-01`*100) %>%
  knitr::kable(., align = "lccrr")
measure Specialty 2019-01-01 2021-04-01 pct_change
FTE doctors Child and adolescent psychiatry 981.6823 1064.256 8.411452
#Latest data on consultants
NHS_workforce_doctors %>%
  mutate(.,date_ymd=lubridate::ymd(Date)) %>%
  mutate(.,date_ymd=floor_date(date_ymd, "month"),
         measure="FTE doctors") %>%
  rename(.,MEASURE_VALUE=FTE) %>%
  filter(., date_ymd %in% c(ymd("2021-05-01"))) %>%
  filter(Specialty %in% c("Child and adolescent psychiatry"))  %>%
  select(.,-"Date") %>% 
  knitr::kable(., align = "lccrr")
Grade Grade Order Code Specialty Group Specialty MEASURE_VALUE date_ymd measure
Consultant 1 Psychiatry group Child and adolescent psychiatry 626.5470 2021-05-01 FTE doctors
Associate Specialist 2 Psychiatry group Child and adolescent psychiatry 13.3725 2021-05-01 FTE doctors
Specialty Doctor 3 Psychiatry group Child and adolescent psychiatry 100.9210 2021-05-01 FTE doctors
Staff Grade 4 Psychiatry group Child and adolescent psychiatry 3.5000 2021-05-01 FTE doctors
Specialty Registrar 5 Psychiatry group Child and adolescent psychiatry 144.8688 2021-05-01 FTE doctors
Core Training 6 Psychiatry group Child and adolescent psychiatry 142.1062 2021-05-01 FTE doctors
Foundation Doctor Year 2 7 Psychiatry group Child and adolescent psychiatry 10.0000 2021-05-01 FTE doctors
Foundation Doctor Year 1 8 Psychiatry group Child and adolescent psychiatry 10.0000 2021-05-01 FTE doctors