Skip to content

Commit

Permalink
Fix visit_occurrence / visit naming discrepancy (#219)
Browse files Browse the repository at this point in the history
* Update stanford.py

Bug fix -- table is named `visit` in MEDS, not `visit_occurrence`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix visit

* fix visit

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Miking98 and pre-commit-ci[bot] authored Apr 28, 2024
1 parent 5d3a6c2 commit e7bde41
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
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

0 comments on commit e7bde41

Please sign in to comment.