Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix visit_occurrence / visit naming discrepancy #219

Merged
merged 4 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ We recommend users start with our [tutorial folder](https://github.com/som-shahl
pip install femr

# If you are using deep learning, you also need to install xformers
#
# Note that xformers has some known issues with MacOS.
#
# Note that xformers has some known issues with MacOS.
# If you are using MacOS you might also need to install llvm. See https://stackoverflow.com/questions/60005176/how-to-deal-with-clang-error-unsupported-option-fopenmp-on-travis
pip install xformers

Expand Down
2 changes: 1 addition & 1 deletion src/femr/post_etl_pipelines/stanford.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


def _is_visit_measurement(e: meds.Measurement) -> bool:
return e["metadata"]["table"] == "visit_occurrence"
return e["metadata"]["table"] == "visit"


def _get_stanford_transformations() -> Callable[[meds.Patient], meds.Patient]:
Expand Down
4 changes: 2 additions & 2 deletions src/femr/transforms/stanford.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def move_visit_start_to_first_event_start(patient: meds.Patient) -> meds.Patient
# Find the stated start time for each visit
for event in patient["events"]:
for measurement in event["measurements"]:
if measurement["metadata"]["table"] == "visit_occurrence":
if measurement["metadata"]["table"] == "visit":
if (
measurement["metadata"]["visit_id"] in visit_starts
and visit_starts[measurement["metadata"]["visit_id"]] != event["time"]
Expand Down Expand Up @@ -72,7 +72,7 @@ def move_visit_start_to_first_event_start(patient: meds.Patient) -> meds.Patient
for event in patient["events"]:
new_measurements = []
for measurement in event["measurements"]:
if measurement["metadata"]["table"] == "visit_occurrence":
if measurement["metadata"]["table"] == "visit":
# Triggers if there is a non-visit event associated with the visit ID that has
# start time strictly after the recorded visit start
if measurement["metadata"]["visit_id"] in first_event_starts:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_move_visit_start_ignores_other_visits() -> None:
{
"code": 4567,
"metadata": {
"table": "visit_occurrence",
"table": "visit",
"visit_id": 9999,
},
}
Expand Down Expand Up @@ -102,7 +102,7 @@ def test_move_visit_start_ignores_other_visits() -> None:
{
"code": 4567,
"metadata": {
"table": "visit_occurrence",
"table": "visit",
"visit_id": 9999,
},
}
Expand All @@ -128,7 +128,7 @@ def test_move_visit_start_minute_after_midnight() -> None:
{
"time": datetime.datetime(1999, 7, 2),
"measurements": [
{"code": 3456, "metadata": {"visit_id": 9999, "table": "visit_occurrence"}},
{"code": 3456, "metadata": {"visit_id": 9999, "table": "visit"}},
{"code": 1234, "metadata": {"visit_id": 9999}},
],
},
Expand All @@ -152,7 +152,7 @@ def test_move_visit_start_minute_after_midnight() -> None:
},
{
"time": datetime.datetime(1999, 7, 2, 0, 1),
"measurements": [{"code": 3456, "metadata": {"visit_id": 9999, "table": "visit_occurrence"}}],
"measurements": [{"code": 3456, "metadata": {"visit_id": 9999, "table": "visit"}}],
},
{
"time": datetime.datetime(1999, 7, 2, 0, 1),
Expand All @@ -179,7 +179,7 @@ def test_move_visit_start_doesnt_move_without_event() -> None:
"time": datetime.datetime(1999, 7, 2),
"measurements": [
{"code": 1234, "metadata": {"visit_id": 9999}},
{"code": 3456, "metadata": {"visit_id": 9999, "table": "visit_occurrence"}},
{"code": 3456, "metadata": {"visit_id": 9999, "table": "visit"}},
{"code": 2345, "metadata": {"visit_id": 9999}},
],
},
Expand All @@ -195,7 +195,7 @@ def test_move_visit_start_doesnt_move_without_event() -> None:
"time": datetime.datetime(1999, 7, 2),
"measurements": [
{"code": 1234, "metadata": {"visit_id": 9999}},
{"code": 3456, "metadata": {"visit_id": 9999, "table": "visit_occurrence"}},
{"code": 3456, "metadata": {"visit_id": 9999, "table": "visit"}},
{"code": 2345, "metadata": {"visit_id": 9999}},
],
}
Expand Down
Loading