Skip to content

Commit

Permalink
Merge pull request #2387 from opensafely-core/rw/expose-discharge-dest
Browse files Browse the repository at this point in the history
Expose the `Discharge_Destination` column of the APCS table
  • Loading branch information
rw251 authored Jan 30, 2025
2 parents a66fdac + 05e2626 commit 2fa95e5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/includes/generated_docs/schemas/tpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,18 @@ The date of discharge from a hospital provider spell.
</dd>
</div>

<div markdown="block">
<dt id="apcs.discharge_destination">
<strong>discharge_destination</strong>
<a class="headerlink" href="#apcs.discharge_destination" title="Permanent link">🔗</a>
<code>string</code>
</dt>
<dd markdown="block">
The destination of a patient on completion of a hospital provider spell, or that the patient died or was a stillbirth. The code is a 2 character string (e.g. 19 = usual place of residence, 54 = NHS run care home). Refer to [this documentation](https://docs.opensafely.org/data-sources/apc/#discharge-destination-reference-table) for a full list of codes.

</dd>
</div>

<div markdown="block">
<dt id="apcs.spell_core_hrg_sus">
<strong>spell_core_hrg_sus</strong>
Expand Down
1 change: 1 addition & 0 deletions ehrql/backends/tpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def apcs(self):
apcs.APCS_Ident AS apcs_ident,
apcs.Admission_Date AS admission_date,
apcs.Discharge_Date AS discharge_date,
apcs.Discharge_Destination as discharge_destination,
apcs.Spell_Core_HRG_SUS AS spell_core_hrg_sus,
apcs.Admission_Method AS admission_method,
apcs.Der_Diagnosis_All AS all_diagnoses,
Expand Down
11 changes: 11 additions & 0 deletions ehrql/tables/tpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@ class apcs(EventFrame):
datetime.date,
description="The date of discharge from a hospital provider spell.",
)
discharge_destination = Series(
str,
description=(
"The destination of a patient on completion of a hospital provider "
"spell, or that the patient died or was a stillbirth. "
"The code is a 2 character string (e.g. 19 = usual place of residence, "
"54 = NHS run care home). "
"Refer to [this documentation](https://docs.opensafely.org/data-sources/apc/#discharge-destination-reference-table) "
"for a full list of codes."
),
)
spell_core_hrg_sus = Series(
str,
description=(
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/backends/test_tpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def test_apcs(select_all_tpp):
APCS_Ident=1,
Admission_Date=date(2023, 1, 1),
Discharge_Date=date(2023, 2, 1),
Discharge_Destination="19",
Spell_Core_HRG_SUS="XXX",
Der_Diagnosis_All="||E119 ,E780 ,J849 ||I801 ,I802 ,N179",
Der_Procedure_All="||E851,T124,X403||Y532,Z921",
Expand Down Expand Up @@ -330,6 +331,7 @@ def test_apcs(select_all_tpp):
"apcs_ident": 1,
"admission_date": date(2023, 1, 1),
"discharge_date": date(2023, 2, 1),
"discharge_destination": "19",
"spell_core_hrg_sus": "XXX",
"all_diagnoses": "||E119 ,E780 ,J849 ||I801 ,I802 ,N179",
"all_procedures": "||E851,T124,X403||Y532,Z921",
Expand All @@ -344,6 +346,7 @@ def test_apcs(select_all_tpp):
"apcs_ident": 2,
"admission_date": date(2022, 6, 1),
"discharge_date": date(2022, 7, 1),
"discharge_destination": None,
"spell_core_hrg_sus": None,
"all_diagnoses": None,
"all_procedures": None,
Expand All @@ -358,6 +361,7 @@ def test_apcs(select_all_tpp):
"apcs_ident": 4,
"admission_date": date(2021, 4, 1),
"discharge_date": date(2021, 5, 1),
"discharge_destination": None,
"spell_core_hrg_sus": None,
"all_diagnoses": None,
"all_procedures": None,
Expand Down

0 comments on commit 2fa95e5

Please sign in to comment.