Skip to content

Commit

Permalink
Merge branch 'feat/ehrshot' of https://github.com/som-shahlab/femr in…
Browse files Browse the repository at this point in the history
…to feat/ehrshot
  • Loading branch information
Miking98 committed Apr 16, 2024
2 parents 53c0e4f + c602bc2 commit 5755121
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
5 changes: 1 addition & 4 deletions src/femr/labelers/ehrshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ def get_outpatient_visit_measurements(
measurements: List[meds.Measurement] = []
for e in patient["events"]:
for m in e["measurements"]:
if (
m["metadata"]["table"] == "visit"
and m["code"] in admission_codes
):
if m["metadata"]["table"] == "visit" and m["code"] in admission_codes:
if isinstance(m["metadata"]["end"], str):
m["metadata"]["end"] = datetime.datetime.fromisoformat(m["metadata"]["end"])
# Error checking
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 @@ -12,12 +12,12 @@

from femr.transforms import delta_encode, remove_nones
from femr.transforms.stanford import (
join_consecutive_day_visits,
move_billing_codes,
move_pre_birth,
move_to_day_end,
move_visit_start_to_first_event_start,
switch_to_icd10cm,
join_consecutive_day_visits,
)


Expand Down
13 changes: 9 additions & 4 deletions src/femr/transforms/stanford.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,14 @@ def join_consecutive_day_visits(patient: meds.Patient) -> meds.Patient:
for m_idx, m in enumerate(event['measurements']):
if m['metadata']['visit_id'] is not None and m['metadata']['table'] in ['visit', 'visit_detail']:
# Found visit measurement
m_end = datetime.datetime.fromisoformat(m['metadata']['end']) if isinstance(m['metadata']['end'], str) else m['metadata']['end']
m_end = (
datetime.datetime.fromisoformat(m["metadata"]["end"])
if isinstance(m["metadata"]["end"], str)
else m["metadata"]["end"]
)
if current_visit_id is None:
# Start a new visit
current_visit_id = m['metadata']['visit_id']
current_visit_id = m["metadata"]["visit_id"]
current_visit_end = m_end
current_visit_code = m['code']
elif m['metadata']['visit_id'] == current_visit_id:
Expand All @@ -196,13 +200,13 @@ def join_consecutive_day_visits(patient: meds.Patient) -> meds.Patient:
current_visit_end = max(m_end, current_visit_end)
current_visit_code = select_code(current_visit_code, m['code'])
else:
if (event['time'] - current_visit_end).days <= 1:
if (event["time"] - current_visit_end).days <= 1:
# Merge the two visits
current_visit_end = max(m_end, current_visit_end)
current_visit_code = select_code(current_visit_code, m['code'])
else:
# Start a new visit
current_visit_id = m['metadata']['visit_id']
current_visit_id = m["metadata"]["visit_id"]
current_visit_end = m_end
current_visit_code = m['code']
# NOTE: Need to update both this visit_id and the current_visit_id
Expand Down Expand Up @@ -238,6 +242,7 @@ def join_consecutive_day_visits(patient: meds.Patient) -> meds.Patient:
patient['events'] = events
return patient


def move_billing_codes(patient: meds.Patient) -> meds.Patient:
"""Move billing codes to the end of each visit.
Expand Down
8 changes: 2 additions & 6 deletions tests/labelers/test_CodeLabelers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
from femr_test_tools import EventsWithLabels, run_test_for_labeler

from femr.labelers import TimeHorizon
from femr.labelers.omop import (
CodeLabeler,
LupusCodeLabeler,
MortalityCodeLabeler,
OMOPConceptCodeLabeler,
)
from femr.labelers.omop import CodeLabeler, LupusCodeLabeler, MortalityCodeLabeler, OMOPConceptCodeLabeler

# from femr.labelers.ehrshot import (
# AnemiaCodeLabeler,
# HyperkalemiaCodeLabeler,
Expand Down

0 comments on commit 5755121

Please sign in to comment.