Add support for comprehensive time precision handling and multiple observations per person #210
Merged
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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.
Add support for comprehensive time precision handling and multiple observations per person
TL;DR
ehrdata.io.omop.setup_variables/ehrdata.io.omop.setup_interval_variablesnow allow to specify with a new argumenttime_precisioneitherdateordatetimevisit_occurrencesper person is fineSummary
This PR enhances the OMOP I/O functionality to handle multiple observations per person (e.g., multiple visits, observation periods) and adds more flexible time precision validation with helpful warnings. The changes enable more flexible and accurate temporal data extraction from OMOP CDM databases.
Key Features
New Parameter: time_precision can be "date" or "datetime" to control temporal granularity.
Example:
Previously: Each person could only have one row in the resulting EHRData object.
Now: Rows represent individual observation units (visits, observation periods, cohorts, or persons), and a single person can have multiple rows. This failed with an error before.
Example:
Now Supported: Use observation_table="person" for lifetime analysis, if
birth_datetimeis available.Example:
Smarter Warnings
Warning 1: Time Precision Mismatch
Warns when using fine-grained intervals with date-only precision:
Warning 2: Datetime Precision Fallback
Logs when datetime precision is requested but only date columns are available:
Bug Fixes
Fix 1: Interval Boundary Handling
Problem: Measurements at interval boundaries were counted in both adjacent intervals.
Before:
After:
Changed from BETWEEN start AND end to half-open intervals >= start AND < end.
Fix 2: Chronological LAST/FIRST Aggregation
Problem: LAST() without ordering could return arbitrary values, not the chronologically last value.
Before:
After: