feat: automate preventive maintenance SLA alerts - #975
Conversation
📝 WalkthroughWalkthroughThe 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. ChangesSLA alert processing
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
Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
Backend/src/main/java/com/medtrack/service/MaintenanceSlaAlertScheduler.javaBackend/src/main/java/com/medtrack/service/MaintenanceSlaAlertSchedulerTest.javaBackend/src/main/java/com/medtrack/service/PreventiveMaintenanceService.java
| @Scheduled(cron = "${app.maintenance.sla.alert.cron:0 0 * * * *}") | ||
| public void runSlaSweep() { |
There was a problem hiding this comment.
🎯 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.
| @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
| activityService.recordSystemCreated( | ||
| task, | ||
| "escalated due to critical SLA breach" | ||
| ); | ||
|
|
||
| publishSlaEscalatedEvent(task); |
There was a problem hiding this comment.
🗄️ 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.
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
MaintenanceSlaAlertScheduler.app.maintenance.sla.alert.cron.SLA_WARNINGSLA_BREACHEDSLA_ESCALATEDMAINTENANCE_OVERDUEReliability
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 testgit diff --checkImpact
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