Skip to content

[Backend] Implement Drug Interaction Checker in Prescriptions Module #498

@llinsss

Description

@llinsss

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

Description

PrescriptionsService imports and injects DrugInteractionService from backend/src/modules/prescriptions/services/drug-interaction.service.ts, but this file contains only a stub. When a new prescription is created, no interaction check is performed, meaning dangerous drug combinations can be silently saved.

Current State

  • backend/src/modules/prescriptions/services/drug-interaction.service.ts — stub/empty
  • PrescriptionsService.create() calls this.drugInteractionService.check() but receives no real result
  • No interaction data source is defined

What Needs to Be Built

1. Interaction Data Source

  • Define a static JSON dataset of known drug interactions (common veterinary medications)
  • Or integrate with an external API (e.g. RxNorm / custom vet drug DB) via HTTP
  • Store interaction rules in a drug_interactions DB table with severity levels: MILD, MODERATE, SEVERE, CONTRAINDICATED

2. DrugInteractionService

@Injectable()
export class DrugInteractionService {
  async check(
    newMedication: string,
    existingMedications: string[],
  ): Promise<InteractionResult[]>
}

export interface InteractionResult {
  drug1: string;
  drug2: string;
  severity: 'MILD' | 'MODERATE' | 'SEVERE' | 'CONTRAINDICATED';
  description: string;
}

3. Integration in PrescriptionsService

  • On create(), fetch all active prescriptions for the pet
  • Run interaction check against new medication
  • If CONTRAINDICATED or SEVERE: throw BadRequestException with interaction details
  • If MODERATE: save prescription but attach a warning in the response
  • If MILD: save silently, log warning

4. New Endpoint

POST /prescriptions/check-interactions
Body: { petId, medication }
  • Allows frontend to check interactions before submitting a prescription form

Acceptance Criteria

  • CONTRAINDICATED combinations are blocked with a descriptive error
  • MODERATE interactions return a warning alongside the saved prescription
  • POST /prescriptions/check-interactions returns interaction results without saving
  • Interaction data covers at least 20 common veterinary drug pairs
  • Unit tests cover all severity levels and the no-interaction case

Files to Create / Modify

  • backend/src/modules/prescriptions/services/drug-interaction.service.ts (implement)
  • backend/src/modules/prescriptions/prescriptions.service.ts (integrate check)
  • backend/src/modules/prescriptions/prescriptions.controller.ts (add check endpoint)
  • backend/src/modules/prescriptions/dto/check-interaction.dto.ts (new)
  • backend/src/modules/prescriptions/services/drug-interaction.service.spec.ts (new)

Priority

High — patient safety feature

Estimated Effort

2–3 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