Skip to content

Commit

Permalink
updating files to fix page deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
faaiz-25 authored Nov 9, 2023
1 parent 70a6509 commit 77573a4
Show file tree
Hide file tree
Showing 11 changed files with 7,598 additions and 61 deletions.
106 changes: 45 additions & 61 deletions 02-geomapping-ICS_22_23.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ library(st)


## Load 'curated' DSPT file
data <- read.csv("/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/DSPT_CCG_21_22_snapshot09_09_22.csv")
data <- data[-107,]
data <- read.csv("./data/DSPT Snapshots/22_23/ICB_dspt_snapshot_17_10_23.csv")

dsptlevels=c("21/22 Standards Exceeded","21/22 Standards Met","21/22 Approaching Standards","21/22 Standards Not Met","21/22 Not Published")
dsptlevels=c("22/23 Standards Exceeded","22/23 Standards Met","22/23 Approaching Standards","22/23 Standards Not Met","22/23 Not Published")

# Make Status a categorical
data$Short.Status = factor(data$Status,dsptlevels)
Expand All @@ -52,7 +51,7 @@ data$Short.Status = factor(data$Status,dsptlevels)

## Load STP shapefile
# Source: https://geoportal.statistics.gov.uk/datasets/clinical-commissioning-groups-april-2020-full-clipped-boundaries-en/explore?location=52.950000%2C-2.000000%2C7.02
stp_spdf <- read_sf("/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/Inputs/shapefile/STP_APR_2021_EN_BUC_V2.shp")
stp_spdf <- read_sf("./Inputs/shapefiles/22_23/ICB_APR_2023_EN_BSC.shp")

#proj4string(stp_spdf) <- CRS("+init=epsg:27700") # BNG projection system

Expand All @@ -62,23 +61,27 @@ stp_spdf <- stp_spdf %>% st_transform(CRS("+init=epsg:4326")) # reproject to lat

stp_data = stp_spdf
#############################################
# CCG shapefile
# CCG shapefile #CCGs will not be submitting for 22/23
#############################################

## Load CCG shapefile

ccg_spdf <- read_sf("/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/Inputs/shapefile/CCG_APR_2021_EN_BFC.shp")
#ccg_spdf <- read_sf("/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/Inputs/shapefile/CCG_APR_2021_EN_BFC.shp")

#proj4string(ccg_spdf) <- CRS("+init=epsg:27700") # BNG projection system

#ccg_spdf@proj4string # check system

ccg_spdf <- ccg_spdf %>% st_transform(CRS("+init=epsg:4326")) # reproject to latlong system
#ccg_spdf <- ccg_spdf %>% st_transform(CRS("+init=epsg:4326")) # reproject to latlong system

# Write to shapefile
#writeOGR(ccg_spdf, layer = 'myshp_simplified', 'C:/temp', driver="ESRI Shapefile")

region_spdf = read_sf('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/Inputs/shapefile/NHS_England_Regions_(April_2020)_Boundaries_EN_BUC.shp')
#############################################
# Load in Region data
#############################################

region_spdf = read_sf('./Inputs/shapefiles/22_23/NHSER_JUL_2022_EN_BUC.shp')
#proj4string(region_spdf) <- CRS("+init=epsg:27700") # BNG projection system

#region_spdf@proj4string # check system
Expand All @@ -104,13 +107,13 @@ region_full <- region_spdf
# Create a points shapefile for Trusts
##########+
##########+###################################
trusts_data = read.csv("/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/DSPT_trusts_21_22_snapshot09_09_22.csv")
trusts_data <- subset(trusts_data, !(ODS.Code %in% c('RBZ', 'RW6', 'RTV')))
trusts_data = read.csv("./data/DSPT Snapshots/22_23/dspt_trusts_snapshot_17_10_23.csv") %>% select(-c(Organisation.Name.x))
#trusts_data <- subset(trusts_data, !(ODS.Code %in% c('RBZ', 'RW6', 'RTV')))


trust_spdf_points <- sp::SpatialPointsDataFrame(
coords = trusts_data %>% select(longitude,latitude),
data = trusts_data %>% select(-c(longitude,latitude)),
coords = trusts_data %>% select(long,lat),
data = trusts_data %>% select(-c(long,lat)),
proj4string = CRS("+init=epsg:4326") # indicate it is is longitude latitude
)

Expand All @@ -121,27 +124,14 @@ trust_spdf_points <- sp::SpatialPointsDataFrame(
#Further prep
#############################################
# Join DSPT data and ONS code
lookupdata = read.csv('/Users/muhammad-faaiz.shanawas/Documents/Github/open-cyber/data/Clinical_Commissioning_Group_to_STPs_(April_2021)_Lookup_in_England.csv')
data_merged = left_join(data, lookupdata, by = c("ODS.Code" = "CCG21CDH"))
data_merged = data_merged[-107,]


#load in ccg-stp-region lookup data
regions_lookup = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/Clinical_Commissioning_Group_to_STP_and_NHS_England_(Region)_(April_2021)_Lookup_in_England.csv')
data_regions = unique(select(regions_lookup, 'STP21CD', 'STP21NM', 'NHSER21NM'))

# Join the reduced DSPT info with the CCG shapefile
ccg_spdf <- left_join(ccg_spdf,data_merged,by=c("CCG21CD"="CCG21CD"))
data_ccg_spdf <- ccg_spdf
lookupdata = read.csv('./data/aux/22_23/Sub_ICB_Locations_to_Integrated_Care_Boards_to_NHS_England_(Region)_(April_2023)_Lookup_in_England (1).csv')

data_merged = left_join(data, lookupdata %>% select(-c(ICB23CD, ICB23NM)), by = c("ICB23CDH" = "ICB23CDH"))
data_merged = data_merged %>% select(-c(X))

#merge and assign to stp_spdf data
stp_spdfdata = stp_spdf
stp_spdfdata = merge(stp_spdfdata, select(data_regions, 'STP21CD', 'NHSER21NM'), by = "STP21CD", all = TRUE)
#stp_spdfdata = na.omit(stp_spdfdata)
stp_spdf = stp_spdfdata

#jon the shapefile data with dspt data for ICBs

stp_spdf = left_join(stp_spdf, data_merged %>% select(-c(ICB23NM, Integrated.Care.Board..where.available..from.ODS.)), by = c('ICB23CD'))

# Make Status a categorical
#ccg_spdf@data$Short.Status = factor(ccg_spdf@data$Short.Status,dsptlevels)
Expand All @@ -157,18 +147,17 @@ catpal <- colorFactor(my_palette, dsptlevels,reverse=F,ordered=T)
## Plotting
# Prepare the text for tooltips:
mytext <- paste(
"<b>SUB-ICB 2022 code (ODS): </b>", ccg_spdf$ICB22CD, "<br/>",
"<b>SUB-ICB 2022 name: </b>", ccg_spdf$LOC22NM,"<br/>",
"<b>2021 STP name: </b>", ccg_spdf$STP21NM,"<br/>",
"<b>Region name: </b>", ccg_spdf$NHSER22NM,"<br/>",
"<b>DSPT Status: </b>", ccg_spdf$Short.Status, "<br/>",
"<b>ICB 2023 code (ODS): </b>", stp_spdf$ICB23CD, "<br/>",
"<b>ICB 2023 name: </b>", stp_spdf$ICB23NM,"<br/>",
"<b>Region name: </b>", stp_spdf$NHSER23NM,"<br/>",
"<b>DSPT Status: </b>", stp_spdf$Short.Status, "<br/>",
sep="") %>%
lapply(htmltools::HTML)

mytext_ics <- paste(
"<b>ICS/STP 2021 code: </b>", stp_spdf$STP21CD,"<br/>",
"<b>ICS/STP 2021 name: </b>", stp_spdf$STP21NM,"<br/>",
"<b>Region name: </b>", stp_spdf$NHSER21NM,"<br/>",

mytext_region <- paste(
"<b>Region 2023 code: </b>", region_spdf$NHSER22CD,"<br/>",
"<b>Region 2023 name: </b>", region_spdf$NHSER22NM,"<br/>",
sep="") %>%
lapply(htmltools::HTML)

Expand All @@ -178,7 +167,7 @@ mytext_ics <- paste(


# Final Map
m<-leaflet(ccg_spdf) %>%
m<-leaflet(stp_spdf) %>%
addTiles() %>%
setView( lat=53, lng=-2 , zoom=6) %>%
addPolygons(
Expand All @@ -194,21 +183,22 @@ m<-leaflet(ccg_spdf) %>%
direction = "auto"
)
) %>%
addLegend( pal=catpal, values=~Status, opacity=0.9, title = "21/22 DSPT Status (CCG)", position = "bottomleft" )
addLegend( pal=catpal, values=~Status, opacity=0.9, title = "22/23 ICB Status", position = "bottomleft" )

m



#############################################
# Mapping - CCGS + ICS layer
# Mapping - CCGS + ICS + trust layer
#############################################

# https://gis.stackexchange.com/questions/283658/add-layers-with-leaflet-from-different-spatial-data-frames-in-r
m02 <- leaflet() %>%
addTiles() %>%
setView( lat=53, lng=-2 , zoom=6) %>%
addPolygons(
data=ccg_spdf,
group = "CCG",
data=stp_spdf,
group = "ICB",
fillColor = ~catpal(Status),
stroke=TRUE,
fillOpacity = 0.7,
Expand All @@ -222,35 +212,29 @@ m02 <- leaflet() %>%
)
) %>%
addPolygons(
data=stp_spdf,
group="ICS boundary",
data=region_spdf,
group="Region boundary",
fillOpacity=0.1,
color='black',
weight=2,
label=mytext_ics
label=mytext_region
) %>%
#addLegend( data=ccg_spdf,pal=catpal, values=~Short.Status, opacity=0.9, title = "21/22 DSPT Status (CCG)", position = "bottomleft" ) %>%
leaflet::addLayersControl(
overlayGroups = c("CCG","ICS boundary"), # add these layers
overlayGroups = c("ICB","Region boundary"), # add these layers
options = layersControlOptions(collapsed = FALSE) # expand on hover?
) %>%
hideGroup(c("ICS boundary")) # turn these off by default



m02_l <- m02 %>% addLegend( data=ccg_spdf,pal=catpal, values=~Short.Status, opacity=0.9, title = "21/22 DSPT Status (CCG)", position = "bottomleft" )



#############################################
# Mapping - CCGS + ICS + trust layer
#############################################
m02_l <- m02 %>% addLegend( data=stp_spdf,pal=catpal, values=~Short.Status, opacity=0.9, title = "22/23 ICB DSPT Status", position = "bottomleft" )


get_popup_content <- function(my_spdf) {
paste0(
"<b>Provider </b>",
"<br><b>- Provider code</b>:", my_spdf$ODS.Code,
"<br><b>- Provider code</b>:", my_spdf$Code,
"<br><b>- Provider name:</b> ", my_spdf$ODS.Org.Name,
#"<br><b>- STP/ICS (HQ postcode-based):</b> ", my_spdf$STP20NM,
#"<br><b>- Region:</b> ", my_spdf$`NHSER20NM`,
Expand All @@ -261,7 +245,7 @@ get_popup_content <- function(my_spdf) {



m03 <- m02_l %>%
m03 <- m %>%
addCircleMarkers(data=trust_spdf_points,
group="Trusts",
label = ~ lapply(get_popup_content(trust_spdf_points), htmltools::HTML),
Expand All @@ -273,17 +257,17 @@ m03 <- m02_l %>%
#clusterOptions = markerClusterOptions(),
radius= 6)

#m03
m03

#adding the zoom toggle for trust level (trust layer appears between 9 and 20)
#m03 <- m03 %>%
# groupOptions("Trusts", zoomLevels = 9:20)

#adding legend and layering CCG trusts and ICG boundary together
m03 <- m03 %>%
addLegend( data=trust_spdf_points,pal=catpal, values=~Status, opacity=0.9, title = "21/22 DSPT Status (trust)", position = "bottomright" ) %>%
addLegend( data=trust_spdf_points,pal=catpal, values=~Status, opacity=0.9, title = "22/23 Trusts DSPT Status", position = "bottomright" ) %>%
leaflet::addLayersControl(
overlayGroups = c("ICS boundary","CCG","Trusts"), # add these layers
overlayGroups = c("ICS boundary","Trusts"), # add these layers
options = layersControlOptions(collapsed = FALSE) # expand on hover?
) %>%
hideGroup(c("ICS boundary","Trusts")) # turn these off by default
Expand Down
128 changes: 128 additions & 0 deletions 20_21.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>

# Open Statistics - Cyber Security
<!---
{% include update.html %}
<div class="nhsuk-warning-callout">
<h3 class="nhsuk-warning-callout__label">
Important<span class="nhsuk-u-visually-hidden">:</span>
</h3>
<p>This project is currently in development. For more information please contact <a
class="nhsuk-footer__list-item-link"
href="{{ site.github.owner_url }}"
>{{ site.github.owner_name }}</a>
</p>
</div>
-->

<div class="nhsuk-warning-callout">
<h3 class="nhsuk-warning-callout__label">
Important<span class="nhsuk-u-visually-hidden">:</span>
</h3>
<p>This project is currently in development. An overview of methodology and caveats are given below. For more information please contact <a href="mailto:analytics-unit@nhsx.nhs.uk">analytics-unit@nhsx.nhs.uk</a>. <br>Opinions expressed in this page are not representative of the views of NHS England and any content here should not be regarded as official output in any form. For more information about the NHS England Transformation Directorate please visit our <a href="https://www.nhsx.nhs.uk/">official website</a>.
</p>
</div>

The <b>Data Security and Protection Toolkit</b> is an online self-assessment tool that allows organisations to measure their performance against the National Data Guardian’s 10 data security standards.

All organisations that have access to NHS patient data and systems must use this toolkit to provide assurance that they are practising good data security and that personal information is handled correctly. This includes trusts, commissioners and CSUs.

The following information displays data taken from a specific snapshot of the DSPT data. The latest status information was downloaded on the <b>8th February 2022</b>.

For more information on the Data Security and Protection Toolkit, please visit the <a href="https://www.dsptoolkit.nhs.uk/">DSPT portal</a>.

<hr class="nhsuk-u-margin-top-0 nhsuk-u-margin-bottom-6">

## Notes on Methodology

<b>Composite Metrics for ICS</b>

The DSPT status for Clinical Commissioning Groups (CCGs) and Trusts are coded (scored) as follows to create the proxy for Integrated Care System (ICS) summary metrics:

<li>Status Exceeded = 3</li>
<li>Status Met = 1</li>
<li>Approaching Standards = -1</li>
<li>Not Published/Not Met = -3</li>
<br>
CCG scores within an ICS are then weighted based on the resident population.

Trust scores within an ICS are weighted either a) as simple average or b) based on their EPRR score.

Finally, for each ICS, the CCG and Trust scores are weighted equally to arrive at the ICS composite score.

The final scaling for each of the summary metrics displayed will have an upper bound of 3 and a lower bound of -3.

<!---
<b>Emergency Preparedness, Resilience and Response (EPRR) Score</b>
Organisations are ranked in a 4 tier system, to measure their impact of risk. This is used to calculate one of our summary metrics below. The Tier ranks are mapped as follows:
<li>Tier 1 - Major Trauma Centres/ Ambulance Trusts/ NHS Blood & Transplant = 4</li>
<li>Tier 2 - Trauma Units/ Specialist Hospitals = 3</li>
<li>Tier 3 - Geographically remote / High secure Mental Health = 2</li>
<li>Tier 4 - Community Hospitals = 1</li>
<br>
<b>Successor Organisations</b>
<br>
Organisations open 31st March 2021 are considered (the end of 20/21, the financial year of the last DSPT edition that closed).
Organisations without a published DSPT status as a result of a merger, inherit their DSPT status from it's successor organisation if published. Otherwise, the DSPT status will be mapped as 'Not Published'.
-->
## Summary of DSPT Compliance (2020/2021 edition).
<br>
Summary statistics from the DSPT 2020/21 toolkit are shown.

{% include data_DSPTmetric2022-02-08.html %}

<iframe src="./outputs/barchart_summary_FY2021_2022-02-28.html" height="600px" width="100%" style="border:none;"></iframe>

<hr class="nhsuk-u-margin-top-0 nhsuk-u-margin-bottom-6">


## CCGs and Trusts - Individual Compliance
<br>
The compliance of individual CCGs and Trusts are mapped below, with ICS boundaries. Toggle the boxes on the top right-hand side to add layers.

<iframe src="chloropleth_DSPT_CCG_Trusts.html" height="600px" width="100%" style="border:none;"></iframe>

<hr class="nhsuk-u-margin-top-0 nhsuk-u-margin-bottom-6">

<!---
## CCGs and Proportions of Trusts Compliance - Pie Charts Diameter by Population
<br>
The proportions of trust compliance within each ICS with boundaries (in black) are shown. The diameter of each pie chart relates to the population level within each ICS.
<iframe src="chloropleth_DSPT_PieCharts.html" height="600px" width="100%" style="border:none;"></iframe>
<hr class="nhsuk-u-margin-top-0 nhsuk-u-margin-bottom-6">
-->

## CCGs and Proportions of Trusts Compliance - Colour Coded Population
<br>
The proportions of trust compliance within each ICS with boundaries (in black) are shown. The ICSs are colored to represent the patient population level. The darker the shade of blue the higher the patient population level.

<iframe src="chloropleth_DSPT_PieCharts_population.html" height="600px" width="100%" style="border:none;"></iframe>

<hr class="nhsuk-u-margin-top-0 nhsuk-u-margin-bottom-6">


## ICSs Composite Compliance - CCG and Trust Score Average Weighted For Population
<br>
The compliance of individual ICSs, made up of a composite score of 50% CCG scores which have been weighted for population and 50% of a simple average of Trust scores. Region boundaries are displayed in blue.
<iframe src="chloropleth_DSPT_CCGp_Trusts.html" height="600px" width="100%" style="border:none;"></iframe>

<hr class="nhsuk-u-margin-top-0 nhsuk-u-margin-bottom-6">
<!---
## ICSs Composite Compliance - CCG and Trust Score Average Weighted For Population and EPRR
<br>
The compliance of individual ICSs, made up of a composite score of 50% CCG scores which have been weighted for population and 50% of average Trusts scores weighted for EPRR risk rating. Region boundaries are displayed in blue.
<iframe src="chloropleth_DSPT_CCGp_Trusts_EPRR.html" height="600px" width="100%" style="border:none;"></iframe>
-->
<hr class="nhsuk-u-margin-top-0 nhsuk-u-margin-bottom-6">

<br>
Template for end-to-end open source analytics: [github.io](https://pages.github.com/), and [github actions](https://github.com/features/actions).

Analytics leverages open source data and R libraries such as [leaflet](https://cran.r-project.org/web/packages/leaflet/index.html) for interactive maps, [plotly](https://plotly.com/r/) for other interactive visualisations and [summarytools](https://cran.r-project.org/web/packages/summarytools/vignettes/introduction.html) for descriptive statistics.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# open-analytics-template
[NHS.UK](https://service-manual.nhs.uk/) themed template for open analytics projects. Build your own open source end-to-end analytical tool using python, plotly, github.io, and github actions.

Example page deployed here: [[GitHub.io](https://nhsx.github.io/open-analytics-template/)]

Used in the following projects:
- [Open Source Healthcare Statistics](https://nhsx.github.io/open-health-statistics/) [[GitHub](https://github.com/nhsx/open-health-statistics)]
- [NHSX Publications from PubMed API](nhsx.github.io/nhsx-publications) [[GitHub](https://github.com/nhsx/nhsx-publications)] (in development)
- [Digital Health Insights](https://nhsx.github.io/digital-health-insights/) [[GitHub](https://github.com/nhsx/digital-health-insights)] (in development)
- [The Prescribing Cost of Antibiotics](https://mattia-ficarelli.github.io/antibiotic_cost/) [[GitHub](https://github.com/mattia-ficarelli/antibiotic_cost)]
- [Number of Patients Registered at GP Practices in London](https://mattia-ficarelli.github.io/gp_mapping/) [[GitHub](https://github.com/mattia-ficarelli/gp_mapping)]
Loading

0 comments on commit 77573a4

Please sign in to comment.