Store explicit side-effect severity - #144
Open
Airwhale wants to merge 2 commits into
Open
Conversation
Represent each classified side effect as a validated object containing the symptom name and an optional ordinal severity. Persist the objects in the existing JSON column without migrating prior rows, and document the new shape. Severity remains null unless the author explicitly states it. Add focused validation and SQLite persistence tests.
Combine successful nested classification validation with the SQLite round trip so one test verifies parsing, serialization, and persistence. Preserve mild and severe values, explicit null, and omitted severity in the stored JSON assertions. Keep a focused invalid-severity check on SideEffectReport and remove the duplicate standalone success assertion. Validation: uv run --locked pytest -q (378 passed); uvx ruff check tests/test_side_effect_severity.py; git diff --check.
Airwhale
marked this pull request as ready for review
September 11, 2026 22:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from
main: #121 -> #119 -> #122 -> #118 -> #120 -> #142 -> #141 -> #144The first five PRs are merged. The remaining open stack is #142 -> #141 -> #144.
Why
The classifier currently stores side effects as symptom strings. That preserves which effect was reported but loses whether the author described it as mild, moderate, severe, or life-threatening. As a result, analyses can compare side-effect reporting rates but cannot test whether dose or route is associated with reported severity.
The extraction must remain conservative. A symptom that sounds clinically serious is not evidence that the author experienced it severely, so severity should remain missing unless the author explicitly states it.
Approach taken
SideEffectReportmodel withside_effectand nullableseverityfields.mild,moderate,severe, andlife_threatening.treatment_reports.side_effectstext column. No schema migration or rewrite of existing rows is required.User-facing changes
New classification rows store side effects as objects such as:
{"side_effect": "headache", "severity": "mild"}When the author reports a side effect without describing its intensity,
severityisnull. Existing database rows are unchanged and retain their original string-array JSON.Detailed test plan
Expected result:
379 passed.Expected result:
3 passed.Expected result:
All checks passed!Expected files: