justin13601 / ACES

ACES: Automatic Cohort Extraction System for Event-Streams
https://eventstreamaces.readthedocs.io/en/latest/
MIT License
25 stars 1 forks source link

Support derived predicates between static predicates and plain predicates, as well as nested derived predicates #145

Closed justin13601 closed 3 weeks ago

justin13601 commented 4 weeks ago

For #144

Summary by CodeRabbit

coderabbitai[bot] commented 4 weeks ago

Walkthrough

The changes in this pull request involve enhancements to the get_predicates_df function in src/aces/predicates.py, improving the handling of static variables in derived predicates and refining error messaging. Additionally, several GitHub Actions workflow files have been updated to use newer versions of actions and to include additional steps for installing development packages. The .pre-commit-config.yaml has been updated to a newer version of pre-commit-hooks, while the pyproject.toml file restricts the pre-commit dependency to versions less than 4. The README.md and docs/source/configuration.md files have also been updated to improve documentation clarity and usability.

Changes

File Change Summary
src/aces/predicates.py Enhanced get_predicates_df to handle static variables in derived predicates; improved error handling; added example usages in docstring.
.github/workflows/code-quality-main.yaml Updated actions/checkout and actions/setup-python to versions 4 and 5; added step to install dev packages; updated pre-commit/action.
.github/workflows/code-quality-pr.yaml Similar updates as code-quality-main.yaml, including action version upgrades and new dev package installation step.
.github/workflows/tests.yml Upgraded actions/checkout and actions/setup-python; changed package installation command.
.pre-commit-config.yaml Updated pre-commit-hooks repository version from v4.4.0 to v5.0.0.
pyproject.toml Updated pre-commit dependency constraint from "pre-commit" to "pre-commit<4".
README.md Enhanced documentation for ACES, added details on new features, predicates configuration, and installation instructions.
docs/source/configuration.md Clarified configuration language specification, added notes on memory optimization, and detailed field explanations.
src/aces/config.py Improved error handling in TaskExtractorConfig for predicate definitions; updated docstring examples.
src/aces/query.py Enhanced logging and error handling in query function for label extraction.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Predicates
    participant DataFrame

    User->>Predicates: Call get_predicates_df()
    Predicates->>DataFrame: Retrieve static variables
    DataFrame-->>Predicates: Return static variable values
    Predicates->>DataFrame: Process derived predicates
    DataFrame-->>User: Return updated DataFrame

🐇 "In code we hop and play,
With predicates bright as day,
Static values now align,
In our DataFrame, they shine!
With workflows fresh and neat,
Our coding journey's sweet!" 🐇


📜 Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
📥 Commits Files that changed from the base of the PR and between f5b0dbcd3a7d68f5016e42a921c71500623a2d86 and 89023651b5d57e5faca0b85607083a4d2dc9783b.
📒 Files selected for processing (1) * src/aces/config.py (6 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/aces/config.py
[warning] 1378-1378: src/aces/config.py#L1378 Added line #L1378 was not covered by tests
🔇 Additional comments (5)
src/aces/config.py (5)
`1077-1077`: **LGTM! Improved error message clarity.** The error message now clearly indicates the number of missing relationships and provides better context. --- `1169-1169`: **Excellent documentation improvements!** The added examples effectively demonstrate: 1. Configuration loading with predicates 2. Static and plain predicate joining 3. Complex nested derived predicates This significantly improves the understanding of the configuration system. Also applies to: 1199-1258 --- `1399-1404`: **LGTM! Enhanced input validation.** The added validation properly catches incorrect string-based predicate definitions and provides clear guidance on the correct format. --- `1454-1454`: **LGTM! Consistent error message formatting.** The error message formatting maintains consistency with the codebase style and improves readability. --- `1339-1339`: **LGTM! Robust predicate handling implementation.** The changes effectively: 1. Merge predicates from multiple sources 2. Recursively validate nested derived predicates 3. Build a comprehensive set of referenced predicates However, there's an uncovered code path. Let's verify the test coverage: Also applies to: 1353-1391
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
❤️ Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
codecov[bot] commented 4 weeks ago

Codecov Report

Attention: Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/aces/config.py 93.75% 1 Missing :warning:
Files with missing lines Coverage Δ
src/aces/predicates.py 83.59% <100.00%> (-0.41%) :arrow_down:
src/aces/query.py 72.09% <ø> (-23.66%) :arrow_down:
src/aces/config.py 97.22% <93.75%> (-0.41%) :arrow_down:

... and 4 files with indirect coverage changes

justin13601 commented 4 weeks ago

@mmcdermott I tried to implement a way to allow for derived predicates joining static and plain predicates - basically I just copy over the static predicate values from the null timestamp rows throughout the same subject_id if they exist since these are static and do not change. Then the logic for the evaluation of the derived predicates shouldn't need to change. Does this seem reasonable?

justin13601 commented 4 weeks ago

Might be a bit difficult to properly test the new error/warning messages in query.py...

mmcdermott commented 3 weeks ago

@justin13601, can you add tests to get the codecov up to the desired target?

justin13601 commented 3 weeks ago

Also closes #94

justin13601 commented 3 weeks ago

@mmcdermott I realized nested derived predicates will most likely be needed for creating these different reference ranges so I tried to enable that. Let me know if the following seems reasonable:

To create different reference ranges (for illustration purposes, not following actual clinical guidelines):

Different normal ranges:

  normal_spo2_male_range:
    code: lab_name//O2 saturation pulseoxymetry (%)
    value_min: 90
    value_max: 120
    value_min_inclusive: True
    value_max_inclusive: True
  normal_spo2_female_range:
    code: lab_name//O2 saturation pulseoxymetry (%)
    value_min: 80
    value_max: 110
    value_min_inclusive: True
    value_max_inclusive: True
  normal_spo2_male:
    expr: and(normal_spo2_male_range, male)
  normal_spo2_female:
    expr: and(normal_spo2_female_range, female)

Different abnormal ranges (may be worth looking into not() logic...:

  abnormally_low_spo2_male:
    code: lab_name//O2 saturation pulseoxymetry (%)
    value_max: 90
    value_max_inclusive: False
  abnormally_low_spo2_female:
    code: lab_name//O2 saturation pulseoxymetry (%)
    value_max: 80
    value_max_inclusive: False
  abnormally_high_spo2:
    code: lab_name//O2 saturation pulseoxymetry (%)
    value_min: 120
    value_min_inclusive: False
  abnormal_spo2_male_range:
    expr: or(abnormally_low_spo2_male, abnormally_high_spo2)
  abnormal_spo2_male:
    expr: and(abnormal_spo2_male_range, male)
  abnormal_spo2_female_range:
    expr: or(abnormally_low_spo2_female, abnormally_high_spo2)
  abnormal_spo2_female:
    expr: and(abnormal_spo2_female_range, female)
  abnormal_spo2:
    expr: or(abnormal_spo2_male, abnormal_spo2_female)
mmcdermott commented 3 weeks ago

@justin13601 this LGTM, so merge at your leisure.