[e988c2]: / ehrql / tables / raw / core.py

Download this file

121 lines (103 with data), 4.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""
This schema defines the core tables and columns which should be available in any backend
providing primary care data, allowing dataset definitions written using this schema to
run across multiple backends.
The data provided by this schema are minimally transformed. They are very close to the
data provided by the underlying database tables. They are provided for data development
and data curation purposes.
"""
import datetime
from ehrql.codes import ICD10Code
from ehrql.tables import EventFrame, Series, table
__all__ = [
"ons_deaths",
]
class ons_deaths_raw(EventFrame):
"""
Registered deaths
Date and cause of death based on information recorded when deaths are
certified and registered in England and Wales from February 2019 onwards.
The data provider is the Office for National Statistics (ONS).
This table includes the underlying cause of death and up to 15 medical conditions mentioned on the death certificate.
These codes (`cause_of_death_01` to `cause_of_death_15`) are not ordered meaningfully.
More information about this table can be found in following documents provided by the ONS:
- [Information collected at death registration](https://www.ons.gov.uk/peoplepopulationandcommunity/birthsdeathsandmarriages/deaths/methodologies/userguidetomortalitystatisticsjuly2017#information-collected-at-death-registration)
- [User guide to mortality statistics](https://www.ons.gov.uk/peoplepopulationandcommunity/birthsdeathsandmarriages/deaths/methodologies/userguidetomortalitystatisticsjuly2017)
- [How death registrations are recorded and stored by ONS](https://www.ons.gov.uk/aboutus/transparencyandgovernance/freedomofinformationfoi/howdeathregistrationsarerecordedandstoredbyons)
In the associated database table a small number of patients have multiple registered deaths.
This table contains all registered deaths.
The `ehrql.tables.core.ons_deaths` table contains the earliest registered death.
!!! tip
To return one row per patient from `ehrql.tables.raw.core.ons_deaths`,
for example the latest registered death, you can use:
```py
ons_deaths.sort_by(ons_deaths.date).last_for_patient()
```
"""
date = Series(
datetime.date,
description=("Patient's date of death."),
)
underlying_cause_of_death = Series(ICD10Code)
# TODO: Revisit this when we have support for multi-valued fields
cause_of_death_01 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_02 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_03 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_04 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_05 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_06 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_07 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_08 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_09 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_10 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_11 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_12 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_13 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_14 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
cause_of_death_15 = Series(
ICD10Code,
description="Medical condition mentioned on the death certificate.",
)
ons_deaths = table(ons_deaths_raw)