Skip to content

Fix division by zero in ClinicActivityDataService-created-by-agentic #100

Description

@asafchen-dig

Issue Description

An ArithmeticException is occurring in the ClinicActivityDataService when calculating active logs ratio due to a division by zero scenario.

Impact

  • Service failures when attempting to calculate ratios for log types with no entries
  • Affects endpoints:
    • /api/clinic-activity/active-errors-ratio
    • /api/clinic-activity/active-warning-ratio

Root Cause

The getActiveLogsRatio method performs division without checking for a zero denominator:

public int getActiveLogsRatio(String type) {
    var all = repository.countLogsByType(type);
    var active = repository.countActiveLogsByType(type);
    return active/all;  // Throws ArithmeticException when all == 0
}

Solution

A fix has been implemented in PR #99 that:

  1. Adds validation for zero denominator
  2. Returns 0 when no logs exist
  3. Adds proper error logging
  4. Converts ratio to percentage for better readability

Additional Notes

  • Added warning logs to help track when this edge case occurs
  • Improved method to return percentage instead of raw ratio for better usability

Related PR: #99

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions