Skip to content

Report log issue in pharmacy reports #11701

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

Merged
merged 2 commits into from
Apr 9, 2025

Conversation

ImeshRanawellaSG
Copy link
Collaborator

@ImeshRanawellaSG ImeshRanawellaSG commented Apr 9, 2025

Summary by CodeRabbit

  • New Features

    • Introduced asynchronous report logging for improved performance and responsiveness.
    • Added new report options for transfer-related metrics.
    • Enhanced tracking of report generation times for departmental transfers.
  • Refactor

    • Streamlined report tracking logic with more accurate timing calculations.

Copy link
Contributor

coderabbitai bot commented Apr 9, 2025

Walkthrough

The changes refactor the report logging mechanism to operate asynchronously. The synchronous usage of ReportLogFacade in ReportTimerController has been replaced with an asynchronous ReportLogAsyncService. ReportTimerController now creates and awaits a Future from the asynchronous service. Additionally, the ReportsTransfer class now wraps report generation logic with execution time tracking via ReportTimerController. New report types have been added to the DisbursementReports enum, and the ReportLog entity has been updated to accommodate a nullable endTime with corresponding execution time calculations.

Changes

File(s) Change Summary
src/main/java/com/divudi/bean/common/ReportTimerController.java
src/main/java/com/divudi/bean/pharmacy/ReportsTransfer.java
src/main/java/com/divudi/service/ReportLogAsyncService.java
Migrated from synchronous logging (using ReportLogFacade) to asynchronous logging using ReportLogAsyncService. ReportTimerController now creates a ReportLog, sends it via an asynchronous call (returning a Future), and awaits its result. ReportsTransfer methods have been updated to wrap execution logic with trackReportExecution. A new stateless bean provides asynchronous logReport functionality with error handling.
src/main/java/com/divudi/core/entity/report/ReportLog.java
src/main/java/com/divudi/core/data/reports/DisbursementReports.java
Updated ReportLog to allow a nullable endTime and to recalculate executionTimeInMillis only when both startTime and endTime are non-null (with a new setter method). Added new enum constants (TRANSFER_ISSUE_BY_BILL, TRANSFER_RECEIVE_BY_BILL) in DisbursementReports to support additional reporting types.

Sequence Diagram(s)

sequenceDiagram
    participant Controller as ReportTimerController
    participant AsyncService as ReportLogAsyncService
    participant LogFacade as ReportLogFacade
    participant ReportGen as Report Generation Logic

    Controller->>Controller: Create ReportLog (capture startTime)
    Controller->>AsyncService: logReport(reportLog) (asynchronous call)
    AsyncService->>LogFacade: Create/Edit ReportLog
    AsyncService-->>Controller: Return CompletableFuture<ReportLog>
    Controller->>Controller: Await result (futureLog.get())
    ReportGen->>Controller: Execute report generation logic
    Controller->>Controller: Capture endTime
    Controller->>Controller: Set endTime via ReportLog.setEndTime()
    Controller->>AsyncService: logReport(updated ReportLog) (asynchronous update)
Loading

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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: 0

🧹 Nitpick comments (4)
src/main/java/com/divudi/service/ReportLogAsyncService.java (2)

29-37: Consider adding transaction retry mechanism.

While the error handling is good, there's no retry mechanism for transient database errors. For async operations, it might be beneficial to add retry logic for temporary failures.

if (reportLog.getId() == null) {
    try {
        getFacade().create(reportLog);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Error occurred while saving the report log", e);
+       // Consider implementing retry logic for transient errors
+       // e.g., using exponential backoff strategy
    }
} else {
    try {
        getFacade().edit(reportLog);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Error occurred while updating the report log", e);
    }
}

42-44: Consider returning the field directly.

The getter method is simple enough that it doesn't need a dedicated method. You could access the field directly, especially since the class is already a service.

src/main/java/com/divudi/bean/common/ReportTimerController.java (2)

