OpenSafely
Overview
Section titled “Overview”The OpenSafely dataset provides pseudonymised primary care data from EMIS Web GP practices in England. It is designed for secure health research and analytics, enabling population-level studies while protecting individual patient privacy.
The data is made available through a set of structured models covering clinical events, patient demographics, medications, referrals, and reference data.
Available Models
Section titled “Available Models”Core Clinical Models
Section titled “Core Clinical Models”| Model | Description |
|---|---|
| Patient | Demographics, registration status, and opt-in flags |
| Observation | Clinical observations, test results, and coded entries |
| Consultation | Patient consultations with practitioners |
| Consultation Section | Sections within a consultation (e.g. History, Examination) |
| Problem | Active and past clinical problems |
| Referral | Inbound and outbound referrals |
| Diary | Diary entries and recall events |
| Appointment Slot | Appointment bookings and slot status |
Medication Models
Section titled “Medication Models”| Model | Description |
|---|---|
| Drug Record | Medication courses (repeat and acute prescriptions) |
| Issue Record | Individual prescription issues from a drug record |
Reference & Lookup Models
Section titled “Reference & Lookup Models”| Model | Description |
|---|---|
| Clinical Code | SNOMED CT and Read code mappings |
| Codeable Concept | Extended code metadata including fully specified names |
| Drug Code | Drug code to dm+d product mappings |
| MKB Drug Pack | Drug pack details (units, pricing, supplier) |
| MKB Mapping Attributes | Language and sexual orientation code mappings |
| MKB Mapping DMD Preparation | dm+d preparation code mappings |
| MKB Mapping Ethnicity | Ethnicity SNOMED code mappings |
| Sensitive SNOMED Code | Codes classified as sensitive |
Administrative Models
Section titled “Administrative Models”| Model | Description |
|---|---|
| Sharing Agreements | Data sharing agreement status between organisations |
| Query Utilization | Your personal query execution history and performance |
Key Concepts
Section titled “Key Concepts”Data Freshness
Section titled “Data Freshness”The pipeline processes source data weekly, but consumer-facing models update monthly (last Sunday of each month). This provides a stable analytical baseline throughout the month. See Data Freshness & Quality for full details.
Patient Deduplication
Section titled “Patient Deduplication”Each patient appears as a single row globally, deduplicated by NHS number across all qualifying practices. When a patient transfers between practices, their record updates to reflect the new practice without creating duplicates. See Practice Transfers for details.
Pseudonymisation
Section titled “Pseudonymisation”All patient identifiers (patient_id, nhs_number) are pseudonymised.
Pseudonymisation is deterministic within your user context and stable across
practice transfers, enabling longitudinal analysis.
Data Scope
Section titled “Data Scope”Only data from England GP practices with an active sharing agreement is included. Records flagged as sensitive or confidential at the source are excluded from clinical event models.
Common Patterns
Section titled “Common Patterns”Joining Clinical Events to Patient
Section titled “Joining Clinical Events to Patient”All clinical event models include a patient_id and organisation column. Join
to the patient model on both columns to access demographic information:
SELECT o.observation_id, o.effective_datetime, o.snomed_concept_id, p.sex, p.age, p.date_of_birthFROM explorer_open_safely.observation AS oINNER JOIN explorer_open_safely.patient AS p ON o.patient_id = p.patient_id AND o.organisation = p.organisationWHERE o.is_deleted = FALSE AND p.is_deleted = FALSEResolving Clinical Codes
Section titled “Resolving Clinical Codes”Use the clinical_code or codeable_concept models to look up human-readable
terms for code_id values:
SELECT o.observation_id, o.effective_datetime, c.term, c.snomed_concept_idFROM explorer_open_safely.observation AS oINNER JOIN explorer_open_safely.clinical_code AS c ON o.code_id = c.code_idWHERE o.is_deleted = FALSE AND c.is_deleted = FALSEFiltering Soft-Deleted Records
Section titled “Filtering Soft-Deleted Records”All models include an is_deleted column. When is_deleted = TRUE, the record
has been soft-deleted at the source and all non-primary-key columns will be
NULL. Always filter these out unless you have a specific reason to include them:
WHERE is_deleted = FALSE