Skip to content

Instantly share code, notes, and snippets.

View tomjemmett's full-sized avatar
😀

Tom Jemmett tomjemmett

😀
View GitHub Profile

Transitive Closure Table of CCG Mergers

The following script builds a transitive closure of the CCG mergers over time. The included .csv will include one row for each CCG from when it was valid, to the day before the successor was valid. It then includes a row from that CCG to any of it's successors, along with the dates that successor was valid from and to.

You can therefore filter the .csv file for any date by checking if your_date >= from_date & your_date <= to_date, then you can join your data on the from column, using the to column as the successor organisation.

Assumptions

@tomjemmett
tomjemmett / nhs-r-raffle.R
Created November 15, 2022 13:57
NHS-R Conference 2022 - T Shirt Raffle App
library(shiny)
library(shinyjs)
library(AzureTableStor)
library(openssl)
library(stringr)
salt <- sha256("nhs-r conference 2022") |> charToRaw()
validate_email <- function(email) {
regex <- r"{^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$}"
library(tidyverse)
library(readxl)
library(sf)
library(withr)
library(janitor)
library(PostcodesioR)
library(leaflet)
get_epcn <- function() {
tf_zip <- withr::local_file("epcn.zip")
@tomjemmett
tomjemmett / Readme.md
Last active September 16, 2022 08:41
CCG to ICB

CCG to ICB

This script will convert any historical CCG to ICB's, as of July 2022. It creates a directed acyclic graph from the ODS successors lists to find the ultimate successor of any CCG.

It does not handle the boundary changes, unless the boundary change covers an entire CCG.

Note, if any ICB sub location is succeeded in the future, then the icb lookup will need to be replaced.

@tomjemmett
tomjemmett / app.R
Created August 18, 2022 15:33
Shiny app with two inputs that update one another
library(shiny)
ui <- fluidPage(
fluidRow(
numericInput("value", "Value", 0, 0, 10),
sliderInput("slider", "Slider", 0, 1, 0.2)
)
)
server <- function(input, output, session) {
@tomjemmett
tomjemmett / aaf.csv
Last active August 11, 2022 14:51
Alcohol Attributable Fractions
condition condition_group sex min_age max_age value diagnoses mortality_flag
Infectious and parasitic diseases: Tuberculosis chronic 1 16 24 -0.01 A1[5-9] NA
Infectious and parasitic diseases: Tuberculosis chronic 2 16 24 0.29 A1[5-9] NA
Infectious and parasitic diseases: Tuberculosis chronic 1 25 34 0.11 A1[5-9] NA
Infectious and parasitic diseases: Tuberculosis chronic 2 25 34 0.25 A1[5-9] NA
Infectious and parasitic diseases: Tuberculosis chronic 1 35 44 0.23 A1[5-9] NA
Infectious and parasitic diseases: Tuberculosis chronic 2 35 44 0.27 A1[5-9] NA
Infectious and parasitic diseases: Tuberculosis chronic 1 45 54 0.26 A1[5-9] NA
Infectious and parasitic diseases: Tuberculosis chronic 2 45 54 0.33 A1[5-9] NA
Infectious and parasitic diseases: Tuberculosis chronic 1 55 64 0.33 A1[5-9] NA
@tomjemmett
tomjemmett / specialties.R
Created June 6, 2022 07:53
Get NHS Specialties List
library(rvest)
url <- "https://www.datadictionary.nhs.uk/supporting_information/main_specialty_and_treatment_function_codes_table.html"
content <- url |>
httr::GET(config = httr::config(ssl_verifypeer= FALSE))
page <- read_html(url)
tables <- html_table(page)[c(1, 3)]
@tomjemmett
tomjemmett / Readme.md
Last active May 5, 2022 20:43
Azure VM/Sql Access with Azure AD

Azure VM/Sql Access with Azure AD

In order to have an Azure VM get access to an Azure Sql database (including Synapse serverless) using Azure AD for authentication follow these steps:

  1. Join the VM to Azure AD
  2. On the Sql database server, in the database you want to grant the VM access to, run
CREATE USER [VM_NAME] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [VM_NAME];
@tomjemmett
tomjemmett / reinstall_steps.md
Last active May 3, 2023 15:43
reinstall r packages after an upgrade

Reinstall R packages after an upgrade

Packages that you install in R are tied to a particular version of R, so after installing a new version none of your previously installed pacakges will remain. I tend to think of this as a feature (time for a spring clean...), and then just reinstall pacakges that I know I need (e.g. install.packages(c("tidyverse", "usethis", "devtools"))) and continue to install pacakges as I realise that I need them.

However, if you really want to reinstall the previous set of packages, the steps below will help. First, we collect a list of packages that were installed from CRAN and a list of packages that were installed from GitHub repositories. Once we have those lists, after intalling the new version of R we can load the list of those packages and reinstall them.

@tomjemmett
tomjemmett / mockery.Rmd
Created July 20, 2021 12:48
{mockery} examples
---
title: "Mocking in Unit Tests"
author: "[Tom Jemmett][tj_email]"
output: github_document
---
```{r setup}
suppressPackageStartupMessages({
library(tidyverse)
library(NHSRdatasets)