32-34: Consider avoiding .get() if full asynchronicity is desired.

Calling futureLog.get() blocks the thread, making the operation effectively synchronous. If the goal is to offload logging entirely, consider removing or deferring the .get() call.


42-44: Capture the second log update result or handle errors.

You are “fire-and-forget” calling reportLogAsyncService.logReport(savedLog). Consider capturing the returned Future<ReportLog> or checking for errors to ensure that any logging failures are detected.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf84811 and 7252548.

📒 Files selected for processing (5)
  • src/main/java/com/divudi/bean/common/ReportTimerController.java (2 hunks)
  • src/main/java/com/divudi/bean/pharmacy/ReportsTransfer.java (6 hunks)
  • src/main/java/com/divudi/core/data/reports/DisbursementReports.java (1 hunks)
  • src/main/java/com/divudi/core/entity/report/ReportLog.java (3 hunks)
  • src/main/java/com/divudi/service/ReportLogAsyncService.java (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/main/java/com/divudi/service/ReportLogAsyncService.java (1)
src/main/java/com/divudi/bean/common/ReportTimerController.java (1)
  • Stateless (17-47)
src/main/java/com/divudi/bean/common/ReportTimerController.java (1)
src/main/java/com/divudi/service/ReportLogAsyncService.java (1)
  • Stateless (14-45)
🔇 Additional comments (11)
src/main/java/com/divudi/core/data/reports/DisbursementReports.java (1)

4-5: New enum constants added for tracking report execution.

These new enum constants will be used to identify and track the execution of transfer issue and receive reports in the asynchronous logging system.

src/main/java/com/divudi/core/entity/report/ReportLog.java (3)

38-38: Column constraint changed to allow null end times.

Making the endTime column nullable is essential for the asynchronous logging system. It allows creating a log entry at the start of report execution with a null endTime, which will be updated after the report completes.


55-55: Null-safety check added for execution time calculation.

This change ensures that execution time is only calculated when both start and end times are available, preventing potential NullPointerExceptions.


116-122: Added setter for endTime with execution time recalculation.

This method is crucial for the asynchronous logging implementation. It allows updating the end time of a report execution and automatically recalculates the execution time if both start and end times are available.

src/main/java/com/divudi/bean/pharmacy/ReportsTransfer.java (2)

454-507: Wrapped report execution with asynchronous tracking.

The report generation logic has been refactored to use the asynchronous tracking system. This ensures that report execution times are logged without blocking the main operation, improving system responsiveness.


1705-1735: Implemented asynchronous tracking for transfer receive report.

Similar to the issue report, the receive report now uses asynchronous execution time tracking. This change is consistent with the overall approach of tracking report performance without impacting user experience.

src/main/java/com/divudi/service/ReportLogAsyncService.java (2)

1-20: New asynchronous service for report logging.

This service implements the asynchronous logging mechanism needed for tracking report execution times. The class is properly annotated with @Stateless and includes appropriate dependencies.


21-40: Implemented asynchronous report logging method.

The @Asynchronous annotation ensures this method runs in a separate thread, preventing it from blocking the main execution flow. The method handles both creation and updating of report logs, with proper null checks and error handling.

src/main/java/com/divudi/bean/common/ReportTimerController.java (3)

6-7: Imports aligned with new asynchronous approach.

These additions for ReportLogAsyncService and Future correctly support the async logging mechanism.

Also applies to: 12-12


22-22: Dependency injection for ReportLogAsyncService looks good.

Replacing the old synchronous dependency with this async EJB is consistent with your asynchronous logging pattern.


27-29: Initialization of ReportLog at start time is correct.

Creating a new ReportLog with a null endTime offers flexibility for finalizing the log once the execution completes.

@GSMgeeth GSMgeeth merged commit 36e6cf8 into development Apr 9, 2025
3 checks passed
@GSMgeeth GSMgeeth deleted the report-log-issue-in-pharmacy-reports branch April 9, 2025 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants