Documentation about common queries against the prescribing dataset.
You will need a Google account with the correct permissions (set up by an administrator) to access our BigQuery account.
Then follow this quickstart (ignoring the first section "Before you begin")
BigQuery provides a SQL-like interface to massive datasets. It has two dialects, "Legacy" and "standard". When running a query, the default is "Legacy"; you must select "standard" in the options section to use that. Nearly all the examples here are in "standard" format, which is compatible with standard SQL. However, sometimes it is necessary to use "Legacy" format as some functions have not yet been ported by Google to the newer format.
Standard SQL supports temp tables which can make your queries more readable than using lots of subqueries.
Legacy SQL used to have a more extensive range of aggregate functions, and in particular, window functions. However, OpenPrescribing is now able to use standard SQL exclusively.
A comparison between the two formats is here.
BigQuery is billed by the amount of data queried. Querying the entire prescribing table costs about 20 cents. You should bear these costs in mind if running large numbers of queries. Good practice is to extract, say, one month of data to a new table to design your queries, e.g. running
SELECT *
FROM ebmdatalab.hscic.prescribing
WHERE month = TIMESTAMP('2016-06-01')
...and selecting "save to table". If you then save this to a table ebmdatalb.tmp.<something>
, then you can continue to design your query like:
SELECT *
FROM ebmdatalab.tmp.<something>
WHERE bnf_code LIKE '02%'
LIMIT 1000
hscic.prescribing
normalised_prescribing_*
tables, described belowsha
: Area team code (TODO: what is this?)pct
: Identifier of CCGpractice
: Identifier of practicebnf_code
: BNF code of presentationbnf_name
: Name of presentation in BNFitems
: Number of items, where "item" means "appearance on a prescription"net_cost
: The cost of the presentation that month to that practice, according to the Drug Tariffactual_cost
: The actual cost when taking into account adjustments for bulk purchases, out of pocket expenses, etc. This is the "cost" field that we usually want to queryquantity
: number of pills/grams/millilitres/dressings/ampoules prescribedmonth
: Month, as a TIMESTAMP
of the first millisecond of the monthhscic.normalised_prescribing_standard
and hscic.normalised_prescribing_legacy
prescribing
table that normalise the pct
and bnf_code
fields as described below.normalised_prescribing_standard
when you want to use Standard SQL, and normalised_prescribing_legacy
when you want to use Legacy SQL.prescribing
table, except:
pct
field is renamed to ccg_id
, and is the identifier of the CCG that the practice is currently in, as it may have moved between CCGsbnf_code
field is the most recent version of the BNF codehscic.practices
:
setting
of 4
are standard GP practices (see below for a full list of settings
s)code
: Identifier of practicename
: Name of practiceaddress1
to address5
, postcode
: Portions of addresslocation
: Location of practice in WG84 formatccg_id
: Identifier of practice's current CCGsetting
: See below for a full list of settings
sclose_date
: Date practice closedjoin_provider_date
: Date practice joined CCGleave_provider_date
: Date practice closedopen_date
: Data practice openedstatus_code
: One of the following:
A
: Active
B
: Retired
C
: Closed
D
: Dormant
P
: Proposed
U
: Unknownhscic.ccgs
:
code
: Identifier of CCGname
: Name of CCGons_code
: ONS codeorg_type
: One of the following:
CCG
PCT
Unknown
open_date
: Date CCG was formedclose_date
: Date CCG closedaddress
, postcode
: Address of principal officehscic.practice_statistics
:
month
practice
pct_id
total_list_size
astro_pu_cost
astro_pu_items
star_pu
0_4
, 15_24
, 25_34
, 35_44
, 45_54
, 55_64
, 5_14
, 65_74
, 75_plus
female_{age_group}
male_{age_group}
hscic.presentation
:
bnf_code
name
is_generic
active_quantity
adq
adq_unit
percent_of_adq
hscic.ppu_savings
:
date
pct_id
practice_id
bnf_code
lowest_decile
quantity
price_per_unit
possible_savings
formulation_swap
dmd.product
:
dmd.tariffprice
:
date
vmpp
product
tariff_category
price_pence
dmd.ncsoconcession
:
vmpp
date
drug
pack_size
price_concession_pence
dmd.vmpp
vvpid
: Primary key, corresponds to tariffprice.vmpp
and ncsoconcession.vmpp
invalid
nm
abbrevnm
vpid
qtyval
qty_uomcd
combpackcd
The different kinds of practice available in the setting
column of the practices
table are as follows:
The datain the prescribing table covers prescriptions prescribed by GPs and other non-medical prescribers (nurses, pharmacists and others) in England and dispensed in the community in the UK. Prescriptions written in England but dispensed outside England are included.
The format of the data in the prescribing table is documented by the NHS here.
The unique identifier for the item prescribed is the bnf_code
.
The BNF (British National Formulary) is the de facto standard list of medicines used UK prescribing. Maintained by the British Medical Association and the Royal Pharmaceutical Society, it lists indications, dosages, side effects and so on for more than 70,000 medicines.
The prescribing data uses a modified version of the BNF which was current in 2014, with custom additions and alterations. The resulting system is called a BNF pseudo-classification and is described here. In particular, appliances are not listed in the BNF at all, so are included in the pseudo-classification with sections named DUMMY SECTION
.
The first characters of the code provide a hierarchical classification of the presentation.
The last few characters identify individual presentations, and a way of identifying their generic equivalents.
The image below shows how you might examine Tramadol. Tramadol is an opiod pain medicine, available in the UK as tablets (i.e. pills), capsules (i.e. gelatine things), patches, liquids and more. Just focussing on tablets, these are available as standard tablets, and modified release tablets (which are absorbed by the body over a longer period of time, allowing the patient to take less frequent doses). Modified release tablets are available in 50mg, 100mg, 150mg, 200mg, 300mg and 400mg pills.