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

LNK-2950: Ability to run measure eval using a command line interface #460

Merged
merged 15 commits into from
Sep 24, 2024

Conversation

seanmcilvenna
Copy link
Contributor

@seanmcilvenna seanmcilvenna commented Sep 6, 2024

Adding FileSystemInvocation class that allows evaluating a measure using a data from the locally running file system

Format: java -jar measureeval.jar -cp com.lantanagroup.link.measureeval.FileSystemInvocation "<measure-bundle-path>" "<patient-bundle-path>" "<start>" "<end>"

Example: java -jar measureeval.jar -cp com.lantanagroup.link.measureeval.FileSystemInvocation "C:/path/to/measure-bundle.json" "C:/path/to/patient-bundle.json" "2021-01-01" "2021-12-31"

Or directly via IntelliJ with a debug configuration.

Summary by CodeRabbit

  • New Features

    • Introduced a command-line interface for evaluating healthcare measures using files from the filesystem.
    • Users can specify paths for measure and patient bundles, along with evaluation date ranges.
    • Comprehensive documentation added to guide users on building and running the module.
    • Enhanced flexibility with multiple execution profiles for different use cases.
    • New logging configuration for improved monitoring and debugging.
  • Bug Fixes

    • Improved error handling during file loading and evaluation processes to provide clearer feedback.

…ing a data from the locally running file system
Copy link
Contributor

coderabbitai bot commented Sep 6, 2024

Walkthrough

The pull request introduces a README.md file for the measureeval module, providing comprehensive instructions for building and using the module as a command-line interface (CLI). It also adds the FileSystemInvocation class for evaluating healthcare measures using FHIR resources from the filesystem, along with modifications to the pom.xml file to support multiple execution profiles. The changes enhance the usability and configurability of the measure evaluation process.

Changes

File Path Change Summary
Java/measureeval/README.md Added documentation for building and running the measureeval module as a CLI.
Java/measureeval/pom.xml Added <mainClass> configuration and introduced api and cli profiles for dynamic execution.
Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java Introduced FileSystemInvocation class for command-line measure evaluations, including methods for loading and evaluating measure and patient bundles.
Java/measureeval/src/main/resources/logback-cli.xml Added logging configuration for CLI application using Logback.

Assessment against linked issues

Objective Addressed Explanation
Ability to run measure eval using a command line interface (LNK-2950)

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
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 54f43a8 and 20d6a77.

Files selected for processing (1)
  • Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java (1 hunks)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (3)
Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java (3)

28-90: LGTM with minor suggestions!

The getBundle method effectively handles loading measure bundles from both files and directories. The logic for parsing JSON and XML formats and recursively loading resources from directories is implemented correctly.

Suggestions for minor improvements:

  • Use the two-argument version of readFileToString to specify the charset explicitly, otherwise it defaults to the system charset which may not always be UTF-8.
  • Consider parsing directly from a FileInputStream instead of first reading the entire file into a String. This can be more memory-efficient, especially for large files.

128-134: Looks good with a suggestion!

The findPatient method correctly uses streams to find the first Patient resource in a Bundle and throws an appropriate exception if no Patient resource is found.

Suggestion:

  • Consider throwing an exception if more than one Patient resource is found in the Bundle. You can replace findFirst() with reduce(StreamUtils::toOnlyElement) to achieve this.

147-179: Looks good with a minor suggestion!

The main method effectively orchestrates the measure evaluation process. It validates the command-line arguments, loads the measure and patient bundles, and evaluates the patient bundle(s) using the compiled MeasureEvaluator. The method handles both single file and directory patient bundle paths and logs detailed evaluation results for each patient.

Suggestion:

  • Consider wrapping the argument parsing logic (lines 153-156) in a try-catch block and print usage information to stderr if it fails. This will provide a more user-friendly experience if the arguments are not provided correctly.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 20d6a77 and 089060d.

Files selected for processing (4)
  • Java/measureeval/README.md (1 hunks)
  • Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java (1 hunks)
  • Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/services/MeasureEvaluator.java (3 hunks)
  • Java/measureeval/src/main/resources/logback.xml (1 hunks)
Additional context used
Learnings (1)
Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java (1)
Learnt from: seanmcilvenna
PR: lantanagroup/link-cloud#460
File: Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java:13-22
Timestamp: 2024-09-17T21:49:24.887Z
Learning: When reviewing class documentation, ensure that suggested enhancements are not already covered in the existing comments.
Additional comments not posted (10)
Java/measureeval/src/main/resources/logback.xml (3)

3-9: LGTM!

The console appender is correctly configured with a PatternLayout that includes relevant information for debugging and monitoring. The pattern layout is well-structured and readable.


11-13: LGTM!

The loggers for com.lantanagroup.link and org.opencds.cqf packages are correctly configured with appropriate log levels. Referencing the "CONSOLE" appender ensures that the logs are output to the console as expected.

Also applies to: 15-17


19-21: LGTM!

The root logger is correctly configured to log messages at the "error" level and directs the output to the "CONSOLE" appender. This ensures that all error messages are captured and logged to the console.

Java/measureeval/README.md (1)

1-38: Excellent documentation for the measureeval module!

The README.md file provides clear and comprehensive instructions for building and running the measureeval module as a CLI. It includes:

  • Steps to compile the module using Maven
  • Instructions for executing the JAR file with specific parameters
  • A table describing the required parameters
  • An example command demonstrating how to structure the command line input

The well-formatted and easy-to-follow documentation enhances user understanding and accessibility of the measureeval functionality, facilitating its use in practical scenarios.

Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/services/MeasureEvaluator.java (4)

32-34: LGTM!

The new public constructor provides a convenient way to create MeasureEvaluator instances with debug logging disabled by default. It delegates to the private constructor with the appropriate arguments.


Line range hint 36-49: LGTM!

The modification to the private constructor allows controlling the debug logging behavior for the CQL engine based on the isDebug flag. This provides flexibility in enabling or disabling debug logging as needed.


61-62: LGTM!

The update to the compile method maintains backward compatibility by delegating to the overloaded version with isDebug set to false. This ensures that the existing behavior is preserved when the isDebug parameter is not provided.


64-65: LGTM!

The new overloaded compile method provides a way to create MeasureEvaluator instances with the ability to control the debug logging behavior. It uses the private constructor with the isDebug flag to enable or disable debug logging as desired.

Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java (2)

93-115: Looks good!

The getBundlesFromDirectoryAndSubDirectories method correctly implements the recursive loading of bundles from a directory and its subdirectories. Filtering files based on extensions and handling exceptions during bundle loading is done appropriately.


117-126: LGTM!

The getGroupPopulations method correctly extracts and formats the group and population information from a MeasureReport into a human-readable string. The implementation looks good.

@seanmcilvenna
Copy link
Contributor Author

@smailliwcs In this round of changes I added a logback.xml file to support logging when running as a CLI... It doesn't seem to be conflicting with spring-boot... But, what do you think? Is that a problem?

@smailliwcs
Copy link
Contributor

Pushed a commit to allow choosing (at build time via a Maven profile) whether to use the API (default) or the CLI as the main class. This allows you to run the CLI via java -jar without the loader.main/PropertiesLauncher rigmarole. Updated the README to reflect this change.

@smailliwcs In this round of changes I added a logback.xml file to support logging when running as a CLI... It doesn't seem to be conflicting with spring-boot... But, what do you think? Is that a problem?

In my testing, logback.xml overrides logback-spring.xml, so I don't think that will work. One option would be to specify a CLI-specific configuration file at invocation time:

java -Dlogback.configurationFile=/path/to/logback-cli.xml -jar measureeval.jar ...

seanmcilvenna and others added 2 commits September 24, 2024 10:14
… `logback-spring.xml` when running as a service

