Skip to content

feat: automate preventive maintenance SLA alerts - #975

Open
Anubhutisharma-07 wants to merge 1 commit into
kRamu81:mainfrom
Anubhutisharma-07:feature/972-maintenance-sla-escalation
Open

feat: automate preventive maintenance SLA alerts#975
Anubhutisharma-07 wants to merge 1 commit into
kRamu81:mainfrom
Anubhutisharma-07:feature/972-maintenance-sla-escalation

Conversation

@Anubhutisharma-07

@Anubhutisharma-07 Anubhutisharma-07 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

Introduces automated SLA monitoring for preventive-maintenance tasks through a scheduled hospital-wide SLA sweep.

The implementation ensures SLA states are recalculated proactively without requiring a hospital user to open the SLA dashboard, while preserving the existing event-driven warning, breach, and escalation behavior.

Changes

  • Added scheduled SLA sweep using MaintenanceSlaAlertScheduler.
  • Runs hourly by default with configurable cron scheduling through app.maintenance.sla.alert.cron.
  • Processes SLA status independently for every hospital.
  • Continues processing remaining hospitals when one hospital fails.
  • Added operational logging for:
    • Hospitals processed
    • Failed hospital sweeps
    • Warning tasks
    • Breached tasks
    • Escalated tasks
  • Added scheduler-level tests covering:
    • Multiple hospital processing
    • Failure isolation
    • Invalid hospital records
    • Empty hospital lists
  • Added explicit SLA scheduler configuration.
  • Preserved existing SLA transition events:
    • SLA_WARNING
    • SLA_BREACHED
    • SLA_ESCALATED
    • MAINTENANCE_OVERDUE

Reliability

The scheduler delegates SLA computation to the existing PreventiveMaintenanceService, ensuring manual and scheduled SLA processing use the same business logic.

A failure for one hospital does not terminate the complete SLA sweep.

Validation

  • mvn clean test
  • git diff --check

Impact

This makes preventive-maintenance SLA monitoring proactive and production-oriented, allowing overdue and critical maintenance work to be detected and escalated even when no user is actively viewing the SLA dashboard.

Summary by CodeRabbit

  • New Features
    • Enhanced preventive maintenance SLA monitoring with summary tracking for warnings, breaches, and escalations.
    • Added SLA escalation notifications for critical and unassigned high-priority overdue tasks.
  • Bug Fixes
    • Improved scheduled SLA processing so one hospital’s processing failure does not interrupt checks for others.
    • Added handling for hospitals without valid identifiers and periods with no hospitals to process.
  • Reliability
    • Improved operational visibility with clearer SLA sweep completion and failure reporting.

@github-actions github-actions Bot added the ECSoC26 ECSoC 2026 Initiative label Aug 11, 2026
@github-actions github-actions Bot added backend Backend related changes Frontend Frontend related changes labels Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The scheduled SLA sweep now validates hospitals, isolates processing failures, aggregates SLA counts, and logs summaries. Preventive-maintenance escalation paths now publish SLA escalation events after saving escalated tasks.

Changes

SLA alert processing

Layer / File(s) Summary
Scheduled SLA sweep and validation
Backend/src/main/java/com/medtrack/service/MaintenanceSlaAlertScheduler.java, Backend/src/main/java/com/medtrack/service/MaintenanceSlaAlertSchedulerTest.java
The scheduler validates hospital IDs, continues after per-hospital failures, aggregates SLA results, and logs sweep summaries. Unit tests cover valid, invalid, empty, and failing hospital inputs.
Escalation activity and event publication
Backend/src/main/java/com/medtrack/service/PreventiveMaintenanceService.java
Critical breached tasks and unassigned high-priority breached tasks now publish SLA escalation events after escalation is saved.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MaintenanceSlaAlertScheduler
  participant HospitalRepository
  participant PreventiveMaintenanceService
  MaintenanceSlaAlertScheduler->>HospitalRepository: Load hospitals
  HospitalRepository-->>MaintenanceSlaAlertScheduler: Return hospital list
  loop Each hospital with an ID
    MaintenanceSlaAlertScheduler->>PreventiveMaintenanceService: Process SLA alerts
    PreventiveMaintenanceService-->>MaintenanceSlaAlertScheduler: Return SlaSummaryResponse
  end
  MaintenanceSlaAlertScheduler->>MaintenanceSlaAlertScheduler: Log completion summary
Loading

Possibly related issues

Possibly related PRs

Suggested labels: good-backend, good-pr

Suggested reviewers: kramu81

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: automated preventive-maintenance SLA alerts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@Backend/src/main/java/com/medtrack/service/MaintenanceSlaAlertScheduler.java`:
- Around line 38-39: Remove the duplicate nested `@Scheduled` annotation and
runSlaSweep() declaration, leaving only the existing top-level scheduler
declaration so the class remains valid Java.

In
`@Backend/src/main/java/com/medtrack/service/PreventiveMaintenanceService.java`:
- Around line 348-353: Replace activityService.recordSystemCreated in both
PreventiveMaintenanceService.java ranges 348-353 and 365-370 with the dedicated
escalation activity method, using the corresponding escalation activity type,
while preserving the existing escalation message and publishSlaEscalatedEvent
flow.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7fcf504b-325f-4f3f-9f26-7da51340fc93

📥 Commits

Reviewing files that changed from the base of the PR and between b18cc4d and d53351d.

📒 Files selected for processing (3)
  • Backend/src/main/java/com/medtrack/service/MaintenanceSlaAlertScheduler.java
  • Backend/src/main/java/com/medtrack/service/MaintenanceSlaAlertSchedulerTest.java
  • Backend/src/main/java/com/medtrack/service/PreventiveMaintenanceService.java

Comment on lines +38 to +39
@Scheduled(cron = "${app.maintenance.sla.alert.cron:0 0 * * * *}")
public void runSlaSweep() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Remove the duplicate nested scheduler declaration.

Line 38 repeats @Scheduled inside runSlaSweep. Line 39 declares a method inside another method. Java cannot parse this class. Keep the annotation and method declaration at lines 36-37 only.

Proposed fix
-        `@Scheduled`(cron = "${app.maintenance.sla.alert.cron:0 0 * * * *}")
-        public void runSlaSweep() {
             log.info("Starting scheduled maintenance SLA sweep");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Scheduled(cron = "${app.maintenance.sla.alert.cron:0 0 * * * *}")
public void runSlaSweep() {
🧰 Tools
🪛 PMD (7.26.0)

[High] 39-39: Parse Error: ParseException: Parse exception in file 'Backend/src/main/java/com/medtrack/service/MaintenanceSlaAlertScheduler.java' at line 39, column 16: Encountered .
Was expecting one of:

(Parse Error)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Backend/src/main/java/com/medtrack/service/MaintenanceSlaAlertScheduler.java`
around lines 38 - 39, Remove the duplicate nested `@Scheduled` annotation and
runSlaSweep() declaration, leaving only the existing top-level scheduler
declaration so the class remains valid Java.

Source: Linters/SAST tools

Comment on lines +348 to +353
activityService.recordSystemCreated(
task,
"escalated due to critical SLA breach"
);

publishSlaEscalatedEvent(task);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Record an escalation activity instead of a creation activity.

recordSystemCreated writes a TASK_CREATED activity and a task-created summary. Neither path creates a task. Each escalation will create a false task-creation audit entry.

  • Backend/src/main/java/com/medtrack/service/PreventiveMaintenanceService.java#L348-L353: Use a dedicated escalation activity method and activity type.
  • Backend/src/main/java/com/medtrack/service/PreventiveMaintenanceService.java#L365-L370: Use the same dedicated escalation activity method and activity type.
📍 Affects 1 file
  • Backend/src/main/java/com/medtrack/service/PreventiveMaintenanceService.java#L348-L353 (this comment)
  • Backend/src/main/java/com/medtrack/service/PreventiveMaintenanceService.java#L365-L370
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Backend/src/main/java/com/medtrack/service/PreventiveMaintenanceService.java`
around lines 348 - 353, Replace activityService.recordSystemCreated in both
PreventiveMaintenanceService.java ranges 348-353 and 365-370 with the dedicated
escalation activity method, using the corresponding escalation activity type,
while preserving the existing escalation message and publishSlaEscalatedEvent
flow.

@kRamu81 kRamu81 added good-pr Bonus: Exceptional Pull Request good-ui Bonus: Excellent User Interface good-backend Bonus: Excellent Backend Code good-issue Bonus: High Quality Issue labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend related changes ECSoC26 ECSoC 2026 Initiative Frontend Frontend related changes good-backend Bonus: Excellent Backend Code good-issue Bonus: High Quality Issue good-pr Bonus: Exceptional Pull Request good-ui Bonus: Excellent User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants