Using ehrQL as part of a study
The last piece in the puzzle is to demonstrate how to use a dataset definition in an OpenSAFELY study. An OpenSAFELY study consists of a set of actions. At least one action must be an ehrQL action, to extract a dataset from an OpenSAFELY backend.
You can run a single action using opensafely exec.
In your Codespace, open a terminal by pressing Ctrl+J, and run:
opensafely exec ehrql:v1 generate-dataset dataset_definition.py --dummy-tables dummy_tables
You should see the terminal fill with a table of data in CSV format.
Scroll up to see the column headers, and notice the two columns from your dataset definition (prt_or_mal and ace_or_arb).

Question: what happens if you rename the
datasetvariable and run theopensafely execcommand again?
The anatomy of an OpenSAFELY command
What do the parts of the OpenSAFELY command
opensafely exec ehrql:v1 generate-dataset dataset_definition.py
do?
- opensafely execexecutes an OpenSAFELY action independently of other OpenSAFELY actions
- ehrqlis the OpenSAFELY action to execute
- v1is the major version of the ehrQL action
- generate-datasetis the ehrQL command to generate a dataset from a dataset definition
- dataset_definition.pyis the dataset definition
- --dummy-tables dummy_tablesgives the path to the dummy data
Note: the main OpenSAFELY tutorial documents how you can describe the actions of your study in a file called project.yaml.
Next: Test your ehrQL knowledge with a quiz!
Feedback
Don't fancy the quiz? That's not a problem, but if you could fill in this very short feedback form we'd really appreciate it.