Updating `pom.xml` to use a specific file name and set the logback-cli.xml file as the primary for the `cli` profile in maven
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (4)
Java/measureeval/src/main/resources/logback-cli.xml (1)

15-17: Consider adjusting the log level for org.opencds.cqf.

The logger for the org.opencds.cqf package is set to the "debug" level, which may generate verbose logs. While this could be intentional for detailed debugging of the CQF library, it might be too verbose for regular CLI usage.

Consider adjusting the log level to "info" for regular usage:

-    <logger name="org.opencds.cqf" level="debug" additivity="false">
+    <logger name="org.opencds.cqf" level="info" additivity="false">
         <appender-ref ref="CONSOLE"/>
     </logger>

Alternatively, you could make this configurable via a command-line parameter to allow users to enable debug logging when needed.

Java/measureeval/pom.xml (3)

161-170: LGTM: 'api' profile addition with a minor suggestion.

The 'api' profile is well-structured and correctly set as the default. This ensures backward compatibility with existing builds.

Consider adding a brief comment above the profile to explain its purpose, e.g.:

<!-- Profile for running the application as a Spring Boot API -->
<profile>
    <id>api</id>
    ...
</profile>

This would enhance the readability and maintainability of the POM file.


172-181: LGTM: 'cli' profile addition with a minor suggestion.

The 'cli' profile is well-structured and correctly implements the CLI functionality as per the PR objectives. The custom logback configuration and final name are good additions.

Similar to the 'api' profile, consider adding a brief comment above the profile to explain its purpose, e.g.:

<!-- Profile for building the application as a command-line interface tool -->
<profile>
    <id>cli</id>
    ...
</profile>

This would enhance the readability and maintainability of the POM file.


Line range hint 149-182: Overall changes look good. Consider updating documentation.

The introduction of 'api' and 'cli' profiles effectively implements the new CLI functionality while maintaining the existing API mode. This approach aligns well with the PR objectives and provides a clean separation of concerns.

To ensure proper usage of these new profiles, consider the following suggestions:

  1. Update the project's README or documentation to explain how to build and run the application in both API and CLI modes.
  2. Provide examples of Maven commands to activate each profile, e.g.:
    mvn clean package -Papi
    mvn clean package -Pcli
    
  3. Document the differences in the resulting JAR files and how to execute them, especially for the CLI mode.

These documentation updates will help users and other developers understand and utilize the new functionality effectively.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d596308 and fc9df0e.

Files selected for processing (2)
  • Java/measureeval/pom.xml (2 hunks)
  • Java/measureeval/src/main/resources/logback-cli.xml (1 hunks)
Additional comments not posted (4)
Java/measureeval/src/main/resources/logback-cli.xml (3)

3-9: LGTM: Console appender configuration is well-structured.

The console appender is correctly configured with a comprehensive log pattern that includes timestamp, thread name, log level, logger name, and message. This setup provides detailed information for effective debugging and log analysis.


11-13: LGTM: Logger configuration for com.lantanagroup.link is appropriate.

The logger for the com.lantanagroup.link package is correctly set to the "info" level, which is suitable for general application logging. Setting additivity to false prevents log duplication, ensuring clean log output. This configuration aligns well with the PR objectives for CLI logging.


19-21: LGTM: Root logger configuration is appropriate.

The root logger is correctly set to the "error" level, which is a good practice for CLI applications. This configuration ensures that only critical issues are logged by default, minimizing noise from third-party libraries while still capturing important error messages.

Java/measureeval/pom.xml (1)

149-149: LGTM: Dynamic main class configuration.

The addition of <mainClass>${mainClass}</mainClass> allows for flexible specification of the main class. This is a good practice, enabling different entry points based on profiles or build configurations.

@seanmcilvenna seanmcilvenna merged commit 4574752 into dev Sep 24, 2024
20 checks passed
@seanmcilvenna seanmcilvenna deleted the LNK-2950 branch September 24, 2024 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants