The Fingertips API was published recently at this link. At first sight it looks rather complex so we are developing scripts in R to facilitate extracting data via the API. The data and meta data are all available in JSON format which is easily handled by R using packages like jsonlite
.
Lets start with a simple example - extracting the age groups contained within the Fingertips tool. All the calls to the API are of the form https://fingertips.phe.org.uk/api/ so to read the data we simply need to pass the URL to the fromJSON
function. So for example the following code reads the IDs and names for all the age bands used in Fingertips.
if(!require(jsonlite))install.packages("jsonlite")
Loading required package: jsonlite
library(jsonlite)
ages <- fromJSON("https://fingertips.phe.org.uk/api/ages")
head(ages, 20)
Id <int> | Name <chr> | |||
---|---|---|---|---|
1 | -1 | Not applicable | ||
2 | 1 | All ages | ||
3 | 2 | < 1 yr | ||
4 | 3 | 1-4 yrs | ||
5 | 4 | 5-9 yrs | ||
6 | 5 | 10-14 yrs | ||
7 | 6 | 15-19 yrs | ||
8 | 7 | 20-24 yrs | ||
9 | 8 | 25-29 yrs | ||
10 | 9 | 30-34 yrs |
We can extract the gender codes in a similar fashion
sexes <- fromJSON("https://fingertips.phe.org.uk/api/sexes")
head(sexes)
Id <int> | Name <chr> | |||
---|---|---|---|---|
1 | -1 | Not applicable | ||
2 | 4 | Persons | ||
3 | 1 | Male | ||
4 | 2 | Female |
And see what profiles are contained in the tool
profiles <- fromJSON("https://fingertips.phe.org.uk/api/profiles")
names(profiles)
[1] "Id" "Name" "Key" "GroupIds"
head(profiles, 20)
Id <int> | Name <chr> | ||
---|---|---|---|
1 | 8 | Adult Social Care | |
2 | 18 | Local Tobacco Control Profiles | |
3 | 19 | Public Health Outcomes Framework | |
4 | 20 | National General Practice Profiles | |
5 | 21 | National General Practice Profiles (supporting indicators) | |
6 | 22 | Longer Lives | |
7 | 26 | Health Profiles | |
8 | 29 | Inhale - INteractive Health Atlas of Lung conditions in England | |
9 | 30 | Health Protection | |
10 | 32 | NCMP Local Authority Profile |
We can see that within each profiles there are GroupIDs which reflect profile subdomains. For examples, within the PHOF tool which is profile 19, there are 6 domains, or 8 in the Common Mental Disorders Profile.
Domain names can be extracted as follows:
## for mental health profiles
mh <- fromJSON("https://fingertips.phe.org.uk/api/profile?profile_id=40")
mhdomains <- as.vector(mh$GroupIds)
url <- paste0("https://fingertips.phe.org.uk/api/group_metadata?group_ids=", paste0(mhdomains, collapse = "%2C"))
url
[1] "https://fingertips.phe.org.uk/api/group_metadata?group_ids=8000026%2C8000041%2C8000042%2C8000043%2C8000044%2C1938132720%2C1938132954%2C1938132955"
mhdon <- fromJSON(url)
mhdon
Id <int> | Name <chr> | Sequence <int> | ProfileId <int> | |
---|---|---|---|---|
1 | 8000041 | Risk and related factors | 1 | 40 |
2 | 8000026 | Prevalence | 2 | 40 |
3 | 8000042 | Services | 3 | 40 |
4 | 8000043 | Quality and Outcomes | 4 | 40 |
5 | 8000044 | Finance | 5 | 40 |
6 | 1938132720 | CMHD pathway | 6 | 40 |
7 | 1938132954 | Outcomes by problem descriptor | 7 | 40 |
8 | 1938132955 | Availability of therapy type | 8 | 40 |
Follows a similar pattern.
## First we need to extract area types
areatype <- fromJSON("https://fingertips.phe.org.uk/api/area_types")
areatype
Id <int> | Name <chr> | ||
---|---|---|---|
1 | 1 | Local Authority District | |
2 | 2 | Primary Care Trust | |
3 | 3 | Middle Super Output Area | |
4 | 4 | Lower Super Output Area | |
5 | 5 | Strategic Health Authority | |
6 | 6 | Government Office Region | |
7 | 7 | General Practice | |
8 | 8 | Ward | |
9 | 9 | County | |
10 | 14 | Acute Trust |
## for LADs Id = 1
areanames <- fromJSON("https://fingertips.phe.org.uk/api/areas/by_area_type?area_type_id=1")
areanames
Code <chr> | Name <chr> | Short <chr> | AreaTypeId <int> | |
---|---|---|---|---|
1 | E07000223 | Adur | Adur | 1 |
2 | E07000026 | Allerdale | Allerdale | 1 |
3 | E07000032 | Amber Valley | Amber Val | 1 |
4 | E07000224 | Arun | Arun | 1 |
5 | E07000170 | Ashfield | Ashfield | 1 |
6 | E07000105 | Ashford | Ashford | 1 |
7 | E07000004 | Aylesbury Vale | Ayles Vale | 1 |
8 | E07000200 | Babergh | Babergh | 1 |
9 | E07000027 | Barrow-in-Furness | Barrow | 1 |
10 | E07000066 | Basildon | Basildon | 1 |
## First we need to extract area types
subject <- "alcohol"
url = paste0("https://fingertips.phe.org.uk/api/indicator_search?search_text=", subject)
## for LADs Id = 1
indicators <- fromJSON(url)
indicators
named list()