fixes invest/treat order column in aae hes data - #290
Conversation
tomjemmett
left a comment
There was a problem hiding this comment.
for information: I have already fixed the data in UDAL using this code.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The order literal remains quoted ('{i + 1}'), producing a string column instead of the numeric value stated in the PR description and used unquoted in the sibling diagnoses.py helper.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
This PR fixes the treatment_order / investigation_order columns produced by the HES A&E melt (stack) helpers. Previously the order value was set to the source column name (e.g. treat_01, invest_02), so the ordinal position was lost; the change derives the order from the enumeration index instead. This feeds downstream primary-treatment selection in raw_data/aae.py, which filters on *_order == 1.
Changes:
- Replace the column-name order key with the 1-based enumeration index in the
stackexpression for A&E treatments. - Apply the same fix for A&E investigations.
| File | Description |
|---|---|
| src/nhp/data/hes/aae/treatments.py | Uses i + 1 instead of the column name as the treatment_order value in the stack melt string. |
| src/nhp/data/hes/aae/investigations.py | Uses i + 1 instead of the column name as the investigation_order value in the stack melt string. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
yiwen-h
left a comment
There was a problem hiding this comment.
Makes sense to me; do we know what the expected difference will be to TPMA data, if any?
|
None, this was an artifact of moving the hes steps into nhp_data. |

the invest/treat order columns should be a numeric value, 1, 2, 3... etc. but, we were using the column name, so these were coming through as treat_01, treat_02, treat_03, etc.
this fixes that by replacing the strings with the correct integer value