Skip to content

[Backend] Implement Critical Condition Severity Alerts in Conditions Module #507

@llinsss

Description

@llinsss

⚠️ This is a backend issue — work is done inside the backend/ folder

Description

backend/src/modules/conditions/conditions.service.ts has full CRUD for pet health conditions and sorts by severity DESC, but there is no alerting when a critical condition is created or when a condition's severity is escalated. Vets and owners are not notified when a pet is diagnosed with a critical condition.

Current State

  • ConditionsService — CRUD only, no notification logic
  • Condition entity has a severity field (assumed enum: LOW, MEDIUM, HIGH, CRITICAL)
  • NotificationsService is not injected into ConditionsModule
  • No severity escalation detection on update()

What Needs to Be Built

1. Inject NotificationsService

  • Add NotificationsModule to ConditionsModule imports
  • Inject NotificationsService into ConditionsService

2. Alert on Critical Condition Creation

In ConditionsService.create():

if (dto.severity === ConditionSeverity.CRITICAL) {
  await this.notificationsService.create({
    userId: pet.ownerId,
    title: 'Critical Condition Diagnosed',
    body: `${pet.name} has been diagnosed with a critical condition: ${dto.name}`,
    category: NotificationCategory.ALERT,
  });
}

3. Alert on Severity Escalation

In ConditionsService.update():

  • Load the existing condition before updating
  • If severity changes from non-critical to CRITICAL: send alert
  • If severity changes from CRITICAL to lower: send a resolution notification

4. Vet Notification

  • Also notify the assigned vet (if vetId is present on the condition) for CRITICAL and HIGH severity

5. Audit Logging

  • Log severity changes via AuditService with action: UPDATE and metadata containing old/new severity

Acceptance Criteria

  • Creating a CRITICAL condition sends an immediate alert to the pet owner
  • Escalating severity to CRITICAL sends an alert
  • Resolving a CRITICAL condition sends a resolution notification
  • Assigned vet is notified for CRITICAL and HIGH severity conditions
  • Severity changes are recorded in the audit log
  • Unit tests cover creation alert, escalation, and resolution scenarios

Files to Modify

  • backend/src/modules/conditions/conditions.service.ts
  • backend/src/modules/conditions/conditions.module.ts
  • backend/src/modules/conditions/conditions.service.spec.ts (new)

Priority

High — critical diagnoses must trigger immediate owner notification

Estimated Effort

1–2 days

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions